: TransportUSB
}
}
- const status = await this.#connect()
- if (!this.isUnsupported && !this.#isPolling) {
- this.#isPolling = true
- this.#poll().catch(() => { })
+ try {
+ return await this.#connect()
+ } catch (err) {
+ throw new Error('Ledger.connect()', { cause: err })
+ } finally {
+ if (!this.isUnsupported && !this.#isPolling) {
+ this.#isPolling = true
+ this.#poll().catch(() => { })
+ }
}
- return status
}
/**
* Clears Ledger connections from HID and USB interfaces and stops polling for
* connection updates.
*/
- static disconnect (): void {
+ static async disconnect (): Promise<void> {
this.#isPolling = false
- setTimeout(async () => {
- const hidDevices = (await navigator?.hid?.getDevices?.() ?? [])
- .filter(device => device.vendorId === this.ledgerVendorId)
- .map(device => device.close())
- const usbDevices = (await navigator?.usb?.getDevices?.() ?? [])
- .filter(device => device.vendorId === this.ledgerVendorId)
- .map(device => device.close())
- this.#status = 'DISCONNECTED'
+ return new Promise(resolve => {
+ setTimeout(async () => {
+ await (await navigator?.hid?.getDevices?.() ?? [])
+ .filter(device => device.vendorId === this.ledgerVendorId)
+ .map(device => device.close())
+ await (await navigator?.usb?.getDevices?.() ?? [])
+ .filter(device => device.vendorId === this.ledgerVendorId)
+ .map(device => device.close())
+ this.#status = 'DISCONNECTED'
+ resolve()
+ })
})
}