File tree 1 file changed +18
-10
lines changed
wormhole-connect/src/utils/wallet
1 file changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -135,17 +135,25 @@ export const connectLastUsedWallet = async (
135
135
chain : Chain ,
136
136
dispatch : Dispatch < any > ,
137
137
) => {
138
+ const localStorageKey = `wormhole-connect:wallet:${ chainConfig . context } ` ;
138
139
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 ;
149
157
}
150
158
}
151
159
} ;
You can’t perform that action at this time.
0 commit comments