fix account balances being requested before the transaction is confirmed

requesting balance reload too quickly often resulted in inaccurate balances after receiving funds, and is likely the reason users were shown an incoming balance card listing amount of funds that were already received
This commit is contained in:
keeri 2023-08-15 14:23:50 +00:00
commit 1f1391d270
3 changed files with 33 additions and 13 deletions

View file

@ -375,7 +375,6 @@ export class ReceiveComponent implements OnInit, OnDestroy {
} }
receivableBlock.loading = false; receivableBlock.loading = false;
await this.walletService.reloadBalances();
this.updatePendingBlocks(); // update the list this.updatePendingBlocks(); // update the list
} }

View file

@ -659,8 +659,6 @@ export class SendComponent implements OnInit {
this.confirmingTransaction = false; this.confirmingTransaction = false;
await this.walletService.reloadBalances();
} }
setMaxAmount() { setMaxAmount() {

View file

@ -154,10 +154,26 @@ export class WalletService {
const walletAccountIDs = this.wallet.accounts.map(a => a.id); const walletAccountIDs = this.wallet.accounts.map(a => a.id);
// If an incoming pending const isConfirmedIncomingTransactionForOwnWalletAccount = (
if (transaction.block.type === 'state' && transaction.block.subtype === 'send' (transaction.block.type === 'state')
&& walletAccountIDs.indexOf(transaction.block.link_as_account) !== -1) { && (transaction.block.subtype === 'send')
if (shouldNotify) { && ( walletAccountIDs.includes(transaction.block.link_as_account) === true )
);
const isConfirmedSendTransactionFromOwnWalletAccount = (
(transaction.block.type === 'state')
&& (transaction.block.subtype === 'send')
&& ( walletAccountIDs.includes(transaction.block.account) === true )
);
const isConfirmedReceiveTransactionFromOwnWalletAccount = (
(transaction.block.type === 'state')
&& (transaction.block.subtype === 'receive')
&& ( walletAccountIDs.includes(transaction.block.account) === true )
);
if (isConfirmedIncomingTransactionForOwnWalletAccount === true) {
if (shouldNotify === true) {
if (this.wallet.locked && this.appSettings.settings.pendingOption !== 'manual') { if (this.wallet.locked && this.appSettings.settings.pendingOption !== 'manual') {
this.notifications.sendWarning(`New incoming transaction - Unlock the wallet to receive`, { length: 10000, identifier: 'pending-locked' }); this.notifications.sendWarning(`New incoming transaction - Unlock the wallet to receive`, { length: 10000, identifier: 'pending-locked' });
} else if (this.appSettings.settings.pendingOption === 'manual') { } else if (this.appSettings.settings.pendingOption === 'manual') {
@ -171,12 +187,11 @@ export class WalletService {
); );
} }
await this.processStateBlock(transaction); await this.processStateBlock(transaction);
} else if (isConfirmedSendTransactionFromOwnWalletAccount === true) {
// If a confirmed outgoing transaction
} else if (transaction.block.type === 'state' && transaction.block.subtype === 'send'
&& walletAccountIDs.indexOf(transaction.block.account) !== -1) {
shouldNotify = true; shouldNotify = true;
await this.processStateBlock(transaction); await this.processStateBlock(transaction);
} else if (isConfirmedReceiveTransactionFromOwnWalletAccount === true) {
shouldNotify = true;
} }
// Find if the source or destination is a tracked address in the address book // Find if the source or destination is a tracked address in the address book
@ -229,8 +244,16 @@ export class WalletService {
// I'm not sure about that because what happens if the websocket is disconnected and misses a transaction? // I'm not sure about that because what happens if the websocket is disconnected and misses a transaction?
// won't the balance be incorrect if relying only on the websocket? / Json // won't the balance be incorrect if relying only on the websocket? / Json
// Only reload balance if the incoming is to an internal wallet (to avoid RPC spam) const shouldReloadBalances = (
if (shouldNotify && walletAccountIDs.indexOf(transaction.block.link_as_account) !== -1) { (shouldNotify === true)
&& (
(isConfirmedIncomingTransactionForOwnWalletAccount === true)
|| (isConfirmedSendTransactionFromOwnWalletAccount === true)
|| (isConfirmedReceiveTransactionFromOwnWalletAccount === true)
)
);
if (shouldReloadBalances === true) {
await this.reloadBalances(); await this.reloadBalances();
} }
}); });