From 759316e5024c5d9586410543f0637230f0808f39 Mon Sep 17 00:00:00 2001 From: fbwoolf Date: Wed, 25 Oct 2023 15:40:56 -0500 Subject: [PATCH] fix: tx req fee error, closes #4231 --- .../hooks/use-transaction-error.ts | 16 +++++++++------- .../transaction-request/transaction-request.tsx | 17 +++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/app/features/stacks-transaction-request/hooks/use-transaction-error.ts b/src/app/features/stacks-transaction-request/hooks/use-transaction-error.ts index fc980743c07..41f0493d41a 100644 --- a/src/app/features/stacks-transaction-request/hooks/use-transaction-error.ts +++ b/src/app/features/stacks-transaction-request/hooks/use-transaction-error.ts @@ -2,10 +2,13 @@ import { useMemo } from 'react'; import { ContractCallPayload, TransactionTypes } from '@stacks/connect'; import BigNumber from 'bignumber.js'; +import { useFormikContext } from 'formik'; + +import { StacksTransactionFormValues } from '@shared/models/form.model'; import { useDefaultRequestParams } from '@app/common/hooks/use-default-request-search-params'; import { initialSearchParams } from '@app/common/initial-search-params'; -import { microStxToStx } from '@app/common/money/unit-conversion'; +import { stxToMicroStx } from '@app/common/money/unit-conversion'; import { validateStacksAddress } from '@app/common/stacks-utils'; import { TransactionErrorReason } from '@app/features/stacks-transaction-request/transaction-error/transaction-error'; import { useCurrentStacksAccountAnchoredBalances } from '@app/query/stacks/balance/stx-balance.hooks'; @@ -21,6 +24,7 @@ export function useTransactionError() { const transactionRequest = useTransactionRequestState(); const contractInterface = useContractInterface(transactionRequest as ContractCallPayload); const { origin } = useDefaultRequestParams(); + const { values } = useFormikContext(); const currentAccount = useCurrentStacksAccount(); const { data: balances } = useCurrentStacksAccountAnchoredBalances(); @@ -52,13 +56,11 @@ export function useTransactionError() { if (!transactionRequest.sponsored) { if (zeroBalance) return TransactionErrorReason.FeeInsufficientFunds; - if (transactionRequest.fee) { - const feeValue = microStxToStx(transactionRequest.fee); - if (feeValue.gte(balances?.stx.unlockedStx.amount)) - return TransactionErrorReason.FeeInsufficientFunds; - } + const feeValue = stxToMicroStx(values.fee); + if (feeValue.gte(balances?.stx.unlockedStx.amount)) + return TransactionErrorReason.FeeInsufficientFunds; } } return; - }, [contractInterface, balances, currentAccount, transactionRequest, origin]); + }, [origin, transactionRequest, balances, currentAccount, contractInterface, values.fee]); } diff --git a/src/app/pages/transaction-request/transaction-request.tsx b/src/app/pages/transaction-request/transaction-request.tsx index 330016ef3d7..54b69a7bd49 100644 --- a/src/app/pages/transaction-request/transaction-request.tsx +++ b/src/app/pages/transaction-request/transaction-request.tsx @@ -106,14 +106,6 @@ function TransactionRequestBase() { return ( - - - - - - {transactionRequest.txType === 'contract_call' && } - {transactionRequest.txType === 'token_transfer' && } - {transactionRequest.txType === 'smart_contract' && } {() => ( <> + + + + + + {transactionRequest.txType === 'contract_call' && } + {transactionRequest.txType === 'token_transfer' && } + {transactionRequest.txType === 'smart_contract' && } +