Skip to content

Commit

Permalink
fix: tx req fee error, closes #4231
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Oct 25, 2023
1 parent d9bd157 commit 759316e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,6 +24,7 @@ export function useTransactionError() {
const transactionRequest = useTransactionRequestState();
const contractInterface = useContractInterface(transactionRequest as ContractCallPayload);
const { origin } = useDefaultRequestParams();
const { values } = useFormikContext<StacksTransactionFormValues>();

const currentAccount = useCurrentStacksAccount();
const { data: balances } = useCurrentStacksAccountAnchoredBalances();
Expand Down Expand Up @@ -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]);
}
17 changes: 9 additions & 8 deletions src/app/pages/transaction-request/transaction-request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ function TransactionRequestBase() {

return (
<Flex alignItems="center" flexDirection="column" p="loose" width="100%">
<PageTop />
<RequestingTabClosedWarningMessage />
<PostConditionModeWarning />
<TransactionError />
<PostConditions />
{transactionRequest.txType === 'contract_call' && <ContractCallDetails />}
{transactionRequest.txType === 'token_transfer' && <StxTransferDetails />}
{transactionRequest.txType === 'smart_contract' && <ContractDeployDetails />}
<Formik
initialValues={initialValues}
onSubmit={onSubmit}
Expand All @@ -124,6 +116,15 @@ function TransactionRequestBase() {
>
{() => (
<>
<PageTop />
<RequestingTabClosedWarningMessage />
<PostConditionModeWarning />
<TransactionError />
<PostConditions />
{transactionRequest.txType === 'contract_call' && <ContractCallDetails />}
{transactionRequest.txType === 'token_transfer' && <StxTransferDetails />}
{transactionRequest.txType === 'smart_contract' && <ContractDeployDetails />}

<NonceSetter />
<FeeForm fees={stxFees} />
<EditNonceButton
Expand Down

0 comments on commit 759316e

Please sign in to comment.