Skip to content

Commit

Permalink
After granting usb access to ext, navigate next popup to ledger import
Browse files Browse the repository at this point in the history
Improves UX after ConnectDevice popup closes and user has to re-open the normal
popup to continue the flow.
  • Loading branch information
lukaw3d committed Jan 24, 2025
1 parent 517481e commit dd89392
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions extension/src/ExtLedgerAccessPopup/ExtLedgerAccessPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function ExtLedgerAccessPopup() {
const device = await requestDevice()
if (device) {
setConnection('connected')
// Used to redirect after reopening wallet
window.localStorage.setItem('oasis_wallet_granted_usb_ledger_timestamp', Date.now().toString())
setTimeout(() => window.close(), 5_000)
}
} catch {
Expand Down
12 changes: 11 additions & 1 deletion src/app/useRouteRedirects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ export const useRouteRedirects = () => {
const navigate = useNavigate()

useEffect(() => {
if (address) {
const hasRecentlyGrantedUsbAccess =
Date.now() - parseInt(window.localStorage.getItem('oasis_wallet_granted_usb_ledger_timestamp') ?? '0') <
5 * 60 * 1000

if (hasRecentlyGrantedUsbAccess) {
// When we implement auto-locking, this won't correctly redirect if wallet
// gets locked within 5min (useEffect called with address=undefined before unlocking).
navigate(`/open-wallet/ledger`)
// Delay is needed as workaround for React.StrictMode.
setTimeout(() => window.localStorage.removeItem('oasis_wallet_granted_usb_ledger_timestamp'), 1000)
} else if (address) {
navigate(`/account/${address}`)
}
}, [address, navigate])
Expand Down

0 comments on commit dd89392

Please sign in to comment.