diff --git a/packages/kit/src/background/providers/ProviderApiWalletConnect.ts b/packages/kit/src/background/providers/ProviderApiWalletConnect.ts index 3f9aa3669db..fe9ec60b7c8 100644 --- a/packages/kit/src/background/providers/ProviderApiWalletConnect.ts +++ b/packages/kit/src/background/providers/ProviderApiWalletConnect.ts @@ -109,6 +109,10 @@ class ProviderApiWalletConnect extends WalletConnectClientForWallet { }); const chainId = await this.getChainIdInteger(connector); + // walletConnect approve empty accounts is not allowed + if (!result || !result.length) { + throw new Error('WalletConnect Session error: accounts is empty'); + } return { chainId, accounts: result }; } diff --git a/packages/kit/src/views/DappModals/Connection.tsx b/packages/kit/src/views/DappModals/Connection.tsx index 1cd80f0a921..2a9fc3ac171 100644 --- a/packages/kit/src/views/DappModals/Connection.tsx +++ b/packages/kit/src/views/DappModals/Connection.tsx @@ -67,6 +67,8 @@ type RouteProps = RouteProp< DappConnectionModalRoutes.ConnectionModal >; +let lastWalletConnectUri: string | undefined = ''; + /* Connection Modal are use to accept user with permission to dapp */ const defaultSourceInfo = Object.freeze({}) as IDappSourceInfo; const Connection = () => { @@ -90,6 +92,7 @@ const Connection = () => { }, [origin]); const route = useRoute(); const walletConnectUri = route?.params?.walletConnectUri; + lastWalletConnectUri = walletConnectUri; const isWalletConnectPreloading = Boolean(walletConnectUri); const [walletConnectError, setWalletConnectError] = useState(''); const closeModal = useModalClose(); @@ -115,6 +118,13 @@ const Connection = () => { isWalletConnectPreloading, ]); + useEffect( + () => () => { + isClosedDone.current = true; + }, + [], + ); + useEffect(() => { if (walletConnectUri) { backgroundApiProxy.walletConnect @@ -122,8 +132,10 @@ const Connection = () => { uri: walletConnectUri || '', }) .then(() => { - isClosedDone.current = true; - closeModal(); + if (!isClosedDone.current && lastWalletConnectUri) { + closeModal(); + isClosedDone.current = true; + } dispatch(refreshConnectedSites()); }) .catch((error) => {