Skip to content

Commit 3423d2c

Browse files
committed
don't throw when user rejects wallet connection
1 parent ace4f80 commit 3423d2c

File tree

1 file changed

+18
-10
lines changed
  • wormhole-connect/src/utils/wallet

1 file changed

+18
-10
lines changed

wormhole-connect/src/utils/wallet/index.ts

+18-10
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,25 @@ export const connectLastUsedWallet = async (
135135
chain: Chain,
136136
dispatch: Dispatch<any>,
137137
) => {
138+
const localStorageKey = `wormhole-connect:wallet:${chainConfig.context}`;
138139
const chainConfig = config.chains[chain!]!;
139-
const lastUsedWallet = localStorage.getItem(
140-
`wormhole-connect:wallet:${chainConfig.context}`,
141-
);
142-
143-
// if the last used wallet is not WalletConnect, try to connect to it
144-
if (lastUsedWallet && lastUsedWallet !== 'WalletConnect') {
145-
const options = await getWalletOptions(chainConfig);
146-
const wallet = options.find((w) => w.name === lastUsedWallet);
147-
if (wallet) {
148-
await connectWallet(type, chain, wallet, dispatch);
140+
const lastUsedWallet = localStorage.getItem(localStorageKey);
141+
142+
try {
143+
// if the last used wallet is not WalletConnect, try to connect to it
144+
if (lastUsedWallet && lastUsedWallet !== 'WalletConnect') {
145+
const options = await getWalletOptions(chainConfig);
146+
const wallet = options.find((w) => w.name === lastUsedWallet);
147+
if (wallet) {
148+
await connectWallet(type, chain, wallet, dispatch);
149+
}
150+
}
151+
} catch (e: any) {
152+
if (e.message && e.message.includes('UserRejectedRequestError')) {
153+
// If user doesn't want to connect to this wallet, remove it from localStorage
154+
localStorage.removeItem(localStorageKey);
155+
} else {
156+
throw e;
149157
}
150158
}
151159
};

0 commit comments

Comments
 (0)