Skip to content

Commit

Permalink
fix: fee estimation error
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Jan 20, 2024
1 parent 7d75f4a commit 8121ffe
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/app/pages/transaction-request/transaction-request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/app/query/stacks/fees/fees.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

0 comments on commit 8121ffe

Please sign in to comment.