fix: negative stx available balance, closes #3761

This commit is contained in:
alter-eggo
2023-06-27 15:17:52 +04:00
committed by Anastasios
parent 1a7f6830eb
commit 6a2adf0574
2 changed files with 11 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ export function useStxBalance() {
const stxEffectiveBalance = isDefined(totalBalance)
? subtractMoney(totalBalance, stxOutboundQuery.data)
: createMoney(0, 'STX');
const stxEffectiveUsdBalance = isDefined(totalBalance)
? i18nFormatCurrency(baseCurrencyAmountInQuote(stxEffectiveBalance, stxMarketData))
: undefined;

View File

@@ -66,15 +66,19 @@ export function useCurrentAccountMempoolTransactionsBalance() {
const address = useCurrentAccountStxAddressState();
const { transactions: pendingTransactions } = useStacksPendingTransactions();
const tokenTransferTxsBalance = (
pendingTransactions.filter(
tx => tx.tx_type === 'token_transfer' && tx.sender_address === address
) as unknown as MempoolTokenTransferTransaction[]
).reduce((acc, tx) => acc.plus(tx.token_transfer.amount), new BigNumber(0));
const pendingTxsFeesBalance = pendingTransactions.reduce(
const pendingOutboundTxs = pendingTransactions.filter(
tx => 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),
new BigNumber(0)
);
const pendingTxsFeesBalance = pendingOutboundTxs.reduce(
(acc, tx) => acc.plus(tx.fee_rate),
new BigNumber(0)
);
return createMoney(tokenTransferTxsBalance.plus(pendingTxsFeesBalance), 'STX');
}