Skip to content

Commit

Permalink
fix: bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Dec 9, 2024
1 parent 6289527 commit b38f96d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 66 deletions.
16 changes: 11 additions & 5 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4927,7 +4927,7 @@ export class WalletController extends BaseController {
}
) => {
let chainId: string;
let tx: any;
let tx: Tx | undefined;

if ('tx' in params) {
if (params.tx.nonce === undefined) {
Expand All @@ -4947,10 +4947,16 @@ export class WalletController extends BaseController {
params.tx.data = '0x';
}
chainId = params.chain.serverId;
tx = params.tx;
delete tx.isSend;
delete tx.isSwap;
delete tx.swapPreferMEVGuarded;
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;
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Approval/components/MiniSignTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -851,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
1 change: 1 addition & 0 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1997,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
68 changes: 8 additions & 60 deletions src/ui/views/SendToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { query2obj } from 'ui/utils/url';
import { formatTokenAmount, splitNumberByStep } from 'ui/utils/number';
import AccountCard from '../Approval/components/AccountCard';
import TokenAmountInput from 'ui/component/TokenAmountInput';
import { GasLevel, TokenItem } from 'background/service/openapi';
import { GasLevel, TokenItem, Tx } from 'background/service/openapi';
import { PageHeader, AddressViewer } from 'ui/component';
import ContactEditModal from 'ui/component/Contact/EditModal';
import ContactListModal from 'ui/component/Contact/ListModal';
Expand Down Expand Up @@ -461,21 +461,6 @@ const SendToken = () => {
const isNativeToken =
!!chainItem && currentToken?.id === chainItem.nativeTokenAddress;

const fetchGasList = useCallback(async () => {
const list: GasLevel[] = chainItem?.isTestnet
? await wallet.getCustomTestnetGasMarket({ chainId: chainItem.id })
: await wallet.openapi.gasMarket(chainItem?.serverId || '');
return list;
}, [wallet, chainItem]);

const [{ value: gasList }, loadGasList] = useAsyncFn(() => {
return fetchGasList();
}, [fetchGasList]);

useEffect(() => {
loadGasList();
}, [loadGasList]);

useDebounce(
async () => {
const targetChain = findChainByEnum(chain)!;
Expand Down Expand Up @@ -634,51 +619,14 @@ const SendToken = () => {
const chain = findChain({
serverId: currentToken.chain,
})!;
const sendValue = new BigNumber(amount)
.multipliedBy(10 ** currentToken.decimals)
.decimalPlaces(0, BigNumber.ROUND_DOWN);
const dataInput = [
{
name: 'transfer',
type: 'function',
inputs: [
{
type: 'address',
name: 'to',
},
{
type: 'uint256',
name: 'value',
},
] as any[],
} as const,
[to, sendValue.toFixed(0)] as any[],
] as const;
const params: Record<string, any> = {
chainId: chain.id,
from: currentAccount!.address,
to: currentToken.id,
value: '0x0',
data: abiCoder.encodeFunctionCall(dataInput[0], dataInput[1]),
isSend: true,
};
if (safeInfo?.nonce != null) {
params.nonce = safeInfo.nonce;
}
if (isNativeToken) {
params.to = to;
delete params.data;

if (isShowMessageDataForToken && messageDataForSendToEoa) {
const encodedValue = formatTxInputDataOnERC20(messageDataForSendToEoa)
.hexData;

params.data = encodedValue;
} else if (isShowMessageDataForContract && messageDataForContractCall) {
params.data = messageDataForContractCall;
}
const params = getParams({
to,
amount,
messageDataForSendToEoa,
messageDataForContractCall,
});

params.value = `0x${sendValue.toString(16)}`;
if (isNativeToken) {
// L2 has extra validation fee so we can not set gasLimit as 21000 when send native token
const couldSpecifyIntrinsicGas = !CAN_NOT_SPECIFY_INTRINSIC_GAS_CHAINS.includes(
chain.enum
Expand Down

0 comments on commit b38f96d

Please sign in to comment.