From aa292083d685b6a0ddcfa7ef082c6b3fd6b1fcd2 Mon Sep 17 00:00:00 2001 From: Todd Kao Date: Mon, 13 Jan 2025 15:17:57 -0500 Subject: [PATCH] Fix showing SetAddressModal if chain id isn't supported by the wallet --- .../widget/src/hooks/useAutoSetAddress.ts | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/packages/widget/src/hooks/useAutoSetAddress.ts b/packages/widget/src/hooks/useAutoSetAddress.ts index 76f80fd2..6da81596 100644 --- a/packages/widget/src/hooks/useAutoSetAddress.ts +++ b/packages/widget/src/hooks/useAutoSetAddress.ts @@ -82,18 +82,18 @@ export const useAutoSetAddress = () => { if (chainAddresses[index]?.address) return; switch (chainType) { case ChainType.Cosmos: { - const wallets = createCosmosWallets(chainID); - const wallet = wallets.find((w) => w.walletName === sourceWallet.cosmos?.walletName); - if (!wallet) { - if (!openModal) return; - NiceModal.show(Modals.SetAddressModal, { - signRequired: isSignRequired, - chainId: chainID, - chainAddressIndex: index, - }); - return; - } try { + const wallets = createCosmosWallets(chainID); + const wallet = wallets.find((w) => w.walletName === sourceWallet.cosmos?.walletName); + if (!wallet) { + if (!openModal) return; + NiceModal.show(Modals.SetAddressModal, { + signRequired: isSignRequired, + chainId: chainID, + chainAddressIndex: index, + }); + return; + } const address = await wallet?.getAddress?.({ signRequired: isSignRequired, }); @@ -116,22 +116,27 @@ export const useAutoSetAddress = () => { }, })); } catch (_) { - return; - } - break; - } - case ChainType.SVM: { - const wallets = createSolanaWallets(); - const wallet = wallets.find((w) => w.walletName === sourceWallet.svm?.walletName); - if (!wallet) { if (!openModal) return; NiceModal.show(Modals.SetAddressModal, { signRequired: isSignRequired, chainId: chainID, + chainAddressIndex: index, }); - return; } + break; + } + case ChainType.SVM: { try { + const wallets = createSolanaWallets(); + const wallet = wallets.find((w) => w.walletName === sourceWallet.svm?.walletName); + if (!wallet) { + if (!openModal) return; + NiceModal.show(Modals.SetAddressModal, { + signRequired: isSignRequired, + chainId: chainID, + }); + return; + } const address = await wallet?.getAddress?.({ signRequired: isSignRequired, }); @@ -154,23 +159,28 @@ export const useAutoSetAddress = () => { }, })); } catch (_) { - return; - } - - break; - } - case ChainType.EVM: { - const wallets = createEvmWallets(chainID); - const wallet = wallets.find((w) => w.walletName === sourceWallet.evm?.walletName); - if (!wallet) { if (!openModal) return; NiceModal.show(Modals.SetAddressModal, { signRequired: isSignRequired, chainId: chainID, + chainAddressIndex: index, }); - return; } + + break; + } + case ChainType.EVM: { try { + const wallets = createEvmWallets(chainID); + const wallet = wallets.find((w) => w.walletName === sourceWallet.evm?.walletName); + if (!wallet) { + if (!openModal) return; + NiceModal.show(Modals.SetAddressModal, { + signRequired: isSignRequired, + chainId: chainID, + }); + return; + } const address = await wallet?.getAddress?.({ signRequired: isSignRequired, }); @@ -193,7 +203,12 @@ export const useAutoSetAddress = () => { }, })); } catch (_) { - return; + if (!openModal) return; + NiceModal.show(Modals.SetAddressModal, { + signRequired: isSignRequired, + chainId: chainID, + chainAddressIndex: index, + }); } break; }