fix: coin selection

This commit is contained in:
Vlad Stan 2022-07-26 17:42:37 +03:00
parent 24d162f3fc
commit 59d960b5f9
4 changed files with 16 additions and 25 deletions

View file

@ -163,7 +163,7 @@ async function payment(path) {
this.selectChangeAddress(this.changeWallet)
},
handleOutputsChange: function () {
this.$refs.utxoList.applyUtxoSelectionMode()
this.$refs.utxoList.refreshUtxoSelection(this.totalPayedAmount)
},
getTotalPaymentAmount: function () {
return this.sendToList.reduce((t, a) => t + (a.amount || 0), 0)

View file

@ -67,7 +67,6 @@ async function sendTo(path) {
0,
inputAmount - payedAmount - feeValue
)
this.handleOutputsChange()
},
handleOutputsChange: function () {
this.$emit('update:outputs')

View file

@ -9,7 +9,7 @@
v-model="utxoSelectionMode"
:options="utxoSelectionModes"
label="Selection Mode"
@input="applyUtxoSelectionMode"
@input="updateUtxoSelection"
></q-select>
</div>
<div v-if="selectable" class="col-1 q-pr-lg">
@ -17,7 +17,7 @@
outline
icon="refresh"
color="grey"
@click="applyUtxoSelectionMode"
@click="updateUtxoSelection"
class="q-ml-sm"
></q-btn>
</div>
@ -130,23 +130,6 @@
</q-td>
</q-tr>
</template>
<template v-slot:bottom-row>
<q-tr>
<q-td colspan="100%">
<div class="row items-center no-wrap q-mb-md q-pt-lg">
<div class="col-12">
<div>
<span class="text-weight-bold">Selected Amount: </span>
<q-badge class="text-subtitle2 q-ml-lg" color="green"
>{{satBtc(getTotalSelectedUtxoAmount())}}
</q-badge>
</div>
</div>
</div>
</q-td>
</q-tr>
</template>
</q-table>
</q-card-section></q-card
>

View file

@ -75,7 +75,8 @@ async function utxoList(path) {
'Smaller Inputs First',
'Larger Inputs First'
],
utxoSelectionMode: 'Random'
utxoSelectionMode: 'Random',
utxoSelectAmount: 0
}
},
@ -101,7 +102,16 @@ async function utxoList(path) {
.reduce((t, a) => t + (a.amount || 0), 0)
return total
},
refreshUtxoSelection: function (totalPayedAmount) {
this.utxoSelectAmount = totalPayedAmount
this.applyUtxoSelectionMode()
},
updateUtxoSelection: function () {
this.utxoSelectAmount = this.payedAmount
this.applyUtxoSelectionMode()
},
applyUtxoSelectionMode: function () {
console.log('### this.utxoSelectAmount', this.utxoSelectAmount)
const mode = this.utxoSelectionMode
const isSelectAll = mode === 'Select All'
if (isSelectAll) {
@ -111,11 +121,10 @@ async function utxoList(path) {
this.utxos.forEach(u => (u.selected = false))
const isManual = mode === 'Manual'
if (isManual || !this.payedAmount) return
if (isManual || !this.utxoSelectAmount) return
const isSmallerFirst = mode === 'Smaller Inputs First'
const isLargerFirst = mode === 'Larger Inputs First'
let selectedUtxos = this.utxos.slice()
if (isSmallerFirst || isLargerFirst) {
const sortFn = isSmallerFirst
@ -127,7 +136,7 @@ async function utxoList(path) {
selectedUtxos = _.shuffle(selectedUtxos)
}
selectedUtxos.reduce((total, utxo) => {
utxo.selected = total < this.payedAmount
utxo.selected = total < this.utxoSelectAmount
total += utxo.amount
return total
}, 0)