import { ledgerUSBVendorId } from '@ledgerhq/devices'
import { default as TransportBLE } from '@ledgerhq/hw-transport-web-ble'
-import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb'
import { default as TransportHID } from '@ledgerhq/hw-transport-webhid'
+import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb'
import { DeviceStatus, LedgerAccountResponse, LedgerResponse, LedgerSignResponse, LedgerVersionResponse } from '#types'
import { Account } from '../account'
import { Block } from '../block'
if (version.status !== 'OK') {
this.#status = 'DISCONNECTED'
} else if (version.name === 'Nano') {
- const { status } = await Ledger.account()
+ const { status } = await this.account()
if (status === 'OK') {
this.#status = 'CONNECTED'
} else if (status === 'SECURITY_STATUS_NOT_SATISFIED') {
return this.#status
}
+ /**
+ *
+ */
+ static disconnect (): void {
+ setTimeout(async () => {
+ const hidDevices = await globalThis.navigator.hid.getDevices()
+ for (const device of hidDevices) {
+ if (device.vendorId === this.UsbVendorId) {
+ device.forget()
+ }
+ }
+ const bleDevices = await globalThis.navigator.bluetooth.getDevices()
+ for (const device of bleDevices) {
+ TransportBLE.disconnect(device.id)
+ }
+ const usbDevices = await globalThis.navigator.usb.getDevices()
+ for (const device of usbDevices) {
+ if (device.vendorId === this.UsbVendorId) {
+ device.forget()
+ }
+ }
+ })
+ }
+
/**
* Sign a block with the Ledger device.
*
try {
if (wallet.type === 'Ledger') {
const { Ledger } = await import('./ledger')
- setTimeout(async () => {
- const devices = await globalThis.navigator.usb.getDevices()
- for (const device of devices) {
- if (device.vendorId === Ledger.UsbVendorId) {
- device.forget()
- }
- }
- })
+ Ledger.disconnect()
} else {
await vault.request({
action: 'lock'