feat: add wipe command

This commit is contained in:
Vlad Stan 2022-07-21 11:48:33 +03:00
parent 5f7537f600
commit 9cbd01d514
3 changed files with 90 additions and 1 deletions

View file

@ -48,6 +48,7 @@ new Vue({
password: null, password: null,
authenticated: false, authenticated: false,
showPasswordDialog: false, showPasswordDialog: false,
showWipeDialog: false,
showConsole: false, showConsole: false,
showSignedPsbt: false, showSignedPsbt: false,
sendingPsbt: false, sendingPsbt: false,
@ -701,6 +702,7 @@ new Vue({
else if (msg[0] == COMMAND_PASSWORD_CLEAR) else if (msg[0] == COMMAND_PASSWORD_CLEAR)
this.handleLogoutResponse(msg[1]) this.handleLogoutResponse(msg[1])
else if (msg[0] == COMMAND_SEND_PSBT) this.handleSendPsbtResponse(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) else console.log('### handleSerialPortResponse', value)
}, },
updateSerialPortConsole: function (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 () { hwwLogin: async function () {
try { try {
await this.serial.writer.write( 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 ################### //################### UTXOs ###################
scanAllAddresses: async function () { scanAllAddresses: async function () {
await this.refreshAddresses() await this.refreshAddresses()

View file

@ -4,6 +4,7 @@ const COMMAND_PASSWORD_CLEAR = '/password-clear'
const COMMAND_SEND_PSBT = '/psbt' const COMMAND_SEND_PSBT = '/psbt'
const COMMAND_SIGN_PSBT = '/sign' const COMMAND_SIGN_PSBT = '/sign'
const COMMAND_HELP = '/help' const COMMAND_HELP = '/help'
const COMMAND_WIPE = '/wipe'
const blockTimeToDate = blockTime => const blockTimeToDate = blockTime =>
blockTime ? moment(blockTime * 1000).format('LLL') : '' blockTime ? moment(blockTime * 1000).format('LLL') : ''

View file

@ -1184,7 +1184,11 @@
> >
</q-item-section> </q-item-section>
</q-item> </q-item>
<q-item clickable v-close-popup> <q-item
@click="hwwShowWipeDialog()"
clickable
v-close-popup
>
<q-item-section> <q-item-section>
<q-item-label>Wipe</q-item-label> <q-item-label>Wipe</q-item-label>
<q-item-label caption <q-item-label caption
@ -1564,6 +1568,40 @@
</q-form> </q-form>
</q-card> </q-card>
</q-dialog> </q-dialog>
<q-dialog v-model="hww.showWipeDialog" position="top">
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
<q-form @submit="hwwWipe" class="q-gutter-md">
<q-badge color="pink" text-color="black">
This action will remove all data from the Hardware Wallet. Please
create a back-up for the seed!
</q-badge>
<span>Enter new password for Hardware Wallet</span>
<q-input
filled
dense
v-model.trim="hww.password"
type="password"
label="Password"
></q-input>
<q-badge color="pink" text-color="black">
This action cannot be reversed!
</q-badge>
<div class="row q-mt-lg">
<q-btn
unelevated
color="primary"
:disable="!serial.selectedPort"
type="submit"
>Wipe</q-btn
>
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
>Cancel</q-btn
>
</div>
</q-form>
</q-card>
</q-dialog>
{% endraw %} {% endraw %}
</div> </div>