Skip to content

Commit

Permalink
fix: incorrect type when transfer erc20 (DimensionDev#5713)
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-0229 authored Feb 22, 2022
1 parent 77305eb commit 41b4a92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ import {
} from '@masknet/web3-shared-evm'
import { isGreaterThan, isZero, multipliedBy, rightShift } from '@masknet/web3-shared-base'
import BigNumber from 'bignumber.js'
import { NetworkPluginID, useLookupAddress, useNetworkDescriptor, useWeb3State } from '@masknet/plugin-infra'
import {
NetworkPluginID,
TokenType,
useLookupAddress,
useNetworkDescriptor,
useWeb3State,
Web3Plugin,
} from '@masknet/plugin-infra'
import { FormattedAddress, TokenAmountPanel, useRemoteControlledDialog } from '@masknet/shared'
import TuneIcon from '@mui/icons-material/Tune'
import { EthereumAddress } from 'wallet.ts'
Expand All @@ -34,7 +41,7 @@ import type { SelectTokenDialogEvent } from '@masknet/plugin-wallet'
import { RightIcon } from '@masknet/icons'

interface TransferERC20Props {
token: FungibleTokenDetailed
token: FungibleTokenDetailed | Web3Plugin.FungibleToken
}

const GAS_LIMIT = 21000
Expand Down Expand Up @@ -64,7 +71,7 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {

const { value: defaultGasPrice = '0' } = useGasPrice()

const [selectedToken, setSelectedToken] = useState<FungibleTokenDetailed>(token)
const [selectedToken, setSelectedToken] = useState<FungibleTokenDetailed | Web3Plugin.FungibleToken>(token)
const chainId = useChainId()
const is1559Supported = useMemo(() => isEIP1559Supported(chainId), [chainId])

Expand Down Expand Up @@ -97,7 +104,11 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {
// transfer amount
const transferAmount = rightShift(amount || '0', selectedToken.decimals).toFixed()
const erc20GasLimit = useGasLimit(
selectedToken.type,
selectedToken.type === TokenType.Fungible
? selectedToken.symbol === nativeToken.value?.symbol
? EthereumTokenType.Native
: EthereumTokenType.ERC20
: selectedToken.type,
selectedToken.address,
transferAmount,
EthereumAddress.isValid(address) ? address : registeredAddress,
Expand Down Expand Up @@ -274,12 +285,13 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {
</Popover>
</Box>
<Box mt={2}>
{/* TODO: Remove forced type conversion */}
<TokenAmountPanel
amount={amount}
maxAmount={maxAmount}
balance={tokenBalance}
label={t.wallets_transfer_amount()}
token={selectedToken}
token={selectedToken as FungibleTokenDetailed}
onAmountChange={setAmount}
SelectTokenChip={{
loading: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import { Box, Tab } from '@mui/material'
import { useTabs } from '@masknet/theme'
import { TabContext, TabList, TabPanel } from '@mui/lab'
import { TransferERC20 } from './TransferERC20'
import { ERC721TokenDetailed, FungibleTokenDetailed, useNativeTokenDetailed } from '@masknet/web3-shared-evm'
import { ERC721TokenDetailed, useNativeTokenDetailed } from '@masknet/web3-shared-evm'
import { useLocation } from 'react-router-dom'
import { useDashboardI18N } from '../../../../locales'
import { TransferERC721 } from './TransferERC721'
import { TransferTab } from './types'

import type { Web3Plugin } from '@masknet/plugin-infra'
const assetTabs = [TransferTab.Token, TransferTab.Collectibles] as const

export * from './types'

export const Transfer = memo(() => {
const t = useDashboardI18N()
const { state } = useLocation() as {
state: { token?: FungibleTokenDetailed; erc721Token?: ERC721TokenDetailed; type?: TransferTab } | null
state: { token?: Web3Plugin.FungibleToken; erc721Token?: ERC721TokenDetailed; type?: TransferTab } | null
}
const { value: nativeToken } = useNativeTokenDetailed()
const transferTabsLabel: Record<TransferTab, string> = {
Expand Down

0 comments on commit 41b4a92

Please sign in to comment.