]> git.codecow.com Git - libnemo.git/commitdiff
Move Ledger disconnect function out of wallet lock method and into Ledger class....
authorChris Duncan <chris@zoso.dev>
Sun, 14 Sep 2025 20:41:51 +0000 (13:41 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 14 Sep 2025 20:41:51 +0000 (13:41 -0700)
src/lib/wallet/ledger.ts
src/lib/wallet/lock.ts

index af7b93f864907620fb3932161b90128aaca3400d..3b7e3ea817219145ca333a575d56316d6afb2528 100644 (file)
@@ -3,8 +3,8 @@
 
 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'
@@ -135,7 +135,7 @@ export class Ledger {
                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') {
@@ -149,6 +149,30 @@ export class Ledger {
                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.
        *
index 7d0922006b387f4f3e3e145642ae57bf70d3c1f9..a65773fc20aacc2fbc824e62eb0632fb17f4b959 100644 (file)
@@ -8,14 +8,7 @@ export async function _lock (wallet: Wallet, vault: Vault): Promise<void> {
        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'