fix: change amount
This commit is contained in:
parent
31729e41cf
commit
cec44f4a99
2 changed files with 12 additions and 11 deletions
|
|
@ -95,7 +95,7 @@
|
|||
|
||||
<div class="col-8">
|
||||
<div class="float-right">
|
||||
<span >Fee Rate:</span>
|
||||
<span>Fee Rate:</span>
|
||||
<span class="text-subtitle2 q-ml-md">
|
||||
{{feeRate}} sats/vbyte</span
|
||||
>
|
||||
|
|
@ -179,7 +179,7 @@
|
|||
<div class="float-right">
|
||||
<span>Change:</span>
|
||||
<span class="text-subtitle2 q-ml-md">
|
||||
{{satBtc(balance)}}
|
||||
{{satBtc(changeAmount)}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue