Skip to content

Commit

Permalink
fix: fix a out of gas error
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Feb 19, 2025
1 parent d1a788c commit fa96a35
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function makeGasInfoBy(
}

const gasWantedBN = BigNumber(gasUsed).multipliedBy(safetyMargin);
const gasFeeBN = gasWantedBN.multipliedBy(gasPrice);
const gasFeeBN = BigNumber(gasUsed).multipliedBy(gasPrice);

return {
gasWanted: Number(gasWantedBN.toFixed(0, BigNumber.ROUND_DOWN)),
Expand Down Expand Up @@ -81,7 +81,7 @@ export const useGetEstimateGasInfo = (
return null;
}

const modifiedDocument = modifyDocument(document, gasWanted, gasFee);
const modifiedDocument = modifyDocument(document, gasWanted * 100, gasFee);

const result = await transactionGasService
.estimateGas(documentToDefaultTx(modifiedDocument))
Expand Down
6 changes: 3 additions & 3 deletions packages/adena-extension/src/hooks/wallet/use-network-fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const useNetworkFee = (
const current = gasPriceTiers.find((setting) => setting.settingType === currentSettingType);

return current?.gasInfo || null;
}, [currentSettingType, gasPriceTiers]);
}, [gasPriceTiers, currentSettingType]);

const changedGasInfo = useMemo(() => {
if (!gasPriceTiers) {
Expand All @@ -86,7 +86,7 @@ export const useNetworkFee = (
}, [changedSettingType, gasPriceTiers]);

const currentGasFeeRawAmount = useMemo(() => {
if (!selectedTier) {
if (!selectedTier && !currentGasInfo) {
return BigNumber(document?.fee.amount?.[0].amount || 0).toNumber();
}

Expand All @@ -97,7 +97,7 @@ export const useNetworkFee = (
const currentGasFeeAmount = BigNumber(currentGasInfo.gasFee).toFixed(0, BigNumber.ROUND_UP);

return Number(currentGasFeeAmount);
}, [currentGasInfo, document, selectedTier]);
}, [currentGasInfo?.gasFee, document, selectedTier]);

const networkFee = useMemo(() => {
if (!currentGasInfo) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEFAULT_GAS_WANTED } from '@common/constants/tx.constant';
import { MemoryProvider } from '@common/provider/memory/memory-provider';
import { AdenaExecutor } from '@inject/executor';
import { ContractMessage, TransactionParams } from '@inject/types';
Expand Down Expand Up @@ -125,7 +126,7 @@ function makeTransactionMessage(
gnoMessageInfo: GnoMessageInfo,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
gnoConnectInfo: GnoConnectInfo,
): TransactionParams {
): TransactionParams & { gasFee: number; gasWanted: number } {
const messages: ContractMessage[] = [
{
type: '/vm.m_call',
Expand All @@ -141,5 +142,7 @@ function makeTransactionMessage(

return {
messages,
gasFee: 0,
gasWanted: DEFAULT_GAS_WANTED,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ const ApproveTransactionContainer: React.FC = () => {

useEffect(() => {
updateTransactionData();
}, [memo, useNetworkFeeReturn.currentGasInfo]);
}, [
memo,
useNetworkFeeReturn.currentGasInfo?.gasWanted,
useNetworkFeeReturn.currentGasFeeRawAmount,
]);

const onClickCancel = (): void => {
chrome.runtime.sendMessage(
Expand Down

0 comments on commit fa96a35

Please sign in to comment.