Skip to content

Commit

Permalink
Navigate directly to ble/usb Ledger screen
Browse files Browse the repository at this point in the history
  • Loading branch information
lubej committed Aug 16, 2023
1 parent 41643ca commit 44818d5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/app/pages/OpenWalletPage/Features/FromLedger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Button } from 'grommet/es6/components/Button'
import { Text } from 'grommet/es6/components/Text'
import { canAccessBle, canAccessNavigatorUsb } from '../../../../lib/ledger'
import { useTranslation } from 'react-i18next'
import { useNavigate } from 'react-router-dom'

type SelectOpenMethodProps = {
webExtensionLedgerAccess?: () => void
Expand All @@ -15,15 +16,25 @@ export function FromLedger({ webExtensionLedgerAccess }: SelectOpenMethodProps)
const { t } = useTranslation()
const [supportsUsbLedger, setSupportsUsbLedger] = React.useState<boolean | undefined>(true)
const [supportsBleLedger, setSupportsBleLedger] = React.useState<boolean | undefined>(true)
const navigate = useNavigate()

useEffect(() => {
async function getLedgerSupport() {
setSupportsUsbLedger(await canAccessNavigatorUsb())
setSupportsBleLedger(await canAccessBle())
const usbLedgerSupported = await canAccessNavigatorUsb()
const bleLedgerSupported = await canAccessBle()

if (usbLedgerSupported && !bleLedgerSupported) {
navigate('usb')
} else if (bleLedgerSupported && !usbLedgerSupported) {
navigate('ble')
}

setSupportsUsbLedger(usbLedgerSupported)
setSupportsBleLedger(bleLedgerSupported)
}

getLedgerSupport()
}, [])
}, [navigate])

return (
<Box
Expand Down

0 comments on commit 44818d5

Please sign in to comment.