From 7fb03bb36e45588cb2bbd7246084d55f293d37d5 Mon Sep 17 00:00:00 2001 From: Ken Kunz Date: Wed, 11 Oct 2023 10:19:58 -0500 Subject: [PATCH] Fix wallet connection bug - don't rely on connector.constructor.name to match after minification - fixes tradingstrategy-ai/scratchpad#66 --- src/lib/wallet/ConnectWallet.svelte | 4 ++-- src/lib/wallet/client.ts | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/lib/wallet/ConnectWallet.svelte b/src/lib/wallet/ConnectWallet.svelte index c27749054..b0bf4b76d 100644 --- a/src/lib/wallet/ConnectWallet.svelte +++ b/src/lib/wallet/ConnectWallet.svelte @@ -27,11 +27,11 @@ {:else}
- connectWallet('Injected')}> + connectWallet('injected')}> Connect to your
browser-based wallet
- connectWallet('WalletConnect')}> + connectWallet('walletConnect')}> Scan a QR code
with your mobile wallet
diff --git a/src/lib/wallet/client.ts b/src/lib/wallet/client.ts index 5dcb7f186..c35a75e17 100644 --- a/src/lib/wallet/client.ts +++ b/src/lib/wallet/client.ts @@ -25,7 +25,7 @@ function getRpcUrl({ id }: Chain) { return http && { http }; } -export type ConnectorType = 'Injected' | 'WalletConnect'; +export type ConnectorType = 'injected' | 'walletConnect'; type CommonWallet = { name: string; @@ -88,11 +88,9 @@ function initWalletClient(connectors: Connector[]) { initialized = true; } -function connectWallet(type: ConnectorType, chainId: MaybeNumber) { - return connect({ - chainId, - connector: connectors.find((c) => c.constructor.name === `${type}Connector`)! - }); +function connectWallet(type: ConnectorType, chainId: number | undefined) { + const connector = connectors.find((c) => c.id === type)!; + return connect({ chainId, connector }); } export const wallet = { subscribe, connect: connectWallet, disconnect };