diff --git a/lnbits/extensions/watchonly/static/components/payment/payment.html b/lnbits/extensions/watchonly/static/components/payment/payment.html
index 9a9a430c..02904714 100644
--- a/lnbits/extensions/watchonly/static/components/payment/payment.html
+++ b/lnbits/extensions/watchonly/static/components/payment/payment.html
@@ -95,7 +95,7 @@
-
Fee Rate:
+
Fee Rate:
{{feeRate}} sats/vbyte
@@ -179,7 +179,7 @@
Change:
- {{satBtc(balance)}}
+ {{satBtc(changeAmount)}}
diff --git a/lnbits/extensions/watchonly/static/components/payment/payment.js b/lnbits/extensions/watchonly/static/components/payment/payment.js
index ab844808..d20c1fea 100644
--- a/lnbits/extensions/watchonly/static/components/payment/payment.js
+++ b/lnbits/extensions/watchonly/static/components/payment/payment.js
@@ -28,7 +28,6 @@ async function payment(path) {
sendToList: [{address: '', amount: undefined}],
changeWallet: null,
changeAddress: {},
- changeAmount: 0,
showCustomFee: false,
showCoinSelect: false,
showChange: false,
@@ -53,6 +52,14 @@ async function payment(path) {
.filter(utxo => utxo.selected)
.reduce((t, a) => t + (a.amount || 0), 0)
},
+ changeAmount: function () {
+ return Math.max(
+ 0,
+ this.selectedAmount -
+ this.totalPayedAmount -
+ this.feeRate * this.txSizeNoChange
+ )
+ },
balance: function () {
return this.utxos.reduce((t, a) => t + (a.amount || 0), 0)
},
@@ -109,12 +116,9 @@ async function payment(path) {
amount: out.amount
}))
- if (excludeChange) {
- this.changeAmount = 0
- } else {
+ if (!excludeChange) {
const change = this.createChangeOutput()
- this.changeAmount = change.amount // todo: compute separately
- if (change.amount >= this.DUST_LIMIT) {
+ if (this.changeAmount >= this.DUST_LIMIT) {
tx.outputs.push(change)
}
}
@@ -127,14 +131,11 @@ async function payment(path) {
},
createChangeOutput: function () {
const change = this.changeAddress
- // const inputAmount = this.getTotalSelectedUtxoAmount() // todo: set amount separately
- // const payedAmount = this.getTotalPaymentAmount()
const walletAcount =
this.accounts.find(w => w.id === change.wallet) || {}
return {
address: change.address,
- // amount: inputAmount - payedAmount - this.feeValue,
addressIndex: change.addressIndex,
addressIndex: change.addressIndex,
masterpub_fingerprint: walletAcount.fingerprint