Skip to content

Commit

Permalink
fix: gasMarketV2 (#2671)
Browse files Browse the repository at this point in the history
* wip: gasMarket

* fix: nonce

* fix: gasMarketV2

* fix: update api

* fix: bugs

* fix: icon

---------

Co-authored-by: vvvvvv1vvvvvv <[email protected]>
  • Loading branch information
heisenberg-2077 and vvvvvv1vvvvvv authored Dec 12, 2024
1 parent aeeaca9 commit 4d85fbc
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 89 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@rabby-wallet/gnosis-sdk": "1.3.9",
"@rabby-wallet/page-provider": "0.4.2",
"@rabby-wallet/rabby-action": "0.1.8",
"@rabby-wallet/rabby-api": "0.8.5",
"@rabby-wallet/rabby-api": "0.9.2",
"@rabby-wallet/rabby-security-engine": "2.0.7",
"@rabby-wallet/rabby-swap": "0.0.42",
"@rabby-wallet/widgets": "1.0.9",
Expand Down
54 changes: 54 additions & 0 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4913,6 +4913,60 @@ export class WalletController extends BaseController {
};

uninstalledSyncStatus = uninstalledService.syncStatus;

gasMarketV2 = async (
params:
| {
chain: Chain;
tx: Tx;
customGas?: number;
}
| {
chainId: string;
customGas?: number;
}
) => {
let chainId: string;
let tx: Tx | undefined;

if ('tx' in params) {
if (params.tx.nonce === undefined) {
params.tx.nonce = await this.getRecommendNonce({
from: params.tx.from,
chainId: params.chain.id,
});
}

if (params.tx.gasPrice === undefined || params.tx.gasPrice === '') {
params.tx.gasPrice = '0x0';
}
if (params.tx.gas === undefined || params.tx.gas === '') {
params.tx.gas = '0x0';
}
if (params.tx.data === undefined || params.tx.data === '') {
params.tx.data = '0x';
}
chainId = params.chain.serverId;
tx = {
chainId: params.tx.chainId,
data: params.tx.data,
from: params.tx.from,
gas: params.tx.gas,
nonce: params.tx.nonce,
to: params.tx.to,
value: params.tx.value,
gasPrice: params.tx.gasPrice,
};
} else {
chainId = params.chainId;
}

return openapiService.gasMarketV2({
customGas: params.customGas,
chainId,
tx,
});
};
}

const wallet = new WalletController();
Expand Down
1 change: 1 addition & 0 deletions src/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import {
default as LogoLedgerDark,
default as LogoLedgerWhite,
ReactComponent as RcLogoLedgerDark,
ReactComponent as RcLogoLedgerWhite,
} from 'ui/assets/walletlogo/ledger.svg';
import LogoLedgerDisable, {
ReactComponent as RcLogoLedgerDisable,
Expand Down
5 changes: 4 additions & 1 deletion src/ui/utils/sendTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export const sendTransaction = async ({
// get gas
let normalGas = gasLevel;
if (!normalGas) {
const gasMarket = await wallet.openapi.gasMarket(chainServerId);
const gasMarket = await wallet.gasMarketV2({
chain,
tx,
});
normalGas = gasMarket.find((item) => item.level === 'normal')!;
}

Expand Down
10 changes: 6 additions & 4 deletions src/ui/views/Approval/components/MiniSignTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,11 @@ export const MiniSignTx = ({
chain: Chain,
custom?: number
): Promise<GasLevel[]> => {
const list = await wallet.openapi.gasMarket(
chain.serverId,
custom && custom > 0 ? custom : undefined
);
const list = await wallet.gasMarketV2({
chain,
customGas: custom && custom > 0 ? custom : undefined,
tx: txs[0],
});
setGasList(list);
return list;
};
Expand Down Expand Up @@ -850,6 +851,7 @@ export const MiniSignTx = ({
className={clsx(task.status !== 'idle' && 'pointer-events-none')}
>
<GasSelectorHeader
tx={txs[0]}
gasAccountCost={gasAccountCost}
gasMethod={gasMethod}
onChangeGasMethod={setGasMethod}
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Approval/components/SignTestnetTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => {
<FooterBar
Header={
<GasSelectorHeader
tx={tx}
disabled={false}
isReady={isReady}
gasLimit={gasLimit}
Expand Down
10 changes: 6 additions & 4 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1339,10 +1339,11 @@ const SignTx = ({ params, origin }: SignTxProps) => {
chain: Chain,
custom?: number
): Promise<GasLevel[]> => {
const list = await wallet.openapi.gasMarket(
chain.serverId,
custom && custom > 0 ? custom : undefined
);
const list = await wallet.gasMarketV2({
chain,
customGas: custom && custom > 0 ? custom : undefined,
tx,
});
setGasList(list);
return list;
};
Expand Down Expand Up @@ -1996,6 +1997,7 @@ const SignTx = ({ params, origin }: SignTxProps) => {
<FooterBar
Header={
<GasSelectorHeader
tx={tx}
gasAccountCost={gasAccountCost}
gasMethod={gasMethod}
onChangeGasMethod={setGasMethod}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Input, Skeleton, Tooltip } from 'antd';
import { matomoRequestEvent } from '@/utils/matomo-request';
import { ValidateStatus } from 'antd/lib/form/FormItem';
import { GasLevel, TxPushType } from 'background/service/openapi';
import { GasLevel, Tx, TxPushType } from 'background/service/openapi';
import BigNumber from 'bignumber.js';
import clsx from 'clsx';
import {
Expand Down Expand Up @@ -58,6 +58,7 @@ export interface GasSelectorResponse extends GasLevel {
}

interface GasSelectorProps {
tx: Tx;
gasLimit: string | undefined;
gas: {
gasCostUsd: number | string | BigNumber;
Expand Down Expand Up @@ -298,6 +299,7 @@ const GasSelectorHeader = ({
gasMethod,
gasAccountCost,
onChangeGasMethod,
tx,
}: GasSelectorProps) => {
const wallet = useWallet();
const dispatch = useRabbyDispatch();
Expand Down Expand Up @@ -350,10 +352,11 @@ const GasSelectorHeader = ({

const loadCustomGasData = useCallback(
async (custom?: number): Promise<GasLevel> => {
const list = await wallet.openapi.gasMarket(
chain.serverId,
custom && custom > 0 ? custom : undefined
);
const list = await wallet.gasMarketV2({
chain,
customGas: custom && custom > 0 ? custom : undefined,
tx,
});
return list.find((item) => item.level === 'custom')!;
},
[]
Expand Down
4 changes: 3 additions & 1 deletion src/ui/views/Dashboard/components/GasPriceBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export const GasPriceBar: React.FC<Props> = ({ currentConnectedSiteChain }) => {
? await wallet.getCustomTestnetGasMarket({
chainId: chain?.id,
})
: await wallet.openapi.gasMarket(currentConnectedSiteChainNativeToken);
: await wallet.gasMarketV2({
chainId: currentConnectedSiteChainNativeToken,
});
const selectedGasPice = marketGas.find((item) => item.level === 'slow')
?.price;
if (selectedGasPice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const useDbkChainBridge = ({
);

const fetchGasPrice = useMemoizedFn(async (serverId: string) => {
const marketGas = await wallet.openapi.gasMarket(serverId);
const marketGas = await wallet.gasMarketV2({ chainId: serverId });
const selectedGasPice = marketGas.find((item) => item.level === 'normal');
return selectedGasPice;
});
Expand Down
Loading

0 comments on commit 4d85fbc

Please sign in to comment.