From 8121ffe813760ee46947137dee6446bac29fb415 Mon Sep 17 00:00:00 2001 From: Fara Woolf Date: Sat, 20 Jan 2024 13:16:12 -0600 Subject: [PATCH] fix: fee estimation error --- .../stacks-transaction-signer.tsx | 4 ++-- .../form/stacks-sip10/use-sip10-send-form.tsx | 4 ++-- .../send-crypto-asset-form/form/stx/use-stx-send-form.tsx | 5 ++--- src/app/pages/transaction-request/transaction-request.tsx | 4 ++-- src/app/query/stacks/fees/fees.hooks.ts | 7 +++++++ 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/app/features/stacks-transaction-request/stacks-transaction-signer.tsx b/src/app/features/stacks-transaction-request/stacks-transaction-signer.tsx index bce6c6504b2..1020d7ca8c3 100644 --- a/src/app/features/stacks-transaction-request/stacks-transaction-signer.tsx +++ b/src/app/features/stacks-transaction-request/stacks-transaction-signer.tsx @@ -28,7 +28,7 @@ import { PostConditions } from '@app/features/stacks-transaction-request/post-co import { StxTransferDetails } from '@app/features/stacks-transaction-request/stx-transfer-details/stx-transfer-details'; import { TransactionError } from '@app/features/stacks-transaction-request/transaction-error/transaction-error'; import { useCurrentStacksAccountAnchoredBalances } from '@app/query/stacks/balance/stx-balance.hooks'; -import { useCalculateStacksTxFees } from '@app/query/stacks/fees/fees.hooks'; +import { useStacksFees } from '@app/query/stacks/fees/fees.hooks'; import { useNextNonce } from '@app/query/stacks/nonce/account-nonces.hooks'; import { useTransactionRequestState } from '@app/store/transactions/requests.hooks'; import { Link } from '@app/ui/components/link/link'; @@ -53,7 +53,7 @@ export function StacksTransactionSigner({ isMultisig, }: StacksTransactionSignerProps) { const transactionRequest = useTransactionRequestState(); - const { data: stxFees } = useCalculateStacksTxFees(stacksTransaction); + const stxFees = useStacksFees(stacksTransaction); const analytics = useAnalytics(); const { data: stacksBalances } = useCurrentStacksAccountAnchoredBalances(); const navigate = useNavigate(); diff --git a/src/app/pages/send/send-crypto-asset-form/form/stacks-sip10/use-sip10-send-form.tsx b/src/app/pages/send/send-crypto-asset-form/form/stacks-sip10/use-sip10-send-form.tsx index 10fe5b0a81b..7cecfbf95e1 100644 --- a/src/app/pages/send/send-crypto-asset-form/form/stacks-sip10/use-sip10-send-form.tsx +++ b/src/app/pages/send/send-crypto-asset-form/form/stacks-sip10/use-sip10-send-form.tsx @@ -11,7 +11,7 @@ import { convertAmountToBaseUnit } from '@app/common/money/calculate-money'; import { formatContractId } from '@app/common/utils'; import { stacksFungibleTokenAmountValidator } from '@app/common/validation/forms/amount-validators'; import { useStacksFungibleTokenAssetBalance } from '@app/query/stacks/balance/stacks-ft-balances.hooks'; -import { useCalculateStacksTxFees } from '@app/query/stacks/fees/fees.hooks'; +import { useStacksFees } from '@app/query/stacks/fees/fees.hooks'; import { useFtTokenTransferUnsignedTx, useGenerateFtTokenTransferUnsignedTx, @@ -31,7 +31,7 @@ export function useSip10SendForm({ symbol, contractId }: UseSip10SendFormArgs) { const sendFormNavigate = useSendFormNavigate(); const unsignedTx = useFtTokenTransferUnsignedTx(assetBalance); - const { data: stacksFtFees } = useCalculateStacksTxFees(unsignedTx); + const stacksFtFees = useStacksFees(unsignedTx); const availableTokenBalance = assetBalance.balance; const sendMaxBalance = useMemo( 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 ae39961fc94..afbcdb3796f 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 @@ -15,7 +15,7 @@ import { } from '@app/common/validation/forms/amount-validators'; import { stxFeeValidator } from '@app/common/validation/forms/fee-validators'; import { useUpdatePersistedSendFormValues } from '@app/features/popup-send-form-restoration/use-update-persisted-send-form-values'; -import { useCalculateStacksTxFees } from '@app/query/stacks/fees/fees.hooks'; +import { useStacksFees } from '@app/query/stacks/fees/fees.hooks'; import { useStacksValidateFeeByNonce } from '@app/query/stacks/mempool/mempool.hooks'; import { useGenerateStxTokenTransferUnsignedTx, @@ -27,8 +27,7 @@ import { useStacksCommonSendForm } from '../stacks/use-stacks-common-send-form'; export function useStxSendForm() { const unsignedTx = useStxTokenTransferUnsignedTxState(); - const { data: stxFees } = useCalculateStacksTxFees(unsignedTx); - + const stxFees = useStacksFees(unsignedTx); const generateTx = useGenerateStxTokenTransferUnsignedTx(); const { onFormStateChange } = useUpdatePersistedSendFormValues(); diff --git a/src/app/pages/transaction-request/transaction-request.tsx b/src/app/pages/transaction-request/transaction-request.tsx index e565a736125..241983c8e4f 100644 --- a/src/app/pages/transaction-request/transaction-request.tsx +++ b/src/app/pages/transaction-request/transaction-request.tsx @@ -33,7 +33,7 @@ import { StxTransferDetails } from '@app/features/stacks-transaction-request/stx import { SubmitAction } from '@app/features/stacks-transaction-request/submit-action'; import { TransactionError } from '@app/features/stacks-transaction-request/transaction-error/transaction-error'; import { useCurrentStacksAccountAnchoredBalances } from '@app/query/stacks/balance/stx-balance.hooks'; -import { useCalculateStacksTxFees } from '@app/query/stacks/fees/fees.hooks'; +import { useStacksFees } from '@app/query/stacks/fees/fees.hooks'; import { useNextNonce } from '@app/query/stacks/nonce/account-nonces.hooks'; import { useTransactionRequestState } from '@app/store/transactions/requests.hooks'; import { @@ -49,7 +49,7 @@ function TransactionRequestBase() { const { setIsLoading, setIsIdle } = useLoading(LoadingKeys.SUBMIT_TRANSACTION_REQUEST); // const handleBroadcastTransaction = useSoftwareWalletTransactionRequestBroadcast(); const unsignedTx = useUnsignedStacksTransactionBaseState(); - const { data: stxFees } = useCalculateStacksTxFees(unsignedTx.transaction); + const stxFees = useStacksFees(unsignedTx.transaction); const analytics = useAnalytics(); const generateUnsignedTx = useGenerateUnsignedStacksTransaction(); const { data: stacksBalances } = useCurrentStacksAccountAnchoredBalances(); diff --git a/src/app/query/stacks/fees/fees.hooks.ts b/src/app/query/stacks/fees/fees.hooks.ts index 766de8ab51c..6f759fe515e 100644 --- a/src/app/query/stacks/fees/fees.hooks.ts +++ b/src/app/query/stacks/fees/fees.hooks.ts @@ -6,6 +6,7 @@ import { logger } from '@shared/logger'; import { FeeCalculationTypes, Fees } from '@shared/models/fees/fees.model'; import { StacksFeeEstimate, StacksTxFeeEstimation } from '@shared/models/fees/stacks-fees.model'; import { Money, createMoney } from '@shared/models/money.model'; +import { isUndefined } from '@shared/utils'; import { useConfigFeeEstimationsMaxEnabled, @@ -136,3 +137,9 @@ export function useCalculateStacksTxFees(unsignedTx?: StacksTransaction) { }), }); } + +export function useStacksFees(unsignedTx?: StacksTransaction) { + const { data: stxFees } = useCalculateStacksTxFees(unsignedTx); + if (isUndefined(stxFees)) return defaultStacksFees; + return stxFees; +}