diff --git a/example/package-lock.json b/example/package-lock.json index 19a9815..b3cdb85 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -39,7 +39,7 @@ }, "..": { "name": "@noahsaso/cosmodal", - "version": "0.10.6", + "version": "0.10.8", "license": "ISC", "dependencies": { "@toruslabs/eccrypto": "^2.1.1", diff --git a/package-lock.json b/package-lock.json index 140cb7c..4440bcb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@noahsaso/cosmodal", - "version": "0.10.6", + "version": "0.10.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@noahsaso/cosmodal", - "version": "0.10.6", + "version": "0.10.8", "license": "ISC", "dependencies": { "@toruslabs/eccrypto": "^2.1.1", diff --git a/package.json b/package.json index 7e165dd..4813b0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@noahsaso/cosmodal", - "version": "0.10.6", + "version": "0.10.8", "repository": { "type": "git", "url": "git+https://github.com/NoahSaso/cosmodal.git" diff --git a/src/wallets/web3auth/utils.ts b/src/wallets/web3auth/utils.ts index 84758e7..08f490e 100644 --- a/src/wallets/web3auth/utils.ts +++ b/src/wallets/web3auth/utils.ts @@ -4,6 +4,7 @@ import eccrypto, { Ecies } from "@toruslabs/eccrypto" import { LOGIN_PROVIDER_TYPE, UX_MODE } from "@toruslabs/openlogin" import { isMobile } from "@walletconnect/utils" import { + ADAPTER_STATUS, CHAIN_NAMESPACES, SafeEventEmitterProvider, WALLET_ADAPTERS, @@ -132,7 +133,8 @@ export const connectClientAndProvider = async ( // If using redirect method while trying to login, set localStorage key // indicating that we should try to reconnect to this wallet after the // redirect on library init. - if (uxMode === UX_MODE.REDIRECT && !dontAttemptLogin) { + const usingRedirect = uxMode === UX_MODE.REDIRECT && !dontAttemptLogin + if (usingRedirect) { localStorage.setItem(WEB3AUTH_REDIRECT_AUTO_CONNECT_KEY, walletType) } @@ -159,9 +161,20 @@ export const connectClientAndProvider = async ( loginProvider, })) - // On successful connection, remove the localStorage key indicating that we - // should try to reconnect to this wallet after the redirect on library init. - localStorage.removeItem(WEB3AUTH_REDIRECT_AUTO_CONNECT_KEY) + if (usingRedirect) { + if (client.status === ADAPTER_STATUS.CONNECTED) { + // On successful connection from a redirect, remove the localStorage key + // so we do not attempt to auto connect on the next page load. + localStorage.removeItem(WEB3AUTH_REDIRECT_AUTO_CONNECT_KEY) + } else { + // If not yet connected but redirecting, hang to give the page time to + // redirect without throwing any errors. After 30 seconds, throw a + // timeout error because it should definitely have redirected by then. + await new Promise((_, reject) => + setTimeout(() => reject(new Error("Redirect timed out.")), 30000) + ) + } + } return { client,