Skip to content
Closed
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 @@ -6,14 +6,13 @@ import {
formatWeiToEther,
FungibleTokenDetailed,
isEIP1559Supported,
isSameAddress,
isZeroAddress,
TransactionStateType,
useChainId,
useFungibleTokenBalance,
useGasLimit,
useGasPrice,
useNativeTokenDetailed,
useTokenConstants,
useTokenTransferCallback,
} from '@masknet/web3-shared-evm'
import { isGreaterThan, isZero, multipliedBy, rightShift } from '@masknet/web3-shared-base'
Expand All @@ -38,7 +37,6 @@ interface TransferERC20Props {
const GAS_LIMIT = 30000
export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {
const t = useDashboardI18N()
const { NATIVE_TOKEN_ADDRESS } = useTokenConstants()
const anchorEl = useRef<HTMLDivElement | null>(null)
const [id] = useState(uuid())
const [amount, setAmount] = useState('')
Expand Down Expand Up @@ -73,7 +71,7 @@ export const TransferERC20 = memo<TransferERC20Props>(({ token }) => {
}, [token])

// workaround: transferERC20 should support non-evm network
const isNativeToken = isSameAddress(selectedToken?.address, NATIVE_TOKEN_ADDRESS)
const isNativeToken = isZeroAddress(selectedToken?.address)
const tokenType = isNativeToken ? EthereumTokenType.Native : EthereumTokenType.ERC20
Comment thread
guanbinrui marked this conversation as resolved.

// balance
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/components/shared/TokenPrice.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FC, HTMLProps } from 'react'
import type BigNumber from 'bignumber.js'
import { ChainId, CurrencyType, isSameAddress, ZERO_ADDRESS } from '@masknet/web3-shared-evm'
import { ChainId, CurrencyType, isZeroAddress } from '@masknet/web3-shared-evm'
import { useNativeTokenPrice, useTokenPrice } from '../../plugins/Wallet/hooks/useTokenPrice'
import { multipliedBy } from '@masknet/web3-shared-base'

Expand All @@ -20,6 +20,6 @@ export const TokenPrice: FC<TokenPriceProps> = ({
}) => {
const tokenPrice = useTokenPrice(chainId, contractAddress?.toLowerCase(), currencyType)
const nativeTokenPrice = useNativeTokenPrice(chainId)
const price = isSameAddress(contractAddress, ZERO_ADDRESS) ? nativeTokenPrice : tokenPrice
const price = isZeroAddress(contractAddress) ? nativeTokenPrice : tokenPrice
return <span {...rest}>${multipliedBy(amount, price).toFixed(2)}</span>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EthereumMethodType,
getChainDetailedCAIP,
ZERO_ADDRESS,
isZeroAddress,
} from '@masknet/web3-shared-evm'
import type { TransactionConfig } from 'web3-core'
import type { JsonRpcPayload } from 'web3-core-helpers'
Expand Down Expand Up @@ -132,7 +133,7 @@ export async function getSendTransactionComputedPayload(payload: JsonRpcPayload)
}

