diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/hooks/useAccountSwitcher.ts | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/lib/hooks/useAccountSwitcher.ts b/src/lib/hooks/useAccountSwitcher.ts index d4e026958..de50e5336 100644 --- a/src/lib/hooks/useAccountSwitcher.ts +++ b/src/lib/hooks/useAccountSwitcher.ts @@ -12,7 +12,7 @@ import {logEvent} from '../statsig/statsig' import {LogEvents} from '../statsig/statsig' export function useAccountSwitcher() { - const [isSwitchingAccounts, setIsSwitchingAccounts] = useState(false) + const [pendingDid, setPendingDid] = useState<string | null>(null) const {_} = useLingui() const {track} = useAnalytics() const {initSession, clearCurrentAccount} = useSessionApi() @@ -24,9 +24,12 @@ export function useAccountSwitcher() { logContext: LogEvents['account:loggedIn']['logContext'], ) => { track('Settings:SwitchAccountButtonClicked') - + if (pendingDid) { + // The session API isn't resilient to race conditions so let's just ignore this. + return + } try { - setIsSwitchingAccounts(true) + setPendingDid(account.did) if (account.accessJwt) { if (isWeb) { // We're switching accounts, which remounts the entire app. @@ -57,11 +60,18 @@ export function useAccountSwitcher() { Toast.show(_(msg`Sorry! We need you to enter your password.`)) }, 100) } finally { - setIsSwitchingAccounts(false) + setPendingDid(null) } }, - [_, track, clearCurrentAccount, initSession, requestSwitchToAccount], + [ + _, + track, + clearCurrentAccount, + initSession, + requestSwitchToAccount, + pendingDid, + ], ) - return {onPressSwitchAccount, isSwitchingAccounts} + return {onPressSwitchAccount, pendingDid} } |