From 44190057a1f690311cdb9eb68c5e44a2ff9f9e44 Mon Sep 17 00:00:00 2001 From: AuroraHuang22 Date: Wed, 5 Feb 2025 13:58:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Avoid=20forcing=20signer=20stora?= =?UTF-8?q?ge=20on=20every=20session=20restore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stores/wallet.ts | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/stores/wallet.ts b/stores/wallet.ts index ba732488..24b121d8 100644 --- a/stores/wallet.ts +++ b/stores/wallet.ts @@ -125,26 +125,34 @@ export const useWalletStore = defineStore('wallet', () => { } const session = connector.value.restoreSession() if (session) { - try { - const connection = await connector.value.initIfNecessary() - if (connection) { await initWallet(connection) } - } catch (e) { - console.error(e) - } + handleConnection({ accounts: session.accounts, method: session.method }) } } } - function handleConnection (connection: LikeCoinWalletConnectorConnectionResult) { - if (!connection) { return } - accounts.value = connection.accounts - signer.value = connection.offlineSigner as (OfflineAminoSigner & OfflineDirectSigner) - const method = connection.method - useTrackEvent('login', { method }) + function handleConnection (connection: LikeCoinWalletConnectorConnectionResult | { accounts?: any[], offlineSigner?: OfflineAminoSigner & OfflineDirectSigner, method?: string }) { + const accountsValue = connection?.accounts || [] + const signerValue = connection?.offlineSigner || undefined + const methodValue = connection?.method || undefined + + if (accountsValue && accountsValue.length > 0) { + accounts.value = accountsValue + } + if (signerValue) { + signer.value = signerValue as (OfflineAminoSigner & OfflineDirectSigner) + } + if (methodValue) { + useTrackEvent('login', { method: methodValue }) + } + if (window.$crisp) { - const wallet = accounts.value[0]?.address - window.$crisp.push(['set', 'session:data', [[['like_wallet', wallet]]]]) - window.$crisp.push(['set', 'session:data', [[['login_method', method]]]]) + const wallet = accounts.value?.[0]?.address + if (wallet) { + window.$crisp.push(['set', 'session:data', [[['like_wallet', wallet]]]]) + } + if (methodValue) { + window.$crisp.push(['set', 'session:data', [[['login_method', methodValue]]]]) + } } }