From c407e054fd92c422cfe8074f39ebcc074beadb7b Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Tue, 2 Aug 2022 16:42:06 +0300 Subject: [PATCH] feat: integrate transaction broadcast --- .../static/components/payment/payment.html | 82 +++++++++++++++++++ .../static/components/payment/payment.js | 28 +++++-- .../serial-signer/serial-signer.html | 30 +++++++ .../components/serial-signer/serial-signer.js | 46 +++++++++-- 4 files changed, 170 insertions(+), 16 deletions(-) diff --git a/lnbits/extensions/watchonly/static/components/payment/payment.html b/lnbits/extensions/watchonly/static/components/payment/payment.html index 9d9b714e..417703c0 100644 --- a/lnbits/extensions/watchonly/static/components/payment/payment.html +++ b/lnbits/extensions/watchonly/static/components/payment/payment.html @@ -225,4 +225,86 @@ + + + +
+
+ Transaction Details +
+
+ +
+
+
+
Version
+
{{signedTx.version}}
+
+
+
Locktime
+
{{signedTx.locktime}}
+
+
+
Fee
+
+ {{satBtc(signedTx.fee)}} +
+
+ + Outputs + +
+
+ {{satBtc(out.amount)}} +
+ +
+ {{out.address}} +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+ Send + Close +
+
+
diff --git a/lnbits/extensions/watchonly/static/components/payment/payment.js b/lnbits/extensions/watchonly/static/components/payment/payment.js index 89b95cf9..e5892b30 100644 --- a/lnbits/extensions/watchonly/static/components/payment/payment.js +++ b/lnbits/extensions/watchonly/static/components/payment/payment.js @@ -28,6 +28,7 @@ async function payment(path) { DUST_LIMIT: 546, tx: null, psbtBase64: null, + psbtBase64Signed: null, signedTx: null, sentTxId: null, signedTxId: null, @@ -40,6 +41,7 @@ async function payment(path) { showChecking: false, showChange: false, showPsbt: false, + showFinalTx: false, feeRate: 1 } }, @@ -224,15 +226,23 @@ async function payment(path) { this.selectChangeAddress(this.changeWallet) }, updateSignedPsbt: async function (psbtBase64) { - console.log('### payment updateSignedPsbt psbtBase64', psbtBase64) + try { + this.showChecking = true + this.psbtBase64Signed = psbtBase64 - const data = await this.extractTxFromPsbt(psbtBase64) - if (data) { - this.signedTx = JSON.parse(data.tx_json) - this.signedTxHex = data.tx_hex - } else { - this.signedTx = null - this.signedTxHex = null + console.log('### payment updateSignedPsbt psbtBase64', psbtBase64) + + const data = await this.extractTxFromPsbt(psbtBase64) + this.showFinalTx = true + if (data) { + this.signedTx = JSON.parse(data.tx_json) + this.signedTxHex = data.tx_hex + } else { + this.signedTx = null + this.signedTxHex = null + } + } finally { + this.showChecking = false } }, extractTxFromPsbt: async function (psbtBase64) { @@ -286,6 +296,8 @@ async function payment(path) { caption: `${error}`, timeout: 10000 }) + } finally { + this.showFinalTx = false } }, fetchTxHex: async function (txId) { diff --git a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html index a9fc7885..8f1a2264 100644 --- a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html +++ b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.html @@ -307,6 +307,36 @@ + + + Check word at position {{hww.seedWordPosition}} on display + +
+
+ Prev +
+
+ Next +
+
+ Close +
+
+
+
+ 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 6f4b8d48..659ac28b 100644 --- a/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js +++ b/lnbits/extensions/watchonly/static/components/serial-signer/serial-signer.js @@ -31,6 +31,8 @@ async function serialSigner(path) { loginResolve: null, psbtSentResolve: null, xpubResolve: null, + seedWordPosition: 1, + showSeedDialog: false, confirm: { outputIndex: 0, showFee: false @@ -402,13 +404,11 @@ async function serialSigner(path) { handleSignResponse: function (res = '') { this.hww.signingPsbt = false this.updateSignedPsbt(res) - if (this.hww.authenticated) { - this.$q.notify({ - type: 'positive', - message: 'Transaction Signed', - timeout: 10000 - }) - } + this.$q.notify({ + type: 'positive', + message: 'Transaction Signed', + timeout: 10000 + }) }, hwwHelp: async function () { try { @@ -496,7 +496,11 @@ async function serialSigner(path) { }, hwwShowSeed: async function () { try { - await this.writer.write(COMMAND_SEED + '\n') + this.hww.showSeedDialog = true + this.hww.seedWordPosition = 1 + await this.writer.write( + COMMAND_SEED + ' ' + this.hww.seedWordPosition + '\n' + ) } catch (error) { this.$q.notify({ type: 'warning', @@ -506,6 +510,31 @@ async function serialSigner(path) { }) } }, + showNextSeedWord: async function () { + this.hww.seedWordPosition++ + await this.writer.write( + COMMAND_SEED + ' ' + this.hww.seedWordPosition + '\n' + ) + }, + showPrevSeedWord: async function () { + this.hww.seedWordPosition = Math.max(1, this.hww.seedWordPosition - 1) + console.log('### this.hww.seedWordPosition', this.hww.seedWordPosition) + await this.writer.write( + COMMAND_SEED + ' ' + this.hww.seedWordPosition + '\n' + ) + }, + handleShowSeedResponse: function (res = '') { + const args = res.trim().split(' ') + if (args.length < 2 || args[0].trim() !== '1') { + this.$q.notify({ + type: 'warning', + message: 'Failed to show seed!', + caption: `${res}`, + timeout: 10000 + }) + return + } + }, hwwRestore: async function () { try { await this.writer.write( @@ -529,6 +558,7 @@ async function serialSigner(path) { this.hww.showPassword = false } }, + updateSignedPsbt: async function (value) { this.$emit('signed:psbt', value) }