diff --git a/lnbits/extensions/watchonly/static/components/payment/payment.html b/lnbits/extensions/watchonly/static/components/payment/payment.html index 2af39c6e..6a1bf36b 100644 --- a/lnbits/extensions/watchonly/static/components/payment/payment.html +++ b/lnbits/extensions/watchonly/static/components/payment/payment.html @@ -186,8 +186,13 @@ +
- + + + + + +
+
+ Check transaction on your hardware device +
+
+ +
+ + + + + Cancel +
+
+
+
+ diff --git a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js index abd92ffb..944c092b 100644 --- a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js +++ b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js @@ -24,11 +24,13 @@ async function serialSigner(path) { showPasswordDialog: false, showWipeDialog: false, showRestoreDialog: false, + showConfirmationDialog: false, showConsole: false, showSignedPsbt: false, sendingPsbt: false, signingPsbt: false, - psbtSent: false + psbtSent: false, + psbtSentResolve: null } } }, @@ -113,6 +115,12 @@ async function serialSigner(path) { isAuthenticated: function () { return this.hww.authenticated }, + isSendingPsbt: async function () { + if (!this.hww.sendingPsbt) return false + return new Promise(resolve => { + this.psbtSentResolve = resolve + }) + }, checkSerialPortSupported: function () { if (!navigator.serial) { @@ -281,6 +289,7 @@ async function serialSigner(path) { timeout: 5000 }) } catch (error) { + this.hww.sendingPsbt = false this.$q.notify({ type: 'warning', message: 'Failed to send data to serial port!', @@ -292,9 +301,11 @@ async function serialSigner(path) { handleSendPsbtResponse: function (res = '') { this.hww.psbtSent = true this.hww.sendingPsbt = false + this.psbtSentResolve() }, hwwSignPsbt: async function () { try { + this.hww.psbtSent = false this.hww.signingPsbt = true await this.writer.write(COMMAND_SIGN_PSBT + '\n') this.$q.notify({ @@ -407,6 +418,9 @@ async function serialSigner(path) { this.hww.password = null this.hww.showPassword = false } + }, + updateSignedPsbt: async function (value) { + this.$emit('signed:psbt', value) } }, created: async function () {} diff --git a/lnbits/extensions/watchonly/static/js/index.js b/lnbits/extensions/watchonly/static/js/index.js index a01e0e10..c8ca588c 100644 --- a/lnbits/extensions/watchonly/static/js/index.js +++ b/lnbits/extensions/watchonly/static/js/index.js @@ -84,7 +84,9 @@ const watchOnly = async () => { showAddress: false, addressNote: '', showPayment: false, - fetchedUtxos: false + fetchedUtxos: false, + signedTx: null, + signedTxHex: null } }, @@ -202,75 +204,11 @@ const watchOnly = async () => { //################### PSBT ################### - extractTxFromPsbt: async function (psbtBase64) { - const wallet = this.g.user.wallets[0] - try { - const {data} = await LNbits.api.request( - 'PUT', - '/watchonly/api/v1/psbt/extract', - wallet.adminkey, - { - psbtBase64, - inputs: this.payment.tx.inputs - } - ) - return data - } catch (error) { - this.$q.notify({ - type: 'warning', - message: 'Cannot finalize PSBT!', - timeout: 10000 - }) - LNbits.utils.notifyApiError(error) - } + updateSignedPsbt: async function (psbtBase64) { + console.log('### updateSignedPsbt psbtBase64', psbtBase64) + this.$refs.paymentRef.updateSignedPsbt(psbtBase64) }, - updateSignedPsbt: async function (value) { - this.payment.psbtBase64Signed = value - const data = await this.extractTxFromPsbt(this.payment.psbtBase64Signed) - if (data) { - this.payment.signedTx = JSON.parse(data.tx_json) - this.payment.signedTxHex = data.tx_hex - } else { - this.payment.signedTx = null - this.payment.signedTxHex = null - } - }, - broadcastTransaction: async function () { - try { - const wallet = this.g.user.wallets[0] - const {data} = await LNbits.api.request( - 'POST', - '/watchonly/api/v1/tx', - wallet.adminkey, - {tx_hex: this.payment.signedTxHex} - ) - this.payment.sentTxId = data - - this.$q.notify({ - type: 'positive', - message: 'Transaction broadcasted!', - caption: `${data}`, - timeout: 10000 - }) - - this.hww.psbtSent = false - this.payment.psbtBase64Signed = null - this.payment.signedTxHex = null - this.payment.signedTx = null - this.payment.psbtBase64 = null - - await this.scanAddressWithAmount() - } catch (error) { - this.payment.sentTxId = null - this.$q.notify({ - type: 'warning', - message: 'Failed to broadcast!', - caption: `${error}`, - timeout: 10000 - }) - } - }, //################### SERIAL PORT ################### //################### HARDWARE WALLET ################### diff --git a/lnbits/extensions/watchonly/static/js/utils.js b/lnbits/extensions/watchonly/static/js/utils.js index 7080ab1e..65ac8a0a 100644 --- a/lnbits/extensions/watchonly/static/js/utils.js +++ b/lnbits/extensions/watchonly/static/js/utils.js @@ -124,7 +124,6 @@ const readFromSerialPort = reader => { } while (true) { const {value, done} = await reader.read() - console.log('### serial read', value) if (value) { const values = value.split(separator) // found one or more separators diff --git a/lnbits/extensions/watchonly/templates/watchonly/index.html b/lnbits/extensions/watchonly/templates/watchonly/index.html index 0dda9657..d54ac618 100644 --- a/lnbits/extensions/watchonly/templates/watchonly/index.html +++ b/lnbits/extensions/watchonly/templates/watchonly/index.html @@ -8,7 +8,10 @@ :adminkey="g.user.wallets[0].adminkey" > @@ -113,6 +116,7 @@