Skip to content

Commit

Permalink
fix: add back error handling in web3auth utils
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Dec 20, 2024
1 parent bec767b commit d147c8f
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions wallets/web3auth/src/extension/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const listenOnce = (
try {
remove = await callback(data);
} catch (error) {
console.error(error);
remove = true;
}

Expand All @@ -57,7 +58,6 @@ export const listenOnce = (
removeEventListener?.call(worker, 'message', listener as any);
}
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
addEventListener?.call(worker, 'message', listener as any);
};
Expand Down Expand Up @@ -126,6 +126,7 @@ export const connectClientAndProvider = async (
chainId: 'other',
rpcTarget: 'other',
displayName: 'other',
blockExplorer: 'other',
ticker: 'other',
tickerName: 'other',
...options.client.chainConfig,
Expand Down Expand Up @@ -170,12 +171,25 @@ export const connectClientAndProvider = async (

let provider = client.connected ? client.provider : null;
if (!client.connected && !dontAttemptLogin) {
const loginHint = options.getLoginHint?.();

provider = await client.connectTo(WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: options.loginProvider,
login_hint: loginHint,
} as OpenloginLoginParams);
try {
const loginHint = options.getLoginHint?.();
provider = await client.connectTo(WALLET_ADAPTERS.OPENLOGIN, {
loginProvider: options.loginProvider,
login_hint: loginHint,
} as OpenloginLoginParams);
} catch (err) {
// Unnecessary error thrown during redirect, so log and ignore it.
if (
usingRedirect &&
err instanceof Error &&
err.message.includes('null')
) {
console.error(err);
} else {
// Rethrow all other relevant errors.
throw err;
}
}
}

if (usingRedirect) {
Expand Down

0 comments on commit d147c8f

Please sign in to comment.