Skip to content

Commit 455f764

Browse files
committed
fix: gas fees
1 parent ee608ee commit 455f764

File tree

3 files changed

+25
-82
lines changed

3 files changed

+25
-82
lines changed

wallets/rn_cli_wallet/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ android {
8989
applicationId "com.walletconnect.web3wallet.rnsample"
9090
minSdkVersion rootProject.ext.minSdkVersion
9191
targetSdkVersion rootProject.ext.targetSdkVersion
92-
versionCode 51
92+
versionCode 52
9393
versionName "1.0"
9494
resValue "string", "build_config_package", "com.walletconnect.web3wallet.rnsample"
9595
}

wallets/rn_cli_wallet/src/modals/SessionSendTransactionModal.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import {BridgeBadge} from '@/components/BridgeBadge';
1616
import {
1717
calculateEip155Gas,
1818
getNonce,
19-
getTransactionGas,
2019
getTransferDetails,
2120
} from '@/utils/EIP155WalletUtil';
2221
import {isVerified} from '@/utils/HelperUtil';
2322
import {VerifiedDomain} from '@/components/VerifiedDomain';
2423
import {Loader} from '@/components/Loader';
24+
import {ethers} from 'ethers';
2525

2626
export default function SessionSendTransactionModal() {
2727
const {data} = useSnapshot(ModalStore.state);
@@ -111,7 +111,7 @@ export default function SessionSendTransactionModal() {
111111
gasLimit: fees.gasLimit,
112112
});
113113
console.log('fees updated', fees);
114-
setNetworkFee(`${fees.totalGas} ETH`);
114+
setNetworkFee(`${ethers.utils.formatEther(fees.gasLimit)} ETH`);
115115
setFetchingGas(false);
116116
};
117117

