From ec6d4e33d57b7f85890931cad50593d521b7a360 Mon Sep 17 00:00:00 2001 From: Anastasios Date: Fri, 17 Jan 2025 14:33:46 +0400 Subject: [PATCH] fix: stx available balance issues --- .../stx-crypto-asset-item.tsx | 11 ++++----- .../form/stx/stx-send-form.tsx | 11 ++++----- .../form/stx/use-stx-send-form.tsx | 24 +++++++++++-------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx b/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx index b62f7dadfc4..2d5df5b3679 100644 --- a/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx +++ b/src/app/features/asset-list/stacks/stx-crypo-asset-item/stx-crypto-asset-item.tsx @@ -17,6 +17,7 @@ interface StxCryptoAssetItemProps { isPrivate?: boolean; onSelectAsset?(symbol: string): void; } + export function StxCryptoAssetItem({ balance, isLoading, @@ -25,15 +26,13 @@ export function StxCryptoAssetItem({ }: StxCryptoAssetItemProps) { const marketData = useCryptoCurrencyMarketDataMeanAverage('STX'); - const { availableBalance, lockedBalance } = balance; + const { lockedBalance, totalBalance } = balance; const showLockedBalance = lockedBalance.amount.isGreaterThan(0) && !isPrivate; const fiatLockedBalance = i18nFormatCurrency( baseCurrencyAmountInQuote(lockedBalance, marketData) ); - const fiatAvailableBalance = i18nFormatCurrency( - baseCurrencyAmountInQuote(availableBalance, marketData) - ); + const fiatTotalBalance = i18nFormatCurrency(baseCurrencyAmountInQuote(totalBalance, marketData)); const titleRightBulletInfo = ( {formatMoneyWithoutSymbol(lockedBalance)} locked ); @@ -41,10 +40,10 @@ export function StxCryptoAssetItem({ return ( } isLoading={isLoading} isPrivate={isPrivate} diff --git a/src/app/pages/send/send-crypto-asset-form/form/stx/stx-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/stx/stx-send-form.tsx index 6c5014560f0..2af149b6557 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/stx/stx-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/stx/stx-send-form.tsx @@ -17,7 +17,7 @@ const symbol = 'STX' satisfies CryptoCurrency; export function StxSendForm() { const stxMarketData = useCryptoCurrencyMarketDataMeanAverage(symbol); const { - availableUnlockedBalance, + availableBalance, initialValues, previewTransaction, sendMaxBalance, @@ -27,13 +27,10 @@ export function StxSendForm() { const amountField = ( } bottomInputOverlay={ - + } /> ); @@ -53,7 +50,7 @@ export function StxSendForm() { amountField={amountField} selectedAssetField={selectedAssetField} fees={fees} - availableTokenBalance={availableUnlockedBalance} + availableTokenBalance={availableBalance} /> diff --git a/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx index 0f6f845b398..2e36c3dc2ef 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/stx/use-stx-send-form.tsx @@ -7,9 +7,9 @@ import { STX_DECIMALS } from '@leather.io/constants'; import { useCalculateStacksTxFees, useStacksValidateFeeByNonce, - useStxAvailableUnlockedBalance, + useStxCryptoAssetBalance, } from '@leather.io/query'; -import { convertAmountToBaseUnit } from '@leather.io/utils'; +import { convertAmountToBaseUnit, createMoney } from '@leather.io/utils'; import { logger } from '@shared/logger'; import { StacksSendFormValues } from '@shared/models/form.model'; @@ -37,34 +37,38 @@ export function useStxSendForm() { const sendFormNavigate = useSendFormNavigate(); const address = useCurrentStacksAccountAddress(); const { changeFeeByNonce } = useStacksValidateFeeByNonce(address); - const availableUnlockedBalance = useStxAvailableUnlockedBalance(address); + + // get stx balance + const { filteredBalanceQuery } = useStxCryptoAssetBalance(address); + const { data: balance } = filteredBalanceQuery; + const availableBalance = balance?.availableUnlockedBalance ?? createMoney(0, 'STX'); const sendMaxBalance = useMemo( () => convertAmountToBaseUnit( - availableUnlockedBalance.amount.minus(stxFees?.estimates[1].fee.amount || 0), + availableBalance.amount.minus(stxFees?.estimates[1].fee.amount || 0), STX_DECIMALS ), - [availableUnlockedBalance.amount, stxFees?.estimates] + [availableBalance.amount, stxFees?.estimates] ); const { initialValues, checkFormValidation, recipient, memo, nonce } = useStacksCommonSendForm({ symbol: 'STX', - availableTokenBalance: availableUnlockedBalance, + availableTokenBalance: availableBalance, }); return { - availableUnlockedBalance, + availableBalance, initialValues, onFormStateChange, sendMaxBalance, stxFees, validationSchema: yup.object({ - amount: stxAmountValidator(availableUnlockedBalance).concat( - stxAvailableBalanceValidator(availableUnlockedBalance) + amount: stxAmountValidator(availableBalance).concat( + stxAvailableBalanceValidator(availableBalance) ), - fee: stxFeeValidator(availableUnlockedBalance), + fee: stxFeeValidator(availableBalance), recipient, memo, nonce,