fix: change amount
This commit is contained in:
@@ -95,7 +95,7 @@
|
|||||||
|
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span >Fee Rate:</span>
|
<span>Fee Rate:</span>
|
||||||
<span class="text-subtitle2 q-ml-md">
|
<span class="text-subtitle2 q-ml-md">
|
||||||
{{feeRate}} sats/vbyte</span
|
{{feeRate}} sats/vbyte</span
|
||||||
>
|
>
|
||||||
@@ -179,7 +179,7 @@
|
|||||||
<div class="float-right">
|
<div class="float-right">
|
||||||
<span>Change:</span>
|
<span>Change:</span>
|
||||||
<span class="text-subtitle2 q-ml-md">
|
<span class="text-subtitle2 q-ml-md">
|
||||||
{{satBtc(balance)}}
|
{{satBtc(changeAmount)}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ async function payment(path) {
|
|||||||
sendToList: [{address: '', amount: undefined}],
|
sendToList: [{address: '', amount: undefined}],
|
||||||
changeWallet: null,
|
changeWallet: null,
|
||||||
changeAddress: {},
|
changeAddress: {},
|
||||||
changeAmount: 0,
|
|
||||||
showCustomFee: false,
|
showCustomFee: false,
|
||||||
showCoinSelect: false,
|
showCoinSelect: false,
|
||||||
showChange: false,
|
showChange: false,
|
||||||
@@ -53,6 +52,14 @@ async function payment(path) {
|
|||||||
.filter(utxo => utxo.selected)
|
.filter(utxo => utxo.selected)
|
||||||
.reduce((t, a) => t + (a.amount || 0), 0)
|
.reduce((t, a) => t + (a.amount || 0), 0)
|
||||||
},
|
},
|
||||||
|
changeAmount: function () {
|
||||||
|
return Math.max(
|
||||||
|
0,
|
||||||
|
this.selectedAmount -
|
||||||
|
this.totalPayedAmount -
|
||||||
|
this.feeRate * this.txSizeNoChange
|
||||||
|
)
|
||||||
|
},
|
||||||
balance: function () {
|
balance: function () {
|
||||||
return this.utxos.reduce((t, a) => t + (a.amount || 0), 0)
|
return this.utxos.reduce((t, a) => t + (a.amount || 0), 0)
|
||||||
},
|
},
|
||||||
@@ -109,12 +116,9 @@ async function payment(path) {
|
|||||||
amount: out.amount
|
amount: out.amount
|
||||||
}))
|
}))
|
||||||
|
|
||||||
if (excludeChange) {
|
if (!excludeChange) {
|
||||||
this.changeAmount = 0
|
|
||||||
} else {
|
|
||||||
const change = this.createChangeOutput()
|
const change = this.createChangeOutput()
|
||||||
this.changeAmount = change.amount // todo: compute separately
|
if (this.changeAmount >= this.DUST_LIMIT) {
|
||||||
if (change.amount >= this.DUST_LIMIT) {
|
|
||||||
tx.outputs.push(change)
|
tx.outputs.push(change)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,14 +131,11 @@ async function payment(path) {
|
|||||||
},
|
},
|
||||||
createChangeOutput: function () {
|
createChangeOutput: function () {
|
||||||
const change = this.changeAddress
|
const change = this.changeAddress
|
||||||
// const inputAmount = this.getTotalSelectedUtxoAmount() // todo: set amount separately
|
|
||||||
// const payedAmount = this.getTotalPaymentAmount()
|
|
||||||
const walletAcount =
|
const walletAcount =
|
||||||
this.accounts.find(w => w.id === change.wallet) || {}
|
this.accounts.find(w => w.id === change.wallet) || {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
address: change.address,
|
address: change.address,
|
||||||
// amount: inputAmount - payedAmount - this.feeValue,
|
|
||||||
addressIndex: change.addressIndex,
|
addressIndex: change.addressIndex,
|
||||||
addressIndex: change.addressIndex,
|
addressIndex: change.addressIndex,
|
||||||
masterpub_fingerprint: walletAcount.fingerprint
|
masterpub_fingerprint: walletAcount.fingerprint
|
||||||
|
|||||||
Reference in New Issue
Block a user