diff --git a/src/keepkeyManager.ts b/src/keepkeyManager.ts index b8d86c9..4efddd2 100644 --- a/src/keepkeyManager.ts +++ b/src/keepkeyManager.ts @@ -78,18 +78,22 @@ export default class KeepKeyManager { public async remove (deviceID: string): Promise { if (!this.keepkeys[deviceID]) return - const keepkey = this.get(deviceID) - await keepkey.clearSession() - await keepkey.device.disconnect() + + try { + const keepkey = this.get(deviceID) + await keepkey.clearSession() + await keepkey.device.disconnect() + } catch (e) { + console.error(e) + } + delete this.keepkeys[deviceID] } public async removeAll (): Promise { - Object.values(this.keepkeys).forEach(async (keepkey) => { - await keepkey.clearSession() - await keepkey.device.disconnect() - }) - this.keepkeys = {} + return Promise.all(Object.keys(this.keepkeys).map((deviceId) => + this.remove(deviceId))) + .then(() => undefined) // don't return an array } public decorateEvents (deviceID: string, events: eventemitter2.EventEmitter2): void {