From 92c4d99fdbabdeb0872022100640cd0c5a4e528c Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Thu, 16 Dec 2021 16:13:40 +0800 Subject: [PATCH 01/17] refactor: some patches on 2.3.0 (#5214) * fix: getPastLog erorrs * refactor: hide entrance --- .../UI/components/ProviderIconClickBait.tsx | 3 ++ .../src/plugins/MaskBox/hooks/useContext.ts | 18 ++++----- .../hooks/useMaskBoxCreationSuccessEvent.ts | 40 ++++++++++++++----- packages/plugins/Flow/src/base.ts | 2 +- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/packages/mask/src/plugins/EVM/UI/components/ProviderIconClickBait.tsx b/packages/mask/src/plugins/EVM/UI/components/ProviderIconClickBait.tsx index f90765cf7fa9..eb5f9953ac41 100644 --- a/packages/mask/src/plugins/EVM/UI/components/ProviderIconClickBait.tsx +++ b/packages/mask/src/plugins/EVM/UI/components/ProviderIconClickBait.tsx @@ -81,6 +81,9 @@ export function ProviderIconClickBait({ if (providerType === ProviderType.Fortmatic && !isFortmaticSupported(getChainIdFromNetworkType(networkType))) return null + // hide fortmatic and coin98 wallets + if (providerType === ProviderType.Fortmatic || providerType === ProviderType.Coin98) return null + // coinbase and mathwallet are blocked by CSP if ([ProviderType.WalletLink, ProviderType.MathWallet].includes(providerType)) return null diff --git a/packages/mask/src/plugins/MaskBox/hooks/useContext.ts b/packages/mask/src/plugins/MaskBox/hooks/useContext.ts index 008ba79f0c54..1ef558b50ea1 100644 --- a/packages/mask/src/plugins/MaskBox/hooks/useContext.ts +++ b/packages/mask/src/plugins/MaskBox/hooks/useContext.ts @@ -1,5 +1,8 @@ import { useEffect, useMemo, useState, useCallback } from 'react' import { useAsyncRetry } from 'react-use' +import fromUnixTime from 'date-fns/fromUnixTime' +import addDays from 'date-fns/addDays' +import subDays from 'date-fns/subDays' import { omit, clamp, first, uniq } from 'lodash-unified' import BigNumber from 'bignumber.js' import { createContainer } from 'unstated-next' @@ -80,28 +83,25 @@ function useContext(initialState?: { boxId: string }) { loading: loadingBoxInfo, retry: retryBoxInfo, } = useAsyncRetry(async () => { - if ( - !maskBoxInfo || - !maskBoxStatus || - isSameAddress(maskBoxInfo?.creator ?? ZERO_ADDRESS, ZERO_ADDRESS) || - !maskBoxCreationSuccessEvent - ) + if (!maskBoxInfo || !maskBoxStatus || isSameAddress(maskBoxInfo?.creator ?? ZERO_ADDRESS, ZERO_ADDRESS)) return null const personalLimit = Number.parseInt(maskBoxInfo.personal_limit, 10) const remaining = Number.parseInt(maskBoxStatus.remaining, 10) const sold = Number.parseInt(maskBoxStatus.total, 10) - remaining const personalRemaining = Math.max(0, personalLimit - purchasedTokens.length) + const startAt = Number.parseInt(maskBoxCreationSuccessEvent?.returnValues.start_time ?? '0', 10) + const endAt = Number.parseInt(maskBoxCreationSuccessEvent?.returnValues.end_time ?? '0', 10) const info: BoxInfo = { boxId, creator: maskBoxInfo.creator, name: maskBoxInfo.name, - sellAll: maskBoxCreationSuccessEvent.returnValues.sell_all, + sellAll: maskBoxCreationSuccessEvent?.returnValues.sell_all ?? false, personalLimit: personalLimit, personalRemaining, remaining, availableAmount: Math.min(personalRemaining, remaining), - startAt: new Date(Number.parseInt(maskBoxCreationSuccessEvent.returnValues.start_time, 10) * 1000), - endAt: new Date(Number.parseInt(maskBoxCreationSuccessEvent.returnValues.end_time, 10) * 1000), + startAt: startAt === 0 ? subDays(new Date(), 1) : fromUnixTime(startAt), + endAt: endAt === 0 ? addDays(new Date(), 1) : fromUnixTime(endAt), total: maskBoxStatus.total, sold, canceled: maskBoxStatus.canceled, diff --git a/packages/mask/src/plugins/MaskBox/hooks/useMaskBoxCreationSuccessEvent.ts b/packages/mask/src/plugins/MaskBox/hooks/useMaskBoxCreationSuccessEvent.ts index 6ebc77683e77..29befa81153e 100644 --- a/packages/mask/src/plugins/MaskBox/hooks/useMaskBoxCreationSuccessEvent.ts +++ b/packages/mask/src/plugins/MaskBox/hooks/useMaskBoxCreationSuccessEvent.ts @@ -1,24 +1,42 @@ import { first } from 'lodash-unified' import { useAsyncRetry } from 'react-use' import type { CreationSuccess } from '@masknet/web3-contracts/types/MaskBox' -import { useMaskBoxConstants } from '@masknet/web3-shared-evm' +import { useBlockNumber, useMaskBoxConstants } from '@masknet/web3-shared-evm' import { useMaskBoxContract } from './useMaskBoxContract' +// dynamically set the block range window size +const FRAGMENT_SIZE = 5000 +const MAX_PAGE_SIZE = 10 + export function useMaskBoxCreationSuccessEvent(creatorAddress: string, tokenAddress: string, boxId: string) { + const blockNumber = useBlockNumber() const maskBoxContract = useMaskBoxContract() - const { MASK_BOX_CONTRACT_FROM_BLOCK } = useMaskBoxConstants() + const { MASK_BOX_CONTRACT_FROM_BLOCK = Math.max(0, blockNumber - FRAGMENT_SIZE) } = useMaskBoxConstants() return useAsyncRetry(async () => { if (!maskBoxContract) return null - const events = await maskBoxContract.getPastEvents('CreationSuccess', { - filter: { - creator: creatorAddress, - nft_address: tokenAddress, - box_id: boxId, - }, - fromBlock: MASK_BOX_CONTRACT_FROM_BLOCK, - }) + + const getPastEvents = (fromBlock: number, toBlock: number) => { + return maskBoxContract.getPastEvents('CreationSuccess', { + filter: { + creator: creatorAddress, + nft_address: tokenAddress, + box_id: boxId, + }, + fromBlock, + toBlock, + }) + } + + const range = blockNumber - MASK_BOX_CONTRACT_FROM_BLOCK + const size = Math.min(MAX_PAGE_SIZE, Math.ceil(range / FRAGMENT_SIZE)) + const allSettled = await Promise.allSettled( + Array.from({ length: size }).map((_, index) => + getPastEvents(blockNumber - FRAGMENT_SIZE * (index + 1), blockNumber - FRAGMENT_SIZE * index - 1), + ), + ) + const events = allSettled.flatMap((x) => (x.status === 'fulfilled' ? x.value : [])) const filtered = (events as unknown as CreationSuccess[]).filter((evt) => evt.returnValues.box_id === boxId) return first(filtered) - }, [boxId, creatorAddress, tokenAddress, maskBoxContract, MASK_BOX_CONTRACT_FROM_BLOCK]) + }, [boxId, creatorAddress, tokenAddress, maskBoxContract, blockNumber, MASK_BOX_CONTRACT_FROM_BLOCK]) } diff --git a/packages/plugins/Flow/src/base.ts b/packages/plugins/Flow/src/base.ts index ff7430a31978..8319d9170670 100644 --- a/packages/plugins/Flow/src/base.ts +++ b/packages/plugins/Flow/src/base.ts @@ -11,7 +11,7 @@ export const base: Plugin.Shared.Definition = { enableRequirement: { architecture: { app: true, web: true }, networks: { type: 'opt-out', networks: {} }, - target: 'stable', + target: 'insider', }, i18n: languages, declareApplicationCategories: [], From 74a1f79a44d481be393f1a9913440f639d0ee9c0 Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Sun, 12 Dec 2021 02:47:54 +0800 Subject: [PATCH 02/17] chore: bump version to 2.3.0 --- package.json | 2 +- packages/mask/src/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b5167d71b2f2..738af928e06b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mask-network", "packageManager": "pnpm@6.23.1", - "version": "2.2.0", + "version": "2.3.0", "private": true, "license": "AGPL-3.0-or-later", "scripts": { diff --git a/packages/mask/src/manifest.json b/packages/mask/src/manifest.json index 6e8fbad1fdae..d46e6a243549 100644 --- a/packages/mask/src/manifest.json +++ b/packages/mask/src/manifest.json @@ -1,6 +1,6 @@ { "name": "Mask Network", - "version": "2.2.0", + "version": "2.3.0", "manifest_version": 2, "permissions": ["storage", "downloads", "webNavigation", "activeTab"], "optional_permissions": ["", "notifications", "clipboardRead"], From cdcb1bec16fc7ac73b88020e9d37d92f7197286e Mon Sep 17 00:00:00 2001 From: Lantt Date: Thu, 16 Dec 2021 17:33:15 +0800 Subject: [PATCH 03/17] fix: dashboard error when from assets list (#5191) --- .../Wallets/components/Transfer/TransferERC20.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx index 2ff4894d99cc..09b6b6ce44ab 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx @@ -6,12 +6,14 @@ import { formatWeiToEther, FungibleTokenDetailed, isEIP1559Supported, + isSameAddress, TransactionStateType, useChainId, useFungibleTokenBalance, useGasLimit, useGasPrice, useNativeTokenDetailed, + useTokenConstants, useTokenTransferCallback, } from '@masknet/web3-shared-evm' import { isGreaterThan, isZero, multipliedBy, rightShift } from '@masknet/web3-shared-base' @@ -36,6 +38,7 @@ interface TransferERC20Props { const GAS_LIMIT = 30000 export const TransferERC20 = memo(({ token }) => { const t = useDashboardI18N() + const { NATIVE_TOKEN_ADDRESS } = useTokenConstants() const anchorEl = useRef(null) const [id] = useState(uuid()) const [amount, setAmount] = useState('') @@ -71,7 +74,10 @@ export const TransferERC20 = memo(({ token }) => { // balance const { value: tokenBalance = '0', retry: tokenBalanceRetry } = useFungibleTokenBalance( - selectedToken?.type ?? EthereumTokenType.Native, + // workaround: transferERC20 should support non-evm network + isSameAddress(selectedToken?.address, NATIVE_TOKEN_ADDRESS) + ? EthereumTokenType.Native + : EthereumTokenType.ERC20, selectedToken?.address ?? '', ) const nativeToken = useNativeTokenDetailed() @@ -114,7 +120,7 @@ export const TransferERC20 = memo(({ token }) => { }, [tokenBalance, gasPrice, selectedToken?.type, amount]) const [transferState, transferCallback, resetTransferCallback] = useTokenTransferCallback( - selectedToken.type, + EthereumTokenType.ERC20, selectedToken.address, ) From 37d202361aa6002a0b73a3aa2a8904785996739f Mon Sep 17 00:00:00 2001 From: Hancheng Zhou Date: Thu, 16 Dec 2021 17:35:22 +0800 Subject: [PATCH 04/17] fix: twitter popup selector (#5216) --- .../src/social-network-adaptor/twitter.com/utils/selector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts index ec9dbd048940..fdf20af5e6d8 100644 --- a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts +++ b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts @@ -89,7 +89,7 @@ export const postEditorContentInPopupSelector: () => LiveSelector = () querySelector('[aria-labelledby="modal-header"] > div:first-child > div:nth-child(3)') export const postEditorInPopupSelector: () => LiveSelector = () => querySelector( - '[aria-labelledby="modal-header"] > div:first-child > div:nth-child(3) > div:first-child > div:first-child [role="button"][aria-label]:nth-child(6)', + '[aria-labelledby="modal-header"] > div:first-child > div:first-child > div:first-child > div:nth-child(3) > div:first-child > div:first-child [role="button"][aria-label]:nth-child(6)', ) export const toolBoxInSideBarSelector: () => LiveSelector = () => querySelector('[role="banner"] [role="navigation"] > div') From 1fc3a874ca26649d9f37c47f9090daee5c574062 Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Thu, 16 Dec 2021 19:55:54 +0800 Subject: [PATCH 05/17] fix: debank history api (#5221) --- packages/mask/src/plugins/Wallet/services/transactions.ts | 2 +- packages/mask/src/plugins/Wallet/types/debank.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/mask/src/plugins/Wallet/services/transactions.ts b/packages/mask/src/plugins/Wallet/services/transactions.ts index 1f5ded904a8e..6b72899bf5cf 100644 --- a/packages/mask/src/plugins/Wallet/services/transactions.ts +++ b/packages/mask/src/plugins/Wallet/services/transactions.ts @@ -63,7 +63,7 @@ function fromDeBank({ cate_dict, history_list, token_dict }: HistoryResponse['da .map((transaction) => { let type = transaction.tx?.name if (!type && !isNil(transaction.cate_id)) { - type = cate_dict[transaction.cate_id].en + type = cate_dict[transaction.cate_id].name } else if (type === '') { type = 'contract interaction' } diff --git a/packages/mask/src/plugins/Wallet/types/debank.ts b/packages/mask/src/plugins/Wallet/types/debank.ts index 9bede1241adf..15a8a03b27d1 100644 --- a/packages/mask/src/plugins/Wallet/types/debank.ts +++ b/packages/mask/src/plugins/Wallet/types/debank.ts @@ -5,8 +5,7 @@ export enum DebankTransactionDirection { export interface DictItem { id: string - cn: string - en: string + name: string } export interface ProjectItem { From dddb41279e1f3b178067e010d2480ecbcf9b7f17 Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Thu, 16 Dec 2021 20:12:48 +0800 Subject: [PATCH 06/17] fix: the remaining/total numbers (#5224) --- packages/mask/src/plugins/MaskBox/hooks/useContext.ts | 8 +++++--- packages/mask/src/plugins/MaskBox/type.ts | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/mask/src/plugins/MaskBox/hooks/useContext.ts b/packages/mask/src/plugins/MaskBox/hooks/useContext.ts index 1ef558b50ea1..74584edbc49a 100644 --- a/packages/mask/src/plugins/MaskBox/hooks/useContext.ts +++ b/packages/mask/src/plugins/MaskBox/hooks/useContext.ts @@ -86,8 +86,10 @@ function useContext(initialState?: { boxId: string }) { if (!maskBoxInfo || !maskBoxStatus || isSameAddress(maskBoxInfo?.creator ?? ZERO_ADDRESS, ZERO_ADDRESS)) return null const personalLimit = Number.parseInt(maskBoxInfo.personal_limit, 10) - const remaining = Number.parseInt(maskBoxStatus.remaining, 10) - const sold = Number.parseInt(maskBoxStatus.total, 10) - remaining + const remaining = Number.parseInt(maskBoxStatus.remaining, 10) // the current balance of the creator's account + const total = Number.parseInt(maskBoxStatus.total, 10) // the total amount of tokens in the box + const totalComputed = total && remaining && remaining > total ? remaining : total + const sold = Math.max(0, totalComputed - remaining) const personalRemaining = Math.max(0, personalLimit - purchasedTokens.length) const startAt = Number.parseInt(maskBoxCreationSuccessEvent?.returnValues.start_time ?? '0', 10) const endAt = Number.parseInt(maskBoxCreationSuccessEvent?.returnValues.end_time ?? '0', 10) @@ -102,7 +104,7 @@ function useContext(initialState?: { boxId: string }) { availableAmount: Math.min(personalRemaining, remaining), startAt: startAt === 0 ? subDays(new Date(), 1) : fromUnixTime(startAt), endAt: endAt === 0 ? addDays(new Date(), 1) : fromUnixTime(endAt), - total: maskBoxStatus.total, + total: totalComputed, sold, canceled: maskBoxStatus.canceled, tokenIds: allTokens, diff --git a/packages/mask/src/plugins/MaskBox/type.ts b/packages/mask/src/plugins/MaskBox/type.ts index 692564eb90f0..7f9426a78aa3 100644 --- a/packages/mask/src/plugins/MaskBox/type.ts +++ b/packages/mask/src/plugins/MaskBox/type.ts @@ -43,7 +43,7 @@ export interface BoxInfo { payments: PaymentInfo[] remaining: number availableAmount: number - total: string + total: number sold: number startAt: Date endAt: Date From 50d49046d46c189017d8a0af78f1ce770b2c8674 Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Thu, 16 Dec 2021 20:46:49 +0800 Subject: [PATCH 07/17] fix: debank api changes --- .../mask/src/plugins/Wallet/services/transactions.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/mask/src/plugins/Wallet/services/transactions.ts b/packages/mask/src/plugins/Wallet/services/transactions.ts index 6b72899bf5cf..8d104c129b52 100644 --- a/packages/mask/src/plugins/Wallet/services/transactions.ts +++ b/packages/mask/src/plugins/Wallet/services/transactions.ts @@ -75,20 +75,20 @@ function fromDeBank({ cate_dict, history_list, token_dict }: HistoryResponse['da failed: transaction.tx?.status === 0, pairs: [ ...transaction.sends.map(({ amount, token_id }) => ({ - name: token_dict[token_id].name, - symbol: token_dict[token_id].optimized_symbol, + name: token_dict[token_id]?.name, + symbol: token_dict[token_id]?.optimized_symbol, address: token_id, direction: DebankTransactionDirection.SEND, amount, logoURI: token_dict[token_id].logo_url, })), ...transaction.receives.map(({ amount, token_id }) => ({ - name: token_dict[token_id].name, - symbol: token_dict[token_id].optimized_symbol, + name: token_dict[token_id]?.name, + symbol: token_dict[token_id]?.optimized_symbol, address: token_id, direction: DebankTransactionDirection.RECEIVE, amount, - logoURI: token_dict[token_id].logo_url, + logoURI: token_dict[token_id]?.logo_url, })), ], gasFee: transaction.tx From 5ef4ffc4bcc21c1bdde401110f4a2e8983c8add5 Mon Sep 17 00:00:00 2001 From: Hancheng Zhou Date: Fri, 17 Dec 2021 14:37:04 +0800 Subject: [PATCH 08/17] fix: twitter popup selector (#5231) --- .../src/social-network-adaptor/twitter.com/utils/selector.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts index fdf20af5e6d8..62aa2b61f228 100644 --- a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts +++ b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts @@ -86,7 +86,9 @@ export const composeAnchorTextSelector: () => LiveSelector LiveSelector = () => - querySelector('[aria-labelledby="modal-header"] > div:first-child > div:nth-child(3)') + querySelector( + '[aria-labelledby="modal-header"] > div:first-child > div:first-child > div:first-child > div:nth-child(3)', + ) export const postEditorInPopupSelector: () => LiveSelector = () => querySelector( '[aria-labelledby="modal-header"] > div:first-child > div:first-child > div:first-child > div:nth-child(3) > div:first-child > div:first-child [role="button"][aria-label]:nth-child(6)', From 902fb4cfc4372a0d15e79147e502b8454a156bba Mon Sep 17 00:00:00 2001 From: nuanyang233 Date: Fri, 17 Dec 2021 14:39:38 +0800 Subject: [PATCH 09/17] fix: valid address and domain when transfer erc20 with ens (#5226) --- .../src/pages/Wallets/components/Transfer/TransferERC20.tsx | 3 ++- packages/mask/src/plugins/EVM/UI/Web3State/index.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx index 09b6b6ce44ab..6af44678640d 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx @@ -141,7 +141,8 @@ export const TransferERC20 = memo(({ token }) => { if (isGreaterThan(rightShift(amount, selectedToken.decimals), maxAmount)) return t.wallets_transfer_error_insufficient_balance({ symbol: selectedToken.symbol ?? '' }) if (!address) return t.wallets_transfer_error_address_absence() - if (!EthereumAddress.isValid(address)) return t.wallets_transfer_error_invalid_address() + if (!(EthereumAddress.isValid(address) || Utils?.isValidDomain?.(address))) + return t.wallets_transfer_error_invalid_address() if (Utils?.isValidDomain?.(address) && (resolveDomainError || !registeredAddress)) { if (network?.type !== NetworkType.Ethereum) return t.wallet_transfer_error_no_ens_support() return t.wallet_transfer_error_no_address_has_been_set_name() diff --git a/packages/mask/src/plugins/EVM/UI/Web3State/index.ts b/packages/mask/src/plugins/EVM/UI/Web3State/index.ts index 200c1a3dbb49..5d4de50d1f38 100644 --- a/packages/mask/src/plugins/EVM/UI/Web3State/index.ts +++ b/packages/mask/src/plugins/EVM/UI/Web3State/index.ts @@ -69,7 +69,7 @@ export function fixWeb3State(state?: Web3Plugin.ObjectCapabilities.Capabilities, if ( isSameAddress(address, ZERO_ADDRESS) || isSameAddress(address, ZERO_X_ERROR_ADDRESS) || - isValidAddress(address) + !isValidAddress(address) ) { return undefined } From 7c7594401a58763387b222e946f54f9890f48376 Mon Sep 17 00:00:00 2001 From: Lantt Date: Fri, 17 Dec 2021 14:59:17 +0800 Subject: [PATCH 10/17] fix: send eth can not call provider (#5228) --- .../Wallets/components/Transfer/TransferERC20.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx index 6af44678640d..3efa54345a95 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx @@ -72,17 +72,17 @@ export const TransferERC20 = memo(({ token }) => { setSelectedToken(token) }, [token]) + // workaround: transferERC20 should support non-evm network + const isNativeToken = isSameAddress(selectedToken?.address, NATIVE_TOKEN_ADDRESS) + const tokenType = isNativeToken ? EthereumTokenType.Native : EthereumTokenType.ERC20 + // balance const { value: tokenBalance = '0', retry: tokenBalanceRetry } = useFungibleTokenBalance( - // workaround: transferERC20 should support non-evm network - isSameAddress(selectedToken?.address, NATIVE_TOKEN_ADDRESS) - ? EthereumTokenType.Native - : EthereumTokenType.ERC20, + tokenType, selectedToken?.address ?? '', ) const nativeToken = useNativeTokenDetailed() const nativeTokenPrice = useNativeTokenPrice() - const isNativeToken = selectedToken.type === EthereumTokenType.Native //#region resolve ENS domain const { @@ -120,7 +120,7 @@ export const TransferERC20 = memo(({ token }) => { }, [tokenBalance, gasPrice, selectedToken?.type, amount]) const [transferState, transferCallback, resetTransferCallback] = useTokenTransferCallback( - EthereumTokenType.ERC20, + tokenType, selectedToken.address, ) From 2c2dfac15effc93d316102bb649aad8c3cd14faf Mon Sep 17 00:00:00 2001 From: nuanyang233 Date: Fri, 17 Dec 2021 14:59:59 +0800 Subject: [PATCH 11/17] fix: swap box bug (#5215) * fix: swap box bug * chore: reply review * fix: update chainId * fix: tokenlist and zero output amount * fix: show trade if it don't have estimate gas * fix: balance bug --- .../SNSAdaptor/trader/InputTokenPanel.tsx | 1 + .../Trader/SNSAdaptor/trader/Trader.tsx | 49 ++++++++++++++----- .../Trader/SNSAdaptor/trader/TraderDialog.tsx | 9 +++- .../UI/components/ERC20TokenList/index.tsx | 13 +++-- .../evm/hooks/useERC20TokenBalance.ts | 3 +- 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx index 2068c15fa765..722de799b0dc 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/InputTokenPanel.tsx @@ -23,6 +23,7 @@ const useStyles = makeStyles<{ isDashboard: boolean }>()((theme, { isDashboard } fontSize: 14, lineHeight: '20px', color: theme.palette.text.primary, + wordBreak: 'keep-all', }, amount: { marginLeft: 10, diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx index 8f32d0f20300..61e377c27180 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx @@ -28,7 +28,7 @@ import { TradeForm } from './TradeForm' import { AllProviderTradeActionType, AllProviderTradeContext } from '../../trader/useAllProviderTradeContext' import { MINIMUM_AMOUNT, UST } from '../../constants' import { SelectTokenDialogEvent, WalletMessages } from '@masknet/plugin-wallet' -import { useAsync, useUpdateEffect } from 'react-use' +import { useAsync, useUnmount, useUpdateEffect } from 'react-use' import { isTwitter } from '../../../../social-network-adaptor/twitter.com/base' import { activatedSocialNetworkUI } from '../../../../social-network' import { isFacebook } from '../../../../social-network-adaptor/facebook.com/base' @@ -99,6 +99,7 @@ export function Trader(props: TraderProps) { //#region if coin be changed, update output token useEffect(() => { if (!coin || currentChainId !== targetChainId) return + // if coin be native token and input token also be native token, reset it if ( isSameAddress(coin.contract_address, NATIVE_TOKEN_ADDRESS) && @@ -110,7 +111,7 @@ export function Trader(props: TraderProps) { token: undefined, }) } - if (!inputToken && !outputToken) { + if (!outputToken) { dispatchTradeStore({ type: AllProviderTradeActionType.UPDATE_OUTPUT_TOKEN, token: coin.contract_address @@ -129,8 +130,11 @@ export function Trader(props: TraderProps) { //#region update balance const { value: inputTokenBalance_, loading: loadingInputTokenBalance } = useFungibleTokenBalance( - inputToken?.type ?? EthereumTokenType.Native, + isSameAddress(inputToken?.address, NATIVE_TOKEN_ADDRESS) + ? EthereumTokenType.Native + : inputToken?.type ?? EthereumTokenType.Native, inputToken?.address ?? '', + chainId, ) const { value: outputTokenBalance_, loading: loadingOutputTokenBalance } = useFungibleTokenBalance( @@ -152,7 +156,12 @@ export function Trader(props: TraderProps) { type: AllProviderTradeActionType.UPDATE_INPUT_TOKEN_BALANCE, balance: inputTokenBalance_, }) - if (outputToken && outputTokenBalance_ && !loadingOutputTokenBalance) { + if ( + outputToken && + outputToken?.type !== EthereumTokenType.Native && + outputTokenBalance_ && + !loadingOutputTokenBalance + ) { dispatchTradeStore({ type: AllProviderTradeActionType.UPDATE_OUTPUT_TOKEN_BALANCE, balance: outputTokenBalance_, @@ -165,10 +174,24 @@ export function Trader(props: TraderProps) { outputTokenBalance_, loadingInputTokenBalance, loadingOutputTokenBalance, + NATIVE_TOKEN_ADDRESS, ]) // Query the balance of native tokens on target chain useAsync(async () => { + if (!currentAccount) { + dispatchTradeStore({ + type: AllProviderTradeActionType.UPDATE_INPUT_TOKEN_BALANCE, + balance: '0', + }) + + dispatchTradeStore({ + type: AllProviderTradeActionType.UPDATE_OUTPUT_TOKEN_BALANCE, + balance: '0', + }) + return + } + if (chainId && currentProvider && currentAccount) { const cacheBalance = currentBalancesSettings.value[currentProvider]?.[chainId] @@ -273,11 +296,6 @@ export function Trader(props: TraderProps) { token: outputToken, }) - dispatchTradeStore({ - type: AllProviderTradeActionType.UPDATE_INPUT_TOKEN_BALANCE, - balance: '', - }) - dispatchTradeStore({ type: AllProviderTradeActionType.UPDATE_OUTPUT_TOKEN, token: inputToken, @@ -395,7 +413,7 @@ export function Trader(props: TraderProps) { const nativeTokenPrice = useNativeTokenPrice(chainId) const outputTokenPrice = useTokenPrice(chainId, outputToken?.address.toLowerCase()) const sortedAllTradeComputed = useMemo(() => { - if (outputToken && outputTokenPrice) { + if (outputToken && (outputTokenPrice || nativeTokenPrice)) { return allTradeComputed .map((trade) => { if ( @@ -423,7 +441,7 @@ export function Trader(props: TraderProps) { } return trade }) - .filter(({ finalPrice }) => !!finalPrice) + .filter(({ value }) => !!value && !value.outputAmount.isZero()) .sort(({ finalPrice: a }, { finalPrice: b }) => { if (a && b && isGreaterThan(a, b)) return -1 if (a && b && isLessThan(a, b)) return 1 @@ -431,7 +449,7 @@ export function Trader(props: TraderProps) { }) } return allTradeComputed - .filter(({ value }) => !!value) + .filter(({ value }) => !!value && !value.outputAmount.isZero()) .sort(({ value: a }, { value: b }) => { if (a?.outputAmount.isGreaterThan(b?.outputAmount ?? 0)) return -1 if (a?.outputAmount.isLessThan(b?.outputAmount ?? 0)) return 1 @@ -471,6 +489,13 @@ export function Trader(props: TraderProps) { }) }, []) + useUnmount(() => { + dispatchTradeStore({ + type: AllProviderTradeActionType.UPDATE_OUTPUT_TOKEN, + token: undefined, + }) + }) + return (
{ + if (currentChainId) { + setChainId(currentChainId) + } + }, [currentChainId]) + return ( @@ -99,6 +105,7 @@ export function TraderDialog({ open, onClose }: TraderDialogProps) { open={open || remoteOpen} onClose={() => { onClose?.() + setTraderProps(undefined) closeDialog() }} title={t('plugin_trader_swap')}> diff --git a/packages/shared/src/UI/components/ERC20TokenList/index.tsx b/packages/shared/src/UI/components/ERC20TokenList/index.tsx index bc9a94e663a1..e46e30ec072b 100644 --- a/packages/shared/src/UI/components/ERC20TokenList/index.tsx +++ b/packages/shared/src/UI/components/ERC20TokenList/index.tsx @@ -48,9 +48,10 @@ const Placeholder = memo(({ message, height }: { message: string; height?: numbe export const ERC20TokenList = memo((props) => { const t = useSharedI18N() const account = useAccount() - const chainId = useChainId() + const currentChainId = useChainId() + const chainId = props.targetChainId ?? currentChainId const trustedERC20Tokens = useTrustedERC20Tokens() - const { value: nativeToken } = useNativeTokenDetailed(props.targetChainId ?? chainId) + const { value: nativeToken } = useNativeTokenDetailed(chainId) const [keyword, setKeyword] = useState('') const { @@ -62,13 +63,14 @@ export const ERC20TokenList = memo((props) => { selectedTokens = [], } = props - const { ERC20_TOKEN_LISTS } = useEthereumConstants() + const { ERC20_TOKEN_LISTS } = useEthereumConstants(chainId) const { value: erc20TokensDetailed = [], loading: erc20TokensDetailedLoading } = useERC20TokensDetailedFromTokenLists( ERC20_TOKEN_LISTS, keyword, nativeToken ? [...trustedERC20Tokens, nativeToken] : trustedERC20Tokens, + chainId, ) //#region add token by address @@ -95,7 +97,10 @@ export const ERC20TokenList = memo((props) => { loading: assetsLoading, error: assetsError, retry: retryLoadAsset, - } = useAssetsByTokenList(renderTokens.filter((x) => isValidAddress(x.address))) + } = useAssetsByTokenList( + renderTokens.filter((x) => isValidAddress(x.address)), + chainId, + ) useEffect(() => { if (assetsError) retryLoadAsset() diff --git a/packages/web3-shared/evm/hooks/useERC20TokenBalance.ts b/packages/web3-shared/evm/hooks/useERC20TokenBalance.ts index 37fba479cfa6..49587dc6a146 100644 --- a/packages/web3-shared/evm/hooks/useERC20TokenBalance.ts +++ b/packages/web3-shared/evm/hooks/useERC20TokenBalance.ts @@ -8,7 +8,8 @@ import { toHex } from 'web3-utils' /** * Fetch token balance from chain - * @param token + * @param address + * @param targetChainId */ export function useERC20TokenBalance(address?: string, targetChainId?: ChainId) { const account = useAccount() From 97630c1f9a3eb21ec44305ba3567835f6ec9e8ff Mon Sep 17 00:00:00 2001 From: Hancheng Zhou Date: Fri, 17 Dec 2021 15:35:26 +0800 Subject: [PATCH 12/17] fix: twitter comment selector (#5233) --- .../src/social-network-adaptor/twitter.com/utils/selector.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts index 62aa2b61f228..ba73bedacd5c 100644 --- a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts +++ b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts @@ -91,7 +91,7 @@ export const postEditorContentInPopupSelector: () => LiveSelector = () ) export const postEditorInPopupSelector: () => LiveSelector = () => querySelector( - '[aria-labelledby="modal-header"] > div:first-child > div:first-child > div:first-child > div:nth-child(3) > div:first-child > div:first-child [role="button"][aria-label]:nth-child(6)', + '[aria-labelledby="modal-header"] > div:first-child > div:first-child > div:first-child > div:nth-child(3) > div:first-child [role="button"][aria-label]:nth-child(6)', ) export const toolBoxInSideBarSelector: () => LiveSelector = () => querySelector('[role="banner"] [role="navigation"] > div') From 0e82036df1e55cb486f0a212ae271185cf9e0532 Mon Sep 17 00:00:00 2001 From: lelenei <72531217+lelenei@users.noreply.github.com> Date: Fri, 17 Dec 2021 16:36:17 +0800 Subject: [PATCH 13/17] fix: add cache expiration (#5229) * fix: add cache expiration * fix: expiration time 60s --- packages/mask/src/plugins/Avatar/Services/rss3.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/mask/src/plugins/Avatar/Services/rss3.ts b/packages/mask/src/plugins/Avatar/Services/rss3.ts index c1bc78e880bd..6f2efb7c36ee 100644 --- a/packages/mask/src/plugins/Avatar/Services/rss3.ts +++ b/packages/mask/src/plugins/Avatar/Services/rss3.ts @@ -4,6 +4,7 @@ import { isSameAddress } from '@masknet/web3-shared-evm' import { personalSign } from '../../../extension/background-script/EthereumService' import { RSS3_APP } from '../constants' import type { AvatarMetaDB } from '../types' +import addSeconds from 'date-fns/addSeconds' interface NFTRSSNode { signature: string @@ -20,16 +21,19 @@ export async function createRSS3(address: string) { }) } -const cache = new Map | NFTRSSNode } | undefined>>() +const cache = new Map< + string, + [Promise<{ type: string; nfts: Record | NFTRSSNode } | undefined>, number] +>() export async function getNFTAvatarFromRSS(userId: string, address: string) { let v = cache.get(address) - if (!v) { - v = _getNFTAvatarFromRSS(address) - cache.set(address, v) + if (!v || Date.now() > v[1]) { + cache.set(address, [_getNFTAvatarFromRSS(address), addSeconds(Date.now(), 60).getTime()]) } - const result = await v + v = cache.get(address) + const result = await v?.[0] if (!result) return const { type, nfts } = result From 09b30fff3ce3861ba01fa9c3eff11831aee179e4 Mon Sep 17 00:00:00 2001 From: UncleBill Date: Fri, 17 Dec 2021 19:33:27 +0800 Subject: [PATCH 14/17] fix(Maskbox): update mask info after purchasing (#5225) --- .../src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx b/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx index a5b7d58e07a0..b72a1a575238 100644 --- a/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx +++ b/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx @@ -76,6 +76,7 @@ export function PreviewCard(props: PreviewCardProps) { setOpenBoxTransactionOverrides, // retry + retryMaskBoxStatus, retryMaskBoxInfo, retryBoxInfo, retryMaskBoxCreationSuccessEvent, @@ -118,10 +119,11 @@ export function PreviewCard(props: PreviewCardProps) { refreshLastPurchasedTokenIds() try { await openBoxCallback() + retryMaskBoxStatus() setOpenDrawDialog(false) } catch {} setDrawing(false) - }, [openBoxCallback, refreshLastPurchasedTokenIds]) + }, [openBoxCallback, refreshLastPurchasedTokenIds, retryMaskBoxStatus]) const { setDialog: setTransactionDialog } = useRemoteControlledDialog( WalletMessages.events.transactionDialogUpdated, From 6c152225cc53f92d1a3e174c13f93ad4f9eaa91f Mon Sep 17 00:00:00 2001 From: nuanyang233 Date: Fri, 17 Dec 2021 22:29:42 +0800 Subject: [PATCH 15/17] fix: reset page tag when identifier be changed (#5236) --- .../src/plugins/Profile/SNSAdaptor/EnhancedProfile.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/mask/src/plugins/Profile/SNSAdaptor/EnhancedProfile.tsx b/packages/mask/src/plugins/Profile/SNSAdaptor/EnhancedProfile.tsx index 1e4ccbb9de06..9e96f2171a51 100644 --- a/packages/mask/src/plugins/Profile/SNSAdaptor/EnhancedProfile.tsx +++ b/packages/mask/src/plugins/Profile/SNSAdaptor/EnhancedProfile.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useMemo } from 'react' +import { useEffect, useMemo, useState } from 'react' import { makeStyles, useStylesExtends } from '@masknet/theme' import { MaskMessages } from '../../../utils' @@ -12,6 +12,7 @@ import { PageTags } from '../types' import { unreachable } from '@dimensiondev/kit' import { PageTag } from './PageTag' import { useDao } from './hooks/useDao' +import { useUpdateEffect } from 'react-use' const useStyles = makeStyles()((theme) => ({ root: { @@ -61,7 +62,11 @@ export function EnhancedProfilePage(props: EnhancedProfilePageProps) { default: unreachable(currentTag) } - }, [currentTag]) + }, [currentTag, daoPayload, identity.identifier]) + + useUpdateEffect(() => { + setCurrentTag(PageTags.NFTTag) + }, [identity.identifier]) if (!show) return null From b018248678301aa3e60e6f1f5435411ee0fcad52 Mon Sep 17 00:00:00 2001 From: UncleBill Date: Fri, 17 Dec 2021 23:06:18 +0800 Subject: [PATCH 16/17] fix: the balance on multi-networks (#5237) Co-authored-by: guanbinrui --- packages/dashboard/src/pages/Wallets/index.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/index.tsx b/packages/dashboard/src/pages/Wallets/index.tsx index 79f54f92cbeb..2ab5f975712f 100644 --- a/packages/dashboard/src/pages/Wallets/index.tsx +++ b/packages/dashboard/src/pages/Wallets/index.tsx @@ -75,8 +75,15 @@ function Wallets() { }, [pathname]) const balance = useMemo(() => { - return BigNumber.sum.apply(null, detailedTokens?.map((asset) => getTokenUSDValue(asset.value)) ?? []).toNumber() - }, [detailedTokens]) + return BigNumber.sum + .apply( + null, + detailedTokens + ?.filter((x) => (selectedNetwork ? x.chainId === selectedNetwork.chainId : true)) + ?.map((y) => getTokenUSDValue(y.value)) ?? [], + ) + .toNumber() + }, [selectedNetwork, detailedTokens]) const pateTitle = useMemo(() => { if (wallets.length === 0) return t.create_wallet_form_title() From e805f7e215b4f08772d6a6414a449fcca1d7b805 Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Sat, 18 Dec 2021 00:35:04 +0800 Subject: [PATCH 17/17] fix: read network type from wrong place (#5238) --- .../components/NetworkSelector/index.tsx | 20 ++++++++----------- .../Wallet/ContractInteraction/index.tsx | 6 +++--- .../popups/pages/Wallet/GasSetting/index.tsx | 6 ++---- .../pages/Wallet/ReplaceTransaction/index.tsx | 7 +++---- .../popups/pages/Wallet/Transfer/index.tsx | 9 ++++----- .../SNSAdaptor/trader/SettingsDialog.tsx | 5 ++--- .../Trader/SNSAdaptor/trending/TraderView.tsx | 6 ++---- 7 files changed, 24 insertions(+), 35 deletions(-) diff --git a/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx b/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx index 093886514540..b92609c5e5bf 100644 --- a/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx +++ b/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx @@ -2,14 +2,10 @@ import { memo, useCallback } from 'react' import { Box, MenuItem, Typography } from '@mui/material' import { makeStyles } from '@masknet/theme' import { Flags } from '../../../../../shared' -import { ChainId, ProviderType, useAccount } from '@masknet/web3-shared-evm' +import { ChainId, ProviderType, useAccount, useChainId, useProviderType } from '@masknet/web3-shared-evm' import { getRegisteredWeb3Networks, NetworkPluginID, Web3Plugin } from '@masknet/plugin-infra' -import { - currentMaskWalletAccountSettings, - currentMaskWalletChainIdSettings, - currentProviderSettings, -} from '../../../../plugins/Wallet/settings' -import { ChainIcon, useMenu, useValueRef, WalletIcon } from '@masknet/shared' +import { currentMaskWalletAccountSettings } from '../../../../plugins/Wallet/settings' +import { ChainIcon, useMenu, WalletIcon } from '@masknet/shared' import { ArrowDownRound } from '@masknet/icons' import { WalletRPC } from '../../../../plugins/Wallet/messages' @@ -49,11 +45,11 @@ const useStyles = makeStyles()((theme) => ({ export const NetworkSelector = memo(() => { const networks = getRegisteredWeb3Networks() const account = useAccount() - const currentChainId = useValueRef(currentMaskWalletChainIdSettings) - const currentProvider = useValueRef(currentProviderSettings) + const chainId = useChainId() + const providerType = useProviderType() const onChainChange = useCallback( async (chainId: ChainId) => { - if (currentProvider === ProviderType.MaskWallet) { + if (providerType === ProviderType.MaskWallet) { await WalletRPC.updateAccount({ chainId, }) @@ -63,12 +59,12 @@ export const NetworkSelector = memo(() => { account: currentMaskWalletAccountSettings.value, }) }, - [currentProvider, account], + [providerType, account], ) return ( x.chainId === currentChainId) ?? networks[0]} + currentNetwork={networks.find((x) => x.chainId === chainId) ?? networks[0]} onChainChange={onChainChange} networks={networks} /> diff --git a/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx index 75298e83442c..a358274bf83b 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/ContractInteraction/index.tsx @@ -15,8 +15,9 @@ import { useChainId, useERC20TokenDetailed, useNativeTokenDetailed, + useNetworkType, } from '@masknet/web3-shared-evm' -import { FormattedBalance, FormattedCurrency, TokenIcon, useValueRef } from '@masknet/shared' +import { FormattedBalance, FormattedCurrency, TokenIcon } from '@masknet/shared' import { Link, Typography } from '@mui/material' import { useI18N } from '../../../../../utils' import { PopupRoutes } from '@masknet/shared-base' @@ -24,7 +25,6 @@ import { LoadingButton } from '@mui/lab' import { unreachable } from '@dimensiondev/kit' import { WalletRPC } from '../../../../../plugins/Wallet/messages' import Services from '../../../../service' -import { currentNetworkSettings } from '../../../../../plugins/Wallet/settings' import BigNumber from 'bignumber.js' import { useNativeTokenPrice, useTokenPrice } from '../../../../../plugins/Wallet/hooks/useTokenPrice' import { LoadingPlaceholder } from '../../../components/LoadingPlaceholder' @@ -136,7 +136,7 @@ const ContractInteraction = memo(() => { const location = useLocation() const history = useHistory() const chainId = useChainId() - const networkType = useValueRef(currentNetworkSettings) + const networkType = useNetworkType() const [transferError, setTransferError] = useState(false) const { value: request, loading: requestLoading } = useUnconfirmedRequest() diff --git a/packages/mask/src/extension/popups/pages/Wallet/GasSetting/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/GasSetting/index.tsx index 6fb1d0e13b08..cb3b2cc30f86 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/GasSetting/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/GasSetting/index.tsx @@ -1,12 +1,10 @@ import { memo } from 'react' import { makeStyles } from '@masknet/theme' import { Typography } from '@mui/material' -import { useValueRef } from '@masknet/shared' -import { NetworkType } from '@masknet/web3-shared-evm' +import { NetworkType, useNetworkType } from '@masknet/web3-shared-evm' import { useI18N } from '../../../../../utils' import { GasSetting1559 } from './GasSetting1559' import { Prior1559GasSetting } from './Prior1559GasSetting' -import { currentNetworkSettings } from '../../../../../plugins/Wallet/settings' const useStyles = makeStyles()(() => ({ container: { @@ -30,7 +28,7 @@ const useStyles = makeStyles()(() => ({ const GasSetting = memo(() => { const { t } = useI18N() const { classes } = useStyles() - const networkType = useValueRef(currentNetworkSettings) + const networkType = useNetworkType() return (
{t('popups_wallet_gas_fee_settings')} diff --git a/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx index 0861d2598eb1..1c645fab477a 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/ReplaceTransaction/index.tsx @@ -12,13 +12,12 @@ import { getChainIdFromNetworkType, isEIP1559Supported, useNativeTokenDetailed, + useNetworkType, } from '@masknet/web3-shared-evm' -import { useValueRef } from '@masknet/shared' -import { currentNetworkSettings } from '../../../../../plugins/Wallet/settings' +import { z as zod } from 'zod' import BigNumber from 'bignumber.js' import { useI18N } from '../../../../../utils' import { hexToNumber, toHex } from 'web3-utils' -import { z as zod } from 'zod' import { Controller, useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' import { StyledInput } from '../../../components/StyledInput' @@ -79,7 +78,7 @@ const ReplaceTransaction = memo(() => { const { value: nativeToken } = useNativeTokenDetailed() const nativeTokenPrice = useNativeTokenPrice(nativeToken?.chainId) - const networkType = useValueRef(currentNetworkSettings) + const networkType = useNetworkType() const is1559 = isEIP1559Supported(getChainIdFromNetworkType(networkType)) const schema = useMemo(() => { diff --git a/packages/mask/src/extension/popups/pages/Wallet/Transfer/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/Transfer/index.tsx index 05729160830d..796187e3053f 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/Transfer/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/Transfer/index.tsx @@ -1,11 +1,10 @@ import { memo, useMemo, useState } from 'react' -import { makeStyles } from '@masknet/theme' -import { formatBalance, NetworkType, ProviderType, useWallets } from '@masknet/web3-shared-evm' import { MenuItem, Typography } from '@mui/material' -import { FormattedBalance, TokenIcon, useMenu, useValueRef } from '@masknet/shared' +import { makeStyles } from '@masknet/theme' +import { formatBalance, NetworkType, ProviderType, useNetworkType, useWallets } from '@masknet/web3-shared-evm' +import { FormattedBalance, TokenIcon, useMenu } from '@masknet/shared' import { useContainer } from 'unstated-next' import { WalletContext } from '../hooks/useWalletContext' -import { currentNetworkSettings } from '../../../../../plugins/Wallet/settings' import { Transfer1559 } from './Transfer1559' import { Prior1559Transfer } from './Prior1559Transfer' @@ -26,7 +25,7 @@ const useStyles = makeStyles()({ const Transfer = memo(() => { const { classes } = useStyles() - const networkType = useValueRef(currentNetworkSettings) + const networkType = useNetworkType() const wallets = useWallets(ProviderType.MaskWallet) const { assets, currentToken } = useContainer(WalletContext) const [selectedAsset, setSelectedAsset] = useState(currentToken) diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/SettingsDialog.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/SettingsDialog.tsx index 7f53c02e843a..3ff3234e570f 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/SettingsDialog.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/SettingsDialog.tsx @@ -9,9 +9,8 @@ import { InjectedDialog } from '../../../../components/shared/InjectedDialog' import { PluginTraderMessages } from '../../messages' import { ExpandMore } from '@mui/icons-material' import { Gas1559Settings } from './Gas1559Settings' -import { currentNetworkSettings } from '../../../Wallet/settings' import { GasPrior1559Settings } from './GasPrior1559Settings' -import { GasOptionConfig, NetworkType } from '@masknet/web3-shared-evm' +import { GasOptionConfig, NetworkType, useNetworkType } from '@masknet/web3-shared-evm' const useStyles = makeStyles()((theme) => { return { @@ -47,7 +46,7 @@ export function SettingsDialog(props: SettingsDialogProps) { const classes = useStylesExtends(useStyles(), props) const slippage = useValueRef(currentSlippageSettings) - const networkType = useValueRef(currentNetworkSettings) + const networkType = useNetworkType() const [gasConfig, setGasConfig] = useState() const [unconfirmedSlippage, setUnconfirmedSlippage] = useState(slippage) diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx index 96b895b5867b..d9a0c65acf76 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/TraderView.tsx @@ -1,7 +1,6 @@ import { useState, useEffect } from 'react' import { Link, Tab, Tabs } from '@mui/material' import { makeStyles } from '@masknet/theme' -import { useValueRef } from '@masknet/shared' import { useI18N, useSettingsSwitcher } from '../../../../utils' import type { TagType } from '../../types' import { DataProvider, TradeProvider } from '@masknet/public-api' @@ -22,9 +21,8 @@ import { TrendingViewDeck } from './TrendingViewDeck' import { currentDataProviderSettings } from '../../settings' import { useAvailableCoins } from '../../trending/useAvailableCoins' import { usePreferredCoinId } from '../../trending/useCurrentCoinId' -import { EthereumTokenType, useFungibleTokenDetailed, useChainIdValid } from '@masknet/web3-shared-evm' +import { EthereumTokenType, useFungibleTokenDetailed, useChainIdValid, useNetworkType } from '@masknet/web3-shared-evm' import { TradeContext, useTradeContext } from '../../trader/useTradeContext' -import { currentNetworkSettings } from '../../../Wallet/settings' const useStyles = makeStyles<{ isPopper: boolean }>()((theme, props) => { return { @@ -114,7 +112,7 @@ export function TraderView(props: TraderViewProps) { const chainIdValid = useChainIdValid() //#region track network type - const networkType = useValueRef(currentNetworkSettings) + const networkType = useNetworkType() useEffect(() => setTabIndex(0), [networkType]) //#endregion