From 9cbd01d514d3350f8a5b2e5900bb802b5d841487 Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 21 Jul 2022 11:48:33 +0300 Subject: [PATCH] feat: add wipe command --- .../extensions/watchonly/static/js/index.js | 50 +++++++++++++++++++ .../extensions/watchonly/static/js/utils.js | 1 + .../watchonly/templates/watchonly/index.html | 40 ++++++++++++++- 3 files changed, 90 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/watchonly/static/js/index.js b/lnbits/extensions/watchonly/static/js/index.js index 7e019df2..a4d7eb39 100644 --- a/lnbits/extensions/watchonly/static/js/index.js +++ b/lnbits/extensions/watchonly/static/js/index.js @@ -48,6 +48,7 @@ new Vue({ password: null, authenticated: false, showPasswordDialog: false, + showWipeDialog: false, showConsole: false, showSignedPsbt: false, sendingPsbt: false, @@ -701,6 +702,7 @@ new Vue({ else if (msg[0] == COMMAND_PASSWORD_CLEAR) this.handleLogoutResponse(msg[1]) else if (msg[0] == COMMAND_SEND_PSBT) this.handleSendPsbtResponse(msg[1]) + else if (msg[0] == COMMAND_WIPE) this.handleWipeResponse(msg[1]) else console.log('### handleSerialPortResponse', value) }, updateSerialPortConsole: function (value) { @@ -727,6 +729,19 @@ new Vue({ }) } }, + hwwShowWipeDialog: async function () { + try { + this.hww.showWipeDialog = true + await this.serial.writer.write(COMMAND_WIPE + '\n') + } catch (error) { + this.$q.notify({ + type: 'warning', + message: 'Failed to connect to Hardware Wallet!', + caption: `${error}`, + timeout: 10000 + }) + } + }, hwwLogin: async function () { try { await this.serial.writer.write( @@ -857,6 +872,41 @@ new Vue({ }) } }, + hwwWipe: async function () { + try { + this.hww.showWipeDialog = false + await this.serial.writer.write( + COMMAND_WIPE + ' ' + this.hww.password + '\n' + ) + } catch (error) { + this.$q.notify({ + type: 'warning', + message: 'Failed to ask for help!', + caption: `${error}`, + timeout: 10000 + }) + } finally { + this.hww.password = null + } + }, + handleWipeResponse: function (res = '') { + const wiped = res.trim() === '1' + console.log('### wiped', wiped) + if (wiped) { + this.$q.notify({ + type: 'positive', + message: 'Wallet wiped!', + timeout: 10000 + }) + } else { + this.$q.notify({ + type: 'warning', + message: 'Failed to wipe wallet!', + caption: `${error}`, + timeout: 10000 + }) + } + }, //################### UTXOs ################### scanAllAddresses: async function () { await this.refreshAddresses() diff --git a/lnbits/extensions/watchonly/static/js/utils.js b/lnbits/extensions/watchonly/static/js/utils.js index 69fa1220..b56e78ea 100644 --- a/lnbits/extensions/watchonly/static/js/utils.js +++ b/lnbits/extensions/watchonly/static/js/utils.js @@ -4,6 +4,7 @@ const COMMAND_PASSWORD_CLEAR = '/password-clear' const COMMAND_SEND_PSBT = '/psbt' const COMMAND_SIGN_PSBT = '/sign' const COMMAND_HELP = '/help' +const COMMAND_WIPE = '/wipe' const blockTimeToDate = blockTime => blockTime ? moment(blockTime * 1000).format('LLL') : '' diff --git a/lnbits/extensions/watchonly/templates/watchonly/index.html b/lnbits/extensions/watchonly/templates/watchonly/index.html index a9ea7bce..f3679753 100644 --- a/lnbits/extensions/watchonly/templates/watchonly/index.html +++ b/lnbits/extensions/watchonly/templates/watchonly/index.html @@ -1184,7 +1184,11 @@ > - + Wipe + + + + + This action will remove all data from the Hardware Wallet. Please + create a back-up for the seed! + + Enter new password for Hardware Wallet + + + This action cannot be reversed! + + +
+ Wipe + Cancel +
+
+
+
{% endraw %}