Skip to content

Commit

Permalink
fix: native token estimated gas.
Browse files Browse the repository at this point in the history
---

- don't pass `params.gas` if no estimated gas queried on Send UI
  • Loading branch information
richardo2016x committed May 6, 2024
1 parent ff7cfc8 commit 29fd8cb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
12 changes: 12 additions & 0 deletions patches/@debank+common+0.3.60.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/node_modules/@debank/common/dist/chain.d.ts b/node_modules/@debank/common/dist/chain.d.ts
index ae0b2d4..70873af 100644
--- a/node_modules/@debank/common/dist/chain.d.ts
+++ b/node_modules/@debank/common/dist/chain.d.ts
@@ -2,6 +2,7 @@ import { CHAINS_ENUM, ChainRaw } from "./chain-data";
export declare type Chain = ChainRaw & {
logo: string;
whiteLogo?: string;
+ needEstimateGas?: boolean;
};
export { CHAINS_ENUM } from "./chain-data";
export declare const MAINNET_CHAINS_LIST: Array<Chain>;
1 change: 1 addition & 0 deletions src/background/service/customTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface TestnetChain extends TestnetChainBase {
isTestnet?: boolean;
logo: string;
whiteLogo?: string;
needEstimateGas?: boolean;
}

export interface RPCItem {
Expand Down
22 changes: 17 additions & 5 deletions src/ui/views/SendToken/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint "react-hooks/exhaustive-deps": ["error"] */
import React, { useState, useCallback, useEffect, useMemo } from 'react';
import ClipboardJS from 'clipboard';
import clsx from 'clsx';
import BigNumber from 'bignumber.js';
import { Trans, useTranslation } from 'react-i18next';
Expand All @@ -19,6 +19,7 @@ import {
MINIMUM_GAS_LIMIT,
CAN_ESTIMATE_L1_FEE_CHAINS,
ARB_LIKE_L2_CHAINS,
L2_ENUMS,
} from 'consts';
import { useRabbyDispatch, useRabbySelector, connectStore } from 'ui/store';
import { Account, ChainGas } from 'background/service/preference';
Expand Down Expand Up @@ -428,7 +429,7 @@ const SendToken = () => {
</>
),
};
}, [temporaryGrant, whitelist, toAddressInWhitelist, whitelistEnabled]);
}, [t, temporaryGrant, toAddressInWhitelist, whitelistEnabled]);

const canSubmit =
isValidAddress(form.getFieldValue('to')) &&
Expand Down Expand Up @@ -578,6 +579,10 @@ const SendToken = () => {
}

params.value = `0x${sendValue.toString(16)}`;
const noEstimateGasRequired =
!ARB_LIKE_L2_CHAINS.includes(chain.enum) &&
!L2_ENUMS.includes(chain.enum);

try {
const code = await wallet.requestETHRpc(
{
Expand All @@ -586,17 +591,21 @@ const SendToken = () => {
},
chain.serverId
);
if (estimateGas > 0) {
/**
* we dont' need always fetch estimateGas, if no `params.gas` set below,
* `params.gas` would be filled on Tx Page.
*/
if (chain.needEstimateGas && estimateGas > 0) {
params.gas = intToHex(estimateGas);
} else if (
code &&
(code === '0x' || code === '0x0') &&
!ARB_LIKE_L2_CHAINS.includes(chain.enum)
noEstimateGasRequired
) {
params.gas = intToHex(21000); // L2 has extra validation fee so can not set gasLimit as 21000 when send native token
}
} catch (e) {
if (!ARB_LIKE_L2_CHAINS.includes(chain.enum)) {
if (noEstimateGasRequired) {
params.gas = intToHex(21000); // L2 has extra validation fee so can not set gasLimit as 21000 when send native token
}
}
Expand Down Expand Up @@ -1066,6 +1075,7 @@ const SendToken = () => {
if (inited) {
initByCache();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [inited]);

const getAlianName = async () => {
Expand Down Expand Up @@ -1156,12 +1166,14 @@ const SendToken = () => {
return () => {
wallet.clearPageStateCache();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (currentAccount) {
getAlianName();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentAccount]);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export function supportedChainToChain(item: SupportedChain): Chain {
nativeTokenLogo: item.native_token?.logo,
nativeTokenDecimals: item.native_token?.decimals,
nativeTokenAddress: item.native_token?.id,
// needEstimateGas: item.need_estimate_gas,
needEstimateGas: item.need_estimate_gas,
scanLink: `${item.explorer_host}/${
item.id === 'heco' ? 'transaction' : 'tx'
}/_s_`,
Expand Down

0 comments on commit 29fd8cb

Please sign in to comment.