Skip to content

Commit

Permalink
fix: adjust ens link content (DimensionDev#5636)
Browse files Browse the repository at this point in the history
* fix: adjust ens link content

* fix: add margin gas when calculating maxAmount
  • Loading branch information
albert-0229 authored Feb 11, 2022
1 parent 088d1ef commit 6702162
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MaskColorVar, MaskTextField } from '@masknet/theme'
import { Box, Button, IconButton, Link, Popover, Stack, Typography } from '@mui/material'
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import {
addGasMargin,
EthereumTokenType,
formatWeiToEther,
FungibleTokenDetailed,
Expand Down Expand Up @@ -110,7 +111,7 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {

const gasFee = useMemo(() => {
const price = is1559Supported && maxFee ? new BigNumber(maxFee) : gasPrice
return multipliedBy(gasLimit, price)
return multipliedBy(addGasMargin(gasLimit), price)
}, [gasLimit, gasPrice, maxFee, is1559Supported])
const gasFeeInUsd = formatWeiToEther(gasFee).multipliedBy(nativeTokenPrice)

Expand Down Expand Up @@ -176,12 +177,12 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {
if (resolveDomainLoading) return
if (registeredAddress) {
return (
<Link
href={Utils?.resolveDomainLink?.(address)}
target="_blank"
rel="noopener noreferrer"
underline="none">
<Box style={{ padding: 10 }}>
<Box style={{ padding: 10 }}>
<Link
href={Utils?.resolveDomainLink?.(address)}
target="_blank"
rel="noopener noreferrer"
underline="none">
<Typography
fontSize={16}
lineHeight="22px"
Expand All @@ -193,8 +194,8 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {
<Typography fontSize={14} lineHeight="20px" style={{ color: MaskColorVar.textSecondary }}>
<FormattedAddress address={registeredAddress} size={4} formatter={Utils?.formatAddress} />
</Typography>
</Box>
</Link>
</Link>
</Box>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ export const TransferERC721 = memo(() => {
if (resolveDomainLoading) return
if (registeredAddress) {
return (
<Link
href={Utils?.resolveDomainLink?.(allFormFields.recipient)}
target="_blank"
rel="noopener noreferrer"
underline="none">
<Box style={{ padding: 10 }}>
<Box style={{ padding: 10 }}>
<Link
href={Utils?.resolveDomainLink?.(allFormFields.recipient)}
target="_blank"
rel="noopener noreferrer"
underline="none">
<Typography
fontSize={16}
lineHeight="22px"
Expand All @@ -242,8 +242,8 @@ export const TransferERC721 = memo(() => {
<Typography fontSize={14} lineHeight="20px" style={{ color: MaskColorVar.textSecondary }}>
<FormattedAddress address={registeredAddress} size={4} formatter={Utils?.formatAddress} />
</Typography>
</Box>
</Link>
</Link>
</Box>
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { memo, ReactElement, SyntheticEvent, useCallback, useMemo, useRef, useState } from 'react'
import { useI18N } from '../../../../../utils'
import {
addGasMargin,
Asset,
EthereumTokenType,
formatBalance,
Expand Down Expand Up @@ -364,7 +365,8 @@ export const Transfer1559 = memo<Transfer1559Props>(({ selectedAsset, openAssetM
)

const maxAmount = useMemo(() => {
const gasFee = formatGweiToWei(maxFeePerGas ?? 0).multipliedBy(MIN_GAS_LIMIT)
const gasFee = formatGweiToWei(new BigNumber(maxFeePerGas ?? 0)).multipliedBy(addGasMargin(MIN_GAS_LIMIT))

let amount_ = new BigNumber(tokenBalance ?? 0)
amount_ = selectedAsset?.token.type === EthereumTokenType.Native ? amount_.minus(gasFee) : amount_
return formatBalance(amount_.toFixed(), selectedAsset?.token.decimals)
Expand Down Expand Up @@ -455,12 +457,12 @@ export const Transfer1559 = memo<Transfer1559Props>(({ selectedAsset, openAssetM

if (registeredAddress && !resolveDomainError && Utils?.resolveDomainLink)
return (
<Link
href={Utils.resolveDomainLink(address)}
target="_blank"
rel="noopener noreferrer"
underline="none">
<Box display="flex" justifyContent="space-between" alignItems="center" py={2.5} px={1.5}>
<Box display="flex" justifyContent="space-between" alignItems="center" py={2.5} px={1.5}>
<Link
href={Utils.resolveDomainLink(address)}
target="_blank"
rel="noopener noreferrer"
underline="none">
<Box>
<Typography className={classes.domainName}>{address}</Typography>
<Typography className={classes.registeredAddress}>
Expand All @@ -471,9 +473,9 @@ export const Transfer1559 = memo<Transfer1559Props>(({ selectedAsset, openAssetM
/>
</Typography>
</Box>
<RightIcon />
</Box>
</Link>
</Link>
<RightIcon />
</Box>
)

return
Expand Down

0 comments on commit 6702162

Please sign in to comment.