Skip to content

Commit

Permalink
fix: handle simulation error
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Jan 13, 2025
1 parent 1a40447 commit 0ef73ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class GnoProvider extends GnoJSONRPCProvider {

const simulateResult = parseProto(responseValue, ResponseDeliverTx.decode);
if (simulateResult.responseBase?.error) {
console.warn('Failed to estimate gas', simulateResult.responseBase.error);
throw new Error(`Failed to estimate gas: ${simulateResult.responseBase.error.typeUrl}`);
}

return simulateResult.gasUsed.toInt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GasToken } from '@common/constants/token.constant';
import { DEFAULT_GAS_FEE } from '@common/constants/tx.constant';
import { Tx } from '@gnolang/tm2-js-client';
import { useAdenaContext, useWalletContext } from '@hooks/use-context';
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
Expand All @@ -25,7 +26,8 @@ function makeSimulateTx(document: Document, gasAmount: string): Tx {
function makeTokenAmountWithDecimals(amount: string | number, decimals: number): string {
return BigNumber(amount)
.shiftedBy(decimals * -1)
.toFixed(decimals, BigNumber.ROUND_DOWN);
.toFixed(decimals, BigNumber.ROUND_DOWN)
.replace(/\.?0+$/, '');
}

export const useGetEstimateGas = (
Expand All @@ -48,7 +50,7 @@ export const useGetEstimateGas = (
);

const estimatedGasAmounts = await Promise.all(
simulateTxs.map((tx) => transactionGasService.estimateGas(tx).catch(() => 0)),
simulateTxs.map((tx) => transactionGasService.estimateGas(tx).catch(() => DEFAULT_GAS_FEE)),
);

return gasPriceTiers.map((tier, index) => {
Expand Down

0 comments on commit 0ef73ae

Please sign in to comment.