mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-24 22:58:46 +01:00
fix: coin selection
This commit is contained in:
parent
24d162f3fc
commit
59d960b5f9
4 changed files with 16 additions and 25 deletions
|
@ -163,7 +163,7 @@ async function payment(path) {
|
||||||
this.selectChangeAddress(this.changeWallet)
|
this.selectChangeAddress(this.changeWallet)
|
||||||
},
|
},
|
||||||
handleOutputsChange: function () {
|
handleOutputsChange: function () {
|
||||||
this.$refs.utxoList.applyUtxoSelectionMode()
|
this.$refs.utxoList.refreshUtxoSelection(this.totalPayedAmount)
|
||||||
},
|
},
|
||||||
getTotalPaymentAmount: function () {
|
getTotalPaymentAmount: function () {
|
||||||
return this.sendToList.reduce((t, a) => t + (a.amount || 0), 0)
|
return this.sendToList.reduce((t, a) => t + (a.amount || 0), 0)
|
||||||
|
|
|
@ -67,7 +67,6 @@ async function sendTo(path) {
|
||||||
0,
|
0,
|
||||||
inputAmount - payedAmount - feeValue
|
inputAmount - payedAmount - feeValue
|
||||||
)
|
)
|
||||||
this.handleOutputsChange()
|
|
||||||
},
|
},
|
||||||
handleOutputsChange: function () {
|
handleOutputsChange: function () {
|
||||||
this.$emit('update:outputs')
|
this.$emit('update:outputs')
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
v-model="utxoSelectionMode"
|
v-model="utxoSelectionMode"
|
||||||
:options="utxoSelectionModes"
|
:options="utxoSelectionModes"
|
||||||
label="Selection Mode"
|
label="Selection Mode"
|
||||||
@input="applyUtxoSelectionMode"
|
@input="updateUtxoSelection"
|
||||||
></q-select>
|
></q-select>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="selectable" class="col-1 q-pr-lg">
|
<div v-if="selectable" class="col-1 q-pr-lg">
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
outline
|
outline
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
color="grey"
|
color="grey"
|
||||||
@click="applyUtxoSelectionMode"
|
@click="updateUtxoSelection"
|
||||||
class="q-ml-sm"
|
class="q-ml-sm"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
</div>
|
</div>
|
||||||
|
@ -130,23 +130,6 @@
|
||||||
</q-td>
|
</q-td>
|
||||||
</q-tr>
|
</q-tr>
|
||||||
</template>
|
</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-table>
|
||||||
</q-card-section></q-card
|
</q-card-section></q-card
|
||||||
>
|
>
|
||||||
|
|
|
@ -75,7 +75,8 @@ async function utxoList(path) {
|
||||||
'Smaller Inputs First',
|
'Smaller Inputs First',
|
||||||
'Larger 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)
|
.reduce((t, a) => t + (a.amount || 0), 0)
|
||||||
return total
|
return total
|
||||||
},
|
},
|
||||||
|
refreshUtxoSelection: function (totalPayedAmount) {
|
||||||
|
this.utxoSelectAmount = totalPayedAmount
|
||||||
|
this.applyUtxoSelectionMode()
|
||||||
|
},
|
||||||
|
updateUtxoSelection: function () {
|
||||||
|
this.utxoSelectAmount = this.payedAmount
|
||||||
|
this.applyUtxoSelectionMode()
|
||||||
|
},
|
||||||
applyUtxoSelectionMode: function () {
|
applyUtxoSelectionMode: function () {
|
||||||
|
console.log('### this.utxoSelectAmount', this.utxoSelectAmount)
|
||||||
const mode = this.utxoSelectionMode
|
const mode = this.utxoSelectionMode
|
||||||
const isSelectAll = mode === 'Select All'
|
const isSelectAll = mode === 'Select All'
|
||||||
if (isSelectAll) {
|
if (isSelectAll) {
|
||||||
|
@ -111,11 +121,10 @@ async function utxoList(path) {
|
||||||
|
|
||||||
this.utxos.forEach(u => (u.selected = false))
|
this.utxos.forEach(u => (u.selected = false))
|
||||||
const isManual = mode === 'Manual'
|
const isManual = mode === 'Manual'
|
||||||
if (isManual || !this.payedAmount) return
|
if (isManual || !this.utxoSelectAmount) return
|
||||||
|
|
||||||
const isSmallerFirst = mode === 'Smaller Inputs First'
|
const isSmallerFirst = mode === 'Smaller Inputs First'
|
||||||
const isLargerFirst = mode === 'Larger Inputs First'
|
const isLargerFirst = mode === 'Larger Inputs First'
|
||||||
|
|
||||||
let selectedUtxos = this.utxos.slice()
|
let selectedUtxos = this.utxos.slice()
|
||||||
if (isSmallerFirst || isLargerFirst) {
|
if (isSmallerFirst || isLargerFirst) {
|
||||||
const sortFn = isSmallerFirst
|
const sortFn = isSmallerFirst
|
||||||
|
@ -127,7 +136,7 @@ async function utxoList(path) {
|
||||||
selectedUtxos = _.shuffle(selectedUtxos)
|
selectedUtxos = _.shuffle(selectedUtxos)
|
||||||
}
|
}
|
||||||
selectedUtxos.reduce((total, utxo) => {
|
selectedUtxos.reduce((total, utxo) => {
|
||||||
utxo.selected = total < this.payedAmount
|
utxo.selected = total < this.utxoSelectAmount
|
||||||
total += utxo.amount
|
total += utxo.amount
|
||||||
return total
|
return total
|
||||||
}, 0)
|
}, 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue