Prep for v2 by catching errors from selectAccount
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import {useCallback} from 'react'
|
import {useCallback} from 'react'
|
||||||
|
import {msg} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {useAnalytics} from '#/lib/analytics/analytics'
|
import {useAnalytics} from '#/lib/analytics/analytics'
|
||||||
|
import {logger} from '#/logger'
|
||||||
import {isWeb} from '#/platform/detection'
|
import {isWeb} from '#/platform/detection'
|
||||||
import {SessionAccount, useSessionApi} from '#/state/session'
|
import {SessionAccount, useSessionApi} from '#/state/session'
|
||||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||||
@@ -8,6 +11,7 @@ import * as Toast from '#/view/com/util/Toast'
|
|||||||
import {LogEvents} from '../statsig/statsig'
|
import {LogEvents} from '../statsig/statsig'
|
||||||
|
|
||||||
export function useAccountSwitcher() {
|
export function useAccountSwitcher() {
|
||||||
|
const {_} = useLingui()
|
||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const {selectAccount, clearCurrentAccount} = useSessionApi()
|
const {selectAccount, clearCurrentAccount} = useSessionApi()
|
||||||
const {requestSwitchToAccount} = useLoggedOutViewControls()
|
const {requestSwitchToAccount} = useLoggedOutViewControls()
|
||||||
@@ -31,21 +35,26 @@ export function useAccountSwitcher() {
|
|||||||
}
|
}
|
||||||
await selectAccount(account, logContext)
|
await selectAccount(account, logContext)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Toast.show(`Signed in as @${account.handle}`)
|
Toast.show(_(msg`Signed in as @${account.handle}`))
|
||||||
}, 100)
|
}, 100)
|
||||||
} else {
|
} else {
|
||||||
requestSwitchToAccount({requestedAccount: account.did})
|
requestSwitchToAccount({requestedAccount: account.did})
|
||||||
Toast.show(
|
Toast.show(
|
||||||
`Please sign in as @${account.handle}`,
|
_(msg`Please sign in as @${account.handle}`),
|
||||||
'circle-exclamation',
|
'circle-exclamation',
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
Toast.show('Sorry! We need you to enter your password.')
|
logger.error(`switch account: selectAccount failed`, {
|
||||||
|
message: e.message,
|
||||||
|
})
|
||||||
clearCurrentAccount() // back user out to login
|
clearCurrentAccount() // back user out to login
|
||||||
|
setTimeout(() => {
|
||||||
|
Toast.show(_(msg`Sorry! We need you to enter your password.`))
|
||||||
|
}, 100)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[track, clearCurrentAccount, selectAccount, requestSwitchToAccount],
|
[_, track, clearCurrentAccount, selectAccount, requestSwitchToAccount],
|
||||||
)
|
)
|
||||||
|
|
||||||
return {onPressSwitchAccount}
|
return {onPressSwitchAccount}
|
||||||
|
|||||||
Reference in New Issue
Block a user