From 05a1f5653b3bacda4a283f824e48c6407b89aabc Mon Sep 17 00:00:00 2001 From: Carson Aberle Date: Thu, 29 Jun 2023 21:27:03 -0700 Subject: [PATCH] Fixed issue with wallet button menu showing and check if the offline signer returned exists to show an error --- .changeset/proud-jobs-pump.md | 5 +++++ .../WalletSelectModal/WalletSelectModal.tsx | 3 ++- .../react/src/lib/provider/SeiWalletProvider.tsx | 13 ++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .changeset/proud-jobs-pump.md diff --git a/.changeset/proud-jobs-pump.md b/.changeset/proud-jobs-pump.md new file mode 100644 index 00000000..0df4c209 --- /dev/null +++ b/.changeset/proud-jobs-pump.md @@ -0,0 +1,5 @@ +--- +'@sei-js/react': patch +--- + +Fixed an issue when wallets don't connect and the UI hangs, fixed an issue where the WalletConnectButton menu shows after selecting a wallet diff --git a/packages/react/src/lib/components/WalletSelectModal/WalletSelectModal.tsx b/packages/react/src/lib/components/WalletSelectModal/WalletSelectModal.tsx index 39badcf3..d85e5f0a 100644 --- a/packages/react/src/lib/components/WalletSelectModal/WalletSelectModal.tsx +++ b/packages/react/src/lib/components/WalletSelectModal/WalletSelectModal.tsx @@ -20,7 +20,8 @@ const WalletSelectModal = ({ wallets: inputWallets }: WalletSelectModalProps) => } }, [connectedWallet, connectionError]); - const closeModal = () => { + const closeModal = (e) => { + e.stopPropagation(); setConnectionError(undefined); setShowConnectModal(false); }; diff --git a/packages/react/src/lib/provider/SeiWalletProvider.tsx b/packages/react/src/lib/provider/SeiWalletProvider.tsx index fbfcd5a7..8bd0ec67 100644 --- a/packages/react/src/lib/provider/SeiWalletProvider.tsx +++ b/packages/react/src/lib/provider/SeiWalletProvider.tsx @@ -42,18 +42,25 @@ const SeiWalletProvider = ({ children, chainConfiguration, wallets, autoConnect return; } - await targetWallet.connect(chainConfiguration.chainId); const fetchedOfflineSigner = await targetWallet.getOfflineSigner(chainConfiguration.chainId); + + if (!fetchedOfflineSigner) { + setConnectionError(targetWallet.walletInfo.windowKey); + return; + } const fetchedAccounts = await targetWallet.getAccounts(chainConfiguration.chainId); - if (fetchedAccounts.length > 0 && fetchedOfflineSigner) { + if (fetchedAccounts.length === 0) { + setConnectionError(targetWallet.walletInfo.windowKey); + return; + } else { setShowConnectModal(false); setOfflineSigner(fetchedOfflineSigner); setAccounts(fetchedAccounts); setConnectedWallet(targetWallet); } } catch (e) { - console.log('Error connecting to wallet', e); + console.error('Error connecting to wallet', e); setConnectionError(targetWallet.walletInfo.windowKey); return; }