From 345c1965aaa915c3462af65c3738dd3782bbf41a Mon Sep 17 00:00:00 2001 From: sproxet Date: Tue, 26 Jul 2022 17:18:03 +0700 Subject: [PATCH] Fix an issue where breaking masternodes would fail. --- src/renderer/components/SendPage.vue | 8 +++++--- src/renderer/components/SendPage/SendFlow.vue | 6 +++--- src/store/modules/Balance.ts | 2 +- src/store/modules/Transactions.ts | 1 + 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/renderer/components/SendPage.vue b/src/renderer/components/SendPage.vue index 6eca447b..6401f600 100644 --- a/src/renderer/components/SendPage.vue +++ b/src/renderer/components/SendPage.vue @@ -238,7 +238,7 @@ export default { }), transactionFee() { - if (!this.satoshiAmount) return undefined; + if (!this.satoshiAmount || !this.available || this.available < this.satoshiAmount) return undefined; return this.calculateTransactionFee(this.isPrivate, this.satoshiAmount, this.txFeePerKb, this.subtractFeeFromAmount, this.customInputs.length ? this.customInputs : undefined); }, @@ -270,7 +270,9 @@ export default { }, available () { - return this.isPrivate ? this.availablePrivate : this.availablePublic; + if (this.coinControl) return this.coinControlSelectedAmount; + else if (this.isPrivate) return this.availablePrivate; + else return this.availablePublic; }, // This is the amount the user entered in satoshis. @@ -290,7 +292,7 @@ export default { // We can begin the send if the fee has been shown and the form is valid. canBeginSend () { - return this.isValidated && this.transactionFee > 0 && !this.totalAmountExceedsBalance; + return this.isValidated && this.transactionFee > 0 && (this.available >= this.totalAmount); }, isValidated () { diff --git a/src/renderer/components/SendPage/SendFlow.vue b/src/renderer/components/SendPage/SendFlow.vue index c186bc67..f83e3b85 100644 --- a/src/renderer/components/SendPage/SendFlow.vue +++ b/src/renderer/components/SendPage/SendFlow.vue @@ -74,7 +74,7 @@ export default { computed: { ...mapGetters({ addressBook: 'AddressBook/addressBook', - lockedTransactions: 'Transactions/lockedTransactions', + lockedUTXOs: 'Transactions/lockedUTXOs', allowBreakingMasternodes: 'App/allowBreakingMasternodes', selectInputs: 'Transactions/selectInputs' }), @@ -116,9 +116,9 @@ export default { } else { if (this.coinControl && this.allowBreakingMasternodes) { const lockedCoins = this.coinControl.filter(coin => - this.lockedTransactions.find(tx => tx.txid === coin[0] && tx.txIndex === coin[1]) + this.lockedUTXOs.find(tx => tx.txid === coin[0] && tx.index === coin[1]) ); - await $daemon.updateCoinLocks(passphrase, [], lockedCoins); + if (lockedCoins.length) await $daemon.updateCoinLocks(passphrase, [], lockedCoins); } // Under the hood we'll always use coin control because the daemon uses a very complex stochastic diff --git a/src/store/modules/Balance.ts b/src/store/modules/Balance.ts index d60eeee9..31db8fd7 100644 --- a/src/store/modules/Balance.ts +++ b/src/store/modules/Balance.ts @@ -6,7 +6,7 @@ const getters = { unconfirmedPublicChange, locked, immature] = [0, 0, 0, 0, 0, 0, 0, 0, 0]; let nextHeight: number = rootGetters['ApiStatus/currentBlockHeight'] + 1; - for (const txo of rootGetters['Transactions/TXOs']) { + for (const txo of rootGetters['Transactions/UTXOs']) { if (!txo.isToMe || txo.isSpent) continue; else if (txo.isLocked) locked += txo.amount; else if (txo.inputPrivacy == 'mined' && txo.validAt > nextHeight) immature += txo.amount; diff --git a/src/store/modules/Transactions.ts b/src/store/modules/Transactions.ts index 46d1d8ad..93020b61 100644 --- a/src/store/modules/Transactions.ts +++ b/src/store/modules/Transactions.ts @@ -185,6 +185,7 @@ const getters = { txo.spendSize && txo.validAt <= rootGetters['ApiStatus/currentBlockHeight'] + 1 ), + lockedUTXOs: (state, getters) => getters.UTXOs.filter((txo: TXO) => txo.isLocked), userVisibleTransactions: (state, getters): TXO[] => getters.TXOs .filter((txo: TXO) => !txo.isChange && txo.destination)