Skip to content

Commit

Permalink
Improve toasts, log caught error, during switch account
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Apr 25, 2024
1 parent 2c85c04 commit fe0d150
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/lib/hooks/useAccountSwitcher.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {useCallback} from 'react'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {useAnalytics} from '#/lib/analytics/analytics'
import {logger} from '#/logger'
import {isWeb} from '#/platform/detection'
import {SessionAccount, useSessionApi} from '#/state/session'
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
import * as Toast from '#/view/com/util/Toast'
import {LogEvents} from '../statsig/statsig'

export function useAccountSwitcher() {
const {_} = useLingui()
const {track} = useAnalytics()
const {selectAccount, clearCurrentAccount} = useSessionApi()
const {requestSwitchToAccount} = useLoggedOutViewControls()
Expand All @@ -31,21 +35,26 @@ export function useAccountSwitcher() {
}
await selectAccount(account, logContext)
setTimeout(() => {
Toast.show(`Signed in as @${account.handle}`)
Toast.show(_(msg`Signed in as @${account.handle}`))
}, 100)
} else {
requestSwitchToAccount({requestedAccount: account.did})
Toast.show(
`Please sign in as @${account.handle}`,
_(msg`Please sign in as @${account.handle}`),
'circle-exclamation',
)
}
} catch (e) {
Toast.show('Sorry! We need you to enter your password.')
} catch (e: any) {
logger.error(`switch account: selectAccount failed`, {
message: e.message,
})
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}
Expand Down

0 comments on commit fe0d150

Please sign in to comment.