Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ export const Prior1559GasSetting = memo(() => {
}, [value, setValue, chainId])

useUpdateEffect(() => {
if (gas) setValue('gasLimit', new BigNumber(gas).toString())
}, [gas, setValue])
const gasLimit = minGasLimit || gas
if (gasLimit) setValue('gasLimit', new BigNumber(gasLimit).toString())
}, [minGasLimit, gas, setValue])

useEffect(() => {
if (selected !== null) setValue('gasPrice', formatWeiToGwei(options[selected].gasPrice).toString())
Expand Down Expand Up @@ -266,7 +267,10 @@ export const Prior1559GasSetting = memo(() => {
<Typography>{formatWeiToGwei(gasPrice ?? 0).toString()} Gwei</Typography>
<Typography className={classes.gasUSD}>
{t('popups_wallet_gas_fee_settings_usd', {
usd: formatWeiToEther(gasPrice).times(nativeTokenPrice).times(21000).toPrecision(3),
usd: formatWeiToEther(gasPrice)
.times(nativeTokenPrice)
.times(minGasLimit || 21000)
.toPrecision(3),
})}
</Typography>
</div>
Expand Down
21 changes: 19 additions & 2 deletions packages/mask/src/plugins/Wallet/apis/debank.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HistoryResponse, GasPriceDictResponse, WalletTokenRecord } from '../types'
import urlcat from 'urlcat'
import { ChainId, getDeBankConstants } from '@masknet/web3-shared-evm'
import { ChainId, formatGweiToWei, getDeBankConstants } from '@masknet/web3-shared-evm'

const DEBANK_API = 'https://api.debank.com'
const DEBANK_OPEN_API = 'https://openapi.debank.com'
Expand All @@ -23,13 +23,30 @@ export async function getAssetsList(address: string) {
}
}

const auroraChainOnDebank = getDeBankConstants(ChainId.Aurora).CHAIN_ID
const fieldKeys = ['fast', 'normal', 'slow'] as const
/**
* Debank's data might be outdated, like gas price for aurora which requires 1 Gwei at least
* https://twitter.com/AlexAuroraDev/status/1490353255817302016
* Once debank fixes it, we will remove this modifier.
*/
function gasModifier(gasDict: GasPriceDictResponse, chain: string) {
if (chain === auroraChainOnDebank) {
fieldKeys.forEach((fieldKey) => {
const field = gasDict.data[fieldKey]
field.price = Math.max(field.price, formatGweiToWei(1).toNumber())
})
}
return gasDict
}

export async function getGasPriceDict(chainId: ChainId) {
const { CHAIN_ID = '' } = getDeBankConstants(chainId)
if (!CHAIN_ID) return null
const response = await fetch(urlcat(DEBANK_API, '/chain/gas_price_dict_v2', { chain: CHAIN_ID }))
const result = await response.json()
if (result.error_code === 0) {
return result as GasPriceDictResponse
return gasModifier(result as GasPriceDictResponse, CHAIN_ID)
}
return null
}