// contract deployment
if (isSameAddress(to, ZERO_ADDRESS)) {
if (isZeroAddress(to)) {
return {
type: EthereumRpcType.CONTRACT_DEPLOYMENT,
code: data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {
EthereumMethodType,
EthereumRpcType,
EthereumTransactionConfig,
ZERO_ADDRESS,
isEIP1559Supported,
isSameAddress,
ProviderType,
SendOverrides,
isZeroAddress,
} from '@masknet/web3-shared-evm'
import type { IJsonRpcRequest } from '@walletconnect/types'
import * as MetaMask from './providers/MetaMask'
Expand Down Expand Up @@ -138,7 +138,7 @@ async function handleTransferTransaction(chainId: ChainId, payload: JsonRpcPaylo
const from = (computedPayload._tx.from as string) ?? ''
const to = getTo(computedPayload)

if (!isSameAddress(from, to) && !isSameAddress(to, ZERO_ADDRESS)) await WalletRPC.addAddress(chainId, to)
if (!isSameAddress(from, to) && !isZeroAddress(to)) await WalletRPC.addAddress(chainId, to)
}

function handleRecentTransaction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EthereumTokenType,
formatEthereumAddress,
getChainDetailed,
isSameAddress,
} from '@masknet/web3-shared-evm'
import { groupBy } from 'lodash-unified'

Expand Down Expand Up @@ -56,7 +57,7 @@ async function fetch1inchERC20TokensFromTokenList(
const tokens = ((await fetchTokenList(url)) as TokenObject).tokens
const _tokens = Object.values(tokens)
return _tokens
.filter((x) => x.address.toLowerCase() !== NATIVE_TOKEN_ADDRESS_IN_1INCH)
.filter((x) => !isSameAddress(x.address, NATIVE_TOKEN_ADDRESS_IN_1INCH))
.map((x) => ({
type: EthereumTokenType.ERC20,
...x,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ERC721TokenDetailed,
EthereumTokenType,
FungibleTokenDetailed,
isNative,
isZeroAddress,
} from '@masknet/web3-shared-evm'
import { useSnackbarCallback } from '@masknet/shared'
import { WalletRPC } from '../../../../plugins/Wallet/messages'
Expand Down Expand Up @@ -52,7 +52,7 @@ export function DashboardWalletHideTokenConfirmDialog(
props.onClose,
)

if (isNative(tokenAddress)) return null
if (isZeroAddress(tokenAddress)) return null
return (
<DashboardDialogCore fullScreen={false} {...props}>
<DashboardDialogWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Button, Link, List } from '@mui/material'
import {
ChainId,
EthereumRpcType,
isNative,
isZeroAddress,
isSameAddress,
resolveTransactionLinkOnExplorer,
useChainId,
Expand Down Expand Up @@ -104,7 +104,8 @@ export const ActivityList = memo<ActivityListProps>(({ tokenAddress }) => {
const dataSource =
transactions?.filter((transaction) => {
if (!tokenAddress) return true
else if (isNative(tokenAddress)) return transaction.computedPayload?.type === EthereumRpcType.SEND_ETHER
else if (isZeroAddress(tokenAddress))
return transaction.computedPayload?.type === EthereumRpcType.SEND_ETHER
else if (
transaction.computedPayload?.type === EthereumRpcType.CONTRACT_INTERACTION &&
(transaction.computedPayload?.name === 'transfer' ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { makeStyles } from '@masknet/theme'
import {
EthereumTokenType,
FungibleTokenDetailed,
isNative,
isZeroAddress,
FungibleTokenWatched,
useAccount,
} from '@masknet/web3-shared-evm'
Expand Down Expand Up @@ -99,7 +99,7 @@ export function ListingByHighestBidCard(props: ListingByHighestBidCardProps) {
amount={amount}
balance={balance.value ?? '0'}
token={token.value as FungibleTokenDetailed}
disableNativeToken={!paymentTokens.some((x) => isNative(x.address))}
disableNativeToken={!paymentTokens.some(isZeroAddress)}
onAmountChange={setAmount}
onTokenChange={setToken}
TokenAmountPanelProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { makeStyles } from '@masknet/theme'
import {
EthereumTokenType,
FungibleTokenDetailed,
isNative,
isZeroAddress,
FungibleTokenWatched,
useAccount,
} from '@masknet/web3-shared-evm'
Expand Down Expand Up @@ -143,7 +143,7 @@ export function ListingByPriceCard(props: ListingByPriceCardProps) {
amount={amount}
balance={balance.value ?? '0'}
token={token.value as FungibleTokenDetailed}
disableNativeToken={!paymentTokens.some((x) => isNative(x.address))}
disableNativeToken={!paymentTokens.some(isZeroAddress)}
onAmountChange={setAmount}
onTokenChange={setToken}
TokenAmountPanelProps={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
FungibleTokenDetailed,
EthereumTokenType,
useAccount,
isNative,
isZeroAddress,
useFungibleTokenWatched,
} from '@masknet/web3-shared-evm'
import formatDateTime from 'date-fns/format'
Expand Down Expand Up @@ -167,7 +167,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) {
amount={amount}
balance={balance.value ?? '0'}
token={token.value as FungibleTokenDetailed}
disableNativeToken={!paymentTokens.some((x) => isNative(x.address))}
disableNativeToken={!paymentTokens.some(isZeroAddress)}
onAmountChange={setAmount}
onTokenChange={setToken}
TokenAmountPanelProps={{
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/plugins/Collectible/hooks/useEvents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAsyncRetry } from 'react-use'
import { ChainId, useChainId, ZERO_ADDRESS, isSameAddress } from '@masknet/web3-shared-evm'
import { ChainId, useChainId, isZeroAddress } from '@masknet/web3-shared-evm'
import { CollectibleToken, NFTHistory, CollectibleProvider, OpenSeaAssetEventType } from '../types'
import { PluginCollectibleRPC } from '../messages'
import { NullAddress, OpenSeaAccountURL } from '../constants'
Expand Down Expand Up @@ -92,7 +92,7 @@ export function useEvents(provider: CollectibleProvider, token?: CollectibleToke
accountPair: {
from: event.fromInfo
? {
username: isSameAddress(event.fromInfo?.id, ZERO_ADDRESS)
username: isZeroAddress(event.fromInfo?.id)
? NullAddress
: event.fromInfo?.name,
address: event.fromInfo?.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DialogContent, Box, Card, CardContent, CardActions, Link } from '@mui/m
import { makeStyles } from '@masknet/theme'
import { first } from 'lodash-unified'
import BigNumber from 'bignumber.js'
import { FungibleTokenDetailed, isNative, useFungibleTokenWatched, useChainId } from '@masknet/web3-shared-evm'
import { FungibleTokenDetailed, isZeroAddress, useFungibleTokenWatched, useChainId } from '@masknet/web3-shared-evm'
import { useI18N } from '../../../utils'
import { InjectedDialog } from '../../../components/shared/InjectedDialog'
import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton'
Expand Down Expand Up @@ -213,7 +213,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) {
amount={amount}
balance={balance.value ?? '0'}
token={token.value as FungibleTokenDetailed}
disableNativeToken={!paymentTokens.some((x: any) => isNative(x.address))}
disableNativeToken={!paymentTokens.some(isZeroAddress)}
onAmountChange={setAmount}
onTokenChange={setToken}
TokenAmountPanelProps={{
Expand Down
13 changes: 5 additions & 8 deletions packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
getERC721TokenAssetFromChain,
getEthereumConstants,
getRPCConstants,
getTokenConstants,
isZeroAddress,
isSameAddress,
NATIVE_TOKEN_ADDRESS,
NonFungibleAssetProvider,
Web3ProviderType,
} from '@masknet/web3-shared-evm'
Expand All @@ -37,7 +38,6 @@ export const getFungibleAssetsFn =

const web3 = new Web3(provider)
const { BALANCE_CHECKER_ADDRESS } = getEthereumConstants(chainId)
const { NATIVE_TOKEN_ADDRESS } = getTokenConstants()
const dataFromProvider = await context.getAssetsList(address, FungibleAssetProvider.DEBANK)
const assetsFromProvider: Web3Plugin.Asset<Web3Plugin.FungibleToken>[] = dataFromProvider.map((x) => ({
id: x.token.address,
Expand Down Expand Up @@ -89,15 +89,12 @@ export const getFungibleAssetsFn =
const nativeTokens: Web3Plugin.Asset<Web3Plugin.FungibleToken>[] = networks
.filter(
(t) =>
t.isMainnet &&
!allTokens.find(
(x) => x.token.chainId === t.chainId && isSameAddress(x.token.id, NATIVE_TOKEN_ADDRESS),
),
t.isMainnet && !allTokens.find((x) => x.token.chainId === t.chainId && isZeroAddress(x.token.id)),
)
.map((x) => ({
id: NATIVE_TOKEN_ADDRESS!,
id: NATIVE_TOKEN_ADDRESS,
chainId: x.chainId,
token: { ...createNativeToken(x.chainId), id: NATIVE_TOKEN_ADDRESS!, type: TokenType.Fungible },
token: { ...createNativeToken(x.chainId), id: NATIVE_TOKEN_ADDRESS, type: TokenType.Fungible },
balance: '0',
}))

Expand Down
10 changes: 3 additions & 7 deletions packages/mask/src/plugins/EVM/UI/Web3State/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
isValidDomain,
resolveDomainLink,
formatDomainName,
ZERO_ADDRESS,
isZeroAddress,
} from '@masknet/web3-shared-evm'
import Ens from 'ethjs-ens'
import { getStorage } from '../../storage'
Expand Down Expand Up @@ -66,11 +66,7 @@ export function fixWeb3State(state?: Web3Plugin.ObjectCapabilities.Capabilities,
network: chainId,
}).lookup(domain)

if (
isSameAddress(address, ZERO_ADDRESS) ||
isSameAddress(address, ZERO_X_ERROR_ADDRESS) ||
!isValidAddress(address)
) {
if (isZeroAddress(address) || isSameAddress(address, ZERO_X_ERROR_ADDRESS) || !isValidAddress(address)) {
return undefined
}

Expand Down Expand Up @@ -103,7 +99,7 @@ export function fixWeb3State(state?: Web3Plugin.ObjectCapabilities.Capabilities,
network: chainId,
}).reverse(address)

if (isSameAddress(domain, ZERO_ADDRESS) || isSameAddress(domain, ZERO_X_ERROR_ADDRESS)) {
if (isZeroAddress(domain) || isSameAddress(domain, ZERO_X_ERROR_ADDRESS)) {
return undefined
}

Expand Down
5 changes: 2 additions & 3 deletions packages/mask/src/plugins/EVM/utils/token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Web3Plugin } from '@masknet/plugin-infra'
import { CurrencyType, formatBalance, getTokenConstants, isSameAddress } from '@masknet/web3-shared-evm'
import { CurrencyType, formatBalance, isZeroAddress } from '@masknet/web3-shared-evm'

// TODO: remove
export const getTokenUSDValue = (token: Web3Plugin.Asset) =>
Expand All @@ -9,8 +9,7 @@ export const getBalanceValue = (asset: Web3Plugin.Asset<Web3Plugin.FungibleToken
Number.parseFloat(formatBalance(asset.balance, asset.token.decimals))

export const getTokenChainIdValue = (asset: Web3Plugin.Asset) => {
const { NATIVE_TOKEN_ADDRESS } = getTokenConstants()
return isSameAddress(asset.token.id, NATIVE_TOKEN_ADDRESS) ? 1 / asset.token.chainId : 0
return isZeroAddress(asset.token.id) ? 1 / asset.token.chainId : 0
}

export const makeSortAssertWithoutChainFn = () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/plugins/GoodGhosting/hooks/useGameInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
isSameAddress,
isZeroAddress,
useAccount,
useGoodGhostingConstants,
useSingleContractMultipleData,
Expand Down Expand Up @@ -101,7 +101,7 @@ export function useGameInfo(gameData: GameMetaData) {
adaiTokenAddress: adaiToken,
lendingPoolAddress: lendingPool,
earlyWithdrawalFee,
currentPlayer: !isSameAddress(player?.addr, ZERO_ADDRESS) ? player : undefined,
currentPlayer: !isZeroAddress(player?.addr) ? player : undefined,
gameHasEnded: Number.parseInt(currentSegment, 10) > Number.parseInt(lastSegment, 10),
refresh: asyncResult.retry,
} as GoodGhostingInfo
Expand Down
4 changes: 2 additions & 2 deletions packages/mask/src/plugins/ITO/SNSAdaptor/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
formatBalance,
formatEthereumAddress,
FungibleTokenDetailed,
isNative,
isZeroAddress,
resolveAddressLinkOnExplorer,
resolveTokenLinkOnExplorer,
useChainId,
Expand Down Expand Up @@ -152,7 +152,7 @@ export function ConfirmDialog(props: ConfirmDialogProps) {
<Typography variant="body1" component="span">
{poolSettings?.token?.symbol}
</Typography>
{isNative(poolSettings?.token?.address!) ? null : (
{isZeroAddress(poolSettings?.token?.address) ? null : (
<Link
className={classes.link}
href={resolveTokenLinkOnExplorer(poolSettings?.token!)}
Expand Down
11 changes: 4 additions & 7 deletions packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import {
formatEthereumAddress,
FungibleTokenDetailed,
getChainDetailed,
isSameAddress,
currySameAddress,
resolveLinkOnExplorer,
TransactionStateType,
useAccount,
useChainId,
useChainIdValid,
useTokenConstants,
isZeroAddress,
isSameAddress,
} from '@masknet/web3-shared-evm'
import { isZero, ZERO, isGreaterThan } from '@masknet/web3-shared-base'
import { Box, Card, Grid, Link, Typography } from '@mui/material'
Expand Down Expand Up @@ -198,8 +198,6 @@ interface TokenItemProps {

const TokenItem = ({ price, token, exchangeToken }: TokenItemProps) => {
const { classes } = useStyles({})
const { NATIVE_TOKEN_ADDRESS } = useTokenConstants()

return (
<>
<TokenIcon
Expand All @@ -209,7 +207,7 @@ const TokenItem = ({ price, token, exchangeToken }: TokenItemProps) => {
/>
<Typography component="span">
<strong>{price}</strong>{' '}
{isSameAddress(exchangeToken.address, NATIVE_TOKEN_ADDRESS)
{isZeroAddress(exchangeToken.address)
? getChainDetailed(exchangeToken.chainId)?.nativeCurrency.symbol
: exchangeToken.symbol}{' '}
/ {token.symbol}
Expand Down Expand Up @@ -285,8 +283,7 @@ export function ITO(props: ITO_Props) {
} = useIfQualified(qualificationAddress, payload.contract_address)
//#endregion

const isAccountSeller =
payload.seller.address.toLowerCase() === account.toLowerCase() && chainId === payload.chain_id
const isAccountSeller = isSameAddress(payload.seller.address, account) && chainId === payload.chain_id
const noRemain = total_remaining.isZero()

//#region remote controlled select provider dialog
Expand Down
Loading