fix: max amount

This commit is contained in:
Vlad Stan 2022-07-26 14:09:16 +03:00
parent b576ef4f21
commit eedd0ee6a3
6 changed files with 32 additions and 24 deletions

View file

@ -3,7 +3,7 @@
<!-- {{addresses}} --> <!-- {{addresses}} -->
<q-tabs v-model="paymentTab" no-caps class="bg-dark text-white shadow-2"> <q-tabs v-model="paymentTab" no-caps class="bg-dark text-white shadow-2">
<q-tab name="destination" label="Send To"></q-tab> <q-tab name="destination" label="Send To"></q-tab>
<q-tab name="coinControl" label="Coin Control"></q-tab> <q-tab name="coinControl" label="Coin Select"></q-tab>
</q-tabs> </q-tabs>
<q-tab-panels v-model="paymentTab"> <q-tab-panels v-model="paymentTab">
<q-tab-panel name="destination"> <q-tab-panel name="destination">
@ -11,7 +11,9 @@
<q-card-section> <q-card-section>
<send-to <send-to
:data.sync="sendToList" :data.sync="sendToList"
:tx:size="txSizeNoChange" :fee-rate="feeRate"
:tx-size="txSizeNoChange"
:selected-amount="selectedAmount"
:sats-denominated="sats_denominated" :sats-denominated="sats_denominated"
></send-to> ></send-to>
<!-- <div class="row items-center no-wrap q-mb-md"> <!-- <div class="row items-center no-wrap q-mb-md">
@ -158,7 +160,7 @@
</q-card-section> </q-card-section>
</q-card> </q-card>
<utxo-list <utxo-list
:utxos="utxos.data" :utxos="utxos"
:selectable="true" :selectable="true"
:payed-amount="getTotalPaymentAmount()" :payed-amount="getTotalPaymentAmount()"
:mempool_endpoint="mempool_endpoint" :mempool_endpoint="mempool_endpoint"

View file

@ -45,6 +45,11 @@ async function payment(path) {
}, },
feeValue: function () { feeValue: function () {
return this.feeRate * this.txSize return this.feeRate * this.txSize
},
selectedAmount: function () {
return this.utxos
.filter(utxo => utxo.selected)
.reduce((t, a) => t + (a.amount || 0), 0)
} }
}, },
@ -84,7 +89,7 @@ async function payment(path) {
fingerprint: w.fingerprint fingerprint: w.fingerprint
})) }))
} }
tx.inputs = this.utxos.data tx.inputs = this.utxos
.filter(utxo => utxo.selected) .filter(utxo => utxo.selected)
.map(mapUtxoToPsbtInput) .map(mapUtxoToPsbtInput)
.sort((a, b) => .sort((a, b) =>

View file

@ -4,7 +4,13 @@ async function sendTo(path) {
name: 'send-to', name: 'send-to',
template, template,
props: ['data', 'tx-size', 'total-amount', 'fee-rate', 'sats_denominated'], props: [
'data',
'tx-size',
'selected-amount',
'fee-rate',
'sats_denominated'
],
computed: { computed: {
dataLocal: { dataLocal: {
@ -21,7 +27,6 @@ async function sendTo(path) {
data: function () { data: function () {
return { return {
DUST_LIMIT: 546, DUST_LIMIT: 546,
amount: 0,
paymentTable: { paymentTable: {
columns: [ columns: [
{ {
@ -50,17 +55,19 @@ async function sendTo(path) {
this.dataLocal.splice(index, 1) this.dataLocal.splice(index, 1)
} }
}, },
sendMaxToAddress: function (paymentAddress = {}) {
const feeValue = this.feeRate * this.txSize
const inputAmount = this.selectedAmount
const currentAmount = Math.max(0, paymentAddress.amount || 0)
const payedAmount = this.getTotalPaymentAmount() - currentAmount
paymentAddress.amount = Math.max(
0,
inputAmount - payedAmount - feeValue
)
},
getTotalPaymentAmount: function () { getTotalPaymentAmount: function () {
return this.dataLocal.reduce((t, a) => t + (a.amount || 0), 0) return this.dataLocal.reduce((t, a) => t + (a.amount || 0), 0)
},
sendMaxToAddress: function (paymentAddress = {}) {
this.amount = 0
// const tx = this.createTx(true)
// this.payment.txSize = Math.round(txSize(tx))
const fee = this['fee-rate'] * this['tx-size']
const inputAmount = this['total-amount']
const payedAmount = this.getTotalPaymentAmount()
paymentAddress.amount = Math.max(0, inputAmount - payedAmount - fee)
} }
}, },

View file

@ -96,7 +96,7 @@ async function utxoList(path) {
return wallet ? wallet.title : 'unknown' return wallet ? wallet.title : 'unknown'
}, },
getTotalSelectedUtxoAmount: function () { getTotalSelectedUtxoAmount: function () {
const total = this.utxos const total = (this.utxos || [])
.filter(u => u.selected) .filter(u => u.selected)
.reduce((t, a) => t + (a.amount || 0), 0) .reduce((t, a) => t + (a.amount || 0), 0)
return total return total

View file

@ -759,13 +759,6 @@ const watchOnly = async () => {
) )
this.updateAmountForAddress(addressData, addressTotal) this.updateAmountForAddress(addressData, addressTotal)
}, },
// todo: move/dedup
getTotalSelectedUtxoAmount: function () {
const total = this.utxos.data
.filter(u => u.selected)
.reduce((t, a) => t + (a.amount || 0), 0)
return total
},
//################### MEMPOOL API ################### //################### MEMPOOL API ###################
getAddressTxsDelayed: async function (addrData) { getAddressTxsDelayed: async function (addrData) {

View file

@ -497,8 +497,9 @@
<payment <payment
:accounts="walletAccounts" :accounts="walletAccounts"
:addresses="addresses" :addresses="addresses"
:utxos="utxos" :utxos="utxos.data"
></payment> ></payment>
<!-- todo: no more utxos.data -->
</q-card-section> </q-card-section>
</q-card> </q-card>
</div> </div>