forked from DimensionDev/Maskbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bugfix for zrx (DimensionDev#5891)
* fix: replace gas source from zrx api to web3 api * chore: reply review
- Loading branch information
1 parent
439e9dc
commit 973f999
Showing
3 changed files
with
34 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 17 additions & 5 deletions
22
packages/mask/src/plugins/Trader/trader/0x/useTradeGasLimit.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
import type { TradeComputed, SwapQuoteResponse } from '../../types' | ||
import { useMemo } from 'react' | ||
import { TargetChainIdContext } from '../useTargetChainIdContext' | ||
import BigNumber from 'bignumber.js' | ||
import { SUPPORTED_CHAIN_ID_LIST } from './constants' | ||
import { useAccount, useWeb3 } from '@masknet/web3-shared-evm' | ||
import { pick } from 'lodash-unified' | ||
import { useAsync } from 'react-use' | ||
|
||
export function useTradeGasLimit(tradeComputed: TradeComputed<SwapQuoteResponse> | null) { | ||
const { targetChainId } = TargetChainIdContext.useContainer() | ||
|
||
return useMemo(() => { | ||
if (!tradeComputed?.trade_ || !SUPPORTED_CHAIN_ID_LIST.includes(targetChainId)) return 0 | ||
return new BigNumber(tradeComputed.trade_.gas).toNumber() | ||
}, [targetChainId, tradeComputed]) | ||
const web3 = useWeb3({ chainId: targetChainId }) | ||
const account = useAccount() | ||
const config = useMemo(() => { | ||
if (!account || !tradeComputed?.trade_) return null | ||
return { | ||
from: account, | ||
...pick(tradeComputed.trade_, ['to', 'data', 'value']), | ||
} | ||
}, [account, tradeComputed]) | ||
|
||
return useAsync(async () => { | ||
if (!tradeComputed?.trade_ || !SUPPORTED_CHAIN_ID_LIST.includes(targetChainId) || !config) return 0 | ||
return web3.eth.estimateGas(config) | ||
}, [targetChainId, tradeComputed, config, web3]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters