Skip to content

Commit

Permalink
fix: unprocessable pending txs balance subtraction, closes #3921
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-eggo committed Jul 18, 2023
1 parent d5e8f26 commit 2d284db
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/app/query/stacks/mempool/mempool.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { microStxToStx } from '@app/common/money/unit-conversion';
import { useTransactionsById } from '@app/query/stacks/transactions/transactions-by-id.query';
import { useCurrentAccountStxAddressState } from '@app/store/accounts/blockchain/stacks/stacks-account.hooks';

import { useStacksConfirmedTransactions } from '../transactions/transactions-with-transfers.hooks';
import { useAccountMempoolQuery } from './mempool.query';

const droppedCache = new Map();
Expand Down Expand Up @@ -65,10 +66,14 @@ export function useCurrentAccountMempool() {
export function useCurrentAccountMempoolTransactionsBalance() {
const address = useCurrentAccountStxAddressState();
const { transactions: pendingTransactions } = useStacksPendingTransactions();
const confirmedTxs = useStacksConfirmedTransactions();

const pendingOutboundTxs = pendingTransactions.filter(
tx => tx.tx_type === 'token_transfer' && tx.sender_address === address
) as unknown as MempoolTokenTransferTransaction[];
const pendingOutboundTxs = pendingTransactions.filter(tx => {
if (confirmedTxs.some(confirmedTx => confirmedTx.nonce === tx.nonce)) {
return false;
}
return tx.tx_type === 'token_transfer' && tx.sender_address === address;
}) as unknown as MempoolTokenTransferTransaction[];

const tokenTransferTxsBalance = pendingOutboundTxs.reduce(
(acc, tx) => acc.plus(tx.token_transfer.amount),
Expand Down

0 comments on commit 2d284db

Please sign in to comment.