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
5 changes: 4 additions & 1 deletion packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import type { ERC20Bytes32 } from '@masknet/web3-contracts/types/ERC20Bytes32'
import { useERC20TokenContract, useERC20TokenContracts } from '../contracts/useERC20TokenContract'
import { useERC20TokenBytes32Contract, useERC20TokenBytes32Contracts } from '../contracts/useERC20TokenBytes32Contract'
import { parseStringOrBytes32, createERC20Token, createNativeToken } from '../utils'
import { useEthereumTokenType } from './useEthereumTokenType'

export function useERC20TokenDetailed(address?: string, token?: Partial<ERC20TokenDetailed>, targetChainId?: ChainId) {
const currentChainId = useChainId()
const chainId = targetChainId ?? currentChainId
const erc20TokenContract = useERC20TokenContract(address, chainId)
const erc20TokenBytes32Contract = useERC20TokenBytes32Contract(address, chainId)
const tokenType = useEthereumTokenType(address)

return useAsyncRetry(async () => {
if (!address) return
if (!EthereumAddress.isValid(address)) return
if (tokenType !== EthereumTokenType.ERC20) return
return getERC20TokenDetailed(address, chainId, erc20TokenContract, erc20TokenBytes32Contract, token)
}, [chainId, token, erc20TokenContract, erc20TokenBytes32Contract, address])
}, [chainId, token, erc20TokenContract, erc20TokenBytes32Contract, address, tokenType])
}

export function useFungibleTokensDetailed(listOfToken: Pick<FungibleToken, 'address' | 'type'>[], _chainId?: ChainId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web3-shared/evm/hooks/useEthereumTokenType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function useCheckERC1155(address: string) {
return useERC165(erc1155Contract, address, ERC1155_ENUMERABLE_INTERFACE_ID)
}

export function useEthereumTokenType(address: string): EthereumTokenType | undefined {
export function useEthereumTokenType(address = ''): EthereumTokenType | undefined {
const { value: isContract, loading: loadingContract } = useCheckContract(address)
const { value: isERC721, loading: loadingERC721 } = useCheckERC721(address)
const { value: isERC1155, loading: loadingERC1155 } = useCheckERC1155(address)
Expand Down