@@ -152,7 +152,7 @@ export default function SessionSendTransactionModal() {
152152
const txData = {
153153
...tx,
154154
gasLimit: tx.gas,
155-
...(await getTransactionGas(tx, tx.chainId)),
155+
...(await calculateEip155Gas(tx, tx.chainId)),
156156
};
157157
delete txData.gas;
158158
delete txData.gasPrice;
@@ -166,11 +166,7 @@ export default function SessionSendTransactionModal() {
166166
);
167167
const txData = {
168168
...transaction,
169-
gasLimit: routes.initialTransaction?.gas || {
170-
hex: '0x05b6a8',
171-
type: 'BigNumber',
172-
},
173-
...(await getTransactionGas(transaction, chainId)),
169+
...(await calculateEip155Gas(transaction, chainId)),
174170
};
175171
delete txData.gas;
176172
delete txData.gasPrice;

wallets/rn_cli_wallet/src/utils/EIP155WalletUtil.ts

Lines changed: 20 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ export async function replaceMnemonic(mnemonicOrPrivateKey: string) {
6161
export async function calculateEip155Gas(transaction: any, chainId: string) {
6262
console.log('calculateEip155Gas:', chainId);
6363
const chainData = PresetsUtil.getChainData(parseChainId(chainId));
64-
console.log('chainData:');
65-
// Define the sender (from) and receiver (to) addresses
66-
const from = transaction.from;
67-
const to = transaction.to; // Could be a contract address
68-
const data = transaction.data; // Some contract interaction data
69-
70-
// Prepare the transaction object
71-
const tx = {
72-
from: from,
73-
to: to,
74-
data: data,
75-
};
76-
7764
let provider = new ethers.providers.JsonRpcProvider(chainData.rpcUrl);
7865

7966
// Fetch the latest block to get the base fee
@@ -90,56 +77,26 @@ export async function calculateEip155Gas(transaction: any, chainId: string) {
9077
// Calculate the max fee per gas (base fee + priority fee)
9178
const maxFeePerGas = baseFee!.add(maxPriorityFeePerGas);
9279

93-
try {
94-
// use this node to estimate gas as it doesn't reject when the amount is greater than the balance
95-
// very useful for chain abstraction
96-
provider = new ethers.providers.JsonRpcProvider(
97-
'https://endpoints.omniatech.io/v1/arbitrum/one/public',
98-
);
99-
100-
// Estimate the gas limit for this transaction based on its size and complexity
101-
const gasLimit = await provider.estimateGas(tx);
102-
103-
// Log the details of the gas fees
104-
console.log(
105-
'Base Fee:',
106-
ethers.utils.formatUnits(baseFee!, 'gwei'),
107-
'Gwei',
108-
);
109-
console.log(
110-
'Max Priority Fee:',
111-
ethers.utils.formatUnits(maxPriorityFeePerGas, 'gwei'),
112-
'Gwei',
113-
);
114-
console.log(
115-
'Max Fee per Gas:',
116-
ethers.utils.formatUnits(maxFeePerGas, 'gwei'),
117-
'Gwei',
118-
);
119-
console.log('Estimated Gas Limit:', gasLimit.toString());
120-
121-
// The total gas cost (just as an example, no sign and send in this code)
122-
const estimatedGasCost = gasLimit.mul(maxFeePerGas);
123-
console.log('Estimated Gas Cost (Wei):', estimatedGasCost.toString());
124-
125-
return {
126-
maxFeePerGas: ethers.utils.formatUnits(maxFeePerGas, 'wei'),
127-
maxPriorityFeePerGas: ethers.utils.formatUnits(
128-
maxPriorityFeePerGas,
129-
'wei',
130-
),
131-
gasLimit,
132-
totalGas: ethers.utils.formatUnits(estimatedGasCost, 'ether'),
133-
};
134-
} catch (error) {
135-
console.error('Error fetching gas fees:', error);
136-
return {
137-
gasLimit: {hex: '0x05b6a8', type: 'BigNumber'},
138-
maxFeePerGas: maxFeePerGas,
139-
maxPriorityFeePerGas: '1100000',
140-
totalGas: '0.00000020607740523',
141-
};
142-
}
80+
const gasLimit = ethers.BigNumber.from(0x05b6a8);
81+
// Log the details of the gas fees
82+
console.log('Base Fee:', ethers.utils.formatUnits(baseFee!, 'gwei'), 'Gwei');
83+
console.log(
84+
'Max Priority Fee:',
85+
ethers.utils.formatUnits(maxPriorityFeePerGas, 'gwei'),
86+
'Gwei',
87+
);
88+
console.log(
89+
'Max Fee per Gas:',
90+
ethers.utils.formatUnits(maxFeePerGas, 'gwei'),
91+
'Gwei',
92+
);
93+
console.log('Estimated Gas Limit:', gasLimit.toString());
94+
95+
return {
96+
maxFeePerGas: ethers.utils.formatUnits(maxFeePerGas, 'wei'),
97+
maxPriorityFeePerGas: ethers.utils.formatUnits(maxPriorityFeePerGas, 'wei'),
98+
gasLimit: ethers.utils.formatUnits(gasLimit, 'wei'),
99+
};
143100
}
144101

145102
const fetchGasPrice = async (chainId: string) => {
@@ -153,16 +110,6 @@ const fetchGasPrice = async (chainId: string) => {
153110
return data?.data;
154111
};
155112

156-
export async function getTransactionGas(tx: any, chainId: string) {
157-
const chainData = PresetsUtil.getChainData(parseChainId(chainId));
158-
const provider = new ethers.providers.JsonRpcProvider(chainData.rpcUrl);
159-
const feeData = await provider.getFeeData();
160-
return {
161-
maxFeePerGas: feeData.maxFeePerGas,
162-
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
163-
};
164-
}
165-
166113
export async function calculateGasLimit(tx: any, chainId: string) {
167114
const chainData = PresetsUtil.getChainData(parseChainId(chainId));
168115
const provider = new ethers.providers.JsonRpcProvider(chainData.rpcUrl);

0 commit comments

Comments
 (0)