Skip to content

Commit 1a22f6d

Browse files
committed
Add additional handling for single wallet connect from older W3O version, add try to disconnect logic
1 parent d473dfd commit 1a22f6d

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/core/src/disconnect.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,23 @@ async function disconnect(options: DisconnectOptions): Promise<WalletState[]> {
4646

4747
const lastConnectedWallets = getLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET)
4848
if (lastConnectedWallets) {
49-
const labels = JSON.parse(lastConnectedWallets)
49+
try {
50+
const labels = JSON.parse(lastConnectedWallets)
5051

51-
if (Array.isArray(labels) && labels.indexOf(label) >= 0) {
52-
setLocalStore(
53-
STORAGE_KEYS.LAST_CONNECTED_WALLET,
54-
JSON.stringify(labels.filter(walletLabel => walletLabel !== label))
52+
if (Array.isArray(labels) && labels.indexOf(label) >= 0) {
53+
setLocalStore(
54+
STORAGE_KEYS.LAST_CONNECTED_WALLET,
55+
JSON.stringify(labels.filter(walletLabel => walletLabel !== label))
56+
)
57+
}
58+
if (typeof labels === 'string' && labels === label) {
59+
delLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET)
60+
}
61+
} catch (e) {
62+
console.error(
63+
`There was an error disconnecting the last connected wallet from localStorage - Error: ${e}`
5564
)
5665
}
57-
if (typeof labels === 'string' && labels === label) {
58-
delLocalStore(STORAGE_KEYS.LAST_CONNECTED_WALLET)
59-
}
6066
}
6167

6268
return state.get().wallets

packages/core/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ function init(options: InitOptions): OnboardAPI {
290290
) {
291291
connectAllPreviousWallets(lastConnectedWalletsParsed, connect)
292292
}
293+
if (
294+
lastConnectedWalletsParsed &&
295+
typeof lastConnectedWalletsParsed === 'string'
296+
) {
297+
connectAllPreviousWallets([lastConnectedWalletsParsed], connect)
298+
}
293299
} catch (err) {
294300
// Handle for legacy single wallet approach
295301
// Above try will throw syntax error is local storage is not json

0 commit comments

Comments
 (0)