feat: wait for HWW to authenticate, then open dialog

This commit is contained in:
Vlad Stan 2022-07-28 17:15:04 +03:00
parent 1089be017b
commit 5414e3e772
3 changed files with 25 additions and 12 deletions

View file

@ -88,7 +88,8 @@ async function payment(path) {
} }
if (!this.serialSignerRef.isAuthenticated()) { if (!this.serialSignerRef.isAuthenticated()) {
await this.serialSignerRef.hwwShowPasswordDialog() await this.serialSignerRef.hwwShowPasswordDialog()
return const authenticated = await this.serialSignerRef.isAuthenticating()
if (!authenticated) return
} }
await this.createPsbt() await this.createPsbt()

View file

@ -158,7 +158,9 @@
<q-form @submit="hwwSignPsbt" class="q-gutter-md"> <q-form @submit="hwwSignPsbt" class="q-gutter-md">
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<div class="col-12"> <div class="col-12">
<q-badge class="text-subtitle2" color="yellow" text-color="black">
<span>Check data on the display of the hardware device.</span> <span>Check data on the display of the hardware device.</span>
</q-badge>
</div> </div>
</div> </div>
<div v-if="tx"> <div v-if="tx">
@ -167,6 +169,13 @@
<span class="text-subtitle2" <span class="text-subtitle2"
>Output {{hww.confirm.outputIndex}}</span >Output {{hww.confirm.outputIndex}}</span
> >
<q-badge
v-if="tx.outputs[hww.confirm.outputIndex].branch_index === 1"
color="orange"
text-color="black"
>
<span>change</span>
</q-badge>
</div> </div>
</div> </div>
<div v-if="!hww.confirm.showFee" class="row q-mt-lg"> <div v-if="!hww.confirm.showFee" class="row q-mt-lg">
@ -207,7 +216,7 @@
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<div class="col-6"> <div class="col-6">
<q-btn <q-btn
v-if="hww.confirm.confirmed" v-if="hww.confirm.showFee"
unelevated unelevated
color="green" color="green"
:disable="!selectedPort" :disable="!selectedPort"
@ -224,7 +233,7 @@
color="secondary" color="secondary"
label="Next" label="Next"
class="float-left" class="float-left"
v-if="!hww.confirm.confirmed" v-if="!hww.confirm.showFee"
@click="hwwConfirmNext" @click="hwwConfirmNext"
> >
</q-btn> </q-btn>

View file

@ -29,10 +29,10 @@ async function serialSigner(path) {
sendingPsbt: false, sendingPsbt: false,
signingPsbt: false, signingPsbt: false,
psbtSentResolve: null, psbtSentResolve: null,
loginResolve: null,
confirm: { confirm: {
outputIndex: 0, outputIndex: 0,
showFee: false, showFee: false
confirmed: false
} }
}, },
tx: null, // todo: move to hww tx: null, // todo: move to hww
@ -122,6 +122,13 @@ async function serialSigner(path) {
isAuthenticated: function () { isAuthenticated: function () {
return this.hww.authenticated return this.hww.authenticated
}, },
isAuthenticating: function () {
if (this.isAuthenticated()) return false
return new Promise(resolve => {
this.loginResolve = resolve
})
},
isSendingPsbt: async function () { isSendingPsbt: async function () {
if (!this.hww.sendingPsbt) return false if (!this.hww.sendingPsbt) return false
return new Promise(resolve => { return new Promise(resolve => {
@ -229,10 +236,6 @@ async function serialSigner(path) {
} }
}, },
hwwConfirmNext: async function () { hwwConfirmNext: async function () {
if (this.hww.confirm.showFee === true) {
this.hww.confirm.confirmed = true
return
}
this.hww.confirm.outputIndex += 1 this.hww.confirm.outputIndex += 1
if (this.hww.confirm.outputIndex >= this.tx.outputs.length) { if (this.hww.confirm.outputIndex >= this.tx.outputs.length) {
this.hww.confirm.showFee = true this.hww.confirm.showFee = true
@ -271,6 +274,7 @@ async function serialSigner(path) {
}, },
handleLoginResponse: function (res = '') { handleLoginResponse: function (res = '') {
this.hww.authenticated = res.trim() === '1' this.hww.authenticated = res.trim() === '1'
this.loginResolve(this.hww.authenticated)
if (this.hww.authenticated) { if (this.hww.authenticated) {
this.$q.notify({ this.$q.notify({
type: 'positive', type: 'positive',
@ -333,8 +337,7 @@ async function serialSigner(path) {
this.hww.showConfirmationDialog = true this.hww.showConfirmationDialog = true
this.hww.confirm = { this.hww.confirm = {
outputIndex: 0, outputIndex: 0,
showFee: false, showFee: false
confirmed: false
} }
this.hww.sendingPsbt = false this.hww.sendingPsbt = false
this.psbtSentResolve() this.psbtSentResolve()