Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lift default transport detection to wallet logic
- Loading branch information
1 parent
a654c31
commit 531e7c4
Showing
4 changed files
with
46 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {isWindows, isOpera} from 'react-device-detect' | ||
|
||
import LedgerTransportWebUsb from '@ledgerhq/hw-transport-webusb' | ||
import LedgerTransportWebHid from '@ledgerhq/hw-transport-webhid' | ||
import {LedgerTransportType} from '../types' | ||
|
||
const isWebUsbSupported = async (): Promise<boolean> => { | ||
const isSupported = await LedgerTransportWebUsb.isSupported() | ||
return isSupported && !isWindows && !isOpera | ||
} | ||
|
||
const isWebHidSupported = async (): Promise<boolean> => { | ||
// On Opera the device-selection pop-up appears but there's no apparent way to | ||
// select the device, resulting in an "Operation rejected by user" error | ||
const isSupported = await LedgerTransportWebHid.isSupported() | ||
return isSupported && !isOpera | ||
} | ||
|
||
const getDefaultTransport = async (): Promise<LedgerTransportType> => { | ||
const supportWebHid = await isWebHidSupported() | ||
const supportWebUsb = await isWebUsbSupported() | ||
|
||
if (supportWebHid) { | ||
return LedgerTransportType.WEB_HID | ||
} else if (supportWebUsb) { | ||
return LedgerTransportType.WEB_USB | ||
} else { | ||
return LedgerTransportType.U2F | ||
} | ||
} | ||
|
||
export {getDefaultTransport} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters