From 999d82997e93665d1711cb9e49e74b56ff1d17d8 Mon Sep 17 00:00:00 2001 From: nuanyang233 Date: Thu, 26 May 2022 15:17:57 +0800 Subject: [PATCH 01/17] fix: add missing deps (#6356) --- .../src/components/InjectedComponents/ProfileTabContent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index 0487f9d1b095..aaf461822524 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -124,7 +124,7 @@ export function ProfileTabContent(props: ProfileTabContentProps) { ? displayPlugins?.find((tab) => tab?.pluginID === PluginId.NextID)?.ID : selectedTabId return getTabContent(tabId ?? '') - }, [selectedTabId, identity.identifier?.userId]) + }, [selectedTabId, identity.identifier?.userId, currentAccountNotConnectPersona]) if (hidden) return null From b3d28c74c6478aa246d6740a6d1bda59ab001f2f Mon Sep 17 00:00:00 2001 From: zhouhanseng Date: Tue, 24 May 2022 14:38:11 +0800 Subject: [PATCH 02/17] fix(ui): claim button && mind fb tool box hint (#6337) --- cspell.json | 1 + .../InjectedComponents/ToolboxUnstyled.tsx | 5 ++++- .../DashboardComponents/ActionButton.tsx | 21 +++++++++++++++---- .../plugins/ITO/SNSAdaptor/ClaimAllDialog.tsx | 2 ++ .../facebook.com/injection/Toolbar.tsx | 3 ++- .../facebook.com/injection/ToolbarUI.tsx | 19 +++++++++-------- .../minds.com/customization/custom.ts | 3 +++ .../minds.com/injection/ToolboxHint_UI.tsx | 4 ++-- .../minds.com/utils/selector.ts | 4 +--- .../src/web3/UI/EthereumChainBoundary.tsx | 3 +++ 10 files changed, 45 insertions(+), 20 deletions(-) diff --git a/cspell.json b/cspell.json index 28e4e04fbc54..4dbe240d7ac5 100644 --- a/cspell.json +++ b/cspell.json @@ -286,6 +286,7 @@ "redpackets", "renfil", "shapeclip", + "ssrb", "steth", "swaptoken", "testweb", diff --git a/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx b/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx index 106098381aeb..6a2593c93cca 100644 --- a/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx +++ b/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx @@ -91,6 +91,7 @@ export function ToolboxHintUnstyled(props: ToolboxHintProps) { function ToolboxHintForApplication(props: ToolboxHintProps) { const { ListItemButton = MuiListItemButton, + ListItemIcon = MuiListItemIcon, Container = 'div', Typography = MuiTypography, iconSize = 24, @@ -104,7 +105,9 @@ function ToolboxHintForApplication(props: ToolboxHintProps) { - + + + {mini ? null : ( ('init') - const completeClass = classNames(classes.success, b.className) - const failClass = classNames(classes.failed, b.className) + const basicClass = classNames(classes.button, b.className) + const completeClass = classNames(basicClass, classes.success) + const failClass = classNames(basicClass, classes.failed) const run = () => { setState('wait') @@ -144,7 +145,16 @@ export function ActionButtonPromise(props: ActionButtonPromiseProps) { }, [executor, noUpdateEffect]) if (state === 'wait') - return ) @@ -155,12 +157,12 @@ export function PreviewCard(props: PreviewCardProps) {
- {t('plugin_gitcoin_last_updated')} {grant.last_update_natural} + {t.last_updated()} {grant.last_update_natural}
- {t('plugin_gitcoin_by')} + {t.by()} - {t('plugin_gitcoin_view_on')} + {t.view_on()} @@ -199,7 +201,7 @@ export function PreviewCard(props: PreviewCardProps) { color: 'white', }} onClick={onDonate}> - {t('plugin_gitcoin_donate')} + {t.donate()} diff --git a/packages/mask/src/plugins/Gitcoin/SNSAdaptor/index.tsx b/packages/mask/src/plugins/Gitcoin/SNSAdaptor/index.tsx index 956f016b34d3..1ffb8a4109eb 100644 --- a/packages/mask/src/plugins/Gitcoin/SNSAdaptor/index.tsx +++ b/packages/mask/src/plugins/Gitcoin/SNSAdaptor/index.tsx @@ -1,18 +1,15 @@ -import { useMemo } from 'react' -import { ChainId } from '@masknet/web3-shared-evm' -import { usePostInfoDetails, Plugin, usePluginWrapper } from '@masknet/plugin-infra/content-script' -import { NetworkPluginID, useChainId } from '@masknet/plugin-infra/web3' -import { extractTextFromTypedMessage } from '@masknet/typed-message' -import { parseURL } from '@masknet/shared-base' import { GitcoinIcon } from '@masknet/icons' -import { PreviewCard } from './PreviewCard' +import { Plugin, PluginId, usePluginWrapper, usePostInfoDetails } from '@masknet/plugin-infra/content-script' +import { parseURL } from '@masknet/shared-base' +import { extractTextFromTypedMessage } from '@masknet/typed-message' +import { useMemo } from 'react' import { Trans } from 'react-i18next' import { base } from '../base' -import { PLUGIN_NAME, PLUGIN_META_KEY } from '../constants' +import { PLUGIN_META_KEY, PLUGIN_NAME } from '../constants' import { DonateDialog } from './DonateDialog' +import { PreviewCard } from './PreviewCard' const isGitcoin = (x: string): boolean => /^https:\/\/gitcoin.co\/grants\/\d+/.test(x) -const isGitCoinSupported = (chainId: ChainId) => [ChainId.Mainnet, ChainId.Matic].includes(chainId) const sns: Plugin.SNSAdaptor.Definition = { ...base, @@ -41,8 +38,8 @@ const sns: Plugin.SNSAdaptor.Definition = { { ApplicationEntryID: base.ID, category: 'dapp', - description: , - name: , + description: , + name: , icon: , marketListSortingPriority: 9, tutorialLink: 'https://realmasknetwork.notion.site/98ed83784ed4446a8a13fa685c7bddfb', @@ -52,7 +49,6 @@ const sns: Plugin.SNSAdaptor.Definition = { function Renderer(props: React.PropsWithChildren<{ url: string }>) { const [id = ''] = props.url.match(/\d+/) ?? [] - const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) usePluginWrapper(true) return } diff --git a/packages/mask/src/plugins/Gitcoin/base.ts b/packages/mask/src/plugins/Gitcoin/base.ts index 2ba903193d15..399adeb050cb 100644 --- a/packages/mask/src/plugins/Gitcoin/base.ts +++ b/packages/mask/src/plugins/Gitcoin/base.ts @@ -2,6 +2,7 @@ import type { Plugin } from '@masknet/plugin-infra' import { NetworkPluginID } from '@masknet/plugin-infra/web3' import { ChainId } from '@masknet/web3-shared-evm' import { PLUGIN_ID, PLUGIN_NAME, PLUGIN_DESCRIPTION } from './constants' +import { languages } from './locales/languages' export const base: Plugin.Shared.Definition = { ID: PLUGIN_ID, @@ -21,4 +22,5 @@ export const base: Plugin.Shared.Definition = { }, }, contribution: { postContent: new Set([/https:\/\/gitcoin.co\/grants\/\d+/]) }, + i18n: languages, } diff --git a/packages/mask/src/plugins/Gitcoin/locales/en-US.json b/packages/mask/src/plugins/Gitcoin/locales/en-US.json new file mode 100644 index 000000000000..96bdf7b52625 --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/en-US.json @@ -0,0 +1,15 @@ +{ + "name": "Gitcoin", + "description": "Display specific information of Gitcoin projects, donate to a project directly on social media.", + "promote": "Share or browse Gitcoin projects you have donated or interested in.", + "select_a_token": "Select a token", + "grant_not_available": "Grant not available", + "enter_an_amount": "Enter an amount", + "insufficient_balance": "Insufficient {{symbol}} balance", + "gitcoin_readme": "By using this service, you will also be contributing 5% of your contribution to the Gitcoin grants development fund.", + "donate": "Donate", + "last_updated": "Last update:", + "by": "By", + "view_on": "View on Gitcoin", + "readme_fund_link": "https://gitcoin.co/grants/86/gitcoin-sustainability-fund" +} diff --git a/packages/mask/src/plugins/Gitcoin/locales/index.ts b/packages/mask/src/plugins/Gitcoin/locales/index.ts new file mode 100644 index 000000000000..d6ead60252e4 --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/index.ts @@ -0,0 +1,6 @@ +// This file is auto generated. DO NOT EDIT +// Run `npx gulp sync-languages` to regenerate. +// Default fallback language in a family of languages are chosen by the alphabet order +// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts + +export * from './i18n_generated' diff --git a/packages/mask/src/plugins/Gitcoin/locales/ja-JP.json b/packages/mask/src/plugins/Gitcoin/locales/ja-JP.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/ja-JP.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Gitcoin/locales/ko-KR.json b/packages/mask/src/plugins/Gitcoin/locales/ko-KR.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/ko-KR.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Gitcoin/locales/languages.ts b/packages/mask/src/plugins/Gitcoin/locales/languages.ts new file mode 100644 index 000000000000..9b496c047c8a --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/languages.ts @@ -0,0 +1,34 @@ +// This file is auto generated. DO NOT EDIT +// Run `npx gulp sync-languages` to regenerate. +// Default fallback language in a family of languages are chosen by the alphabet order +// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts +import en_US from './en-US.json' +import ja_JP from './ja-JP.json' +import ko_KR from './ko-KR.json' +import qya_AA from './qya-AA.json' +import zh_CN from './zh-CN.json' +import zh_TW from './zh-TW.json' +export const languages = { + en: en_US, + ja: ja_JP, + ko: ko_KR, + qy: qya_AA, + 'zh-CN': zh_CN, + zh: zh_TW, +} +// @ts-ignore +if (import.meta.webpackHot) { + // @ts-ignore + import.meta.webpackHot.accept( + ['./en-US.json', './ja-JP.json', './ko-KR.json', './qya-AA.json', './zh-CN.json', './zh-TW.json'], + () => + globalThis.dispatchEvent?.( + new CustomEvent('MASK_I18N_HMR', { + detail: [ + 'com.maskbook.gitcoin', + { en: en_US, ja: ja_JP, ko: ko_KR, qy: qya_AA, 'zh-CN': zh_CN, zh: zh_TW }, + ], + }), + ), + ) +} diff --git a/packages/mask/src/plugins/Gitcoin/locales/qya-AA.json b/packages/mask/src/plugins/Gitcoin/locales/qya-AA.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/qya-AA.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Gitcoin/locales/zh-CN.json b/packages/mask/src/plugins/Gitcoin/locales/zh-CN.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/zh-CN.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Gitcoin/locales/zh-TW.json b/packages/mask/src/plugins/Gitcoin/locales/zh-TW.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Gitcoin/locales/zh-TW.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx b/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx index 7b761a3bb0fb..325506b44221 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx @@ -5,12 +5,9 @@ import { FungibleTokenDetailed, getChainDetailed, isSameAddress, - currySameAddress, resolveLinkOnExplorer, - TransactionStateType, useAccount, useChainId, - useChainIdValid, useTokenConstants, isNativeTokenAddress, } from '@masknet/web3-shared-evm' @@ -246,8 +243,7 @@ export function ITO(props: ITO_Props) { const account = useAccount() const postLink = usePostLink() const chainId = useChainId() - const chainIdValid = useChainIdValid() - const [destructState, destructCallback, resetDestructCallback] = useDestructCallback(props.payload.contract_address) + const [, destructCallback] = useDestructCallback(props.payload.contract_address) const [openClaimDialog, setOpenClaimDialog] = useState(false) const [claimDialogStatus, setClaimDialogStatus] = useState(SwapStatus.Remind) @@ -414,23 +410,8 @@ export function ITO(props: ITO_Props) { return () => clearTimeout(timer) }, [endTime, listOfStatus]) - useEffect(() => { - if (destructState.type === TransactionStateType.UNKNOWN || !canWithdraw) return - let summary = t('plugin_ito_withdraw') - if (!noRemain) { - summary += ' ' + formatBalance(total_remaining, token.decimals) + ' ' + token.symbol - } - availability?.exchange_addrs.forEach((addr, i) => { - const token = exchange_tokens.find(currySameAddress(addr)) - const comma = noRemain && i === 0 ? ' ' : ', ' - if (token) { - summary += comma + formatBalance(availability?.exchanged_tokens[i], token.decimals) + ' ' + token.symbol - } - }) - }, [destructState, canWithdraw]) - const onWithdraw = useCallback(async () => { - destructCallback(payload.pid) + await destructCallback(payload.pid) }, [destructCallback, payload.pid]) // #endregion diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx b/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx index 7190867404a9..f4eaba6d32be 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx @@ -1,17 +1,11 @@ import formatDateTime from 'date-fns/format' -import { - ChainId, - TransactionStateType, - useAccount, - resolveTransactionLinkOnExplorer, - useChainId, -} from '@masknet/web3-shared-evm' +import { ChainId, useAccount, resolveTransactionLinkOnExplorer, useChainId } from '@masknet/web3-shared-evm' import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' import { Box, Typography, Button, TextField, CircularProgress, Link } from '@mui/material' import { useSpaceStationClaimableTokenCountCallback } from './hooks/useSpaceStationClaimableTokenCountCallback' import { useSpaceStationContractClaimCallback } from './hooks/useSpaceStationContractClaimCallback' import { useI18N } from '../../../utils' -import { useState, useEffect } from 'react' +import { useState, useEffect, useCallback } from 'react' import { makeStyles, useCustomSnackbar, OptionsObject } from '@masknet/theme' import OpenInNewIcon from '@mui/icons-material/OpenInNew' import CloseIcon from '@mui/icons-material/Close' @@ -287,8 +281,9 @@ function ClaimItem(props: ClaimItemProps) { horizontal: 'center', }, } - useEffect(() => { - if (claimState.type === TransactionStateType.CONFIRMED && claimState.no === 0) { + const claim = useCallback(async () => { + const hash = await claimCallback() + if (typeof hash === 'string') { showSnackbar(
@@ -299,10 +294,7 @@ function ClaimItem(props: ClaimItemProps) { className={classes.whiteText} target="_blank" rel="noopener noreferrer" - href={resolveTransactionLinkOnExplorer( - ChainId.Mumbai, - claimState.receipt.transactionHash, - )}> + href={resolveTransactionLinkOnExplorer(ChainId.Mumbai, hash)}> @@ -316,7 +308,7 @@ function ClaimItem(props: ClaimItemProps) { ) retry() - } else if (claimState.type === TransactionStateType.FAILED) { + } else { showSnackbar(
@@ -331,7 +323,7 @@ function ClaimItem(props: ClaimItemProps) { } as OptionsObject, ) } - }, [claimState]) + }, [showSnackbar]) const unClaimable = now < campaignInfo.startTime * 1000 || @@ -359,17 +351,10 @@ function ClaimItem(props: ClaimItemProps) { unlockMetaMask: classNames(classes.actionButton, classes.connectWallet), }}> {claimed diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/PoolInList.tsx b/packages/mask/src/plugins/ITO/SNSAdaptor/PoolInList.tsx index e044f04798a5..67441435125f 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/PoolInList.tsx +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/PoolInList.tsx @@ -5,7 +5,6 @@ import { FungibleTokenInitial, getChainDetailed, isSameAddress, - TransactionStateType, useAccount, useFungibleTokenDetailed, useFungibleTokensDetailed, @@ -35,10 +34,10 @@ import { useAvailabilityComputed } from './hooks/useAvailabilityComputed' import { usePoolTradeInfo } from './hooks/usePoolTradeInfo' import { ITO_Status, JSON_PayloadFromChain, JSON_PayloadInMask, PoolFromNetwork } from '../types' import { useDestructCallback } from './hooks/useDestructCallback' -import { useTransactionDialog } from '../../../web3/hooks/useTransactionDialog' import { omit } from 'lodash-unified' import { useSubscription } from 'use-subscription' import { PersistentStorages } from '../../../../shared' +import { useCallback } from 'react' const useStyles = makeStyles()((theme) => { const smallQuery = `@media (max-width: ${theme.breakpoints.values.sm}px)` @@ -175,11 +174,14 @@ export function PoolInList(props: PoolInListProps) { // #endregion // #region withdraw - const [destructState, destructCallback, resetDestructCallback] = useDestructCallback(pool.contract_address) - useTransactionDialog(null, destructState, TransactionStateType.CONFIRMED, () => { - onRetry() - resetDestructCallback() - }) + const [{ loading: destructing }, destructCallback] = useDestructCallback(pool.contract_address) + const destruct = useCallback( + async (pid: string) => { + await destructCallback(pid) + onRetry() + }, + [destructCallback, onRetry], + ) // #endregion const account = useAccount() @@ -202,7 +204,13 @@ export function PoolInList(props: PoolInListProps) { return ( <> {loadingTradeInfo || loadingAvailability ? null : canWithdraw ? ( - destructCallback(pool.pid)}> + destruct(pool.pid)}> {t('plugin_ito_withdraw')} ) : canSend ? ( diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useDestructCallback.ts b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useDestructCallback.ts index 2e736befd4e6..2176cfce5699 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useDestructCallback.ts +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useDestructCallback.ts @@ -1,43 +1,22 @@ -import { useCallback } from 'react' -import type { TransactionReceipt } from 'web3-core' import type { NonPayableTx } from '@masknet/web3-contracts/types/types' -import { TransactionEventType, TransactionStateType, useAccount, useTransactionState } from '@masknet/web3-shared-evm' +import { TransactionEventType, useAccount } from '@masknet/web3-shared-evm' +import { useAsyncFn } from 'react-use' import { useITO_Contract } from './useITO_Contract' export function useDestructCallback(ito_address: string) { const account = useAccount() const { contract: ITO_Contract } = useITO_Contract(ito_address) - const [destructState, setDestructState] = useTransactionState() - const destructCallback = useCallback( + return useAsyncFn( async (id: string) => { - if (!ITO_Contract || !id) { - setDestructState({ - type: TransactionStateType.UNKNOWN, - }) - return - } - - // start waiting for provider to confirm tx - setDestructState({ - type: TransactionStateType.WAIT_FOR_CONFIRMING, - }) + if (!ITO_Contract || !id) return // estimate gas and compose transaction const config = { from: account, - gas: await ITO_Contract.methods - .destruct(id) - .estimateGas({ - from: account, - }) - .catch((error: Error) => { - setDestructState({ - type: TransactionStateType.FAILED, - error, - }) - throw error - }), + gas: await ITO_Contract.methods.destruct(id).estimateGas({ + from: account, + }), } // send transaction and wait for hash @@ -45,39 +24,14 @@ export function useDestructCallback(ito_address: string) { ITO_Contract.methods .destruct(id) .send(config as NonPayableTx) - .on(TransactionEventType.RECEIPT, (receipt: TransactionReceipt) => { - setDestructState({ - type: TransactionStateType.CONFIRMED, - no: 0, - receipt, - }) - resolve(receipt.transactionHash) - }) - .on(TransactionEventType.CONFIRMATION, (no: number, receipt: TransactionReceipt) => { - setDestructState({ - type: TransactionStateType.CONFIRMED, - no, - receipt, - }) + .on(TransactionEventType.CONFIRMATION, (no, receipt) => { resolve(receipt.transactionHash) }) .on(TransactionEventType.ERROR, (error: Error) => { - setDestructState({ - type: TransactionStateType.FAILED, - error, - }) reject(error) }) }) }, [ITO_Contract], ) - - const resetCallback = useCallback(() => { - setDestructState({ - type: TransactionStateType.UNKNOWN, - }) - }, []) - - return [destructState, destructCallback, resetCallback] as const } diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationContractClaimCallback.ts b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationContractClaimCallback.ts index 3ceca469f049..ab72cf70ea35 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationContractClaimCallback.ts +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationContractClaimCallback.ts @@ -1,49 +1,28 @@ -import { useSpaceStationContract } from './useSpaceStationContract' -import { - useAccount, - useSpaceStationGalaxyConstants, - useTransactionState, - TransactionStateType, - TransactionEventType, -} from '@masknet/web3-shared-evm' -import { useCallback } from 'react' -import type { CampaignInfo } from '../../types' import type { SpaceStationGalaxy } from '@masknet/web3-contracts/types/SpaceStationGalaxy' import type { NonPayableTx } from '@masknet/web3-contracts/types/types' -import { getAccountClaimSignature, mutationParticipate } from '../../Worker/apis/spaceStationGalaxy' +import { TransactionEventType, useAccount, useSpaceStationGalaxyConstants } from '@masknet/web3-shared-evm' +import { useAsyncFn } from 'react-use' import Services from '../../../../extension/service' +import type { CampaignInfo } from '../../types' +import { getAccountClaimSignature, mutationParticipate } from '../../Worker/apis/spaceStationGalaxy' +import { useSpaceStationContract } from './useSpaceStationContract' export function useSpaceStationContractClaimCallback(campaignInfo: CampaignInfo) { const account = useAccount() const spaceStationContract = useSpaceStationContract() const { CONTRACT_ADDRESS } = useSpaceStationGalaxyConstants() - const [claimState, setClaimState] = useTransactionState() - const claimCallback = useCallback(async () => { + return useAsyncFn(async () => { if (!CONTRACT_ADDRESS || !spaceStationContract || !campaignInfo) { - setClaimState({ type: TransactionStateType.UNKNOWN }) return } - // start waiting for provider to confirm tx - setClaimState({ - type: TransactionStateType.WAIT_FOR_CONFIRMING, - }) - - let useSignature = '' - try { - useSignature = await Services.Ethereum.personalSign( - `${campaignInfo.name} + const useSignature = await Services.Ethereum.personalSign( + `${campaignInfo.name} ${campaignInfo.description}`, - account, - ) - } catch (error) { - setClaimState({ - type: TransactionStateType.FAILED, - error: new Error('Not allowed to claim.'), - }) - } + account, + ) const { allow, signature, verifyIDs, nftCoreAddress, powahs } = await getAccountClaimSignature( useSignature, @@ -53,10 +32,7 @@ ${campaignInfo.description}`, ) if (!allow) { - setClaimState({ - type: TransactionStateType.FAILED, - error: new Error('Not allowed to claim.'), - }) + throw new Error('Not allowed to claim.') } const params = [campaignInfo.id, nftCoreAddress, verifyIDs[0], powahs[0], signature] as Parameters< SpaceStationGalaxy['methods']['claim'] @@ -64,15 +40,9 @@ ${campaignInfo.description}`, // estimate gas and compose transaction const config = { from: account, - gas: await spaceStationContract.methods - .claim(...params) - .estimateGas({ from: account }) - .catch((error) => { - setClaimState({ type: TransactionStateType.FAILED, error }) - throw error - }), + gas: await spaceStationContract.methods.claim(...params).estimateGas({ from: account }), } - return new Promise(async (resolve, reject) => { + return new Promise(async (resolve, reject) => { spaceStationContract.methods .claim(...params) .send(config as NonPayableTx) @@ -87,39 +57,15 @@ ${campaignInfo.description}`, ) if (!participated) { - setClaimState({ - type: TransactionStateType.FAILED, - error: new Error('Failed to claim'), - }) + throw new Error('Failed to claim') } }) - .on(TransactionEventType.RECEIPT, (receipt) => { - setClaimState({ - type: TransactionStateType.CONFIRMED, - no: 0, - receipt, - }) - resolve() - }) .on(TransactionEventType.CONFIRMATION, (no, receipt) => { - setClaimState({ - type: TransactionStateType.CONFIRMED, - no, - receipt, - }) - resolve() + resolve(receipt.transactionHash) }) .on(TransactionEventType.ERROR, (error) => { - setClaimState({ - type: TransactionStateType.FAILED, - error, - }) reject(error) }) }) }, [account, campaignInfo, CONTRACT_ADDRESS, spaceStationContract]) - - const resetCallback = useCallback(() => {}, [setClaimState]) - - return [claimState, claimCallback, resetCallback] as const } diff --git a/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx b/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx index faff29761645..bacbc617e7b8 100644 --- a/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx +++ b/packages/mask/src/plugins/MaskBox/SNSAdaptor/components/PreviewCard.tsx @@ -97,7 +97,7 @@ export function PreviewCard(props: PreviewCardProps) { }, [openBoxTransaction?.config, openBoxTransactionOverrides, openBoxTransactionGasLimit]) // #region open box - const [isOpening, openBoxCallback] = useTransactionCallback(txConfig, openBoxTransaction?.method) + const [{ loading: isOpening }, openBoxCallback] = useTransactionCallback(txConfig, openBoxTransaction?.method) const onRefresh = useCallback(() => { state[1](CardTab.Articles) setPaymentCount(1) diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftList.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftList.tsx index e26742b4bfd1..ba5f31bf2a4f 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftList.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftList.tsx @@ -3,8 +3,8 @@ import { ERC721ContractDetailed, formatNFT_TokenId } from '@masknet/web3-shared- import { List, ListItem, ListProps, Typography } from '@mui/material' import classnames from 'classnames' import { FC, HTMLProps, useState } from 'react' -import { useI18N } from '../../../utils' import { NFTCardStyledAssetPlayer } from '@masknet/shared' +import { useI18N } from '../locales' const useStyles = makeStyles()((theme) => { const smallQuery = `@media (max-width: ${theme.breakpoints.values.sm}px)` @@ -99,7 +99,7 @@ interface NftItemProps extends HTMLProps { } export const NftItem: FC = ({ contract, tokenId, className, claimed, renderOrder, ...rest }) => { - const { t } = useI18N() + const t = useI18N() const { classes } = useStyles() const [name, setName] = useState(formatNFT_TokenId(tokenId, 2)) @@ -116,7 +116,7 @@ export const NftItem: FC = ({ contract, tokenId, className, claime setERC721TokenName={setName} /> {name} - {claimed && {t('plugin_red_packet_claimed')}} + {claimed && {t.claimed()}}
) } diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryItem.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryItem.tsx index 286a4d520610..1b767ead5a4f 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryItem.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryItem.tsx @@ -1,5 +1,4 @@ import { FC, memo, MouseEventHandler, useCallback } from 'react' -import { Trans } from 'react-i18next' import classNames from 'classnames' import { fill } from 'lodash-unified' import { TokenIcon } from '@masknet/shared' @@ -9,12 +8,12 @@ import { WalletMessages } from '@masknet/plugin-wallet' import { ERC721ContractDetailed, useAccount, useERC721ContractDetailed } from '@masknet/web3-shared-evm' import { Box, ListItem, Typography } from '@mui/material' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' -import { useI18N } from '../../../utils/i18n-next-ui' import { dateTimeFormat } from '../../ITO/assets/formatDate' import type { NftRedPacketHistory } from '../types' import { useAvailabilityNftRedPacket } from './hooks/useAvailabilityNftRedPacket' import { useNftAvailabilityComputed } from './hooks/useNftAvailabilityComputed' import { NftList } from './NftList' +import { Translate, useI18N } from '../locales' const useStyles = makeStyles()((theme) => { const smallQuery = `@media (max-width: ${theme.breakpoints.values.sm}px)` @@ -150,7 +149,7 @@ export interface NftRedPacketHistoryItemProps { export const NftRedPacketHistoryItem: FC = memo( ({ history, onSend, onShowPopover, onHidePopover }) => { const account = useAccount() - const { t } = useI18N() + const t = useI18N() const { classes } = useStyles() const { computed: { canSend, isPasswordValid }, @@ -175,7 +174,7 @@ export const NftRedPacketHistoryItem: FC = memo( } } const handleShowPopover = (anchor: HTMLElement) => { - onShowPopover(anchor, t('plugin_nft_red_packet_data_broken')) + onShowPopover(anchor, t.nft_data_broken()) } return ( @@ -196,10 +195,10 @@ export const NftRedPacketHistoryItem: FC = memo( - {history.message === '' ? t('plugin_red_packet_best_wishes') : history.message} + {history.message === '' ? t.best_wishes() : history.message} - {t('plugin_red_packet_history_duration', { + {t.history_duration({ startTime: dateTimeFormat(new Date(history.creation_time)), endTime: dateTimeFormat( new Date(history.creation_time + history.duration), @@ -219,7 +218,7 @@ export const NftRedPacketHistoryItem: FC = memo( )} variant="contained" size="large"> - {t('plugin_red_packet_history_send')} + {t.send()} ) : null} @@ -237,14 +236,13 @@ export const NftRedPacketHistoryItem: FC = memo(
- , }} values={{ - claimedShares: history.claimers.length, - shares: history.shares, + claimedShares: history.claimers.length.toString(), + shares: history.shares.toString(), }} /> diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryList.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryList.tsx index 16affe48056f..dc8e88b63923 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryList.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/NftRedPacketHistoryList.tsx @@ -7,7 +7,8 @@ import { useRef, useState } from 'react' import type { NftRedPacketHistory } from '../types' import { useNftRedPacketHistory } from './hooks/useNftRedPacketHistory' import { NftRedPacketHistoryItem } from './NftRedPacketHistoryItem' -import { useI18N } from '../../../utils' +import { useI18N as useBaseI18n } from '../../../utils' +import { useI18N } from '../locales' const useStyles = makeStyles()((theme, _, refs) => { const smallQuery = `@media (max-width: ${theme.breakpoints.values.sm}px)` @@ -80,7 +81,8 @@ interface Props { export function NftRedPacketHistoryList({ onSend }: Props) { const { classes } = useStyles() - const { t } = useI18N() + const { t: tr } = useBaseI18n() + const t = useI18N() const account = useAccount() const chainId = useChainId() const { histories, fetchMore, loading } = useNftRedPacketHistory(account, chainId) @@ -101,7 +103,7 @@ export function NftRedPacketHistoryList({ onSend }: Props) { if (chainId === ChainId.BSC) { return ( - {t('plugin_chain_not_supported', { chain: 'Binance Smart Chain' })} + {t.chain_not_supported({ chain: 'Binance Smart Chain' })} ) } @@ -109,7 +111,7 @@ export function NftRedPacketHistoryList({ onSend }: Props) { if (loading) { return ( - {t('loading')} + {tr('loading')} ) } @@ -117,7 +119,7 @@ export function NftRedPacketHistoryList({ onSend }: Props) { if (!histories?.length) { return ( - {t('plugin_red_packet_nft_no_history')} + {t.nft_no_history()} ) } diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx index 1fc627f16cf3..06e1d7d1f0b7 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx @@ -4,9 +4,10 @@ import { useRemoteControlledDialog } from '@masknet/shared-base-ui' import { ChainId, useAccount, useChainIdValid } from '@masknet/web3-shared-evm' import { Box, useTheme } from '@mui/material' import ActionButton from '../../../../extension/options-page/DashboardComponents/ActionButton' -import { useI18N } from '../../../../utils' import { EthereumChainBoundary } from '../../../../web3/UI/EthereumChainBoundary' +import { useI18N as useBaseI18n } from '../../../../utils' import { EthereumWalletConnectedBoundary } from '../../../../web3/UI/EthereumWalletConnectedBoundary' +import { useI18N } from '../../locales' import { useStyles } from './useStyles' interface OperationFooterProps { @@ -28,7 +29,8 @@ export function OperationFooter({ onClaimOrRefund, }: OperationFooterProps) { const { classes } = useStyles() - const { t } = useI18N() + const { t: tr } = useBaseI18n() + const t = useI18N() const account = useAccount() const chainIdValid = useChainIdValid() const theme = useTheme() @@ -45,14 +47,14 @@ export function OperationFooter({ if (!account) { return ( - {t('plugin_wallet_connect_a_wallet')} + {tr('plugin_wallet_connect_a_wallet')} ) } if (!chainIdValid) { return ( - {t('plugin_wallet_invalid_network')} + {tr('plugin_wallet_invalid_network')} ) } @@ -73,13 +75,7 @@ export function OperationFooter({ disabled={isLoading} variant="contained" onClick={onClaimOrRefund}> - {canClaim - ? isClaiming - ? t('plugin_red_packet_claiming') - : t('plugin_red_packet_claim') - : isRefunding - ? t('plugin_red_packet_refunding') - : t('plugin_red_packet_refund')} + {canClaim ? (isClaiming ? t.claiming() : t.claim()) : isRefunding ? t.refunding() : t.refund()} ) } @@ -109,7 +105,7 @@ export function OperationFooter({ startIcon={} variant="contained" onClick={onShare}> - {t('share')} + {tr('share')} )} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx index 57be9b6a6518..d1f52642f190 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx @@ -15,7 +15,8 @@ import { usePostLink } from '../../../../components/DataSource/usePostInfo' import { activatedSocialNetworkUI } from '../../../../social-network' import { isFacebook } from '../../../../social-network-adaptor/facebook.com/base' import { isTwitter } from '../../../../social-network-adaptor/twitter.com/base' -import { useI18N } from '../../../../utils' +import { useI18N as useBaseI18n } from '../../../../utils' +import { useI18N } from '../../locales' import type { RedPacketAvailability, RedPacketJSONPayload } from '../../types' import { RedPacketStatus } from '../../types' import { useAvailabilityComputed } from '../hooks/useAvailabilityComputed' @@ -31,7 +32,8 @@ export interface RedPacketProps { export function RedPacket(props: RedPacketProps) { const { payload } = props - const { t } = useI18N() + const t = useI18N() + const { t: tr } = useBaseI18n() const { classes } = useStyles() // context @@ -54,12 +56,6 @@ export function RedPacket(props: RedPacketProps) { // #region remote controlled transaction dialog const postLink = usePostLink() - const shareTextOption = { - sender: payload.sender.name, - payload: postLink, - network: resolveNetworkName(networkType), - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - } const [{ loading: isClaiming, value: claimTxHash }, claimCallback] = useClaimCallback( payload.contract_version, @@ -68,15 +64,25 @@ export function RedPacket(props: RedPacketProps) { payload.contract_version > 3 ? web3.eth.accounts.sign(account, payload.password).signature : payload.password, ) - const shareText = ( - listOfStatus.includes(RedPacketStatus.claimed) || claimTxHash - ? isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? t('plugin_red_packet_share_message_official_account', shareTextOption) - : t('plugin_red_packet_share_message_not_twitter', shareTextOption) - : isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? t('plugin_red_packet_share_unclaimed_message_official_account', shareTextOption) - : t('plugin_red_packet_share_unclaimed_message_not_twitter', shareTextOption) - ).trim() + const shareText = useMemo(() => { + const isOnTwitter = isTwitter(activatedSocialNetworkUI) + const isOnFacebook = isFacebook(activatedSocialNetworkUI) + const shareTextOption = { + sender: payload.sender.name, + payload: postLink.toString(), + network: resolveNetworkName(networkType), + account: isTwitter(activatedSocialNetworkUI) ? tr('twitter_account') : tr('facebook_account'), + } + if (listOfStatus.includes(RedPacketStatus.claimed) || claimTxHash) { + return isOnTwitter || isOnFacebook + ? t.share_message_official_account(shareTextOption) + : t.share_message_not_twitter(shareTextOption) + } + + return isOnTwitter || isOnFacebook + ? t.share_unclaimed_message_official_account(shareTextOption) + : t.share_unclaimed_message_not_twitter(shareTextOption) + }, [payload, postLink, networkType, claimTxHash, listOfStatus, activatedSocialNetworkUI, t, tr]) const [{ loading: isRefunding }, isRefunded, refundCallback] = useRefundCallback( payload.contract_version, @@ -105,8 +111,7 @@ export function RedPacket(props: RedPacketProps) { const myStatus = useMemo(() => { if (token && listOfStatus.includes(RedPacketStatus.claimed)) - return t( - 'plugin_red_packet_description_claimed', + return t.description_claimed( (availability as RedPacketAvailability).claimed_amount ? { amount: formatBalance( @@ -114,9 +119,9 @@ export function RedPacket(props: RedPacketProps) { token.decimals, 8, ), - symbol: token.symbol, + symbol: token.symbol || '-', } - : { amount: '', symbol: '' }, + : { amount: '-', symbol: '-' }, ) return '' }, [listOfStatus, t, token]) @@ -125,18 +130,18 @@ export function RedPacket(props: RedPacketProps) { if (!availability || !token) return if (listOfStatus.includes(RedPacketStatus.expired) && canRefund) - return t('plugin_red_packet_description_refund', { + return t.description_refund({ balance: formatBalance(availability.balance, token.decimals), - symbol: token.symbol, + symbol: token.symbol ?? '-', }) - if (listOfStatus.includes(RedPacketStatus.refunded)) return t('plugin_red_packet_description_refunded') - if (listOfStatus.includes(RedPacketStatus.expired)) return t('plugin_red_packet_description_expired') - if (listOfStatus.includes(RedPacketStatus.empty)) return t('plugin_red_packet_description_empty') - if (!payload.password) return t('plugin_red_packet_description_broken') - return t('plugin_red_packet_description_failover', { + if (listOfStatus.includes(RedPacketStatus.refunded)) return t.description_refunded() + if (listOfStatus.includes(RedPacketStatus.expired)) return t.description_expired() + if (listOfStatus.includes(RedPacketStatus.empty)) return t.description_empty() + if (!payload.password) return t.description_broken() + return t.description_failover({ total: formatBalance(payload.total, token.decimals), - symbol: token.symbol, - shares: payload.shares ?? '-', + symbol: token.symbol ?? '-', + shares: payload.shares.toString() ?? '-', }) }, [availability, canRefund, token, t, payload, listOfStatus]) @@ -150,7 +155,7 @@ export function RedPacket(props: RedPacketProps) { return ( - {t('loading')} + {tr('loading')} ) @@ -178,7 +183,7 @@ export function RedPacket(props: RedPacketProps) { {myStatus} - {t('plugin_red_packet_from', { name: payload.sender.name ?? '-' })} + {t.from({ name: payload.sender.name ?? '-' })}
diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketConfirmDialog.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketConfirmDialog.tsx index 1bde8315ac8e..601ee15fcc2b 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketConfirmDialog.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketConfirmDialog.tsx @@ -6,7 +6,6 @@ import { getChainName, isNativeTokenAddress, resolveTokenLinkOnExplorer, - TransactionStateType, useAccount, useChainId, useNetworkType, @@ -18,10 +17,10 @@ import { makeStyles } from '@masknet/theme' import LaunchIcon from '@mui/icons-material/Launch' import { FormattedBalance, useOpenShareTxDialog } from '@masknet/shared' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' -import { useI18N } from '../../../utils' import { RedPacketSettings, useCreateCallback } from './hooks/useCreateCallback' import type { RedPacketJSONPayload, RedPacketRecord } from '../types' import { RedPacketRPC } from '../messages' +import { useI18N } from '../locales' const useStyles = makeStyles()((theme) => ({ link: { @@ -85,7 +84,7 @@ export interface ConfirmRedPacketFormProps { } export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { - const { t } = useI18N() + const t = useI18N() const { onBack, settings, onClose, onCreated } = props const { classes } = useStyles() const chainId = useChainId() @@ -101,12 +100,7 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { const web3 = useWeb3() const account = useAccount() const { address: publicKey, privateKey } = useMemo(() => web3.eth.accounts.create(), []) - const [createState, createCallback, resetCreateCallback] = useCreateCallback(settings!, contract_version, publicKey) - const isCreating = [ - TransactionStateType.WAIT_FOR_CONFIRMING, - TransactionStateType.HASH, - TransactionStateType.RECEIPT, - ].includes(createState.type) + const [{ loading: isCreating }, createCallback] = useCreateCallback(settings!, contract_version, publicKey) const openShareTxDialog = useOpenShareTxDialog() const createRedpacket = useCallback(async () => { const receipt = await createCallback() @@ -114,8 +108,6 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { await openShareTxDialog({ hash: receipt.transactionHash, }) - // reset state - resetCreateCallback() // the settings is not available if (!settings?.token) return @@ -141,9 +133,17 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { payload.current.creation_time = Number.parseInt(CreationSuccess.creation_time, 10) * 1000 payload.current.token = settings.token + const record: RedPacketRecord = { + id: receipt.transactionHash!, + from: '', + password: privateKey, + contract_version, + } + RedPacketRPC.discoverRedPacket(record) + // output the redpacket as JSON payload onCreated(payload.current) - }, [createCallback, resetCreateCallback, settings, openShareTxDialog, onCreated]) + }, [createCallback, settings, openShareTxDialog, onCreated]) // #endregion // assemble JSON payload @@ -154,7 +154,6 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { const { HAPPY_RED_PACKET_ADDRESS_V4 } = useRedPacketConstants() const networkType = useNetworkType() useEffect(() => { - if (createState.type !== TransactionStateType.UNKNOWN) return const contractAddress = HAPPY_RED_PACKET_ADDRESS_V4 if (!contractAddress) { onClose() @@ -163,25 +162,8 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { payload.current.contract_address = contractAddress payload.current.contract_version = contract_version payload.current.network = getChainName(chainId) - }, [chainId, networkType, contract_version, createState]) + }, [chainId, networkType, contract_version]) - useEffect(() => { - if (!settings?.token || createState.type === TransactionStateType.UNKNOWN) return - - // storing the created red packet in DB, it helps retrieve red packet password later - // save to the database early, otherwise red-packet would lose when close the tx dialog or - // web page before create successfully. - if (createState.type === TransactionStateType.HASH && createState.hash) { - payload.current.txid = createState.hash - const record: RedPacketRecord = { - id: createState.hash!, - from: '', - password: privateKey, - contract_version, - } - RedPacketRPC.discoverRedPacket(record) - } - }, [createState /* update tx dialog only if state changed */]) // #endregion return ( @@ -193,7 +175,7 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { - {t('plugin_red_packet_token')} + {t.token()} @@ -215,18 +197,18 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { - {t('plugin_red_packet_split_mode')} + {t.split_mode()} - {settings?.isRandom ? t('plugin_red_packet_random') : t('plugin_red_packet_average')} + {settings?.isRandom ? t.random() : t.average()} - {t('plugin_red_packet_shares')} + {t.shares()} @@ -239,7 +221,7 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { <> - {t('plugin_red_packet_amount_per_share')} + {t.amount_per_share()} @@ -257,7 +239,7 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { - {t('plugin_red_packet_amount_total')} + {t.amount_total()} @@ -273,21 +255,21 @@ export function RedPacketConfirmDialog(props: ConfirmRedPacketFormProps) { - {t('plugin_red_packet_hint')} + {t.hint()} - {t('plugin_red_packet_back')} + {t.back()} - {t('plugin_red_packet_send_symbol', { + {t.send_symbol({ amount: formatBalance(settings?.total, settings?.token?.decimals ?? 0), - symbol: settings?.token?.symbol, + symbol: settings?.token?.symbol ?? '-', })} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketCreateNew.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketCreateNew.tsx index cdc94626b9c1..3ceac4ff3cbd 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketCreateNew.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketCreateNew.tsx @@ -3,7 +3,7 @@ import { useChainId, ChainId } from '@masknet/web3-shared-evm' import { RedPacketFormProps, RedPacketERC20Form } from './RedPacketERC20Form' import { RedPacketERC721Form } from './RedPacketERC721Form' import AbstractTab, { AbstractTabProps } from '../../../components/shared/AbstractTab' -import { useI18N } from '../../../utils' +import { useI18N } from '../locales' import { activatedSocialNetworkUI } from '../../../social-network' import { IconURLs } from './IconURL' import { EnhanceableSite } from '@masknet/shared-base' @@ -49,7 +49,7 @@ const useStyles = makeStyles()((theme, { snsId }) => ({ export function RedPacketCreateNew(props: RedPacketFormProps & { state: readonly [number, (next: number) => void] }) { const { origin, onNext, onChange, onClose, state } = props - const { t } = useI18N() + const t = useI18N() const { classes } = useStyles({ snsId: activatedSocialNetworkUI.networkIdentifier }) const chainId = useChainId() @@ -59,7 +59,7 @@ export function RedPacketCreateNew(props: RedPacketFormProps & { state: readonly label: (
- {t('plugin_red_packet_erc20_tab_title')} + {t.erc20_tab_title()}
), children: , @@ -69,7 +69,7 @@ export function RedPacketCreateNew(props: RedPacketFormProps & { state: readonly label: (
- {t('plugin_red_packet_erc721_tab_title')} + {t.erc721_tab_title()}
), children: , diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketDialog.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketDialog.tsx index cdadc425c58d..5e4e92c5d94a 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketDialog.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketDialog.tsx @@ -13,7 +13,7 @@ import { } from '../../../components/DataSource/useActivatedUI' import AbstractTab, { AbstractTabProps } from '../../../components/shared/AbstractTab' import Services from '../../../extension/service' -import { useI18N } from '../../../utils' +import { useI18N } from '../locales' import { WalletMessages } from '../../Wallet/messages' import { RedPacketMetaKey } from '../constants' import { DialogTabs, RedPacketJSONPayload, RpTypeTabs } from '../types' @@ -63,7 +63,7 @@ interface RedPacketDialogProps extends withClasses { } export default function RedPacketDialog(props: RedPacketDialogProps) { - const { t } = useI18N() + const t = useI18N() const chainId = useChainId() const account = useAccount() const { classes } = useStyles() @@ -134,7 +134,7 @@ export default function RedPacketDialog(props: RedPacketDialogProps) { const tabProps: AbstractTabProps = { tabs: [ { - label: t('plugin_red_packet_create_new'), + label: t.create_new(), children: ( , sx: { p: 0 }, }, @@ -172,7 +172,7 @@ export default function RedPacketDialog(props: RedPacketDialogProps) { ) const isCreateStep = step === CreateRedPacketPageStep.NewRedPacketPage - const title = isCreateStep ? t('plugin_red_packet_display_name') : t('plugin_red_packet_details') + const title = isCreateStep ? t.display_name() : t.details() return ( diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx index a4843e141d93..1055ed3cbb27 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC20Form.tsx @@ -17,7 +17,8 @@ import { ChangeEvent, useCallback, useEffect, useMemo, useRef, useState } from ' import { usePickToken } from '@masknet/shared' import { useCurrentIdentity, useCurrentLinkedPersona } from '../../../components/DataSource/useActivatedUI' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' -import { useI18N } from '../../../utils' +import { useI18N } from '../locales' +import { useI18N as useBaseI18n } from '../../../utils' import { EthereumERC20TokenApprovedBoundary } from '../../../web3/UI/EthereumERC20TokenApprovedBoundary' import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' import { TokenAmountPanel } from '../../../web3/UI/TokenAmountPanel' @@ -82,7 +83,8 @@ export interface RedPacketFormProps extends withClasses { } export function RedPacketERC20Form(props: RedPacketFormProps) { - const { t } = useI18N() + const t = useI18N() + const { t: tr } = useBaseI18n() const classes = useStylesExtends(useStyles(), props) const { onChange, onNext, origin } = props // context @@ -105,7 +107,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) { // #region packet settings const [isRandom, setRandom] = useState(origin?.isRandom ? 1 : 0) - const [message, setMessage] = useState(origin?.message || t('plugin_red_packet_best_wishes')) + const [message, setMessage] = useState(origin?.message || t.best_wishes()) const currentIdentity = useCurrentIdentity() const { value: linkedPersona } = useCurrentLinkedPersona() @@ -153,32 +155,32 @@ export function RedPacketERC20Form(props: RedPacketFormProps) { // #endregion const validationMessage = useMemo(() => { - if (!token) return t('plugin_wallet_select_a_token') - if (!account) return t('plugin_wallet_connect_a_wallet') + if (!token) return t.select_a_token() + if (!account) return tr('plugin_wallet_connect_a_wallet') if (isZero(shares || '0')) return 'Enter shares' if (isGreaterThan(shares || '0', 255)) return 'At most 255 recipients' - if (isZero(amount)) return t('plugin_dhedge_enter_an_amount') + if (isZero(amount)) return tr('plugin_dhedge_enter_an_amount') if (isGreaterThan(totalAmount, tokenBalance)) - return t('plugin_gitcoin_insufficient_balance', { symbol: token.symbol }) + return tr('plugin_gitcoin_insufficient_balance', { symbol: token.symbol }) if (!isDivisible) - return t('plugin_red_packet_indivisible', { - symbol: token.symbol, + return t.indivisible({ + symbol: token.symbol!, amount: formatBalance(1, token.decimals), }) return '' - }, [account, amount, totalAmount, shares, token, tokenBalance]) + }, [account, amount, totalAmount, shares, token, tokenBalance, t, tr]) const creatingParams = useMemo( () => ({ duration, isRandom: Boolean(isRandom), name: senderName, - message: message || t('plugin_red_packet_best_wishes'), + message: message || t.best_wishes(), shares: shares || 0, token: token ? (omit(token, ['logoURI']) as FungibleTokenDetailed) : undefined, total: totalAmount.toFixed(), }), - [isRandom, senderName, message, t('plugin_red_packet_best_wishes'), shares, token, totalAmount], + [isRandom, senderName, message, t.best_wishes(), shares, token, totalAmount], ) const onClick = useCallback(() => { @@ -193,7 +195,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) { <>
- {t('plugin_red_packet_split_mode')} + {t.split_mode()} @@ -241,7 +243,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) {
@@ -282,7 +284,7 @@ export function RedPacketERC20Form(props: RedPacketFormProps) { fullWidth disabled={!!validationMessage} onClick={onClick}> - {validationMessage || t('plugin_red_packet_next')} + {validationMessage || t.next()} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC721Form.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC721Form.tsx index 63c55e2e534b..b53e3f69a5da 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC721Form.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketERC721Form.tsx @@ -1,7 +1,7 @@ import { Box, Typography, List, ListItem, CircularProgress } from '@mui/material' import { makeStyles } from '@masknet/theme' import { useState, useCallback, useEffect, useMemo } from 'react' -import { useI18N } from '../../../utils' +import { useI18N } from '../locales' import classNames from 'classnames' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' import { ERC721ContractSelectPanel } from '../../../web3/UI/ERC721ContractSelectPanel' @@ -201,7 +201,7 @@ interface RedPacketERC721FormProps { onClose: () => void } export function RedPacketERC721Form(props: RedPacketERC721FormProps) { - const { t } = useI18N() + const t = useI18N() const { onClose } = props const { classes } = useStyles() const [open, setOpen] = useState(false) @@ -259,10 +259,10 @@ export function RedPacketERC721Form(props: RedPacketERC721FormProps) { const { RED_PACKET_NFT_ADDRESS } = useNftRedPacketConstants() const validationMessage = useMemo(() => { - if (!balance) return t('plugin_red_packet_erc721_insufficient_balance') - if (tokenDetailedList.length === 0) return t('plugin_wallet_select_a_token') + if (!balance) return t.erc721_insufficient_balance() + if (tokenDetailedList.length === 0) return t.select_a_token() return '' - }, [tokenDetailedList.length, balance]) + }, [tokenDetailedList.length, balance, t]) return ( <> @@ -297,8 +297,11 @@ export function RedPacketERC721Form(props: RedPacketERC721FormProps) { {tokenDetailedOwnerList.length === 0 ? 'All' - : t('plugin_red_packet_nft_select_all_option', { - total: Math.min(NFT_RED_PACKET_MAX_SHARES, tokenDetailedOwnerList.length), + : t.nft_select_all_option({ + total: Math.min( + NFT_RED_PACKET_MAX_SHARES, + tokenDetailedOwnerList.length, + ).toString(), })}
@@ -310,9 +313,7 @@ export function RedPacketERC721Form(props: RedPacketERC721FormProps) { )}>
- - {t('plugin_red_packet_nft_select_partially_option')} - + {t.nft_select_partially_option()}
) @@ -338,12 +339,8 @@ export function RedPacketERC721Form(props: RedPacketERC721FormProps) { {contract && balance && !loadingOwnerList ? ( <> - - {t('plugin_red_packet_nft_unapproved_tip')} - - - {t('plugin_red_packet_nft_approve_all_tip')} - + {t.nft_unapproved_tip()} + {t.nft_approve_all_tip()} ) : null} @@ -358,7 +355,7 @@ export function RedPacketERC721Form(props: RedPacketERC721FormProps) { disabled={!!validationMessage} fullWidth onClick={() => setOpenConfirmDialog(true)}> - {t('plugin_red_packet_next')} + {t.next()} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketInHistoryList.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketInHistoryList.tsx index 3e0749c9e2fc..1a2595f81691 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketInHistoryList.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketInHistoryList.tsx @@ -18,9 +18,8 @@ import intervalToDuration from 'date-fns/intervalToDuration' import nextDay from 'date-fns/nextDay' import { omit, pick } from 'lodash-unified' import { MouseEvent, useCallback, useState } from 'react' -import { Trans } from 'react-i18next' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' -import { useI18N } from '../../../utils' +import { Translate, useI18N } from '../locales' import { dateTimeFormat } from '../../ITO/assets/formatDate' import { StyledLinearProgress } from '../../ITO/SNSAdaptor/StyledLinearProgress' import { RedPacketJSONPayload, RedPacketJSONPayloadFromChain, RedPacketStatus } from '../types' @@ -185,7 +184,7 @@ export interface RedPacketInHistoryListProps { export function RedPacketInHistoryList(props: RedPacketInHistoryListProps) { const account = useAccount() const { history, onSelect } = props - const { t } = useI18N() + const t = useI18N() const { classes } = useStyles() const isSmall = useMediaQuery((theme: Theme) => theme.breakpoints.down('sm')) const { @@ -246,28 +245,24 @@ export function RedPacketInHistoryList(props: RedPacketInHistoryListProps) {
- {history.sender.message === '' - ? t('plugin_red_packet_best_wishes') - : history.sender.message} + {history.sender.message === '' ? t.best_wishes() : history.sender.message}
- {t('plugin_red_packet_history_duration', { + {t.history_duration({ startTime: dateTimeFormat(new Date(history.creation_time)), endTime: dateTimeFormat(new Date(history.creation_time + history.duration), false), })} - {t('plugin_red_packet_history_total_amount', { + {t.history_total_amount({ amount: formatBalance(history.total, historyToken?.decimals, 6), - symbol: historyToken?.symbol, + symbol: historyToken?.symbol!, })} - {t('plugin_red_packet_history_split_mode', { - mode: history.is_random - ? t('plugin_red_packet_random') - : t('plugin_red_packet_average'), + {t.history_split_mode({ + mode: history.is_random ? t.random() : t.average(), })}
@@ -291,12 +286,12 @@ export function RedPacketInHistoryList(props: RedPacketInHistoryListProps) { variant="contained" size="large"> {canSend - ? t('plugin_red_packet_history_send') + ? t.send() : refunded - ? t('plugin_red_packet_refunding') + ? t.refunding() : listOfStatus.includes(RedPacketStatus.empty) - ? t('plugin_red_packet_empty') - : t('plugin_red_packet_refund')} + ? t.empty() + : t.refund()} - {t('plugin_red_packet_data_broken', { duration: formatRefundDuration })} + {t.data_broken({ duration: formatRefundDuration })}
@@ -319,20 +314,18 @@ export function RedPacketInHistoryList(props: RedPacketInHistoryListProps) { />
- , }} values={{ - claimedShares: history.claimers?.length ?? 0, - shares: history.shares, + claimedShares: history.claimers?.length.toString() ?? '0', + shares: history.shares.toString(), }} /> - , span: , @@ -344,7 +337,7 @@ export function RedPacketInHistoryList(props: RedPacketInHistoryListProps) { historyToken?.decimals, 6, ), - symbol: historyToken?.symbol, + symbol: historyToken?.symbol!, }} /> diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx index 3db5fa3656c9..62b11814cbc8 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx @@ -1,30 +1,31 @@ +import { PluginWalletConnectIcon, SharedIcon } from '@masknet/icons' +import { NFTCardStyledAssetPlayer } from '@masknet/shared' +import { openWindow } from '@masknet/shared-base-ui' import { makeStyles } from '@masknet/theme' import { - useAccount, resolveAddressLinkOnExplorer, - useWeb3, resolveNetworkName, - useNetworkType, TransactionStateType, + useAccount, + useNetworkType, + useWeb3, } from '@masknet/web3-shared-evm' import LaunchIcon from '@mui/icons-material/Launch' -import { Card, CardHeader, Typography, Link, CardMedia, CardContent, Button, Box, Skeleton } from '@mui/material' -import { useCallback, useEffect, useState } from 'react' -import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' -import { useI18N } from '../../../utils' -import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' -import type { RedPacketNftJSONPayload } from '../types' -import { useClaimNftRedpacketCallback } from './hooks/useClaimNftRedpacketCallback' -import { useAvailabilityNftRedPacket } from './hooks/useAvailabilityNftRedPacket' +import { Box, Button, Card, CardContent, CardHeader, CardMedia, Link, Skeleton, Typography } from '@mui/material' import classNames from 'classnames' +import { useCallback, useEffect, useMemo, useState } from 'react' import { usePostLink } from '../../../components/DataSource/usePostInfo' +import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' import { activatedSocialNetworkUI } from '../../../social-network' -import { isTwitter } from '../../../social-network-adaptor/twitter.com/base' import { isFacebook } from '../../../social-network-adaptor/facebook.com/base' -import { NFTCardStyledAssetPlayer } from '@masknet/shared' -import { openWindow } from '@masknet/shared-base-ui' -import { PluginWalletConnectIcon, SharedIcon } from '@masknet/icons' +import { isTwitter } from '../../../social-network-adaptor/twitter.com/base' +import { useI18N as useBaseI18N } from '../../../utils' import { EthereumChainBoundary } from '../../../web3/UI/EthereumChainBoundary' +import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' +import { useI18N } from '../locales' +import type { RedPacketNftJSONPayload } from '../types' +import { useAvailabilityNftRedPacket } from './hooks/useAvailabilityNftRedPacket' +import { useClaimNftRedpacketCallback } from './hooks/useClaimNftRedpacketCallback' const useStyles = makeStyles()((theme) => ({ root: { @@ -249,7 +250,8 @@ export interface RedPacketNftProps { } export function RedPacketNft({ payload }: RedPacketNftProps) { - const { t } = useI18N() + const { t: i18n } = useBaseI18N() + const t = useI18N() const { classes } = useStyles() const web3 = useWeb3() const account = useAccount() @@ -295,29 +297,23 @@ export function RedPacketNft({ payload }: RedPacketNftProps) { // #region on share const postLink = usePostLink() const networkType = useNetworkType() - const shareText = availability?.isClaimed - ? t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_red_packet_nft_share_claimed_message' - : 'plugin_red_packet_nft_share_claimed_message_not_twitter', - { - sender: payload.senderName, - payload: postLink, - network: resolveNetworkName(networkType), - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - }, - ).trim() - : t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_red_packet_nft_share_foreshow_message' - : 'plugin_red_packet_nft_share_foreshow_message_not_twitter', - { - sender: payload.senderName, - payload: postLink, - network: resolveNetworkName(networkType), - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - }, - ).trim() + const shareText = useMemo(() => { + const isTwitterOrFacebook = isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + const options = { + sender: payload.senderName, + payload: postLink.toString(), + network: resolveNetworkName(networkType), + account: isTwitter(activatedSocialNetworkUI) ? i18n('twitter_account') : i18n('facebook_account'), + } + if (availability?.isClaimed) { + return isTwitterOrFacebook + ? t.nft_share_claimed_message(options) + : t.nft_share_claimed_message_not_twitter(options) + } + return isTwitterOrFacebook + ? t.nft_share_foreshow_message(options) + : t.nft_share_foreshow_message_not_twitter(options) + }, [availability?.isClaimed, t, i18n]) const onShare = useCallback(() => { if (shareText) activatedSocialNetworkUI.utils.share?.(shareText) @@ -330,13 +326,13 @@ export function RedPacketNft({ payload }: RedPacketNftProps) { - {t('loading_failed')} + {i18n('loading_failed')}
@@ -389,14 +385,14 @@ export function RedPacketNft({ payload }: RedPacketNftProps) { ) : ( - {availability.claimedAmount}/{availability.totalAmount} {t('collectibles_name')} + {availability.claimedAmount}/{availability.totalAmount} {i18n('collectibles_name')} )} - {t('plugin_red_packet_nft_tip')} + {t.nft_tip()}
@@ -426,7 +422,7 @@ export function RedPacketNft({ payload }: RedPacketNftProps) { />
- {availability.expired ? t('plugin_red_packet_expired') : t('plugin_red_packet_completed')} + {availability.expired ? t.expired() : t.completed()}
@@ -439,7 +435,7 @@ export function RedPacketNft({ payload }: RedPacketNftProps) { fullWidth onClick={onShare} variant="contained"> - {t('share')} + {i18n('share')} {availability.isClaimed ? null : ( @@ -460,7 +456,7 @@ export function RedPacketNft({ payload }: RedPacketNftProps) { onClick={claimCallback} className={classes.button} fullWidth> - {isClaiming ? t('plugin_red_packet_claiming') : t('plugin_red_packet_claim')} + {isClaiming ? t.claiming() : t.claim()} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketPast.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketPast.tsx index 644196520eae..40f166399cf0 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketPast.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketPast.tsx @@ -2,7 +2,7 @@ import { useChainId, ChainId } from '@masknet/web3-shared-evm' import { makeStyles } from '@masknet/theme' import { useCallback, useState } from 'react' import AbstractTab, { AbstractTabProps } from '../../../components/shared/AbstractTab' -import { useI18N } from '../../../utils' +import { useI18N } from '../locales' import { IconURLs } from './IconURL' import { RedPacketHistoryList } from './RedPacketHistoryList' import { NftRedPacketHistoryList } from './NftRedPacketHistoryList' @@ -58,7 +58,7 @@ interface Props { } export function RedPacketPast({ onSelect, onClose }: Props) { - const { t } = useI18N() + const t = useI18N() const { classes } = useStyles() const state = useState(RpTypeTabs.ERC20) const chainId = useChainId() @@ -95,7 +95,7 @@ export function RedPacketPast({ onSelect, onClose }: Props) { label: (
- {t('plugin_red_packet_erc20_tab_title')} + {t.erc20_tab_title()}
), children: , @@ -105,7 +105,7 @@ export function RedPacketPast({ onSelect, onClose }: Props) { label: (
- {t('plugin_red_packet_erc721_tab_title')} + {t.erc721_tab_title()}
), children: , diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketMessagePanel.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketMessagePanel.tsx index 7270b5f44c14..86b54fb72449 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketMessagePanel.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketMessagePanel.tsx @@ -1,7 +1,7 @@ import classNames from 'classnames' import { Box, InputBase, Typography } from '@mui/material' import { makeStyles } from '@masknet/theme' -import { useI18N } from '../../../utils' +import { useI18N } from '../locales' const useStyles = makeStyles()((theme) => { return { @@ -40,20 +40,20 @@ export interface RedpacketMessagePanelProps { export function RedpacketMessagePanel(props: RedpacketMessagePanelProps) { const { onChange, message } = props const { classes } = useStyles() - const { t } = useI18N() + const t = useI18N() return (
- {t('plugin_red_packet_message_label')} + {t.message_label()}
onChange(e.target.value)} - inputProps={{ placeholder: t('plugin_red_packet_best_wishes') }} + inputProps={{ placeholder: t.best_wishes() }} value={message} />
diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketNftConfirmDialog.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketNftConfirmDialog.tsx index 0a676a0f9a01..3b96cc508aee 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketNftConfirmDialog.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedpacketNftConfirmDialog.tsx @@ -20,7 +20,7 @@ import { Button, Grid, Link, Typography, DialogContent, List, ListItem } from '@ import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' import LaunchIcon from '@mui/icons-material/Launch' -import { useI18N } from '../../../utils' +import { useI18N as useBaseI18N } from '../../../utils' import { useCreateNftRedpacketCallback } from './hooks/useCreateNftRedpacketCallback' import { useCurrentIdentity } from '../../../components/DataSource/useActivatedUI' import { useCompositionContext } from '@masknet/plugin-infra/content-script' @@ -29,6 +29,7 @@ import { WalletMessages } from '../../Wallet/messages' import { RedPacketRPC } from '../messages' import { useAsync } from 'react-use' import Services from '../../../extension/service' +import { useI18N } from '../locales' const useStyles = makeStyles()((theme) => ({ root: { @@ -167,7 +168,8 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps) const web3 = useWeb3() const { attachMetadata } = useCompositionContext() - const { t } = useI18N() + const { t: i18n } = useBaseI18N() + const t = useI18N() const { address: publicKey, privateKey } = useMemo(() => web3.eth.accounts.create(), []) const duration = 60 * 60 * 24 const currentIdentity = useCurrentIdentity() @@ -236,12 +238,12 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps) }, [createState, onSendPost]) return ( - + - {t('plugin_red_packet_nft_account_name')} + {t.nft_account_name()} @@ -266,7 +268,7 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps) - {t('plugin_red_packet_nft_attached_message')} + {t.nft_attached_message()} @@ -274,13 +276,13 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps) variant="body1" color="textPrimary" align="right" - className={(classes.text, classes.bold, classes.ellipsis)}> + className={classNames(classes.text, classes.bold, classes.ellipsis)}> {message} - {t('plugin_wallet_collections')} + {t.collections()} @@ -307,7 +309,7 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps) - {t('plugin_red_packet_nft_total_amount')} + {t.nft_total_amount()} @@ -327,7 +329,7 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps) onClick={onBack} size="large" variant="contained"> - {t('cancel')} + {i18n('cancel')} @@ -344,8 +346,8 @@ export function RedpacketNftConfirmDialog(props: RedpacketNftConfirmDialogProps) onClick={onSendTx} className={classNames(classes.button, classes.sendButton)} fullWidth> - {t('plugin_red_packet_send_symbol', { - amount: tokenList.length, + {t.send_symbol({ + amount: tokenList.length.toString(), symbol: tokenList.length > 1 ? 'NFTs' : 'NFT', })} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/SelectNftTokenDialog.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/SelectNftTokenDialog.tsx index 0915e71da8a8..acf9198e6695 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/SelectNftTokenDialog.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/SelectNftTokenDialog.tsx @@ -8,17 +8,17 @@ import { isSameAddress, formatNFT_TokenId, } from '@masknet/web3-shared-evm' -import { useI18N } from '../../../utils' +import { useI18N as useBaseI18N } from '../../../utils' import { DialogContent, Box, InputBase, Paper, Button, Typography, ListItem, CircularProgress } from '@mui/material' import QuestionMarkIcon from '@mui/icons-material/QuestionMark' import { makeStyles, ShadowRootTooltip } from '@masknet/theme' import { useCallback, useState, useEffect } from 'react' import { SearchIcon } from '@masknet/icons' import CheckIcon from '@mui/icons-material/Check' -import { Trans } from 'react-i18next' import { useUpdate } from 'react-use' import { findLastIndex } from 'lodash-unified' import { NFT_RED_PACKET_MAX_SHARES } from '../constants' +import { useI18N, Translate } from '../locales' interface StyleProps { isSelectSharesExceed: boolean @@ -320,7 +320,8 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { onClose, loadingOwnerList, } = props - const { t } = useI18N() + const { t: tr } = useBaseI18N() + const t = useI18N() const account = useAccount() const [tokenDetailed, setTokenDetailed] = useState() const [searched, setSearched] = useState(false) @@ -435,8 +436,7 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { }, [tokenDetailed, tokenDetailedSelectedList, setExistTokenDetailedList, onClose]) const NonExistedTokenList = () => ( - @@ -452,12 +452,10 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { /> ) + const maxSharesOptions = { amount: NFT_RED_PACKET_MAX_SHARES.toString() } + return ( - + {tokenDetailedOwnerList.length === 0 ? ( @@ -476,17 +474,13 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { className={classes.searchButton} variant="contained" onClick={onSearch}> - {t('search')} + {t.search()}
{loadingToken || !tokenDetailed || !contract ? ( - {loadingToken - ? t('wallet_loading_token') - : searched - ? t('wallet_search_no_result') - : null} + {loadingToken ? t.loading_token() : searched ? t.search_no_result() : null} ) : ( @@ -512,21 +506,15 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) {
- {isSelectSharesExceed - ? t('plugin_red_packet_nft_max_shares_tip', { amount: NFT_RED_PACKET_MAX_SHARES }) - : null} + {isSelectSharesExceed ? t.nft_max_shares_tip(maxSharesOptions) : null} {tokenDetailedSelectedList.length > NFT_RED_PACKET_MAX_SHARES - ? t('plugin_red_packet_nft_max_shares_tip', { - amount: NFT_RED_PACKET_MAX_SHARES, - }) - : t('plugin_red_packet_nft_max_shares', { - amount: NFT_RED_PACKET_MAX_SHARES, - })} + ? t.nft_max_shares_tip(maxSharesOptions) + : t.nft_max_shares(maxSharesOptions)} } placement="top-end" @@ -546,10 +534,10 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { variant="contained" onClick={onSubmit}> {tokenDetailed && !isOwner - ? t('wallet_add_nft_invalid_owner') + ? t.nft_invalid_owner() : isAdded - ? t('wallet_add_nft_already_added') - : t('confirm')} + ? t.nft_already_added() + : tr('confirm')} ) : ( @@ -574,14 +562,12 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { className={classes.searchButton} variant="contained" onClick={tokenDetailedOwnerList.length === 0 ? onSearch : onFilter}> - {t('search')} + {t.search()}
{(loadingToken || !tokenDetailed) && searched ? ( - - {loadingToken ? t('wallet_loading_token') : t('wallet_search_no_result')} - + {loadingToken ? t.loading_token() : t.search_no_result()} ) : tokenDetailed?.info.name ? ( @@ -606,12 +592,11 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { {selectAll ? : null} - {t('select_all')} + {tr('select_all')} - , }} @@ -670,9 +655,7 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { ) : null} - {isSelectSharesExceed - ? t('plugin_red_packet_nft_max_shares_tip', { amount: NFT_RED_PACKET_MAX_SHARES }) - : null} + {isSelectSharesExceed ? t.nft_max_shares_tip(maxSharesOptions) : null} @@ -681,12 +664,8 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { title={ {tokenDetailedSelectedList.length > NFT_RED_PACKET_MAX_SHARES - ? t('plugin_red_packet_nft_max_shares_tip', { - amount: NFT_RED_PACKET_MAX_SHARES, - }) - : t('plugin_red_packet_nft_max_shares', { - amount: NFT_RED_PACKET_MAX_SHARES, - })} + ? t.nft_max_shares_tip(maxSharesOptions) + : t.nft_max_shares(maxSharesOptions)} } placement="top-end" @@ -714,10 +693,10 @@ export function SelectNftTokenDialog(props: SelectNftTokenDialogProps) { variant="contained" onClick={onSubmit}> {tokenDetailed && !isOwner - ? t('wallet_add_nft_invalid_owner') + ? t.nft_invalid_owner() : isAdded - ? t('wallet_add_nft_already_added') - : t('confirm')} + ? t.nft_already_added() + : tr('confirm')} )} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/hooks/useCreateCallback.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/hooks/useCreateCallback.tsx index aced424d9e3e..f5b967e28b4c 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/hooks/useCreateCallback.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/hooks/useCreateCallback.tsx @@ -5,14 +5,13 @@ import { EthereumTokenType, FungibleTokenDetailed, TransactionEventType, - TransactionStateType, useAccount, useChainId, useTokenConstants, - useTransactionState, } from '@masknet/web3-shared-evm' import { omit } from 'lodash-unified' import { useCallback } from 'react' +import { useAsyncFn } from 'react-use' import type { TransactionReceipt } from 'web3-core' import Web3Utils from 'web3-utils' import { useRedPacketContract } from './useRedPacketContract' @@ -120,17 +119,10 @@ export function useCreateParams(redPacketSettings: RedPacketSettings | undefined export function useCreateCallback(redPacketSettings: RedPacketSettings, version: number, publicKey: string) { const account = useAccount() const chainId = useChainId() - const [createState, setCreateState] = useTransactionState() const redPacketContract = useRedPacketContract(version) const getCreateParams = useCreateParams(redPacketSettings, version, publicKey) - const resetCallback = useCallback(() => { - setCreateState({ - type: TransactionStateType.UNKNOWN, - }) - }, []) - const createCallback = useCallback(async () => { - resetCallback() + return useAsyncFn(async () => { const { token } = redPacketSettings const createParams = await getCreateParams() @@ -139,28 +131,15 @@ export function useCreateCallback(redPacketSettings: RedPacketSettings, version: const { gas, params, paramsObj, gasError } = createParams if (gasError) { - setCreateState({ - type: TransactionStateType.FAILED, - error: gasError, - }) return } try { checkParams(paramsObj) } catch (error) { - setCreateState({ - type: TransactionStateType.FAILED, - error: error as Error, - }) return } - // pre-step: start waiting for provider to confirm tx - setCreateState({ - type: TransactionStateType.WAIT_FOR_CONFIRMING, - }) - // estimate gas and compose transaction const value = toFixed(token.type === EthereumTokenType.Native ? paramsObj.total : 0) const config: PayableTx = { @@ -175,22 +154,11 @@ export function useCreateCallback(redPacketSettings: RedPacketSettings, version: .create_red_packet(...params) .send(config) .on(TransactionEventType.CONFIRMATION, (no, receipt) => { - setCreateState({ - type: TransactionStateType.CONFIRMED, - no, - receipt, - }) resolve(receipt) }) .on(TransactionEventType.ERROR, (error: Error) => { - setCreateState({ - type: TransactionStateType.FAILED, - error, - }) reject(error) }) }) }, [account, redPacketContract, redPacketSettings, chainId, getCreateParams]) - - return [createState, createCallback, resetCallback] as const } diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/index.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/index.tsx index f56ca1eb9aec..d1ec432b53a0 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/index.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/index.tsx @@ -1,4 +1,4 @@ -import { type Plugin, usePluginWrapper } from '@masknet/plugin-infra/content-script' +import { type Plugin, usePluginWrapper, PluginId } from '@masknet/plugin-infra/content-script' import { ChainId, EthereumTokenType, @@ -94,9 +94,9 @@ const sns: Plugin.SNSAdaptor.Definition = { ApplicationEntries: [ (() => { const icon = - const name = + const name = const recommendFeature = { - description: , + description: , backgroundGradient: 'linear-gradient(180.54deg, #FF9A9E 0.71%, #FECFEF 98.79%, #FECFEF 99.78%)', } return { @@ -125,7 +125,7 @@ const sns: Plugin.SNSAdaptor.Definition = { appBoardSortingDefaultPriority: 1, marketListSortingPriority: 1, icon, - description: , + description: , name, tutorialLink: 'https://realmasknetwork.notion.site/0a71fd421aae4563bd07caa3e2129e5b', category: 'dapp', diff --git a/packages/mask/src/plugins/RedPacket/base.ts b/packages/mask/src/plugins/RedPacket/base.ts index cb9aeeea4ca9..c1fe7aa7fc8b 100644 --- a/packages/mask/src/plugins/RedPacket/base.ts +++ b/packages/mask/src/plugins/RedPacket/base.ts @@ -2,6 +2,7 @@ import type { Plugin } from '@masknet/plugin-infra' import { NetworkPluginID } from '@masknet/plugin-infra/web3' import { ChainId } from '@masknet/web3-shared-evm' import { RedPacketMetaKey, RedPacketNftMetaKey, RedPacketPluginID } from './constants' +import { languages } from './locales/languages' export const base: Plugin.Shared.Definition = { ID: RedPacketPluginID, @@ -40,4 +41,5 @@ export const base: Plugin.Shared.Definition = { contribution: { metadataKeys: new Set([RedPacketMetaKey, RedPacketNftMetaKey]), }, + i18n: languages, } diff --git a/packages/mask/src/plugins/RedPacket/locales/en-US.json b/packages/mask/src/plugins/RedPacket/locales/en-US.json new file mode 100644 index 000000000000..b3491141c7f6 --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/en-US.json @@ -0,0 +1,84 @@ +{ + "promote": "🧧🧧🧧 Try sending Lucky Drop to your friends with tokens or NFTs to share the joy now! Install Mask.io to send your first Lucky Drop.", + "promote_short": "🧧🧧🧧 Try sending Lucky Drop to your friends with Mask.io.", + "nft_shift_select_tip": "You can also use {{text}} to select multiple NFTs.", + "collections": "Collections", + "select_a_token": "Select a Token", + "search": "Search", + "loading_token": "Loading token...", + "search_no_result": "No results.", + "nft_already_added": "The collectible has already been added.", + "nft_invalid_owner": "The collectible does not belong to you.", + "nft_max_shares": "The maximum number of NFTs to be sold in NFT lucky drop contract is {{amount}}.", + "nft_max_shares_tip": "The NFT lucky drop supports up to {{amount, number}} NFTs selected for one time.", + "nft_non_existed_tip": "Token ID does not exist or belong to you.", + "nft_select_collection": "Choose your collection", + "completed": "Completed", + "expired": "Expired", + "nft_tip": "This is an NFT lucky drop.", + "nft_share_foreshow_message_not_twitter": "@{{sender}} is sending an NFT lucky drop on {{network}} network. \n{{payload}}", + "nft_share_foreshow_message": "@{{sender}} is sending an NFT lucky drop on {{network}} network. Follow @{{account}} (mask.io) to claim NFT lucky drops.\n#mask_io #LuckyDrop\n{{payload}}", + "nft_share_claimed_message_not_twitter": "I just claimed an NFT lucky drop from @{{sender}} on {{network}} network.\n$t(promote_short) \n{{payload}}", + "nft_share_claimed_message": "I just claimed an NFT lucky drop from @{{sender}} on {{network}} network. Follow @{{account}} (mask.io) to claim NFT lucky drops.\n$t(promote_short)\n#mask_io #LuckyDrop\n{{payload}}", + "nft_total_amount": "Total Amount", + "nft_attached_message": "Attached Message", + "nft_account_name": "Wallet account", + "message_label": "Title", + "claiming": "Claiming...", + "claim": "Claim", + "data_broken": "The Lucky Drop can’t be sent due to data damage. Please withdraw the assets after {{duration}}.", + "refund": "Refund", + "empty": "Empty", + "refunding": "Refunding", + "history_send": "Send", + "history_total_amount": "Total Amount: {{amount}} {{symbol}}", + "history_split_mode": "Split Mode: {{mode}}", + "history_total_claimed_amount": "Total: {{claimedAmount}}/{{amount}} {{symbol}}", + "attached_message": "Attached Message", + "indivisible": "The minimum amount for each share is {{amount}} {{symbol}}", + "name": "Lucky Drop", + "description": "Gift crypto or NFTs to any users, first come, first served.", + "next": "Next", + "nft_approve_all_tip": "Note: When selecting approve all, all NFTs in the contract will be authorized for sale by default, including the NFTs transfered later.", + "nft_unapproved_tip": "You can get the rest of your NFTs back after 24 hours of sending.", + "nft_select_partially_option": "Select partially", + "nft_select_all_option": "ALL ({{total}} NFT)", + "erc721_insufficient_balance": "Insufficient Balance", + "erc721_tab_title": "Collectibles", + "erc20_tab_title": "Token", + "claimed": "Claimed", + "details": "Lucky Drop Details", + "display_name": "Plugin: Lucky Drop", + "select_existing": "Past", + "create_new": "New", + "send_symbol": "Send {{amount}} {{symbol}}", + "back": "Back", + "hint": "You can withdraw the remaining balance 24 hours after the Lucky Drop is sent.", + "amount_total": "Amount Total", + "amount_per_share": "Amount per Share", + "shares": "Shares", + "average": "Average", + "random": "Random", + "split_mode": "Split Mode", + "token": "Token", + "chain_not_supported": "Not supported on {{chain}} yet.", + "nft_no_history": "You haven’t created any NFT lucky drop yet. Try to create and share lucky with your friends.", + "history_claimed": "Claimed: {{claimedShares}}/{{shares}} Share", + "send": "Send", + "history_duration": "Time: {{startTime}} ~ {{endTime}} (UTC+8)", + "best_wishes": "Best Wishes!", + "nft_data_broken": "The Lucky Drop can’t be sent due to data damage.", + "from": "From: @{{name}}", + "share_message_official_account": "I just claimed a lucky drop from @{{sender}} on {{network}} network. Follow @{{account}} (mask.io) to claim lucky drops.\n$t(promote_short)\n#mask_io #LuckyDrop\n{{payload}}", + "share_message_not_twitter": "I just claimed a lucky drop from @{{sender}} on {{network}} network.\n$t(promote_short)\n{{payload}}", + "share_unclaimed_message_official_account": "Hi friends, I just found a lucky drop sent by @{{sender}} on {{network}} network. Follow @{{account}} (mask.io) to claim lucky drops.\n$t(promote_short)\n#mask_io #LuckyDrop\n{{payload}}", + "share_unclaimed_message_not_twitter": "Hi friends, I just found a lucky drop sent by @{{sender}} on {{network}} network.\n$t(promote_short)\n{{payload}}", + "description_claimed": "You got {{amount}} {{symbol}}", + "description_refund": "You could refund {{balance}} {{symbol}}.", + "description_refunded": "The Lucky Drop has been refunded.", + "description_expired": "The Lucky Drop is expired.", + "description_broken": "The Lucky Drop is broken.", + "description_empty": "The Lucky Drop is empty.", + "description_failover": "{{shares}} shares / {{total}} {{symbol}}", + "recommend_feature_description": "Surpirse your social friends with Lucky Drop" +} diff --git a/packages/mask/src/plugins/RedPacket/locales/index.ts b/packages/mask/src/plugins/RedPacket/locales/index.ts new file mode 100644 index 000000000000..d6ead60252e4 --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/index.ts @@ -0,0 +1,6 @@ +// This file is auto generated. DO NOT EDIT +// Run `npx gulp sync-languages` to regenerate. +// Default fallback language in a family of languages are chosen by the alphabet order +// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts + +export * from './i18n_generated' diff --git a/packages/mask/src/plugins/RedPacket/locales/ja-JP.json b/packages/mask/src/plugins/RedPacket/locales/ja-JP.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/ja-JP.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/RedPacket/locales/ko-KR.json b/packages/mask/src/plugins/RedPacket/locales/ko-KR.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/ko-KR.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/RedPacket/locales/languages.ts b/packages/mask/src/plugins/RedPacket/locales/languages.ts new file mode 100644 index 000000000000..e8cd5a8b1cd5 --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/languages.ts @@ -0,0 +1,34 @@ +// This file is auto generated. DO NOT EDIT +// Run `npx gulp sync-languages` to regenerate. +// Default fallback language in a family of languages are chosen by the alphabet order +// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts +import en_US from './en-US.json' +import ja_JP from './ja-JP.json' +import ko_KR from './ko-KR.json' +import qya_AA from './qya-AA.json' +import zh_CN from './zh-CN.json' +import zh_TW from './zh-TW.json' +export const languages = { + en: en_US, + ja: ja_JP, + ko: ko_KR, + qy: qya_AA, + 'zh-CN': zh_CN, + zh: zh_TW, +} +// @ts-ignore +if (import.meta.webpackHot) { + // @ts-ignore + import.meta.webpackHot.accept( + ['./en-US.json', './ja-JP.json', './ko-KR.json', './qya-AA.json', './zh-CN.json', './zh-TW.json'], + () => + globalThis.dispatchEvent?.( + new CustomEvent('MASK_I18N_HMR', { + detail: [ + 'com.maskbook.red_packet', + { en: en_US, ja: ja_JP, ko: ko_KR, qy: qya_AA, 'zh-CN': zh_CN, zh: zh_TW }, + ], + }), + ), + ) +} diff --git a/packages/mask/src/plugins/RedPacket/locales/qya-AA.json b/packages/mask/src/plugins/RedPacket/locales/qya-AA.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/qya-AA.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/RedPacket/locales/zh-CN.json b/packages/mask/src/plugins/RedPacket/locales/zh-CN.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/zh-CN.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/RedPacket/locales/zh-TW.json b/packages/mask/src/plugins/RedPacket/locales/zh-TW.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/RedPacket/locales/zh-TW.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx index 7986af9309d3..47d5a9576b6c 100644 --- a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx +++ b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsForm.tsx @@ -13,6 +13,7 @@ import { formatCurrency, getAaveConstants, isSameAddress, + resolveChainName, useAccount, useFungibleTokenBalance, useTokenConstants, @@ -26,7 +27,6 @@ import { useAsync, useAsyncFn } from 'react-use' import type { AbiItem } from 'web3-utils' import { ActionButtonPromise } from '../../../extension/options-page/DashboardComponents/ActionButton' import { activatedSocialNetworkUI } from '../../../social-network' -import { isFacebook } from '../../../social-network-adaptor/facebook.com/base' import { isTwitter } from '../../../social-network-adaptor/twitter.com/base' import { useI18N } from '../../../utils' import { EthereumChainBoundary } from '../../../web3/UI/EthereumChainBoundary' @@ -164,16 +164,12 @@ export function SavingsForm({ chainId, protocol, tab, onClose }: SavingsFormProp }, [protocol.bareToken, inputAmount, chainId]) const openShareTxDialog = useOpenShareTxDialog() - const shareText = [ - `I just deposit ${inputAmount} ${protocol.bareToken.symbol} with ${resolveProtocolName(protocol.type)}. ${ - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? `Follow @${ - isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') - } (mask.io) to deposit.` - : '' - }`, - '#mask_io', - ].join('\n') + const shareText = t('promote_savings', { + amount: inputAmount, + symbol: protocol.bareToken.symbol, + chain: resolveChainName(chainId), + account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), + }) const [, executor] = useAsyncFn(async () => { switch (tab) { case TabType.Deposit: diff --git a/packages/mask/src/plugins/Snapshot/SNSAdaptor/VotingCard.tsx b/packages/mask/src/plugins/Snapshot/SNSAdaptor/VotingCard.tsx index 1d09bbab169f..068d235a77f1 100644 --- a/packages/mask/src/plugins/Snapshot/SNSAdaptor/VotingCard.tsx +++ b/packages/mask/src/plugins/Snapshot/SNSAdaptor/VotingCard.tsx @@ -13,6 +13,7 @@ import { usePower } from './hooks/usePower' import { VoteConfirmDialog } from './VoteConfirmDialog' import { useRetry } from './hooks/useRetry' import { NetworkPluginID, useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' +import { activatedSocialNetworkUI } from '../../../social-network' const useStyles = makeStyles()((theme) => { return { @@ -52,11 +53,12 @@ export function VotingCard() { const networkPluginId = useCurrentWeb3NetworkPluginID() const retry = useRetry() const onVoteConfirm = useSnackbarCallback( - () => { + async () => { setLoading(true) - return PluginSnapshotRPC.vote(identifier, choice, account, proposal.type) + await PluginSnapshotRPC.vote(identifier, choice, account, proposal.type) + activatedSocialNetworkUI.utils.share?.(t('promote_snapshot')) }, - [choice, identifier], + [choice, identifier, account, proposal.type, t], () => { setLoading(false) setOpen(false) diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx index 0f3f1536c37f..656592bc4d28 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx @@ -21,7 +21,8 @@ import { useUnmount, useUpdateEffect } from 'react-use' import { activatedSocialNetworkUI } from '../../../../social-network' import { isFacebook } from '../../../../social-network-adaptor/facebook.com/base' import { isTwitter } from '../../../../social-network-adaptor/twitter.com/base' -import { useI18N } from '../../../../utils' +import { useI18N as useBaseI18N } from '../../../../utils' +import { useI18N } from '../../locales' import { isNativeTokenWrapper } from '../../helpers' import { PluginTraderMessages } from '../../messages' import { AllProviderTradeActionType, AllProviderTradeContext } from '../../trader/useAllProviderTradeContext' @@ -61,7 +62,8 @@ export function Trader(props: TraderProps) { const chainIdValid = useChainIdValid() const { NATIVE_TOKEN_ADDRESS } = useTokenConstants() const classes = useStylesExtends(useStyles(), props) - const { t } = useI18N() + const { t: tr } = useBaseI18N() + const t = useI18N() const { setTargetChainId } = TargetChainIdContext.useContainer() // #region trade state @@ -248,16 +250,17 @@ export function Trader(props: TraderProps) { }.${ isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) ? `Follow @${ - isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') + isTwitter(activatedSocialNetworkUI) ? tr('twitter_account') : tr('facebook_account') } (mask.io) to swap cryptocurrencies on ${ isTwitter(activatedSocialNetworkUI) ? 'Twitter' : 'Facebook' }.` : '' }`, '#mask_io', + t.promote(), ].join('\n') : '' - }, [focusedTrade?.value, inputToken, outputToken]) + }, [focusedTrade?.value, inputToken, outputToken, tr, t]) const openShareTxDialog = useOpenShareTxDialog() const onConfirmDialogConfirm = useCallback(async () => { setOpenConfirmDialog(false) diff --git a/packages/mask/src/plugins/Trader/base.ts b/packages/mask/src/plugins/Trader/base.ts index 2bb1969f0c29..e9970b26ff6b 100644 --- a/packages/mask/src/plugins/Trader/base.ts +++ b/packages/mask/src/plugins/Trader/base.ts @@ -2,6 +2,7 @@ import type { Plugin } from '@masknet/plugin-infra' import { NetworkPluginID } from '@masknet/plugin-infra/web3' import { ChainId } from '@masknet/web3-shared-evm' import { PLUGIN_ID } from './constants' +import { languages } from './locales/languages' export const base: Plugin.Shared.Definition = { ID: PLUGIN_ID, @@ -30,4 +31,5 @@ export const base: Plugin.Shared.Definition = { [NetworkPluginID.PLUGIN_SOLANA]: { supportedChainIds: [] }, }, }, + i18n: languages, } diff --git a/packages/mask/src/plugins/Trader/locales/en-US.json b/packages/mask/src/plugins/Trader/locales/en-US.json new file mode 100644 index 000000000000..5920a7a664f4 --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/en-US.json @@ -0,0 +1,3 @@ +{ + "promote": "Instantly token exchange on Twitter. Install Mask.io to explore “better server” on Multi-chain Dex." +} diff --git a/packages/mask/src/plugins/Trader/locales/index.ts b/packages/mask/src/plugins/Trader/locales/index.ts new file mode 100644 index 000000000000..d6ead60252e4 --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/index.ts @@ -0,0 +1,6 @@ +// This file is auto generated. DO NOT EDIT +// Run `npx gulp sync-languages` to regenerate. +// Default fallback language in a family of languages are chosen by the alphabet order +// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts + +export * from './i18n_generated' diff --git a/packages/mask/src/plugins/Trader/locales/ja-JP.json b/packages/mask/src/plugins/Trader/locales/ja-JP.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/ja-JP.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Trader/locales/ko-KR.json b/packages/mask/src/plugins/Trader/locales/ko-KR.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/ko-KR.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Trader/locales/languages.ts b/packages/mask/src/plugins/Trader/locales/languages.ts new file mode 100644 index 000000000000..a189384a2e40 --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/languages.ts @@ -0,0 +1,34 @@ +// This file is auto generated. DO NOT EDIT +// Run `npx gulp sync-languages` to regenerate. +// Default fallback language in a family of languages are chosen by the alphabet order +// To overwrite this, please overwrite packages/scripts/src/locale-kit-next/index.ts +import en_US from './en-US.json' +import ja_JP from './ja-JP.json' +import ko_KR from './ko-KR.json' +import qya_AA from './qya-AA.json' +import zh_CN from './zh-CN.json' +import zh_TW from './zh-TW.json' +export const languages = { + en: en_US, + ja: ja_JP, + ko: ko_KR, + qy: qya_AA, + 'zh-CN': zh_CN, + zh: zh_TW, +} +// @ts-ignore +if (import.meta.webpackHot) { + // @ts-ignore + import.meta.webpackHot.accept( + ['./en-US.json', './ja-JP.json', './ko-KR.json', './qya-AA.json', './zh-CN.json', './zh-TW.json'], + () => + globalThis.dispatchEvent?.( + new CustomEvent('MASK_I18N_HMR', { + detail: [ + 'com.maskbook.trader', + { en: en_US, ja: ja_JP, ko: ko_KR, qy: qya_AA, 'zh-CN': zh_CN, zh: zh_TW }, + ], + }), + ), + ) +} diff --git a/packages/mask/src/plugins/Trader/locales/qya-AA.json b/packages/mask/src/plugins/Trader/locales/qya-AA.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/qya-AA.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Trader/locales/zh-CN.json b/packages/mask/src/plugins/Trader/locales/zh-CN.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/zh-CN.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/Trader/locales/zh-TW.json b/packages/mask/src/plugins/Trader/locales/zh-TW.json new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/packages/mask/src/plugins/Trader/locales/zh-TW.json @@ -0,0 +1 @@ +{} diff --git a/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx b/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx index 53f8e5eda38c..d636468993f7 100644 --- a/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx +++ b/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx @@ -94,7 +94,7 @@ export function InvestDialog() { // #endregion // #region blocking - const [isInvesting, investCallback] = useInvestCallback(pool, amount.toFixed(), token) + const [{ loading: isInvesting }, investCallback] = useInvestCallback(pool, amount.toFixed(), token) const openShareTxDialog = useOpenShareTxDialog() const cashTag = isTwitter(activatedSocialNetworkUI) ? '$' : '' const shareText = token diff --git a/packages/mask/src/plugins/dHEDGE/hooks/useInvestCallback.ts b/packages/mask/src/plugins/dHEDGE/hooks/useInvestCallback.ts index ced58ff42cde..ec087c129d64 100644 --- a/packages/mask/src/plugins/dHEDGE/hooks/useInvestCallback.ts +++ b/packages/mask/src/plugins/dHEDGE/hooks/useInvestCallback.ts @@ -1,6 +1,6 @@ import { toFixed } from '@masknet/web3-shared-base' import { EthereumTokenType, FungibleTokenDetailed, TransactionEventType, useAccount } from '@masknet/web3-shared-evm' -import { useCallback, useState } from 'react' +import { useAsyncFn } from 'react-use' import { useDHedgePoolV1Contract, useDHedgePoolV2Contract } from '../contracts/useDHedgePool' import { Pool, PoolType } from '../types' @@ -15,9 +15,8 @@ export function useInvestCallback(pool: Pool | undefined, amount: string, token? const poolV2Contract = useDHedgePoolV2Contract(pool?.address ?? '') const account = useAccount() - const [loading, setLoading] = useState(false) - const investCallback = useCallback(async () => { + return useAsyncFn(async () => { if (!token || !poolV1Contract || !poolV2Contract) return // step 1: estimate gas @@ -32,11 +31,9 @@ export function useInvestCallback(pool: Pool | undefined, amount: string, token? : poolV2Contract.methods.deposit(token.address, amount) } - setLoading(true) const estimatedGas = await deposit() .estimateGas(config) .catch((error) => { - setLoading(false) throw error }) @@ -53,6 +50,4 @@ export function useInvestCallback(pool: Pool | undefined, amount: string, token? .on(TransactionEventType.ERROR, reject) }) }, [pool, account, amount, token]) - - return [loading, investCallback] as const } diff --git a/packages/mask/src/social-network-adaptor/twitter.com/injection/NFT/NFTAvatarInTwitter.tsx b/packages/mask/src/social-network-adaptor/twitter.com/injection/NFT/NFTAvatarInTwitter.tsx index 1fb279a56651..b8a0682dcea7 100644 --- a/packages/mask/src/social-network-adaptor/twitter.com/injection/NFT/NFTAvatarInTwitter.tsx +++ b/packages/mask/src/social-network-adaptor/twitter.com/injection/NFT/NFTAvatarInTwitter.tsx @@ -1,4 +1,4 @@ -import { createReactRootShadowed, MaskMessages, NFTAvatarEvent, startWatch } from '../../../../utils' +import { createReactRootShadowed, MaskMessages, NFTAvatarEvent, startWatch, useI18N } from '../../../../utils' import { searchTwitterAvatarLinkSelector, searchTwitterAvatarSelector } from '../../utils/selector' import { MutationObserverWatcher } from '@dimensiondev/holoflows-kit' import { makeStyles } from '@masknet/theme' @@ -16,6 +16,9 @@ import { trim } from 'lodash-unified' import { RSS3_KEY_SNS } from '../../../../plugins/Avatar/constants' import { openWindow } from '@masknet/shared-base-ui' import { usePersonaNFTAvatar } from '../../../../plugins/Avatar/hooks/usePersonaNFTAvatar' +import { NFTCardStyledAssetPlayer, useShowConfirm } from '@masknet/shared' +import { Box, Typography } from '@mui/material' +import { activatedSocialNetworkUI } from '../../../../social-network' export function injectNFTAvatarInTwitter(signal: AbortSignal) { const watcher = new MutationObserverWatcher(searchTwitterAvatarSelector()) @@ -61,6 +64,7 @@ function NFTAvatarInTwitter() { const windowSize = useWindowSize() const location = useLocation() + const { t } = useI18N() const showAvatar = useMemo( () => getAvatarId(identity.avatar ?? '') === avatar?.avatarId && avatar.avatarId, [avatar?.avatarId, identity.avatar], @@ -81,6 +85,7 @@ function NFTAvatarInTwitter() { const onUpdate = (data: NFTAvatarEvent) => { setNFTEvent(data) } + const openConfirmDialog = useShowConfirm() // After the avatar is set, it cannot be saved immediately, and must wait until the avatar of twitter is updated useAsync(async () => { @@ -118,6 +123,21 @@ function NFTAvatarInTwitter() { window.alert('Sorry, failed to save NFT Avatar. Please set again.') return } + openConfirmDialog({ + title: t('plugin_avatar_setup_share_title'), + content: ( + + + + {t('plugin_avatar_setup_success')} + + + ), + confirmLabel: t('share'), + onSubmit() { + activatedSocialNetworkUI.utils.share?.(t('plugin_avatar_setup_pfp_share')) + }, + }) setAvatar(avatar) MaskMessages.events.NFTAvatarTimelineUpdated.sendToAll( @@ -130,7 +150,7 @@ function NFTAvatarInTwitter() { ) setNFTEvent(undefined) - }, [identity.avatar]) + }, [identity.avatar, openConfirmDialog, t]) useEffect(() => { setAvatar(_avatar) diff --git a/packages/mask/src/tsconfig.json b/packages/mask/src/tsconfig.json index 9d137580ffed..5be5ef7a1573 100644 --- a/packages/mask/src/tsconfig.json +++ b/packages/mask/src/tsconfig.json @@ -31,6 +31,7 @@ { "path": "../../plugin-infra" }, { "path": "../../plugins/Wallet" }, { "path": "../../plugins/Flow" }, + { "path": "../../plugins/FileService" }, { "path": "../../external-plugin-previewer" }, { "path": "../../injected-script/sdk" }, { "path": "../../mask-sdk/server" }, diff --git a/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx b/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx index 8759226ec53d..7ae770d3fc76 100644 --- a/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx +++ b/packages/mask/src/web3/UI/EthereumERC20TokenApprovedBoundary.tsx @@ -154,7 +154,7 @@ export function EthereumERC20TokenApprovedBoundary(props: EthereumERC20TokenAppr ) : null} ) - if (approveStateType === ApproveStateType.PENDING || approveStateType === ApproveStateType.UPDATING) + if (transactionState.loading || approveStateType === ApproveStateType.UPDATING) return ( - {approveStateType === ApproveStateType.PENDING + {transactionState.loading ? t('plugin_ito_unlocking_symbol', { symbol: token.symbol }) : `Updating ${token.symbol}`} … diff --git a/packages/mask/src/web3/UI/EthereumERC721TokenApprovedBoundary.tsx b/packages/mask/src/web3/UI/EthereumERC721TokenApprovedBoundary.tsx index e10bd3c2760b..e84035bd6bf9 100644 --- a/packages/mask/src/web3/UI/EthereumERC721TokenApprovedBoundary.tsx +++ b/packages/mask/src/web3/UI/EthereumERC721TokenApprovedBoundary.tsx @@ -1,17 +1,16 @@ +import { makeStyles, useCustomSnackbar, useStylesExtends } from '@masknet/theme' import { - useERC721ContractIsApproveForAll, - useERC721ContractSetApproveForAllCallback, - TransactionStateType, ERC721ContractDetailed, resolveTransactionLinkOnExplorer, + useERC721ContractIsApproveForAll, + useERC721ContractSetApproveForAllCallback, } from '@masknet/web3-shared-evm' import OpenInNewIcon from '@mui/icons-material/OpenInNew' -import { useI18N } from '../../utils' -import { makeStyles, useCustomSnackbar, useStylesExtends } from '@masknet/theme' -import { Typography, Link } from '@mui/material' -import ActionButton, { ActionButtonProps } from '../../extension/options-page/DashboardComponents/ActionButton' -import { useMemo, useEffect } from 'react' +import { Link, Typography } from '@mui/material' +import { useCallback, useMemo } from 'react' import { EthereumAddress } from 'wallet.ts' +import ActionButton, { ActionButtonProps } from '../../extension/options-page/DashboardComponents/ActionButton' +import { useI18N } from '../../utils' const useStyles = makeStyles()(() => ({ snackBarText: { @@ -48,45 +47,39 @@ export function EthereumERC721TokenApprovedBoundary(props: EthereumERC712TokenAp const { t } = useI18N() const classes = useStylesExtends(useStyles(), props) const { value, loading, retry } = useERC721ContractIsApproveForAll(contractDetailed?.address, owner, operator) - const [approveState, approveCallback, resetCallback] = useERC721ContractSetApproveForAllCallback( + const [approveState, approveCallback] = useERC721ContractSetApproveForAllCallback( contractDetailed?.address, operator, true, ) const { showSnackbar } = useCustomSnackbar() - useEffect(() => { - if (approveState.type === TransactionStateType.CONFIRMED && approveState.no === 0) { - showSnackbar( -
- - {t('plugin_wallet_approve_all_nft_successfully', { symbol: contractDetailed?.symbol })} - - - - -
, - { - variant: 'success', - anchorOrigin: { horizontal: 'right', vertical: 'top' }, - }, - ) - resetCallback() - retry() - } else if (approveState.type === TransactionStateType.FAILED) { - showSnackbar(approveState.error.message, { - variant: 'error', - }) - resetCallback() + const approve = useCallback(async () => { + const hash = await approveCallback() + if (typeof hash !== 'string') { + showSnackbar(approveState.error?.message) + return } - }, [approveState, contractDetailed]) + showSnackbar( +
+ + {t('plugin_wallet_approve_all_nft_successfully', { symbol: contractDetailed?.symbol })} + + + + +
, + { + variant: 'success', + anchorOrigin: { horizontal: 'right', vertical: 'top' }, + }, + ) + retry() + }, [showSnackbar, approveState, retry, contractDetailed]) const validationMessage = useMemo(() => { if (!contractDetailed?.address || !EthereumAddress.isValid(contractDetailed?.address)) @@ -97,7 +90,7 @@ export function EthereumERC721TokenApprovedBoundary(props: EthereumERC712TokenAp return '' }, [contractDetailed, owner, operator, _validationMessage]) - if ([TransactionStateType.WAIT_FOR_CONFIRMING, TransactionStateType.HASH].includes(approveState.type)) { + if (approveState.loading) { return ( {t('plugin_wallet_approve_all_nft', { symbol: contractDetailed?.symbol diff --git a/packages/plugins/FileService/src/index.ts b/packages/plugins/FileService/src/index.ts index 69226b786ae4..79ee5520eaa9 100644 --- a/packages/plugins/FileService/src/index.ts +++ b/packages/plugins/FileService/src/index.ts @@ -1,6 +1,8 @@ import { registerPlugin } from '@masknet/plugin-infra' import { base } from './base' +export { FileInfoMetadataReader } from './helpers' + registerPlugin({ ...base, SNSAdaptor: { diff --git a/packages/web3-shared/evm/hooks/useERC20TokenApproveCallback.ts b/packages/web3-shared/evm/hooks/useERC20TokenApproveCallback.ts index 346b49771765..2e52b2049043 100644 --- a/packages/web3-shared/evm/hooks/useERC20TokenApproveCallback.ts +++ b/packages/web3-shared/evm/hooks/useERC20TokenApproveCallback.ts @@ -1,13 +1,13 @@ -import { useCallback, useMemo } from 'react' -import { once } from 'lodash-unified' import type { NonPayableTx } from '@masknet/web3-contracts/types/types' -import { TransactionStateType, TransactionEventType } from '../types' +import { isLessThan, toFixed } from '@masknet/web3-shared-base' +import { once } from 'lodash-unified' +import { useCallback, useMemo } from 'react' +import { useAsyncFn } from 'react-use' import { useERC20TokenContract } from '../contracts/useERC20TokenContract' +import { TransactionEventType } from '../types' import { useAccount } from './useAccount' import { useERC20TokenAllowance } from './useERC20TokenAllowance' import { useERC20TokenBalance } from './useERC20TokenBalance' -import { useTransactionState } from './useTransactionState' -import { isLessThan, toFixed } from '@masknet/web3-shared-base' const MaxUint256 = toFixed('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') @@ -23,7 +23,6 @@ export enum ApproveStateType { export function useERC20TokenApproveCallback(address?: string, amount?: string, spender?: string) { const account = useAccount() const erc20Contract = useERC20TokenContract(address) - const [transactionState, setTransactionState] = useTransactionState() // read the approved information from the chain const { @@ -44,43 +43,20 @@ export function useERC20TokenApproveCallback(address?: string, amount?: string, if (!amount || !spender) return ApproveStateType.UNKNOWN if (loadingBalance || loadingAllowance) return ApproveStateType.UPDATING if (errorBalance || errorAllowance) return ApproveStateType.FAILED - if (transactionState.type === TransactionStateType.WAIT_FOR_CONFIRMING) return ApproveStateType.PENDING return isLessThan(allowance, amount) ? ApproveStateType.NOT_APPROVED : ApproveStateType.APPROVED - }, [ - amount, - spender, - balance, - allowance, - errorBalance, - errorAllowance, - loadingAllowance, - loadingBalance, - transactionState.type, - ]) + }, [amount, spender, balance, allowance, errorBalance, errorAllowance, loadingAllowance, loadingBalance]) - const approveCallback = useCallback( + const [state, approveCallback] = useAsyncFn( async (useExact = false) => { - setTransactionState({ - type: TransactionStateType.UNKNOWN, - }) if (approveStateType === ApproveStateType.UNKNOWN || !amount || !spender || !erc20Contract) { return } // error: failed to approve token if (approveStateType !== ApproveStateType.NOT_APPROVED) { - setTransactionState({ - type: TransactionStateType.FAILED, - error: new Error('Failed to approve token.'), - }) return } - // start waiting for provider to confirm tx - setTransactionState({ - type: TransactionStateType.WAIT_FOR_CONFIRMING, - }) - // estimate gas and compose transaction const config = { from: account, @@ -96,16 +72,12 @@ export function useERC20TokenApproveCallback(address?: string, amount?: string, }) }) .catch((error) => { - setTransactionState({ - type: TransactionStateType.FAILED, - error, - }) throw error }), } // send transaction and wait for hash - return new Promise(async (resolve, reject) => { + return new Promise(async (resolve, reject) => { const revalidate = once(() => { revalidateBalance() revalidateAllowance() @@ -113,43 +85,25 @@ export function useERC20TokenApproveCallback(address?: string, amount?: string, erc20Contract.methods .approve(spender, useExact ? amount : MaxUint256) .send(config as NonPayableTx) - .on(TransactionEventType.RECEIPT, (receipt) => { - setTransactionState({ - type: TransactionStateType.CONFIRMED, - no: 0, - receipt, - }) + .on(TransactionEventType.RECEIPT, () => { revalidate() - resolve() }) .on(TransactionEventType.CONFIRMATION, (no, receipt) => { - setTransactionState({ - type: TransactionStateType.CONFIRMED, - no, - receipt, - }) revalidate() - resolve() + resolve(receipt.transactionHash) }) .on(TransactionEventType.ERROR, (error) => { - setTransactionState({ - type: TransactionStateType.FAILED, - error, - }) revalidate() reject(error) }) }) }, - [account, amount, balance, spender, loadingAllowance, loadingBalance, erc20Contract, approveStateType], + [account, amount, spender, erc20Contract, approveStateType], ) const resetCallback = useCallback(() => { revalidateBalance() revalidateAllowance() - setTransactionState({ - type: TransactionStateType.UNKNOWN, - }) }, [revalidateBalance, revalidateAllowance]) return [ @@ -160,7 +114,7 @@ export function useERC20TokenApproveCallback(address?: string, amount?: string, spender, balance, }, - transactionState, + state, approveCallback, resetCallback, ] as const diff --git a/packages/web3-shared/evm/hooks/useERC721ContractSetApproveForAllCallback.ts b/packages/web3-shared/evm/hooks/useERC721ContractSetApproveForAllCallback.ts index 6eb6672de354..99c2cf200196 100644 --- a/packages/web3-shared/evm/hooks/useERC721ContractSetApproveForAllCallback.ts +++ b/packages/web3-shared/evm/hooks/useERC721ContractSetApproveForAllCallback.ts @@ -1,9 +1,8 @@ -import { useCallback } from 'react' import type { NonPayableTx } from '@masknet/web3-contracts/types/types' -import { useAccount } from './useAccount' -import { useTransactionState } from './useTransactionState' +import { useAsyncFn } from 'react-use' import { useERC721TokenContract } from '../contracts' -import { TransactionStateType, TransactionEventType } from '../types' +import { TransactionEventType } from '../types' +import { useAccount } from './useAccount' import { useChainId } from './useChainId' /** @@ -19,62 +18,32 @@ export function useERC721ContractSetApproveForAllCallback( const account = useAccount() const chainId = useChainId() const erc721TokenContract = useERC721TokenContract(contractAddress) - const [approveState, setApproveState] = useTransactionState() - const approveCallback = useCallback(async () => { + return useAsyncFn(async () => { if (!erc721TokenContract || !contractAddress || !operator) { - setApproveState({ type: TransactionStateType.UNKNOWN }) return } - setApproveState({ - type: TransactionStateType.WAIT_FOR_CONFIRMING, - }) - const config = { from: account, gas: await erc721TokenContract.methods .setApprovalForAll(operator, approved) .estimateGas({ from: account }) .catch((error) => { - setApproveState({ type: TransactionStateType.FAILED, error }) throw error }), } - return new Promise(async (resolve, reject) => { + return new Promise(async (resolve, reject) => { erc721TokenContract.methods .setApprovalForAll(operator, approved) .send(config as NonPayableTx) - .on(TransactionEventType.RECEIPT, (receipt) => { - setApproveState({ - type: TransactionStateType.CONFIRMED, - no: 0, - receipt, - }) - resolve() - }) .on(TransactionEventType.CONFIRMATION, (no, receipt) => { - setApproveState({ - type: TransactionStateType.CONFIRMED, - no, - receipt, - }) - resolve() + resolve(receipt.transactionHash) }) .on(TransactionEventType.ERROR, (error) => { - setApproveState({ - type: TransactionStateType.FAILED, - error, - }) reject(error) }) }) - }, [account, chainId, erc721TokenContract, approved, contractAddress, operator, setApproveState]) - - const resetCallback = useCallback(() => { - setApproveState({ type: TransactionStateType.UNKNOWN }) - }, []) - - return [approveState, approveCallback, resetCallback] as const + }, [account, chainId, erc721TokenContract, approved, contractAddress, operator]) } diff --git a/packages/web3-shared/evm/hooks/useTransactionCallback.ts b/packages/web3-shared/evm/hooks/useTransactionCallback.ts index b2a8f6f446d2..a2f6d92d0f7e 100644 --- a/packages/web3-shared/evm/hooks/useTransactionCallback.ts +++ b/packages/web3-shared/evm/hooks/useTransactionCallback.ts @@ -1,32 +1,24 @@ import type { PayableTransactionObject, PayableTx } from '@masknet/web3-contracts/types/types' import { omit } from 'lodash-unified' -import { useCallback, useState } from 'react' +import { useAsyncFn } from 'react-use' import { TransactionEventType } from '../types' export function useTransactionCallback( config: PayableTx | undefined, method: PayableTransactionObject | undefined, ) { - const [loading, setLoading] = useState(false) - - const updateCallback = useCallback(async () => { + return useAsyncFn(async () => { if (!config || !method) return const gasExpectedConfig = { ...config } - setLoading(true) try { const estimatedGas = await method.estimateGas(omit(config, 'gas')) if (!gasExpectedConfig.gas && estimatedGas) { gasExpectedConfig.gas = estimatedGas } } catch (error) { - try { - await method.call(config) - } catch (error) { - setLoading(false) - throw error - } + await method.call(config) } return new Promise(async (resolve, reject) => { @@ -40,6 +32,4 @@ export function useTransactionCallback( }) }) }, [config, method]) - - return [loading, updateCallback] as const } From 988c25a66a9ca1e6882ca5c21e5a329b15438f84 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 27 May 2022 12:09:26 +0800 Subject: [PATCH 04/17] fix: eslint --- .../backup-format/src/utils/hex2buffer.ts | 2 +- packages/backup-format/src/version-1/index.ts | 6 +++--- packages/backup-format/src/version-2/index.ts | 4 ++-- .../src/components/CreateWalletForm/index.tsx | 4 ++-- .../components/FungibleTokenTable/index.tsx | 2 +- .../encryption/src/encryption/Decryption.ts | 2 +- .../encryption/src/encryption/v38-ecdh.ts | 2 +- .../main/EventListenerPatch/capture.ts | 2 +- .../database/avatar-cache/avatar.ts | 2 +- .../mask/background/database/post/dbType.ts | 2 +- .../mask/background/database/utils/openDB.ts | 8 ++++---- .../background/services/__utils__/convert.ts | 4 ++-- .../background/services/backup/restore.ts | 2 +- .../services/helper/deprecated-storage.ts | 2 +- packages/mask/src/UIRoot.tsx | 2 +- .../DecryptedPost/DecryptedPost.tsx | 2 +- .../src/components/shared/AbstractTab.tsx | 4 ++-- .../mask/src/database/helpers/pagination.ts | 2 +- .../EthereumServices/nonce.ts | 2 +- .../providers/WalletConnect.ts | 4 ++-- .../EthereumServices/rpc/abi.ts | 4 ++-- .../Wallet/Transfer/Prior1559Transfer.tsx | 2 +- .../pages/Wallet/Transfer/Transfer1559.tsx | 2 +- .../components/DeriveWalletTable/index.tsx | 2 +- .../src/plugins/Collectible/types/opensea.ts | 4 ++-- .../src/plugins/Collectible/types/rarible.ts | 4 ++-- .../plugins/EVM/UI/Web3State/getAssetsFn.ts | 6 +++--- .../FindTruman/SNSAdaptor/ConstPromise.ts | 4 ++-- packages/mask/src/plugins/FindTruman/types.ts | 2 +- .../Gitcoin/hooks/useDonateCallback.ts | 2 +- .../plugins/ITO/SNSAdaptor/NftAirdropCard.tsx | 4 ++-- .../plugins/ITO/SNSAdaptor/hooks/useFill.ts | 2 +- .../plugins/ITO/SNSAdaptor/hooks/useRegion.ts | 4 ++-- .../ITO/Worker/apis/spaceStationGalaxy.ts | 2 +- .../src/plugins/ITO/Worker/apis/subgraph.ts | 20 +++++++++---------- packages/mask/src/plugins/ITO/types.ts | 4 ++-- packages/mask/src/plugins/MaskBox/type.ts | 4 ++-- .../RedPacket/Worker/apis/erc20Redpacket.ts | 2 +- packages/mask/src/plugins/RedPacket/types.ts | 6 +++--- .../mask/src/plugins/Savings/constants.ts | 4 ++-- .../plugins/Savings/protocols/AAVEProtocol.ts | 8 ++++---- .../src/plugins/Snapshot/Worker/apis/index.ts | 2 +- packages/mask/src/plugins/Snapshot/types.ts | 8 ++++---- .../SNSAdaptor/trending/CoinMetadataTable.tsx | 2 +- .../SNSAdaptor/trending/LBPPriceChart.tsx | 2 +- .../SNSAdaptor/trending/PriceChangedTable.tsx | 2 +- .../mask/src/plugins/Trader/apis/LBP/index.ts | 6 +++--- .../plugins/Trader/apis/coingecko/index.ts | 4 ++-- .../Trader/apis/uniswap-health/index.ts | 4 ++-- .../Trader/apis/uniswap-v2-subgraph/index.ts | 6 +++--- .../Trader/graphs/usePriceLineChart.ts | 2 +- .../trader/uniswap/useAllCommonPairs.ts | 6 +++--- .../Trader/trader/uniswap/useAllV3Routes.ts | 6 +++--- .../plugins/Trader/trader/uniswap/usePools.ts | 8 ++++---- .../Trader/trader/uniswap/useV3SwapPools.ts | 2 +- .../Trader/trending/useCurrentCurrency.ts | 4 ++-- packages/mask/src/plugins/Trader/types/0x.ts | 4 ++-- .../mask/src/plugins/Trader/types/trader.ts | 2 +- .../src/plugins/UnlockProtocol/Services.ts | 8 ++++---- packages/mask/src/plugins/Wallet/apis/ens.ts | 4 ++-- .../plugins/Wallet/services/wallet/index.ts | 8 ++++---- .../mask/src/plugins/hooks/useLineChart.ts | 2 +- .../src/plugins/hooks/usePriceLineChart.ts | 2 +- .../utils/create-post-context.ts | 2 +- packages/mask/src/utils/hooks/useSuspense.ts | 2 +- .../utils/shadow-root/renderInShadowRoot.tsx | 2 +- packages/plugin-infra/src/web3-types.ts | 2 +- .../Flow/src/apis/getFungibleAssets.ts | 4 ++-- .../SNSAdaptor/components/DonationCard.tsx | 4 ++-- packages/plugins/RSS3/src/types.ts | 4 ++-- .../Solana/src/apis/getFungibleAssets.ts | 4 ++-- packages/plugins/Solana/src/apis/shared.ts | 2 +- packages/plugins/example/src/Worker/index.ts | 2 +- packages/shared-base/src/Identifier/map.ts | 8 ++++---- packages/shared-base/src/NextID/type.ts | 2 +- .../UI/components/ConcealableTabs/index.tsx | 2 +- .../components/MiniNetworkSelector/index.tsx | 4 ++-- packages/theme/src/ShadowRoot/Contexts.ts | 2 +- .../ShadowRoot/createReactRootShadowed.tsx | 2 +- packages/theme/src/Theme/Provider.tsx | 2 +- .../theme/src/UIHelper/custom-ui-helper.tsx | 2 +- packages/theme/stories/utils/Material-UI.ts | 2 +- packages/theme/stories/utils/args.ts | 2 +- packages/typed-message/base/utils/extract.ts | 4 ++-- packages/typed-message/base/utils/internal.ts | 4 ++-- packages/web3-constants/compile-constants.ts | 2 +- packages/web3-contracts/compile-contracts.ts | 2 +- packages/web3-providers/src/opensea/types.ts | 12 +++++------ packages/web3-providers/src/rarible/index.ts | 2 +- packages/web3-providers/src/rarible/types.ts | 4 ++-- packages/web3-providers/src/types.ts | 16 +++++++-------- .../evm/constants/getContractOwnerDomain.ts | 2 +- .../evm/hooks/useERC20TokenDetailed.ts | 2 +- .../useERC20TokensDetailedFromTokenLists.ts | 4 ++-- .../evm/hooks/useERC721TokenDetailed.ts | 2 +- .../web3-shared/evm/hooks/useMulticall.ts | 4 ++-- 96 files changed, 181 insertions(+), 181 deletions(-) diff --git a/packages/backup-format/src/utils/hex2buffer.ts b/packages/backup-format/src/utils/hex2buffer.ts index 4b8f76f2e0c2..b4fa7099a733 100644 --- a/packages/backup-format/src/utils/hex2buffer.ts +++ b/packages/backup-format/src/utils/hex2buffer.ts @@ -22,7 +22,7 @@ export function hex2buffer(hexString: string, padded?: boolean) { } /** @internal */ -function concat(...buf: (Uint8Array | number[])[]) { +function concat(...buf: Array) { const res = new Uint8Array(sum(buf.map((item) => item.length))) let offset = 0 buf.forEach((item) => { diff --git a/packages/backup-format/src/version-1/index.ts b/packages/backup-format/src/version-1/index.ts index 7abf0376c303..4f001c0dc895 100644 --- a/packages/backup-format/src/version-1/index.ts +++ b/packages/backup-format/src/version-1/index.ts @@ -89,16 +89,16 @@ interface BackupJSONFileVersion1 { publicKey: EC_Public_JsonWebKey privateKey: EC_Private_JsonWebKey localKey: AESJsonWebKey - previousIdentifiers?: { network: string; userId: string }[] + previousIdentifiers?: Array<{ network: string; userId: string }> nickname?: string }> people?: Array<{ network: string userId: string publicKey: EC_Public_JsonWebKey - previousIdentifiers?: { network: string; userId: string }[] + previousIdentifiers?: Array<{ network: string; userId: string }> nickname?: string - groups?: { network: string; groupID: string; virtualGroupOwner: string | null }[] + groups?: Array<{ network: string; groupID: string; virtualGroupOwner: string | null }> // Note: those props are not existed in the backup, just to make the code more readable privateKey?: EC_Private_JsonWebKey diff --git a/packages/backup-format/src/version-2/index.ts b/packages/backup-format/src/version-2/index.ts index 2ed7c710d425..7a9da8856975 100644 --- a/packages/backup-format/src/version-2/index.ts +++ b/packages/backup-format/src/version-2/index.ts @@ -322,7 +322,7 @@ interface BackupJSONFileVersion2 { privateKey?: JsonWebKey localKey?: JsonWebKey nickname?: string - linkedProfiles: [/** ProfileIdentifier.toText() */ string, LinkedProfileDetails][] + linkedProfiles: Array<[/** ProfileIdentifier.toText() */ string, LinkedProfileDetails]> createdAt: number // Unix timestamp updatedAt: number // Unix timestamp }> @@ -345,7 +345,7 @@ interface BackupJSONFileVersion2 { postBy: string // ProfileIdentifier.toText() identifier: string // PostIVIdentifier.toText() postCryptoKey?: JsonWebKey - recipients: 'everyone' | [/** ProfileIdentifier.toText() */ string, { reason: RecipientReasonJSON[] }][] + recipients: 'everyone' | Array<[/** ProfileIdentifier.toText() */ string, { reason: RecipientReasonJSON[] }]> /** @deprecated */ recipientGroups: never[] foundAt: number // Unix timestamp diff --git a/packages/dashboard/src/components/CreateWalletForm/index.tsx b/packages/dashboard/src/components/CreateWalletForm/index.tsx index ddb77638de16..2a5df398e1a0 100644 --- a/packages/dashboard/src/components/CreateWalletForm/index.tsx +++ b/packages/dashboard/src/components/CreateWalletForm/index.tsx @@ -31,11 +31,11 @@ const useStyles = makeStyles()((theme) => ({ // TODO: actions, and icon may be an img url export interface CreateWalletFormProps { - options: { + options: Array<{ label: string icon: React.ReactNode value: number - }[] + }> } export function CreateWalletForm(props: CreateWalletFormProps) { diff --git a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx index dd7a4a744d6a..e2236f600657 100644 --- a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx @@ -125,7 +125,7 @@ export const FungibleTokenTable = memo(({ selectedChainId }) => export interface TokenTableUIProps { isLoading: boolean isEmpty: boolean - dataSource: Web3Plugin.Asset[] + dataSource: Array> onSwap(token: Web3Plugin.FungibleToken): void onSend(token: Web3Plugin.FungibleToken): void } diff --git a/packages/encryption/src/encryption/Decryption.ts b/packages/encryption/src/encryption/Decryption.ts index ca41d207507e..ba50cec0ba9f 100644 --- a/packages/encryption/src/encryption/Decryption.ts +++ b/packages/encryption/src/encryption/Decryption.ts @@ -167,7 +167,7 @@ async function* v38To40StaticECDH( } type StaticV38OrOlderECDH = { type: 'static-v38-or-older' - derive: (postKeyIV: Uint8Array) => Promise<(readonly [key: AESCryptoKey, iv: Uint8Array])[]> + derive: (postKeyIV: Uint8Array) => Promise> } type EphemeralECDH = { type: 'ephemeral' diff --git a/packages/encryption/src/encryption/v38-ecdh.ts b/packages/encryption/src/encryption/v38-ecdh.ts index e01036308290..91e82cba52db 100644 --- a/packages/encryption/src/encryption/v38-ecdh.ts +++ b/packages/encryption/src/encryption/v38-ecdh.ts @@ -27,7 +27,7 @@ export async function deriveAESByECDH_version38OrOlderExtraSteps( deriveAESByECDH: (key: EC_Public_CryptoKey) => Promise, pub: EC_Public_CryptoKey, iv: Uint8Array, -): Promise<(readonly [key: AESCryptoKey, iv: Uint8Array])[]> { +): Promise> { const deriveResult = await deriveAESByECDH(pub) const extraSteps = deriveResult.map(async (key) => { const derivedKeyRaw = await crypto.subtle.exportKey('raw', key) diff --git a/packages/injected-script/main/EventListenerPatch/capture.ts b/packages/injected-script/main/EventListenerPatch/capture.ts index a70a3e4e0556..30c231554d85 100644 --- a/packages/injected-script/main/EventListenerPatch/capture.ts +++ b/packages/injected-script/main/EventListenerPatch/capture.ts @@ -1,7 +1,7 @@ import { clone_into, redefineEventTargetPrototype, unwrapXRay_CPPBindingObject } from '../utils' import { apply, error, no_xray_Proxy, warn, xray_Map } from '../intrinsic' -const CapturingEvents: Set = new Set(['keyup', 'input', 'paste', 'change'] as (keyof DocumentEventMap)[]) +const CapturingEvents: Set = new Set(['keyup', 'input', 'paste', 'change'] as Array) type EventListenerDescriptor = { once: boolean; passive: boolean; capture: boolean } const CapturedListeners = new WeakMap>>() diff --git a/packages/mask/background/database/avatar-cache/avatar.ts b/packages/mask/background/database/avatar-cache/avatar.ts index 1488e8bf04f1..cf993a959ba3 100644 --- a/packages/mask/background/database/avatar-cache/avatar.ts +++ b/packages/mask/background/database/avatar-cache/avatar.ts @@ -19,7 +19,7 @@ async function nativeImpl(identifiers: IdentifierWithAvatar[]): Promise> { - const promises: Promise[] = [] + const promises: Array> = [] const map = new Map() const t = createTransaction(await createAvatarDBAccess(), 'readonly')('avatars') diff --git a/packages/mask/background/database/post/dbType.ts b/packages/mask/background/database/post/dbType.ts index 4ccf9e3490ad..890481c1d85a 100644 --- a/packages/mask/background/database/post/dbType.ts +++ b/packages/mask/background/database/post/dbType.ts @@ -7,7 +7,7 @@ export declare namespace PostDB_HistoryTypes { postBy: { userId: string; network: string } | undefined identifier: string recipientGroups?: unknown - recipients?: { userId: string; network: string }[] + recipients?: Array<{ userId: string; network: string }> foundAt: Date postCryptoKey?: CryptoKey } diff --git a/packages/mask/background/database/utils/openDB.ts b/packages/mask/background/database/utils/openDB.ts index 1581315ca75b..4c5c9fcc5e65 100644 --- a/packages/mask/background/database/utils/openDB.ts +++ b/packages/mask/background/database/utils/openDB.ts @@ -109,7 +109,7 @@ export function createDBAccessWithAsyncUpgrade[] = StoreNames[], + TxStores extends Array> = Array>, StoreName extends StoreNames = StoreNames, Writable extends boolean = boolean, > extends Pick< @@ -170,14 +170,14 @@ export interface IDBPSafeObjectStore< } export type IDBPSafeTransaction< DBTypes extends DBSchema, - TxStores extends StoreNames[], + TxStores extends Array>, Mode extends IDBTransactionMode = 'readonly', > = Omit, 'mode' | 'objectStoreNames' | 'objectStore' | 'store'> & { readonly objectStoreNames: TypedDOMStringList & string> readonly mode: IDBTransactionMode readonly __writable__?: Mode extends 'readwrite' ? true : boolean readonly __stores__?: Record< - TxStores extends readonly (infer ValueOfUsedStoreName)[] + TxStores extends ReadonlyArray ? ValueOfUsedStoreName extends string | number | symbol ? ValueOfUsedStoreName : never @@ -194,7 +194,7 @@ export function createTransaction[] = []>(...storeNames: UsedStoreName) => { + return > = []>(...storeNames: UsedStoreName) => { return db.transaction(storeNames, mode) as IDBPSafeTransaction } } diff --git a/packages/mask/background/services/__utils__/convert.ts b/packages/mask/background/services/__utils__/convert.ts index dcbb60a43f30..88814d3f4c27 100644 --- a/packages/mask/background/services/__utils__/convert.ts +++ b/packages/mask/background/services/__utils__/convert.ts @@ -25,8 +25,8 @@ export function toProfileInformation(profiles: ProfileRecord[]) { /** @internal */ export function toPersonaInformation(personas: PersonaRecord[], t: FullPersonaDBTransaction<'readonly'>) { const personaInfo: PersonaInformation[] = [] - const dbQueryPass2: Promise[] = [] - const dbQuery: Promise[] = personas.map(async (persona) => { + const dbQueryPass2: Array> = [] + const dbQuery: Array> = personas.map(async (persona) => { const map: ProfileInformation[] = [] personaInfo.push({ nickname: persona.nickname, diff --git a/packages/mask/background/services/backup/restore.ts b/packages/mask/background/services/backup/restore.ts index 4153d80322c8..4471113809e9 100644 --- a/packages/mask/background/services/backup/restore.ts +++ b/packages/mask/background/services/backup/restore.ts @@ -44,7 +44,7 @@ export async function addUnconfirmedBackup(raw: string): Promise { +): Promise }> { if (!unconfirmedBackup.has(id)) return undefined const backup = unconfirmedBackup.get(id)! return { diff --git a/packages/mask/background/services/helper/deprecated-storage.ts b/packages/mask/background/services/helper/deprecated-storage.ts index 9e618ad9e031..a55a66364678 100644 --- a/packages/mask/background/services/helper/deprecated-storage.ts +++ b/packages/mask/background/services/helper/deprecated-storage.ts @@ -5,7 +5,7 @@ import { timeout } from '@dimensiondev/kit' * Make sure that the storage is used serially. */ class MutexStorage { - private tasks: (() => void)[] = [] + private tasks: Array<() => void> = [] private locked = false private lock() { diff --git a/packages/mask/src/UIRoot.tsx b/packages/mask/src/UIRoot.tsx index e820a9a59f6a..9d7c5eefe82b 100644 --- a/packages/mask/src/UIRoot.tsx +++ b/packages/mask/src/UIRoot.tsx @@ -16,7 +16,7 @@ import { isTwitter } from './social-network-adaptor/twitter.com/base' import { MaskThemeProvider } from '@masknet/theme' const identity = (jsx: React.ReactNode) => jsx as JSX.Element -function compose(init: React.ReactNode, ...f: ((children: React.ReactNode) => JSX.Element)[]) { +function compose(init: React.ReactNode, ...f: Array<(children: React.ReactNode) => JSX.Element>) { // eslint-disable-next-line unicorn/no-array-reduce return f.reduceRight((prev, curr) => curr(prev), <>{init}) } diff --git a/packages/mask/src/components/InjectedComponents/DecryptedPost/DecryptedPost.tsx b/packages/mask/src/components/InjectedComponents/DecryptedPost/DecryptedPost.tsx index 1ab0de6a8474..04c7deb6aa61 100644 --- a/packages/mask/src/components/InjectedComponents/DecryptedPost/DecryptedPost.tsx +++ b/packages/mask/src/components/InjectedComponents/DecryptedPost/DecryptedPost.tsx @@ -15,7 +15,7 @@ import { type PostContext, usePostInfoDetails, usePostInfo } from '@masknet/plug import { Some } from 'ts-results' function progressReducer( - state: { key: string; progress: SuccessDecryption | FailureDecryption | DecryptionProgress }[], + state: Array<{ key: string; progress: SuccessDecryption | FailureDecryption | DecryptionProgress }>, payload: { type: 'refresh' key: string diff --git a/packages/mask/src/components/shared/AbstractTab.tsx b/packages/mask/src/components/shared/AbstractTab.tsx index 6b6d5c8dbc73..3357f4f06564 100644 --- a/packages/mask/src/components/shared/AbstractTab.tsx +++ b/packages/mask/src/components/shared/AbstractTab.tsx @@ -23,11 +23,11 @@ interface TabPanelProps extends BoxProps { export interface AbstractTabProps extends withClasses<'tab' | 'tabs' | 'tabPanel' | 'indicator' | 'focusTab' | 'tabPaper' | 'flexContainer'> { - tabs: (Omit & { + tabs: Array & { cb?: () => void disableFocusRipple?: boolean disableRipple?: boolean - })[] + }> state?: readonly [number, (next: number) => void] index?: number disableFocusRipple?: boolean diff --git a/packages/mask/src/database/helpers/pagination.ts b/packages/mask/src/database/helpers/pagination.ts index 9d267b7a5ca3..ea6f4619e7c6 100644 --- a/packages/mask/src/database/helpers/pagination.ts +++ b/packages/mask/src/database/helpers/pagination.ts @@ -3,7 +3,7 @@ import type { IDBPSafeTransaction } from '../../../background/database/utils/ope export async function queryTransactionPaged< DBType extends DBSchema, - TxStores extends StoreNames[], + TxStores extends Array>, Mode extends 'readonly' | 'readwrite', RecordType extends IDBPCursorWithValueIteratorValue['value'], >( diff --git a/packages/mask/src/extension/background-script/EthereumServices/nonce.ts b/packages/mask/src/extension/background-script/EthereumServices/nonce.ts index 4963d8a79965..54a828312be7 100644 --- a/packages/mask/src/extension/background-script/EthereumServices/nonce.ts +++ b/packages/mask/src/extension/background-script/EthereumServices/nonce.ts @@ -7,7 +7,7 @@ class NonceManager { constructor(private address: string) {} private nonce = NonceManager.INITIAL_NONCE private locked = false - private tasks: (() => void)[] = [] + private tasks: Array<() => void> = [] private lock() { this.locked = true diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts index b5f1133b1544..14e20bc09ccb 100644 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts +++ b/packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts @@ -92,10 +92,10 @@ const onConnect = () => onUpdate(null) const onUpdate = async ( error: Error | null, payload?: { - params: { + params: Array<{ chainId: number accounts: string[] - }[] + }> }, ) => { if (error) return diff --git a/packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts b/packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts index 5460b661eaa2..0bf230349bc6 100644 --- a/packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts +++ b/packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts @@ -16,10 +16,10 @@ const coder = ABICoder as unknown as ABICoder.AbiCoder type InternalItem = { name: string - parameters: { + parameters: Array<{ name: string type: string - }[] + }> } const ABI_MAP: Map = new Map() diff --git a/packages/mask/src/extension/popups/pages/Wallet/Transfer/Prior1559Transfer.tsx b/packages/mask/src/extension/popups/pages/Wallet/Transfer/Prior1559Transfer.tsx index 1bfc6b0934a3..10ef1fda1fa4 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/Transfer/Prior1559Transfer.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/Transfer/Prior1559Transfer.tsx @@ -146,7 +146,7 @@ const useStyles = makeStyles()({ export interface Prior1559TransferProps { selectedAsset?: Asset - otherWallets: { name: string; address: string }[] + otherWallets: Array<{ name: string; address: string }> openAssetMenu: (anchorElOrEvent: HTMLElement | SyntheticEvent) => void } diff --git a/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx b/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx index 7cbfe4f51144..b250aa196786 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/Transfer/Transfer1559.tsx @@ -176,7 +176,7 @@ const useStyles = makeStyles()({ const MIN_GAS_LIMIT = 21000 export interface Transfer1559Props { selectedAsset?: Asset - otherWallets: { name: string; address: string }[] + otherWallets: Array<{ name: string; address: string }> openAssetMenu: (anchorElOrEvent: HTMLElement | SyntheticEvent) => void } diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx index c5fd78aead04..0c625ce957aa 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx @@ -41,7 +41,7 @@ const useStyles = makeStyles()({ export interface DeriveWalletTableProps { loading: boolean - dataSource?: { address: string; added: boolean; selected: boolean }[] + dataSource?: Array<{ address: string; added: boolean; selected: boolean }> onCheck: (checked: boolean, index: number) => void confirmLoading: boolean } diff --git a/packages/mask/src/plugins/Collectible/types/opensea.ts b/packages/mask/src/plugins/Collectible/types/opensea.ts index 98bbd2557b12..929bccf9b03d 100644 --- a/packages/mask/src/plugins/Collectible/types/opensea.ts +++ b/packages/mask/src/plugins/Collectible/types/opensea.ts @@ -216,10 +216,10 @@ export interface OpenSeaResponse extends Asset { background_color: string | null transfer_fee: string | null transfer_fee_payment_token: OpenSeaFungibleToken | null - top_ownerships: { + top_ownerships: Array<{ owner: OpenSeaCustomAccount quantity: string - }[] + }> creator: OpenSeaCustomAccount endTime: string } diff --git a/packages/mask/src/plugins/Collectible/types/rarible.ts b/packages/mask/src/plugins/Collectible/types/rarible.ts index 28387ada41c6..772dc83e6877 100644 --- a/packages/mask/src/plugins/Collectible/types/rarible.ts +++ b/packages/mask/src/plugins/Collectible/types/rarible.ts @@ -60,10 +60,10 @@ export interface Creator { export interface Meta { name: string description: string - attributes: { + attributes: Array<{ key: string value: string - }[] + }> image: { meta: { PREVIEW: { diff --git a/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts b/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts index 0b11a8f2617e..31feb1eb43ff 100644 --- a/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts +++ b/packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts @@ -136,13 +136,13 @@ export const getFungibleAssetsFn = const tokenUnavailableFromDebankResults = (await Promise.allSettled(allRequest)) .map((x) => (x.status === 'fulfilled' ? x.value : null)) - .filter((x) => Boolean(x)) as { + .filter((x) => Boolean(x)) as Array<{ chainId: ChainId balance: string price: PriceRecord - }[] + }> - const nativeTokens: Web3Plugin.Asset[] = networks + const nativeTokens: Array> = networks .filter( (t) => t.isMainnet && diff --git a/packages/mask/src/plugins/FindTruman/SNSAdaptor/ConstPromise.ts b/packages/mask/src/plugins/FindTruman/SNSAdaptor/ConstPromise.ts index 0d303203dda1..1c654cd8ab02 100644 --- a/packages/mask/src/plugins/FindTruman/SNSAdaptor/ConstPromise.ts +++ b/packages/mask/src/plugins/FindTruman/SNSAdaptor/ConstPromise.ts @@ -20,8 +20,8 @@ export default class FindTrumanConstPromise { value?: FindTrumanConst err?: any - successCallback: ((value?: FindTrumanConst) => void)[] = [] - failCallback: ((err: any) => void)[] = [] + successCallback: Array<(value?: FindTrumanConst) => void> = [] + failCallback: Array<(err: any) => void> = [] resolve = (value: FindTrumanConst) => { if (this.status !== Status.PENDING) return diff --git a/packages/mask/src/plugins/FindTruman/types.ts b/packages/mask/src/plugins/FindTruman/types.ts index 349cd201ae53..92ead19e5538 100644 --- a/packages/mask/src/plugins/FindTruman/types.ts +++ b/packages/mask/src/plugins/FindTruman/types.ts @@ -235,7 +235,7 @@ export interface SubmitPollParams { export interface SubmitCompletionParams { timestamp: number quesId: string - answers: { id: string; answer: string }[] + answers: Array<{ id: string; answer: string }> } export enum ClueConditionType { diff --git a/packages/mask/src/plugins/Gitcoin/hooks/useDonateCallback.ts b/packages/mask/src/plugins/Gitcoin/hooks/useDonateCallback.ts index 66e006227cc1..c85572035151 100644 --- a/packages/mask/src/plugins/Gitcoin/hooks/useDonateCallback.ts +++ b/packages/mask/src/plugins/Gitcoin/hooks/useDonateCallback.ts @@ -24,7 +24,7 @@ export function useDonateCallback(address: string, amount: string, token?: Fungi const account = useAccount() - const donations = useMemo((): [string, string, string][] => { + const donations = useMemo((): Array<[string, string, string]> => { if (!address || !token) return [] if (!GITCOIN_ETH_ADDRESS || !GITCOIN_TIP_PERCENTAGE) return [] const tipAmount = new BigNumber(GITCOIN_TIP_PERCENTAGE / 100).multipliedBy(amount) diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx b/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx index f4eaba6d32be..0b480f32d41d 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx @@ -153,13 +153,13 @@ const useStyles = makeStyles()((theme) => ({ })) interface NftAirdropCardProps { - campaignInfos: { + campaignInfos: Array<{ campaignInfo: CampaignInfo claimableInfo: { claimable: boolean claimed: boolean } - }[] + }> loading: boolean retry: () => void } diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useFill.ts b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useFill.ts index 5f739678c5bc..e65395a050c6 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useFill.ts +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useFill.ts @@ -49,7 +49,7 @@ type paramsObjType = { total: string limit: string qualificationAddress: string - exchangeAmountsDivided: (readonly [BigNumber, BigNumber])[] + exchangeAmountsDivided: Array now: number invalidTokenAt: number exchangeAmounts: string[] diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useRegion.ts b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useRegion.ts index e283feedbd78..04de368b83af 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useRegion.ts +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useRegion.ts @@ -300,9 +300,9 @@ export function useIPRegion(): AsyncStateRetry { return useAsyncRetry(IPGeoResolver) } -export function useRegionList(): Array { +export function useRegionList(): Region[] { // TODO return name by i18n - return regions as Array + return regions as Region[] } export function useRegionSelect(initRegionCodes?: RegionCode[]) { diff --git a/packages/mask/src/plugins/ITO/Worker/apis/spaceStationGalaxy.ts b/packages/mask/src/plugins/ITO/Worker/apis/spaceStationGalaxy.ts index 9a3cc8b4a9c6..9380fb990c71 100644 --- a/packages/mask/src/plugins/ITO/Worker/apis/spaceStationGalaxy.ts +++ b/packages/mask/src/plugins/ITO/Worker/apis/spaceStationGalaxy.ts @@ -58,7 +58,7 @@ export async function getCampaignInfo(id: number): Promise { endTime: number startTime: number gamification: { - nfts: { nft: { image: string } }[] + nfts: Array<{ nft: { image: string } }> } } }>(` diff --git a/packages/mask/src/plugins/ITO/Worker/apis/subgraph.ts b/packages/mask/src/plugins/ITO/Worker/apis/subgraph.ts index 4f6ab889688c..9cba129fa129 100644 --- a/packages/mask/src/plugins/ITO/Worker/apis/subgraph.ts +++ b/packages/mask/src/plugins/ITO/Worker/apis/subgraph.ts @@ -68,7 +68,7 @@ async function fetchFromMarketSubgraph(query: string, chainId?: ChainId) { export async function getTradeInfo(pid: string, trader: string) { const data = await fetchFromMarketSubgraph<{ - buyInfos: { + buyInfos: Array<{ buyer: { address: string name: string @@ -77,23 +77,23 @@ export async function getTradeInfo(pid: string, trader: string) { amount: string amount_sold: string amount_bought: string - }[] - sellInfos: { + }> + sellInfos: Array<{ buyer: { address: string name: string } token: JSON_PayloadOutMask['token'] amount: string - }[] - destructInfos: { + }> + destructInfos: Array<{ buyer: { address: string name: string } token: JSON_PayloadOutMask['token'] amount: string - }[] + }> }>(` { buyInfos (where: { pool: "${pid.toLowerCase()}", buyer: "${trader.toLowerCase()}" }) { @@ -147,12 +147,12 @@ export async function getPool(pid: string) { export async function getAllPoolsAsSeller(address: string, page: number, chainId: ChainId) { const data = await fetchFromMarketSubgraph<{ - sellInfos: { + sellInfos: Array<{ pool: JSON_PayloadOutMask & { exchange_in_volumes: string[] exchange_out_volumes: string[] } - }[] + }> }>( ` { @@ -183,12 +183,12 @@ export async function getAllPoolsAsSeller(address: string, page: number, chainId export async function getAllPoolsAsBuyer(address: string, chainId: ChainId) { const data = await fetchFromMarketSubgraph<{ - buyInfos: { + buyInfos: Array<{ pool: JSON_PayloadOutMask & { exchange_in_volumes: string[] exchange_out_volumes: string[] } - }[] + }> }>( ` { diff --git a/packages/mask/src/plugins/ITO/types.ts b/packages/mask/src/plugins/ITO/types.ts index abe216b9556f..7e7649c54dae 100644 --- a/packages/mask/src/plugins/ITO/types.ts +++ b/packages/mask/src/plugins/ITO/types.ts @@ -57,7 +57,7 @@ export interface JSON_PayloadOutMask extends Omit { token: string - exchange_tokens: { address: string }[] + exchange_tokens: Array<{ address: string }> } export enum ITO_Status { @@ -113,7 +113,7 @@ export interface CampaignInfo { chain: string endTime: number startTime: number - nfts: { image: string }[] + nfts: Array<{ image: string }> } export interface ClaimParams { diff --git a/packages/mask/src/plugins/MaskBox/type.ts b/packages/mask/src/plugins/MaskBox/type.ts index ac12d96c65a3..063518d7aac7 100644 --- a/packages/mask/src/plugins/MaskBox/type.ts +++ b/packages/mask/src/plugins/MaskBox/type.ts @@ -76,8 +76,8 @@ export interface BoxMetadata { name: string mediaType: MediaType mediaUrl: string - activities: { + activities: Array<{ title: string body: string - }[] + }> } diff --git a/packages/mask/src/plugins/RedPacket/Worker/apis/erc20Redpacket.ts b/packages/mask/src/plugins/RedPacket/Worker/apis/erc20Redpacket.ts index c3a96cc598f8..33d07a7d27e7 100644 --- a/packages/mask/src/plugins/RedPacket/Worker/apis/erc20Redpacket.ts +++ b/packages/mask/src/plugins/RedPacket/Worker/apis/erc20Redpacket.ts @@ -57,7 +57,7 @@ const RED_PACKET_FIELDS = ` type RedpacketFromSubgraphType = { chain_id: ChainId - claimers: { name: string; address: string }[] + claimers: Array<{ name: string; address: string }> contract_address: string contract_version: number block_number: number diff --git a/packages/mask/src/plugins/RedPacket/types.ts b/packages/mask/src/plugins/RedPacket/types.ts index 824649e80d42..4d94b4e98a59 100644 --- a/packages/mask/src/plugins/RedPacket/types.ts +++ b/packages/mask/src/plugins/RedPacket/types.ts @@ -62,7 +62,7 @@ export interface RedPacketJSONPayload extends RedPacketBasic { token_type?: EthereumTokenType.Native | EthereumTokenType.ERC20 token?: FungibleTokenDetailed token_address?: string - claimers?: { address: string; name: string }[] + claimers?: Array<{ address: string; name: string }> total_remaining?: string } @@ -126,10 +126,10 @@ export interface NftRedPacketSubgraphInMask extends Omit creator: { name: string address: string diff --git a/packages/mask/src/plugins/Savings/constants.ts b/packages/mask/src/plugins/Savings/constants.ts index 4f800312198b..83f06963c5e3 100644 --- a/packages/mask/src/plugins/Savings/constants.ts +++ b/packages/mask/src/plugins/Savings/constants.ts @@ -3,14 +3,14 @@ import { ChainId, createERC20Tokens, createNativeToken, FungibleTokenDetailed } export const SAVINGS_PLUGIN_NAME = 'Savings' export const SAVINGS_PLUGIN_ID = 'com.savings' -export const LDO_PAIRS: [FungibleTokenDetailed, FungibleTokenDetailed][] = [ +export const LDO_PAIRS: Array<[FungibleTokenDetailed, FungibleTokenDetailed]> = [ [ createNativeToken(ChainId.Mainnet), createERC20Tokens('LDO_stETH_ADDRESS', 'Liquid staked Ether 2.0', 'stETH', 18)[ChainId.Mainnet], ], ] -export const AAVE_PAIRS: [FungibleTokenDetailed, FungibleTokenDetailed][] = [ +export const AAVE_PAIRS: Array<[FungibleTokenDetailed, FungibleTokenDetailed]> = [ [ createERC20Tokens('USDT_ADDRESS', 'Tether USD', 'USDT', 6)[ChainId.Mainnet], createERC20Tokens('aUSDT_ADDRESS', 'Aave Interest bearing USDT', 'aUSDT', 6)[ChainId.Mainnet], diff --git a/packages/mask/src/plugins/Savings/protocols/AAVEProtocol.ts b/packages/mask/src/plugins/Savings/protocols/AAVEProtocol.ts index 2c684f3d64e9..9290417d100f 100644 --- a/packages/mask/src/plugins/Savings/protocols/AAVEProtocol.ts +++ b/packages/mask/src/plugins/Savings/protocols/AAVEProtocol.ts @@ -78,13 +78,13 @@ export class AAVEProtocol implements SavingsProtocol { }) const fullResponse: { data: { - reserves: { + reserves: Array<{ id: string name: string decimals: number underlyingAsset: string liquidityRate: number - }[] + }> } } = await response.json() const liquidityRate = +fullResponse.data.reserves[0].liquidityRate @@ -129,11 +129,11 @@ export class AAVEProtocol implements SavingsProtocol { const fullResponse: { data: { - reserves: { + reserves: Array<{ aToken: { id: string } - }[] + }> } } = await response.json() diff --git a/packages/mask/src/plugins/Snapshot/Worker/apis/index.ts b/packages/mask/src/plugins/Snapshot/Worker/apis/index.ts index 64411842eb66..5f266290aedf 100644 --- a/packages/mask/src/plugins/Snapshot/Worker/apis/index.ts +++ b/packages/mask/src/plugins/Snapshot/Worker/apis/index.ts @@ -113,7 +113,7 @@ export async function getScores( space: string, strategies: Strategy[], ) { - const scores: { [key in string]: number }[] = await ss.utils.getScores( + const scores: Array<{ [key in string]: number }> = await ss.utils.getScores( space, strategies, network, diff --git a/packages/mask/src/plugins/Snapshot/types.ts b/packages/mask/src/plugins/Snapshot/types.ts index 5959e80fad7d..d57fded9f0a8 100644 --- a/packages/mask/src/plugins/Snapshot/types.ts +++ b/packages/mask/src/plugins/Snapshot/types.ts @@ -89,11 +89,11 @@ export interface VoteItem { choice: string | undefined totalWeight: number | undefined choices: - | { + | Array<{ index: number weight: number name: string - }[] + }> | undefined address: string authorIpfsHash: string @@ -115,10 +115,10 @@ export type VoteItemList = { export interface ProposalResult { choice: string - powerDetail: { + powerDetail: Array<{ power: number name: string - }[] + }> power: number percentage: number } diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/CoinMetadataTable.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/CoinMetadataTable.tsx index 7e77157fcb48..5193d749fe21 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/CoinMetadataTable.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/CoinMetadataTable.tsx @@ -63,7 +63,7 @@ export function CoinMetadataTable(props: CoinMetadataTableProps) { ['Tech Docs', trending.coin.tech_docs_urls], ['Source Code', trending.coin.source_code_urls], ['Community', trending.coin.community_urls], - ] as [string, string[] | undefined][] + ] as Array<[string, string[] | undefined]> return ( diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/LBPPriceChart.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/LBPPriceChart.tsx index 20f7dca725ae..baae9010c044 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/LBPPriceChart.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/LBPPriceChart.tsx @@ -15,7 +15,7 @@ const DEFAULT_DIMENSION: Dimension = { } export interface PriceChartProps extends withClasses<'root'> { - data: { date: Date; value: number }[] + data: Array<{ date: Date; value: number }> width?: number height?: number currency: Currency diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/PriceChangedTable.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/PriceChangedTable.tsx index 21e3693aae00..77b758e5c011 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trending/PriceChangedTable.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trending/PriceChangedTable.tsx @@ -56,7 +56,7 @@ export function PriceChangedTable({ market }: PriceChangedTableProps) { }, ] - const filteredRecords = records.filter((record) => typeof record.percentage === 'number') as Required[] + const filteredRecords = records.filter((record) => typeof record.percentage === 'number') as Array> return ( diff --git a/packages/mask/src/plugins/Trader/apis/LBP/index.ts b/packages/mask/src/plugins/Trader/apis/LBP/index.ts index 6f9e848c3aa2..5f3aa16d4f09 100644 --- a/packages/mask/src/plugins/Trader/apis/LBP/index.ts +++ b/packages/mask/src/plugins/Trader/apis/LBP/index.ts @@ -18,10 +18,10 @@ async function fetchFromBalancerPoolSubgraph(query: string) { export async function fetchLBP_PoolsByTokenAddress(address: string) { const data = await fetchFromBalancerPoolSubgraph<{ - pools: { + pools: Array<{ id: string createTime: number - }[] + }> }>(` { pools( @@ -53,7 +53,7 @@ export async function fetchLBP_PoolTokenPrices(poolId: string, address: string, } `, ) - const data = await fetchFromBalancerPoolSubgraph>(` + const data = await fetchFromBalancerPoolSubgraph>>(` query tokenPrices { ${queries.join('\n')} } diff --git a/packages/mask/src/plugins/Trader/apis/coingecko/index.ts b/packages/mask/src/plugins/Trader/apis/coingecko/index.ts index 9c73bf402fee..a0735a045a5e 100644 --- a/packages/mask/src/plugins/Trader/apis/coingecko/index.ts +++ b/packages/mask/src/plugins/Trader/apis/coingecko/index.ts @@ -77,7 +77,7 @@ export interface CoinInfo { platforms: Record name: string symbol: string - tickers: { + tickers: Array<{ base: string target: string market: { @@ -108,7 +108,7 @@ export interface CoinInfo { trade_url: string coin_id: string target_coin_id?: string - }[] + }> } export async function getCoinInfo(coinId: string) { diff --git a/packages/mask/src/plugins/Trader/apis/uniswap-health/index.ts b/packages/mask/src/plugins/Trader/apis/uniswap-health/index.ts index 959e6798fd54..a59243a21705 100644 --- a/packages/mask/src/plugins/Trader/apis/uniswap-health/index.ts +++ b/packages/mask/src/plugins/Trader/apis/uniswap-health/index.ts @@ -20,14 +20,14 @@ export async function fetchLatestBlocks() { type status = { synced: string health: string - chains: { + chains: Array<{ chainHeadBlock: { number: number } latestBlock: { number: number } - }[] + }> } const response = await fetchFromUniswapV2Health<{ indexingStatusForCurrentVersion: status diff --git a/packages/mask/src/plugins/Trader/apis/uniswap-v2-subgraph/index.ts b/packages/mask/src/plugins/Trader/apis/uniswap-v2-subgraph/index.ts index dd59d68420f9..b70283cbc0ff 100644 --- a/packages/mask/src/plugins/Trader/apis/uniswap-v2-subgraph/index.ts +++ b/packages/mask/src/plugins/Trader/apis/uniswap-v2-subgraph/index.ts @@ -182,7 +182,7 @@ export async function fetchTokenDayData(address: string, date: Date) { const utcTimestamp = Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate()) const data = await fetchFromUniswapV2Subgraph<{ data: { - tokenDayData: { + tokenDayData: Array<{ id: string date: number priceUSD: string @@ -192,7 +192,7 @@ export async function fetchTokenDayData(address: string, date: Date) { dailyVolumeETH: number dailyVolumeToken: number dailyVolumeUSD: number - }[] + }> } }>(` { @@ -317,7 +317,7 @@ export async function fetchPairData(pairAddress: string, blockNumber?: string) { */ export async function fetchPricesByBlocks( tokenAddress: string, - blocks: { blockNumber?: string; timestamp: number }[], + blocks: Array<{ blockNumber?: string; timestamp: number }>, skipCount = 50, ) { // avoiding request entity too large diff --git a/packages/mask/src/plugins/Trader/graphs/usePriceLineChart.ts b/packages/mask/src/plugins/Trader/graphs/usePriceLineChart.ts index e6a8cd169539..59296bedbfde 100644 --- a/packages/mask/src/plugins/Trader/graphs/usePriceLineChart.ts +++ b/packages/mask/src/plugins/Trader/graphs/usePriceLineChart.ts @@ -5,7 +5,7 @@ import type { Dimension } from './useDimension' export function usePriceLineChart( svgRef: RefObject, - data: { date: Date; value: number }[], + data: Array<{ date: Date; value: number }>, dimension: Dimension, id: string, color = 'steelblue', diff --git a/packages/mask/src/plugins/Trader/trader/uniswap/useAllCommonPairs.ts b/packages/mask/src/plugins/Trader/trader/uniswap/useAllCommonPairs.ts index 04220f26f898..ac7928175153 100644 --- a/packages/mask/src/plugins/Trader/trader/uniswap/useAllCommonPairs.ts +++ b/packages/mask/src/plugins/Trader/trader/uniswap/useAllCommonPairs.ts @@ -24,8 +24,8 @@ export function useAllCurrencyCombinations(tradeProvider: TradeProvider, currenc return [...common, ...additionalA, ...additionalB].map((x) => toUniswapToken(chainId, x)) }, [chainId, chainIdValid, tokenA?.address, tokenB?.address]) - const basePairs: [Token, Token][] = useMemo( - () => flatMap(bases, (base): [Token, Token][] => bases.map((otherBase) => [base, otherBase])), + const basePairs: Array<[Token, Token]> = useMemo( + () => flatMap(bases, (base): Array<[Token, Token]> => bases.map((otherBase) => [base, otherBase])), [bases], ) @@ -73,7 +73,7 @@ export function useAllCommonPairs(tradeProvider: TradeProvider, currencyA?: Curr // only pass along valid pairs, non-duplicated pairs const allPairs_ = useMemo(() => { const filtered = new Map() - for (const [state, pair] of allPairs as [PairState.EXISTS, Pair][]) { + for (const [state, pair] of allPairs as Array<[PairState.EXISTS, Pair]>) { // filter out invalid pairs if (state !== PairState.EXISTS) continue if (!pair) continue diff --git a/packages/mask/src/plugins/Trader/trader/uniswap/useAllV3Routes.ts b/packages/mask/src/plugins/Trader/trader/uniswap/useAllV3Routes.ts index b0d496ab37c2..6d2dff736c20 100644 --- a/packages/mask/src/plugins/Trader/trader/uniswap/useAllV3Routes.ts +++ b/packages/mask/src/plugins/Trader/trader/uniswap/useAllV3Routes.ts @@ -11,10 +11,10 @@ function computeAllRoutes( pools: Pool[], chainId: number, currentPath: Pool[] = [], - allPaths: Route[] = [], + allPaths: Array> = [], startCurrencyIn: Currency = currencyIn, maxHops = 2, -): Route[] { +): Array> { const tokenIn = currencyIn?.wrapped const tokenOut = currencyOut?.wrapped if (!tokenIn || !tokenOut) throw new Error('Missing tokenIn/tokenOut') @@ -54,7 +54,7 @@ function computeAllRoutes( export function useAllV3Routes( currencyIn?: Currency, currencyOut?: Currency, -): { loading: boolean; routes: Route[] } { +): { loading: boolean; routes: Array> } { const { targetChainId: chainId } = TargetChainIdContext.useContainer() const { pools, loading: poolsLoading } = useV3SwapPools(currencyIn, currencyOut) const singleHopOnly = useSingleHopOnly() diff --git a/packages/mask/src/plugins/Trader/trader/uniswap/usePools.ts b/packages/mask/src/plugins/Trader/trader/uniswap/usePools.ts index 79640191d3db..5614c9170847 100644 --- a/packages/mask/src/plugins/Trader/trader/uniswap/usePools.ts +++ b/packages/mask/src/plugins/Trader/trader/uniswap/usePools.ts @@ -19,12 +19,12 @@ export enum PoolState { export function usePools( tradeProvider: TradeProvider, - poolKeys: [Currency | undefined, Currency | undefined, FeeAmount | undefined][], -): [PoolState, Pool | null][] { + poolKeys: Array<[Currency | undefined, Currency | undefined, FeeAmount | undefined]>, +): Array<[PoolState, Pool | null]> { const { targetChainId: chainId } = TargetChainIdContext.useContainer() const context = useGetTradeContext(tradeProvider) - const transformed: ([Token, Token, FeeAmount] | null)[] = useMemo(() => { + const transformed: Array<[Token, Token, FeeAmount] | null> = useMemo(() => { return poolKeys.map(([currencyA, currencyB, feeAmount]) => { if (!chainId || !currencyA || !currencyB || !feeAmount) return null @@ -111,7 +111,7 @@ export function usePool( currencyB: Currency | undefined, feeAmount: FeeAmount | undefined, ): [PoolState, Pool | null] { - const poolKeys: [Currency | undefined, Currency | undefined, FeeAmount | undefined][] = useMemo( + const poolKeys: Array<[Currency | undefined, Currency | undefined, FeeAmount | undefined]> = useMemo( () => [[currencyA, currencyB, feeAmount]], [currencyA, currencyB, feeAmount], ) diff --git a/packages/mask/src/plugins/Trader/trader/uniswap/useV3SwapPools.ts b/packages/mask/src/plugins/Trader/trader/uniswap/useV3SwapPools.ts index 4e8d6591b71a..059f68186f7b 100644 --- a/packages/mask/src/plugins/Trader/trader/uniswap/useV3SwapPools.ts +++ b/packages/mask/src/plugins/Trader/trader/uniswap/useV3SwapPools.ts @@ -19,7 +19,7 @@ export function useV3SwapPools( } { const allCurrencyCombinations = useAllCurrencyCombinations(TradeProvider.UNISWAP_V3, currencyIn, currencyOut) - const allCurrencyCombinationsWithAllFees: [Token, Token, FeeAmount][] = useMemo( + const allCurrencyCombinationsWithAllFees: Array<[Token, Token, FeeAmount]> = useMemo( () => allCurrencyCombinations.flatMap<[Token, Token, FeeAmount]>(([tokenA, tokenB]) => [ [tokenA, tokenB, FeeAmount.LOW], diff --git a/packages/mask/src/plugins/Trader/trending/useCurrentCurrency.ts b/packages/mask/src/plugins/Trader/trending/useCurrentCurrency.ts index bfa644cd3812..c71eef46e687 100644 --- a/packages/mask/src/plugins/Trader/trending/useCurrentCurrency.ts +++ b/packages/mask/src/plugins/Trader/trending/useCurrentCurrency.ts @@ -3,12 +3,12 @@ import { DataProvider } from '@masknet/public-api' const CURRENCIES_MAP: Record< DataProvider, | undefined - | { + | Array<{ id: string name: string symbol: string description: string - }[] + }> > = { [DataProvider.COIN_GECKO]: [ { diff --git a/packages/mask/src/plugins/Trader/types/0x.ts b/packages/mask/src/plugins/Trader/types/0x.ts index 5d7ad2e8c5f6..5175a9d86ed0 100644 --- a/packages/mask/src/plugins/Trader/types/0x.ts +++ b/packages/mask/src/plugins/Trader/types/0x.ts @@ -76,11 +76,11 @@ export interface SwapQuoteResponse { export interface SwapValidationErrorResponse { code: number reason: string - validationErrors: { + validationErrors: Array<{ code: number field: string reason: string - }[] + }> } export interface SwapServerErrorResponse { diff --git a/packages/mask/src/plugins/Trader/types/trader.ts b/packages/mask/src/plugins/Trader/types/trader.ts index 956f1a8fc0f7..62ed8d28b0ff 100644 --- a/packages/mask/src/plugins/Trader/types/trader.ts +++ b/packages/mask/src/plugins/Trader/types/trader.ts @@ -92,7 +92,7 @@ export interface TradeComputed { maximumSold: BigNumber minimumReceived: BigNumber fee: BigNumber - path?: (PartialRequired | PartialRequired)[][] + path?: Array | PartialRequired>> trade_?: T } diff --git a/packages/mask/src/plugins/UnlockProtocol/Services.ts b/packages/mask/src/plugins/UnlockProtocol/Services.ts index f18ca77677b2..5a3329a0095d 100644 --- a/packages/mask/src/plugins/UnlockProtocol/Services.ts +++ b/packages/mask/src/plugins/UnlockProtocol/Services.ts @@ -10,15 +10,15 @@ for (const [key, url] of Object.entries(graphEndpointKeyVal)) { } export interface verifyHolderResponse { - keyHolders: { - keys: { + keyHolders: Array<{ + keys: Array<{ expiration: number keyId: string lock: { address: string } - }[] - }[] + }> + }> } const verifyHolder = async (_lockAddress: string, _holder: string, _chain: number) => { diff --git a/packages/mask/src/plugins/Wallet/apis/ens.ts b/packages/mask/src/plugins/Wallet/apis/ens.ts index a422c0cdb61a..48ec09c400c9 100644 --- a/packages/mask/src/plugins/Wallet/apis/ens.ts +++ b/packages/mask/src/plugins/Wallet/apis/ens.ts @@ -17,10 +17,10 @@ export async function fetchAddressNamesByTwitterId(twitterId: string) { if (!twitterId) return [] const data = await fetchFromENSTextResolverSubgraph<{ twitterHandle?: { - domains: { + domains: Array<{ id: string owner: string - }[] + }> } }>(` query twitterHandle { diff --git a/packages/mask/src/plugins/Wallet/services/wallet/index.ts b/packages/mask/src/plugins/Wallet/services/wallet/index.ts index 29ef45a18c76..62893f8f752e 100644 --- a/packages/mask/src/plugins/Wallet/services/wallet/index.ts +++ b/packages/mask/src/plugins/Wallet/services/wallet/index.ts @@ -51,11 +51,11 @@ export async function getWallet(address?: string) { } export async function getWallets(providerType?: ProviderType): Promise< - (Omit & { + Array & { configurable: boolean hasStoredKeyInfo: boolean hasDerivationPath: boolean - })[] + }> > { if (hasNativeAPI) { if (providerType && providerType !== ProviderType.MaskWallet) return [] @@ -112,11 +112,11 @@ export async function getDerivableAccounts(mnemonic: string, page: number, pageS }) if (!imported?.StoredKey) throw new Error('Failed to import the wallet.') - const accounts: { + const accounts: Array<{ index: number address: string derivationPath: string - }[] = [] + }> = [] for (let i = pageSize * page; i < pageSize * (page + 1); i += 1) { const derivationPath = `${HD_PATH_WITHOUT_INDEX_ETHEREUM}/${i}` diff --git a/packages/mask/src/plugins/hooks/useLineChart.ts b/packages/mask/src/plugins/hooks/useLineChart.ts index bd35c37089db..3555285d7133 100644 --- a/packages/mask/src/plugins/hooks/useLineChart.ts +++ b/packages/mask/src/plugins/hooks/useLineChart.ts @@ -5,7 +5,7 @@ import type { Dimension } from './useDimension' export function useLineChart( svgRef: RefObject, - data: { date: Date; value: number }[], + data: Array<{ date: Date; value: number }>, dimension: Dimension, id: string, opts: { color?: string; tickFormat?: string; formatTooltip?: Function }, diff --git a/packages/mask/src/plugins/hooks/usePriceLineChart.ts b/packages/mask/src/plugins/hooks/usePriceLineChart.ts index f173a19c7e52..89998fc0966b 100644 --- a/packages/mask/src/plugins/hooks/usePriceLineChart.ts +++ b/packages/mask/src/plugins/hooks/usePriceLineChart.ts @@ -5,7 +5,7 @@ import { useLineChart } from './useLineChart' export function usePriceLineChart( svgRef: RefObject, - data: { date: Date; value: number }[], + data: Array<{ date: Date; value: number }>, dimension: Dimension, id: string, opts: { color?: string; sign?: string }, diff --git a/packages/mask/src/social-network/utils/create-post-context.ts b/packages/mask/src/social-network/utils/create-post-context.ts index 240cf305a258..25650d2d0b90 100644 --- a/packages/mask/src/social-network/utils/create-post-context.ts +++ b/packages/mask/src/social-network/utils/create-post-context.ts @@ -33,7 +33,7 @@ import { difference } from 'lodash-unified' export function createSNSAdaptorSpecializedPostContext(create: PostContextSNSActions) { return function createPostContext(opt: PostContextCreation): PostContext { - const cancel: (Function | undefined)[] = [] + const cancel: Array = [] opt.signal?.addEventListener('abort', () => cancel.forEach((fn) => fn?.())) // #region Mentioned links diff --git a/packages/mask/src/utils/hooks/useSuspense.ts b/packages/mask/src/utils/hooks/useSuspense.ts index 9903775e2679..5b981f27dddd 100644 --- a/packages/mask/src/utils/hooks/useSuspense.ts +++ b/packages/mask/src/utils/hooks/useSuspense.ts @@ -1,6 +1,6 @@ import { useUpdate } from 'react-use' -export function useSuspense>( +export function useSuspense( id: string, args: U, cache: Map] | [1, T] | [2, Error]>, diff --git a/packages/mask/src/utils/shadow-root/renderInShadowRoot.tsx b/packages/mask/src/utils/shadow-root/renderInShadowRoot.tsx index f0166037968c..b43757e4740e 100644 --- a/packages/mask/src/utils/shadow-root/renderInShadowRoot.tsx +++ b/packages/mask/src/utils/shadow-root/renderInShadowRoot.tsx @@ -2,7 +2,7 @@ import { createReactRootShadowedPartial, setupPortalShadowRoot, CSSVariableInjec import { MaskUIRoot } from '../../UIRoot' import { useClassicMaskSNSTheme } from '../theme' -const captureEvents: (keyof HTMLElementEventMap)[] = [ +const captureEvents: Array = [ 'paste', 'keydown', 'keypress', diff --git a/packages/plugin-infra/src/web3-types.ts b/packages/plugin-infra/src/web3-types.ts index fcc289bd62a6..057cd24024b2 100644 --- a/packages/plugin-infra/src/web3-types.ts +++ b/packages/plugin-infra/src/web3-types.ts @@ -281,7 +281,7 @@ export declare namespace Web3Plugin { providerType: string, network: NetworkDescriptor, pagination?: Pagination, - ) => Promise[]> + ) => Promise>> /** Get non-fungible assets of given account. */ getNonFungibleAssets?: ( address: string, diff --git a/packages/plugins/Flow/src/apis/getFungibleAssets.ts b/packages/plugins/Flow/src/apis/getFungibleAssets.ts index a1335e23a821..a3965e48982c 100644 --- a/packages/plugins/Flow/src/apis/getFungibleAssets.ts +++ b/packages/plugins/Flow/src/apis/getFungibleAssets.ts @@ -103,7 +103,7 @@ export async function getFungibleAssets( provider: string, network: Web3Plugin.NetworkDescriptor, pagination?: Pagination, -): Promise[]> { +): Promise>> { const allSettled = await Promise.allSettled([ getAssetFLOW(network.chainId, address), getAssetFUSD(network.chainId, address), @@ -112,5 +112,5 @@ export async function getFungibleAssets( return allSettled .map((x) => (x.status === 'fulfilled' ? x.value : null)) - .filter(Boolean) as Web3Plugin.Asset[] + .filter(Boolean) as Array> } diff --git a/packages/plugins/RSS3/src/SNSAdaptor/components/DonationCard.tsx b/packages/plugins/RSS3/src/SNSAdaptor/components/DonationCard.tsx index 3e6b365975ee..b012d9304989 100644 --- a/packages/plugins/RSS3/src/SNSAdaptor/components/DonationCard.tsx +++ b/packages/plugins/RSS3/src/SNSAdaptor/components/DonationCard.tsx @@ -8,10 +8,10 @@ export interface DonationCardProps extends HTMLProps { imageUrl: string name: string contribCount: number - contribDetails: { + contribDetails: Array<{ token: string amount: string - }[] + }> } const useStyles = makeStyles()((theme) => ({ diff --git a/packages/plugins/RSS3/src/types.ts b/packages/plugins/RSS3/src/types.ts index 5a94d76053a5..fbd9d744ac23 100644 --- a/packages/plugins/RSS3/src/types.ts +++ b/packages/plugins/RSS3/src/types.ts @@ -23,10 +23,10 @@ export interface GeneralAsset { animation_original_url?: string | null title?: string total_contribs?: number - token_contribs?: { + token_contribs?: Array<{ token: string amount: string - }[] + }> start_date?: string end_date?: string country?: string diff --git a/packages/plugins/Solana/src/apis/getFungibleAssets.ts b/packages/plugins/Solana/src/apis/getFungibleAssets.ts index 7859f6a017ca..fb8073a36ca9 100644 --- a/packages/plugins/Solana/src/apis/getFungibleAssets.ts +++ b/packages/plugins/Solana/src/apis/getFungibleAssets.ts @@ -68,7 +68,7 @@ export async function getFungibleAssets( provider: string, network: Web3Plugin.NetworkDescriptor, pagination?: Pagination, -): Promise[]> { +): Promise>> { const allSettled = await Promise.allSettled([ getSolanaBalance(network.chainId, address).then((x) => [x]), getSplTokenList(network.chainId, address), @@ -77,5 +77,5 @@ export async function getFungibleAssets( return allSettled .map((x) => (x.status === 'fulfilled' ? x.value : null)) .flat() - .filter(Boolean) as Web3Plugin.Asset[] + .filter(Boolean) as Array> } diff --git a/packages/plugins/Solana/src/apis/shared.ts b/packages/plugins/Solana/src/apis/shared.ts index 54aa78d0697e..20b57481355d 100644 --- a/packages/plugins/Solana/src/apis/shared.ts +++ b/packages/plugins/Solana/src/apis/shared.ts @@ -49,7 +49,7 @@ export interface ProgramAccount { pubkey: string } -export type GetProgramAccountsResponse = RpcResponse> +export type GetProgramAccountsResponse = RpcResponse let id = 0 export async function requestRPC(chainId: ChainId, options: RpcOptions): Promise { diff --git a/packages/plugins/example/src/Worker/index.ts b/packages/plugins/example/src/Worker/index.ts index c9a0027ae6d5..f336e4386a26 100644 --- a/packages/plugins/example/src/Worker/index.ts +++ b/packages/plugins/example/src/Worker/index.ts @@ -10,7 +10,7 @@ interface File { interface Folder { type: 'folder' id: string - files: File['id'][] + files: Array } let storage: Plugin.Worker.DatabaseStorage | undefined const worker: Plugin.Worker.Definition = { diff --git a/packages/shared-base/src/Identifier/map.ts b/packages/shared-base/src/Identifier/map.ts index 531ee0814f62..18b4311d65c3 100644 --- a/packages/shared-base/src/Identifier/map.ts +++ b/packages/shared-base/src/Identifier/map.ts @@ -7,10 +7,10 @@ import { PostIVIdentifier as D } from './post-iv' type I = Iterable // you're free to add a new overload... -export function convertRawMapToIdentifierMap(it: I, ...of: typeof A[]): Map -export function convertRawMapToIdentifierMap(it: I, ...of: typeof B[]): Map -export function convertRawMapToIdentifierMap(it: I, ...of: typeof C[]): Map -export function convertRawMapToIdentifierMap(it: I, ...of: typeof D[]): Map +export function convertRawMapToIdentifierMap(it: I, ...of: Array): Map +export function convertRawMapToIdentifierMap(it: I, ...of: Array): Map +export function convertRawMapToIdentifierMap(it: I, ...of: Array): Map +export function convertRawMapToIdentifierMap(it: I, ...of: Array): Map export function convertRawMapToIdentifierMap(it: I, ...of: unknown[]): Map { const hasProfileIdentifier = of.includes(A) const hasECKeyIdentifier = of.includes(B) diff --git a/packages/shared-base/src/NextID/type.ts b/packages/shared-base/src/NextID/type.ts index 17c8f914b586..e6ab5e2d52bc 100644 --- a/packages/shared-base/src/NextID/type.ts +++ b/packages/shared-base/src/NextID/type.ts @@ -61,7 +61,7 @@ export interface NextIDStoragePayload { } export interface NextIDStorageInfo { persona: string - proofs: NextIDStorageProofs[] + proofs: Array> } export interface NextIDStorageProofs { content: { diff --git a/packages/shared/src/UI/components/ConcealableTabs/index.tsx b/packages/shared/src/UI/components/ConcealableTabs/index.tsx index 6ea0aa321f2a..dc4c95a7ef59 100644 --- a/packages/shared/src/UI/components/ConcealableTabs/index.tsx +++ b/packages/shared/src/UI/components/ConcealableTabs/index.tsx @@ -106,7 +106,7 @@ interface TabOption { } export interface ConcealableTabsProps extends Omit, 'onChange'> { - tabs: TabOption[] + tabs: Array> selectedId?: T onChange?(id: T): void tail?: ReactNode diff --git a/packages/shared/src/UI/components/MiniNetworkSelector/index.tsx b/packages/shared/src/UI/components/MiniNetworkSelector/index.tsx index c3498dc4b812..aa64050dcd92 100644 --- a/packages/shared/src/UI/components/MiniNetworkSelector/index.tsx +++ b/packages/shared/src/UI/components/MiniNetworkSelector/index.tsx @@ -44,13 +44,13 @@ export interface NetworkSelectorMinProps { ID: string chainId: number } | null - networks: { + networks: Array<{ ID: string isMainnet: boolean chainId: number icon: URL iconColor: string - }[] + }> onSelect(network: { chainId: number } | null): void hideAllNetworkButton?: boolean disabledNonCurrentNetwork?: boolean diff --git a/packages/theme/src/ShadowRoot/Contexts.ts b/packages/theme/src/ShadowRoot/Contexts.ts index fef9cfa0b3d3..91515aa2e9b8 100644 --- a/packages/theme/src/ShadowRoot/Contexts.ts +++ b/packages/theme/src/ShadowRoot/Contexts.ts @@ -4,6 +4,6 @@ import type { StyleSheet } from './ShadowRootStyleSheet' /** @internal */ export const StyleSheetsContext = createContext(null!) /** @internal */ -export const PreventEventPropagationListContext = createContext<(keyof HTMLElementEventMap)[]>([]) +export const PreventEventPropagationListContext = createContext>([]) /** This context does not join any ShadowRoot related feature. */ export const DisableShadowRootContext = createContext(false) diff --git a/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx b/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx index 32535b1a52af..66949d641135 100644 --- a/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx +++ b/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx @@ -20,7 +20,7 @@ export interface CreateRenderInShadowRootHostConfig { * * ! This is not a security boundary ! */ - preventEventPropagationList: (keyof HTMLElementEventMap)[] + preventEventPropagationList: Array wrapJSX?(jsx: React.ReactChild): React.ReactChild } export interface ReactRootShadowed { diff --git a/packages/theme/src/Theme/Provider.tsx b/packages/theme/src/Theme/Provider.tsx index 2260bdc1a4d2..7ab86e6dcacf 100644 --- a/packages/theme/src/Theme/Provider.tsx +++ b/packages/theme/src/Theme/Provider.tsx @@ -2,7 +2,7 @@ import { CssBaseline, Theme, ThemeProvider } from '@mui/material' import { MaskIconPalette, MaskIconPaletteContext } from '@masknet/icons' import { CustomSnackbarProvider } from '../Components' -function compose(init: React.ReactNode, ...f: ((children: React.ReactNode) => JSX.Element)[]) { +function compose(init: React.ReactNode, ...f: Array<(children: React.ReactNode) => JSX.Element>) { // eslint-disable-next-line unicorn/no-array-reduce return f.reduceRight((prev, curr) => curr(prev), <>{init}) } diff --git a/packages/theme/src/UIHelper/custom-ui-helper.tsx b/packages/theme/src/UIHelper/custom-ui-helper.tsx index db8ed7aba8cd..233d13ffcf70 100644 --- a/packages/theme/src/UIHelper/custom-ui-helper.tsx +++ b/packages/theme/src/UIHelper/custom-ui-helper.tsx @@ -11,7 +11,7 @@ export function useStylesExtends> | undefined)[]): Partial> { +export function mergeClasses(...args: Array> | undefined>): Partial> { args = args.filter(Boolean) if (args.length === 1) return args[0]! const result = {} as Partial> diff --git a/packages/theme/stories/utils/Material-UI.ts b/packages/theme/stories/utils/Material-UI.ts index 94ef7291de68..953910f489cf 100644 --- a/packages/theme/stories/utils/Material-UI.ts +++ b/packages/theme/stories/utils/Material-UI.ts @@ -2,7 +2,7 @@ import type { ButtonProps, SelectProps, TextFieldProps } from '@mui/material' import type { ArgType, ArgTypes } from '@storybook/addons' import { argsOfArr, ControlType } from './args' function enumIn(enums: { - [Prop in keyof T]?: (argsFromEnum: (enumString: NonNullable[], type?: ControlType) => ArgType) => ArgType + [Prop in keyof T]?: (argsFromEnum: (enumString: Array>, type?: ControlType) => ArgType) => ArgType }): ArgTypes { for (const key of Object.keys(enums) as Array) { enums[key] = (enums[key] as any)(argsOfArr) diff --git a/packages/theme/stories/utils/args.ts b/packages/theme/stories/utils/args.ts index 01a6609863f2..9561b40cc1c1 100644 --- a/packages/theme/stories/utils/args.ts +++ b/packages/theme/stories/utils/args.ts @@ -1,5 +1,5 @@ export type ControlType = 'radio' | 'inline-radio' | 'check' | 'inline-check' | 'select' | 'multi-select' -export function argsOfArr(keys: NonNullable[], type?: ControlType) { +export function argsOfArr(keys: Array>, type?: ControlType) { if (type === undefined) { if (keys.length <= 6) type = 'inline-radio' else type = 'select' diff --git a/packages/typed-message/base/utils/extract.ts b/packages/typed-message/base/utils/extract.ts index 5a1220fe216a..2e1e5ba38ddc 100644 --- a/packages/typed-message/base/utils/extract.ts +++ b/packages/typed-message/base/utils/extract.ts @@ -27,10 +27,10 @@ export function extractTextFromTypedMessage( if (text.length) return Some(text.join(' ')) return None } -export function extractImageFromTypedMessage(message: TypedMessage | null): (string | Blob)[] { +export function extractImageFromTypedMessage(message: TypedMessage | null): Array { if (!message) return [] - const image: (string | Blob)[] = [] + const image: Array = [] function visitor(message: TypedMessage): void { if (isTypedMessageImage(message)) return void image.push(message.image) return forEachTypedMessageChild(message, visitor) diff --git a/packages/typed-message/base/utils/internal.ts b/packages/typed-message/base/utils/internal.ts index cd9523604cdb..eda1b255c5ea 100644 --- a/packages/typed-message/base/utils/internal.ts +++ b/packages/typed-message/base/utils/internal.ts @@ -8,11 +8,11 @@ export function createIsType(x: T['type'], version?: num } } /** @internal */ -export function composeSome(...fns: ((...args: Args) => boolean)[]) { +export function composeSome(...fns: Array<(...args: Args) => boolean>) { return (...args: Args) => fns.some((f) => f(...args)) } /** @internal */ -export function composeEvery(...fns: ((...args: Args) => boolean)[]) { +export function composeEvery(...fns: Array<(...args: Args) => boolean>) { return (...args: Args) => fns.every((f) => f(...args)) } diff --git a/packages/web3-constants/compile-constants.ts b/packages/web3-constants/compile-constants.ts index ab288a6150c3..ef2c95494704 100644 --- a/packages/web3-constants/compile-constants.ts +++ b/packages/web3-constants/compile-constants.ts @@ -11,7 +11,7 @@ async function compileConstants(folderPath: string, names: string[]) { for (const name of Object.keys(constants)) { const values = constants[name] const defaultValue = getDefaultValue(Object.values(values)[0]) - const pairs: [string, unknown][] = [] + const pairs: Array<[string, unknown]> = [] for (const name of names) { pairs.push([name, values[name] ?? defaultValue]) } diff --git a/packages/web3-contracts/compile-contracts.ts b/packages/web3-contracts/compile-contracts.ts index 24911661fd24..494476eb1c5d 100644 --- a/packages/web3-contracts/compile-contracts.ts +++ b/packages/web3-contracts/compile-contracts.ts @@ -6,7 +6,7 @@ import { run } from './utils' const ABIS_PATH = path.join(__dirname, 'abis') const GENERATED_PATH = path.join(__dirname, 'types') -async function replaceFileAll(file: string, pairs: [string, string][]) { +async function replaceFileAll(file: string, pairs: Array<[string, string]>) { let content = await fs.readFile(file, 'utf-8') for (const [pattern, value] of pairs) { content = content.replace(new RegExp(pattern, 'img'), value) diff --git a/packages/web3-providers/src/opensea/types.ts b/packages/web3-providers/src/opensea/types.ts index 9ee7062c7b14..efd8ce281dc2 100644 --- a/packages/web3-providers/src/opensea/types.ts +++ b/packages/web3-providers/src/opensea/types.ts @@ -80,11 +80,11 @@ export interface OpenSeaCollection extends OpenSeaFees { wiki_link?: string safelist_request_status: string owned_asset_count: number - primary_asset_contracts: { + primary_asset_contracts: Array<{ address: string asset_contract_type: string symbol: string - }[] + }> } export interface OpenSeaResponse extends Asset { @@ -104,19 +104,19 @@ export interface OpenSeaResponse extends Asset { image_thumbnail_url: string opensea_link: string external_link: string - traits: { + traits: Array<{ trait_type: string value: string - }[] + }> num_sales: number last_sale: NonFungibleTokenAPI.AssetEvent | null background_color: string | null transfer_fee: string | null transfer_fee_payment_token: OpenSeaFungibleToken | null - top_ownerships: { + top_ownerships: Array<{ owner: OpenSeaCustomAccount quantity: string - }[] + }> creator: OpenSeaCustomAccount endTime: string } diff --git a/packages/web3-providers/src/rarible/index.ts b/packages/web3-providers/src/rarible/index.ts index 4d660764186e..cdd1b548266e 100644 --- a/packages/web3-providers/src/rarible/index.ts +++ b/packages/web3-providers/src/rarible/index.ts @@ -36,7 +36,7 @@ async function fetchFromRarible(url: string, path: string, init?: RequestInit return response.json() as Promise } -function getProfilesFromRarible(addresses: (string | undefined)[]) { +function getProfilesFromRarible(addresses: Array) { return fetchFromRarible(RaribleMainnetURL, '/profiles/list', { method: 'POST', body: JSON.stringify(addresses), diff --git a/packages/web3-providers/src/rarible/types.ts b/packages/web3-providers/src/rarible/types.ts index d772dcabc1d0..7616b1d8e9a1 100644 --- a/packages/web3-providers/src/rarible/types.ts +++ b/packages/web3-providers/src/rarible/types.ts @@ -58,10 +58,10 @@ export interface Creator { export interface Meta { name: string description: string - attributes: { + attributes: Array<{ key: string value: string - }[] + }> image?: { meta: { PREVIEW: { diff --git a/packages/web3-providers/src/types.ts b/packages/web3-providers/src/types.ts index e33ba8eed336..ca204bd3db7e 100644 --- a/packages/web3-providers/src/types.ts +++ b/packages/web3-providers/src/types.ts @@ -40,10 +40,10 @@ export namespace RSS3BaseAPI { animation_original_url?: string | null title?: string total_contribs?: number - token_contribs?: { + token_contribs?: Array<{ token: string amount: string - }[] + }> start_date?: string end_date?: string country?: string @@ -204,13 +204,13 @@ export namespace NonFungibleTokenAPI { collection_name: string animation_url?: string end_time: Date | null - order_payment_tokens: (ERC20TokenDetailed | NativeTokenDetailed)[] - offer_payment_tokens: (ERC20TokenDetailed | NativeTokenDetailed)[] + order_payment_tokens: Array + offer_payment_tokens: Array slug: string | null desktopOrder?: AssetOrder - top_ownerships: { + top_ownerships: Array<{ owner: AssetOwner - }[] + }> last_sale: AssetEvent | null response_: any } @@ -464,10 +464,10 @@ export namespace TwitterBaseAPI { name: string } } - traits: { + traits: Array<{ trait_type: string value: string - }[] + }> } } export interface AvatarInfo { diff --git a/packages/web3-shared/evm/constants/getContractOwnerDomain.ts b/packages/web3-shared/evm/constants/getContractOwnerDomain.ts index ae6757dc5d64..2e9077899143 100644 --- a/packages/web3-shared/evm/constants/getContractOwnerDomain.ts +++ b/packages/web3-shared/evm/constants/getContractOwnerDomain.ts @@ -13,7 +13,7 @@ import RedPacket from '@masknet/web3-constants/evm/red-packet.json' import Trader from '@masknet/web3-constants/evm/trader.json' import { filter, flatten, pick, uniq, values } from 'lodash-unified' -const collect = >>(data: T, fields: (keyof T)[]): string[] => { +const collect = >>(data: T, fields: Array): string[] => { const groupedByFields = values(pick(data, fields)) const listOfAddresses = groupedByFields.map((v) => values(v)) const listOfAddress = flatten(listOfAddresses) diff --git a/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts b/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts index 6fad5daaf80e..8703e37e037a 100644 --- a/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts +++ b/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts @@ -25,7 +25,7 @@ export function useERC20TokenDetailed(address?: string, token?: Partial[], _chainId?: ChainId) { +export function useFungibleTokensDetailed(listOfToken: Array>, _chainId?: ChainId) { const currentChainId = useChainId() const chainId = _chainId ? _chainId : currentChainId const listOfAddress = useMemo(() => listOfToken.map((t) => t.address), [JSON.stringify(listOfToken)]) diff --git a/packages/web3-shared/evm/hooks/useERC20TokensDetailedFromTokenLists.ts b/packages/web3-shared/evm/hooks/useERC20TokensDetailedFromTokenLists.ts index 81a63449bb6c..d3c38f381bfd 100644 --- a/packages/web3-shared/evm/hooks/useERC20TokensDetailedFromTokenLists.ts +++ b/packages/web3-shared/evm/hooks/useERC20TokensDetailedFromTokenLists.ts @@ -12,9 +12,9 @@ import { EMPTY_LIST } from '@masknet/shared-base' export function useERC20TokensDetailedFromTokenLists( lists?: string[], keyword = '', - additionalTokens: (ERC20TokenDetailed | NativeTokenDetailed)[] = EMPTY_LIST, + additionalTokens: Array = EMPTY_LIST, targetChainId?: ChainId, -): AsyncStateRetry<(ERC20TokenDetailed | NativeTokenDetailed)[]> { +): AsyncStateRetry> { // #region fetch token lists const currentChainId = useChainId() const chainId = targetChainId ?? currentChainId diff --git a/packages/web3-shared/evm/hooks/useERC721TokenDetailed.ts b/packages/web3-shared/evm/hooks/useERC721TokenDetailed.ts index cc9397ca4313..41b177ef1d99 100644 --- a/packages/web3-shared/evm/hooks/useERC721TokenDetailed.ts +++ b/packages/web3-shared/evm/hooks/useERC721TokenDetailed.ts @@ -39,7 +39,7 @@ export async function getERC721TokenDetailedFromOpensea( description: string image_url: string animation_url: string - top_ownerships: { owner: { address: string } }[] + top_ownerships: Array<{ owner: { address: string } }> } if (response.ok) { diff --git a/packages/web3-shared/evm/hooks/useMulticall.ts b/packages/web3-shared/evm/hooks/useMulticall.ts index 323d362272e2..f05a80aecb2a 100644 --- a/packages/web3-shared/evm/hooks/useMulticall.ts +++ b/packages/web3-shared/evm/hooks/useMulticall.ts @@ -192,7 +192,7 @@ export function useMulticallStateDecoded< export function useSingleContractMultipleData( contract: T | null, names: K[], - callDatas: Parameters[], + callDatas: Array>, gasLimit = DEFAULT_GAS_LIMIT, chainId?: ChainId, blockNumber?: number, @@ -241,7 +241,7 @@ export function useMultipleContractSingleData( contracts: T[], names: K[], - callDatas: Parameters[], + callDatas: Array>, gasLimit = DEFAULT_GAS_LIMIT, chainId?: ChainId, ) { From 5128f38145c44499e520421d722322416697a75e Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 27 May 2022 12:11:48 +0800 Subject: [PATCH 05/17] fix: prettier --- packages/mask/src/components/shared/AbstractTab.tsx | 12 +++++++----- packages/mask/src/plugins/Trader/types/trader.ts | 4 +++- .../mask/src/plugins/Wallet/services/wallet/index.ts | 12 +++++++----- packages/plugins/Flow/src/apis/getFungibleAssets.ts | 6 +++--- packages/theme/stories/utils/Material-UI.ts | 4 +++- .../evm/constants/getContractOwnerDomain.ts | 5 ++++- .../web3-shared/evm/hooks/useERC20TokenDetailed.ts | 5 ++++- 7 files changed, 31 insertions(+), 17 deletions(-) diff --git a/packages/mask/src/components/shared/AbstractTab.tsx b/packages/mask/src/components/shared/AbstractTab.tsx index 3357f4f06564..fc124d5bbcfc 100644 --- a/packages/mask/src/components/shared/AbstractTab.tsx +++ b/packages/mask/src/components/shared/AbstractTab.tsx @@ -23,11 +23,13 @@ interface TabPanelProps extends BoxProps { export interface AbstractTabProps extends withClasses<'tab' | 'tabs' | 'tabPanel' | 'indicator' | 'focusTab' | 'tabPaper' | 'flexContainer'> { - tabs: Array & { - cb?: () => void - disableFocusRipple?: boolean - disableRipple?: boolean - }> + tabs: Array< + Omit & { + cb?: () => void + disableFocusRipple?: boolean + disableRipple?: boolean + } + > state?: readonly [number, (next: number) => void] index?: number disableFocusRipple?: boolean diff --git a/packages/mask/src/plugins/Trader/types/trader.ts b/packages/mask/src/plugins/Trader/types/trader.ts index 62ed8d28b0ff..20fa860c5e49 100644 --- a/packages/mask/src/plugins/Trader/types/trader.ts +++ b/packages/mask/src/plugins/Trader/types/trader.ts @@ -92,7 +92,9 @@ export interface TradeComputed { maximumSold: BigNumber minimumReceived: BigNumber fee: BigNumber - path?: Array | PartialRequired>> + path?: Array< + Array | PartialRequired> + > trade_?: T } diff --git a/packages/mask/src/plugins/Wallet/services/wallet/index.ts b/packages/mask/src/plugins/Wallet/services/wallet/index.ts index 62893f8f752e..96c990f49f0c 100644 --- a/packages/mask/src/plugins/Wallet/services/wallet/index.ts +++ b/packages/mask/src/plugins/Wallet/services/wallet/index.ts @@ -51,11 +51,13 @@ export async function getWallet(address?: string) { } export async function getWallets(providerType?: ProviderType): Promise< - Array & { - configurable: boolean - hasStoredKeyInfo: boolean - hasDerivationPath: boolean - }> + Array< + Omit & { + configurable: boolean + hasStoredKeyInfo: boolean + hasDerivationPath: boolean + } + > > { if (hasNativeAPI) { if (providerType && providerType !== ProviderType.MaskWallet) return [] diff --git a/packages/plugins/Flow/src/apis/getFungibleAssets.ts b/packages/plugins/Flow/src/apis/getFungibleAssets.ts index a3965e48982c..8888c2d0fb8f 100644 --- a/packages/plugins/Flow/src/apis/getFungibleAssets.ts +++ b/packages/plugins/Flow/src/apis/getFungibleAssets.ts @@ -110,7 +110,7 @@ export async function getFungibleAssets( getAssetTether(network.chainId, address), ]) - return allSettled - .map((x) => (x.status === 'fulfilled' ? x.value : null)) - .filter(Boolean) as Array> + return allSettled.map((x) => (x.status === 'fulfilled' ? x.value : null)).filter(Boolean) as Array< + Web3Plugin.Asset + > } diff --git a/packages/theme/stories/utils/Material-UI.ts b/packages/theme/stories/utils/Material-UI.ts index 953910f489cf..2bc1c3fd4dc3 100644 --- a/packages/theme/stories/utils/Material-UI.ts +++ b/packages/theme/stories/utils/Material-UI.ts @@ -2,7 +2,9 @@ import type { ButtonProps, SelectProps, TextFieldProps } from '@mui/material' import type { ArgType, ArgTypes } from '@storybook/addons' import { argsOfArr, ControlType } from './args' function enumIn(enums: { - [Prop in keyof T]?: (argsFromEnum: (enumString: Array>, type?: ControlType) => ArgType) => ArgType + [Prop in keyof T]?: ( + argsFromEnum: (enumString: Array>, type?: ControlType) => ArgType, + ) => ArgType }): ArgTypes { for (const key of Object.keys(enums) as Array) { enums[key] = (enums[key] as any)(argsOfArr) diff --git a/packages/web3-shared/evm/constants/getContractOwnerDomain.ts b/packages/web3-shared/evm/constants/getContractOwnerDomain.ts index 2e9077899143..b38f5de4fe91 100644 --- a/packages/web3-shared/evm/constants/getContractOwnerDomain.ts +++ b/packages/web3-shared/evm/constants/getContractOwnerDomain.ts @@ -13,7 +13,10 @@ import RedPacket from '@masknet/web3-constants/evm/red-packet.json' import Trader from '@masknet/web3-constants/evm/trader.json' import { filter, flatten, pick, uniq, values } from 'lodash-unified' -const collect = >>(data: T, fields: Array): string[] => { +const collect = >>( + data: T, + fields: Array, +): string[] => { const groupedByFields = values(pick(data, fields)) const listOfAddresses = groupedByFields.map((v) => values(v)) const listOfAddress = flatten(listOfAddresses) diff --git a/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts b/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts index 8703e37e037a..5577105a6757 100644 --- a/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts +++ b/packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts @@ -25,7 +25,10 @@ export function useERC20TokenDetailed(address?: string, token?: Partial>, _chainId?: ChainId) { +export function useFungibleTokensDetailed( + listOfToken: Array>, + _chainId?: ChainId, +) { const currentChainId = useChainId() const chainId = _chainId ? _chainId : currentChainId const listOfAddress = useMemo(() => listOfToken.map((t) => t.address), [JSON.stringify(listOfToken)]) From d807a28f342ad5afbc1c8f5202ced17ed21755fb Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Fri, 27 May 2022 15:13:58 +0800 Subject: [PATCH 06/17] docs: add template for requesting a new EVM-compatible chain (#6364) --- .github/ISSUE_TEMPLATE/evm.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/evm.md diff --git a/.github/ISSUE_TEMPLATE/evm.md b/.github/ISSUE_TEMPLATE/evm.md new file mode 100644 index 000000000000..89ecabfdd35f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/evm.md @@ -0,0 +1,31 @@ +--- +name: Deploy Contract Request +about: Request to deploy contracts on a new EVM-compatible chain. +title: '[EVM Chain] Request to deploy contracts on ' +labels: '' +assignees: DimensionDev/dev-smartcontract +--- + +Request to depoly contracts on . + + + +## Chain Info + +| Name | Content | +| ---- | ------- | +| Name | \- | +| ChainId | \- | +| Website | \- | + + +## Checklist + +The following contracts are requested. + ++ [RedPacket](https://github.com/DimensionDev/RedPacket) ++ [Initial Twitter Offer](https://github.com/DimensionDev/InitialTwitterOffering) ++ Dummy Qualification ++ BalanceChecker ++ Multicall ++ UniswapInterfaceMulticall From 69e2db4c880d620f29c41f8e199017881cdc3ea7 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 27 May 2022 15:58:56 +0800 Subject: [PATCH 07/17] remove provider-proxy package to merge 6002 --- .github/workflows/deploy-proxy.yml | 30 --- packages/provider-proxy/build.mjs | 63 ------ packages/provider-proxy/package.json | 26 --- packages/provider-proxy/rollup.config.js | 51 ----- packages/provider-proxy/src/helper/request.ts | 23 -- packages/provider-proxy/src/index.ts | 14 -- .../src/producers/fetchProxyVersion.ts | 21 -- .../src/producers/fungibleTokenAsset.ts | 25 --- .../producers/nonFungibleCollectibleAsset.ts | 55 ----- .../nonFungibleCollectibleAssetV2.ts | 55 ----- .../producers/nonFungibleCollectionAsset.ts | 45 ---- packages/provider-proxy/src/types.ts | 12 -- packages/provider-proxy/tsconfig.json | 16 -- pnpm-lock.yaml | 197 ++++++++---------- tsconfig.json | 2 - 15 files changed, 84 insertions(+), 551 deletions(-) delete mode 100644 .github/workflows/deploy-proxy.yml delete mode 100644 packages/provider-proxy/build.mjs delete mode 100644 packages/provider-proxy/package.json delete mode 100644 packages/provider-proxy/rollup.config.js delete mode 100644 packages/provider-proxy/src/helper/request.ts delete mode 100644 packages/provider-proxy/src/index.ts delete mode 100644 packages/provider-proxy/src/producers/fetchProxyVersion.ts delete mode 100644 packages/provider-proxy/src/producers/fungibleTokenAsset.ts delete mode 100644 packages/provider-proxy/src/producers/nonFungibleCollectibleAsset.ts delete mode 100644 packages/provider-proxy/src/producers/nonFungibleCollectibleAssetV2.ts delete mode 100644 packages/provider-proxy/src/producers/nonFungibleCollectionAsset.ts delete mode 100644 packages/provider-proxy/src/types.ts delete mode 100644 packages/provider-proxy/tsconfig.json diff --git a/.github/workflows/deploy-proxy.yml b/.github/workflows/deploy-proxy.yml deleted file mode 100644 index 9bd3176fa268..000000000000 --- a/.github/workflows/deploy-proxy.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Publish Proxy Package - -on: - workflow_dispatch: -jobs: - build: - runs-on: ubuntu-20.04 - permissions: - packages: write - contents: read - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 0 - - uses: pnpm/action-setup@v2.2.1 - - uses: actions/setup-node@v2 - with: - cache: pnpm - - uses: DimensionDev/github-token-action@latest - with: - registry: true - - run: pnpm install - - run: pnpm build - name: Build solution - - run: pnpm build - name: Build provider-proxy Package - working-directory: packages/provider-proxy - - run: npm publish - working-directory: packages/provider-proxy/dist diff --git a/packages/provider-proxy/build.mjs b/packages/provider-proxy/build.mjs deleted file mode 100644 index 8afa346dc36d..000000000000 --- a/packages/provider-proxy/build.mjs +++ /dev/null @@ -1,63 +0,0 @@ -// @ts-check -import { spawn } from 'child_process' -import { readFile, writeFile } from 'fs/promises' -import { join, resolve } from 'path' -import { fileURLToPath } from 'url' -import { format as formatDate } from 'date-fns' - -const __file = fileURLToPath(import.meta.url) -const __dirname = resolve(__file, '../') -const __root = join(__dirname, './dist') - -function awaitChildProcess(child) { - return new Promise((resolve, reject) => { - child.on('error', () => reject(child.exitCode || 0)) - child.on('exit', (code) => resolve(code || 0)) - }) -} - -const version = JSON.parse(await readFile(join(__dirname, 'package.json'), 'utf-8')).version -const buildVersion = process.env.BUILD_VERSION ?? formatDate(Date.now(), 'yyyymmddHHMMss') -const fullVersion = `${version}-${buildVersion}` - -const rollup = awaitChildProcess( - spawn(`PROXY_VERSION=${fullVersion} pnpm run build:rollup`, { - cwd: __dirname, - shell: true, - stdio: 'inherit', - }), -) -await rollup -const packageJSON = { - name: '@dimensiondev/provider-proxy', - repository: 'https://github.com/DimensionDev/Maskbook', - version: fullVersion, - dependencies: { - // 'wallet.ts': '1.0.1', - 'bignumber.js': '9.0.1', - 'socket.io-client': '2.4.0', - 'lodash-unified': '1.0.1', - 'date-fns': '2.27.0', - urlcat: '^2.0.4', - }, - main: './output.js', - types: './output.d.ts', - files: ['output.js', 'output.d.ts'], -} -await writeFile(join(__root, 'package.json'), JSON.stringify(packageJSON, undefined, 4)) - -// validate if there is dependency missing -await awaitChildProcess( - spawn('npm install', { - cwd: __root, - shell: true, - stdio: 'inherit', - }), -) -await awaitChildProcess( - spawn('node output.js', { - cwd: __root, - shell: true, - stdio: 'inherit', - }), -) diff --git a/packages/provider-proxy/package.json b/packages/provider-proxy/package.json deleted file mode 100644 index 6f5c19a74aed..000000000000 --- a/packages/provider-proxy/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@dimensiondev/provider-proxy", - "version": "0.0.1", - "scripts": { - "build": "node ./build.mjs", - "build:rollup": "rollup -c --environment PROXY_VERSION:$PROXY_VERSION" - }, - "dependencies": { - "@masknet/plugin-infra": "workspace:*", - "@masknet/web3-providers": "workspace:*", - "@masknet/web3-shared-base": "workspace:*", - "@masknet/web3-shared-evm": "workspace:*", - "urlcat": "^2.0.4" - }, - "devDependencies": { - "@rollup/plugin-alias": "^3.1.8", - "@rollup/plugin-commonjs": "^22.0.0", - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.3.0", - "@rollup/plugin-replace": "^4.0.0", - "@rollup/plugin-sucrase": "^4.0.4", - "date-fns": "^2.28.0", - "rollup": "^2.73.0", - "rollup-plugin-dts": "4.2.1" - } -} diff --git a/packages/provider-proxy/rollup.config.js b/packages/provider-proxy/rollup.config.js deleted file mode 100644 index d39b10ba756d..000000000000 --- a/packages/provider-proxy/rollup.config.js +++ /dev/null @@ -1,51 +0,0 @@ -import commonjs from '@rollup/plugin-commonjs' -import node from '@rollup/plugin-node-resolve' -import sucrase from '@rollup/plugin-sucrase' -import json from '@rollup/plugin-json' -import alias from '@rollup/plugin-alias' -import dts from 'rollup-plugin-dts' -import replace from '@rollup/plugin-replace' - -const config = { - input: './src/index.ts', - output: { - file: 'dist/output.js', - format: 'cjs', - }, - plugins: [ - commonjs(), - node(), - json(), - alias({ - entries: [ - { find: '@masknet/web3-shared-evm', replacement: '../web3-shared/evm/index.ts' }, - { find: '@masknet/web3-shared-base', replacement: '../web3-shared/base/index.ts' }, - ], - }), - sucrase({ transforms: ['typescript', 'jsx'] }), - replace({ - 'process.env.PROVIDER_API_ENV': JSON.stringify('proxy'), - 'process.env.PROXY_VERSION': JSON.stringify(process.env.PROXY_VERSION), - }), - ], - external: (id) => { - if (id.startsWith('.')) return false - if (id.includes('@masknet')) return false - if (id.includes('node_modules')) return true - return false - }, - treeshake: { moduleSideEffects: false, propertyReadSideEffects: false }, -} - -const dtsConfig = { - input: './dist/index.d.ts', - output: [{ file: './dist/output.d.ts', format: 'es' }], - plugins: [ - dts({ - respectExternal: true, - }), - ], - external: config.external, -} - -export default [config, dtsConfig] diff --git a/packages/provider-proxy/src/helper/request.ts b/packages/provider-proxy/src/helper/request.ts deleted file mode 100644 index 3e11d6090d23..000000000000 --- a/packages/provider-proxy/src/helper/request.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { ProducerPushFunction } from '../types' -import type { NonFungibleTokenAPI } from '@masknet/web3-providers' - -export async function collectAllPageDate( - fetcher: (page: number, pageInfo: { [key in string]: unknown }) => Promise>, - pageSize: number, - handler?: ProducerPushFunction, -) { - let data: T[] = [] - let hasNextPage = true - let page = 0 - let pageInfo = {} - while (hasNextPage) { - const result = await fetcher(page, pageInfo) - await handler?.(result.data) - data = [...data, ...result.data] - hasNextPage = result.hasNextPage - pageInfo = result.nextPageInfo ?? {} - page = page + 1 - } - - return data -} diff --git a/packages/provider-proxy/src/index.ts b/packages/provider-proxy/src/index.ts deleted file mode 100644 index bd464fb580ba..000000000000 --- a/packages/provider-proxy/src/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { RPCMethodRegistrationValue } from './types' -import fetchProxyVersion from './producers/fetchProxyVersion' -import fungibleTokenProducer from './producers/fungibleTokenAsset' -import nonFungibleCollectionAsset from './producers/nonFungibleCollectionAsset' -import nonFungibleCollectibleAsset from './producers/nonFungibleCollectibleAsset' -import nonFungibleCollectibleAssetV2 from './producers/nonFungibleCollectibleAssetV2' - -export const producers: RPCMethodRegistrationValue[] = [ - fetchProxyVersion, - fungibleTokenProducer, - nonFungibleCollectibleAsset, - nonFungibleCollectibleAssetV2, - nonFungibleCollectionAsset, -] diff --git a/packages/provider-proxy/src/producers/fetchProxyVersion.ts b/packages/provider-proxy/src/producers/fetchProxyVersion.ts deleted file mode 100644 index dbd123973f37..000000000000 --- a/packages/provider-proxy/src/producers/fetchProxyVersion.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { ProducerPushFunction, RPCMethodRegistrationValue } from '../types' - -export function getProxyVersion() { - try { - return process.env.PROXY_VERSION ?? '' - } catch { - return '' - } -} - -const fetchProxyVersion = async (push: ProducerPushFunction): Promise => { - await push([getProxyVersion()]) -} - -const producer: RPCMethodRegistrationValue = { - method: 'mask.fetchProxyVersion', - producer: fetchProxyVersion, - distinctBy: (item) => item, -} - -export default producer diff --git a/packages/provider-proxy/src/producers/fungibleTokenAsset.ts b/packages/provider-proxy/src/producers/fungibleTokenAsset.ts deleted file mode 100644 index ca78d22190f4..000000000000 --- a/packages/provider-proxy/src/producers/fungibleTokenAsset.ts +++ /dev/null @@ -1,25 +0,0 @@ -import type { Web3Plugin } from '@masknet/plugin-infra/web3' -import { getAssetListFromDebank } from '@masknet/web3-providers' -import type { ProducerArgBase, ProducerKeyFunction, ProducerPushFunction, RPCMethodRegistrationValue } from '../types' - -export interface FungibleTokenAssetArgs extends ProducerArgBase { - address: string -} - -const fungibleTokenAsset = async ( - push: ProducerPushFunction>, - getKeys: ProducerKeyFunction, - args: FungibleTokenAssetArgs, -): Promise => { - const { address } = args - const data = await getAssetListFromDebank(address) - await push(data) -} - -const producer: RPCMethodRegistrationValue, FungibleTokenAssetArgs> = { - method: 'mask.fetchFungibleTokenAsset', - producer: fungibleTokenAsset, - distinctBy: (item) => `${item.id}_${item.chainId}`, -} - -export default producer diff --git a/packages/provider-proxy/src/producers/nonFungibleCollectibleAsset.ts b/packages/provider-proxy/src/producers/nonFungibleCollectibleAsset.ts deleted file mode 100644 index e81802b995b1..000000000000 --- a/packages/provider-proxy/src/producers/nonFungibleCollectibleAsset.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { getOpenSeaNFTList, getRaribleNFTList, getNFTScanNFTs } from '@masknet/web3-providers' -import type { ERC721TokenDetailed } from '@masknet/web3-shared-evm' -import type { ProducerArgBase, ProducerKeyFunction, ProducerPushFunction, RPCMethodRegistrationValue } from '../types' -import { collectAllPageDate } from '../helper/request' - -export interface NonFungibleTokenAssetArgs extends ProducerArgBase { - address: string -} - -const nonFungibleCollectibleAsset = async ( - push: ProducerPushFunction, - getKeys: ProducerKeyFunction, - args: NonFungibleTokenAssetArgs, -): Promise => { - const { address } = args - const size = 50 - const openSeaApiKey = await getKeys('opensea') - - try { - await collectAllPageDate( - (page) => getOpenSeaNFTList(openSeaApiKey, address, page, size), - size, - push, - ) - } finally { - try { - await collectAllPageDate( - (page, pageInfo) => getRaribleNFTList(address, page, size, pageInfo), - size, - push, - ) - } finally { - await collectAllPageDate( - (page) => getNFTScanNFTs(address, 'erc721', page, size), - size, - push, - ) - - await collectAllPageDate( - (page) => getNFTScanNFTs(address, 'erc1155', page, size), - size, - push, - ) - } - } -} - -const producer: RPCMethodRegistrationValue = { - method: 'mask.fetchNonFungibleCollectibleAsset', - producer: nonFungibleCollectibleAsset, - distinctBy: (item) => - `${item.tokenId.toLowerCase()}_${item.contractDetailed.address.toLowerCase()}_${item.contractDetailed.chainId}`, -} - -export default producer diff --git a/packages/provider-proxy/src/producers/nonFungibleCollectibleAssetV2.ts b/packages/provider-proxy/src/producers/nonFungibleCollectibleAssetV2.ts deleted file mode 100644 index 71298f8eed69..000000000000 --- a/packages/provider-proxy/src/producers/nonFungibleCollectibleAssetV2.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { getOpenSeaNFTList, getRaribleNFTList, getNFTScanNFTs } from '@masknet/web3-providers' -import type { ERC721TokenDetailed } from '@masknet/web3-shared-evm' -import type { ProducerArgBase, ProducerKeyFunction, ProducerPushFunction, RPCMethodRegistrationValue } from '../types' -import { collectAllPageDate } from '../helper/request' - -export interface NonFungibleTokenAssetArgs extends ProducerArgBase { - address: string -} - -const nonFungibleCollectibleAsset = async ( - push: ProducerPushFunction, - getKeys: ProducerKeyFunction, - args: NonFungibleTokenAssetArgs, -): Promise => { - const { address } = args - const size = 50 - const openSeaApiKey = await getKeys('opensea') - - try { - await collectAllPageDate( - (page) => getOpenSeaNFTList(openSeaApiKey, address, page, size), - size, - push, - ) - } finally { - const fromRarible = collectAllPageDate( - (page, pageInfo) => getRaribleNFTList(address, page, size, pageInfo), - size, - push, - ) - - const formNFTScanERC721 = collectAllPageDate( - (page) => getNFTScanNFTs(address, 'erc721', page, size), - size, - push, - ) - - const fromNFTScanERC1155 = collectAllPageDate( - (page) => getNFTScanNFTs(address, 'erc1155', page, size), - size, - push, - ) - - await Promise.allSettled([fromRarible, formNFTScanERC721, fromNFTScanERC1155]) - } -} - -const producer: RPCMethodRegistrationValue = { - method: 'mask.fetchNonFungibleCollectibleAssetV2', - producer: nonFungibleCollectibleAsset, - distinctBy: (item) => - `${item.tokenId.toLowerCase()}_${item.contractDetailed.address.toLowerCase()}_${item.contractDetailed.chainId}`, -} - -export default producer diff --git a/packages/provider-proxy/src/producers/nonFungibleCollectionAsset.ts b/packages/provider-proxy/src/producers/nonFungibleCollectionAsset.ts deleted file mode 100644 index 4a622cd6fd07..000000000000 --- a/packages/provider-proxy/src/producers/nonFungibleCollectionAsset.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { Web3Plugin } from '@masknet/plugin-infra/web3' -import { getNFTScanNFTList, getOpenSeaCollectionList } from '@masknet/web3-providers' -import { collectAllPageDate } from '../helper/request' -import type { ProducerArgBase, ProducerKeyFunction, ProducerPushFunction, RPCMethodRegistrationValue } from '../types' - -interface NonFungibleCollectibleAssetArgs extends ProducerArgBase { - address: string -} - -const nonFungibleCollectionAsset = async ( - push: ProducerPushFunction, - getKeys: ProducerKeyFunction, - args: NonFungibleCollectibleAssetArgs, -): Promise => { - const { address } = args - const openSeaApiKey = await getKeys('opensea') - - const pageSize = 50 - const collectionsFromNFTScan = await getNFTScanNFTList(address) - await push( - collectionsFromNFTScan.map((x) => ({ - id: x.contractDetailed.address, - chainId: x.contractDetailed.chainId, - name: x.contractDetailed.name, - symbol: x.contractDetailed.symbol, - address: x.contractDetailed.address, - iconURL: x.contractDetailed.iconURL, - balance: x.balance, - })), - ) - - const collectionsFromOpenSea = await collectAllPageDate( - (page: number) => getOpenSeaCollectionList(openSeaApiKey, address, page, pageSize), - pageSize, - ) - await push(collectionsFromOpenSea) -} - -const producer: RPCMethodRegistrationValue = { - method: 'mask.fetchNonFungibleCollectionAsset', - producer: nonFungibleCollectionAsset, - distinctBy: (item) => item.address, -} - -export default producer diff --git a/packages/provider-proxy/src/types.ts b/packages/provider-proxy/src/types.ts deleted file mode 100644 index cb48133c2394..000000000000 --- a/packages/provider-proxy/src/types.ts +++ /dev/null @@ -1,12 +0,0 @@ -export type ProducerPushFunction = (item: T[]) => Promise -export type ProducerKeyFunction = (provider: string) => Promise - -export interface ProducerArgBase { - size: number -} - -export interface RPCMethodRegistrationValue { - method: string - producer(push: ProducerPushFunction, getKey: ProducerKeyFunction, args: TArgs): Promise - distinctBy(item: T): string -} diff --git a/packages/provider-proxy/tsconfig.json b/packages/provider-proxy/tsconfig.json deleted file mode 100644 index fd8ba048eac1..000000000000 --- a/packages/provider-proxy/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "./src/", - "outDir": "./dist/", - "tsBuildInfoFile": "./dist/.tsbuildinfo", - "emitDeclarationOnly": true - }, - "include": ["./src", "./src/**/*.json"], - "references": [ - { "path": "../plugin-infra" }, - { "path": "../web3-providers" }, - { "path": "../web3-shared/base" }, - { "path": "../web3-shared/evm" } - ] -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a315e77d7e0..58a983fbca5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1012,39 +1012,6 @@ importers: packages/polyfills/types: specifiers: {} - packages/provider-proxy: - specifiers: - '@masknet/plugin-infra': workspace:* - '@masknet/web3-providers': workspace:* - '@masknet/web3-shared-base': workspace:* - '@masknet/web3-shared-evm': workspace:* - '@rollup/plugin-alias': ^3.1.8 - '@rollup/plugin-commonjs': ^22.0.0 - '@rollup/plugin-json': ^4.1.0 - '@rollup/plugin-node-resolve': ^13.3.0 - '@rollup/plugin-replace': ^4.0.0 - '@rollup/plugin-sucrase': ^4.0.4 - date-fns: ^2.28.0 - rollup: ^2.73.0 - rollup-plugin-dts: 4.2.1 - urlcat: ^2.0.4 - dependencies: - '@masknet/plugin-infra': link:../plugin-infra - '@masknet/web3-providers': link:../web3-providers - '@masknet/web3-shared-base': link:../web3-shared/base - '@masknet/web3-shared-evm': link:../web3-shared/evm - urlcat: 2.0.4 - devDependencies: - '@rollup/plugin-alias': 3.1.9_rollup@2.73.0 - '@rollup/plugin-commonjs': 22.0.0_rollup@2.73.0 - '@rollup/plugin-json': 4.1.0_rollup@2.73.0 - '@rollup/plugin-node-resolve': 13.3.0_rollup@2.73.0 - '@rollup/plugin-replace': 4.0.0_rollup@2.73.0 - '@rollup/plugin-sucrase': 4.0.4_rollup@2.73.0 - date-fns: 2.28.0 - rollup: 2.73.0 - rollup-plugin-dts: 4.2.1_rollup@2.73.0 - packages/public-api: specifiers: {} @@ -1483,7 +1450,7 @@ packages: dependencies: '@0xproject/utils': 0.2.4 chalk: 2.4.2 - glob: 7.2.3 + glob: 7.2.0 handlebars: 4.7.7 lodash: 4.17.21 mkdirp: 0.5.6 @@ -1498,7 +1465,7 @@ packages: dependencies: '@0xproject/utils': 0.3.4 chalk: 2.4.2 - glob: 7.2.3 + glob: 7.2.0 handlebars: 4.7.7 lodash: 4.17.21 mkdirp: 0.5.6 @@ -1526,12 +1493,12 @@ packages: dev: false /@0xproject/json-schemas/0.7.24: - resolution: {integrity: sha512-20MeFHMptuv0e58mjSLmW84m2HbYdmuxFeeXqGZjv047zBawONe2aXKqLX266XYjgNSif/cDVzdgh7/46J9MVQ==} + resolution: {integrity: sha1-IaErQ6sKtKowLQLEiRZozaNrbGQ=} engines: {node: '>=6.12'} dependencies: '@0xproject/typescript-typings': 0.3.2 '@types/node': 17.0.34 - jsonschema: 1.4.1 + jsonschema: 1.4.0 lodash.values: 4.3.0 dev: false @@ -1543,7 +1510,7 @@ packages: dev: false /@0xproject/types/0.7.0: - resolution: {integrity: sha512-LlTnq7raPnCioCokNy5CLDxZJeg3KtcHT4PBJD6BDiXYtNJxBWvL7/jr6JiwdjReNg7ihGi1265VKfFX7qukRw==} + resolution: {integrity: sha1-+tE5Je6SrU7hmAZopcsr7U3Kq48=} engines: {node: '>=6.12'} dependencies: '@types/node': 17.0.34 @@ -1551,7 +1518,7 @@ packages: dev: false /@0xproject/typescript-typings/0.3.2: - resolution: {integrity: sha512-sHwGTxerREyQhyXFHhZRHvy7PlbBUjsoVbxhf5f+9JasC+IhQ2Nv4uJFjOo16uUPPp7l+lsRUvK/ZwrdGRbFBA==} + resolution: {integrity: sha1-q8NgtEGv2pkxAEUMqDad+r91k2s=} engines: {node: '>=6.12'} dependencies: '@0xproject/types': 0.7.0 @@ -6971,6 +6938,7 @@ packages: dependencies: rollup: 2.73.0 slash: 3.0.0 + dev: false /@rollup/plugin-commonjs/22.0.0_rollup@2.73.0: resolution: {integrity: sha512-Ktvf2j+bAO+30awhbYoCaXpBcyPmJbaEUYClQns/+6SNCYFURbvBiNbWgHITEsIgDDWCDUclWRKEuf8cwZCFoQ==} @@ -7017,6 +6985,7 @@ packages: '@rollup/pluginutils': 3.1.0_rollup@2.73.0 magic-string: 0.25.9 rollup: 2.73.0 + dev: false /@rollup/plugin-sucrase/4.0.4_rollup@2.73.0: resolution: {integrity: sha512-YH4J8yoJb5EVnLhAwWxYAQNh2SJOR+SdZ6XdgoKEv6Kxm33riYkM8MlMaggN87UoISP52qAFyZ5ey56wu6umGg==} @@ -11398,7 +11367,7 @@ packages: dev: true /array-uniq/1.0.3: - resolution: {integrity: sha512-MNha4BWQ6JbwhFhj03YK552f7cb3AzoE8SzeljgChvL1dl3IcvggXVz1DilzySZkCja+CXuZbdW7yATchWn8/Q==} + resolution: {integrity: sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=} engines: {node: '>=0.10.0'} /array-unique/0.3.2: @@ -11579,7 +11548,7 @@ packages: dev: true /async/1.5.2: - resolution: {integrity: sha512-nSVgobk4rv61R9PUSDtYt7mPVB2olxNR5RWJcAsH676/ef11bUZwvu7+RGYrYauVdDPcO519v68wRhXQtxsV9w==} + resolution: {integrity: sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=} dev: false /async/2.6.3: @@ -11659,7 +11628,7 @@ packages: dev: false /axios/0.17.1: - resolution: {integrity: sha512-mZzWRyJeJ0rtK7e1/6iYBUzmeXjzei+1h1IvbedyU0sB52++tU5AU6r6TLXpwNVR0ebXIpvTVW+9CpWNyc1n8w==} + resolution: {integrity: sha1-LY4+XQvb1zJ/kbyBT1xXZg+Bgk0=} deprecated: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410 dependencies: follow-redirects: 1.15.0 @@ -11693,7 +11662,7 @@ packages: dev: false /babel-code-frame/6.26.0: - resolution: {integrity: sha512-XqYMR2dfdGMW+hd0IUZ2PwK+fGeFkOxZJ0wY+JaQAHzt1Zx8LcvpiZD2NiGkEG8qx0CfkAOr5xt76d1e8vG90g==} + resolution: {integrity: sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=} dependencies: chalk: 1.1.3 esutils: 2.0.3 @@ -11740,7 +11709,7 @@ packages: dev: false /babel-helper-builder-binary-assignment-operator-visitor/6.24.1: - resolution: {integrity: sha512-gCtfYORSG1fUMX4kKraymq607FWgMWg+j42IFPc18kFQEsmtaibP4UrqsXt8FlEJle25HUd4tsoDR7H2wDhe9Q==} + resolution: {integrity: sha1-zORReto1b0IgvK6KAsKzRvmlZmQ=} dependencies: babel-helper-explode-assignable-expression: 6.24.1 babel-runtime: 6.26.0 @@ -11750,7 +11719,7 @@ packages: dev: false /babel-helper-call-delegate/6.24.1: - resolution: {integrity: sha512-RL8n2NiEj+kKztlrVJM9JT1cXzzAdvWFh76xh/H1I4nKwunzE4INBXn8ieCZ+wh4zWszZk7NBS1s/8HR5jDkzQ==} + resolution: {integrity: sha1-7Oaqzdx25Bw0YfiL/Fdb0Nqi340=} dependencies: babel-helper-hoist-variables: 6.24.1 babel-runtime: 6.26.0 @@ -11761,7 +11730,7 @@ packages: dev: false /babel-helper-define-map/6.26.0: - resolution: {integrity: sha512-bHkmjcC9lM1kmZcVpA5t2om2nzT/xiZpo6TJq7UlZ3wqKfzia4veeXbIhKvJXAMzhhEBd3cR1IElL5AenWEUpA==} + resolution: {integrity: sha1-pfVtq0GiX5fstJjH66ypgZ+Vvl8=} dependencies: babel-helper-function-name: 6.24.1 babel-runtime: 6.26.0 @@ -11772,7 +11741,7 @@ packages: dev: false /babel-helper-explode-assignable-expression/6.24.1: - resolution: {integrity: sha512-qe5csbhbvq6ccry9G7tkXbzNtcDiH4r51rrPUbwwoTzZ18AqxWYRZT6AOmxrpxKnQBW0pYlBI/8vh73Z//78nQ==} + resolution: {integrity: sha1-8luCz33BBDPFX3BZLVdGQArCLKo=} dependencies: babel-runtime: 6.26.0 babel-traverse: 6.26.0 @@ -11782,7 +11751,7 @@ packages: dev: false /babel-helper-function-name/6.24.1: - resolution: {integrity: sha512-Oo6+e2iX+o9eVvJ9Y5eKL5iryeRdsIkwRYheCuhYdVHsdEQysbc2z2QkqCLIYnNxkT5Ss3ggrHdXiDI7Dhrn4Q==} + resolution: {integrity: sha1-00dbjAPtmCQqJbSDUasYOZ01gKk=} dependencies: babel-helper-get-function-arity: 6.24.1 babel-runtime: 6.26.0 @@ -11794,28 +11763,28 @@ packages: dev: false /babel-helper-get-function-arity/6.24.1: - resolution: {integrity: sha512-WfgKFX6swFB1jS2vo+DwivRN4NB8XUdM3ij0Y1gnC21y1tdBoe6xjVnd7NSI6alv+gZXCtJqvrTeMW3fR/c0ng==} + resolution: {integrity: sha1-j3eCqpNAfEHTqlCQj4mwMbG2hT0=} dependencies: babel-runtime: 6.26.0 babel-types: 6.26.0 dev: false /babel-helper-hoist-variables/6.24.1: - resolution: {integrity: sha512-zAYl3tqerLItvG5cKYw7f1SpvIxS9zi7ohyGHaI9cgDUjAT6YcY9jIEH5CstetP5wHIVSceXwNS7Z5BpJg+rOw==} + resolution: {integrity: sha1-HssnaJydJVE+rbyZFKc/VAi+enY=} dependencies: babel-runtime: 6.26.0 babel-types: 6.26.0 dev: false /babel-helper-optimise-call-expression/6.24.1: - resolution: {integrity: sha512-Op9IhEaxhbRT8MDXx2iNuMgciu2V8lDvYCNQbDGjdBNCjaMvyLf4wl4A3b8IgndCyQF8TwfgsQ8T3VD8aX1/pA==} + resolution: {integrity: sha1-96E0J7qfc/j0+pk8VKl4gtEkQlc=} dependencies: babel-runtime: 6.26.0 babel-types: 6.26.0 dev: false /babel-helper-regex/6.26.0: - resolution: {integrity: sha512-VlPiWmqmGJp0x0oK27Out1D+71nVVCTSdlbhIVoaBAj2lUgrNjBCRR9+llO4lTSb2O4r7PJg+RobRkhBrf6ofg==} + resolution: {integrity: sha1-MlxZ+QL4LyS3T6zu0DY5VPZJXnI=} dependencies: babel-runtime: 6.26.0 babel-types: 6.26.0 @@ -11823,7 +11792,7 @@ packages: dev: false /babel-helper-remap-async-to-generator/6.24.1: - resolution: {integrity: sha512-RYqaPD0mQyQIFRu7Ho5wE2yvA/5jxqCIj/Lv4BXNq23mHYu/vxikOy2JueLiBxQknwapwrJeNCesvY0ZcfnlHg==} + resolution: {integrity: sha1-XsWBgnrXI/7N04HxySg5BnbkVRs=} dependencies: babel-helper-function-name: 6.24.1 babel-runtime: 6.26.0 @@ -11835,7 +11804,7 @@ packages: dev: false /babel-helper-replace-supers/6.24.1: - resolution: {integrity: sha512-sLI+u7sXJh6+ToqDr57Bv973kCepItDhMou0xCP2YPVmR1jkHSCY+p1no8xErbV1Siz5QE8qKT1WIwybSWlqjw==} + resolution: {integrity: sha1-v22/5Dk40XNpohPKiov3S2qQqxo=} dependencies: babel-helper-optimise-call-expression: 6.24.1 babel-messages: 6.23.0 @@ -11848,7 +11817,7 @@ packages: dev: false /babel-helpers/6.24.1: - resolution: {integrity: sha512-n7pFrqQm44TCYvrCDb0MqabAF+JUBq+ijBvNMUxpkLjJaAu32faIexewMumrH5KLLJ1HDyT0PTEqRyAe/GwwuQ==} + resolution: {integrity: sha1-NHHenK7DiOXIUOWX5Yom3fN2ArI=} dependencies: babel-runtime: 6.26.0 babel-template: 6.26.0 @@ -11967,7 +11936,7 @@ packages: dev: true /babel-messages/6.23.0: - resolution: {integrity: sha512-Bl3ZiA+LjqaMtNYopA9TYE9HP1tQ+E5dLxE0XrAzcIJeK2UqF0/EaqXwBn9esd4UmTfEab+P+UYQ1GnioFIb/w==} + resolution: {integrity: sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=} dependencies: babel-runtime: 6.26.0 dev: false @@ -11990,7 +11959,7 @@ packages: dev: true /babel-plugin-check-es2015-constants/6.22.0: - resolution: {integrity: sha512-B1M5KBP29248dViEo1owyY32lk1ZSH2DaNNrXLGt8lyjjHm7pBqAdQ7VKUPR6EEDO323+OvT3MQXbCin8ooWdA==} + resolution: {integrity: sha1-NRV7EBQm/S/9PaP3XH0ekYNbv4o=} dependencies: babel-runtime: 6.26.0 dev: false @@ -12191,11 +12160,11 @@ packages: dev: true /babel-plugin-syntax-async-functions/6.13.0: - resolution: {integrity: sha512-4Zp4unmHgw30A1eWI5EpACji2qMocisdXhAftfhXoSV9j0Tvj6nRFE3tOmRY912E0FMRm/L5xWE7MGVT2FoLnw==} + resolution: {integrity: sha1-ytnK0RkbWtY0vzCuCHI5HgZHvpU=} dev: false /babel-plugin-syntax-exponentiation-operator/6.13.0: - resolution: {integrity: sha512-Z/flU+T9ta0aIEKl1tGEmN/pZiI1uXmCiGFRegKacQfEJzp7iNsKloZmyJlQr+75FCJtiFfGIK03SiCvCt9cPQ==} + resolution: {integrity: sha1-nufoM3KQ2pUoggGmpX9BcDF4MN4=} dev: false /babel-plugin-syntax-jsx/6.18.0: @@ -12203,11 +12172,11 @@ packages: dev: true /babel-plugin-syntax-trailing-function-commas/6.22.0: - resolution: {integrity: sha512-Gx9CH3Q/3GKbhs07Bszw5fPTlU+ygrOGfAhEt7W2JICwufpC4SuO0mG0+4NykPBSYPMJhqvVlDBU17qB1D+hMQ==} + resolution: {integrity: sha1-ugNgk3+NBuQBgKQ/4NVhb/9TLPM=} dev: false /babel-plugin-transform-async-to-generator/6.24.1: - resolution: {integrity: sha512-7BgYJujNCg0Ti3x0c/DL3tStvnKS6ktIYOmo9wginv/dfZOrbSZ+qG4IRRHMBOzZ5Awb1skTiAsQXg/+IWkZYw==} + resolution: {integrity: sha1-ZTbjeK/2yx1VF6wOQOs+n8jQh2E=} dependencies: babel-helper-remap-async-to-generator: 6.24.1 babel-plugin-syntax-async-functions: 6.13.0 @@ -12217,19 +12186,19 @@ packages: dev: false /babel-plugin-transform-es2015-arrow-functions/6.22.0: - resolution: {integrity: sha512-PCqwwzODXW7JMrzu+yZIaYbPQSKjDTAsNNlK2l5Gg9g4rz2VzLnZsStvp/3c46GfXpwkyufb3NCyG9+50FF1Vg==} + resolution: {integrity: sha1-RSaSy3EdX3ncf4XkQM5BufJE0iE=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-block-scoped-functions/6.22.0: - resolution: {integrity: sha512-2+ujAT2UMBzYFm7tidUsYh+ZoIutxJ3pN9IYrF1/H6dCKtECfhmB8UkHVpyxDwkj0CYbQG35ykoz925TUnBc3A==} + resolution: {integrity: sha1-u8UbSflk1wy42OC5ToICRs46YUE=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-block-scoping/6.26.0: - resolution: {integrity: sha512-YiN6sFAQ5lML8JjCmr7uerS5Yc/EMbgg9G8ZNmk2E3nYX4ckHR01wrkeeMijEf5WHNK5TW0Sl0Uu3pv3EdOJWw==} + resolution: {integrity: sha1-1w9SmcEwjQXBL0Y4E7CgnnOxiV8=} dependencies: babel-runtime: 6.26.0 babel-template: 6.26.0 @@ -12241,7 +12210,7 @@ packages: dev: false /babel-plugin-transform-es2015-classes/6.24.1: - resolution: {integrity: sha512-5Dy7ZbRinGrNtmWpquZKZ3EGY8sDgIVB4CU8Om8q8tnMLrD/m94cKglVcHps0BCTdZ0TJeeAWOq2TK9MIY6cag==} + resolution: {integrity: sha1-WkxYpQyclGHlZLSyo7+ryXolhNs=} dependencies: babel-helper-define-map: 6.26.0 babel-helper-function-name: 6.24.1 @@ -12257,7 +12226,7 @@ packages: dev: false /babel-plugin-transform-es2015-computed-properties/6.24.1: - resolution: {integrity: sha512-C/uAv4ktFP/Hmh01gMTvYvICrKze0XVX9f2PdIXuriCSvUmV9j+u+BB9f5fJK3+878yMK6dkdcq+Ymr9mrcLzw==} + resolution: {integrity: sha1-b+Ko0WiV1WNPTNmZttNICjCBWbM=} dependencies: babel-runtime: 6.26.0 babel-template: 6.26.0 @@ -12266,26 +12235,26 @@ packages: dev: false /babel-plugin-transform-es2015-destructuring/6.23.0: - resolution: {integrity: sha512-aNv/GDAW0j/f4Uy1OEPZn1mqD+Nfy9viFGBfQ5bZyT35YqOiqx7/tXdyfZkJ1sC21NyEsBdfDY6PYmLHF4r5iA==} + resolution: {integrity: sha1-mXux8auWf2gtKwh2/jWNYOdlxW0=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-duplicate-keys/6.24.1: - resolution: {integrity: sha512-ossocTuPOssfxO2h+Z3/Ea1Vo1wWx31Uqy9vIiJusOP4TbF7tPs9U0sJ9pX9OJPf4lXRGj5+6Gkl/HHKiAP5ug==} + resolution: {integrity: sha1-c+s9MQypaePvnskcU3QabxV2Qj4=} dependencies: babel-runtime: 6.26.0 babel-types: 6.26.0 dev: false /babel-plugin-transform-es2015-for-of/6.23.0: - resolution: {integrity: sha512-DLuRwoygCoXx+YfxHLkVx5/NpeSbVwfoTeBykpJK7JhYWlL/O8hgAK/reforUnZDlxasOrVPPJVI/guE3dCwkw==} + resolution: {integrity: sha1-9HyVsrYT3x0+zC/bdXNiPHUkhpE=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-function-name/6.24.1: - resolution: {integrity: sha512-iFp5KIcorf11iBqu/y/a7DK3MN5di3pNCzto61FqCNnUX4qeBwcV1SLqe10oXNnCaxBUImX3SckX2/o1nsrTcg==} + resolution: {integrity: sha1-g0yJhTvDaxrw86TF26qU/Y6sqos=} dependencies: babel-helper-function-name: 6.24.1 babel-runtime: 6.26.0 @@ -12295,13 +12264,13 @@ packages: dev: false /babel-plugin-transform-es2015-literals/6.22.0: - resolution: {integrity: sha512-tjFl0cwMPpDYyoqYA9li1/7mGFit39XiNX5DKC/uCNjBctMxyL1/PT/l4rSlbvBG1pOKI88STRdUsWXB3/Q9hQ==} + resolution: {integrity: sha1-T1SgLWzWbPkVKAAZox0xklN3yi4=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-modules-amd/6.24.1: - resolution: {integrity: sha512-LnIIdGWIKdw7zwckqx+eGjcS8/cl8D74A3BpJbGjKTFFNJSMrjN4bIh22HY1AlkUbeLG6X6OZj56BDvWD+OeFA==} + resolution: {integrity: sha1-Oz5UAXI5hC1tGcMBHEvS8AoA0VQ=} dependencies: babel-plugin-transform-es2015-modules-commonjs: 6.26.2 babel-runtime: 6.26.0 @@ -12322,7 +12291,7 @@ packages: dev: false /babel-plugin-transform-es2015-modules-systemjs/6.24.1: - resolution: {integrity: sha512-ONFIPsq8y4bls5PPsAWYXH/21Hqv64TBxdje0FvU3MhIV6QM2j5YS7KvAzg/nTIVLot2D2fmFQrFWCbgHlFEjg==} + resolution: {integrity: sha1-/4mhQrkRmpBhlfXxBuzzBdlAfSM=} dependencies: babel-helper-hoist-variables: 6.24.1 babel-runtime: 6.26.0 @@ -12332,7 +12301,7 @@ packages: dev: false /babel-plugin-transform-es2015-modules-umd/6.24.1: - resolution: {integrity: sha512-LpVbiT9CLsuAIp3IG0tfbVo81QIhn6pE8xBJ7XSeCtFlMltuar5VuBV6y6Q45tpui9QWcy5i0vLQfCfrnF7Kiw==} + resolution: {integrity: sha1-rJl+YoXNGO1hdq22B9YCNErThGg=} dependencies: babel-plugin-transform-es2015-modules-amd: 6.24.1 babel-runtime: 6.26.0 @@ -12342,7 +12311,7 @@ packages: dev: false /babel-plugin-transform-es2015-object-super/6.24.1: - resolution: {integrity: sha512-8G5hpZMecb53vpD3mjs64NhI1au24TAmokQ4B+TBFBjN9cVoGoOvotdrMMRmHvVZUEvqGUPWL514woru1ChZMA==} + resolution: {integrity: sha1-JM72muIcuDp/hgPa0CH1cusnj40=} dependencies: babel-helper-replace-supers: 6.24.1 babel-runtime: 6.26.0 @@ -12351,7 +12320,7 @@ packages: dev: false /babel-plugin-transform-es2015-parameters/6.24.1: - resolution: {integrity: sha512-8HxlW+BB5HqniD+nLkQ4xSAVq3bR/pcYW9IigY+2y0dI+Y7INFeTbfAQr+63T3E4UDsZGjyb+l9txUnABWxlOQ==} + resolution: {integrity: sha1-V6w1GrScrxSpfNE7CfZv3wpiXys=} dependencies: babel-helper-call-delegate: 6.24.1 babel-helper-get-function-arity: 6.24.1 @@ -12364,20 +12333,20 @@ packages: dev: false /babel-plugin-transform-es2015-shorthand-properties/6.24.1: - resolution: {integrity: sha512-mDdocSfUVm1/7Jw/FIRNw9vPrBQNePy6wZJlR8HAUBLybNp1w/6lr6zZ2pjMShee65t/ybR5pT8ulkLzD1xwiw==} + resolution: {integrity: sha1-JPh11nIch2YbvZmkYi5R8U3jiqA=} dependencies: babel-runtime: 6.26.0 babel-types: 6.26.0 dev: false /babel-plugin-transform-es2015-spread/6.22.0: - resolution: {integrity: sha512-3Ghhi26r4l3d0Js933E5+IhHwk0A1yiutj9gwvzmFbVV0sPMYk2lekhOufHBswX7NCoSeF4Xrl3sCIuSIa+zOg==} + resolution: {integrity: sha1-1taKmfia7cRTbIGlQujdnxdG+NE=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-sticky-regex/6.24.1: - resolution: {integrity: sha512-CYP359ADryTo3pCsH0oxRo/0yn6UsEZLqYohHmvLQdfS9xkf+MbCzE3/Kolw9OYIY4ZMilH25z/5CbQbwDD+lQ==} + resolution: {integrity: sha1-AMHNsaynERLN8M9hJsLta0V8zbw=} dependencies: babel-helper-regex: 6.26.0 babel-runtime: 6.26.0 @@ -12385,19 +12354,19 @@ packages: dev: false /babel-plugin-transform-es2015-template-literals/6.22.0: - resolution: {integrity: sha512-x8b9W0ngnKzDMHimVtTfn5ryimars1ByTqsfBDwAqLibmuuQY6pgBQi5z1ErIsUOWBdw1bW9FSz5RZUojM4apg==} + resolution: {integrity: sha1-qEs0UPfp+PH2g51taH2oS7EjbY0=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-typeof-symbol/6.23.0: - resolution: {integrity: sha512-fz6J2Sf4gYN6gWgRZaoFXmq93X+Li/8vf+fb0sGDVtdeWvxC9y5/bTD7bvfWMEq6zetGEHpWjtzRGSugt5kNqw==} + resolution: {integrity: sha1-3sCfHN3/lLUqxz1QXITfWdzOs3I=} dependencies: babel-runtime: 6.26.0 dev: false /babel-plugin-transform-es2015-unicode-regex/6.24.1: - resolution: {integrity: sha512-v61Dbbihf5XxnYjtBN04B/JBvsScY37R1cZT5r9permN1cp+b70DY3Ib3fIkgn1DI9U3tGgBJZVD8p/mE/4JbQ==} + resolution: {integrity: sha1-04sS9C6nMj9yk4fxinxa4frrNek=} dependencies: babel-helper-regex: 6.26.0 babel-runtime: 6.26.0 @@ -12405,7 +12374,7 @@ packages: dev: false /babel-plugin-transform-exponentiation-operator/6.24.1: - resolution: {integrity: sha512-LzXDmbMkklvNhprr20//RStKVcT8Cu+SQtX18eMHLhjHf2yFzwtQ0S2f0jQ+89rokoNdmwoSqYzAhq86FxlLSQ==} + resolution: {integrity: sha1-KrDJx/MJj6SJB3cruBP+QejeOg4=} dependencies: babel-helper-builder-binary-assignment-operator-visitor: 6.24.1 babel-plugin-syntax-exponentiation-operator: 6.13.0 @@ -12415,13 +12384,13 @@ packages: dev: false /babel-plugin-transform-regenerator/6.26.0: - resolution: {integrity: sha512-LS+dBkUGlNR15/5WHKe/8Neawx663qttS6AGqoOUhICc9d1KciBvtrQSuc0PI+CxQ2Q/S1aKuJ+u64GtLdcEZg==} + resolution: {integrity: sha1-4HA2lvveJ/Cj78rPi03KL3s6jy8=} dependencies: regenerator-transform: 0.10.1 dev: false /babel-plugin-transform-strict-mode/6.24.1: - resolution: {integrity: sha512-j3KtSpjyLSJxNoCDrhwiJad8kw0gJ9REGj8/CqL0HeRyLnvUNYV9zcqluL6QJSXh3nfsLEmSLvwRfGzrgR96Pw==} + resolution: {integrity: sha1-1fr3qleKZbvlkc9e2uBKDGcCB1g=} dependencies: babel-runtime: 6.26.0 babel-types: 6.26.0 @@ -12502,7 +12471,7 @@ packages: dev: true /babel-register/6.26.0: - resolution: {integrity: sha512-veliHlHX06wjaeY8xNITbveXSiI+ASFnOqvne/LaIJIqOWi2Ogmj91KOugEz/hoh/fwMhXNBJPCv8Xaz5CyM4A==} + resolution: {integrity: sha1-btAhFz4vy0htestFxgCahW9kcHE=} dependencies: babel-core: 6.26.3 babel-runtime: 6.26.0 @@ -12516,14 +12485,14 @@ packages: dev: false /babel-runtime/6.26.0: - resolution: {integrity: sha512-ITKNuq2wKlW1fJg9sSW52eepoYgZBggvOAHC0u/CYu/qxQ9EVzThCgR69BnSXLHjy2f7SY5zaQ4yt7H9ZVxY2g==} + resolution: {integrity: sha1-llxwWGaOgrVde/4E/yM3vItWR/4=} dependencies: core-js: 2.6.12 regenerator-runtime: 0.11.1 dev: false /babel-template/6.26.0: - resolution: {integrity: sha512-PCOcLFW7/eazGUKIoqH97sO9A2UYMahsn/yRQ7uOk37iutwjq7ODtcTNF+iFDSHNfkctqsLRjLP7URnOx0T1fg==} + resolution: {integrity: sha1-3gPi0WOWsGn0bdn/+FIfsaDjXgI=} dependencies: babel-runtime: 6.26.0 babel-traverse: 6.26.0 @@ -12535,7 +12504,7 @@ packages: dev: false /babel-traverse/6.26.0: - resolution: {integrity: sha512-iSxeXx7apsjCHe9c7n8VtRXGzI2Bk1rBSOJgCCjfyXb6v1aCqE1KSEpq/8SXuVN8Ka/Rh1WDTF0MDzkvTA4MIA==} + resolution: {integrity: sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=} dependencies: babel-code-frame: 6.26.0 babel-messages: 6.23.0 @@ -12551,7 +12520,7 @@ packages: dev: false /babel-types/6.26.0: - resolution: {integrity: sha512-zhe3V/26rCWsEZK8kZN+HaQj5yQ1CilTObixFzKW1UWjqG7618Twz6YEsCnjfg5gBcJh02DrpCkS9h98ZqDY+g==} + resolution: {integrity: sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=} dependencies: babel-runtime: 6.26.0 esutils: 2.0.3 @@ -12560,7 +12529,7 @@ packages: dev: false /babelify/7.3.0: - resolution: {integrity: sha512-vID8Fz6pPN5pJMdlUnNFSfrlcx5MUule4k9aKs/zbZPyXxMTcRrB0M4Tarw22L8afr8eYSWxDPYCob3TdrqtlA==} + resolution: {integrity: sha1-qlau3nBn/XvVSWZu4W3ChQh+iOU=} dependencies: babel-core: 6.26.3 object-assign: 4.1.1 @@ -12717,7 +12686,7 @@ packages: file-uri-to-path: 1.0.0 /bintrees/1.0.2: - resolution: {integrity: sha512-VOMgTMwjAaUG580SXn3LacVgjurrbMme7ZZNYGSSV7mmtY6QQRh0Eg3pwIcntQ77DErK1L0NxkbetjcoXzVwKw==} + resolution: {integrity: sha1-SfiW1uhYpKSZ34XDj7OZua/4QPg=} dev: false /bip32/2.0.6: @@ -13054,8 +13023,8 @@ packages: resolution: {integrity: sha512-WHVocJYavUwVgVViC0ORikPHQquXwVh939TaelZ4WDqpWgTX/FsGhl/+P4qBUAGcRvtOgDgC+xftNWWp2RUTAQ==} hasBin: true dependencies: - caniuse-lite: 1.0.30001341 - electron-to-chromium: 1.4.137 + caniuse-lite: 1.0.30001332 + electron-to-chromium: 1.4.106 dev: false /browserslist/4.20.2: @@ -13172,7 +13141,7 @@ packages: node-gyp-build: 4.3.0 /builtin-modules/1.1.1: - resolution: {integrity: sha512-wxXCdllwGhI2kCC0MnvTGYTMvnVZTvqgypkiTI8Pa5tcz2i6VqsqwYGgqwXji+4RgCzms6EajE4IxiUH6HH8nQ==} + resolution: {integrity: sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=} engines: {node: '>=0.10.0'} dev: false @@ -13354,7 +13323,6 @@ packages: /caniuse-lite/1.0.30001332: resolution: {integrity: sha512-10T30NYOEQtN6C11YGg411yebhvpnC6Z102+B95eAsN0oB6KUs01ivE8u+G6FMIRtIrVlYXhL+LUwQ3/hXwDWw==} - dev: true /caniuse-lite/1.0.30001341: resolution: {integrity: sha512-2SodVrFFtvGENGCv0ChVJIDQ0KPaS1cg7/qtfMaICgeMolDdo/Z2OD32F0Aq9yl6F4YFwGPBS5AaPqNYiW4PoA==} @@ -13454,7 +13422,7 @@ packages: dev: false /checkpoint-store/1.1.0: - resolution: {integrity: sha512-J/NdY2WvIx654cc6LWSq/IYFFCUf75fFTgwzFnmbqyORH4MwgiQCgswLLKBGzmsyTI5V7i5bp/So6sMbDWhedg==} + resolution: {integrity: sha1-BOTLUWuRQziTWB5tRgGnjpVS6gY=} dependencies: functional-red-black-tree: 1.0.1 dev: false @@ -14913,6 +14881,7 @@ packages: /date-fns/2.28.0: resolution: {integrity: sha512-8d35hViGYx/QH0icHYCeLmsLmMUheMmTyV9Fcm6gvNwdw31yXXH+O85sOBJ+OLnLQMKZowvpKb6FgMIQjcpvQw==} engines: {node: '>=0.11'} + dev: false /debug/2.6.9: resolution: {integrity: sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==} @@ -15614,7 +15583,6 @@ packages: /electron-to-chromium/1.4.106: resolution: {integrity: sha512-ZYfpVLULm67K7CaaGP7DmjyeMY4naxsbTy+syVVxT6QHI1Ww8XbJjmr9fDckrhq44WzCrcC5kH3zGpdusxwwqg==} - dev: true /electron-to-chromium/1.4.137: resolution: {integrity: sha512-0Rcpald12O11BUogJagX3HsCN3FE83DSqWjgXoHo5a72KUKMSfI39XBgJpgNNxS9fuGzytaFjE06kZkiVFy2qA==} @@ -15937,10 +15905,9 @@ packages: object-inspect: 1.12.0 object-keys: 1.1.1 object.assign: 4.1.2 - string.prototype.trimend: 1.0.4 - string.prototype.trimstart: 1.0.4 - unbox-primitive: 1.0.1 - dev: true + string.prototype.trimend: 1.0.5 + string.prototype.trimstart: 1.0.5 + unbox-primitive: 1.0.2 /es-abstract/1.20.1: resolution: {integrity: sha512-WEm2oBhfoI2sImeM4OF2zE2V3BYdSF+KnSi9Sidz51fQHd7+JuF8Xgcj9/0o+OWeIeIS/MiuNnlruQrJf16GQA==} @@ -15969,6 +15936,7 @@ packages: string.prototype.trimend: 1.0.5 string.prototype.trimstart: 1.0.5 unbox-primitive: 1.0.2 + dev: true /es-array-method-boxes-properly/1.0.0: resolution: {integrity: sha512-wd6JXUmyHmt8T5a2xreUwKcGPq6f1f+WwIJkijUqiGcJz1qqnZgP6XIK+QyIWU5lT7imeNxUll48bziG+TSYcA==} @@ -17871,6 +17839,7 @@ packages: define-properties: 1.1.4 es-abstract: 1.20.1 functions-have-names: 1.2.3 + dev: true /functional-red-black-tree/1.0.1: resolution: {integrity: sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=} @@ -20837,8 +20806,8 @@ packages: resolution: {integrity: sha1-P02uSpH6wxX3EGL4UhzCOfE2YoA=} engines: {'0': node >= 0.2.0} - /jsonschema/1.4.1: - resolution: {integrity: sha512-S6cATIPVv1z0IlxdN+zUk5EPjkGCdnhN4wVSBlvoUO1tOLJootbo9CquNJmbIh4yikWHiUedhRYrNPn1arpEmQ==} + /jsonschema/1.4.0: + resolution: {integrity: sha512-/YgW6pRMr6M7C+4o8kS+B/2myEpHCrxO4PEWnqJNBFMjn7EWXqlQ4tGwL6xTHeRplwuZmcAncdvfOad1nT2yMw==} dev: false /jsprim/1.4.2: @@ -21419,6 +21388,7 @@ packages: engines: {node: '>=12'} dependencies: sourcemap-codec: 1.4.8 + dev: false /make-dir/2.1.0: resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==} @@ -25154,6 +25124,7 @@ packages: rollup: 2.73.0 optionalDependencies: '@babel/code-frame': 7.16.7 + dev: false /rollup-plugin-terser/7.0.2_rollup@2.73.0: resolution: {integrity: sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==} @@ -26380,7 +26351,7 @@ packages: dependencies: call-bind: 1.0.2 define-properties: 1.1.4 - es-abstract: 1.20.1 + es-abstract: 1.19.5 dev: false /string.prototype.trimend/1.0.4: @@ -26394,7 +26365,7 @@ packages: dependencies: call-bind: 1.0.2 define-properties: 1.1.4 - es-abstract: 1.20.1 + es-abstract: 1.19.5 /string.prototype.trimstart/1.0.4: resolution: {integrity: sha512-jh6e984OBfvxS50tdY2nRZnoC5/mLFKOREQfw8t5yytkoUsJRNxvI/E39qu1sD0OtWI3OC0XgKSmcWwziwYuZw==} @@ -26407,7 +26378,7 @@ packages: dependencies: call-bind: 1.0.2 define-properties: 1.1.4 - es-abstract: 1.20.1 + es-abstract: 1.19.5 /string_decoder/0.10.31: resolution: {integrity: sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=} @@ -26692,7 +26663,7 @@ packages: defined: 1.0.0 dotignore: 0.1.2 for-each: 0.3.3 - glob: 7.2.3 + glob: 7.2.0 has: 1.0.3 inherits: 2.0.4 is-regex: 1.1.4 @@ -27437,7 +27408,7 @@ packages: chalk: 2.4.2 commander: 2.20.3 diff: 4.0.2 - glob: 7.2.3 + glob: 7.2.0 js-yaml: 3.14.1 minimatch: 3.1.2 mkdirp: 0.5.6 @@ -27468,7 +27439,7 @@ packages: /tsutils/1.9.1_typescript@2.9.2: resolution: {integrity: sha1-ufmrROVa+WgYMdXyjQrur1x1DLA=} peerDependencies: - typescript: '>=2.0.0 || >=2.0.0-dev || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >= 2.4.0-dev' + typescript: '>=2.0.0 || >=2.0.0-dev || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >= 2.4.0-dev || 4' peerDependenciesMeta: typescript: optional: true @@ -27479,7 +27450,7 @@ packages: /tsutils/2.29.0_typescript@2.9.2: resolution: {integrity: sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==} peerDependencies: - typescript: '>=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >= 3.0.0-dev || >= 3.1.0-dev' + typescript: '>=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev || >=2.8.0-dev || >=2.9.0-dev || >= 3.0.0-dev || >= 3.1.0-dev || 4' peerDependenciesMeta: typescript: optional: true @@ -29970,7 +29941,7 @@ packages: ethereumjs-abi: github.com/ProjectWyvern/ethereumjs-abi/3d2d89641a6ad5984929b6ca4b646452ec74f73d ethereumjs-util: 5.2.1 json-loader: 0.5.7 - jsonschema: 1.4.1 + jsonschema: 1.4.0 lodash: 4.17.21 web3: 0.20.7 dev: false @@ -29995,7 +29966,7 @@ packages: ethereumjs-abi: github.com/ProjectWyvern/ethereumjs-abi/3d2d89641a6ad5984929b6ca4b646452ec74f73d ethereumjs-util: 5.2.1 json-loader: 0.5.7 - jsonschema: 1.4.1 + jsonschema: 1.4.0 lodash: 4.17.21 ts-node: 6.2.0 tslint: 5.20.1_typescript@2.9.2 diff --git a/tsconfig.json b/tsconfig.json index a01cc8449468..6b86438f9685 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,6 @@ { "path": "./packages/mask-sdk/main" }, { "path": "./packages/mask-sdk/public-api" }, { "path": "./packages/dashboard" }, - { "path": "./packages/provider-proxy" }, // Storybooks are considered as a "project" not depended by any other project { "path": "./packages/dashboard/stories" }, { "path": "./packages/theme/stories" }, @@ -70,7 +69,6 @@ "@masknet/mask-sdk": ["./packages/mask-sdk/server"], "@masknet/plugin-infra": ["./packages/plugin-infra/src"], "@masknet/global-types/*": ["./packages/polyfills/types/*"], - "@masknet/provider-proxy": ["./packages/provider-proxy/src"], "@masknet/public-api": ["./packages/public-api/src"], // @masknet/scripts is not listed. It does not mean to be installed as a dependency and not join the type check. "@masknet/shared": ["./packages/shared/src"], From c362be87b7c94e907f5bfe9b06cefe2b1238f52f Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 27 May 2022 16:03:51 +0800 Subject: [PATCH 08/17] chore: small changes --- .i18n-codegen.json | 63 ++++++++++++---------------------- docs/blockchain-integration.md | 4 +++ 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/.i18n-codegen.json b/.i18n-codegen.json index 6b40857beeb0..48fd89fd6a66 100644 --- a/.i18n-codegen.json +++ b/.i18n-codegen.json @@ -32,8 +32,7 @@ "type": "i18next/react-hooks", "hooks": "useSharedI18N", "namespace": "shared", - "trans": "SharedTrans", - "sourceMap": "inline" + "trans": "SharedTrans" } }, { @@ -44,8 +43,7 @@ "type": "i18next/react-hooks", "hooks": "useSharedBaseI18N", "namespace": "shareBase", - "trans": "SharedBaseTrans", - "sourceMap": "inline" + "trans": "SharedBaseTrans" } }, { @@ -56,8 +54,7 @@ "type": "i18next/react-hooks", "hooks": "useDashboardI18N", "namespace": "dashboard", - "trans": "DashboardTrans", - "sourceMap": "inline" + "trans": "DashboardTrans" } }, { @@ -68,8 +65,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "io.mask.example", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -80,8 +76,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "io.mask.debugger", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -92,8 +87,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.wallet", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -104,8 +98,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.mask.flow", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -116,8 +109,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.fileservice", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -128,8 +120,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.cyberconnect", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -140,8 +131,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "bio.rss3", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -152,8 +142,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "money.juicebox", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -164,8 +153,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.solana", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -176,8 +164,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.mask.next_id", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -188,8 +175,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "__template__", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -200,8 +186,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "io.gopluslabs.security", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -212,8 +197,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "io.mask.cross-chain-bridge", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -224,8 +208,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.red_packet", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -236,8 +219,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.tip", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -248,8 +230,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.avatar", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -260,8 +241,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.trader", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } }, { @@ -272,8 +252,7 @@ "type": "i18next/react-hooks", "hooks": "useI18N", "namespace": "com.maskbook.gitcoin", - "trans": "Translate", - "sourceMap": "inline" + "trans": "Translate" } } ] diff --git a/docs/blockchain-integration.md b/docs/blockchain-integration.md index 7b625e76c890..3e7fce495d56 100644 --- a/docs/blockchain-integration.md +++ b/docs/blockchain-integration.md @@ -1 +1,5 @@ # Blockchain Integration + +Mask Network assumes many capabilities that a blockchain should have. For example, a blockchain uses an "address" to locate a crypto-identity, a wallet keeps the crypto stuff safe from risk, and a "block" contains many transactions that push the system to the next state. + +The fundamental of blockchain is neutral. We could leverage it to do anything. However, a few years ago, people found financial usage from it and heavily developed it. As a result, almost all blockchains support "tokens" natively to proof of ownership. From 8e799ba899373090a28b472ee5499aae6b9a6ef5 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Fri, 27 May 2022 19:03:53 +0800 Subject: [PATCH 09/17] docs(i18n): sync i18n files from Crowdin (#6363) * New translations en-US.json (Japanese) docs(i18n): sync translation en-US.json for Japanese * New translations en-US.json (Chinese Simplified) docs(i18n): sync translation en-US.json for Chinese Simplified * New translations en-US.json (Quenya) docs(i18n): sync translation en-US.json for Quenya * New translations en-US.json (Quenya) docs(i18n): sync translation en-US.json for Quenya * New translations en-US.json (Chinese Simplified) docs(i18n): sync translation en-US.json for Chinese Simplified * New translations en-US.json (Chinese Simplified) docs(i18n): sync translation en-US.json for Chinese Simplified * New translations en-US.json (Korean) docs(i18n): sync translation en-US.json for Korean * New translations en-US.json (Quenya) docs(i18n): sync translation en-US.json for Quenya * New translations en-US.json (Chinese Traditional) docs(i18n): sync translation en-US.json for Chinese Traditional * New translations en-US.json (Chinese Simplified) docs(i18n): sync translation en-US.json for Chinese Simplified * New translations en-US.json (Quenya) docs(i18n): sync translation en-US.json for Quenya --- packages/mask/shared-ui/locales/ja-JP.json | 6 -- packages/mask/shared-ui/locales/ko-KR.json | 9 +- packages/mask/shared-ui/locales/qya-AA.json | 39 +++++---- packages/mask/shared-ui/locales/zh-CN.json | 15 ++-- packages/mask/shared-ui/locales/zh-TW.json | 8 +- .../src/plugins/Gitcoin/locales/qya-AA.json | 16 +++- .../src/plugins/Gitcoin/locales/zh-CN.json | 14 ++- .../src/plugins/RedPacket/locales/qya-AA.json | 85 ++++++++++++++++++- .../src/plugins/RedPacket/locales/zh-CN.json | 42 ++++++++- .../src/plugins/Trader/locales/qya-AA.json | 4 +- .../src/plugins/Trader/locales/zh-CN.json | 4 +- 11 files changed, 190 insertions(+), 52 deletions(-) diff --git a/packages/mask/shared-ui/locales/ja-JP.json b/packages/mask/shared-ui/locales/ja-JP.json index 118edbbc103a..9cd3090de974 100644 --- a/packages/mask/shared-ui/locales/ja-JP.json +++ b/packages/mask/shared-ui/locales/ja-JP.json @@ -104,14 +104,8 @@ "plugin_wallet_return_mobile_wallet_options": "モバイルウォレットのオプションに戻る", "plugin_wallet_view_qr_code": "QR コードを表示する", "plugin_red_packet_create_with_token": "{{symbol}} で投げ銭を作成する", - "plugin_gitcoin_readme": "このサービスを利用するにあたり、寄付金額の 5% が Gitcoin grants development fund に寄付されます", "plugin_gitcoin_select_a_token": "トークンを選択する", - "plugin_gitcoin_enter_an_amount": "量を決める", - "plugin_gitcoin_grant_not_available": "Grantは有効ではありません", "plugin_gitcoin_insufficient_balance": "{{symbol}} の残高が足りません", - "plugin_gitcoin_donate": "寄付する", - "plugin_gitcoin_last_updated": "最新の更新:", - "plugin_gitcoin_view_on": "Gitcoin で見る", "plugin_trader_swap": "スワップ", "plugin_trader_wrap": "ラップ", "plugin_trader_unwrap": "アンラップ", diff --git a/packages/mask/shared-ui/locales/ko-KR.json b/packages/mask/shared-ui/locales/ko-KR.json index b69cc4e22da5..6761f7a7923b 100644 --- a/packages/mask/shared-ui/locales/ko-KR.json +++ b/packages/mask/shared-ui/locales/ko-KR.json @@ -119,6 +119,7 @@ "wallet_rename": "월렛 이름 바꾸기", "wallet_loading_nft_contract": "NFT 컨트렉트 로딩...", "wallet_search_contract_no_result": "검색 포준에 맞추는 결과나 컨트렉트 주소가 없습니다.", + "wallet_search_no_result": "결과 없음.", "wallet_airdrop_nft_unclaimed_title": "수령하지 않는 NFT 에어드랍:", "plugin_airdrop_nft_start_time": "시작 시간: {{date}}", "plugin_airdrop_nft_end_time": "종료 시간: {{date}}", @@ -214,16 +215,8 @@ "plugin_wallet_cancel_sign": "서명이 실패되었습니다.", "plugin_red_packet_create_with_token": "{{symbol}} 으로 빨간 백 만드는 중", "plugin_red_packet_nft_account_name": "지갑 계정", - "plugin_gitcoin_readme": "이 서비스를 이용하면 Gitcoin 개발 기금에 당신의 기여금의 5%를 기부할 것이다.", - "plugin_gitcoin_readme_fund_link": "https://gitcoin.co/grants/86/gitcoin-sustainability-fund", "plugin_gitcoin_select_a_token": "토큰 선택", - "plugin_gitcoin_enter_an_amount": "수액 입력", - "plugin_gitcoin_grant_not_available": "이용 불가", "plugin_gitcoin_insufficient_balance": "{{symbol}} 잔액 부족", - "plugin_gitcoin_donate": "기부", - "plugin_gitcoin_last_updated": "신규 업데이트", - "plugin_gitcoin_by": "By", - "plugin_gitcoin_view_on": "Gitcoin에서 보기", "plugin_trader_safety_alert_title": "토큰 안정성 알림", "plugin_trader_safety_alert": "누구나 ERC20 토큰을 만들고 이름을 지을 수 있다. 토큰이 없는 프로젝트를 대표한다고 주장하는 토큰과 현존 토큰의 가짜 버전을 만드는 경우도 많습니다. Etherscan과 마찬가지로 이 사이트는 모든 ERC20 토큰에 대한 분석을 자동으로 추적합니다. ERC20 토큰과 상호 작용하기 전에 미리 잘 조사하시길 바랍니다.", "plugin_trader_total_supply": "총 공급량", diff --git a/packages/mask/shared-ui/locales/qya-AA.json b/packages/mask/shared-ui/locales/qya-AA.json index ecb471a7d0e4..d1e180adb87d 100644 --- a/packages/mask/shared-ui/locales/qya-AA.json +++ b/packages/mask/shared-ui/locales/qya-AA.json @@ -1,4 +1,11 @@ { + "promote_red_packet": "crwdns16898:0crwdne16898:0", + "promote_ito": "crwdns16900:0crwdne16900:0", + "promote_ito_short": "crwdns16902:0crwdne16902:0", + "promote_file_service": "crwdns16904:0crwdne16904:0", + "promote_savings": "crwdns16906:0{{amount}}crwdnd16906:0{{symbol}}crwdnd16906:0{{chain}}crwdnd16906:0{{account}}crwdne16906:0", + "promote_collectible": "crwdns16908:0crwdne16908:0", + "promote_snapshot": "crwdns16910:0crwdne16910:0", "database_backup": "crwdns10051:0crwdne10051:0", "database_overwrite": "crwdns10053:0crwdne10053:0", "database_clear": "crwdns10055:0crwdne10055:0", @@ -46,9 +53,13 @@ "application_settings_tab_plug_app-listed-placeholder": "crwdns16228:0crwdne16228:0", "application_settings_tab_plug_app-unlisted-placeholder": "crwdns16230:0crwdne16230:0", "additional_post_box__encrypted_post_pre": "crwdns3991:0{{encrypted}}crwdne3991:0", - "additional_post_box__encrypted_post_pre_red_packet_twitter_official_account": "crwdns9169:0{{account}}crwdnd9169:0{{encrypted}}crwdne9169:0", - "additional_post_box__encrypted_post_pre_red_packet": "crwdns3995:0{{encrypted}}crwdne3995:0", - "additional_post_box__steganography_post_pre": "crwdns3997:0{{random}}crwdne3997:0", + "additional_post_box__encrypted_post_pre_red_packet_twitter_official_account": "crwdns9169:0{{account}}crwdnd9169:0$t(promote_red_packet)crwdnd9169:0{{encrypted}}crwdne9169:0", + "additional_post_box__encrypted_post_pre_red_packet": "crwdns3995:0$t(promote_red_packet)crwdnd3995:0{{encrypted}}crwdne3995:0", + "additional_post_box__encrypted_post_pre_ito_twitter_official_account": "crwdns16912:0$t(promote_ito)crwdnd16912:0{{encrypted}}crwdne16912:0", + "additional_post_box__encrypted_post_pre_ito": "crwdns16914:0$t(promote_ito)crwdnd16914:0{{encrypted}}crwdne16914:0", + "additional_post_box__encrypted_post_pre_file_service_twitter_official_account": "crwdns16916:0$t(promote_file_service)crwdnd16916:0{{encrypted}}crwdne16916:0", + "additional_post_box__encrypted_post_pre_file_service": "crwdns16918:0$t(promote_file_service)crwdnd16918:0{{encrypted}}crwdne16918:0", + "additional_post_box__steganography_post_pre": "crwdns3997:0{{random}}crwdnd3997:0$t(promote_red_packet)crwdne3997:0", "auto_paste_failed_dialog_title": "crwdns3999:0crwdne3999:0", "auto_paste_failed_dialog_content": "crwdns4001:0crwdne4001:0", "auto_paste_failed_dialog_image_caption": "crwdns4003:0crwdne4003:0", @@ -133,6 +144,9 @@ "user_guide_tip_2": "crwdns9061:0crwdne9061:0", "user_guide_tip_3": "crwdns13019:0crwdne13019:0", "user_guide_tip_4": "crwdns16572:0crwdne16572:0", + "plugin_avatar_setup_share_title": "crwdns16920:0crwdne16920:0", + "plugin_avatar_setup_pfp_share": "crwdns16922:0crwdne16922:0", + "plugin_avatar_setup_success": "crwdns16924:0crwdne16924:0", "mask_network": "crwdns10321:0crwdne10321:0", "import": "crwdns4193:0crwdne4193:0", "no_search_result": "crwdns4217:0crwdne4217:0", @@ -186,6 +200,7 @@ "wallet_rename": "crwdns4489:0crwdne4489:0", "wallet_loading_nft_contract": "crwdns8135:0crwdne8135:0", "wallet_search_contract_no_result": "crwdns8137:0crwdne8137:0", + "wallet_search_no_result": "crwdns8139:0crwdne8139:0", "wallet_confirm_with_password": "crwdns10141:0crwdne10141:0", "wallet_airdrop_nft_unclaimed_title": "crwdns8093:0crwdne8093:0", "plugin_external_unknown_plugin": "crwdns10143:0crwdne10143:0", @@ -335,18 +350,8 @@ "plugin_nft_red_packet_create": "crwdns11875:0crwdne11875:0", "plugin_red_packet_nft_account_name": "crwdns8159:0crwdne8159:0", "plugin_red_packet_nft_shift_select_tip": "crwdns10819:0{{text}}crwdne10819:0", - "plugin_gitcoin_readme": "crwdns4789:0crwdne4789:0", - "plugin_gitcoin_readme_fund_link": "crwdns4791:0crwdne4791:0", "plugin_gitcoin_select_a_token": "crwdns4793:0crwdne4793:0", - "plugin_gitcoin_name": "crwdns16238:0crwdne16238:0", - "plugin_gitcoin_description": "crwdns16240:0crwdne16240:0", - "plugin_gitcoin_enter_an_amount": "crwdns4795:0crwdne4795:0", - "plugin_gitcoin_grant_not_available": "crwdns4797:0crwdne4797:0", "plugin_gitcoin_insufficient_balance": "crwdns4799:0{{symbol}}crwdne4799:0", - "plugin_gitcoin_donate": "crwdns4801:0crwdne4801:0", - "plugin_gitcoin_last_updated": "crwdns4803:0crwdne4803:0", - "plugin_gitcoin_by": "crwdns4805:0crwdne4805:0", - "plugin_gitcoin_view_on": "crwdns4807:0crwdne4807:0", "plugin_trader_fail_to_load": "crwdns10207:0crwdne10207:0", "plugin_trader_lbp_pool_in_balancer": "crwdns10209:0crwdne10209:0", "plugin_trader_swap_description": "crwdns16242:0crwdne16242:0", @@ -535,10 +540,10 @@ "plugin_ito_qualification_failed": "crwdns5139:0crwdne5139:0", "plugin_ito_congratulations": "crwdns5153:0crwdne5153:0", "plugin_ito_out_of_stock_hit": "crwdns5155:0crwdne5155:0", - "plugin_ito_claim_success_share": "crwdns5157:0{{user}}crwdnd5157:0{{account}}crwdnd5157:0{{symbol}}crwdnd5157:0{{link}}crwdne5157:0", - "plugin_ito_claim_success_share_no_official_account": "crwdns9179:0{{user}}crwdnd9179:0{{symbol}}crwdnd9179:0{{link}}crwdne9179:0", - "plugin_ito_claim_foreshow_share": "crwdns5159:0{{symbol}}crwdnd5159:0{{name}}crwdnd5159:0{{account}}crwdnd5159:0{{link}}crwdne5159:0", - "plugin_ito_claim_foreshow_share_no_official_account": "crwdns9181:0{{symbol}}crwdnd9181:0{{name}}crwdnd9181:0{{link}}crwdne9181:0", + "plugin_ito_claim_success_share": "crwdns5157:0{{user}}crwdnd5157:0{{account}}crwdnd5157:0{{symbol}}crwdnd5157:0$t(promote_ito_short)crwdnd5157:0{{link}}crwdne5157:0", + "plugin_ito_claim_success_share_no_official_account": "crwdns9179:0{{user}}crwdnd9179:0{{symbol}}crwdnd9179:0$t(promote_ito_short)crwdnd9179:0{{link}}crwdne9179:0", + "plugin_ito_claim_foreshow_share": "crwdns5159:0{{symbol}}crwdnd5159:0{{name}}crwdnd5159:0{{account}}crwdnd5159:0{{link}}crwdnd5159:0$t(promote_ito_short)crwdne5159:0", + "plugin_ito_claim_foreshow_share_no_official_account": "crwdns9181:0{{symbol}}crwdnd9181:0{{name}}crwdnd9181:0{{link}}crwdnd9181:0$t(promote_ito_short)crwdne9181:0", "plugin_ito_password": "crwdns5161:0{{password}}crwdne5161:0", "plugin_ito_status_no_start": "crwdns5163:0crwdne5163:0", "plugin_ito_status_ongoing": "crwdns5165:0crwdne5165:0", diff --git a/packages/mask/shared-ui/locales/zh-CN.json b/packages/mask/shared-ui/locales/zh-CN.json index 98ebee360881..a6ec9363bc23 100644 --- a/packages/mask/shared-ui/locales/zh-CN.json +++ b/packages/mask/shared-ui/locales/zh-CN.json @@ -1,4 +1,6 @@ { + "promote_red_packet": "🧧🧧🧧 尝试给你的好友发送代币或 NFTs 红包,分享此时的喜悦吧! 安装 Mask.io 发送你的第一个红包。", + "promote_file_service": "📃📃📃 尝试在推特上使用永久的、去中心化的文件存储功能。安装 Mask.io 上传并分享你的第一份永久的去中心化存储文件,由主流去中心化存储方案提供技术支持。", "database_backup": "备份数据库", "database_overwrite": "使用备份覆盖数据库", "database_clear": "清空数据库", @@ -38,6 +40,10 @@ "additional_post_box__encrypted_post_pre": "安装 #mask_io 解密此贴文 ! {{encrypted}}", "additional_post_box__encrypted_post_pre_red_packet_twitter_official_account": "使用 #mask_io 来认领这个红包!@{{account}} {{encrypted}}", "additional_post_box__encrypted_post_pre_red_packet": "使用 #mask_io 来认领这个红包!@{{encrypted}}", + "additional_post_box__encrypted_post_pre_ito_twitter_official_account": "$t(promote_ito)\n {{encrypted}}", + "additional_post_box__encrypted_post_pre_ito": "$t(promote_ito) {{encrypted}}", + "additional_post_box__encrypted_post_pre_file_service_twitter_official_account": "$t(promote_file_service)\n {{encrypted}}", + "additional_post_box__encrypted_post_pre_file_service": "$t(promote_file_service) {{encrypted}}", "additional_post_box__steganography_post_pre": "此图片使用#mask_io加密。📪🔑 安装mask.io解密它。 {{random}}", "auto_paste_failed_dialog_title": "手动粘贴", "auto_paste_failed_dialog_content": "请复制下面的文本和图片(如果有的话)再进行发布。", @@ -157,6 +163,7 @@ "wallet_rename": "重新命名钱包", "wallet_loading_nft_contract": "正在加载 NFT 合约...", "wallet_search_contract_no_result": "没有结果或合同地址不符合查询标准。", + "wallet_search_no_result": "没有任何结果。", "wallet_confirm_with_password": "使用密码确认", "wallet_airdrop_nft_unclaimed_title": "未认领的NFT Airdrop:", "plugin_external_unknown_plugin": "发现新的未知Mask插件,您想要加载它们吗?", @@ -293,16 +300,8 @@ "plugin_nft_red_packet_create": "创建一个NFT红包", "plugin_red_packet_nft_account_name": "钱包账户", "plugin_red_packet_nft_shift_select_tip": "您也可以使用 {{text}} 选择多个NFT。", - "plugin_gitcoin_readme": "通过使用此服务,您将同时向 Gitcoin grants development fund 捐赠您5%捐款。", - "plugin_gitcoin_readme_fund_link": "https://gitcoin.co/gitcoin-sustainability-fund", "plugin_gitcoin_select_a_token": "选择代币", - "plugin_gitcoin_enter_an_amount": "输入数额", - "plugin_gitcoin_grant_not_available": "授权不可用", "plugin_gitcoin_insufficient_balance": "{{symbol}} 余额不足", - "plugin_gitcoin_donate": "捐赠", - "plugin_gitcoin_last_updated": "最新更新:", - "plugin_gitcoin_by": "提供者为:", - "plugin_gitcoin_view_on": "在 Gitcoin 上查看", "plugin_trader_fail_to_load": "无法加载趋势信息自 ", "plugin_trader_lbp_pool_in_balancer": "Balancer 的 LBP 池", "plugin_trader_tutorial": "教程", diff --git a/packages/mask/shared-ui/locales/zh-TW.json b/packages/mask/shared-ui/locales/zh-TW.json index 227d7a9a385e..1a335c4501db 100644 --- a/packages/mask/shared-ui/locales/zh-TW.json +++ b/packages/mask/shared-ui/locales/zh-TW.json @@ -98,6 +98,7 @@ "wallet_name": "錢包名稱", "wallet_rename": "重新命名錢包", "wallet_loading_nft_contract": "加載NFT合約中...", + "wallet_search_no_result": "無結果", "wallet_confirm_with_password": "確認密碼", "wallet_airdrop_nft_unclaimed_title": "尚未認領的NFT空投", "plugin_external_loader_search_holder": "搜尋外部插件", @@ -197,15 +198,8 @@ "plugin_wallet_not_available_on": "{{network}} 不可用", "plugin_wallet_connect_wallet": "連接錢包", "plugin_red_packet_create_with_token": "使用 {{symbol}} 建立紅包", - "plugin_gitcoin_readme": "通過使用此服務,您還將向 Gitcoin grants development fund 捐款 5%", "plugin_gitcoin_select_a_token": "選擇一個代幣", - "plugin_gitcoin_enter_an_amount": "輸入一個金額", - "plugin_gitcoin_grant_not_available": "Grant 無法使用", "plugin_gitcoin_insufficient_balance": "{{symbol}} 餘額不足", - "plugin_gitcoin_donate": "捐款", - "plugin_gitcoin_last_updated": "最近更新:", - "plugin_gitcoin_by": "提供者為", - "plugin_gitcoin_view_on": "在 Gitcoin 觀看", "plugin_trader_tutorial": "新手教學", "plugin_trader_safety_agree": "我瞭解", "plugin_trader_total_supply": "供應總量", diff --git a/packages/mask/src/plugins/Gitcoin/locales/qya-AA.json b/packages/mask/src/plugins/Gitcoin/locales/qya-AA.json index 0967ef424bce..d9c126e1cd08 100644 --- a/packages/mask/src/plugins/Gitcoin/locales/qya-AA.json +++ b/packages/mask/src/plugins/Gitcoin/locales/qya-AA.json @@ -1 +1,15 @@ -{} +{ + "name": "crwdns16706:0crwdne16706:0", + "description": "crwdns16708:0crwdne16708:0", + "promote": "crwdns16710:0crwdne16710:0", + "select_a_token": "crwdns16712:0crwdne16712:0", + "grant_not_available": "crwdns16714:0crwdne16714:0", + "enter_an_amount": "crwdns16716:0crwdne16716:0", + "insufficient_balance": "crwdns16718:0{{symbol}}crwdne16718:0", + "gitcoin_readme": "crwdns16720:0crwdne16720:0", + "donate": "crwdns16722:0crwdne16722:0", + "last_updated": "crwdns16724:0crwdne16724:0", + "by": "crwdns16726:0crwdne16726:0", + "view_on": "crwdns16728:0crwdne16728:0", + "readme_fund_link": "crwdns16730:0crwdne16730:0" +} diff --git a/packages/mask/src/plugins/Gitcoin/locales/zh-CN.json b/packages/mask/src/plugins/Gitcoin/locales/zh-CN.json index 0967ef424bce..2696e58e5e38 100644 --- a/packages/mask/src/plugins/Gitcoin/locales/zh-CN.json +++ b/packages/mask/src/plugins/Gitcoin/locales/zh-CN.json @@ -1 +1,13 @@ -{} +{ + "name": "Gitcoin", + "promote": "分享或浏览曾经捐助过或感兴趣的 Gitcoin 项目。", + "select_a_token": "选择代币", + "grant_not_available": "授权不可用", + "enter_an_amount": "输入数额", + "gitcoin_readme": "通过使用此服务,您将同时向 Gitcoin grants development fund 捐赠您5%捐款。", + "donate": "捐赠", + "last_updated": "最新更新:", + "by": "提供者为:", + "view_on": "在 Gitcoin 上查看", + "readme_fund_link": "https://gitcoin.co/grants/86/gitcoin-sustainability-fund" +} diff --git a/packages/mask/src/plugins/RedPacket/locales/qya-AA.json b/packages/mask/src/plugins/RedPacket/locales/qya-AA.json index 0967ef424bce..0dec9e1e3e55 100644 --- a/packages/mask/src/plugins/RedPacket/locales/qya-AA.json +++ b/packages/mask/src/plugins/RedPacket/locales/qya-AA.json @@ -1 +1,84 @@ -{} +{ + "promote": "crwdns16732:0crwdne16732:0", + "promote_short": "crwdns16734:0crwdne16734:0", + "nft_shift_select_tip": "crwdns16736:0{{text}}crwdne16736:0", + "collections": "crwdns16738:0crwdne16738:0", + "select_a_token": "crwdns16740:0crwdne16740:0", + "search": "crwdns16742:0crwdne16742:0", + "loading_token": "crwdns16744:0crwdne16744:0", + "search_no_result": "crwdns16746:0crwdne16746:0", + "nft_already_added": "crwdns16748:0crwdne16748:0", + "nft_invalid_owner": "crwdns16750:0crwdne16750:0", + "nft_max_shares": "crwdns16752:0{{amount}}crwdne16752:0", + "nft_max_shares_tip": "crwdns16754:0{{amount, number}}crwdne16754:0", + "nft_non_existed_tip": "crwdns16756:0crwdne16756:0", + "nft_select_collection": "crwdns16758:0crwdne16758:0", + "completed": "crwdns16760:0crwdne16760:0", + "expired": "crwdns16762:0crwdne16762:0", + "nft_tip": "crwdns16764:0crwdne16764:0", + "nft_share_foreshow_message_not_twitter": "crwdns16766:0{{sender}}crwdnd16766:0{{network}}crwdnd16766:0{{payload}}crwdne16766:0", + "nft_share_foreshow_message": "crwdns16768:0{{sender}}crwdnd16768:0{{network}}crwdnd16768:0{{account}}crwdnd16768:0{{payload}}crwdne16768:0", + "nft_share_claimed_message_not_twitter": "crwdns16770:0{{sender}}crwdnd16770:0{{network}}crwdnd16770:0$t(promote_short)crwdnd16770:0{{payload}}crwdne16770:0", + "nft_share_claimed_message": "crwdns16772:0{{sender}}crwdnd16772:0{{network}}crwdnd16772:0{{account}}crwdnd16772:0$t(promote_short)crwdnd16772:0{{payload}}crwdne16772:0", + "nft_total_amount": "crwdns16774:0crwdne16774:0", + "nft_attached_message": "crwdns16776:0crwdne16776:0", + "nft_account_name": "crwdns16778:0crwdne16778:0", + "message_label": "crwdns16780:0crwdne16780:0", + "claiming": "crwdns16782:0crwdne16782:0", + "claim": "crwdns16784:0crwdne16784:0", + "data_broken": "crwdns16786:0{{duration}}crwdne16786:0", + "refund": "crwdns16788:0crwdne16788:0", + "empty": "crwdns16790:0crwdne16790:0", + "refunding": "crwdns16792:0crwdne16792:0", + "history_send": "crwdns16794:0crwdne16794:0", + "history_total_amount": "crwdns16796:0{{amount}}crwdnd16796:0{{symbol}}crwdne16796:0", + "history_split_mode": "crwdns16798:0{{mode}}crwdne16798:0", + "history_total_claimed_amount": "crwdns16800:0{{claimedAmount}}crwdnd16800:0{{amount}}crwdnd16800:0{{symbol}}crwdne16800:0", + "attached_message": "crwdns16802:0crwdne16802:0", + "indivisible": "crwdns16804:0{{amount}}crwdnd16804:0{{symbol}}crwdne16804:0", + "name": "crwdns16806:0crwdne16806:0", + "description": "crwdns16808:0crwdne16808:0", + "next": "crwdns16810:0crwdne16810:0", + "nft_approve_all_tip": "crwdns16812:0crwdne16812:0", + "nft_unapproved_tip": "crwdns16814:0crwdne16814:0", + "nft_select_partially_option": "crwdns16816:0crwdne16816:0", + "nft_select_all_option": "crwdns16818:0{{total}}crwdne16818:0", + "erc721_insufficient_balance": "crwdns16820:0crwdne16820:0", + "erc721_tab_title": "crwdns16822:0crwdne16822:0", + "erc20_tab_title": "crwdns16824:0crwdne16824:0", + "claimed": "crwdns16826:0crwdne16826:0", + "details": "crwdns16828:0crwdne16828:0", + "display_name": "crwdns16830:0crwdne16830:0", + "select_existing": "crwdns16832:0crwdne16832:0", + "create_new": "crwdns16834:0crwdne16834:0", + "send_symbol": "crwdns16836:0{{amount}}crwdnd16836:0{{symbol}}crwdne16836:0", + "back": "crwdns16838:0crwdne16838:0", + "hint": "crwdns16840:0crwdne16840:0", + "amount_total": "crwdns16842:0crwdne16842:0", + "amount_per_share": "crwdns16844:0crwdne16844:0", + "shares": "crwdns16846:0crwdne16846:0", + "average": "crwdns16848:0crwdne16848:0", + "random": "crwdns16850:0crwdne16850:0", + "split_mode": "crwdns16852:0crwdne16852:0", + "token": "crwdns16854:0crwdne16854:0", + "chain_not_supported": "crwdns16856:0{{chain}}crwdne16856:0", + "nft_no_history": "crwdns16858:0crwdne16858:0", + "history_claimed": "crwdns16860:0{{claimedShares}}crwdnd16860:0{{shares}}crwdne16860:0", + "send": "crwdns16862:0crwdne16862:0", + "history_duration": "crwdns16864:0{{startTime}}crwdnd16864:0{{endTime}}crwdne16864:0", + "best_wishes": "crwdns16866:0crwdne16866:0", + "nft_data_broken": "crwdns16868:0crwdne16868:0", + "from": "crwdns16870:0{{name}}crwdne16870:0", + "share_message_official_account": "crwdns16872:0{{sender}}crwdnd16872:0{{network}}crwdnd16872:0{{account}}crwdnd16872:0$t(promote_short)crwdnd16872:0{{payload}}crwdne16872:0", + "share_message_not_twitter": "crwdns16874:0{{sender}}crwdnd16874:0{{network}}crwdnd16874:0$t(promote_short)crwdnd16874:0{{payload}}crwdne16874:0", + "share_unclaimed_message_official_account": "crwdns16876:0{{sender}}crwdnd16876:0{{network}}crwdnd16876:0{{account}}crwdnd16876:0$t(promote_short)crwdnd16876:0{{payload}}crwdne16876:0", + "share_unclaimed_message_not_twitter": "crwdns16878:0{{sender}}crwdnd16878:0{{network}}crwdnd16878:0$t(promote_short)crwdnd16878:0{{payload}}crwdne16878:0", + "description_claimed": "crwdns16880:0{{amount}}crwdnd16880:0{{symbol}}crwdne16880:0", + "description_refund": "crwdns16882:0{{balance}}crwdnd16882:0{{symbol}}crwdne16882:0", + "description_refunded": "crwdns16884:0crwdne16884:0", + "description_expired": "crwdns16886:0crwdne16886:0", + "description_broken": "crwdns16888:0crwdne16888:0", + "description_empty": "crwdns16890:0crwdne16890:0", + "description_failover": "crwdns16892:0{{shares}}crwdnd16892:0{{total}}crwdnd16892:0{{symbol}}crwdne16892:0", + "recommend_feature_description": "crwdns16894:0crwdne16894:0" +} diff --git a/packages/mask/src/plugins/RedPacket/locales/zh-CN.json b/packages/mask/src/plugins/RedPacket/locales/zh-CN.json index 0967ef424bce..2a91a240c6f2 100644 --- a/packages/mask/src/plugins/RedPacket/locales/zh-CN.json +++ b/packages/mask/src/plugins/RedPacket/locales/zh-CN.json @@ -1 +1,41 @@ -{} +{ + "collections": "收藏品", + "select_a_token": "选择代币", + "nft_max_shares": "NFT红包合约最多支持 {{amount}} 个NFT投放。", + "nft_max_shares_tip": "NFT红包合约最多支持 {{amount, number}} 个NFT投放。", + "nft_non_existed_tip": "Token ID 不存在或不属于您。", + "nft_select_collection": "选择您的收藏品系列", + "completed": "已完成", + "expired": "已过期", + "nft_tip": "这是一个 NFT 红包。", + "nft_share_foreshow_message_not_twitter": "@{{sender}} 正在 {{network}} 网络上发送一个 NFT 红包。 \n{{payload}}", + "nft_share_foreshow_message": "@{{sender}} 正在 {{network}} 网络上发送一个 NFT 红包。关注@{{account}} (mask.io) 以获取NFT 红包。\n#mask_io #LuckyDrop\n{{payload}}", + "nft_share_claimed_message_not_twitter": "我刚从@{{sender}} 在 {{network}} 网络上认领了一个 NFT 红包。\n$t(promote_short)\n{{payload}}", + "nft_share_claimed_message": "我刚从@{{sender}} 在 {{network}} 网络上认领了一个 NFT 红包。关注@{{account}} (mask.io) 来获取红包。\n$t(promote_short)\n#mask_io #LuckyDrop\n{{payload}}", + "nft_total_amount": "总数", + "nft_attached_message": "附加信息", + "nft_account_name": "钱包账户", + "message_label": "标题", + "claiming": "认领中...", + "claim": "认领", + "data_broken": "由于数据损坏,此红包无法发送。请在 {{duration}} 之后申请退款。", + "refund": "退款", + "empty": "空的", + "refunding": "退款中", + "history_send": "发送", + "history_total_amount": "总额: {{amount}} {{symbol}}", + "history_split_mode": "分享模式:{{mode}}", + "history_total_claimed_amount": "总额: {{claimedAmount}}/{{amount}} {{symbol}}", + "attached_message": "附加信息", + "indivisible": "每个份额的最小金额为 {{amount}} {{symbol}}", + "next": "下一步", + "nft_approve_all_tip": "注意:在选择批准所有NFT时,合约中的所有NFT都将被授权默认销售,包括随后转移的NFT。", + "nft_select_partially_option": "选择部分", + "nft_select_all_option": "全部 ({{total}} NFT)", + "erc721_insufficient_balance": "余额不足", + "erc721_tab_title": "收藏品", + "erc20_tab_title": "代币", + "claimed": "已认领", + "details": "红包详情", + "display_name": "插件:红包" +} diff --git a/packages/mask/src/plugins/Trader/locales/qya-AA.json b/packages/mask/src/plugins/Trader/locales/qya-AA.json index 0967ef424bce..6261786979e0 100644 --- a/packages/mask/src/plugins/Trader/locales/qya-AA.json +++ b/packages/mask/src/plugins/Trader/locales/qya-AA.json @@ -1 +1,3 @@ -{} +{ + "promote": "crwdns16896:0crwdne16896:0" +} diff --git a/packages/mask/src/plugins/Trader/locales/zh-CN.json b/packages/mask/src/plugins/Trader/locales/zh-CN.json index 0967ef424bce..9666697afc42 100644 --- a/packages/mask/src/plugins/Trader/locales/zh-CN.json +++ b/packages/mask/src/plugins/Trader/locales/zh-CN.json @@ -1 +1,3 @@ -{} +{ + "promote": "在推特上即可完成加密货币的即时互换。安装 Mask.io ,尝试快速、低费用的代币互换功能。" +} From a3b50101d6b46e91c9ae6455687a5ab40d37b297 Mon Sep 17 00:00:00 2001 From: Jack Works Date: Sun, 29 May 2022 14:26:11 +0800 Subject: [PATCH 10/17] docs(i18n): sync i18n files from Crowdin (#6372) * New translations en-US.json (Chinese Traditional) docs(i18n): sync translation en-US.json for Chinese Traditional * New translations en-US.json (Korean) docs(i18n): sync translation en-US.json for Korean * New translations en-US.json (Chinese Traditional) docs(i18n): sync translation en-US.json for Chinese Traditional * New translations en-US.json (Japanese) docs(i18n): sync translation en-US.json for Japanese --- .../src/plugins/Gitcoin/locales/ja-JP.json | 11 +++++++- .../src/plugins/Gitcoin/locales/ko-KR.json | 11 +++++++- .../src/plugins/Gitcoin/locales/zh-TW.json | 11 +++++++- .../src/plugins/RedPacket/locales/zh-TW.json | 27 ++++++++++++++++++- 4 files changed, 56 insertions(+), 4 deletions(-) diff --git a/packages/mask/src/plugins/Gitcoin/locales/ja-JP.json b/packages/mask/src/plugins/Gitcoin/locales/ja-JP.json index 0967ef424bce..aa9fe6ef67b7 100644 --- a/packages/mask/src/plugins/Gitcoin/locales/ja-JP.json +++ b/packages/mask/src/plugins/Gitcoin/locales/ja-JP.json @@ -1 +1,10 @@ -{} +{ + "select_a_token": "トークンを選択する", + "grant_not_available": "Grantは有効ではありません", + "enter_an_amount": "量を決める", + "insufficient_balance": "{{symbol}} の残高が足りません", + "gitcoin_readme": "このサービスを利用するにあたり、寄付金額の 5% が Gitcoin grants development fund に寄付されます", + "donate": "寄付する", + "last_updated": "最新の更新:", + "view_on": "Gitcoin で見る" +} diff --git a/packages/mask/src/plugins/Gitcoin/locales/ko-KR.json b/packages/mask/src/plugins/Gitcoin/locales/ko-KR.json index 0967ef424bce..a6abcd5bad82 100644 --- a/packages/mask/src/plugins/Gitcoin/locales/ko-KR.json +++ b/packages/mask/src/plugins/Gitcoin/locales/ko-KR.json @@ -1 +1,10 @@ -{} +{ + "select_a_token": "토큰 선택", + "grant_not_available": "이용 불가", + "enter_an_amount": "수액 입력", + "insufficient_balance": "{{symbol}} 잔액 부족", + "gitcoin_readme": "이 서비스를 이용하면 Gitcoin 개발 기금에 당신의 기여금의 5%를 기부할 것이다.", + "donate": "기부", + "last_updated": "신규 업데이트", + "view_on": "Gitcoin에서 보기" +} diff --git a/packages/mask/src/plugins/Gitcoin/locales/zh-TW.json b/packages/mask/src/plugins/Gitcoin/locales/zh-TW.json index 0967ef424bce..c5292c692f0f 100644 --- a/packages/mask/src/plugins/Gitcoin/locales/zh-TW.json +++ b/packages/mask/src/plugins/Gitcoin/locales/zh-TW.json @@ -1 +1,10 @@ -{} +{ + "select_a_token": "選擇一個代幣", + "enter_an_amount": "輸入一個金額", + "insufficient_balance": "{{symbol}} 餘額不足", + "gitcoin_readme": "通過使用此服務,您還將向 Gitcoin grants development fund 捐款 5%", + "donate": "捐款", + "last_updated": "最近更新:", + "by": "提供者為", + "view_on": "在 Gitcoin 觀看" +} diff --git a/packages/mask/src/plugins/RedPacket/locales/zh-TW.json b/packages/mask/src/plugins/RedPacket/locales/zh-TW.json index 0967ef424bce..2e881836d62f 100644 --- a/packages/mask/src/plugins/RedPacket/locales/zh-TW.json +++ b/packages/mask/src/plugins/RedPacket/locales/zh-TW.json @@ -1 +1,26 @@ -{} +{ + "search": "搜尋", + "nft_already_added": "此收藏品已被添加", + "nft_invalid_owner": "此藏品不屬於你", + "completed": "已完成", + "expired": "已過期", + "nft_tip": "這是一個NFT紅包", + "nft_total_amount": "總額", + "nft_attached_message": "附加的訊息", + "message_label": "標題", + "claiming": "認領中...", + "claim": "認領", + "refund": "退款", + "empty": "空的", + "refunding": "退款中", + "history_send": "發送", + "history_total_amount": "總額: {{amount}} {{symbol}}", + "history_split_mode": "分割模式: {{mode}}", + "history_total_claimed_amount": "總共: {{claimedAmount}}/{{amount}} {{symbol}}", + "attached_message": "附加的訊息", + "next": "下一步", + "erc721_insufficient_balance": "餘額不足", + "erc20_tab_title": "代幣", + "claimed": "已領取", + "details": "紅包詳情" +} From 4d6a74c1dc543952ab7d82e5f278d1aefade47e1 Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Sun, 29 May 2022 17:00:21 +0800 Subject: [PATCH 11/17] doc: add RPC endpoint --- .github/ISSUE_TEMPLATE/evm.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/evm.md b/.github/ISSUE_TEMPLATE/evm.md index 89ecabfdd35f..e7298aaae56a 100644 --- a/.github/ISSUE_TEMPLATE/evm.md +++ b/.github/ISSUE_TEMPLATE/evm.md @@ -12,11 +12,12 @@ Request to depoly contracts on . ## Chain Info -| Name | Content | -| ---- | ------- | -| Name | \- | -| ChainId | \- | -| Website | \- | +| Name | Content | +| ------------ | ------- | +| Name | \- | +| ChainId | \- | +| Website | \- | +| RPC Endponit | \- | ## Checklist From c109b878fd6da9b9c51505cc4b0244d2b5ee24fc Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Sun, 29 May 2022 22:05:27 +0800 Subject: [PATCH 12/17] refactor: transfer docs/ to docs.mask.io (#6314) --- docs/ARCHITECTURE.md | 53 ------- docs/FAQ.md | 103 ------------ docs/blockchain-integration.md | 5 - docs/bounty-development-guide.md | 74 --------- docs/concepts.md | 21 --- docs/css-in-js.md | 104 ------------- docs/dependencies.md | 8 - docs/evm-integration.md | 122 --------------- docs/failed-checklist.md | 15 -- docs/form-guide.md | 104 ------------- docs/i18n-guide.md | 22 --- docs/local-or-remote-dialog.md | 71 --------- docs/mask-flavored-jsonrpc-api.md | 113 -------------- docs/npm-scope.md | 9 -- docs/payload-format/payload-container.md | 32 ---- docs/payload-format/payload-v37.md | 189 ----------------------- docs/payload-format/typed-message.md | 121 --------------- docs/plugin-development-guide.md | 92 ----------- docs/plugin-development-quickstart.md | 31 ---- docs/setup.md | 104 ------------- docs/toc.md | 59 ------- docs/wallet-integration.md | 105 ------------- 22 files changed, 1557 deletions(-) delete mode 100644 docs/ARCHITECTURE.md delete mode 100644 docs/FAQ.md delete mode 100644 docs/blockchain-integration.md delete mode 100644 docs/bounty-development-guide.md delete mode 100644 docs/concepts.md delete mode 100644 docs/css-in-js.md delete mode 100644 docs/dependencies.md delete mode 100644 docs/evm-integration.md delete mode 100644 docs/failed-checklist.md delete mode 100644 docs/form-guide.md delete mode 100644 docs/i18n-guide.md delete mode 100644 docs/local-or-remote-dialog.md delete mode 100644 docs/mask-flavored-jsonrpc-api.md delete mode 100644 docs/npm-scope.md delete mode 100644 docs/payload-format/payload-container.md delete mode 100644 docs/payload-format/payload-v37.md delete mode 100644 docs/payload-format/typed-message.md delete mode 100644 docs/plugin-development-guide.md delete mode 100644 docs/plugin-development-quickstart.md delete mode 100644 docs/setup.md delete mode 100644 docs/toc.md delete mode 100644 docs/wallet-integration.md diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md deleted file mode 100644 index e9c4c414a9c4..000000000000 --- a/docs/ARCHITECTURE.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -author: Jack-Works -maintainer: - - Jack-Works - - Septs ---- - -# Mask Network Architecture Overview - -![WIP](https://img.shields.io/badge/status-wip-orange.svg?style=flat-square) - -> This document describes the Mask Network protocols, the subsystems, -> the interfaces, and how it all fits together. -> It delegates non-interface details to other specs as much as possible. -> This is meant as a top-level view of the protocol and how the system fits together. - -## Subsystems - -### Background service - -The entry point is `packages/mask/src/background-service.ts` - -Background service is like a "backend" or "server" in a normal web app. -It is running on a web page that not visible to the user ([background page in Web Extensions][background-page]). -The background page hosts mosts of our non-UI-related work in the Mask Network. If you see code like - -[background-page]: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Anatomy_of_a_WebExtension#background_scripts - -```js -Services.Crypto.encrypt(...) -``` - -It is sending the request to the background service. - -### Content scripts - -The entry point is `packages/mask/src/content-script.ts`. - -All UI on the Twitter/Facebook are rendered by the content scripts. - -### Options page (or Dashboard) - -The entry point is `packages/mask/src/extension/options-page/index.tsx`. - -This is a normal web app that interacts with the background page. - -### Injected scripts - -The entry point is `packages/mask/src/extension/injected-script/index.ts`. - -Generally, you don't need to modify this. It provides the ability to change the main Realm of the web page. (Thus we can emulate some DOM events). - -![Architecture overview](https://user-images.githubusercontent.com/5390719/109270562-28f4a700-7849-11eb-9a7a-b364318bdeec.png) diff --git a/docs/FAQ.md b/docs/FAQ.md deleted file mode 100644 index 543bef8d0847..000000000000 --- a/docs/FAQ.md +++ /dev/null @@ -1,103 +0,0 @@ -# FAQ - -## How to resolve merge conflicts in `pnpm-lock.yaml`? - -Merge the target branch into yours and never mind those conflicts in `pnpm-lock.yaml`. And checkout the file to be the one on the target branch to revert changes your branch took in. Then run `pnpm install` to up the lockfile to date. - -E.g., your `feat/fantasy` branch conflicts with `develop` branch. - -```bash -> git branch --show-current -feat/fantasy - -# merge the develop branch and never manually handle the conflicts in lock file -> git merge develop - -# check out the lock file from the base branch -> git checkout develop -- pnpm-lock.yaml - -# up the lockfile to date -> pnpm install -``` - -## Why my Git hooks don't work? - -```bash -npx husky install # on project root directory -``` - -## How to fix cspell errors in CI? - -This project uses [cspell](https://github.com/streetsidesoftware/cspell) for checking typos. You can add unlisted words into `cspell.json` to bypass cspell checking. After you update the configuration file, you could run checking locally before pushing it to make sure your patch is working. - -```bash -npx cspell lint pattern_that_match_your_files - -# e.g. check spell of the RSS3 plugin -npx cspell lint ./packages/plugins/RSS3/**/* -``` - -Learn more: [`cspell.json`](https://cspell.org/configuration/#cspelljson) - -## Why were my components rendered many times? - -All components should working in [Strict Mode](https://reactjs.org/docs/strict-mode.html) and React 18 new [Strict Effects](https://github.com/reactwg/react-18/discussions/19). - -If you found your code not working correctly, please read the documentation above. In addition, you can comment out `` temporarily to verify if it is a problem with your component not supporting Strict Mode. - -DO NOT remove ``. - -## How to download CI builds? - -| Name | Description | -| ----------------------------- | ----------------------------------------------------------------------- | -| MaskNetwork.base.zip | The default build, currently is the same as the Chromium build. | -| MaskNetwork.chromium-beta.zip | Build for Chromium based browsers with some insider features turned on. | -| MaskNetwork.chromium.zip | Build for Chromium based browsers | -| MaskNetwork.firefox.zip | Build for Firefox | -| MaskNetwork.gecko.zip | Build for Android native Mask app | -| MaskNetwork.iOS.zip | Build for iOS native Mask app | - -You can download these builds in two places. - -- Github: Open the pull request page, and click the **Actions** tab. Then on the opened page, click the **build** sub-item on the **Compile** item. On the action detailed page, click the **Summary** tab. Now you can download builds on the **Artifacts** section. - - E.g., - -- CircleCI: Open the pull request page, and scroll down to the review status card. Click **Show all checks** to find the ** - ci/circleci: build** item, and click the **details** link. On the opened CircleCI page, click the **ARTIFACTS** tab. - - E.g., - -## How to resolve "No CORS Headers" problem - -Please contact the service maintainer to add CORS headers, the extension will send requests in following origins: - -| Browser | Origin | -| -------- | --------------------------------------------------- | -| Chromium | chrome-extension://jkoeaghipilijlahjplgbfiocjhldnap | -| Firefox | moz-extension://id | - -The Chromium extension has a fixed id, but only on production mode. And the Firefox browser will set a new id each time it boots an extension. So, in summary, it's better to allow all origins which match the regexp below. - -```txt -/.*-extension:\/\/[^\S]+/ -``` - -If you cannot reach the service maintainer another workaround is to use a proxy server to add CORS headers. To enable it try to change the request URL into `https://cors.r2d2.to/?=[url]`. - -```ts -// before -fetch('https://api.com') - -// after -fetch('https://cors.r2d2.to/?=https://api.com') -``` - -## How to clear the local settings? - -Open the background.html of the extension and execute the following scripts in the console. - -```js -browser.storage.local.clear() -``` diff --git a/docs/blockchain-integration.md b/docs/blockchain-integration.md deleted file mode 100644 index 3e7fce495d56..000000000000 --- a/docs/blockchain-integration.md +++ /dev/null @@ -1,5 +0,0 @@ -# Blockchain Integration - -Mask Network assumes many capabilities that a blockchain should have. For example, a blockchain uses an "address" to locate a crypto-identity, a wallet keeps the crypto stuff safe from risk, and a "block" contains many transactions that push the system to the next state. - -The fundamental of blockchain is neutral. We could leverage it to do anything. However, a few years ago, people found financial usage from it and heavily developed it. As a result, almost all blockchains support "tokens" natively to proof of ownership. diff --git a/docs/bounty-development-guide.md b/docs/bounty-development-guide.md deleted file mode 100644 index 2e3f8887d93e..000000000000 --- a/docs/bounty-development-guide.md +++ /dev/null @@ -1,74 +0,0 @@ -# Bounty Development Guide - -Hi, Awesome people! Welcome to start a bounty task on Mask Network. - -## Tech Requirements - -Mask Network extension is written in TypeScript. The UI is written by React and [@mui](https://mui.com/) framework. We write CSS in [CSS-in-JS](css-in-js.md) style. - -We prefer widely adopting tech solutions that include: - -- [Web3.js](https://web3js.readthedocs.io/) Ethereum JavaScript API -- [react-use](https://streamich.github.io/react-use/) React Hooks — 👍 -- [bignumber.js](https://mikemcl.github.io/bignumber.js/) A JavaScript library for arbitrary-precision arithmetic. -- [lodash](https://lodash.com/docs/) A modern JavaScript utility library delivering modularity, performance & extras. -- [urlcat](https://urlcat.dev/) A URL builder library for JavaScript. - -> If your bounty task is related to another project, it could have extra requirements that need to consider. - -If you are familiar with these libraries mentioned above, it will take less effort for you to get started. -The codebase is open-sourced under the AGPLv3 license. - -## Packages - -After cloning the repository and [set up the development environment](setup.md). The codebase is constructed as a monorepo with many internal packages. Each package serves a specific purpose. Let's take a quick tour. - -### Core Packages - -- `packages/mask` The main extension which has multiple websites supports, keeps the user's data safe and hosts a plugin system. -- `packages/encryption` The encryption & decryption of mask network. -- `packages/plugin-infra` The definition of the plugin system, with a bunch of APIs to expose the core abilities to plugins. - -### Plugin Packages - -- `packages/plugins/*` All of integrated plugins. - -### Shared Packages - -- `packages/shared` Shared UI components and utilities. -- `packages/shared-base` Shared types, constants, and atomic units. Must be as pure as possible and testable. - -### Web3 Packages - -- `packages/web3-constants` Each Web3 constant must set up for all known chain IDs. -- `packages/web3-contracts` EVM contract ABIs and compiled TypeScript definitions. -- `packages/web3-provider` A hub of APIs for external data source. -- `packages/web3-shared-*` Shared hooks, utilities, types for each network. - -## Learn Through Examples - -Almost all bounty tasks for the Mask Network plugin relate to a plugin. After learning the basics, checkout those pull requests or plugins to learn quick from examples. - -### Dapp Plugins - -| Plugin | Pull Request Links | -| ----------- | ----------------------------------------------------------------------------------------------- | -| Collectible | | -| Trader | | -| Savings | | - -### Network Plugins - -| Plugin | Pull Request Links | -| ---------- | -------------------------------------------------------------------------------------- | -| EVM Chains | | - -## Pull Request Conversions - -After bounty hacker opening a pull request. Reviewer will label it with `Type: Bounty`, and update a status tag while the progress on-going. - -| Status | Description | -| ------------------- | ---------------------------------------------------------------------------- | -| `Bounty: Started` | The DEV team noticed your request. You will receive comments from reviewers. | -| `Bounty: Reviewed` | The QA team noticed your request. You will receive bugs from reviewers. | -| `Bounty: Qualified` | Your request is qualifed. It will ship soon. | diff --git a/docs/concepts.md b/docs/concepts.md deleted file mode 100644 index 8f2f9615e826..000000000000 --- a/docs/concepts.md +++ /dev/null @@ -1,21 +0,0 @@ -# Concepts - -## Persona - -## Post Payload - -## Wallet - -## Dashboard - -## Popup - -## SNS Provider - -## Wallet Provider - -## Plugin - -## Network - -## ChainId diff --git a/docs/css-in-js.md b/docs/css-in-js.md deleted file mode 100644 index d92374225867..000000000000 --- a/docs/css-in-js.md +++ /dev/null @@ -1,104 +0,0 @@ ---- -author: Jack-Works -maintainer: - - Jack-Works - - Septs ---- - -# CSS in JS guide in Mask Network - -## General guides - -- ✅ For recommendations -- ⚠ For warnings -- 🚫 For forbidden -- ✅ Use [the Box component provided by the library](https://next.material-ui.com/components/box/#main-content) - when the CSS is simple and only used once. -- ✅ CSS custom variables is OK but do not abuse it. - Get the variable from the theme if it is possible. -- ✅ CSS grid is OK but you may want to use the `Grid` component. - Choose the fit one based on your need. -- 🚫 DO NOT use mystery abbreviations in the `sx` properties, e.g. `` - (DON'T) but `` (DO, easier to read). - -## Guides on the `makeStyles` style - -```ts -const useStyle = makeStyles()((theme) => ({ - root: { margin: theme.spacing(4) }, -})) -``` - -### Change style of MUI components - -✅ DO - -```js - -} -``` - -First of all, it creates a [Web3](https://web3js.readthedocs.io/) instance which redirects all JSON-RPC requests to the [request](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/extension/background-script/EthereumServices/request.ts) service on the background page. If you'd like to read the source code, you will realise that there is a [Koa.js](https://koajs.com/) styled [composer](https://github.com/koajs/compose) built-in. A list of middleware is used and serve different purposes: a middleware stores transactions into DB, a middleware watches transaction status, a middleware notifies transaction progress, and so on. - -At the current stage, there are two kinds of wallets: Mask Wallet and other wallets. - -Mask Wallet sends requests to the network directly on the background page. If the request takes the response, then the user will get notified. - -But it's not that simple for other wallets. They are supported only on the front end. E.g., the [Fortmatic](https://docs.fortmatic.com/) SDK injects an iframe on the currently visiting page. Mask Network cannot invoke those SDKs on the background page as an extension. Because of that, they should take their requests to the front end and handle them there. Many mounted components, so-called `ProviderBridge`, listen to the `PROVIDER_RPC_REQUEST` event and call the corresponding SDK once they receive any request from the background. After the SKD finishes the work, they return the result to the bridged provider on the background page with the `PROVIDER_RPC_RESPONSE` event. - -It takes a quite long detour, but the benefit is all requests can leverage Mask Wallet abilities. - -## A Wallet on a bridged provider - -If the wallet that only works on the front end. It needs to use the bridged provider way. - -On the front end: - -- create a bridged provider by implementing the [`EIP1193Provider`](https://github.com/DimensionDev/Maskbook/blob/develop/packages/web3-shared/evm/types/index.ts) interface. -- instantiate the bridged provider in [useBridgedProvider](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/plugins/EVM/hooks/useBridgedProvider.ts) which was used by [``](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/plugins/EVM/UI/components/ProviderBridge.tsx). -- add a new `` in the [EVM](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/plugins/EVM/UI/SNSAdaptor/index.tsx) plugin to receive events from the background page. - -On the background page: - -- instantiate a [BridgedProvider](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/extension/background-script/EthereumServices/providers/Bridged.ts) and add it into the supported list in [getProvider](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/extension/background-script/EthereumServices/provider.ts). - -## A wallet without any UI - -If the wallet is totally UI free and can connect/disconnect by calling some APIs. It can send requests to those APIs directly. - -On the background page: - -- create a provider to extend from the [BaseProvider](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts) interface and add it into the supported list in [getProvider](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/extension/background-script/EthereumServices/provider.ts). - -## Interceptor - -The implementation of Ethereum JSON-RPC may very different between wallets. Those JSON-RPC requests will need some preprocessing before sending to the real wallet. Nevertheless, the Mask Network flavors a bunch of self-known RPC methods that were unknown to other wallets. Bypassing a such request will hit an unimplemented error. - - - -For this sake, the [`composer`](https://github.com/DimensionDev/Maskbook/blob/develop/packages/mask/src/extension/background-script/EthereumServices/composer.ts) creates a middleware for intercepting JSON-RPC requests. Here is a quick example that converts the Mask Network flavored [`mask_requestAccounts`](./mask-flavored-**jsonrpc**-api.md#mask_requestaccounts) into an Ethereum styled [`eth_accounts`](https://eth.wiki/json-rpc/API#eth_accounts). - -```ts -export class Example implements Middleware { - async fn(context: Context, next: () => Promise) { - switch (context.method) { - case EthereumMethodType.MASK_REQUEST_ACCOUNTS: - context.requestArguments = { - ...context.requestArguments, - method: EthereumMethodType.ETH_ACCOUNTS, - } - break - default: - break - } - await next() - } -} -``` - -## Examples - -| Wallet | Implementation | -| ------------- | -------------- | -| MetaMask | \- | -| WalletConnect | \- | -| Fortmatic | \- | From 2200750736d564e2b2972f4fa716990ddcaff8fe Mon Sep 17 00:00:00 2001 From: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Date: Sun, 29 May 2022 23:00:18 +0800 Subject: [PATCH 13/17] feat: EVM migration and Web3 Infra (#6371) * refactor: migrate evm Co-authored-by: guanbinrui <52657989+guanbinrui@users.noreply.github.com> Co-authored-by: lelenei <72531217+lelenei@users.noreply.github.com> Co-authored-by: Hancheng Zhou Co-authored-by: UncleBill Co-authored-by: Hom Co-authored-by: BillyS Co-authored-by: nuanyang233 Co-authored-by: Randolph314 <97870249+Randolph314@users.noreply.github.com> Co-authored-by: Lantt * fix: eslint * fix: type error * chore: merge develop * fix: build error * fix: encode arrayBuffer * fix: build error * fix: build error * fix: rollback @dimensiondev/kit to fix build error * fix: build error * fix: typo * fix: build error * fix: typo * fix: unit test * fix: lint errors Co-authored-by: Jack Works Co-authored-by: lelenei <72531217+lelenei@users.noreply.github.com> Co-authored-by: Hancheng Zhou Co-authored-by: UncleBill Co-authored-by: Hom Co-authored-by: BillyS Co-authored-by: nuanyang233 Co-authored-by: Randolph314 <97870249+Randolph314@users.noreply.github.com> Co-authored-by: Lantt --- .i18n-codegen.json | 11 + .prettierignore | 4 + cspell.json | 3 + package.json | 2 +- packages/dashboard/package.json | 3 + .../components/DashboardFrame/Navigation.tsx | 3 +- .../PageFrame/FeaturePromotions/index.tsx | 19 +- packages/dashboard/src/hooks/useGasOptions.ts | 58 - .../src/initialization/Dashboard.tsx | 53 +- .../src/initialization/PluginHost.ts | 22 +- .../src/initialization/isolated_bridge.ts | 4 +- .../components/CreateMnemonic/index.tsx | 9 +- packages/dashboard/src/pages/Settings/api.ts | 6 - .../Settings/components/DataSourceSetting.tsx | 21 - packages/dashboard/src/pages/Wallets/api.ts | 12 - .../components/AddCollectibleDialog/index.tsx | 87 +- .../components/AddTokenConfirmUI/index.tsx | 7 +- .../components/AddTokenFormUI/index.tsx | 5 +- .../pages/Wallets/components/Assets/index.tsx | 7 +- .../Wallets/components/Balance/index.tsx | 35 +- .../components/CollectibleCard/index.tsx | 37 +- .../components/CollectibleList/index.tsx | 106 +- .../CollectiblePlaceHolder/index.tsx | 5 +- .../components/FungibleTokenTable/index.tsx | 127 +- .../ChangeNetworkTip.tsx | 9 +- .../FungibleTokenTableRow/index.tsx | 53 +- .../Wallets/components/History/index.tsx | 4 +- .../Wallets/components/HistoryTable/index.tsx | 29 +- .../components/HistoryTableRow/index.tsx | 45 +- .../components/ReceiveDialog/index.tsx | 133 +- .../components/SelectTokenDialog/index.tsx | 9 +- .../components/TransactionIcon/index.tsx | 7 +- .../Wallets/components/Transfer/NFTCard.tsx | 9 +- .../components/Transfer/SelectNFTList.tsx | 5 +- .../components/Transfer/TransferERC20.tsx | 102 +- .../components/Transfer/TransferERC721.tsx | 194 +- .../Wallets/components/Transfer/index.tsx | 14 +- .../Transfer/useNativeTokenPrice.ts | 29 - .../components/WalletStateBar/index.tsx | 49 +- .../WalletStateBar/useNetworkSelector.tsx | 18 +- .../src/pages/Wallets/hooks/index.ts | 2 - .../src/pages/Wallets/hooks/useAddressBook.ts | 13 - .../Wallets/hooks/useERC20TokensDetailed.ts | 76 +- .../src/pages/Wallets/hooks/useGasConfig.ts | 32 +- .../Wallets/hooks/useRecentTransactions.ts | 21 - .../dashboard/src/pages/Wallets/index.tsx | 52 +- .../pages/Wallets/utils/getTokenUSDValue.tsx | 2 +- packages/dashboard/src/web3/context.ts | 155 -- .../components/Wallet/CollectibleCard.tsx | 18 +- .../components/Wallet/ReceiveDialog.tsx | 7 +- packages/dashboard/tsconfig.json | 2 + .../main/GlobalVariableBridge/index.ts | 31 +- packages/injected-script/main/communicate.ts | 48 +- packages/injected-script/package.json | 3 - packages/injected-script/sdk/Base.ts | 101 + packages/injected-script/sdk/Coin98.ts | 28 + packages/injected-script/sdk/MathWallet.ts | 11 + packages/injected-script/sdk/MetaMask.ts | 11 + packages/injected-script/sdk/Phantom.ts | 7 + packages/injected-script/sdk/Solflare.ts | 15 + packages/injected-script/sdk/WalletLink.ts | 12 + packages/injected-script/sdk/bridgedCoin98.ts | 61 - .../injected-script/sdk/bridgedEthereum.ts | 61 - packages/injected-script/sdk/bridgedSolana.ts | 97 - packages/injected-script/sdk/index.ts | 59 +- packages/injected-script/sdk/tsconfig.json | 12 +- packages/injected-script/shared/index.ts | 47 +- .../background/services/crypto/decryption.ts | 2 +- packages/mask/package.json | 5 +- .../TypedMessageRender/Components/Text.tsx | 5 +- packages/mask/shared-ui/locales/en-US.json | 52 +- packages/mask/shared-ui/locales/ja-JP.json | 20 + packages/mask/shared-ui/locales/ko-KR.json | 42 + packages/mask/shared-ui/locales/qya-AA.json | 51 +- packages/mask/shared-ui/locales/zh-CN.json | 46 + packages/mask/shared-ui/locales/zh-TW.json | 35 + packages/mask/shared/flags.ts | 3 - packages/mask/src/UIRoot.tsx | 14 +- .../CompositionDialog/PluginEntryRender.tsx | 3 +- .../InjectedComponents/ProfileTabContent.tsx | 9 +- .../InjectedComponents/SearchResultBox.tsx | 2 +- .../InjectedComponents/ToolboxUnstyled.tsx | 25 +- .../components/shared/ApplicationBoard.tsx | 4 +- .../mask/src/components/shared/NetworkTab.tsx | 4 +- .../shared/SelectWallet/WalletInList.tsx | 3 +- .../mask/src/components/shared/TokenPrice.tsx | 17 +- .../shared/VerifyWallet/CurrentWalletBox.tsx | 55 +- .../components/shared/VerifyWallet/Steps.tsx | 8 +- .../WalletStatusBox/TransactionList.tsx | 90 +- .../shared/WalletStatusBox/index.tsx | 20 +- .../usePendingTransactions.tsx | 27 +- packages/mask/src/env.d.ts | 11 - .../background-script/BackupService.ts | 22 +- .../background-script/EthereumService.ts | 5 - .../EthereumServices/network.ts | 243 -- .../EthereumServices/nonce.ts | 131 -- .../EthereumServices/provider.ts | 119 - .../providers/CustomNetwork.ts | 12 - .../EthereumServices/providers/Fortmatic.ts | 97 - .../EthereumServices/providers/Injected.ts | 123 - .../EthereumServices/providers/MaskWallet.ts | 89 - .../EthereumServices/providers/MetaMask.ts | 112 - .../providers/WalletConnect.ts | 119 - .../EthereumServices/request.ts | 262 --- .../EthereumServices/rpc/abi.ts | 66 - .../EthereumServices/rpc/index.ts | 197 -- .../EthereumServices/send.ts | 526 ----- .../EthereumServices/web3.ts | 38 - .../Jobs/StartPluginWorker.ts | 19 +- .../background-script/SettingsService.ts | 35 +- .../mask/src/extension/dashboard/index.tsx | 38 +- .../DashboardComponents/ActionsBarNFT.tsx | 8 +- .../CollectibleList/CollectibleCard.tsx | 17 +- .../CollectibleList/CollectionIcon.tsx | 14 +- .../CollectibleList/index.tsx | 517 +++-- .../Wallet/HideTokenConfirm.tsx | 64 +- .../DashboardDialogs/Wallet/TransferNFT.tsx | 23 +- packages/mask/src/extension/popups/UI.tsx | 50 +- .../components/NetworkSelector/index.tsx | 40 +- .../components/WalletStateBar/index.tsx | 11 +- .../pages/Personas/ConnectedWallets/UI.tsx | 9 +- .../pages/Personas/ConnectedWallets/index.tsx | 10 +- .../pages/Personas/VerifyWallet/index.tsx | 63 +- .../popups/pages/Swap/SwapBox/index.tsx | 5 +- .../src/extension/popups/pages/Swap/index.tsx | 75 +- .../pages/Wallet/AddDeriveWallet/index.tsx | 13 +- .../popups/pages/Wallet/AddToken/index.tsx | 13 +- .../pages/Wallet/BackupWallet/index.tsx | 2 +- .../pages/Wallet/ConnectWallet/index.tsx | 111 +- .../Wallet/ContractInteraction/index.tsx | 187 +- .../pages/Wallet/DeleteWallet/index.tsx | 13 +- .../Wallet/GasSetting/GasSetting1559.tsx | 98 +- .../Wallet/GasSetting/Prior1559GasSetting.tsx | 64 +- .../popups/pages/Wallet/GasSetting/index.tsx | 8 +- .../popups/pages/Wallet/GasSetting/types.ts | 6 +- .../pages/Wallet/GasSetting/useGasOptions.ts | 45 - .../pages/Wallet/ImportWallet/index.tsx | 38 +- .../Wallet/LegacyWalletRecovery/index.tsx | 4 +- .../pages/Wallet/ReplaceTransaction/index.tsx | 80 +- .../pages/Wallet/SelectWallet/WalletItem.tsx | 37 +- .../pages/Wallet/SelectWallet/index.tsx | 86 +- .../popups/pages/Wallet/SignRequest/index.tsx | 36 +- .../pages/Wallet/SwitchWallet/WalletItem.tsx | 62 +- .../pages/Wallet/SwitchWallet/index.tsx | 44 +- .../popups/pages/Wallet/TokenDetail/index.tsx | 43 +- .../pages/Wallet/Transfer/AccountItem.tsx | 11 +- .../Wallet/Transfer/Prior1559Transfer.tsx | 105 +- .../pages/Wallet/Transfer/Transfer1559.tsx | 146 +- .../popups/pages/Wallet/Transfer/index.tsx | 16 +- .../pages/Wallet/WalletRecovery/index.tsx | 14 +- .../pages/Wallet/WalletRename/index.tsx | 5 +- .../pages/Wallet/WalletSettings/index.tsx | 19 +- .../ActivityList/ActivityListItem.tsx | 49 +- .../Wallet/components/ActivityList/index.tsx | 76 +- .../Wallet/components/AssetsList/index.tsx | 17 +- .../components/DeriveWalletTable/index.tsx | 8 +- .../Wallet/components/WalletAssets/index.tsx | 5 +- .../Wallet/components/WalletHeader/UI.tsx | 8 +- .../Wallet/components/WalletHeader/index.tsx | 32 +- .../Wallet/components/WalletInfo/index.tsx | 16 +- .../Wallet/hooks/useSetWalletNameForm.ts | 5 +- .../Wallet/hooks/useUnConfirmedRequest.ts | 15 +- .../pages/Wallet/hooks/useWalletContext.ts | 22 +- .../extension/popups/pages/Wallet/index.tsx | 45 +- packages/mask/src/extension/popups/render.tsx | 28 +- packages/mask/src/extension/service.ts | 2 - packages/mask/src/plugin-infra/host.ts | 77 +- packages/mask/src/plugin-infra/register.js | 5 +- .../ArtBlocks/SNSAdaptor/Collectible.tsx | 21 +- .../ArtBlocks/SNSAdaptor/CollectionView.tsx | 5 +- .../ArtBlocks/SNSAdaptor/DetailsView.tsx | 17 +- .../ArtBlocks/SNSAdaptor/PurchaseDialog.tsx | 43 +- .../ArtBlocks/hooks/useArtBlocksContract.ts | 12 +- .../src/plugins/ArtBlocks/hooks/useProject.ts | 9 +- .../ArtBlocks/hooks/usePurchaseCallback.ts | 14 +- .../src/plugins/ArtBlocks/hooks/useToken.ts | 9 +- .../mask/src/plugins/ArtBlocks/pipes/index.ts | 3 +- .../Avatar/Application/NFTAvatarsDialog.tsx | 2 +- .../plugins/Avatar/Application/NFTList.tsx | 9 +- .../Avatar/Application/NFTListDialog.tsx | 39 +- .../Avatar/Application/NFTListPage.tsx | 42 +- .../Avatar/Application/UploadAvatarDialog.tsx | 14 +- .../Avatar/Application/WalletConnect.tsx | 27 +- .../plugins/Avatar/Application/WalletList.tsx | 16 +- .../src/plugins/Avatar/SNSAdaptor/AddNFT.tsx | 43 +- .../plugins/Avatar/SNSAdaptor/NFTAvatar.tsx | 53 +- .../plugins/Avatar/SNSAdaptor/NFTImage.tsx | 21 +- .../mask/src/plugins/Avatar/Services/bind.ts | 4 +- .../mask/src/plugins/Avatar/Services/index.ts | 2 +- .../mask/src/plugins/Avatar/Services/rss3.ts | 6 +- .../plugins/Avatar/hooks/useCheckAddress.ts | 2 +- .../plugins/Avatar/hooks/useCollectibles.ts | 21 + .../mask/src/plugins/Avatar/hooks/useNFT.ts | 23 +- .../src/plugins/Avatar/hooks/useTokenOwner.ts | 31 +- .../src/plugins/Avatar/locales/en-US.json | 2 +- packages/mask/src/plugins/Avatar/types.ts | 6 +- .../mask/src/plugins/Avatar/utils/index.ts | 106 +- .../Collectible/SNSAdaptor/Account.tsx | 3 +- .../Collectible/SNSAdaptor/ArticleTab.tsx | 8 +- .../Collectible/SNSAdaptor/Collectible.tsx | 92 +- .../SNSAdaptor/CollectibleProviderIcon.tsx | 15 +- .../Collectible/SNSAdaptor/HistoryTab/Row.tsx | 86 +- .../SNSAdaptor/HistoryTab/index.tsx | 33 +- .../Collectible/SNSAdaptor/ListingTab.tsx | 43 +- .../Collectible/SNSAdaptor/NFTPage.tsx | 12 +- .../Collectible/SNSAdaptor/OfferTab.tsx | 43 +- .../SNSAdaptor/{ => OpenSea}/ActionBar.tsx | 44 +- .../{ => OpenSea}/CheckoutDialog.tsx | 65 +- .../{ => OpenSea}/CheckoutOrder.tsx | 50 +- .../{ => OpenSea}/ListingByHighestBidCard.tsx | 75 +- .../{ => OpenSea}/ListingByPriceCard.tsx | 76 +- .../{ => OpenSea}/MakeOfferDialog.tsx | 100 +- .../{ => OpenSea}/PostListingDialog.tsx | 22 +- .../Collectible/SNSAdaptor/OrderRow.tsx | 91 +- .../Collectible/SNSAdaptor/Pagination.tsx | 56 - .../SNSAdaptor/SelectTokenListPanel.tsx | 39 +- .../Collectible/SNSAdaptor/TokenTab.tsx | 51 +- .../plugins/Collectible/SNSAdaptor/index.tsx | 32 +- .../plugins/Collectible/SNSAdaptor/shared.tsx | 31 - .../src/plugins/Collectible/apis/index.ts | 1 - .../Collectible/apis/openseaFromSDK.ts | 42 - .../mask/src/plugins/Collectible/constants.ts | 3 +- .../Collectible/hooks/useAssetOrder.ts | 60 +- .../Collectible/hooks/useCollectibleState.ts | 68 +- .../plugins/Collectible/hooks/useOpenSea.ts | 23 + .../src/plugins/Collectible/pipes/index.ts | 95 +- .../plugins/Collectible/queries/OpenSea.ts | 228 -- .../mask/src/plugins/Collectible/services.ts | 2 +- .../src/plugins/Collectible/types/index.ts | 3 - .../src/plugins/Collectible/types/opensea.ts | 248 -- .../src/plugins/Collectible/types/rarible.ts | 212 -- .../CryptoartAI/SNSAdaptor/Account.tsx | 5 +- .../CryptoartAI/SNSAdaptor/CheckoutDialog.tsx | 25 +- .../CryptoartAI/SNSAdaptor/Collectible.tsx | 14 +- .../CryptoartAI/SNSAdaptor/HistoryTab/Row.tsx | 2 +- .../SNSAdaptor/HistoryTab/index.tsx | 5 +- .../SNSAdaptor/MakeOfferDialog.tsx | 41 +- .../CryptoartAI/SNSAdaptor/OfferTab.tsx | 5 +- .../CryptoartAI/SNSAdaptor/OrderRow.tsx | 2 +- .../CryptoartAI/SNSAdaptor/TokenTab.tsx | 10 +- .../src/plugins/CryptoartAI/apis/index.ts | 2 +- .../mask/src/plugins/CryptoartAI/constants.ts | 15 +- .../src/plugins/CryptoartAI/hooks/useAsset.ts | 9 +- .../hooks/useCryptoArtAI_Contract.ts | 13 +- .../plugins/CryptoartAI/hooks/useEvents.ts | 7 +- .../plugins/CryptoartAI/hooks/useOrders.ts | 5 +- .../CryptoartAI/hooks/usePlaceBidCallback.ts | 13 +- .../CryptoartAI/hooks/usePurchaseCallback.ts | 13 +- .../src/plugins/EVM/UI/Dashboard/index.tsx | 23 - .../src/plugins/EVM/UI/SNSAdaptor/index.tsx | 26 - .../UI/Web3State/createGetLatestBalance.ts | 10 - .../UI/Web3State/createNonFungibleToken.ts | 27 - .../plugins/EVM/UI/Web3State/getAssetsFn.ts | 239 -- .../src/plugins/EVM/UI/Web3State/index.ts | 158 -- .../mask/src/plugins/EVM/UI/Web3UI/index.tsx | 12 - .../UI/components/FortmaticProviderBridge.tsx | 83 - .../UI/components/InjectedProviderBridge.tsx | 69 - .../UI/components/NetworkIconClickBait.tsx | 72 - .../UI/components/ProviderIconClickBait.tsx | 114 - packages/mask/src/plugins/EVM/base.ts | 25 - packages/mask/src/plugins/EVM/constants.ts | 246 -- packages/mask/src/plugins/EVM/hooks/index.ts | 8 - .../mask/src/plugins/EVM/hooks/useAsset.ts | 41 - .../plugins/EVM/hooks/useBridgedProvider.ts | 16 - .../mask/src/plugins/EVM/hooks/useHistory.ts | 29 - .../EVM/hooks/useInjectedProviderReady.ts | 10 - .../EVM/hooks/useInjectedProviderType.ts | 31 - .../mask/src/plugins/EVM/hooks/useNetwork.ts | 7 - .../mask/src/plugins/EVM/hooks/useOrders.ts | 37 - .../mask/src/plugins/EVM/hooks/useProvider.ts | 7 - .../src/plugins/EVM/services/Asset/index.ts | 132 -- .../src/plugins/EVM/services/NFT/index.ts | 92 - .../mask/src/plugins/EVM/services/index.ts | 2 - .../mask/src/plugins/EVM/storage/index.ts | 16 - packages/mask/src/plugins/EVM/types/index.ts | 1 - packages/mask/src/plugins/EVM/utils/index.ts | 1 - packages/mask/src/plugins/EVM/utils/token.ts | 36 - .../components/ExternalPluginRenderer.tsx | 11 +- .../External/components/PluginLoader.tsx | 8 +- .../FindTruman/SNSAdaptor/FindTruman.tsx | 17 +- .../FindTruman/SNSAdaptor/FtgPanel.tsx | 13 +- .../FindTruman/SNSAdaptor/MainDialog.tsx | 2 +- .../SNSAdaptor/ParticipatePanel.tsx | 2 +- .../FindTruman/SNSAdaptor/PartsPanel.tsx | 5 +- .../FindTruman/SNSAdaptor/PoapPanel.tsx | 7 +- .../FindTruman/SNSAdaptor/PostInspector.tsx | 5 +- .../plugins/FindTruman/Worker/apis/index.ts | 10 +- packages/mask/src/plugins/FindTruman/base.ts | 20 - .../plugins/Furucombo/UI/FurucomboView.tsx | 19 +- .../src/plugins/Furucombo/UI/PoolView.tsx | 7 +- .../Gitcoin/SNSAdaptor/DonateDialog.tsx | 43 +- .../Gitcoin/SNSAdaptor/PreviewCard.tsx | 24 +- .../src/plugins/Gitcoin/SNSAdaptor/index.tsx | 24 +- packages/mask/src/plugins/Gitcoin/base.ts | 9 - .../contracts/useBulkCheckoutWallet.ts | 11 +- .../Gitcoin/hooks/useDonateCallback.ts | 28 +- packages/mask/src/plugins/Gitcoin/types.tsx | 16 +- .../plugins/GoodGhosting/SNSAdaptor/index.tsx | 7 +- .../plugins/GoodGhosting/UI/GameAction.tsx | 17 +- .../GoodGhosting/UI/GameActionDialog.tsx | 13 +- .../plugins/GoodGhosting/UI/GameStatsView.tsx | 3 +- .../plugins/GoodGhosting/UI/PersonalView.tsx | 14 +- .../contracts/useGoodGhostingContract.ts | 7 +- .../useGoodGhostingIncentivesContract.ts | 6 +- .../GoodGhosting/hooks/useGameActions.ts | 27 +- .../plugins/GoodGhosting/hooks/useGameInfo.ts | 14 +- .../GoodGhosting/hooks/useOtherPlayerInfo.ts | 7 +- .../plugins/GoodGhosting/hooks/usePoolData.ts | 42 +- .../mask/src/plugins/GoodGhosting/types.tsx | 7 +- .../mask/src/plugins/GoodGhosting/utils.ts | 10 +- .../plugins/ITO/SNSAdaptor/ClaimAllDialog.tsx | 110 +- .../ITO/SNSAdaptor/CompositionDialog.tsx | 17 +- .../plugins/ITO/SNSAdaptor/ConfirmDialog.tsx | 23 +- .../src/plugins/ITO/SNSAdaptor/CreateForm.tsx | 33 +- .../ITO/SNSAdaptor/ExchangeTokenPanel.tsx | 10 +- .../SNSAdaptor/ExchangeTokenPanelGroup.tsx | 7 +- .../mask/src/plugins/ITO/SNSAdaptor/ITO.tsx | 56 +- .../src/plugins/ITO/SNSAdaptor/ITO_Card.tsx | 7 +- .../plugins/ITO/SNSAdaptor/NftAirdropCard.tsx | 372 --- .../src/plugins/ITO/SNSAdaptor/PoolInList.tsx | 43 +- .../src/plugins/ITO/SNSAdaptor/PoolList.tsx | 7 +- .../plugins/ITO/SNSAdaptor/PostInspector.tsx | 50 +- .../plugins/ITO/SNSAdaptor/RemindDialog.tsx | 28 +- .../ITO/SNSAdaptor/SelectTokenAmountPanel.tsx | 22 +- .../plugins/ITO/SNSAdaptor/ShareDialog.tsx | 6 +- .../src/plugins/ITO/SNSAdaptor/SwapDialog.tsx | 60 +- .../src/plugins/ITO/SNSAdaptor/SwapGuide.tsx | 11 +- .../plugins/ITO/SNSAdaptor/UnlockDialog.tsx | 32 +- .../SNSAdaptor/hooks/useAllPoolsAsSeller.ts | 60 +- .../ITO/SNSAdaptor/hooks/useAvailability.ts | 25 +- .../hooks/useAvailabilityComputed.ts | 16 +- .../ITO/SNSAdaptor/hooks/useClaimAll.ts | 15 +- .../ITO/SNSAdaptor/hooks/useClaimCallback.ts | 21 +- .../SNSAdaptor/hooks/useDestructCallback.ts | 9 +- .../hooks/useExchangeTokenAmountstate.ts | 9 +- .../plugins/ITO/SNSAdaptor/hooks/useFill.ts | 46 +- .../ITO/SNSAdaptor/hooks/useITO_Contract.ts | 12 +- .../ITO/SNSAdaptor/hooks/useIfQualified.ts | 9 +- .../SNSAdaptor/hooks/useMaskClaimCallback.ts | 12 +- .../SNSAdaptor/hooks/useMaskITO_Contract.ts | 9 +- .../ITO/SNSAdaptor/hooks/useMaskITO_Packet.ts | 8 +- .../ITO/SNSAdaptor/hooks/usePoolPayload.ts | 7 +- .../ITO/SNSAdaptor/hooks/usePoolTradeInfo.ts | 7 +- .../ITO/SNSAdaptor/hooks/useQualification.ts | 8 +- .../hooks/useQualificationContract.ts | 10 +- .../hooks/useQualificationVerify.ts | 11 +- .../hooks/useSpaceStationCampaignInfo.ts | 21 - .../hooks/useSpaceStationClaimable.ts | 12 - ...SpaceStationClaimableTokenCountCallback.ts | 29 - .../hooks/useSpaceStationContract.ts | 9 - .../useSpaceStationContractClaimCallback.ts | 71 - .../ITO/SNSAdaptor/hooks/useSwapCallback.ts | 48 +- .../mask/src/plugins/ITO/SNSAdaptor/index.tsx | 16 +- .../apis => SNSAdaptor/utils}/chain.ts | 51 +- .../utils}/checkAvailability.ts | 14 +- .../ITO/Worker/apis/spaceStationGalaxy.ts | 185 -- .../src/plugins/ITO/Worker/apis/subgraph.ts | 31 +- .../mask/src/plugins/ITO/Worker/services.ts | 52 +- packages/mask/src/plugins/ITO/base.ts | 19 - packages/mask/src/plugins/ITO/types.ts | 15 +- .../SNSAdaptor/components/DrawDialog.tsx | 27 +- .../components/DrawResultDialog.tsx | 5 +- .../SNSAdaptor/components/PreviewCard.tsx | 25 +- .../SNSAdaptor/components/TokenCard.tsx | 12 +- .../src/plugins/MaskBox/SNSAdaptor/index.tsx | 3 +- .../src/plugins/MaskBox/hooks/useContext.ts | 86 +- .../MaskBox/hooks/useMaskBoxContract.ts | 7 +- .../hooks/useMaskBoxCreationSuccessEvent.ts | 9 +- .../plugins/MaskBox/hooks/useMaskBoxInfo.ts | 5 +- .../MaskBox/hooks/useMaskBoxMetadata.ts | 4 +- .../hooks/useMaskBoxPurchasedTokens.ts | 8 +- .../hooks/useMaskBoxQualificationContract.ts | 7 +- .../plugins/MaskBox/hooks/useMaskBoxStatus.ts | 5 +- .../MaskBox/hooks/useMaskBoxTokensForSale.ts | 5 +- .../plugins/MaskBox/hooks/useMerkleProof.ts | 5 +- .../MaskBox/hooks/useOpenBoxGasLimit.ts | 5 +- .../MaskBox/hooks/useOpenBoxTransaction.ts | 14 +- .../plugins/MaskBox/hooks/useQualification.ts | 5 +- packages/mask/src/plugins/MaskBox/type.ts | 5 +- packages/mask/src/plugins/NextID/base.ts | 2 +- .../plugins/NextID/components/BindDialog.tsx | 4 +- .../plugins/NextID/components/BindPanelUI.tsx | 3 +- .../plugins/NextID/components/BindingItem.tsx | 10 +- .../plugins/NextID/components/NextIdPage.tsx | 14 +- .../NextID/components/UnbindConfirm.tsx | 4 +- .../NextID/components/UnbindDialog.tsx | 5 +- .../NextID/components/UnbindPanelUI.tsx | 3 +- .../src/plugins/NextID/hooks/useWalletSign.ts | 4 +- .../src/plugins/Pets/SNSAdaptor/PetDialog.tsx | 2 +- .../plugins/Pets/SNSAdaptor/PetSetDialog.tsx | 31 +- .../mask/src/plugins/Pets/Services/index.ts | 5 +- .../mask/src/plugins/Pets/Services/rss3.ts | 10 +- packages/mask/src/plugins/Pets/base.tsx | 2 +- .../mask/src/plugins/Pets/hooks/useNfts.ts | 53 +- .../mask/src/plugins/Pets/hooks/useUser.ts | 7 +- packages/mask/src/plugins/Pets/types.ts | 6 +- .../src/plugins/PoolTogether/UI/Account.tsx | 2 +- .../plugins/PoolTogether/UI/AccountPool.tsx | 5 +- .../plugins/PoolTogether/UI/DepositDialog.tsx | 25 +- .../plugins/PoolTogether/UI/NetworkView.tsx | 16 +- .../PoolTogether/UI/PoolTogetherView.tsx | 10 +- .../src/plugins/PoolTogether/UI/PoolView.tsx | 10 +- .../src/plugins/PoolTogether/apis/index.ts | 3 +- .../contracts/usePoolTogetherPool.ts | 7 +- .../contracts/usePoolTogetherTicket.ts | 7 +- .../PoolTogether/hooks/useAccountBalances.ts | 15 +- .../PoolTogether/hooks/useDepositCallback.ts | 14 +- .../plugins/PoolTogether/hooks/usePoolURL.ts | 8 +- .../plugins/PoolTogether/hooks/usePools.ts | 11 +- .../mask/src/plugins/PoolTogether/messages.ts | 5 +- .../Profile/SNSAdaptor/WalletsPage.tsx | 128 -- .../src/plugins/Profile/SNSAdaptor/index.ts | 9 - .../mask/src/plugins/Profile/Worker/index.ts | 9 - packages/mask/src/plugins/Profile/base.ts | 16 - .../mask/src/plugins/Profile/constants.ts | 5 - packages/mask/src/plugins/Profile/index.ts | 16 - packages/mask/src/plugins/Profile/messages.ts | 9 - packages/mask/src/plugins/Profile/services.ts | 14 - packages/mask/src/plugins/Profile/types.ts | 7 - .../plugins/RedPacket/SNSAdaptor/NftList.tsx | 15 +- .../SNSAdaptor/NftRedPacketHistoryItem.tsx | 22 +- .../SNSAdaptor/NftRedPacketHistoryList.tsx | 10 +- .../SNSAdaptor/RedPacket/OperationFooter.tsx | 27 +- .../RedPacket/SNSAdaptor/RedPacket/index.tsx | 41 +- .../SNSAdaptor/RedPacketConfirmDialog.tsx | 43 +- .../SNSAdaptor/RedPacketCreateNew.tsx | 6 +- .../RedPacket/SNSAdaptor/RedPacketDialog.tsx | 23 +- .../SNSAdaptor/RedPacketERC20Form.tsx | 53 +- .../SNSAdaptor/RedPacketERC721Form.tsx | 51 +- .../SNSAdaptor/RedPacketHistoryList.tsx | 14 +- .../SNSAdaptor/RedPacketInHistoryList.tsx | 49 +- .../RedPacket/SNSAdaptor/RedPacketInPost.tsx | 9 +- .../RedPacket/SNSAdaptor/RedPacketNft.tsx | 62 +- .../RedPacket/SNSAdaptor/RedPacketPast.tsx | 11 +- .../SNSAdaptor/RedpacketNftConfirmDialog.tsx | 53 +- .../SNSAdaptor/SelectNftTokenDialog.tsx | 52 +- .../SNSAdaptor/hooks/useAvailability.ts | 24 +- .../hooks/useAvailabilityComputed.ts | 25 +- .../SNSAdaptor/hooks/useClaimCallback.ts | 13 +- .../hooks/useClaimNftRedpacketCallback.ts | 17 +- .../SNSAdaptor/hooks/useCreateCallback.tsx | 47 +- .../hooks/useCreateNftRedpacketCallback.ts | 17 +- .../hooks/useNftAvailabilityComputed.ts | 8 +- .../hooks/useNftRedPacketContract.ts | 8 +- .../SNSAdaptor/hooks/useRedPacketContract.ts | 13 +- .../SNSAdaptor/hooks/useRedPacketHistory.ts | 35 +- .../SNSAdaptor/hooks/useRefundCallback.ts | 9 +- .../plugins/RedPacket/SNSAdaptor/index.tsx | 24 +- .../apis => SNSAdaptor/utils}/chain.ts | 23 +- .../utils}/checkAvailability.ts | 13 +- .../RedPacket/Worker/apis/erc20Redpacket.ts | 52 +- .../RedPacket/Worker/apis/nftRedpacket.ts | 28 +- .../src/plugins/RedPacket/Worker/services.ts | 22 +- packages/mask/src/plugins/RedPacket/base.ts | 2 +- packages/mask/src/plugins/RedPacket/types.ts | 39 +- .../Savings/SNSAdaptor/SavingsDialog.tsx | 33 +- .../Savings/SNSAdaptor/SavingsForm.tsx | 104 +- .../Savings/SNSAdaptor/SavingsTable.tsx | 25 +- packages/mask/src/plugins/Savings/base.ts | 2 +- .../mask/src/plugins/Savings/constants.ts | 7 +- .../plugins/Savings/protocols/AAVEProtocol.ts | 12 +- .../plugins/Savings/protocols/LDOProtocol.ts | 6 +- packages/mask/src/plugins/Savings/types.ts | 9 +- .../Snapshot/SNSAdaptor/InformationCard.tsx | 18 +- .../plugins/Snapshot/SNSAdaptor/Snapshot.tsx | 13 +- .../src/plugins/Snapshot/SNSAdaptor/Vote.tsx | 2 +- .../Snapshot/SNSAdaptor/VoteConfirmDialog.tsx | 10 +- .../plugins/Snapshot/SNSAdaptor/VotesCard.tsx | 14 +- .../Snapshot/SNSAdaptor/VotingCard.tsx | 54 +- .../Snapshot/SNSAdaptor/hooks/usePower.ts | 5 +- .../src/plugins/Snapshot/Worker/apis/index.ts | 72 +- .../mask/src/plugins/Snapshot/constants.ts | 4 + packages/mask/src/plugins/Snapshot/utils.ts | 28 + .../Tips/SNSAdaptor/TipsEntranceDialog.tsx | 10 +- .../Tips/SNSAdaptor/bodyViews/AddWallet.tsx | 89 +- .../Tips/SNSAdaptor/bodyViews/Setting.tsx | 2 +- .../Tips/SNSAdaptor/components/WalletItem.tsx | 21 +- .../SNSAdaptor/components/WalletSwitch.tsx | 27 +- .../components/WalletsByNetwork.tsx | 2 +- .../src/plugins/Tips/SNSAdaptor/index.tsx | 2 +- .../src/plugins/Tips/components/AddDialog.tsx | 41 +- .../Tips/components/NFTSection/NFTList.tsx | 32 +- .../Tips/components/NFTSection/index.tsx | 37 +- .../src/plugins/Tips/components/TipDialog.tsx | 36 +- .../src/plugins/Tips/components/TipForm.tsx | 23 +- .../Tips/components/TokenSection/index.tsx | 22 +- .../Tips/contexts/TargetChainIdContext.ts | 6 +- .../plugins/Tips/contexts/Tip/TipContext.ts | 12 +- .../Tips/contexts/Tip/TipTaskProvider.tsx | 14 +- .../plugins/Tips/contexts/Tip/useNftTip.ts | 36 +- .../Tips/contexts/Tip/useTipValidate.ts | 6 +- .../plugins/Tips/contexts/Tip/useTokenTip.ts | 16 +- .../Tips/hooks/useSupportedNetworks.ts | 3 +- .../plugins/Tips/hooks/useTipsWalletsList.ts | 2 +- .../mask/src/plugins/Tips/storage/index.ts | 10 +- .../src/plugins/Trader/Dashboard/index.tsx | 3 +- .../mask/src/plugins/Trader/LBP/useLBP.ts | 22 - .../plugins/Trader/LBP/usePoolTokenPrices.ts | 9 - .../src/plugins/Trader/LBP/usePoolTokens.ts | 9 - .../mask/src/plugins/Trader/LBP/usePools.ts | 9 - .../src/plugins/Trader/SNSAdaptor/cashTag.tsx | 9 +- .../src/plugins/Trader/SNSAdaptor/index.tsx | 21 +- .../SNSAdaptor/trader/ConfirmDialog.tsx | 30 +- .../SNSAdaptor/trader/Gas1559Settings.tsx | 33 +- .../trader/GasPrior1559Settings.tsx | 41 +- .../SNSAdaptor/trader/InputTokenPanel.tsx | 12 +- .../SNSAdaptor/trader/SettingsDialog.tsx | 8 +- .../Trader/SNSAdaptor/trader/TradeForm.tsx | 30 +- .../Trader/SNSAdaptor/trader/TradeView.tsx | 3 +- .../Trader/SNSAdaptor/trader/Trader.tsx | 48 +- .../Trader/SNSAdaptor/trader/TraderDialog.tsx | 9 +- .../Trader/SNSAdaptor/trader/TraderInfo.tsx | 14 +- .../SNSAdaptor/trader/hooks/useGasConfig.ts | 44 +- .../trader/hooks/useSortedTrades.ts | 20 +- .../trader/hooks/useUpdateBalance.ts | 21 +- .../SNSAdaptor/trending/CoinMarketTable.tsx | 2 +- .../SNSAdaptor/trending/CoinSafetyAlert.tsx | 8 +- .../Trader/SNSAdaptor/trending/LBPPanel.tsx | 142 -- .../SNSAdaptor/trending/LBPPriceChart.tsx | 70 - .../SNSAdaptor/trending/TickersTable.tsx | 3 +- .../Trader/SNSAdaptor/trending/TraderView.tsx | 52 +- .../SNSAdaptor/trending/TrendingPopper.tsx | 8 +- .../SNSAdaptor/trending/TrendingViewDeck.tsx | 10 +- .../mask/src/plugins/Trader/apis/LBP/LBP.json | 12 - .../mask/src/plugins/Trader/apis/LBP/index.ts | 105 - .../src/plugins/Trader/apis/balancer/index.ts | 69 +- .../apis/bancor/calculateMinimumReturn.ts | 6 +- .../src/plugins/Trader/apis/blocks/index.ts | 34 +- .../mask/src/plugins/Trader/apis/index.ts | 1 - .../src/plugins/Trader/apis/trader/index.ts | 4 +- .../plugins/Trader/apis/trending/hotfix.ts | 73 +- .../src/plugins/Trader/apis/trending/index.ts | 81 +- .../Trader/apis/uniswap-health/index.ts | 16 +- .../Trader/apis/uniswap-v2-subgraph/index.ts | 81 +- .../src/plugins/Trader/apis/uniswap/index.ts | 50 +- packages/mask/src/plugins/Trader/base.ts | 4 +- .../src/plugins/Trader/constants/types.ts | 7 +- .../balancer/useExchangeProxyContract.ts | 5 +- .../contracts/uniswap/usePairContract.ts | 11 +- .../contracts/uniswap/usePoolContract.ts | 11 +- .../contracts/uniswap/useQuoterContract.ts | 5 +- .../contracts/uniswap/useRouterV2Contract.ts | 7 +- .../uniswap/useSwapRouterContract.ts | 7 +- .../src/plugins/Trader/helpers/uniswap.ts | 38 +- packages/mask/src/plugins/Trader/index.ts | 3 +- packages/mask/src/plugins/Trader/pipes.ts | 2 +- packages/mask/src/plugins/Trader/settings.ts | 8 - .../mask/src/plugins/Trader/storage/index.ts | 28 + .../src/plugins/Trader/trader/0x/useTrade.ts | 90 +- .../Trader/trader/0x/useTradeCallback.ts | 15 +- .../Trader/trader/0x/useTradeComputed.ts | 8 +- .../Trader/trader/0x/useTradeGasLimit.ts | 9 +- .../Trader/trader/balancer/useTrade.ts | 57 +- .../trader/balancer/useTradeCallback.ts | 20 +- .../trader/balancer/useTradeComputed.ts | 8 +- .../trader/balancer/useTradeGasLimit.ts | 14 +- .../plugins/Trader/trader/bancor/useTrade.ts | 77 +- .../Trader/trader/bancor/useTradeCallback.ts | 12 +- .../Trader/trader/bancor/useTradeComputed.ts | 9 +- .../Trader/trader/bancor/useTradeGasLimit.ts | 9 +- .../trader/blocks/useLatestBlockNumber.ts | 5 +- .../plugins/Trader/trader/dodo/useTrade.ts | 81 +- .../Trader/trader/dodo/useTradeCallback.ts | 10 +- .../Trader/trader/dodo/useTradeComputed.ts | 8 +- .../Trader/trader/dodo/useTradeGasLimit.ts | 15 +- .../plugins/Trader/trader/native/useTrade.ts | 10 +- .../Trader/trader/native/useTradeCallback.ts | 7 +- .../Trader/trader/native/useTradeComputed.ts | 12 +- .../Trader/trader/openocean/useTrade.ts | 83 +- .../trader/openocean/useTradeCallback.ts | 12 +- .../trader/openocean/useTradeComputed.ts | 8 +- .../trader/openocean/useTradeGasLimit.ts | 17 +- .../trader/uniswap/useAllCommonPairs.ts | 4 +- .../plugins/Trader/trader/uniswap/usePairs.ts | 4 +- .../plugins/Trader/trader/uniswap/usePools.ts | 4 +- .../plugins/Trader/trader/uniswap/useTrade.ts | 16 +- .../Trader/trader/uniswap/useTradeCallback.ts | 16 +- .../Trader/trader/uniswap/useTradeComputed.ts | 8 +- .../Trader/trader/uniswap/useTradeGasLimit.ts | 9 +- .../trader/uniswap/useTradeParameters.ts | 9 +- .../trader/uniswap/useTransactionDeadline.ts | 6 +- .../Trader/trader/uniswap/useUniswapV2Like.ts | 9 +- .../Trader/trader/uniswap/useV3BestTrade.ts | 2 +- .../trader/useAllProviderTradeContext.ts | 11 +- .../Trader/trader/useAllTradeComputed.ts | 8 +- .../Trader/trader/useNativeTradeGasLimit.ts | 11 +- .../Trader/trader/useTargetBlockNumber.ts | 12 +- .../Trader/trader/useTargetChainIdContext.ts | 6 +- .../Trader/trader/useTradeApproveComputed.ts | 10 +- .../Trader/trending/useAvailableCoins.ts | 8 +- .../trending/useAvailableDataProviders.ts | 7 +- .../trending/useAvailableTraderProviders.ts | 6 +- .../Trader/trending/useCurrentDataProvider.ts | 7 +- .../plugins/Trader/trending/usePriceStats.ts | 5 +- .../plugins/Trader/trending/useTrending.ts | 15 +- .../mask/src/plugins/Trader/types/bancor.ts | 7 +- .../mask/src/plugins/Trader/types/dodo.ts | 7 +- .../src/plugins/Trader/types/openocean.ts | 7 +- .../mask/src/plugins/Trader/types/trader.ts | 27 +- .../Transak/hooks/useTransakAllowanceCoin.ts | 7 +- .../SNSAdaptor/UnlockProtocolDialog.tsx | 9 +- .../SNSAdaptor/UnlockProtocolInPost.tsx | 25 +- .../mask/src/plugins/UnlockProtocol/base.ts | 2 +- .../plugins/UnlockProtocol/utils/crypto.ts | 6 +- .../src/plugins/Wallet/Dashboard/index.tsx | 10 +- .../ConnectionProgress.tsx | 36 +- .../SNSAdaptor/ConnectWalletDialog/index.tsx | 211 +- .../GasSettingDialog/GasSetting.tsx | 8 +- .../GasSettingDialog/GasSetting1559.tsx | 167 +- .../GasSettingDialog/GasSettingBar.tsx | 28 +- .../GasSettingDialog/Prior1559GasSetting.tsx | 119 +- .../SNSAdaptor/GasSettingDialog/index.tsx | 10 +- .../SNSAdaptor/GasSettingDialog/types.ts | 8 +- .../Wallet/SNSAdaptor/RenameWalletDialog.tsx | 78 - .../RestoreLegacyWalletDialog/index.tsx | 69 - .../SNSAdaptor/RiskWarningDialog/index.tsx | 40 +- .../SNSAdaptor/SelectNftContractDialog.tsx | 126 +- .../PluginProviderRender.tsx | 96 +- .../SNSAdaptor/SelectProviderDialog/index.tsx | 88 +- .../Wallet/SNSAdaptor/SelectWalletDialog.tsx | 83 - .../Wallet/SNSAdaptor/TransactionDialog.tsx | 23 +- .../SNSAdaptor/TransactionSnackbar/index.tsx | 132 +- .../FirefoxPlatform.tsx | 11 - .../WalletConnectQRCodeDialog/Icons.tsx | 181 -- .../WalletConnectQRCodeDialog/QRCodeModel.tsx | 36 - .../WalletConnectQRCodeDialog/README.md | 21 - .../SafariPlatform.tsx | 53 - .../WalletConnectQRCodeDialog/index.tsx | 106 - .../TransactionDescription.tsx | 167 -- .../getITO_Description.tsx | 47 - .../getNFTRedpacketDescription.tsx | 20 - .../getRedpacketDescription.tsx | 60 - .../contractMethodDescription/index.ts | 13 - .../SNSAdaptor/WalletStatusDialog/index.tsx | 9 +- .../SNSAdaptor/WalletStatusDialog/type.ts | 7 - .../src/plugins/Wallet/SNSAdaptor/index.tsx | 8 - .../mask/src/plugins/Wallet/apis/debank.ts | 59 - packages/mask/src/plugins/Wallet/apis/ens.ts | 39 - .../mask/src/plugins/Wallet/apis/metaswap.ts | 13 - .../mask/src/plugins/Wallet/apis/nftscan.ts | 75 - .../mask/src/plugins/Wallet/apis/opensea.ts | 161 -- .../mask/src/plugins/Wallet/apis/zerion.ts | 87 - packages/mask/src/plugins/Wallet/constants.ts | 7 +- .../src/plugins/Wallet/database/Plugin.db.ts | 20 +- .../src/plugins/Wallet/database/Wallet.db.ts | 37 +- .../mask/src/plugins/Wallet/database/types.ts | 61 - packages/mask/src/plugins/Wallet/helpers.ts | 37 +- .../mask/src/plugins/Wallet/hooks/index.ts | 5 - .../hooks/useClearRecentTransactions.ts | 13 - .../Wallet/hooks/useRecentTransactions.ts | 24 - .../hooks/useRemoveRecentTransaction.ts | 16 - .../src/plugins/Wallet/hooks/useTokenPrice.ts | 67 - .../hooks/useWalletRiskWarningDialog.ts | 23 - .../mask/src/plugins/Wallet/pipes/index.ts | 35 +- .../src/plugins/Wallet/services/account.ts | 104 +- .../plugins/Wallet/services/addressBook.ts | 62 - .../src/plugins/Wallet/services/assets.ts | 207 -- .../mask/src/plugins/Wallet/services/cloud.ts | 36 - .../src/plugins/Wallet/services/domain.ts | 103 - .../src/plugins/Wallet/services/erc1155.ts | 25 - .../mask/src/plugins/Wallet/services/erc20.ts | 79 - .../src/plugins/Wallet/services/erc721.ts | 60 - .../plugins/Wallet/services/estimateGasFee.ts | 6 - .../src/plugins/Wallet/services/gasPrice.ts | 6 - .../src/plugins/Wallet/services/helpers.ts | 81 +- .../mask/src/plugins/Wallet/services/index.ts | 11 +- .../plugins/Wallet/services/legacyWallet.ts | 47 +- .../src/plugins/Wallet/services/nftscan.ts | 5 - .../mask/src/plugins/Wallet/services/rpc.ts | 2 +- .../src/plugins/Wallet/services/tokenPrice.ts | 120 - .../Wallet/services/transaction/database.ts | 115 - .../Wallet/services/transaction/helpers.ts | 96 - .../Wallet/services/transaction/index.ts | 116 - .../Wallet/services/transaction/progress.ts | 59 - .../Wallet/services/transaction/watcher.ts | 237 -- .../plugins/Wallet/services/transactions.ts | 133 -- .../Wallet/services/wallet/database/index.ts | 1 - .../Wallet/services/wallet/database/token.ts | 158 -- .../Wallet/services/wallet/database/wallet.ts | 119 +- .../plugins/Wallet/services/wallet/index.ts | 146 +- .../plugins/Wallet/services/wallet/locker.ts | 2 +- .../services/wallet/maskwallet/index.ts | 88 - .../plugins/Wallet/services/wallet/type.ts | 24 +- packages/mask/src/plugins/Wallet/settings.ts | 51 +- .../mask/src/plugins/Wallet/types/debank.ts | 163 -- .../mask/src/plugins/Wallet/types/index.ts | 8 +- .../mask/src/plugins/Wallet/types/metaswap.ts | 13 - .../src/plugins/Wallet/types/portfolio.ts | 35 - .../mask/src/plugins/Wallet/types/zerion.ts | 146 -- .../src/plugins/dHEDGE/UI/InvestDialog.tsx | 29 +- .../mask/src/plugins/dHEDGE/UI/PoolStats.tsx | 2 +- .../mask/src/plugins/dHEDGE/UI/PoolView.tsx | 16 +- .../src/plugins/dHEDGE/UI/PoolViewDeck.tsx | 10 +- .../plugins/dHEDGE/contracts/useDHedgePool.ts | 15 +- .../plugins/dHEDGE/hooks/useInvestCallback.ts | 17 +- .../src/plugins/dHEDGE/hooks/useManager.ts | 2 +- .../mask/src/plugins/dHEDGE/hooks/usePool.ts | 8 +- .../src/plugins/hooks/usePriceLineChart.ts | 2 +- packages/mask/src/settings/listener.ts | 18 - packages/mask/src/settings/settings.ts | 10 +- .../injection/NFT/ProfileNFTAvatar.tsx | 19 +- .../injection/NFT/NFTAvatarSettingDialog.tsx | 11 +- .../injection/NFT/NFTAvatarInTwitter.tsx | 9 +- packages/mask/src/social-network/ui.ts | 28 +- packages/mask/src/tsconfig.json | 5 +- packages/mask/src/utils/native-rpc/Web.ts | 17 +- packages/mask/src/web3/UI/ChainBoundary.tsx | 232 ++ .../src/web3/UI/ERC721ContractSelectPanel.tsx | 67 +- packages/mask/src/web3/UI/EthereumBlockie.tsx | 2 +- .../src/web3/UI/EthereumChainBoundary.tsx | 323 --- .../UI/EthereumERC20TokenApprovedBoundary.tsx | 11 +- .../EthereumERC721TokenApprovedBoundary.tsx | 28 +- packages/mask/src/web3/UI/SelectTokenChip.tsx | 9 +- .../mask/src/web3/UI/TokenAmountPanel.tsx | 11 +- ...undary.tsx => WalletConnectedBoundary.tsx} | 37 +- packages/mask/src/web3/context.ts | 265 --- packages/mask/utils-pure/index.ts | 1 - packages/mask/web-workers/wallet.ts | 38 - packages/plugin-infra/package.json | 23 +- packages/plugin-infra/src/entry-web3-evm.ts | 1 + packages/plugin-infra/src/entry-web3.ts | 4 +- packages/plugin-infra/src/hooks/index.ts | 2 - .../src/hooks/useActivatedPluginWeb3State.ts | 6 +- .../src/hooks/useActivatedPluginWeb3UI.ts | 6 +- .../src/hooks/useAllPluginsWeb3State.ts | 11 +- .../plugin-infra/src/hooks/useLookupDomain.ts | 16 - .../src/hooks/useReverseAddress.ts | 14 - .../plugin-infra/src/manager/sns-adaptor.ts | 40 +- packages/plugin-infra/src/manager/store.ts | 40 +- packages/plugin-infra/src/types.ts | 262 ++- .../plugin-infra/src/utils/subscription.ts | 10 + .../plugin-infra/src/web3-helpers/index.ts | 217 ++ .../src/web3-state/AddressBook.ts | 58 + .../plugin-infra/src/web3-state/Connection.ts | 80 + packages/plugin-infra/src/web3-state/Hub.ts | 37 + .../plugin-infra/src/web3-state/Identity.ts | 23 + .../src/web3-state/NameService.ts | 74 + .../plugin-infra/src/web3-state/Others.ts | 79 + .../plugin-infra/src/web3-state/Provider.ts | 189 ++ .../src/web3-state/RiskWarning.ts | 55 + .../plugin-infra/src/web3-state/Settings.ts | 37 + packages/plugin-infra/src/web3-state/Token.ts | 144 ++ .../src/web3-state/Transaction.ts | 185 ++ .../src/web3-state/TransactionFormatter.ts | 30 + .../src/web3-state/TransactionWatcher.ts | 165 ++ .../plugin-infra/src/web3-state/Wallet.ts | 25 + packages/plugin-infra/src/web3-state/index.ts | 14 + packages/plugin-infra/src/web3-types.ts | 470 +--- packages/plugin-infra/src/web3/Context.tsx | 135 +- packages/plugin-infra/src/web3/EVM/index.ts | 25 + .../src/web3/EVM}/useBalanceChecker.ts | 9 +- .../plugin-infra/src/web3/EVM/useContract.ts | 37 + .../src/web3/EVM/useERC1155TokenContract.ts | 8 + .../src/web3/EVM}/useERC165.ts | 13 +- .../src/web3/EVM/useERC165Contract.ts | 9 + .../src/web3/EVM}/useERC20TokenAllowance.ts | 15 +- .../web3/EVM}/useERC20TokenApproveCallback.ts | 18 +- .../web3/EVM/useERC20TokenBytes32Contract.ts | 13 + .../src/web3/EVM/useERC20TokenContract.ts | 13 + .../src/web3/EVM/useERC20TokenTotalSupply.ts | 13 + .../EVM}/useERC20TokenTransferCallback.ts | 19 +- .../EVM}/useERC721ContractIsApproveForAll.ts | 9 +- ...eERC721ContractSetApproveForAllCallback.ts | 15 +- .../src/web3/EVM/useERC721TokenByIndex.ts | 19 + .../src/web3/EVM/useERC721TokenContract.ts | 9 + .../src/web3/EVM/useERC721TokenContracts.ts | 9 + .../EVM}/useERC721TokenTransferCallback.ts | 19 +- .../plugin-infra/src/web3/EVM/useGasLimit.ts | 51 + .../src/web3/EVM/useGetPastLogsParams.ts | 32 + .../src/web3/EVM}/useMulticall.ts | 23 +- .../src/web3/EVM}/useMulticallContract.ts | 9 +- .../EVM}/useNativeTokenTransferCallback.ts | 18 +- .../EVM}/useNativeTokenWrapperCallback.ts | 12 +- .../src/web3/EVM/useNonFungibleOwnerTokens.ts | 61 + .../src/web3/EVM/useReverseLookupContract.ts | 10 + .../src/web3/EVM}/useTokenTransferCallback.ts | 12 +- .../src/web3/EVM}/useTransactionCallback.ts | 4 +- .../src/web3/EVM/useTransactionState.ts | 13 + .../src/web3/EVM}/useWrappedEtherContract.ts | 9 +- packages/plugin-infra/src/web3/index.ts | 79 +- packages/plugin-infra/src/web3/useAccount.ts | 19 +- .../plugin-infra/src/web3/useAddressBook.ts | 9 + .../plugin-infra/src/web3/useAddressNames.ts | 20 + .../plugin-infra/src/web3/useAllowTestnet.ts | 11 +- .../plugin-infra/src/web3/useAssetType.ts | 6 - packages/plugin-infra/src/web3/useBalance.ts | 21 +- packages/plugin-infra/src/web3/useBeat.ts | 47 +- .../plugin-infra/src/web3/useBlockNumber.ts | 19 +- .../src/web3/useBlockTimestamp.ts | 20 + .../src/web3/useBlockedFungibleTokens.ts | 23 + .../src/web3/useBlockedNonFungibleTokens.ts | 23 + .../src/web3}/useBlockie.ts | 0 .../plugin-infra/src/web3/useChainColor.ts | 17 +- .../src/web3/useChainDescriptor.ts | 14 + .../plugin-infra/src/web3/useChainDetailed.ts | 9 - packages/plugin-infra/src/web3/useChainId.ts | 22 +- .../src/web3/useChainIdMainnet.ts | 16 + .../src/web3/useChainIdMatched.ts | 11 + .../src/web3/useChainIdSupport.ts | 17 + .../plugin-infra/src/web3/useChainIdValid.ts | 24 +- .../src/web3/useClearTransactionsCallback.ts | 19 + .../src/web3/useCollectibleType.ts | 6 - .../plugin-infra/src/web3/useCurrencyType.ts | 11 +- .../src/web3/useDefaultChainId.ts | 17 + .../src/web3/useDefaultNetworkType.ts | 17 + .../plugin-infra/src/web3/useFungibleAsset.ts | 23 + .../src/web3/useFungibleAssetSourceType.ts | 9 + .../src/web3/useFungibleAssets.ts | 27 + .../plugin-infra/src/web3/useFungibleToken.ts | 22 + .../src/web3/useFungibleTokenBalance.ts | 19 + .../src/web3/useFungibleTokenPrice.ts | 21 + .../src/web3/useFungibleTokenWatched.ts | 20 + .../src/web3/useFungibleTokens.ts | 20 + .../src/web3/useFungibleTokensBalance.ts | 23 + .../web3/useFungibleTokensFromTokenList.ts | 21 + .../plugin-infra/src/web3/useGasOptionType.ts | 9 + .../plugin-infra/src/web3/useGasOptions.ts | 20 + packages/plugin-infra/src/web3/useGasPrice.ts | 12 + .../src/web3}/useImageChecker.ts | 0 .../plugin-infra/src/web3/useLookupAddress.ts | 17 + packages/plugin-infra/src/web3/useNameType.ts | 6 - .../plugin-infra/src/web3/useNativeToken.ts | 9 + .../src/web3/useNativeTokenAddress.ts | 16 + .../src/web3/useNativeTokenBalance.ts | 20 + .../src/web3/useNativeTokenPrice.ts | 22 + .../src/web3/useNetworkDescriptor.ts | 15 +- .../src/web3/useNetworkDescriptors.ts | 12 +- .../plugin-infra/src/web3/useNetworkType.ts | 20 +- .../src/web3/useNonFungibleAsset.ts | 25 + .../src/web3/useNonFungibleAssetSourceType.ts | 9 + .../src/web3/useNonFungibleAssets.ts | 28 + .../src/web3/useNonFungibleCollections.ts | 26 + .../src/web3/useNonFungibleToken.ts | 24 + .../src/web3/useNonFungibleTokenBalance.ts | 22 + .../src/web3/useNonFungibleTokenContract.ts | 23 + .../src/web3/useNonFungibleTokenPrice.ts | 27 + .../src/web3/useNonFungibleTokens.ts | 21 + .../src/web3/useNonFungibleTokensBalance.ts | 23 + .../web3/useNonFungibleTokensFromTokenList.ts | 21 + .../src/web3/useProviderDescriptor.ts | 13 +- .../src/web3/useProviderDescriptors.ts | 12 +- .../plugin-infra/src/web3/useProviderReady.ts | 18 + .../plugin-infra/src/web3/useProviderType.ts | 18 +- .../src/web3/useRecentTransactions.ts | 21 + .../src/web3/useRemoveTransaction.ts | 26 + .../src/web3/useReverseAddress.ts | 20 + .../src/web3/useRiskWarningApproved.ts | 9 + .../plugin-infra/src/web3/useSchemaType.ts | 21 + .../src/web3}/useSocketOnce.ts | 0 .../plugin-infra/src/web3/useTokenPrice.ts | 7 - .../src/web3/useTransactionType.ts | 6 - .../plugin-infra/src/web3/useTransactions.ts | 17 + .../src/web3/useTrustedFungibleTokens.ts | 23 + .../src/web3/useTrustedNonFungibleTokens.ts | 23 + packages/plugin-infra/src/web3/useWallet.ts | 17 +- .../plugin-infra/src/web3/useWalletPrimary.ts | 11 +- packages/plugin-infra/src/web3/useWallets.ts | 11 +- packages/plugin-infra/src/web3/useWeb3.ts | 28 + .../src/web3/useWeb3Connection.ts | 31 + packages/plugin-infra/src/web3/useWeb3Hub.ts | 33 + .../plugin-infra/src/web3/useWeb3Provider.ts | 31 + .../plugin-infra/src/web3/useWeb3State.ts | 8 +- packages/plugin-infra/src/web3/useWeb3UI.ts | 8 +- .../plugin-infra/src/web3/useZeroAddress.ts | 10 + packages/plugin-infra/tsconfig.json | 4 + .../src/SNSAdaptor/CrossChainBridgeDialog.tsx | 1 + packages/plugins/CyberConnect/package.json | 1 + .../src/SNSAdaptor/ConnectButton.tsx | 10 +- packages/plugins/CyberConnect/src/base.tsx | 13 - packages/plugins/CyberConnect/tsconfig.json | 1 + .../plugins/DAO/src/components/DAOPage.tsx | 2 +- .../src/SNSAdaptor/components/TabContent.tsx | 8 +- packages/plugins/EVM/package.json | 46 + .../plugins/EVM/src/UI/Dashboard/index.tsx | 46 + .../plugins/EVM/src/UI/SNSAdaptor/index.tsx | 46 + .../EVM => plugins/EVM/src}/Worker/index.ts | 0 packages/plugins/EVM/src/assets/nft.png | Bin 0 -> 12065 bytes packages/plugins/EVM/src/base.ts | 19 + packages/plugins/EVM/src/constants/index.ts | 5 + packages/plugins/EVM/src/env.d.ts | 10 + packages/plugins/EVM/src/hooks/index.ts | 1 + .../plugins/EVM/src/hooks/useProviderReady.ts | 7 + .../plugins/EVM => plugins/EVM/src}/index.ts | 33 +- packages/plugins/EVM/src/locales/en-US.json | 1 + packages/plugins/EVM/src/locales/index.ts | 6 + packages/plugins/EVM/src/locales/languages.ts | 19 + .../EVM => plugins/EVM/src}/messages.ts | 18 - .../types.ts => plugins/EVM/src/services.ts} | 0 packages/plugins/EVM/src/settings/index.ts | 6 + packages/plugins/EVM/src/state/AddressBook.ts | 25 + packages/plugins/EVM/src/state/Connection.ts | 42 + .../EVM/src/state/Connection/composer.ts | 211 ++ .../EVM/src/state/Connection/connection.ts | 677 ++++++ .../EVM/src/state/Connection}/error.ts | 14 +- .../Connection/interceptors/MaskWallet.ts | 79 + .../state/Connection/interceptors/MetaMask.ts | 18 + .../Connection/interceptors/WalletConnect.ts | 30 + .../Connection/middleware/AddressBook.ts | 41 + .../Connection/middleware/Interceptor.ts | 22 + .../src/state/Connection/middleware/Nonce.ts | 156 ++ .../src/state/Connection/middleware/Popup.ts | 96 + .../src/state/Connection/middleware/Squash.ts | 78 + .../Connection/middleware/Transaction.ts | 66 + .../state/Connection/middleware/Translator.ts | 24 + .../EVM/src/state/Connection/provider.ts | 26 + .../src/state/Connection/providers/Base.ts | 95 + .../Connection/providers/BaseInjected.ts | 74 + .../src/state/Connection/providers/Coin98.ts | 10 + .../Connection/providers/CustomNetwork.ts | 4 + .../state/Connection/providers/Fortmatic.ts | 111 + .../state/Connection/providers/MaskWallet.ts | 139 ++ .../state/Connection/providers/MathWallet.ts | 10 + .../state/Connection/providers/MetaMask.ts | 26 + .../src/state/Connection/providers/Torus.ts | 95 + .../Connection/providers/WalletConnect.ts | 178 ++ .../state/Connection/providers/WalletLink.ts | 10 + .../src/state/Connection/translators/Base.ts | 62 + .../src/state/Connection/translators/Celo.ts | 11 + .../Connection/translators/Optimistic.ts | 11 + .../state/Connection/translators/Polygon.ts | 27 + .../plugins/EVM/src/state/Connection/types.ts | 77 + .../plugins/EVM/src/state/Connection/utils.ts | 10 + packages/plugins/EVM/src/state/Hub.ts | 20 + .../state/Hub/TokenIconSpecialIconList.json | 197 ++ packages/plugins/EVM/src/state/Hub/hub.ts | 206 ++ packages/plugins/EVM/src/state/Hub/types.ts | 4 + .../plugins/EVM/src/state/IdentityService.ts | 106 + packages/plugins/EVM/src/state/NameService.ts | 61 + packages/plugins/EVM/src/state/Others.ts | 38 + packages/plugins/EVM/src/state/Provider.ts | 61 + packages/plugins/EVM/src/state/RiskWarning.ts | 23 + packages/plugins/EVM/src/state/Settings.ts | 8 + packages/plugins/EVM/src/state/Token.ts | 26 + packages/plugins/EVM/src/state/Transaction.ts | 24 + .../EVM/src/state/TransactionFormatter.ts | 143 ++ .../EVM/src/state/TransactionFormatter/abi.ts | 68 + .../TransactionFormatter/descriptors/Base.ts | 24 + .../descriptors/Cancel.ts | 11 + .../descriptors/ContractDeployment.ts | 24 + .../TransactionFormatter/descriptors/ERC20.ts | 44 + .../TransactionFormatter/descriptors/ITO.ts | 31 + .../descriptors/RedPacket.ts | 42 + .../descriptors/TransferToken.ts | 23 + .../descriptors/Uniswap.ts | 16 + .../src/state/TransactionFormatter/types.ts | 35 + .../src/state/TransactionFormatter/utils.ts | 14 + .../EVM/src/state/TransactionWatcher.ts | 12 + .../src/state/TransactionWatcher/checker.ts | 4 + .../checkers/AccountChecker.ts | 8 + .../checkers/ReceiptChecker.ts | 8 + packages/plugins/EVM/src/state/Wallet.ts | 8 + packages/plugins/EVM/src/state/index.ts | 60 + packages/plugins/EVM/src/types/index.ts | 9 + packages/plugins/EVM/tsconfig.json | 20 + packages/plugins/FileService/src/helpers.ts | 5 +- packages/plugins/Flow/package.json | 8 +- .../plugins/Flow/src/UI/Dashboard/index.tsx | 46 +- .../plugins/Flow/src/UI/SNSAdaptor/index.tsx | 44 +- .../plugins/Flow/src/UI/Web3State/index.ts | 62 - packages/plugins/Flow/src/UI/Web3UI/index.tsx | 9 - .../UI/components/ProviderIconClickBait.tsx | 38 - ...getFungibleAssets.ts => fungibleAssets.ts} | 70 +- packages/plugins/Flow/src/apis/index.ts | 2 +- packages/plugins/Flow/src/base.ts | 16 +- packages/plugins/Flow/src/constants.ts | 37 +- packages/plugins/Flow/src/env.d.ts | 36 +- .../plugins/Flow/src/helpers/formatter.ts | 9 + packages/plugins/Flow/src/helpers/token.ts | 29 +- packages/plugins/Flow/src/index.ts | 31 +- packages/plugins/Flow/src/settings/index.ts | 6 + .../plugins/Flow/src/state/AddressBook.ts | 25 + packages/plugins/Flow/src/state/Connection.ts | 46 + .../Flow/src/state/Connection/connection.ts | 225 ++ .../Flow/src/state/Connection/provider.ts | 11 + .../src/state/Connection/providers/Base.ts | 34 + .../src/state/Connection/providers/Blocto.ts | 24 + .../src/state/Connection/providers/Dapper.ts | 4 + .../src/state/Connection/providers/Ledger.ts | 4 + .../Flow/src/state/Connection/types.ts | 11 + packages/plugins/Flow/src/state/Hub.ts | 20 + packages/plugins/Flow/src/state/Hub/hub.ts | 172 ++ packages/plugins/Flow/src/state/Hub/types.ts | 4 + packages/plugins/Flow/src/state/Others.ts | 47 + packages/plugins/Flow/src/state/Provider.ts | 48 + packages/plugins/Flow/src/state/Settings.ts | 8 + .../plugins/Flow/src/state/Transaction.ts | 25 + packages/plugins/Flow/src/state/Wallet.ts | 8 + packages/plugins/Flow/src/state/index.ts | 36 + packages/plugins/Flow/src/storage/index.ts | 18 - packages/plugins/Flow/src/types.ts | 3 - packages/plugins/Flow/tsconfig.json | 2 + packages/plugins/GoPlusSecurity/package.json | 1 + .../src/SNSAdaptor/components/SearchBox.tsx | 24 +- .../src/SNSAdaptor/components/TokenPanel.tsx | 18 +- packages/plugins/GoPlusSecurity/src/base.ts | 1 - packages/plugins/GoPlusSecurity/tsconfig.json | 8 +- .../plugins/RSS3/src/SNSAdaptor/TabCard.tsx | 10 +- .../plugins/RSS3/src/SNSAdaptor/index.tsx | 19 +- packages/plugins/RSS3/src/base.ts | 3 +- packages/plugins/Solana/package.json | 9 + .../plugins/Solana/src/UI/Dashboard/index.tsx | 46 +- .../Solana/src/UI/SNSAdaptor/index.tsx | 47 +- .../plugins/Solana/src/UI/Web3State/index.ts | 66 - .../plugins/Solana/src/UI/Web3UI/index.tsx | 8 - .../UI/components/ProviderIconClickBait.tsx | 30 +- .../Solana/src/apis/getFungibleAssets.ts | 47 +- .../Solana/src/apis/getNonFungibleAssets.ts | 41 +- packages/plugins/Solana/src/assets/torus.png | Bin 0 -> 3975 bytes packages/plugins/Solana/src/base.ts | 16 +- packages/plugins/Solana/src/constants.ts | 39 +- packages/plugins/Solana/src/env.d.ts | 1 + .../plugins/Solana/src/helpers/formatter.ts | 12 - packages/plugins/Solana/src/helpers/index.ts | 1 - packages/plugins/Solana/src/helpers/token.ts | 29 +- packages/plugins/Solana/src/index.ts | 32 +- packages/plugins/Solana/src/settings/index.ts | 6 + .../plugins/Solana/src/state/AddressBook.ts | 25 + .../plugins/Solana/src/state/Connection.ts | 42 + .../Solana/src/state/Connection/connection.ts | 246 ++ .../Solana/src/state/Connection/provider.ts | 13 + .../src/state/Connection/providers/Base.ts | 52 + .../Connection/providers/BaseInjected.ts | 63 + .../src/state/Connection/providers/Coin98.ts | 48 + .../src/state/Connection/providers/Phantom.ts | 42 + .../Connection/providers/SolflareProvider.ts | 28 + .../src/state/Connection/providers/Sollet.ts | 54 + .../Solana/src/state/Connection/types.ts | 21 + packages/plugins/Solana/src/state/Hub.ts | 20 + packages/plugins/Solana/src/state/Hub/hub.ts | 144 ++ .../plugins/Solana/src/state/Hub/types.ts | 4 + packages/plugins/Solana/src/state/Others.ts | 36 + packages/plugins/Solana/src/state/Provider.ts | 48 + packages/plugins/Solana/src/state/Settings.ts | 8 + packages/plugins/Solana/src/state/Token.ts | 26 + .../plugins/Solana/src/state/Transaction.ts | 23 + packages/plugins/Solana/src/state/Wallet.ts | 8 + packages/plugins/Solana/src/state/index.ts | 39 + packages/plugins/Solana/src/storage/index.ts | 17 - packages/plugins/Solana/src/types.ts | 3 - packages/plugins/Solana/src/utils.ts | 7 - packages/plugins/Solana/src/utils/index.ts | 28 + packages/plugins/Solana/src/wallet/connect.ts | 46 - packages/plugins/Solana/src/wallet/index.ts | 1 - packages/plugins/Solana/tsconfig.json | 3 +- packages/plugins/Wallet/package.json | 1 + packages/plugins/Wallet/src/constants.ts | 10 - packages/plugins/Wallet/src/messages.ts | 123 +- packages/plugins/Wallet/tsconfig.json | 1 + packages/plugins/tsconfig.json | 2 + packages/public-api/src/web.ts | 48 +- packages/shared-base/src/Identifier/ec-key.ts | 2 +- packages/shared-base/src/Messages/Mask.ts | 27 +- packages/shared-base/src/Site/index.ts | 43 + packages/shared-base/src/index.ts | 3 +- .../src/onDemandWorker}/index.ts | 0 .../shared-base/src/utils/asyncIterator.ts | 5 + .../src/utils/createValueRefWithReady.ts | 26 + packages/shared-base/src/utils/index.ts | 2 + .../shared-base/src/utils/subscription.ts | 18 +- packages/shared/package.json | 1 + .../src/UI/components/AddressViewer/index.tsx | 38 +- .../src/UI/components/AssetPlayer/index.tsx | 13 +- .../UI/components/ERC20TokenList/index.tsx | 159 -- .../FungibleTokenItem.tsx} | 103 +- .../UI/components/FungibleTokenList/index.tsx | 192 ++ .../NFTCardStyledAssetPlayer/index.tsx | 21 +- .../UI/components/ReversedAddress/index.tsx | 13 +- .../UI/components/SelectTokenChip/index.tsx | 9 +- .../UI/components/TokenAmountPanel/index.tsx | 9 +- .../src/UI/components/TokenIcon/index.tsx | 60 +- packages/shared/src/UI/components/index.ts | 2 +- packages/shared/src/UI/index.ts | 1 - .../evm/TokenPicker/SelectTokenDialog.tsx | 24 +- .../src/contexts/evm/TokenPicker/index.tsx | 79 +- packages/shared/src/hooks/index.ts | 1 + packages/shared/src/hooks/useImageFailOver.ts | 27 + .../shared/src/hooks/useOpenShareTxDialog.tsx | 10 +- packages/shared/src/index.ts | 2 - packages/shared/src/utils/index.ts | 68 + packages/shared/tsconfig.json | 9 +- packages/web3-constants/evm/lbp.json | 25 - packages/web3-constants/evm/rpc.json | 2 +- packages/web3-constants/evm/token-list.json | 27 +- packages/web3-constants/flow/chain.json | 18 + packages/web3-constants/solana/chain.json | 22 + packages/web3-contracts/abis/ERC165.json | 21 + packages/web3-contracts/types/ERC165.d.ts | 33 + packages/web3-providers/package.json | 1 + packages/web3-providers/src/NFTScan/index.ts | 138 +- .../web3-providers/src/coingecko/constants.ts | 1 - .../web3-providers/src/coingecko/index.ts | 42 +- packages/web3-providers/src/debank/format.ts | 126 +- packages/web3-providers/src/debank/index.ts | 122 +- packages/web3-providers/src/debank/type.ts | 1 + .../web3-providers/src/gopluslabs/index.ts | 10 +- packages/web3-providers/src/hooks/index.ts | 1 - .../hooks/useERC721TokenDetailedOwnerList.ts | 100 - packages/web3-providers/src/index.ts | 21 +- packages/web3-providers/src/mask/index.ts | 86 + packages/web3-providers/src/mask/prepare.ts | 15 + packages/web3-providers/src/mask/worker.ts | 26 + packages/web3-providers/src/metaswap/index.ts | 35 + packages/web3-providers/src/metaswap/types.ts | 13 + packages/web3-providers/src/opensea/index.ts | 527 +++-- packages/web3-providers/src/opensea/types.ts | 73 +- packages/web3-providers/src/rarible/index.ts | 324 ++- .../web3-providers/src/risk-warning/index.ts | 22 + packages/web3-providers/src/rss3/index.ts | 51 +- .../web3-providers/src/token-list/index.ts | 72 +- .../web3-providers/src/token-price/index.ts | 21 - packages/web3-providers/src/types.ts | 336 +-- packages/web3-providers/src/zerion/format.ts | 98 +- packages/web3-providers/src/zerion/index.ts | 107 +- packages/web3-providers/src/zora/index.ts | 690 +++--- packages/web3-shared/base/package.json | 6 + .../web3-shared/base/src/helpers/index.ts | 3 - .../base/src/helpers/lookupTable.ts | 7 - .../web3-shared/base/src/helpers/types.ts | 1 - packages/web3-shared/base/src/hooks/index.ts | 1 - .../web3-shared/base/src/hooks/useBeat.ts | 17 - packages/web3-shared/base/src/index.ts | 3 +- packages/web3-shared/base/src/specs/index.ts | 964 ++++++++ .../web3-shared/base/src/utils/address.ts | 19 + .../web3-shared/base/src/utils/balance.ts | 29 + .../constants.ts => utils/constant.ts} | 30 +- .../web3-shared/base/src/utils/currency.ts | 7 + packages/web3-shared/base/src/utils/index.ts | 9 + .../web3-shared/base/src/utils/pagination.ts | 7 + .../web3-shared/base/src/utils/predicate.ts | 3 + .../web3-shared/base/src/utils/resolver.ts | 159 ++ packages/web3-shared/base/src/utils/token.ts | 139 ++ packages/web3-shared/base/src/utils/types.ts | 13 + packages/web3-shared/base/tsconfig.json | 2 +- .../evm}/assets/arbitrum.png | Bin .../EVM => web3-shared/evm}/assets/aurora.png | Bin .../evm}/assets/avalanche.png | Bin .../evm}/assets/binance.png | Bin .../EVM => web3-shared/evm}/assets/celo.png | Bin .../EVM => web3-shared/evm}/assets/coin98.png | Bin .../evm}/assets/coinbase.png | Bin .../evm}/assets/conflux.png | Bin .../evm}/assets/ethereum.png | Bin .../EVM => web3-shared/evm}/assets/fantom.png | Bin .../evm}/assets/fortmatic.png | Bin .../evm}/assets/harmony.png | Bin .../evm}/assets/lucky_drop.png | Bin .../evm}/assets/maskwallet.png | Bin .../evm}/assets/mathwallet.png | Bin .../evm}/assets/metamask.png | Bin .../EVM => web3-shared/evm}/assets/nfts.png | Bin .../evm}/assets/polygon.png | Bin packages/web3-shared/evm/assets/torus.png | Bin 0 -> 3975 bytes .../evm}/assets/walletconnect.png | Bin .../EVM => web3-shared/evm}/assets/xdai.png | Bin packages/web3-shared/evm/constants/README.md | 11 - .../evm/{assets => constants}/chains.json | 2020 +++++++++-------- .../web3-shared/evm/constants/constants.ts | 61 +- .../web3-shared/evm/constants/descriptors.ts | 334 +++ packages/web3-shared/evm/constants/index.ts | 2 +- packages/web3-shared/evm/constants/tokens.ts | 22 +- packages/web3-shared/evm/constants/utils.ts | 58 - packages/web3-shared/evm/context/index.tsx | 62 - packages/web3-shared/evm/context/type.ts | 89 - packages/web3-shared/evm/contracts/index.ts | 5 - .../evm/contracts/useERC1155TokenContract.ts | 8 - .../contracts/useERC20TokenBytes32Contract.ts | 13 - .../evm/contracts/useERC20TokenContract.ts | 13 - .../evm/contracts/useERC721TokenContract.ts | 9 - .../evm/contracts/useERC721TokenContracts.ts | 8 - .../evm/contracts/useReverseLookupContract.ts | 11 - packages/web3-shared/evm/hooks/index.ts | 72 - packages/web3-shared/evm/hooks/useAccount.ts | 10 - .../evm/hooks/useAddERC20TokenCallback.ts | 15 - .../web3-shared/evm/hooks/useAddressNames.ts | 26 - .../web3-shared/evm/hooks/useAllowTestnet.ts | 5 - packages/web3-shared/evm/hooks/useAssets.ts | 57 - .../evm/hooks/useAssetsByTokenList.ts | 59 - .../evm/hooks/useAssetsFromChain.ts | 53 - .../evm/hooks/useAssetsFromProvider.ts | 25 - .../web3-shared/evm/hooks/useAssetsMerged.ts | 27 - packages/web3-shared/evm/hooks/useBalance.ts | 16 - .../web3-shared/evm/hooks/useBlockNumber.ts | 15 - .../web3-shared/evm/hooks/useChainColor.ts | 7 - .../web3-shared/evm/hooks/useChainDetailed.ts | 5 - .../evm/hooks/useChainEIP1159Supported.ts | 6 - packages/web3-shared/evm/hooks/useChainId.ts | 29 - .../web3-shared/evm/hooks/useChainIdValid.ts | 5 - .../web3-shared/evm/hooks/useCollectibles.ts | 62 - packages/web3-shared/evm/hooks/useContract.ts | 42 - .../evm/hooks/useCurrentBlockTimestamp.ts | 18 - packages/web3-shared/evm/hooks/useENSLabel.ts | 34 - .../evm/hooks/useERC1155TokenAssetDetailed.ts | 14 - .../evm/hooks/useERC20TokenBalance.ts | 30 - .../evm/hooks/useERC20TokenDetailed.ts | 93 - .../useERC20TokenDetailedFromTokenLists.ts | 20 - .../evm/hooks/useERC20TokenTotalSupply.ts | 14 - .../web3-shared/evm/hooks/useERC20Tokens.ts | 15 - .../useERC20TokensDetailedFromTokenLists.ts | 64 - .../evm/hooks/useERC721ContractBalance.ts | 15 - .../evm/hooks/useERC721ContractDetailed.ts | 64 - .../evm/hooks/useERC721TokenByIndex.ts | 14 - .../evm/hooks/useERC721TokenDetailed.ts | 155 -- .../hooks/useERC721TokenDetailedCallback.ts | 48 - .../web3-shared/evm/hooks/useERC721Tokens.ts | 15 - .../evm/hooks/useEthereumTokenType.ts | 42 - .../evm/hooks/useFungibleTokenBalance.ts | 24 - .../evm/hooks/useFungibleTokenDetailed.ts | 29 - .../evm/hooks/useFungibleTokenWatched.tsx | 34 - packages/web3-shared/evm/hooks/useGasLimit.ts | 47 - packages/web3-shared/evm/hooks/useGasPrice.ts | 14 - .../evm/hooks/useGetPastLogsParams.ts | 29 - .../evm/hooks/useNativeTokenBalance.ts | 17 - .../evm/hooks/useNativeTokenDetailed.ts | 9 - .../web3-shared/evm/hooks/useNetworkType.ts | 5 - .../web3-shared/evm/hooks/useProviderType.ts | 5 - .../web3-shared/evm/hooks/useResolveENS.ts | 11 - packages/web3-shared/evm/hooks/useSocket.ts | 65 - .../web3-shared/evm/hooks/useTokensBalance.ts | 28 - .../evm/hooks/useTransactionState.ts | 45 - .../web3-shared/evm/hooks/useTransactions.ts | 29 - .../evm/hooks/useTrustERC20TokenCallback.ts | 17 - .../evm/hooks/useTrustedERC20Tokens.ts | 15 - packages/web3-shared/evm/hooks/useWallet.ts | 9 - .../web3-shared/evm/hooks/useWalletPrimary.ts | 6 - packages/web3-shared/evm/hooks/useWallets.ts | 13 - packages/web3-shared/evm/hooks/useWeb3.ts | 9 - .../web3-shared/evm/hooks/useWeb3Provider.ts | 21 - packages/web3-shared/evm/index.ts | 4 - packages/web3-shared/evm/package.json | 10 +- packages/web3-shared/evm/pipes/index.ts | 241 +- .../web3-shared/evm/providers/Fortmatic.ts | 61 - packages/web3-shared/evm/types/index.ts | 551 +---- packages/web3-shared/evm/utils/abi.ts | 24 + packages/web3-shared/evm/utils/address.ts | 30 +- packages/web3-shared/evm/utils/chain.ts | 5 + .../web3-shared/evm/utils/chainDetailed.ts | 156 -- packages/web3-shared/evm/utils/contract.ts | 55 + packages/web3-shared/evm/utils/domain.ts | 8 + packages/web3-shared/evm/utils/enum.ts | 7 - packages/web3-shared/evm/utils/formatter.ts | 42 +- packages/web3-shared/evm/utils/index.ts | 7 +- packages/web3-shared/evm/utils/misc.ts | 3 - packages/web3-shared/evm/utils/payload.ts | 73 +- packages/web3-shared/evm/utils/provider.ts | 131 +- packages/web3-shared/evm/utils/resolver.ts | 12 + packages/web3-shared/evm/utils/token.ts | 314 +-- packages/web3-shared/evm/utils/transaction.ts | 38 +- packages/web3-shared/flow/assets/FUSD.png | Bin 0 -> 732 bytes packages/web3-shared/flow/assets/blocto.png | Bin 0 -> 6902 bytes packages/web3-shared/flow/assets/flow.png | Bin 0 -> 3063 bytes packages/web3-shared/flow/assets/tUSD.png | Bin 0 -> 4245 bytes .../web3-shared/flow/constants/constants.ts | 14 + .../web3-shared/flow/constants/descriptors.ts | 102 + packages/web3-shared/flow/constants/index.ts | 13 +- .../web3-shared/flow/constants/primitives.ts | 1 + packages/web3-shared/flow/env.d.ts | 1357 ++++++++++- packages/web3-shared/flow/index.ts | 2 +- packages/web3-shared/flow/package.json | 9 +- packages/web3-shared/flow/pipes/index.ts | 44 - packages/web3-shared/flow/sdk/index.ts | 5 +- packages/web3-shared/flow/tsconfig.json | 2 +- packages/web3-shared/flow/types.ts | 34 + packages/web3-shared/flow/utils/address.ts | 16 + packages/web3-shared/flow/utils/domain.ts | 8 + packages/web3-shared/flow/utils/index.ts | 3 + packages/web3-shared/flow/utils/resolver.ts | 17 + packages/web3-shared/solana/assets/coin98.png | Bin 0 -> 8825 bytes .../web3-shared/solana/assets/phantom.png | Bin 0 -> 8430 bytes packages/web3-shared/solana/assets/solana.png | Bin 0 -> 10204 bytes .../web3-shared/solana/assets/solflare.png | Bin 0 -> 2162 bytes packages/web3-shared/solana/assets/sollet.png | Bin 0 -> 21894 bytes packages/web3-shared/solana/assets/usdc.png | Bin 0 -> 5716 bytes packages/web3-shared/solana/coin98.png | Bin 0 -> 8825 bytes .../web3-shared/solana/constants/constants.ts | 10 + .../solana/constants/descriptors.ts | 179 ++ .../web3-shared/solana/constants/index.ts | 9 +- .../solana/constants/primitives.ts | 1 + packages/web3-shared/solana/index.ts | 2 +- packages/web3-shared/solana/package.json | 7 + packages/web3-shared/solana/pipes/index.ts | 45 - packages/web3-shared/solana/tsconfig.json | 7 +- packages/web3-shared/solana/types.ts | 53 + packages/web3-shared/solana/utils/address.ts | 26 + packages/web3-shared/solana/utils/domain.ts | 3 + packages/web3-shared/solana/utils/index.ts | 3 + packages/web3-shared/solana/utils/resolver.ts | 14 + pnpm-lock.yaml | 1069 +++++++-- tsconfig.json | 1 + 1288 files changed, 25960 insertions(+), 26619 deletions(-) delete mode 100644 packages/dashboard/src/hooks/useGasOptions.ts delete mode 100644 packages/dashboard/src/pages/Settings/components/DataSourceSetting.tsx delete mode 100644 packages/dashboard/src/pages/Wallets/api.ts delete mode 100644 packages/dashboard/src/pages/Wallets/components/Transfer/useNativeTokenPrice.ts delete mode 100644 packages/dashboard/src/pages/Wallets/hooks/useAddressBook.ts delete mode 100644 packages/dashboard/src/pages/Wallets/hooks/useRecentTransactions.ts delete mode 100644 packages/dashboard/src/web3/context.ts create mode 100644 packages/injected-script/sdk/Base.ts create mode 100644 packages/injected-script/sdk/Coin98.ts create mode 100644 packages/injected-script/sdk/MathWallet.ts create mode 100644 packages/injected-script/sdk/MetaMask.ts create mode 100644 packages/injected-script/sdk/Phantom.ts create mode 100644 packages/injected-script/sdk/Solflare.ts create mode 100644 packages/injected-script/sdk/WalletLink.ts delete mode 100644 packages/injected-script/sdk/bridgedCoin98.ts delete mode 100644 packages/injected-script/sdk/bridgedEthereum.ts delete mode 100644 packages/injected-script/sdk/bridgedSolana.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumService.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/network.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/nonce.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/provider.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/providers/CustomNetwork.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/providers/Fortmatic.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/providers/Injected.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/providers/MetaMask.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/request.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/rpc/index.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/send.ts delete mode 100644 packages/mask/src/extension/background-script/EthereumServices/web3.ts delete mode 100644 packages/mask/src/extension/popups/pages/Wallet/GasSetting/useGasOptions.ts create mode 100644 packages/mask/src/plugins/Avatar/hooks/useCollectibles.ts rename packages/mask/src/plugins/Collectible/SNSAdaptor/{ => OpenSea}/ActionBar.tsx (65%) rename packages/mask/src/plugins/Collectible/SNSAdaptor/{ => OpenSea}/CheckoutDialog.tsx (79%) rename packages/mask/src/plugins/Collectible/SNSAdaptor/{ => OpenSea}/CheckoutOrder.tsx (66%) rename packages/mask/src/plugins/Collectible/SNSAdaptor/{ => OpenSea}/ListingByHighestBidCard.tsx (71%) rename packages/mask/src/plugins/Collectible/SNSAdaptor/{ => OpenSea}/ListingByPriceCard.tsx (84%) rename packages/mask/src/plugins/Collectible/SNSAdaptor/{ => OpenSea}/MakeOfferDialog.tsx (76%) rename packages/mask/src/plugins/Collectible/SNSAdaptor/{ => OpenSea}/PostListingDialog.tsx (74%) delete mode 100644 packages/mask/src/plugins/Collectible/SNSAdaptor/Pagination.tsx delete mode 100644 packages/mask/src/plugins/Collectible/SNSAdaptor/shared.tsx delete mode 100644 packages/mask/src/plugins/Collectible/apis/index.ts delete mode 100644 packages/mask/src/plugins/Collectible/apis/openseaFromSDK.ts create mode 100644 packages/mask/src/plugins/Collectible/hooks/useOpenSea.ts delete mode 100644 packages/mask/src/plugins/Collectible/queries/OpenSea.ts delete mode 100644 packages/mask/src/plugins/Collectible/types/opensea.ts delete mode 100644 packages/mask/src/plugins/Collectible/types/rarible.ts delete mode 100644 packages/mask/src/plugins/EVM/UI/Dashboard/index.tsx delete mode 100644 packages/mask/src/plugins/EVM/UI/SNSAdaptor/index.tsx delete mode 100644 packages/mask/src/plugins/EVM/UI/Web3State/createGetLatestBalance.ts delete mode 100644 packages/mask/src/plugins/EVM/UI/Web3State/createNonFungibleToken.ts delete mode 100644 packages/mask/src/plugins/EVM/UI/Web3State/getAssetsFn.ts delete mode 100644 packages/mask/src/plugins/EVM/UI/Web3State/index.ts delete mode 100644 packages/mask/src/plugins/EVM/UI/Web3UI/index.tsx delete mode 100644 packages/mask/src/plugins/EVM/UI/components/FortmaticProviderBridge.tsx delete mode 100644 packages/mask/src/plugins/EVM/UI/components/InjectedProviderBridge.tsx delete mode 100644 packages/mask/src/plugins/EVM/UI/components/NetworkIconClickBait.tsx delete mode 100644 packages/mask/src/plugins/EVM/UI/components/ProviderIconClickBait.tsx delete mode 100644 packages/mask/src/plugins/EVM/base.ts delete mode 100644 packages/mask/src/plugins/EVM/constants.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/index.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useAsset.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useBridgedProvider.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useHistory.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useInjectedProviderReady.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useInjectedProviderType.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useNetwork.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useOrders.ts delete mode 100644 packages/mask/src/plugins/EVM/hooks/useProvider.ts delete mode 100644 packages/mask/src/plugins/EVM/services/Asset/index.ts delete mode 100644 packages/mask/src/plugins/EVM/services/NFT/index.ts delete mode 100644 packages/mask/src/plugins/EVM/services/index.ts delete mode 100644 packages/mask/src/plugins/EVM/storage/index.ts delete mode 100644 packages/mask/src/plugins/EVM/types/index.ts delete mode 100644 packages/mask/src/plugins/EVM/utils/index.ts delete mode 100644 packages/mask/src/plugins/EVM/utils/token.ts delete mode 100644 packages/mask/src/plugins/ITO/SNSAdaptor/NftAirdropCard.tsx delete mode 100644 packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationCampaignInfo.ts delete mode 100644 packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationClaimable.ts delete mode 100644 packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationClaimableTokenCountCallback.ts delete mode 100644 packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationContract.ts delete mode 100644 packages/mask/src/plugins/ITO/SNSAdaptor/hooks/useSpaceStationContractClaimCallback.ts rename packages/mask/src/plugins/ITO/{Worker/apis => SNSAdaptor/utils}/chain.ts (87%) rename packages/mask/src/plugins/ITO/{Worker/apis => SNSAdaptor/utils}/checkAvailability.ts (80%) delete mode 100644 packages/mask/src/plugins/ITO/Worker/apis/spaceStationGalaxy.ts delete mode 100644 packages/mask/src/plugins/Profile/SNSAdaptor/WalletsPage.tsx delete mode 100644 packages/mask/src/plugins/Profile/SNSAdaptor/index.ts delete mode 100644 packages/mask/src/plugins/Profile/Worker/index.ts delete mode 100644 packages/mask/src/plugins/Profile/base.ts delete mode 100644 packages/mask/src/plugins/Profile/constants.ts delete mode 100644 packages/mask/src/plugins/Profile/index.ts delete mode 100644 packages/mask/src/plugins/Profile/messages.ts delete mode 100644 packages/mask/src/plugins/Profile/services.ts delete mode 100644 packages/mask/src/plugins/Profile/types.ts rename packages/mask/src/plugins/RedPacket/{Worker/apis => SNSAdaptor/utils}/chain.ts (88%) rename packages/mask/src/plugins/RedPacket/{Worker/apis => SNSAdaptor/utils}/checkAvailability.ts (75%) create mode 100644 packages/mask/src/plugins/Snapshot/utils.ts delete mode 100644 packages/mask/src/plugins/Trader/LBP/useLBP.ts delete mode 100644 packages/mask/src/plugins/Trader/LBP/usePoolTokenPrices.ts delete mode 100644 packages/mask/src/plugins/Trader/LBP/usePoolTokens.ts delete mode 100644 packages/mask/src/plugins/Trader/LBP/usePools.ts delete mode 100644 packages/mask/src/plugins/Trader/SNSAdaptor/trending/LBPPanel.tsx delete mode 100644 packages/mask/src/plugins/Trader/SNSAdaptor/trending/LBPPriceChart.tsx delete mode 100644 packages/mask/src/plugins/Trader/apis/LBP/LBP.json delete mode 100644 packages/mask/src/plugins/Trader/apis/LBP/index.ts create mode 100644 packages/mask/src/plugins/Trader/storage/index.ts delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/RenameWalletDialog.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/RestoreLegacyWalletDialog/index.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/SelectWalletDialog.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/FirefoxPlatform.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/Icons.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/QRCodeModel.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/README.md delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/SafariPlatform.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletConnectQRCodeDialog/index.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/TransactionDescription.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/getITO_Description.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/getNFTRedpacketDescription.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/getRedpacketDescription.tsx delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/contractMethodDescription/index.ts delete mode 100644 packages/mask/src/plugins/Wallet/SNSAdaptor/WalletStatusDialog/type.ts delete mode 100644 packages/mask/src/plugins/Wallet/apis/debank.ts delete mode 100644 packages/mask/src/plugins/Wallet/apis/ens.ts delete mode 100644 packages/mask/src/plugins/Wallet/apis/metaswap.ts delete mode 100644 packages/mask/src/plugins/Wallet/apis/nftscan.ts delete mode 100644 packages/mask/src/plugins/Wallet/apis/opensea.ts delete mode 100644 packages/mask/src/plugins/Wallet/apis/zerion.ts delete mode 100644 packages/mask/src/plugins/Wallet/hooks/useClearRecentTransactions.ts delete mode 100644 packages/mask/src/plugins/Wallet/hooks/useRecentTransactions.ts delete mode 100644 packages/mask/src/plugins/Wallet/hooks/useRemoveRecentTransaction.ts delete mode 100644 packages/mask/src/plugins/Wallet/hooks/useTokenPrice.ts delete mode 100644 packages/mask/src/plugins/Wallet/hooks/useWalletRiskWarningDialog.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/addressBook.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/assets.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/cloud.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/domain.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/erc1155.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/erc20.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/erc721.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/estimateGasFee.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/gasPrice.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/nftscan.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/tokenPrice.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/transaction/database.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/transaction/helpers.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/transaction/index.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/transaction/progress.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/transaction/watcher.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/transactions.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/wallet/database/token.ts delete mode 100644 packages/mask/src/plugins/Wallet/services/wallet/maskwallet/index.ts delete mode 100644 packages/mask/src/plugins/Wallet/types/debank.ts delete mode 100644 packages/mask/src/plugins/Wallet/types/metaswap.ts delete mode 100644 packages/mask/src/plugins/Wallet/types/portfolio.ts delete mode 100644 packages/mask/src/plugins/Wallet/types/zerion.ts create mode 100644 packages/mask/src/web3/UI/ChainBoundary.tsx delete mode 100644 packages/mask/src/web3/UI/EthereumChainBoundary.tsx rename packages/mask/src/web3/UI/{EthereumWalletConnectedBoundary.tsx => WalletConnectedBoundary.tsx} (79%) delete mode 100644 packages/mask/src/web3/context.ts delete mode 100644 packages/mask/web-workers/wallet.ts create mode 100644 packages/plugin-infra/src/entry-web3-evm.ts delete mode 100644 packages/plugin-infra/src/hooks/useLookupDomain.ts delete mode 100644 packages/plugin-infra/src/hooks/useReverseAddress.ts create mode 100644 packages/plugin-infra/src/utils/subscription.ts create mode 100644 packages/plugin-infra/src/web3-helpers/index.ts create mode 100644 packages/plugin-infra/src/web3-state/AddressBook.ts create mode 100644 packages/plugin-infra/src/web3-state/Connection.ts create mode 100644 packages/plugin-infra/src/web3-state/Hub.ts create mode 100644 packages/plugin-infra/src/web3-state/Identity.ts create mode 100644 packages/plugin-infra/src/web3-state/NameService.ts create mode 100644 packages/plugin-infra/src/web3-state/Others.ts create mode 100644 packages/plugin-infra/src/web3-state/Provider.ts create mode 100644 packages/plugin-infra/src/web3-state/RiskWarning.ts create mode 100644 packages/plugin-infra/src/web3-state/Settings.ts create mode 100644 packages/plugin-infra/src/web3-state/Token.ts create mode 100644 packages/plugin-infra/src/web3-state/Transaction.ts create mode 100644 packages/plugin-infra/src/web3-state/TransactionFormatter.ts create mode 100644 packages/plugin-infra/src/web3-state/TransactionWatcher.ts create mode 100644 packages/plugin-infra/src/web3-state/Wallet.ts create mode 100644 packages/plugin-infra/src/web3-state/index.ts create mode 100644 packages/plugin-infra/src/web3/EVM/index.ts rename packages/{web3-shared/evm/contracts => plugin-infra/src/web3/EVM}/useBalanceChecker.ts (57%) create mode 100644 packages/plugin-infra/src/web3/EVM/useContract.ts create mode 100644 packages/plugin-infra/src/web3/EVM/useERC1155TokenContract.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useERC165.ts (63%) create mode 100644 packages/plugin-infra/src/web3/EVM/useERC165Contract.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useERC20TokenAllowance.ts (53%) rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useERC20TokenApproveCallback.ts (86%) create mode 100644 packages/plugin-infra/src/web3/EVM/useERC20TokenBytes32Contract.ts create mode 100644 packages/plugin-infra/src/web3/EVM/useERC20TokenContract.ts create mode 100644 packages/plugin-infra/src/web3/EVM/useERC20TokenTotalSupply.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useERC20TokenTransferCallback.ts (75%) rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useERC721ContractIsApproveForAll.ts (65%) rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useERC721ContractSetApproveForAllCallback.ts (75%) create mode 100644 packages/plugin-infra/src/web3/EVM/useERC721TokenByIndex.ts create mode 100644 packages/plugin-infra/src/web3/EVM/useERC721TokenContract.ts create mode 100644 packages/plugin-infra/src/web3/EVM/useERC721TokenContracts.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useERC721TokenTransferCallback.ts (75%) create mode 100644 packages/plugin-infra/src/web3/EVM/useGasLimit.ts create mode 100644 packages/plugin-infra/src/web3/EVM/useGetPastLogsParams.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useMulticall.ts (92%) rename packages/{web3-shared/evm/contracts => plugin-infra/src/web3/EVM}/useMulticallContract.ts (57%) rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useNativeTokenTransferCallback.ts (79%) rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useNativeTokenWrapperCallback.ts (92%) create mode 100644 packages/plugin-infra/src/web3/EVM/useNonFungibleOwnerTokens.ts create mode 100644 packages/plugin-infra/src/web3/EVM/useReverseLookupContract.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useTokenTransferCallback.ts (69%) rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3/EVM}/useTransactionCallback.ts (94%) create mode 100644 packages/plugin-infra/src/web3/EVM/useTransactionState.ts rename packages/{web3-shared/evm/contracts => plugin-infra/src/web3/EVM}/useWrappedEtherContract.ts (57%) create mode 100644 packages/plugin-infra/src/web3/useAddressBook.ts create mode 100644 packages/plugin-infra/src/web3/useAddressNames.ts delete mode 100644 packages/plugin-infra/src/web3/useAssetType.ts create mode 100644 packages/plugin-infra/src/web3/useBlockTimestamp.ts create mode 100644 packages/plugin-infra/src/web3/useBlockedFungibleTokens.ts create mode 100644 packages/plugin-infra/src/web3/useBlockedNonFungibleTokens.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3}/useBlockie.ts (100%) create mode 100644 packages/plugin-infra/src/web3/useChainDescriptor.ts delete mode 100644 packages/plugin-infra/src/web3/useChainDetailed.ts create mode 100644 packages/plugin-infra/src/web3/useChainIdMainnet.ts create mode 100644 packages/plugin-infra/src/web3/useChainIdMatched.ts create mode 100644 packages/plugin-infra/src/web3/useChainIdSupport.ts create mode 100644 packages/plugin-infra/src/web3/useClearTransactionsCallback.ts delete mode 100644 packages/plugin-infra/src/web3/useCollectibleType.ts create mode 100644 packages/plugin-infra/src/web3/useDefaultChainId.ts create mode 100644 packages/plugin-infra/src/web3/useDefaultNetworkType.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleAsset.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleAssetSourceType.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleAssets.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleToken.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleTokenBalance.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleTokenPrice.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleTokenWatched.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleTokens.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleTokensBalance.ts create mode 100644 packages/plugin-infra/src/web3/useFungibleTokensFromTokenList.ts create mode 100644 packages/plugin-infra/src/web3/useGasOptionType.ts create mode 100644 packages/plugin-infra/src/web3/useGasOptions.ts create mode 100644 packages/plugin-infra/src/web3/useGasPrice.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3}/useImageChecker.ts (100%) create mode 100644 packages/plugin-infra/src/web3/useLookupAddress.ts delete mode 100644 packages/plugin-infra/src/web3/useNameType.ts create mode 100644 packages/plugin-infra/src/web3/useNativeToken.ts create mode 100644 packages/plugin-infra/src/web3/useNativeTokenAddress.ts create mode 100644 packages/plugin-infra/src/web3/useNativeTokenBalance.ts create mode 100644 packages/plugin-infra/src/web3/useNativeTokenPrice.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleAsset.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleAssetSourceType.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleAssets.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleCollections.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleToken.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleTokenBalance.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleTokenContract.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleTokenPrice.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleTokens.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleTokensBalance.ts create mode 100644 packages/plugin-infra/src/web3/useNonFungibleTokensFromTokenList.ts create mode 100644 packages/plugin-infra/src/web3/useProviderReady.ts create mode 100644 packages/plugin-infra/src/web3/useRecentTransactions.ts create mode 100644 packages/plugin-infra/src/web3/useRemoveTransaction.ts create mode 100644 packages/plugin-infra/src/web3/useReverseAddress.ts create mode 100644 packages/plugin-infra/src/web3/useRiskWarningApproved.ts create mode 100644 packages/plugin-infra/src/web3/useSchemaType.ts rename packages/{web3-shared/evm/hooks => plugin-infra/src/web3}/useSocketOnce.ts (100%) delete mode 100644 packages/plugin-infra/src/web3/useTokenPrice.ts delete mode 100644 packages/plugin-infra/src/web3/useTransactionType.ts create mode 100644 packages/plugin-infra/src/web3/useTransactions.ts create mode 100644 packages/plugin-infra/src/web3/useTrustedFungibleTokens.ts create mode 100644 packages/plugin-infra/src/web3/useTrustedNonFungibleTokens.ts create mode 100644 packages/plugin-infra/src/web3/useWeb3.ts create mode 100644 packages/plugin-infra/src/web3/useWeb3Connection.ts create mode 100644 packages/plugin-infra/src/web3/useWeb3Hub.ts create mode 100644 packages/plugin-infra/src/web3/useWeb3Provider.ts create mode 100644 packages/plugin-infra/src/web3/useZeroAddress.ts create mode 100644 packages/plugins/EVM/package.json create mode 100644 packages/plugins/EVM/src/UI/Dashboard/index.tsx create mode 100644 packages/plugins/EVM/src/UI/SNSAdaptor/index.tsx rename packages/{mask/src/plugins/EVM => plugins/EVM/src}/Worker/index.ts (100%) create mode 100644 packages/plugins/EVM/src/assets/nft.png create mode 100644 packages/plugins/EVM/src/base.ts create mode 100644 packages/plugins/EVM/src/constants/index.ts create mode 100644 packages/plugins/EVM/src/env.d.ts create mode 100644 packages/plugins/EVM/src/hooks/index.ts create mode 100644 packages/plugins/EVM/src/hooks/useProviderReady.ts rename packages/{mask/src/plugins/EVM => plugins/EVM/src}/index.ts (58%) create mode 100644 packages/plugins/EVM/src/locales/en-US.json create mode 100644 packages/plugins/EVM/src/locales/index.ts create mode 100644 packages/plugins/EVM/src/locales/languages.ts rename packages/{mask/src/plugins/EVM => plugins/EVM/src}/messages.ts (57%) rename packages/{mask/src/plugins/EVM/types.ts => plugins/EVM/src/services.ts} (100%) create mode 100644 packages/plugins/EVM/src/settings/index.ts create mode 100644 packages/plugins/EVM/src/state/AddressBook.ts create mode 100644 packages/plugins/EVM/src/state/Connection.ts create mode 100644 packages/plugins/EVM/src/state/Connection/composer.ts create mode 100644 packages/plugins/EVM/src/state/Connection/connection.ts rename packages/{mask/src/extension/background-script/EthereumServices => plugins/EVM/src/state/Connection}/error.ts (83%) create mode 100644 packages/plugins/EVM/src/state/Connection/interceptors/MaskWallet.ts create mode 100644 packages/plugins/EVM/src/state/Connection/interceptors/MetaMask.ts create mode 100644 packages/plugins/EVM/src/state/Connection/interceptors/WalletConnect.ts create mode 100644 packages/plugins/EVM/src/state/Connection/middleware/AddressBook.ts create mode 100644 packages/plugins/EVM/src/state/Connection/middleware/Interceptor.ts create mode 100644 packages/plugins/EVM/src/state/Connection/middleware/Nonce.ts create mode 100644 packages/plugins/EVM/src/state/Connection/middleware/Popup.ts create mode 100644 packages/plugins/EVM/src/state/Connection/middleware/Squash.ts create mode 100644 packages/plugins/EVM/src/state/Connection/middleware/Transaction.ts create mode 100644 packages/plugins/EVM/src/state/Connection/middleware/Translator.ts create mode 100644 packages/plugins/EVM/src/state/Connection/provider.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/Base.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/BaseInjected.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/Coin98.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/CustomNetwork.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/Fortmatic.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/MaskWallet.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/MathWallet.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/MetaMask.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/Torus.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/WalletConnect.ts create mode 100644 packages/plugins/EVM/src/state/Connection/providers/WalletLink.ts create mode 100644 packages/plugins/EVM/src/state/Connection/translators/Base.ts create mode 100644 packages/plugins/EVM/src/state/Connection/translators/Celo.ts create mode 100644 packages/plugins/EVM/src/state/Connection/translators/Optimistic.ts create mode 100644 packages/plugins/EVM/src/state/Connection/translators/Polygon.ts create mode 100644 packages/plugins/EVM/src/state/Connection/types.ts create mode 100644 packages/plugins/EVM/src/state/Connection/utils.ts create mode 100644 packages/plugins/EVM/src/state/Hub.ts create mode 100644 packages/plugins/EVM/src/state/Hub/TokenIconSpecialIconList.json create mode 100644 packages/plugins/EVM/src/state/Hub/hub.ts create mode 100644 packages/plugins/EVM/src/state/Hub/types.ts create mode 100644 packages/plugins/EVM/src/state/IdentityService.ts create mode 100644 packages/plugins/EVM/src/state/NameService.ts create mode 100644 packages/plugins/EVM/src/state/Others.ts create mode 100644 packages/plugins/EVM/src/state/Provider.ts create mode 100644 packages/plugins/EVM/src/state/RiskWarning.ts create mode 100644 packages/plugins/EVM/src/state/Settings.ts create mode 100644 packages/plugins/EVM/src/state/Token.ts create mode 100644 packages/plugins/EVM/src/state/Transaction.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/abi.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/Base.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/Cancel.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/ContractDeployment.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/ERC20.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/ITO.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/RedPacket.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/TransferToken.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/descriptors/Uniswap.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/types.ts create mode 100644 packages/plugins/EVM/src/state/TransactionFormatter/utils.ts create mode 100644 packages/plugins/EVM/src/state/TransactionWatcher.ts create mode 100644 packages/plugins/EVM/src/state/TransactionWatcher/checker.ts create mode 100644 packages/plugins/EVM/src/state/TransactionWatcher/checkers/AccountChecker.ts create mode 100644 packages/plugins/EVM/src/state/TransactionWatcher/checkers/ReceiptChecker.ts create mode 100644 packages/plugins/EVM/src/state/Wallet.ts create mode 100644 packages/plugins/EVM/src/state/index.ts create mode 100644 packages/plugins/EVM/src/types/index.ts create mode 100644 packages/plugins/EVM/tsconfig.json delete mode 100644 packages/plugins/Flow/src/UI/Web3State/index.ts delete mode 100644 packages/plugins/Flow/src/UI/Web3UI/index.tsx delete mode 100644 packages/plugins/Flow/src/UI/components/ProviderIconClickBait.tsx rename packages/plugins/Flow/src/apis/{getFungibleAssets.ts => fungibleAssets.ts} (65%) create mode 100644 packages/plugins/Flow/src/settings/index.ts create mode 100644 packages/plugins/Flow/src/state/AddressBook.ts create mode 100644 packages/plugins/Flow/src/state/Connection.ts create mode 100644 packages/plugins/Flow/src/state/Connection/connection.ts create mode 100644 packages/plugins/Flow/src/state/Connection/provider.ts create mode 100644 packages/plugins/Flow/src/state/Connection/providers/Base.ts create mode 100644 packages/plugins/Flow/src/state/Connection/providers/Blocto.ts create mode 100644 packages/plugins/Flow/src/state/Connection/providers/Dapper.ts create mode 100644 packages/plugins/Flow/src/state/Connection/providers/Ledger.ts create mode 100644 packages/plugins/Flow/src/state/Connection/types.ts create mode 100644 packages/plugins/Flow/src/state/Hub.ts create mode 100644 packages/plugins/Flow/src/state/Hub/hub.ts create mode 100644 packages/plugins/Flow/src/state/Hub/types.ts create mode 100644 packages/plugins/Flow/src/state/Others.ts create mode 100644 packages/plugins/Flow/src/state/Provider.ts create mode 100644 packages/plugins/Flow/src/state/Settings.ts create mode 100644 packages/plugins/Flow/src/state/Transaction.ts create mode 100644 packages/plugins/Flow/src/state/Wallet.ts create mode 100644 packages/plugins/Flow/src/state/index.ts delete mode 100644 packages/plugins/Flow/src/storage/index.ts delete mode 100644 packages/plugins/Flow/src/types.ts delete mode 100644 packages/plugins/Solana/src/UI/Web3State/index.ts delete mode 100644 packages/plugins/Solana/src/UI/Web3UI/index.tsx create mode 100644 packages/plugins/Solana/src/assets/torus.png create mode 100644 packages/plugins/Solana/src/env.d.ts delete mode 100644 packages/plugins/Solana/src/helpers/formatter.ts create mode 100644 packages/plugins/Solana/src/settings/index.ts create mode 100644 packages/plugins/Solana/src/state/AddressBook.ts create mode 100644 packages/plugins/Solana/src/state/Connection.ts create mode 100644 packages/plugins/Solana/src/state/Connection/connection.ts create mode 100644 packages/plugins/Solana/src/state/Connection/provider.ts create mode 100644 packages/plugins/Solana/src/state/Connection/providers/Base.ts create mode 100644 packages/plugins/Solana/src/state/Connection/providers/BaseInjected.ts create mode 100644 packages/plugins/Solana/src/state/Connection/providers/Coin98.ts create mode 100644 packages/plugins/Solana/src/state/Connection/providers/Phantom.ts create mode 100644 packages/plugins/Solana/src/state/Connection/providers/SolflareProvider.ts create mode 100644 packages/plugins/Solana/src/state/Connection/providers/Sollet.ts create mode 100644 packages/plugins/Solana/src/state/Connection/types.ts create mode 100644 packages/plugins/Solana/src/state/Hub.ts create mode 100644 packages/plugins/Solana/src/state/Hub/hub.ts create mode 100644 packages/plugins/Solana/src/state/Hub/types.ts create mode 100644 packages/plugins/Solana/src/state/Others.ts create mode 100644 packages/plugins/Solana/src/state/Provider.ts create mode 100644 packages/plugins/Solana/src/state/Settings.ts create mode 100644 packages/plugins/Solana/src/state/Token.ts create mode 100644 packages/plugins/Solana/src/state/Transaction.ts create mode 100644 packages/plugins/Solana/src/state/Wallet.ts create mode 100644 packages/plugins/Solana/src/state/index.ts delete mode 100644 packages/plugins/Solana/src/storage/index.ts delete mode 100644 packages/plugins/Solana/src/types.ts delete mode 100644 packages/plugins/Solana/src/utils.ts create mode 100644 packages/plugins/Solana/src/utils/index.ts delete mode 100644 packages/plugins/Solana/src/wallet/connect.ts delete mode 100644 packages/plugins/Solana/src/wallet/index.ts create mode 100644 packages/shared-base/src/Site/index.ts rename packages/{mask/utils-pure/OnDemandWorker => shared-base/src/onDemandWorker}/index.ts (100%) create mode 100644 packages/shared-base/src/utils/asyncIterator.ts create mode 100644 packages/shared-base/src/utils/createValueRefWithReady.ts delete mode 100644 packages/shared/src/UI/components/ERC20TokenList/index.tsx rename packages/shared/src/UI/components/{ERC20TokenList/ERC20TokenListItem.tsx => FungibleTokenList/FungibleTokenItem.tsx} (62%) create mode 100644 packages/shared/src/UI/components/FungibleTokenList/index.tsx create mode 100644 packages/shared/src/hooks/useImageFailOver.ts create mode 100644 packages/shared/src/utils/index.ts delete mode 100644 packages/web3-constants/evm/lbp.json create mode 100644 packages/web3-constants/flow/chain.json create mode 100644 packages/web3-constants/solana/chain.json create mode 100644 packages/web3-contracts/abis/ERC165.json create mode 100644 packages/web3-contracts/types/ERC165.d.ts delete mode 100644 packages/web3-providers/src/coingecko/constants.ts delete mode 100644 packages/web3-providers/src/hooks/index.ts delete mode 100644 packages/web3-providers/src/hooks/useERC721TokenDetailedOwnerList.ts create mode 100644 packages/web3-providers/src/mask/index.ts create mode 100644 packages/web3-providers/src/mask/prepare.ts create mode 100644 packages/web3-providers/src/mask/worker.ts create mode 100644 packages/web3-providers/src/metaswap/index.ts create mode 100644 packages/web3-providers/src/metaswap/types.ts create mode 100644 packages/web3-providers/src/risk-warning/index.ts delete mode 100644 packages/web3-providers/src/token-price/index.ts delete mode 100644 packages/web3-shared/base/src/helpers/index.ts delete mode 100644 packages/web3-shared/base/src/helpers/lookupTable.ts delete mode 100644 packages/web3-shared/base/src/helpers/types.ts delete mode 100644 packages/web3-shared/base/src/hooks/index.ts delete mode 100644 packages/web3-shared/base/src/hooks/useBeat.ts create mode 100644 packages/web3-shared/base/src/specs/index.ts create mode 100644 packages/web3-shared/base/src/utils/address.ts create mode 100644 packages/web3-shared/base/src/utils/balance.ts rename packages/web3-shared/base/src/{helpers/constants.ts => utils/constant.ts} (70%) create mode 100644 packages/web3-shared/base/src/utils/currency.ts create mode 100644 packages/web3-shared/base/src/utils/pagination.ts create mode 100644 packages/web3-shared/base/src/utils/predicate.ts create mode 100644 packages/web3-shared/base/src/utils/resolver.ts create mode 100644 packages/web3-shared/base/src/utils/token.ts create mode 100644 packages/web3-shared/base/src/utils/types.ts rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/arbitrum.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/aurora.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/avalanche.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/binance.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/celo.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/coin98.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/coinbase.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/conflux.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/ethereum.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/fantom.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/fortmatic.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/harmony.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/lucky_drop.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/maskwallet.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/mathwallet.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/metamask.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/nfts.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/polygon.png (100%) create mode 100644 packages/web3-shared/evm/assets/torus.png rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/walletconnect.png (100%) rename packages/{mask/src/plugins/EVM => web3-shared/evm}/assets/xdai.png (100%) delete mode 100644 packages/web3-shared/evm/constants/README.md rename packages/web3-shared/evm/{assets => constants}/chains.json (66%) create mode 100644 packages/web3-shared/evm/constants/descriptors.ts delete mode 100644 packages/web3-shared/evm/constants/utils.ts delete mode 100644 packages/web3-shared/evm/context/index.tsx delete mode 100644 packages/web3-shared/evm/context/type.ts delete mode 100644 packages/web3-shared/evm/contracts/index.ts delete mode 100644 packages/web3-shared/evm/contracts/useERC1155TokenContract.ts delete mode 100644 packages/web3-shared/evm/contracts/useERC20TokenBytes32Contract.ts delete mode 100644 packages/web3-shared/evm/contracts/useERC20TokenContract.ts delete mode 100644 packages/web3-shared/evm/contracts/useERC721TokenContract.ts delete mode 100644 packages/web3-shared/evm/contracts/useERC721TokenContracts.ts delete mode 100644 packages/web3-shared/evm/contracts/useReverseLookupContract.ts delete mode 100644 packages/web3-shared/evm/hooks/index.ts delete mode 100644 packages/web3-shared/evm/hooks/useAccount.ts delete mode 100644 packages/web3-shared/evm/hooks/useAddERC20TokenCallback.ts delete mode 100644 packages/web3-shared/evm/hooks/useAddressNames.ts delete mode 100644 packages/web3-shared/evm/hooks/useAllowTestnet.ts delete mode 100644 packages/web3-shared/evm/hooks/useAssets.ts delete mode 100644 packages/web3-shared/evm/hooks/useAssetsByTokenList.ts delete mode 100644 packages/web3-shared/evm/hooks/useAssetsFromChain.ts delete mode 100644 packages/web3-shared/evm/hooks/useAssetsFromProvider.ts delete mode 100644 packages/web3-shared/evm/hooks/useAssetsMerged.ts delete mode 100644 packages/web3-shared/evm/hooks/useBalance.ts delete mode 100644 packages/web3-shared/evm/hooks/useBlockNumber.ts delete mode 100644 packages/web3-shared/evm/hooks/useChainColor.ts delete mode 100644 packages/web3-shared/evm/hooks/useChainDetailed.ts delete mode 100644 packages/web3-shared/evm/hooks/useChainEIP1159Supported.ts delete mode 100644 packages/web3-shared/evm/hooks/useChainId.ts delete mode 100644 packages/web3-shared/evm/hooks/useChainIdValid.ts delete mode 100644 packages/web3-shared/evm/hooks/useCollectibles.ts delete mode 100644 packages/web3-shared/evm/hooks/useContract.ts delete mode 100644 packages/web3-shared/evm/hooks/useCurrentBlockTimestamp.ts delete mode 100644 packages/web3-shared/evm/hooks/useENSLabel.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC1155TokenAssetDetailed.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC20TokenBalance.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC20TokenDetailed.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC20TokenDetailedFromTokenLists.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC20TokenTotalSupply.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC20Tokens.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC20TokensDetailedFromTokenLists.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC721ContractBalance.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC721ContractDetailed.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC721TokenByIndex.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC721TokenDetailed.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC721TokenDetailedCallback.ts delete mode 100644 packages/web3-shared/evm/hooks/useERC721Tokens.ts delete mode 100644 packages/web3-shared/evm/hooks/useEthereumTokenType.ts delete mode 100644 packages/web3-shared/evm/hooks/useFungibleTokenBalance.ts delete mode 100644 packages/web3-shared/evm/hooks/useFungibleTokenDetailed.ts delete mode 100644 packages/web3-shared/evm/hooks/useFungibleTokenWatched.tsx delete mode 100644 packages/web3-shared/evm/hooks/useGasLimit.ts delete mode 100644 packages/web3-shared/evm/hooks/useGasPrice.ts delete mode 100644 packages/web3-shared/evm/hooks/useGetPastLogsParams.ts delete mode 100644 packages/web3-shared/evm/hooks/useNativeTokenBalance.ts delete mode 100644 packages/web3-shared/evm/hooks/useNativeTokenDetailed.ts delete mode 100644 packages/web3-shared/evm/hooks/useNetworkType.ts delete mode 100644 packages/web3-shared/evm/hooks/useProviderType.ts delete mode 100644 packages/web3-shared/evm/hooks/useResolveENS.ts delete mode 100644 packages/web3-shared/evm/hooks/useSocket.ts delete mode 100644 packages/web3-shared/evm/hooks/useTokensBalance.ts delete mode 100644 packages/web3-shared/evm/hooks/useTransactionState.ts delete mode 100644 packages/web3-shared/evm/hooks/useTransactions.ts delete mode 100644 packages/web3-shared/evm/hooks/useTrustERC20TokenCallback.ts delete mode 100644 packages/web3-shared/evm/hooks/useTrustedERC20Tokens.ts delete mode 100644 packages/web3-shared/evm/hooks/useWallet.ts delete mode 100644 packages/web3-shared/evm/hooks/useWalletPrimary.ts delete mode 100644 packages/web3-shared/evm/hooks/useWallets.ts delete mode 100644 packages/web3-shared/evm/hooks/useWeb3.ts delete mode 100644 packages/web3-shared/evm/hooks/useWeb3Provider.ts delete mode 100644 packages/web3-shared/evm/providers/Fortmatic.ts create mode 100644 packages/web3-shared/evm/utils/abi.ts create mode 100644 packages/web3-shared/evm/utils/chain.ts delete mode 100644 packages/web3-shared/evm/utils/chainDetailed.ts create mode 100644 packages/web3-shared/evm/utils/contract.ts delete mode 100644 packages/web3-shared/evm/utils/enum.ts delete mode 100644 packages/web3-shared/evm/utils/misc.ts create mode 100644 packages/web3-shared/evm/utils/resolver.ts create mode 100644 packages/web3-shared/flow/assets/FUSD.png create mode 100644 packages/web3-shared/flow/assets/blocto.png create mode 100644 packages/web3-shared/flow/assets/flow.png create mode 100644 packages/web3-shared/flow/assets/tUSD.png create mode 100644 packages/web3-shared/flow/constants/constants.ts create mode 100644 packages/web3-shared/flow/constants/descriptors.ts create mode 100644 packages/web3-shared/flow/constants/primitives.ts delete mode 100644 packages/web3-shared/flow/pipes/index.ts create mode 100644 packages/web3-shared/flow/utils/address.ts create mode 100644 packages/web3-shared/flow/utils/domain.ts create mode 100644 packages/web3-shared/flow/utils/index.ts create mode 100644 packages/web3-shared/flow/utils/resolver.ts create mode 100644 packages/web3-shared/solana/assets/coin98.png create mode 100644 packages/web3-shared/solana/assets/phantom.png create mode 100644 packages/web3-shared/solana/assets/solana.png create mode 100644 packages/web3-shared/solana/assets/solflare.png create mode 100644 packages/web3-shared/solana/assets/sollet.png create mode 100644 packages/web3-shared/solana/assets/usdc.png create mode 100644 packages/web3-shared/solana/coin98.png create mode 100644 packages/web3-shared/solana/constants/constants.ts create mode 100644 packages/web3-shared/solana/constants/descriptors.ts create mode 100644 packages/web3-shared/solana/constants/primitives.ts delete mode 100644 packages/web3-shared/solana/pipes/index.ts create mode 100644 packages/web3-shared/solana/utils/address.ts create mode 100644 packages/web3-shared/solana/utils/domain.ts create mode 100644 packages/web3-shared/solana/utils/index.ts create mode 100644 packages/web3-shared/solana/utils/resolver.ts diff --git a/.i18n-codegen.json b/.i18n-codegen.json index 48fd89fd6a66..831ba5bd6430 100644 --- a/.i18n-codegen.json +++ b/.i18n-codegen.json @@ -145,6 +145,17 @@ "trans": "Translate" } }, + { + "input": "./packages/plugins/EVM/src/locales/en-US.json", + "output": "./packages/plugins/EVM/src/locales/i18n_generated", + "parser": { "type": "i18next", "contextSeparator": "$", "pluralSeparator": "_" }, + "generator": { + "type": "i18next/react-hooks", + "hooks": "useI18N", + "namespace": "com.mask.evm", + "trans": "Translate" + } + }, { "input": "./packages/plugins/Solana/src/locales/en-US.json", "output": "./packages/plugins/Solana/src/locales/i18n_generated", diff --git a/.prettierignore b/.prettierignore index b3703149f7e7..0f8cab04ff43 100644 --- a/.prettierignore +++ b/.prettierignore @@ -168,3 +168,7 @@ common/autoinstallers/*/.npmrc packages/storybook-shared/*.js packages/storybook-shared/*.map packages/storybook-shared/*.d.ts + +# Requires Prettier support for typescript 4.7 +# https://github.com/prettier/prettier/issues/12640 +packages/web3-shared/base/src/specs/index.ts diff --git a/cspell.json b/cspell.json index 4dbe240d7ac5..91230b4de721 100644 --- a/cspell.json +++ b/cspell.json @@ -141,6 +141,7 @@ "pressable", "promi", "proxied", + "portto", "pushstate", "pvtsutils", "qrcode", @@ -170,6 +171,7 @@ "subrepo", "sushiswap", "swappable", + "solflare", "testid", "thegraph", "timelock", @@ -185,6 +187,7 @@ "typechain", "typehash", "typeson", + "toruslabs", "unencrypted", "unreviewed", "unstake", diff --git a/package.json b/package.json index 627d5fa00fad..634ec7a4ab43 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "spellcheck": "cspell lint --no-must-find-files" }, "dependencies": { - "@dimensiondev/kit": "0.0.0-20220228054820-f2378be", + "@dimensiondev/kit": "0.0.0-20220501022859-60d5533", "@emotion/cache": "^11.7.1", "@emotion/react": "^11.9.0", "@emotion/serialize": "^1.0.3", diff --git a/packages/dashboard/package.json b/packages/dashboard/package.json index d2d156cf0f55..b14d4407dc72 100644 --- a/packages/dashboard/package.json +++ b/packages/dashboard/package.json @@ -19,6 +19,7 @@ "@masknet/backup-format": "workspace:*", "@masknet/icons": "workspace:*", "@masknet/plugin-example": "workspace:*", + "@masknet/plugin-evm": "workspace:*", "@masknet/plugin-flow": "workspace:*", "@masknet/plugin-infra": "workspace:*", "@masknet/plugin-solana": "workspace:*", @@ -32,6 +33,8 @@ "@masknet/web3-providers": "workspace:*", "@masknet/web3-shared-base": "workspace:*", "@masknet/web3-shared-evm": "workspace:*", + "@masknet/web3-shared-solana": "workspace:*", + "@masknet/web3-shared-flow": "workspace:*", "@msgpack/msgpack": "^2.7.2", "@servie/events": "^3.0.0", "@types/color": "^3.0.3", diff --git a/packages/dashboard/src/components/DashboardFrame/Navigation.tsx b/packages/dashboard/src/components/DashboardFrame/Navigation.tsx index e6c47ef72ec6..00e45b050a9b 100644 --- a/packages/dashboard/src/components/DashboardFrame/Navigation.tsx +++ b/packages/dashboard/src/components/DashboardFrame/Navigation.tsx @@ -30,7 +30,8 @@ import { import { useDashboardI18N } from '../../locales' import { MaskColorVar } from '@masknet/theme' import { DashboardRoutes } from '@masknet/shared-base' -import { NetworkPluginID, useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' +import { useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' const ListItemLinkUnStyled = ({ to, ...props }: ListItemProps & { to: string }) => { const navigate = useNavigate() diff --git a/packages/dashboard/src/components/PageFrame/FeaturePromotions/index.tsx b/packages/dashboard/src/components/PageFrame/FeaturePromotions/index.tsx index a2533c89433e..7d44196acfe0 100644 --- a/packages/dashboard/src/components/PageFrame/FeaturePromotions/index.tsx +++ b/packages/dashboard/src/components/PageFrame/FeaturePromotions/index.tsx @@ -1,9 +1,10 @@ import { memo, useCallback, useMemo } from 'react' import { useNavigate } from 'react-router-dom' import { makeStyles } from '@masknet/theme' -import { openWindow, useRemoteControlledDialog } from '@masknet/shared-base-ui' -import { useAccount } from '@masknet/web3-shared-evm' -import { PluginMessages, Services } from '../../../API' +import { openWindow } from '@masknet/shared-base-ui' +import { useAccount } from '@masknet/plugin-infra/web3' +import { Services } from '../../../API' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { PersonaContext } from '../../../pages/Personas/hooks/usePersonaContext' import { DashboardRoutes, EnhanceableSite } from '@masknet/shared-base' import { PluginId } from '@masknet/plugin-infra' @@ -31,10 +32,10 @@ const useStyles = makeStyles()((theme) => ({ export const FeaturePromotions = memo(() => { const { classes } = useStyles() const navigate = useNavigate() - const account = useAccount() + const account = useAccount(NetworkPluginID.PLUGIN_EVM) const { currentPersona, connectPersona } = PersonaContext.useContainer() - const { setDialog: setBuyDialog } = useRemoteControlledDialog(PluginMessages.Transak.buyTokenDialogUpdated) + // const { setDialog: setBuyDialog } = useRemoteControlledDialog(PluginMessages.Transak.buyTokenDialogUpdated) const isConnectedTwitter = useMemo(() => { if (!currentPersona) return false @@ -46,10 +47,10 @@ export const FeaturePromotions = memo(() => { }, [currentPersona]) const openTransakDialog = useCallback(() => { - setBuyDialog({ - open: true, - address: account ?? '', - }) + // setBuyDialog({ + // open: true, + // address: account ?? '', + // }) }, []) const openTwitter = (pluginId: string) => async () => { diff --git a/packages/dashboard/src/hooks/useGasOptions.ts b/packages/dashboard/src/hooks/useGasOptions.ts deleted file mode 100644 index c9f42b64bb11..000000000000 --- a/packages/dashboard/src/hooks/useGasOptions.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { GasOption, isEIP1559Supported, useChainId } from '@masknet/web3-shared-evm' -import { useMemo } from 'react' -import { useAsync } from 'react-use' -import { useDashboardI18N } from '../locales' -import { PluginServices } from '../API' - -const { Wallet: WalletRPC } = PluginServices -export function useGasOptions() { - const t = useDashboardI18N() - const chainId = useChainId() - const is1559Supported = useMemo(() => isEIP1559Supported(chainId), [chainId]) - const { value: gasFromMetaMask, loading: getFromMetaMaskLoading } = useAsync(async () => { - if (!is1559Supported) return - - return WalletRPC.getEstimateGasFees(chainId) - }, [is1559Supported, chainId]) - - // #region Get gas options from debank - const { value: gasFromDebank, loading: getFromDebankLoading } = useAsync(async () => { - if (is1559Supported) return - const response = await WalletRPC.getGasPriceDictFromDeBank(chainId) - if (!response) return null - return { - low: response.data.slow.price, - medium: response.data.normal.price, - high: response.data.fast.price, - } - }, [is1559Supported, chainId]) - // #endregion - - const gasOptions = is1559Supported ? gasFromMetaMask : gasFromDebank - - const options = useMemo(() => { - return [ - { - title: t.wallet_gas_fee_settings_low(), - gasOption: GasOption.Low, - gasPrice: gasOptions?.low ?? 0, - }, - { - title: t.wallet_gas_fee_settings_medium(), - gasOption: GasOption.Medium, - gasPrice: gasOptions?.medium ?? 0, - }, - { - title: t.wallet_gas_fee_settings_high(), - gasOption: GasOption.High, - gasPrice: gasOptions?.high ?? 0, - }, - ] - }, [is1559Supported, gasOptions]) - - return { - value: options, - loading: is1559Supported ? getFromMetaMaskLoading : getFromDebankLoading, - gasOptions, - } -} diff --git a/packages/dashboard/src/initialization/Dashboard.tsx b/packages/dashboard/src/initialization/Dashboard.tsx index c16bcb6cc643..83b4c5155b97 100644 --- a/packages/dashboard/src/initialization/Dashboard.tsx +++ b/packages/dashboard/src/initialization/Dashboard.tsx @@ -10,19 +10,15 @@ import { import { I18NextProviderHMR, SharedContextProvider } from '@masknet/shared' import { ErrorBoundary } from '@masknet/shared-base-ui' import { createInjectHooksRenderer, useActivatedPluginsDashboard } from '@masknet/plugin-infra/dashboard' -import { NetworkPluginID, PluginsWeb3ContextProvider, useAllPluginsWeb3State } from '@masknet/plugin-infra/web3' -import { Web3Provider } from '@masknet/web3-shared-evm' - +import { PluginsWeb3ContextProvider, useAllPluginsWeb3State } from '@masknet/plugin-infra/web3' import { i18NextInstance } from '@masknet/shared-base' import '../utils/kv-storage' import './PluginHost' import { Pages } from '../pages/routes' -import { Web3Context } from '../web3/context' import { useAppearance, usePluginID } from '../pages/Personas/api' import { PersonaContext } from '../pages/Personas/hooks/usePersonaContext' -import { fixWeb3State } from '../../../mask/src/plugins/EVM/UI/Web3State' const PluginRender = createInjectHooksRenderer(useActivatedPluginsDashboard, (x) => x.GlobalInjection) @@ -30,9 +26,6 @@ export default function DashboardRoot() { const pluginID = usePluginID() const PluginsWeb3State = useAllPluginsWeb3State() - // TODO: migrate EVM plugin - fixWeb3State(PluginsWeb3State[NetworkPluginID.PLUGIN_EVM], Web3Context) - // #region theme const appearance = useAppearance() const mode = useSystemPreferencePalette() @@ -47,28 +40,26 @@ export default function DashboardRoot() { // #endregion return ( - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + ) } diff --git a/packages/dashboard/src/initialization/PluginHost.ts b/packages/dashboard/src/initialization/PluginHost.ts index 272c30c82d69..848bb1d4954f 100644 --- a/packages/dashboard/src/initialization/PluginHost.ts +++ b/packages/dashboard/src/initialization/PluginHost.ts @@ -2,9 +2,9 @@ import './plugins' import { Emitter } from '@servie/events' import { startPluginDashboard, Plugin } from '@masknet/plugin-infra/dashboard' +import { createI18NBundle, i18NextInstance } from '@masknet/shared-base' import { Services, Messages } from '../API' -import { createI18NBundle, createSubscriptionFromAsync, i18NextInstance } from '@masknet/shared-base' -import { InMemoryStorages, PersistentStorages } from '../utils/kv-storage' +import { createSharedContext } from '../../../mask/src/plugin-infra/host' const PluginHost: Plugin.__Host.Host = { minimalMode: { @@ -16,23 +16,7 @@ const PluginHost: Plugin.__Host.Host = { addI18NResource(plugin, resource) { createI18NBundle(plugin, resource)(i18NextInstance) }, - createContext: (pluginID, signal) => { - const currentPersonaSub = createSubscriptionFromAsync( - Services.Settings.getCurrentPersonaIdentifier, - undefined, - Messages.events.currentPersonaIdentifier.on, - signal, - ) - return { - createKVStorage(type, defaultValues) { - if (type === 'memory') return InMemoryStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - else return PersistentStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - }, - personaSign: Services.Identity.signWithPersona, - walletSign: Services.Ethereum.personalSign, - currentPersona: currentPersonaSub, - } - }, + createContext: createSharedContext, } setTimeout(() => { Messages.events.pluginMinimalModeChanged.on(([id, status]) => { diff --git a/packages/dashboard/src/initialization/isolated_bridge.ts b/packages/dashboard/src/initialization/isolated_bridge.ts index 9e941f0812b0..e7b621e94ac0 100644 --- a/packages/dashboard/src/initialization/isolated_bridge.ts +++ b/packages/dashboard/src/initialization/isolated_bridge.ts @@ -24,11 +24,9 @@ function installPluginService() { const Wallet = channelOf('com.maskbook.wallet') const Transak = channelOf('com.maskbook.transak') const Swap = channelOf('com.maskbook.trader') - const Pets = channelOf('com.maskbook.pets') - setPluginMessages({ Wallet, Transak, Swap, Pets }) + setPluginMessages({ Wallet, Transak, Swap }) setPluginServices({ Wallet: initRPCBridge(PluginMessages.Wallet.events.rpc), - Swap: initRPCBridge(PluginMessages.Swap.rpc), }) } diff --git a/packages/dashboard/src/pages/CreateMaskWallet/components/CreateMnemonic/index.tsx b/packages/dashboard/src/pages/CreateMaskWallet/components/CreateMnemonic/index.tsx index fc44340b5553..d672c8b0df22 100644 --- a/packages/dashboard/src/pages/CreateMaskWallet/components/CreateMnemonic/index.tsx +++ b/packages/dashboard/src/pages/CreateMaskWallet/components/CreateMnemonic/index.tsx @@ -3,7 +3,6 @@ import { Alert, Box, Button, Typography } from '@mui/material' import { makeStyles, MaskColorVar } from '@masknet/theme' import { InfoIcon, RefreshIcon } from '@masknet/icons' import { useDashboardI18N } from '../../../../locales' -import { ChainId, ProviderType } from '@masknet/web3-shared-evm' import { MnemonicReveal } from '../../../../components/Mnemonic' import { VerifyMnemonicDialog } from '../VerifyMnemonicDialog' import { useAsyncFn, useAsyncRetry } from 'react-use' @@ -115,14 +114,10 @@ const CreateMnemonic = memo(() => { const account = await Services.Settings.getSelectedWalletAddress() if (!account) { - await PluginServices.Wallet.updateAccount({ + await PluginServices.Wallet.updateMaskAccount({ account: address_, - providerType: ProviderType.MaskWallet, }) - const chainId = searchParams.get('chainId') - if (chainId) { - await PluginServices.Wallet.selectAccount([address_], Number(chainId) as ChainId) - } + await PluginServices.Wallet.selectMaskAccount([address_]) } return address_ diff --git a/packages/dashboard/src/pages/Settings/api.ts b/packages/dashboard/src/pages/Settings/api.ts index 894e2bfbd781..2d922ef5b290 100644 --- a/packages/dashboard/src/pages/Settings/api.ts +++ b/packages/dashboard/src/pages/Settings/api.ts @@ -1,15 +1,9 @@ import { createGlobalState } from '@masknet/shared-base-ui' import { Messages, Services } from '../../API' -import type { DataProvider } from '@masknet/public-api' import type { AccountType, BackupFileInfo, Scenario, Locale } from './type' export const [useLanguage] = createGlobalState(Services.Settings.getLanguage, Messages.events.languageSettings.on) -export const [useTrendingDataSource] = createGlobalState( - Services.Settings.getTrendingDataSource, - Messages.events.currentDataProviderSettings.on, -) - const BASE_RUL = 'https://vaalh28dbi.execute-api.ap-east-1.amazonaws.com/api' interface BackupBaseRequest { diff --git a/packages/dashboard/src/pages/Settings/components/DataSourceSetting.tsx b/packages/dashboard/src/pages/Settings/components/DataSourceSetting.tsx deleted file mode 100644 index b89cd5166e09..000000000000 --- a/packages/dashboard/src/pages/Settings/components/DataSourceSetting.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { MenuItem } from '@mui/material' -import SettingSelect from './SettingSelect' -import { useTrendingDataSource } from '../api' -import { Services } from '../../../API' -import { MarketTrendProvider } from '../../../type' - -export default function DataSourceSetting() { - const source = useTrendingDataSource() - const handleChange = (event: any) => { - const value = event.target.value - Services.Settings.setTrendingDataSource(value) - } - - return ( - - CoinGecko - CoinMarketCap - Uniswap Info - - ) -} diff --git a/packages/dashboard/src/pages/Wallets/api.ts b/packages/dashboard/src/pages/Wallets/api.ts deleted file mode 100644 index d16731b30b45..000000000000 --- a/packages/dashboard/src/pages/Wallets/api.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { createGlobalState } from '@masknet/shared-base-ui' -import { Messages, Services } from '../../API' - -export const [useCurrentCollectibleDataProvider] = createGlobalState( - Services.Settings.getCurrentCollectibleDataProvider, - (x) => Messages.events.currentNonFungibleAssetDataProviderSettings.on(x), -) - -export const [useCurrentSelectedWalletNetwork] = createGlobalState( - Services.Settings.getCurrentSelectedWalletNetwork, - (x) => Messages.events.currentNetworkSettings.on(x), -) diff --git a/packages/dashboard/src/pages/Wallets/components/AddCollectibleDialog/index.tsx b/packages/dashboard/src/pages/Wallets/components/AddCollectibleDialog/index.tsx index 05e0a75d6da2..1037b19e6ec9 100644 --- a/packages/dashboard/src/pages/Wallets/components/AddCollectibleDialog/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/AddCollectibleDialog/index.tsx @@ -1,19 +1,13 @@ -import { FormEvent, memo, useCallback, useEffect, useState } from 'react' +import { FormEvent, memo, useEffect, useState } from 'react' import { MaskDialog, MaskTextField } from '@masknet/theme' import { Box, Button, DialogActions, DialogContent } from '@mui/material' -import { - EthereumTokenType, - isSameAddress, - useERC721ContractDetailed, - useERC721TokenDetailedCallback, - useWallet, -} from '@masknet/web3-shared-evm' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { EthereumAddress } from 'wallet.ts' import { useDashboardI18N } from '../../../../locales' import { z } from 'zod' import { Controller, useForm } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' -import { PluginServices } from '../../../../API' +import { useWeb3Connection, useWallet, useChainId } from '@masknet/plugin-infra/web3' export interface AddCollectibleDialogProps { open: boolean @@ -31,41 +25,48 @@ enum FormErrorType { } export const AddCollectibleDialog = memo(({ open, onClose }) => { - const wallet = useWallet() + const wallet = useWallet(NetworkPluginID.PLUGIN_EVM) const [address, setAddress] = useState('') - const { value: contractDetailed, loading: contractDetailLoading } = useERC721ContractDetailed(address) - const [tokenId, setTokenId, erc721TokenDetailedCallback] = useERC721TokenDetailedCallback(contractDetailed) - - const onSubmit = useCallback(async () => { - if (contractDetailLoading || !wallet) return - - const tokenInDB = await PluginServices.Wallet.getToken(EthereumTokenType.ERC721, address, tokenId) - if (tokenInDB) throw new Error(FormErrorType.Added) - - const tokenDetailed = await erc721TokenDetailedCallback() - - if ( - (tokenDetailed && !isSameAddress(tokenDetailed.info.owner, wallet.address)) || - !tokenDetailed || - !tokenDetailed.info.owner - ) { - throw new Error(FormErrorType.NotExist) - } else { - await PluginServices.Wallet.addToken(tokenDetailed) - onClose() - } - }, [contractDetailLoading, wallet, address, tokenId, erc721TokenDetailedCallback]) - - return ( - - ) + const [tokenId, setTokenId] = useState('') + const connection = useWeb3Connection(NetworkPluginID.PLUGIN_EVM) + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + + return null + + // const [tokenId, setTokenId, erc721TokenDetailedCallback] = useERC721TokenDetailedCallback(contractDetailed) + + // const onSubmit = useCallback(async () => { + // if (contractDetailLoading || !wallet) return + + // const tokenInDB = await PluginServices.Wallet.getToken(SchemaType.ERC721, address, tokenId) + // if (tokenInDB) throw new Error(FormErrorType.Added) + + // const tokenDetailed = await connection?.getNonFungibleToken(address ?? '', tokenId, { + // chainId, + // }) + + // if ( + // (tokenDetailed && !isSameAddress(tokenDetailed.info.owner, wallet.address)) || + // !tokenDetailed || + // !tokenDetailed.info.owner + // ) { + // throw new Error(FormErrorType.NotExist) + // } else { + // await PluginServices.Wallet.addToken(tokenDetailed) + // onClose() + // } + // }, [contractDetailLoading, wallet, address, tokenId, erc721TokenDetailedCallback]) + + // return ( + // + // ) }) export interface AddCollectibleDialogUIProps { diff --git a/packages/dashboard/src/pages/Wallets/components/AddTokenConfirmUI/index.tsx b/packages/dashboard/src/pages/Wallets/components/AddTokenConfirmUI/index.tsx index be023076b0c5..3e559f0f5522 100644 --- a/packages/dashboard/src/pages/Wallets/components/AddTokenConfirmUI/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/AddTokenConfirmUI/index.tsx @@ -2,14 +2,15 @@ import { memo } from 'react' import { useDashboardI18N } from '../../../../locales' import { Box, Button, DialogActions, DialogContent, Stack, Typography } from '@mui/material' import { makeStyles } from '@masknet/theme' -import type { ERC20TokenDetailed } from '@masknet/web3-shared-evm' import { TokenIcon } from '@masknet/shared' import { useFormContext } from 'react-hook-form' +import type { FungibleToken } from '@masknet/web3-shared-base' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' export interface AddTokenConfirmUIProps { onBack: () => void onConfirm: () => void - token?: ERC20TokenDetailed + token?: FungibleToken balance?: string } @@ -58,7 +59,7 @@ export const AddTokenConfirmUI = memo(({ token, balance, address={token?.address ?? ''} name={token?.name} chainId={token?.chainId} - logoURI={token?.logoURI} + logoURI={token?.logoURL} AvatarProps={{ sx: { width: 48, height: 48 } }} /> diff --git a/packages/dashboard/src/pages/Wallets/components/AddTokenFormUI/index.tsx b/packages/dashboard/src/pages/Wallets/components/AddTokenFormUI/index.tsx index 64a925333c93..aa94b934baac 100644 --- a/packages/dashboard/src/pages/Wallets/components/AddTokenFormUI/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/AddTokenFormUI/index.tsx @@ -2,13 +2,14 @@ import { memo } from 'react' import { useDashboardI18N } from '../../../../locales' import { Button, DialogActions, DialogContent, TextField } from '@mui/material' import { makeStyles } from '@masknet/theme' -import type { ERC20TokenDetailed } from '@masknet/web3-shared-evm' import { useFormContext, Controller } from 'react-hook-form' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' +import type { FungibleToken } from '@masknet/web3-shared-base' export interface AddTokenFormUIProps { onNext: () => void onClose: () => void - token?: ERC20TokenDetailed + token?: FungibleToken } const useStyles = makeStyles()((theme) => ({ diff --git a/packages/dashboard/src/pages/Wallets/components/Assets/index.tsx b/packages/dashboard/src/pages/Wallets/components/Assets/index.tsx index 0dfc10391166..53927168aa98 100644 --- a/packages/dashboard/src/pages/Wallets/components/Assets/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Assets/index.tsx @@ -1,9 +1,10 @@ -import { type Web3Plugin, NetworkPluginID, useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' +import { memo, useEffect, useState } from 'react' +import { useCurrentWeb3NetworkPluginID, Web3Helper } from '@masknet/plugin-infra/web3' import { makeStyles, useTabs } from '@masknet/theme' import { TabContext, TabList, TabPanel } from '@mui/lab' import { Box, Button, Tab } from '@mui/material' -import { memo, useEffect, useState } from 'react' import { usePickToken } from '@masknet/shared' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { ContentContainer } from '../../../../components/ContentContainer' import { useDashboardI18N } from '../../../../locales' import { AddCollectibleDialog } from '../AddCollectibleDialog' @@ -38,7 +39,7 @@ export enum AssetTab { const assetTabs = [AssetTab.Token, AssetTab.Collectibles] as const interface TokenAssetsProps { - network: Web3Plugin.NetworkDescriptor | null + network: Web3Helper.NetworkDescriptorAll | null } export const Assets = memo(({ network }) => { diff --git a/packages/dashboard/src/pages/Wallets/components/Balance/index.tsx b/packages/dashboard/src/pages/Wallets/components/Balance/index.tsx index 88763228ff6d..c631b671625e 100644 --- a/packages/dashboard/src/pages/Wallets/components/Balance/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Balance/index.tsx @@ -1,13 +1,14 @@ +import { memo } from 'react' +import { noop } from 'lodash-unified' import { CardIcon, DownloadIcon, MaskWalletIcon, SendIcon, SwapIcon } from '@masknet/icons' -import type { Web3Plugin } from '@masknet/plugin-infra/web3' import { MiniNetworkSelector } from '@masknet/shared' import { DashboardRoutes } from '@masknet/shared-base' import { MaskColorVar } from '@masknet/theme' +import type { NetworkDescriptor, NetworkPluginID } from '@masknet/web3-shared-base' import { Box, Button, buttonClasses, styled, Typography } from '@mui/material' -import { noop } from 'lodash-unified' -import { memo } from 'react' import { useDashboardI18N } from '../../../../locales' import { useIsMatched } from '../../hooks' +import type { Web3Helper } from '@masknet/plugin-infra/web3' const BalanceContainer = styled('div')( ({ theme }) => ` @@ -75,10 +76,23 @@ export interface BalanceCardProps { onBuy(): void onSwap(): void onReceive(): void - networks: Web3Plugin.NetworkDescriptor[] - selectedNetwork: Web3Plugin.NetworkDescriptor | null + networks: Array< + NetworkDescriptor< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['NetworkType'] + > + > + selectedNetwork: NetworkDescriptor< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['NetworkType'] + > | null showOperations: boolean - onSelectNetwork(network: Web3Plugin.NetworkDescriptor | null): void + onSelectNetwork( + network: NetworkDescriptor< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['NetworkType'] + > | null, + ): void } export const Balance = memo( @@ -114,9 +128,12 @@ export const Balance = memo( disabledNonCurrentNetwork={isDisabledNonCurrentChainSelect} selectedNetwork={selectedNetwork} networks={networks} - onSelect={(network: Web3Plugin.NetworkDescriptor | null) => - networks.length <= 1 ? noop : onSelectNetwork(network) - } + onSelect={( + network: NetworkDescriptor< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['NetworkType'] + > | null, + ) => (networks.length <= 1 ? noop : onSelectNetwork(network))} /> diff --git a/packages/dashboard/src/pages/Wallets/components/CollectibleCard/index.tsx b/packages/dashboard/src/pages/Wallets/components/CollectibleCard/index.tsx index 106b6bf9ad8d..eefdac98ecd6 100644 --- a/packages/dashboard/src/pages/Wallets/components/CollectibleCard/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/CollectibleCard/index.tsx @@ -1,17 +1,18 @@ import { memo, useEffect, useMemo, useRef, useState } from 'react' +import { useHoverDirty } from 'react-use' +import { WalletIcon, NFTCardStyledAssetPlayer } from '@masknet/shared' import { Box, Button, Link, Tooltip, Typography } from '@mui/material' import { makeStyles, MaskColorVar } from '@masknet/theme' +import { NetworkPluginID, NonFungibleAsset } from '@masknet/web3-shared-base' import { CollectiblePlaceholder } from '../CollectiblePlaceHolder' -import { useHoverDirty } from 'react-use' import { useDashboardI18N } from '../../../../locales' -import { WalletIcon, NFTCardStyledAssetPlayer } from '@masknet/shared' import { ChangeNetworkTip } from '../FungibleTokenTableRow/ChangeNetworkTip' import { - NetworkPluginID, - useNetworkDescriptor, + useChainId, useCurrentWeb3NetworkPluginID, + useNetworkDescriptor, useWeb3State, - Web3Plugin, + Web3Helper, } from '@masknet/plugin-infra/web3' const useStyles = makeStyles()((theme) => ({ @@ -94,20 +95,23 @@ const useStyles = makeStyles()((theme) => ({ })) export interface CollectibleCardProps { - chainId: number - token: Web3Plugin.NonFungibleToken + token: NonFungibleAsset< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + > onSend(): void renderOrder: number } -export const CollectibleCard = memo(({ chainId, token, onSend, renderOrder }) => { +export const CollectibleCard = memo(({ token, onSend, renderOrder }) => { const t = useDashboardI18N() - const { Utils } = useWeb3State() + const chainId = useChainId() const { classes } = useStyles() const ref = useRef(null) + const { Others } = useWeb3State() as Web3Helper.Web3StateAll const [isHoveringTooltip, setHoveringTooltip] = useState(false) const isHovering = useHoverDirty(ref) - const networkDescriptor = useNetworkDescriptor(token.contract?.chainId) + const networkDescriptor = useNetworkDescriptor(undefined, token.contract?.chainId) const isOnCurrentChain = useMemo(() => chainId === token.contract?.chainId, [chainId, token]) const currentPluginId = useCurrentWeb3NetworkPluginID() @@ -119,10 +123,9 @@ export const CollectibleCard = memo(({ chainId, token, onS const sendable = currentPluginId === NetworkPluginID.PLUGIN_EVM const showSendButton = (isHovering || isHoveringTooltip) && sendable - let nftLink - if (Utils?.resolveNonFungibleTokenLink && token.contract) { - nftLink = Utils?.resolveNonFungibleTokenLink?.(token.contract?.chainId, token.contract.address, token.tokenId) - } + const nftLink = useMemo(() => { + return Others?.explorerResolver.nonFungibleTokenLink(token.chainId, token.address, token.tokenId) + }, [currentPluginId, token.chainId, token.address, token.tokenId]) return ( @@ -130,7 +133,7 @@ export const CollectibleCard = memo(({ chainId, token, onS - {(token.metadata?.assetURL || token.metadata?.iconURL) && token.contract ? ( + {(token.metadata?.mediaURL || token.metadata?.imageURL) && token.contract ? ( (({ chainId, token, onS contractAddress={token.contract.address} chainId={token.contract.chainId} renderOrder={renderOrder} - url={token.metadata.assetURL || token.metadata.iconURL} + url={token.metadata.imageURL || token.metadata.mediaURL} tokenId={token.tokenId} classes={{ loadingFailImage: classes.loadingFailImage, @@ -183,7 +186,7 @@ export const CollectibleCard = memo(({ chainId, token, onS ) : ( - {token.name || token.tokenId} + {token.metadata?.name || token.tokenId} )} diff --git a/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx b/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx index d41558f5516b..cf03dcd06f4a 100644 --- a/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx @@ -2,22 +2,20 @@ import { Dispatch, memo, SetStateAction, useCallback, useEffect, useRef, useStat import { useNavigate } from 'react-router-dom' import { Box, Stack, TablePagination } from '@mui/material' import { makeStyles } from '@masknet/theme' +import { NetworkPluginID, NonFungibleToken } from '@masknet/web3-shared-base' import { LoadingPlaceholder } from '../../../../components/LoadingPlaceholder' -import { DashboardRoutes, EMPTY_LIST } from '@masknet/shared-base' +import { DashboardRoutes } from '@masknet/shared-base' import { EmptyPlaceholder } from '../EmptyPlaceholder' import { CollectibleCard } from '../CollectibleCard' import { useDashboardI18N } from '../../../../locales' -import { PluginMessages } from '../../../../API' import { TransferTab } from '../Transfer' import { - useNetworkDescriptor, - useWeb3State as useWeb3PluginState, - Web3Plugin, useAccount, useCurrentWeb3NetworkPluginID, - NetworkPluginID, + useNetworkDescriptor, + useNonFungibleAssets, + Web3Helper, } from '@masknet/plugin-infra/web3' -import { useAsyncRetry } from 'react-use' const useStyles = makeStyles()({ root: { @@ -37,7 +35,7 @@ const useStyles = makeStyles()({ }) interface CollectibleListProps { - selectedNetwork: Web3Plugin.NetworkDescriptor | null + selectedNetwork: Web3Helper.NetworkDescriptorAll | null } const ITEM_SIZE = { @@ -49,42 +47,45 @@ export const CollectibleList = memo(({ selectedNetwork }) const [page, setPage] = useState(0) const navigate = useNavigate() const account = useAccount() - const { Asset } = useWeb3PluginState() + const { value = [], error, retry, loading } = useNonFungibleAssets() const network = useNetworkDescriptor() const [loadingSize, setLoadingSize] = useState(0) - const [renderData, setRenderData] = useState([]) + const [renderData, setRenderData] = useState< + Array< + NonFungibleToken< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + > + > + >([]) - const { - value = { data: EMPTY_LIST, hasNextPage: false }, - error: collectiblesError, - loading: isQuerying, - retry, - } = useAsyncRetry( - async () => Asset?.getNonFungibleAssets?.(account, { page, size: 20 }, undefined, selectedNetwork || undefined), - [account, Asset?.getNonFungibleAssets, network, selectedNetwork], - ) useEffect(() => { - const unsubscribeTokens = PluginMessages.Wallet.events.erc721TokensUpdated.on(() => retry()) - const unsubscribeSocket = PluginMessages.Wallet.events.socketMessageUpdated.on((info) => { - if (!info.done) { - retry() - } - }) - return () => { - unsubscribeTokens() - unsubscribeSocket() - } + // const unsubscribeTokens = PluginMessages.Wallet.events.erc721TokensUpdated.on(() => retry()) + // const unsubscribeSocket = PluginMessages.Wallet.events.socketMessageUpdated.on((info) => { + // if (!info.done) { + // retry() + // } + // }) + // return () => { + // unsubscribeTokens() + // unsubscribeSocket() + // } }, [retry]) useEffect(() => { if (!loadingSize) return - const render = value.data.slice(page * loadingSize, (page + 1) * loadingSize) + const render = value.slice(page * loadingSize, (page + 1) * loadingSize) setRenderData(render) - }, [value.data, loadingSize, page]) + }, [value, loadingSize, page]) const currentPluginId = useCurrentWeb3NetworkPluginID() const onSend = useCallback( - (detail: Web3Plugin.NonFungibleToken) => { + ( + detail: NonFungibleToken< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + >, + ) => { // Sending NFT is only available on EVM currently. if (currentPluginId !== NetworkPluginID.PLUGIN_EVM) return navigate(DashboardRoutes.WalletsTransfer, { @@ -97,19 +98,18 @@ export const CollectibleList = memo(({ selectedNetwork }) [currentPluginId], ) - const hasNextPage = (page + 1) * loadingSize < value.data.length - const isLoading = renderData.length === 0 && isQuerying + const hasNextPage = (page + 1) * loadingSize < value.length + const isLoading = renderData.length === 0 && loading return ( setLoadingSize(size)} /> @@ -118,30 +118,29 @@ export const CollectibleList = memo(({ selectedNetwork }) export interface CollectibleListUIProps { page: number - onPageChange: Dispatch> hasNextPage: boolean isLoading: boolean isEmpty: boolean showPagination: boolean - chainId: number - dataSource: Web3Plugin.NonFungibleToken[] - onSend(detail: Web3Plugin.NonFungibleToken): void + chainId?: Web3Helper.ChainIdAll + dataSource: Array< + NonFungibleToken< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + > + > + onSend( + detail: NonFungibleToken< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + >, + ): void + onPageChange: Dispatch> setLoadingSize(fn: (pre: number | undefined) => number): void } export const CollectibleListUI = memo( - ({ - page, - onPageChange, - isLoading, - isEmpty, - hasNextPage, - showPagination, - chainId, - dataSource, - onSend, - setLoadingSize, - }) => { + ({ page, onPageChange, isLoading, isEmpty, hasNextPage, showPagination, dataSource, onSend, setLoadingSize }) => { const t = useDashboardI18N() const { classes } = useStyles() const ref = useRef(null) @@ -167,7 +166,6 @@ export const CollectibleListUI = memo( {dataSource.map((x, index) => (
(({ chainId }) => { const { classes } = useStyles() const t = useDashboardI18N() - const networkDescriptor = useNetworkDescriptor(chainId) + const networkDescriptor = useNetworkDescriptor(NetworkPluginID.PLUGIN_EVM, chainId) return (
diff --git a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx index e2236f600657..d0b80f54abf1 100644 --- a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTable/index.tsx @@ -1,25 +1,17 @@ -import { memo, useCallback, useEffect, useState } from 'react' +import { memo, useCallback, useEffect } from 'react' +import { useNavigate } from 'react-router-dom' +import BigNumber from 'bignumber.js' import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material' import { makeStyles, MaskColorVar } from '@masknet/theme' import { useDashboardI18N } from '../../../../locales' import { EmptyPlaceholder } from '../EmptyPlaceholder' import { LoadingPlaceholder } from '../../../../components/LoadingPlaceholder' import { FungibleTokenTableRow } from '../FungibleTokenTableRow' -import { useWeb3State } from '@masknet/web3-shared-evm' -import BigNumber from 'bignumber.js' -import { useRemoteControlledDialog } from '@masknet/shared-base-ui' +import { formatBalance, FungibleAsset, NetworkPluginID } from '@masknet/web3-shared-base' +import { DashboardRoutes, EMPTY_LIST } from '@masknet/shared-base' +import { useCurrentWeb3NetworkPluginID, useFungibleAssets, useWeb3State, Web3Helper } from '@masknet/plugin-infra/web3' import { PluginMessages } from '../../../../API' -import { DashboardRoutes } from '@masknet/shared-base' -import { useNavigate } from 'react-router-dom' -import { useAsync } from 'react-use' -import { - useNetworkDescriptor, - useWeb3State as useWeb3PluginState, - Web3Plugin, - useAccount, - NetworkPluginID, - useCurrentWeb3NetworkPluginID, -} from '@masknet/plugin-infra/web3' +import { useRemoteControlledDialog } from '@masknet/shared-base-ui' const useStyles = makeStyles()((theme) => ({ container: { @@ -69,53 +61,57 @@ interface TokenTableProps { export const FungibleTokenTable = memo(({ selectedChainId }) => { const navigate = useNavigate() - const account = useAccount() - const { Asset } = useWeb3PluginState() - const { portfolioProvider } = useWeb3State() - const network = useNetworkDescriptor() - const [tokenUpdateCount, setTokenUpdateCount] = useState(0) - const { setDialog: openSwapDialog } = useRemoteControlledDialog(PluginMessages.Swap.swapDialogUpdated) - const { - error: detailedTokensError, - loading: detailedTokensLoading, - value: detailedTokens, - } = useAsync( - async () => Asset?.getFungibleAssets?.(account, portfolioProvider, network!), - [account, Asset, portfolioProvider, tokenUpdateCount], - ) + value: fungibleAssets = EMPTY_LIST, + loading: fungibleAssetsLoading, + error: fungibleAssetsError, + } = useFungibleAssets(NetworkPluginID.PLUGIN_EVM) + const { setDialog: openSwapDialog } = useRemoteControlledDialog(PluginMessages.Swap.swapDialogUpdated) useEffect(() => { - PluginMessages.Wallet.events.erc20TokensUpdated.on(() => - setTimeout(() => setTokenUpdateCount((prev) => prev + 1), 100), - ) + // PluginMessages.Wallet.events.erc20TokensUpdated.on(() => + // setTimeout(() => setTokenUpdateCount((prev) => prev + 1), 100), + // ) }, []) - const onSwap = useCallback((token: Web3Plugin.FungibleToken) => { - openSwapDialog({ - open: true, - traderProps: { - defaultInputCoin: { - id: token.id, - name: token.name || '', - symbol: token.symbol || '', - contract_address: token.address, - decimals: token.decimals, + const onSwap = useCallback( + ( + token: FungibleAsset< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + >, + ) => { + openSwapDialog({ + open: true, + traderProps: { + defaultInputCoin: { + id: token.id, + name: token.name || '', + symbol: token.symbol || '', + contract_address: token.address, + decimals: token.decimals, + }, }, - }, - }) - }, []) + }) + }, + [], + ) const onSend = useCallback( - (token: Web3Plugin.FungibleToken) => navigate(DashboardRoutes.WalletsTransfer, { state: { token } }), + ( + token: FungibleAsset< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + >, + ) => navigate(DashboardRoutes.WalletsTransfer, { state: { token } }), [], ) return ( !selectedChainId || x.chainId === selectedChainId)} + isLoading={fungibleAssetsLoading} + isEmpty={!fungibleAssetsLoading && (!!fungibleAssetsError || !fungibleAssets?.length)} + dataSource={fungibleAssets.filter((x) => !selectedChainId || x.chainId === selectedChainId)} onSwap={onSwap} onSend={onSend} /> @@ -125,16 +121,31 @@ export const FungibleTokenTable = memo(({ selectedChainId }) => export interface TokenTableUIProps { isLoading: boolean isEmpty: boolean - dataSource: Array> - onSwap(token: Web3Plugin.FungibleToken): void - onSend(token: Web3Plugin.FungibleToken): void + dataSource: Array< + FungibleAsset< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + > + > + onSwap( + token: FungibleAsset< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + >, + ): void + onSend( + token: FungibleAsset< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + >, + ): void } export const TokenTableUI = memo(({ onSwap, onSend, isLoading, isEmpty, dataSource }) => { const t = useDashboardI18N() const { classes } = useStyles() const currentPluginId = useCurrentWeb3NetworkPluginID() - const { Utils } = useWeb3PluginState() + const { Others } = useWeb3State() return ( @@ -171,11 +182,9 @@ export const TokenTableUI = memo(({ onSwap, onSend, isLoading {dataSource .sort((first, second) => { - const firstValue = new BigNumber( - Utils?.formatBalance?.(first.balance, first.token.decimals) ?? '', - ) + const firstValue = new BigNumber(formatBalance(first.balance, first.decimals) ?? '') const secondValue = new BigNumber( - Utils?.formatBalance?.(second.balance, second.token.decimals) ?? '', + formatBalance(second.balance, second.decimals) ?? '', ) if (firstValue.isEqualTo(secondValue)) return 0 @@ -184,8 +193,8 @@ export const TokenTableUI = memo(({ onSwap, onSend, isLoading }) .map((asset, index) => ( onSend(asset.token)} - onSwap={() => onSwap(asset.token)} + onSend={() => onSend(asset)} + onSwap={() => onSwap(asset)} asset={asset} key={index} /> diff --git a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/ChangeNetworkTip.tsx b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/ChangeNetworkTip.tsx index 25741491728f..4a28680f46cf 100644 --- a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/ChangeNetworkTip.tsx +++ b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/ChangeNetworkTip.tsx @@ -2,7 +2,7 @@ import { memo } from 'react' import { Link, Typography } from '@mui/material' import { useDashboardI18N } from '../../../../locales' import { MaskColorVar } from '@masknet/theme' -import { useNetworkDescriptors, useProviderDescriptor, useWeb3UI } from '@masknet/plugin-infra/web3' +import { useNetworkDescriptors, useProviderDescriptor, useWeb3UI, Web3Helper } from '@masknet/plugin-infra/web3' interface ChangeNetworkTipProps { chainId?: number @@ -11,9 +11,10 @@ interface ChangeNetworkTipProps { export const ChangeNetworkTip = memo(({ chainId }) => { const t = useDashboardI18N() - const providerDescriptor = useProviderDescriptor() - const { NetworkIconClickBait } = useWeb3UI().SelectNetworkMenu ?? {} - const networkDescriptors = useNetworkDescriptors() + const providerDescriptor = useProviderDescriptor() as Web3Helper.ProviderDescriptorAll + const networkDescriptors = useNetworkDescriptors() as Web3Helper.NetworkDescriptorAll[] + const Web3UI = useWeb3UI() as Web3Helper.Web3UIAll + const { NetworkIconClickBait } = Web3UI.SelectNetworkMenu ?? {} const targetNetwork = networkDescriptors.find((x) => x.chainId === chainId) if (!chainId) return null diff --git a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/index.tsx b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/index.tsx index 90edd2545002..6b2a962805ec 100644 --- a/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/FungibleTokenTableRow/index.tsx @@ -4,19 +4,25 @@ import { Box, Button, TableCell, TableRow, Tooltip, Typography } from '@mui/mate import { getMaskColor, makeStyles } from '@masknet/theme' import { FormattedCurrency, TokenIcon, WalletIcon } from '@masknet/shared' import { - CurrencyType, - NetworkPluginID, useChainId, useNetworkDescriptors, useCurrentWeb3NetworkPluginID, useWeb3State, - Web3Plugin, + Web3Helper, } from '@masknet/plugin-infra/web3' +import { + CurrencyType, + formatBalance, + formatCurrency, + FungibleAsset, + NetworkPluginID, + pow10, + toFixed, +} from '@masknet/web3-shared-base' import { ChainId } from '@masknet/web3-shared-evm' import { useDashboardI18N } from '../../../../locales' import { ChangeNetworkTip } from './ChangeNetworkTip' import { getTokenUSDValue } from '../../utils/getTokenUSDValue' -import { pow10, toFixed } from '@masknet/web3-shared-base' const useStyles = makeStyles()((theme) => ({ icon: { @@ -66,7 +72,10 @@ const useStyles = makeStyles()((theme) => ({ })) export interface TokenTableRowProps { - asset: Web3Plugin.Asset + asset: FungibleAsset< + Web3Helper.Definition[NetworkPluginID]['ChainId'], + Web3Helper.Definition[NetworkPluginID]['SchemaType'] + > onSwap(): void onSend(): void } @@ -75,10 +84,10 @@ export const FungibleTokenTableRow = memo(({ asset, onSend, const t = useDashboardI18N() const { classes } = useStyles() const currentChainId = useChainId() - const { Utils } = useWeb3State() + const { Others } = useWeb3State() const networkDescriptors = useNetworkDescriptors() const currentPluginId = useCurrentWeb3NetworkPluginID() - const isOnCurrentChain = useMemo(() => currentChainId === asset.token.chainId, [asset, currentChainId]) + const isOnCurrentChain = useMemo(() => currentChainId === asset.chainId, [asset, currentChainId]) return ( @@ -87,30 +96,30 @@ export const FungibleTokenTableRow = memo(({ asset, onSend, x.chainId === asset.token.chainId)?.icon} + networkIcon={networkDescriptors.find((x) => x.chainId === asset.chainId)?.icon} /> - {asset.token.symbol} + {asset.symbol} - {toFixed(Utils?.formatBalance?.(asset.balance, asset.token.decimals) ?? '', 6)} + {toFixed(formatBalance(asset.balance, asset.decimals) ?? '', 6)} {asset.price?.[CurrencyType.USD] ? new BigNumber(asset.price[CurrencyType.USD] ?? '').gt(pow10(-6)) - ? Utils?.formatCurrency?.(Number.parseFloat(asset.price[CurrencyType.USD] ?? ''), '$') + ? formatCurrency(Number.parseFloat(asset.price[CurrencyType.USD] ?? '')) : '<0.000001' : '-'} @@ -122,8 +131,8 @@ export const FungibleTokenTableRow = memo(({ asset, onSend, ) : ( )} @@ -133,7 +142,7 @@ export const FungibleTokenTableRow = memo(({ asset, onSend, } + title={} placement="top" classes={{ tooltip: classes.tip, arrow: classes.tipArrow }} arrow> @@ -152,9 +161,9 @@ export const FungibleTokenTableRow = memo(({ asset, onSend, } + title={} placement="top" classes={{ tooltip: classes.tip, arrow: classes.tipArrow }} arrow> @@ -162,11 +171,11 @@ export const FungibleTokenTableRow = memo(({ asset, onSend, - - - ) - }, -) + ) : null} + + + {address} + + + + + + + ) +}) diff --git a/packages/dashboard/src/pages/Wallets/components/SelectTokenDialog/index.tsx b/packages/dashboard/src/pages/Wallets/components/SelectTokenDialog/index.tsx index dd2ce2717fd5..10528de822ea 100644 --- a/packages/dashboard/src/pages/Wallets/components/SelectTokenDialog/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/SelectTokenDialog/index.tsx @@ -1,14 +1,15 @@ import { memo } from 'react' import { MaskDialog } from '@masknet/theme' import { useDashboardI18N } from '../../../../locales' -import { ERC20TokenList } from '@masknet/shared' +import { FungibleTokenList } from '@masknet/shared' import { DialogContent } from '@mui/material' -import type { FungibleTokenDetailed } from '@masknet/web3-shared-evm' +import type { FungibleToken } from '@masknet/web3-shared-base' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' export interface SelectTokenDialogProps { open: boolean onClose: () => void - onSelect?(token: FungibleTokenDetailed | null): void + onSelect?(token: FungibleToken | null): void } // todo use remote dialog for add token list dialog @@ -18,7 +19,7 @@ export const SelectTokenDialog = memo(({ open, onClose, return ( - + ) diff --git a/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx b/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx index acd6fd483c64..26c68d834126 100644 --- a/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx @@ -1,6 +1,7 @@ import { memo, useMemo } from 'react' import { CloseIcon, DownloadIcon, InteractionIcon, ITOIcon, RedPacketIcon, UploadIcon } from '@masknet/icons' -import { FilterTransactionType, isSameAddress, TransactionType, useRedPacketConstants } from '@masknet/web3-shared-evm' +import { isSameAddress } from '@masknet/web3-shared-base' +import { FilterTransactionType, TransactionType, useRedPacketConstants } from '@masknet/web3-shared-evm' import { makeStyles, MaskColorVar } from '@masknet/theme' import { Box } from '@mui/material' import classNames from 'classnames' @@ -29,7 +30,7 @@ const useStyles = makeStyles()(() => ({ export interface TransactionIconProps { type?: string - transactionType: string + transactionType?: string address: string failed: boolean } @@ -52,7 +53,7 @@ export interface TransactionIconUIProps { isRedPacket: boolean isFailed: boolean type?: string - transactionType: string + transactionType?: string } export const TransactionIconUI = memo(({ isFailed, isRedPacket, type, transactionType }) => { diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/NFTCard.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/NFTCard.tsx index 936f25160b62..7cbb411891cf 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/NFTCard.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/NFTCard.tsx @@ -1,9 +1,10 @@ -import type { ERC721TokenDetailed } from '@masknet/web3-shared-evm' import { memo, useMemo, useState } from 'react' import { Checkbox, ImageListItem, ImageListItemBar, Box } from '@mui/material' import { getMaskColor, makeStyles, MaskColorVar } from '@masknet/theme' import { CheckedBorderIcon, CheckedIcon } from '@masknet/icons' import { NFTCardStyledAssetPlayer } from '@masknet/shared' +import type { NonFungibleToken } from '@masknet/web3-shared-base' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' const useStyles = makeStyles()({ card: { @@ -60,7 +61,7 @@ const useStyles = makeStyles()({ }) export interface NFTCardProps { - token: ERC721TokenDetailed + token: NonFungibleToken selectedTokenId: string onSelect(tokenId: string): void renderOrder: number @@ -103,8 +104,8 @@ export const NFTCard = memo(({ token, selectedTokenId, onSelect, r }} className={isDisabled ? classes.disabled : ''}> > selectedTokenId: string loading: boolean error?: boolean diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx index 8b28406f77b6..f544b66511ab 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC20.tsx @@ -1,46 +1,52 @@ import { RightIcon } from '@masknet/icons' +import { useGasLimit, useTokenTransferCallback } from '@masknet/plugin-infra/web3-evm' import { - NetworkPluginID, - TokenType, + useChainId, + useFungibleTokenBalance, + useGasPrice, useLookupAddress, useNetworkDescriptor, useWeb3State, - Web3Plugin, + useNativeToken, + useNativeTokenPrice, } from '@masknet/plugin-infra/web3' -import { NetworkType } from '@masknet/public-api' import { FormattedAddress, TokenAmountPanel, usePickToken } from '@masknet/shared' import { MaskColorVar, MaskTextField } from '@masknet/theme' -import { isGreaterThan, isZero, multipliedBy, rightShift } from '@masknet/web3-shared-base' +import { + TokenType, + FungibleToken, + isGreaterThan, + isSameAddress, + isZero, + multipliedBy, + NetworkPluginID, + rightShift, +} from '@masknet/web3-shared-base' import { addGasMargin, - EthereumTokenType, + SchemaType, formatWeiToEther, - FungibleTokenDetailed, - isEIP1559Supported, - isSameAddress, - useChainId, - useFungibleTokenBalance, - useGasLimit, - useGasPrice, - useNativeTokenDetailed, useTokenConstants, - useTokenTransferCallback, + ChainId, + chainResolver, + explorerResolver, + isValidAddress, + NetworkType, } from '@masknet/web3-shared-evm' import TuneIcon from '@mui/icons-material/Tune' import { Box, Button, IconButton, Link, Popover, Stack, Typography } from '@mui/material' import BigNumber from 'bignumber.js' import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useUpdateEffect } from 'react-use' -import { EthereumAddress } from 'wallet.ts' import { useDashboardI18N } from '../../../../locales' import { useGasConfig } from '../../hooks/useGasConfig' -import { useNativeTokenPrice } from './useNativeTokenPrice' -interface TransferERC20Props { - token: FungibleTokenDetailed | Web3Plugin.FungibleToken +export interface TransferERC20Props { + token: FungibleToken } const GAS_LIMIT = 21000 + export const TransferERC20 = memo(({ token }) => { const t = useDashboardI18N() const { NATIVE_TOKEN_ADDRESS } = useTokenConstants() @@ -53,14 +59,14 @@ export const TransferERC20 = memo(({ token }) => { const network = useNetworkDescriptor() const [gasLimit_, setGasLimit_] = useState(0) - const { value: defaultGasPrice = '0' } = useGasPrice() + const { value: defaultGasPrice = '0' } = useGasPrice(NetworkPluginID.PLUGIN_EVM) - const [selectedToken, setSelectedToken] = useState(token) + const [selectedToken, setSelectedToken] = useState(token) const pickToken = usePickToken() - const chainId = useChainId() - const is1559Supported = useMemo(() => isEIP1559Supported(chainId), [chainId]) + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const is1559Supported = useMemo(() => chainResolver.isSupport(chainId, 'EIP1559'), [chainId]) - const { Utils } = useWeb3State() + const { Others } = useWeb3State() useEffect(() => { setSelectedToken(token) @@ -68,22 +74,22 @@ export const TransferERC20 = memo(({ token }) => { // workaround: transferERC20 should support non-evm network const isNativeToken = isSameAddress(selectedToken?.address, NATIVE_TOKEN_ADDRESS) - const tokenType = isNativeToken ? EthereumTokenType.Native : EthereumTokenType.ERC20 + const tokenType = isNativeToken ? SchemaType.Native : SchemaType.ERC20 // balance - const { value: tokenBalance = '0', retry: refetchTokenBalance } = useFungibleTokenBalance( - tokenType, + const { value: tokenBalance = '0', retry: tokenBalanceRetry } = useFungibleTokenBalance( + NetworkPluginID.PLUGIN_EVM, selectedToken?.address ?? '', ) - const nativeToken = useNativeTokenDetailed() - const nativeTokenPrice = useNativeTokenPrice() + const nativeToken = useNativeToken(NetworkPluginID.PLUGIN_EVM) + const nativeTokenPrice = useNativeTokenPrice(NetworkPluginID.PLUGIN_EVM) // #region resolve ENS domain const { value: registeredAddress = '', error: resolveDomainError, loading: resolveDomainLoading, - } = useLookupAddress(address, NetworkPluginID.PLUGIN_EVM) + } = useLookupAddress(NetworkPluginID.PLUGIN_EVM, address) // #endregion // transfer amount @@ -91,12 +97,12 @@ export const TransferERC20 = memo(({ token }) => { const erc20GasLimit = useGasLimit( selectedToken.type === TokenType.Fungible ? selectedToken.symbol === nativeToken.value?.symbol - ? EthereumTokenType.Native - : EthereumTokenType.ERC20 - : selectedToken.type, + ? SchemaType.Native + : SchemaType.ERC20 + : selectedToken.schema, selectedToken.address, transferAmount, - EthereumAddress.isValid(address) ? address : registeredAddress, + isValidAddress(address) ? address : registeredAddress, ) const { gasConfig, onCustomGasSetting, gasLimit, maxFee } = useGasConfig(gasLimit_, GAS_LIMIT) @@ -110,14 +116,14 @@ export const TransferERC20 = memo(({ token }) => { const price = is1559Supported && maxFee ? new BigNumber(maxFee) : gasPrice return multipliedBy(gasLimit, price) }, [gasLimit, gasPrice, maxFee, is1559Supported]) - const gasFeeInUsd = formatWeiToEther(gasFee).multipliedBy(nativeTokenPrice) + const gasFeeInUsd = formatWeiToEther(gasFee).multipliedBy(nativeTokenPrice.value ?? 0) const maxAmount = useMemo(() => { const price = is1559Supported && maxFee ? new BigNumber(maxFee) : gasPrice const gasFee = multipliedBy(addGasMargin(gasLimit), price) let amount_ = new BigNumber(tokenBalance || '0') - amount_ = selectedToken.type === EthereumTokenType.Native ? amount_.minus(gasFee) : amount_ + amount_ = selectedToken.schema === SchemaType.Native ? amount_.minus(gasFee) : amount_ return BigNumber.max(0, amount_).toFixed() }, [tokenBalance, gasPrice, selectedToken?.type, amount, gasLimit, maxFee, is1559Supported]) @@ -125,18 +131,18 @@ export const TransferERC20 = memo(({ token }) => { const onTransfer = useCallback(async () => { let hash: string | undefined - if (EthereumAddress.isValid(address)) { + if (isValidAddress(address)) { hash = await transferCallback(transferAmount, address, gasConfig, memo) - } else if (Utils?.isValidDomain?.(address)) { + } else if (Others?.isValidDomain?.(address)) { hash = await transferCallback(transferAmount, registeredAddress, gasConfig, memo) } if (typeof hash === 'string') { setMemo('') setAddress('') setAmount('') - refetchTokenBalance() + tokenBalanceRetry() } - }, [transferAmount, address, memo, selectedToken.decimals, transferCallback, gasConfig, registeredAddress, Utils]) + }, [transferAmount, address, memo, selectedToken.decimals, transferCallback, gasConfig, registeredAddress, Others]) // #region validation const validationMessage = useMemo(() => { @@ -144,9 +150,9 @@ 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) || Utils?.isValidDomain?.(address))) + if (!(isValidAddress(address) || Others?.isValidDomain?.(address))) return t.wallets_transfer_error_invalid_address() - if (Utils?.isValidDomain?.(address) && (resolveDomainError || !registeredAddress)) { + if (Others?.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() } @@ -158,10 +164,10 @@ export const TransferERC20 = memo(({ token }) => { tokenBalance, selectedToken, amount, - Utils, registeredAddress, resolveDomainError, network, + Others, ]) // #endregion @@ -171,7 +177,7 @@ export const TransferERC20 = memo(({ token }) => { return ( @@ -184,7 +190,7 @@ export const TransferERC20 = memo(({ token }) => { {address} - + @@ -202,7 +208,7 @@ export const TransferERC20 = memo(({ token }) => { ) } - if (Utils?.isValidDomain?.(address) && resolveDomainError) { + if (Others?.isValidDomain?.(address) && resolveDomainError) { return ( @@ -217,7 +223,7 @@ export const TransferERC20 = memo(({ token }) => { }, [ registeredAddress, address, - Utils?.isValidDomain, + Others?.isValidDomain, MaskColorVar, resolveDomainError, network?.type, @@ -268,7 +274,7 @@ export const TransferERC20 = memo(({ token }) => { maxAmount={maxAmount} balance={tokenBalance} label={t.wallets_transfer_amount()} - token={selectedToken as FungibleTokenDetailed} + token={selectedToken} onAmountChange={setAmount} SelectTokenChip={{ loading: false, diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx index 3f546e33fd4c..4056869e28fc 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx @@ -1,46 +1,46 @@ -import { zodResolver } from '@hookform/resolvers/zod' -import { RightIcon } from '@masknet/icons' -import { NetworkPluginID, useLookupAddress, useNetworkDescriptor, useWeb3State } from '@masknet/plugin-infra/web3' -import { WalletMessages } from '@masknet/plugin-wallet' -import { NetworkType } from '@masknet/public-api' -import { FormattedAddress } from '@masknet/shared' -import { DashboardRoutes } from '@masknet/shared-base' -import { useRemoteControlledDialog } from '@masknet/shared-base-ui' import { makeStyles, MaskColorVar, MaskTextField } from '@masknet/theme' -import { useERC721TokenDetailedOwnerList } from '@masknet/web3-providers' -import { multipliedBy } from '@masknet/web3-shared-base' -import { - ERC721ContractDetailed, - ERC721TokenDetailed, - EthereumTokenType, - formatWeiToEther, - isSameAddress, - isValidAddress, - useAccount, - useChainId, - useGasLimit, - useGasPrice, - useNativeTokenDetailed, - useTokenTransferCallback, -} from '@masknet/web3-shared-evm' -import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' -import TuneIcon from '@mui/icons-material/Tune' import { Box, Button, IconButton, Link, Popover, Stack, Typography } from '@mui/material' -import { unionBy } from 'lodash-unified' import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react' -import { Controller, useForm } from 'react-hook-form' -import { useLocation, useNavigate } from 'react-router-dom' import { useAsync, useUpdateEffect } from 'react-use' import { v4 as uuid } from 'uuid' -import { EthereumAddress } from 'wallet.ts' -import { z } from 'zod' -import { Services } from '../../../../API' -import { LoadingPlaceholder } from '../../../../components/LoadingPlaceholder' +import { + isSameAddress, + NonFungibleToken, + NonFungibleTokenContract, + multipliedBy, + NetworkPluginID, +} from '@masknet/web3-shared-base' +import { SchemaType, formatWeiToEther, NetworkType, ChainId, explorerResolver } from '@masknet/web3-shared-evm' +// import { useERC721TokenDetailedOwnerList } from '@masknet/web3-providers' +import { FormattedAddress } from '@masknet/shared' import { useDashboardI18N } from '../../../../locales' -import { useGasConfig } from '../../hooks/useGasConfig' +import { WalletMessages } from '@masknet/plugin-wallet' import { SelectNFTList } from './SelectNFTList' +import { LoadingPlaceholder } from '../../../../components/LoadingPlaceholder' +import { z } from 'zod' +import { EthereumAddress } from 'wallet.ts' +import { Controller, useForm } from 'react-hook-form' +import { zodResolver } from '@hookform/resolvers/zod' +import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' +import TuneIcon from '@mui/icons-material/Tune' +import { useNavigate, useLocation } from 'react-router-dom' +import { DashboardRoutes } from '@masknet/shared-base' +import { useRemoteControlledDialog } from '@masknet/shared-base-ui' +import { useGasConfig } from '../../hooks/useGasConfig' +import { unionBy } from 'lodash-unified' import { TransferTab } from './types' -import { useNativeTokenPrice } from './useNativeTokenPrice' +import { + useAccount, + useChainId, + useGasPrice, + useLookupAddress, + useNetworkDescriptor, + useWeb3State, + useNativeToken, + useNativeTokenPrice, +} from '@masknet/plugin-infra/web3' +import { RightIcon } from '@masknet/icons' +import { useGasLimit, useTokenTransferCallback } from '@masknet/plugin-infra/web3-evm' const useStyles = makeStyles()((theme) => ({ disabled: { @@ -58,14 +58,14 @@ const GAS_LIMIT = 30000 export const TransferERC721 = memo(() => { const t = useDashboardI18N() - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const anchorEl = useRef(null) const { state } = useLocation() as { - state: { erc721Token?: ERC721TokenDetailed; type?: TransferTab } | null + state: { erc721Token?: NonFungibleToken; type?: TransferTab } | null } const { classes } = useStyles() - const [defaultToken, setDefaultToken] = useState(null) + const [defaultToken, setDefaultToken] = useState | null>(null) const navigate = useNavigate() const [popoverOpen, setPopoverOpen] = useState(false) const [recipientError, setRecipientError] = useState<{ @@ -73,18 +73,22 @@ export const TransferERC721 = memo(() => { message: string } | null>(null) const [minPopoverWidth, setMinPopoverWidth] = useState(0) - const [contract, setContract] = useState() + const [contract, setContract] = useState>() const [id] = useState(uuid) const [gasLimit_, setGasLimit_] = useState(0) const network = useNetworkDescriptor() - const { Utils } = useWeb3State() + const { Others } = useWeb3State() + + const account = useAccount(NetworkPluginID.PLUGIN_EVM) + const nativeToken = useNativeToken(NetworkPluginID.PLUGIN_EVM) + const nativeTokenPrice = useNativeTokenPrice(NetworkPluginID.PLUGIN_EVM) // form const schema = z.object({ recipient: z .string() .refine( - (address) => EthereumAddress.isValid(address) || Utils?.isValidDomain?.(address), + (address) => EthereumAddress.isValid(address) || Others?.isValidDomain?.(address), t.wallets_incorrect_address(), ), contract: z.string().min(1, t.wallets_collectible_contract_is_empty()), @@ -106,11 +110,11 @@ export const TransferERC721 = memo(() => { useEffect(() => { if (!state) return if (!state.erc721Token || state.type !== TransferTab.Collectibles) return - if (state.erc721Token.contractDetailed.chainId !== chainId) return - if (contract && !isSameAddress(contract.address, state.erc721Token.contractDetailed.address)) return + if (state.erc721Token.chainId !== chainId) return + if (!isSameAddress(contract?.address, state.erc721Token.address)) return - setContract(state.erc721Token.contractDetailed) - setValue('contract', state.erc721Token.contractDetailed.name) + setContract(state.erc721Token.contract) + setValue('contract', state.erc721Token.contract?.name ?? '') setValue('tokenId', state.erc721Token.tokenId) setDefaultToken(state.erc721Token) }, [state]) @@ -122,35 +126,34 @@ export const TransferERC721 = memo(() => { value: registeredAddress = '', error: resolveDomainError, loading: resolveDomainLoading, - } = useLookupAddress(allFormFields.recipient, NetworkPluginID.PLUGIN_EVM) + } = useLookupAddress(NetworkPluginID.PLUGIN_EVM, allFormFields.recipient) // #endregion // #region check contract address and account address useAsync(async () => { - const recipient = allFormFields.recipient - setRecipientError(null) - if (!recipient && !registeredAddress) return - if (!isValidAddress(recipient) && !isValidAddress(registeredAddress)) return - - clearErrors() - if (isSameAddress(recipient, account) || isSameAddress(registeredAddress, account)) { - setRecipientError({ - type: 'account', - message: t.wallets_transfer_error_same_address_with_current_account(), - }) - } - const result = await Services.Ethereum.getCode(recipient) - if (result !== '0x') { - setRecipientError({ - type: 'contractAddress', - message: t.wallets_transfer_error_is_contract_address(), - }) - } + // const recipient = allFormFields.recipient + // setRecipientError(null) + // if (!recipient && !registeredAddress) return + // if (!isValidAddress(recipient) && !isValidAddress(registeredAddress)) return + // clearErrors() + // if (isSameAddress(recipient, account) || isSameAddress(registeredAddress, account)) { + // setRecipientError({ + // type: 'account', + // message: t.wallets_transfer_error_same_address_with_current_account(), + // }) + // } + // const result = await EVM_RPC.getCode(recipient) + // if (result !== '0x') { + // setRecipientError({ + // type: 'contractAddress', + // message: t.wallets_transfer_error_is_contract_address(), + // }) + // } }, [allFormFields.recipient, clearErrors, registeredAddress]) // #endregion const erc721GasLimit = useGasLimit( - EthereumTokenType.ERC721, + SchemaType.ERC721, contract?.address, undefined, EthereumAddress.isValid(allFormFields.recipient) ? allFormFields.recipient : registeredAddress, @@ -162,11 +165,8 @@ export const TransferERC721 = memo(() => { }, [erc721GasLimit.value]) const { gasConfig, onCustomGasSetting, gasLimit } = useGasConfig(gasLimit_, GAS_LIMIT) - const account = useAccount() - const nativeToken = useNativeTokenDetailed() - const nativeTokenPrice = useNativeTokenPrice() const [{ loading: isTransferring }, transferCallback] = useTokenTransferCallback( - EthereumTokenType.ERC721, + SchemaType.ERC721, contract?.address ?? '', ) @@ -174,47 +174,47 @@ export const TransferERC721 = memo(() => { const { value: defaultGasPrice = '0' } = useGasPrice() const gasPrice = gasConfig.gasPrice || defaultGasPrice const gasFee = useMemo(() => multipliedBy(gasLimit, gasPrice), [gasLimit, gasPrice]) - const gasFeeInUsd = formatWeiToEther(gasFee).multipliedBy(nativeTokenPrice) + const gasFeeInUsd = formatWeiToEther(gasFee).multipliedBy(nativeTokenPrice.value ?? 0) // dialog const { setDialog: setSelectContractDialog } = useRemoteControlledDialog( WalletMessages.events.selectNftContractDialogUpdated, (ev) => { - if (ev.open || !ev.contract || ev.uuid !== id) return - if (!contract || (contract && !isSameAddress(contract.address, ev.contract.address))) { - if ( - contract && - defaultToken && - !isSameAddress(contract.address, defaultToken.contractDetailed.address) - ) { - setDefaultToken(null) - } - setValue('contract', ev.contract.name || ev.contract.address, { shouldValidate: true }) - setContract(ev.contract) - setValue('tokenId', '') - } + // if (ev.open || !ev.contract || ev.uuid !== id) return + // if (!contract || (contract && !isSameAddress(contract.address, ev.contract.address))) { + // if (contract && defaultToken && !isSameAddress(contract.address, defaultToken.address)) { + // setDefaultToken(null) + // } + // setValue('contract', ev.contract.name || ev.contract.address, { shouldValidate: true }) + // setContract(ev.contract) + // setValue('tokenId', '') + // } }, ) - const { - asyncRetry: { loading: loadingOwnerList }, - tokenDetailedOwnerList = [], - refreshing, - } = useERC721TokenDetailedOwnerList(contract, account) + // const { + // asyncRetry: { loading: loadingOwnerList }, + // tokenDetailedOwnerList = [], + // refreshing, + // } = useERC721TokenDetailedOwnerList(contract, account) + + const loadingOwnerList = false + const tokenDetailedOwnerList: Array> = [] + const refreshing = false const onTransfer = useCallback( async (data: FormInputs) => { let hash: string | undefined if (EthereumAddress.isValid(data.recipient)) { hash = await transferCallback(data.tokenId, data.recipient, gasConfig) - } else if (Utils?.isValidDomain?.(data.recipient) && EthereumAddress.isValid(registeredAddress)) { + } else if (Others?.isValidDomain?.(data.recipient) && EthereumAddress.isValid(registeredAddress)) { hash = await transferCallback(data.tokenId, registeredAddress, gasConfig) } if (typeof hash === 'string') { navigate(DashboardRoutes.WalletsHistory) } }, - [transferCallback, contract?.address, gasConfig, registeredAddress, Utils?.isValidDomain, navigate], + [transferCallback, contract?.address, gasConfig, registeredAddress, Others?.isValidDomain], ) const ensContent = useMemo(() => { @@ -223,7 +223,7 @@ export const TransferERC721 = memo(() => { return ( @@ -235,7 +235,7 @@ export const TransferERC721 = memo(() => { {allFormFields.recipient} - + @@ -253,7 +253,7 @@ export const TransferERC721 = memo(() => { ) } - if (Utils?.isValidDomain?.(allFormFields.recipient) && resolveDomainError) { + if (Others?.isValidDomain?.(allFormFields.recipient) && resolveDomainError) { return ( @@ -267,7 +267,7 @@ export const TransferERC721 = memo(() => { }, [ allFormFields.recipient, resolveDomainError, - Utils?.isValidDomain, + Others?.isValidDomain, resolveDomainLoading, network, registeredAddress, @@ -278,10 +278,10 @@ export const TransferERC721 = memo(() => { }, [ensContent]) const contractIcon = useMemo(() => { - if (!contract?.iconURL) return null + if (!contract?.logoURL) return null return ( - + ) }, [contract]) diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx index 4bd3a214af25..13a58bd68212 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/index.tsx @@ -4,12 +4,14 @@ import { Box, Tab } from '@mui/material' import { useTabs } from '@masknet/theme' import { TabContext, TabList, TabPanel } from '@mui/lab' import { TransferERC20 } from './TransferERC20' -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/web3' +import { FungibleToken, NetworkPluginID } from '@masknet/web3-shared-base' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' +import { useNativeToken } from '@masknet/plugin-infra/web3' + const assetTabs = [TransferTab.Token, TransferTab.Collectibles] as const export * from './types' @@ -17,9 +19,13 @@ export * from './types' export const Transfer = memo(() => { const t = useDashboardI18N() const { state } = useLocation() as { - state: { token?: Web3Plugin.FungibleToken; erc721Token?: ERC721TokenDetailed; type?: TransferTab } | null + state: { + token?: FungibleToken + erc721Token?: FungibleToken + type?: TransferTab + } | null } - const { value: nativeToken } = useNativeTokenDetailed() + const { value: nativeToken } = useNativeToken(NetworkPluginID.PLUGIN_EVM) const transferTabsLabel: Record = { [TransferTab.Token]: t.wallets_assets_token(), [TransferTab.Collectibles]: t.wallets_assets_collectibles(), diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/useNativeTokenPrice.ts b/packages/dashboard/src/pages/Wallets/components/Transfer/useNativeTokenPrice.ts deleted file mode 100644 index e906bc79387e..000000000000 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/useNativeTokenPrice.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useCallback, useEffect, useState } from 'react' -import { useInterval } from 'react-use' -import { CryptoPrice, CurrencyType, getCoinGeckoCoinId, useChainId } from '@masknet/web3-shared-evm' -import { UPDATE_CHAIN_STATE_DELAY } from '@masknet/plugin-wallet' - -const URL_BASE = 'https://api.coingecko.com/api/v3' -async function getNativeTokenPrice(tokenId: string, currency: CurrencyType) { - const requestPath = `${URL_BASE}/simple/price?ids=${tokenId}&vs_currencies=${currency}` - const prices = await fetch(requestPath).then((r) => r.json() as Promise) - return prices -} - -const USD = CurrencyType.USD - -export function useNativeTokenPrice() { - const chainId = useChainId() - const coinId = getCoinGeckoCoinId(chainId) - const [price, setPrice] = useState(0) - - const trackPrice = useCallback(() => { - if (!coinId) return - getNativeTokenPrice(coinId, USD).then((result) => setPrice(result[coinId][USD])) - }, [coinId]) - - useEffect(trackPrice, [trackPrice]) - useInterval(trackPrice, UPDATE_CHAIN_STATE_DELAY) - - return price -} diff --git a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/index.tsx b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/index.tsx index 6a67cf0cc5a9..11aaa86280f4 100644 --- a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/index.tsx @@ -1,6 +1,6 @@ import React, { FC, memo } from 'react' import { Box, Button, Stack, Typography } from '@mui/material' -import { ProviderType, TransactionStatusType } from '@masknet/web3-shared-evm' +import { ProviderType } from '@masknet/web3-shared-evm' import { makeStyles, MaskColorVar } from '@masknet/theme' import { FormattedAddress, LoadingAnimation, WalletIcon } from '@masknet/shared' import { useRemoteControlledDialog } from '@masknet/shared-base-ui' @@ -9,14 +9,15 @@ import { useProviderDescriptor, useWallet, useWeb3State, - Web3Plugin, useReverseAddress, + useRecentTransactions, + Web3Helper, + useAccount, } from '@masknet/plugin-infra/web3' -import { EMPTY_LIST } from '@masknet/shared-base' import { PluginMessages } from '../../../../API' -import { useRecentTransactions } from '../../hooks/useRecentTransactions' import { useDashboardI18N } from '../../../../locales' import { useNetworkSelector } from './useNetworkSelector' +import { NetworkPluginID, TransactionStatusType } from '@masknet/web3-shared-base' const useStyles = makeStyles()((theme) => ({ bar: { @@ -63,12 +64,11 @@ const useStyles = makeStyles()((theme) => ({ export const WalletStateBar = memo(() => { const t = useDashboardI18N() + const account = useAccount() const wallet = useWallet() - const networkDescriptor = useNetworkDescriptor() - const providerDescriptor = useProviderDescriptor() - const { value: pendingTransactions = EMPTY_LIST } = useRecentTransactions({ - status: TransactionStatusType.NOT_DEPEND, - }) + const networkDescriptor = useNetworkDescriptor() as Web3Helper.NetworkDescriptorAll + const providerDescriptor = useProviderDescriptor() as Web3Helper.ProviderDescriptorAll + const pendingTransactions = useRecentTransactions(NetworkPluginID.PLUGIN_EVM, TransactionStatusType.NOT_DEPEND) const { openDialog: openWalletStatusDialog } = useRemoteControlledDialog( PluginMessages.Wallet.events.walletStatusDialogUpdated, @@ -80,15 +80,16 @@ export const WalletStateBar = memo(() => { const [menu, openMenu] = useNetworkSelector() - const { value: domain } = useReverseAddress(wallet?.address) + const { value: domain } = useReverseAddress(NetworkPluginID.PLUGIN_EVM, account) - if (!wallet) { + if (!account) { return } return ( { interface WalletStateBarUIProps { isPending: boolean - network?: Web3Plugin.NetworkDescriptor - provider?: Web3Plugin.ProviderDescriptor - wallet?: Web3Plugin.Wallet + network?: Web3Helper.NetworkDescriptorAll + provider?: Web3Helper.ProviderDescriptorAll + name?: string + address?: string domain?: string openConnectWalletDialog(): void openMenu: ReturnType[1] @@ -113,7 +115,8 @@ export const WalletStateBarUI: FC isPending, network, provider, - wallet, + name, + address, domain, openConnectWalletDialog, openMenu, @@ -121,9 +124,9 @@ export const WalletStateBarUI: FC }) => { const t = useDashboardI18N() const { classes } = useStyles() - const { Utils } = useWeb3State() + const { Others } = useWeb3State() - if (!wallet || !network || !provider) return null + if (!network || !provider) return null return ( @@ -165,19 +168,19 @@ export const WalletStateBarUI: FC {provider.type !== ProviderType.MaskWallet ? ( - {domain && Utils?.formatDomainName ? Utils.formatDomainName(domain) : provider.name} + {domain && Others?.formatDomainName ? Others.formatDomainName(domain) : provider.name} ) : ( - {wallet.name} - {domain && Utils?.formatDomainName ? ( - {Utils.formatDomainName(domain)} + {name} + {domain && Others?.formatDomainName ? ( + {Others.formatDomainName(domain)} ) : null} )} - + diff --git a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx index a221eba8c480..48229a080206 100644 --- a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx +++ b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx @@ -2,7 +2,14 @@ import { MenuItem, Stack, Typography } from '@mui/material' import { makeStyles } from '@masknet/theme' import { SuccessIcon } from '@masknet/icons' import { WalletIcon, useMenu } from '@masknet/shared' -import { useChainId, useNetworkDescriptors, useProviderDescriptor, useWeb3UI } from '@masknet/plugin-infra/web3' +import type { NetworkPluginID } from '@masknet/web3-shared-base' +import { + useChainId, + useNetworkDescriptors, + useProviderDescriptor, + useWeb3UI, + Web3Helper, +} from '@masknet/plugin-infra/web3' const useStyles = makeStyles()((theme) => ({ item: { @@ -18,13 +25,14 @@ const useStyles = makeStyles()((theme) => ({ }, })) -export const useNetworkSelector = () => { +export const useNetworkSelector = (pluginID?: NetworkPluginID) => { const { classes } = useStyles() const currentChainId = useChainId() - const providerDescriptor = useProviderDescriptor() - const networkDescriptors = useNetworkDescriptors() - const { NetworkIconClickBait } = useWeb3UI().SelectNetworkMenu ?? {} + const providerDescriptor = useProviderDescriptor() as Web3Helper.ProviderDescriptorAll + const networkDescriptors = useNetworkDescriptors() as Web3Helper.NetworkDescriptorAll[] + const Web3UI = useWeb3UI() as Web3Helper.Web3UIAll + const { NetworkIconClickBait } = Web3UI.SelectNetworkMenu ?? {} const networkMenu = useMenu( ...(networkDescriptors diff --git a/packages/dashboard/src/pages/Wallets/hooks/index.ts b/packages/dashboard/src/pages/Wallets/hooks/index.ts index ad00f5de33a3..25e929f50f28 100644 --- a/packages/dashboard/src/pages/Wallets/hooks/index.ts +++ b/packages/dashboard/src/pages/Wallets/hooks/index.ts @@ -1,5 +1,3 @@ -export * from './useAddressBook' export * from './useERC20TokensDetailed' export * from './useGasConfig' export * from './useIsMatched' -export * from './useRecentTransactions' diff --git a/packages/dashboard/src/pages/Wallets/hooks/useAddressBook.ts b/packages/dashboard/src/pages/Wallets/hooks/useAddressBook.ts deleted file mode 100644 index fbba94c40961..000000000000 --- a/packages/dashboard/src/pages/Wallets/hooks/useAddressBook.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { useEffect } from 'react' -import { useChainId } from '@masknet/web3-shared-evm' -import { useAsyncRetry } from 'react-use' -import { PluginMessages, PluginServices } from '../../../API' - -export function useAddressBook() { - const chainId = useChainId() - const result = useAsyncRetry(async () => PluginServices.Wallet.getAllAddress(chainId), [chainId]) - - useEffect(() => PluginMessages.Wallet.events.addressBookUpdated.on(result.retry), [result.retry]) - - return result -} diff --git a/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts b/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts index 3d5d5cad4ab0..0d11d923afaa 100644 --- a/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts +++ b/packages/dashboard/src/pages/Wallets/hooks/useERC20TokensDetailed.ts @@ -1,49 +1,43 @@ -import { - EthereumTokenType, - isSameAddress, - useAssetsFromChain, - useERC20TokensDetailedFromTokenLists, - useNativeTokenDetailed, - useTokenConstants, - useTokenListConstants, -} from '@masknet/web3-shared-evm' -import { uniqBy } from 'lodash-unified' -import { useMemo } from 'react' - export function useERC20TokensDetailed() { - const { ERC20 } = useTokenListConstants() - const { value: nativeTokenDetailed } = useNativeTokenDetailed() - const { value: erc20TokensDetailed = [], loading: erc20TokensDetailedLoading } = - useERC20TokensDetailedFromTokenLists(ERC20) + // const { FUNGIBLE_TOKEN_LISTS = [] } = useTokenListConstants() + // const { value: nativeTokenDetailed } = useFungibleToken(NetworkPluginID.PLUGIN_EVM) + // const { value: erc20TokensDetailed = [], loading: erc20TokensDetailedLoading } = useFungibleTokensFromTokenList( + // NetworkPluginID.PLUGIN_EVM, + // ) - // #region mask token - const { MASK_ADDRESS } = useTokenConstants() - // #endregion + // // #region mask token + // const { MASK_ADDRESS } = useTokenConstants() + // // #endregion - const tokens = useMemo( - () => - uniqBy( - nativeTokenDetailed ? [nativeTokenDetailed, ...erc20TokensDetailed] : [...erc20TokensDetailed], - (x) => x.address.toLowerCase(), - ).sort((a, z) => { - if (a.type === EthereumTokenType.Native) return -1 - if (z.type === EthereumTokenType.Native) return 1 - if (isSameAddress(a.address, MASK_ADDRESS)) return -1 - if (isSameAddress(z.address, MASK_ADDRESS)) return 1 - return 0 - }), - [nativeTokenDetailed, erc20TokensDetailed.length], - ) + // const tokens = useMemo( + // () => + // uniqBy( + // nativeTokenDetailed ? [nativeTokenDetailed, ...erc20TokensDetailed] : [...erc20TokensDetailed], + // (x) => x.address.toLowerCase(), + // ).sort((a, z) => { + // if (a.type === SchemaType.Native) return -1 + // if (z.type === SchemaType.Native) return 1 + // if (isSameAddress(a.address, MASK_ADDRESS)) return -1 + // if (isSameAddress(z.address, MASK_ADDRESS)) return 1 + // return 0 + // }), + // [nativeTokenDetailed, erc20TokensDetailed.length], + // ) - const { - value: assetsDetailedChain = [], - loading: assetsDetailedChainLoading, - error: assetsDetailedChainError, - } = useAssetsFromChain(tokens) + // const { + // value: assetsDetailedChain = [], + // loading: assetsDetailedChainLoading, + // error: assetsDetailedChainError, + // } = useAssetsFromChain(tokens) + // return { + // value: assetsDetailedChain, + // loading: erc20TokensDetailedLoading || assetsDetailedChainLoading, + // error: assetsDetailedChainError, + // } return { - value: assetsDetailedChain, - loading: erc20TokensDetailedLoading || assetsDetailedChainLoading, - error: assetsDetailedChainError, + value: [], + loading: false, + error: undefined, } } diff --git a/packages/dashboard/src/pages/Wallets/hooks/useGasConfig.ts b/packages/dashboard/src/pages/Wallets/hooks/useGasConfig.ts index 51b62436afaf..4b28631e388c 100644 --- a/packages/dashboard/src/pages/Wallets/hooks/useGasConfig.ts +++ b/packages/dashboard/src/pages/Wallets/hooks/useGasConfig.ts @@ -1,24 +1,25 @@ import { useEffect, useMemo, useState } from 'react' import { toHex } from 'web3-utils' import BigNumber from 'bignumber.js' -import { formatGweiToWei, GasOption, isEIP1559Supported, useChainId, useGasPrice } from '@masknet/web3-shared-evm' +import { chainResolver, formatGweiToWei } from '@masknet/web3-shared-evm' import { useRemoteControlledDialog } from '@masknet/shared-base-ui' import { WalletMessages } from '@masknet/plugin-wallet' -import { useGasOptions } from '../../../hooks/useGasOptions' +import { useChainId, useGasOptions, useGasPrice } from '@masknet/plugin-infra/web3' +import { GasOptionType, NetworkPluginID } from '@masknet/web3-shared-base' export const useGasConfig = (gasLimit: number, minGasLimit: number) => { - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const [gasLimit_, setGasLimit_] = useState(0) const [customGasPrice, setCustomGasPrice] = useState(0) - const [gasOption, setGasOption] = useState(GasOption.Medium) + const [gasOption, setGasOption] = useState(GasOptionType.NORMAL) const [maxFee, setMaxFee] = useState(0) const [priorityFee, setPriorityFee] = useState(0) - const is1559Supported = useMemo(() => isEIP1559Supported(chainId), [chainId]) - const { value: defaultGasPrice = '0' } = useGasPrice() + const is1559Supported = useMemo(() => chainResolver.isSupport(chainId, 'EIP1559'), [chainId]) + const { value: defaultGasPrice = '0' } = useGasPrice(NetworkPluginID.PLUGIN_EVM) const gasPrice = customGasPrice || defaultGasPrice - const { gasOptions } = useGasOptions() + const { value: gasOptions } = useGasOptions(NetworkPluginID.PLUGIN_EVM) const { setDialog: setGasSettingDialog, closeDialog } = useRemoteControlledDialog( WalletMessages.events.gasSettingDialogUpdated, @@ -44,29 +45,28 @@ export const useGasConfig = (gasLimit: number, minGasLimit: number) => { if (!gasOptions) return if (is1559Supported) { - const gasLevel = gasOptions.medium as Exclude + const gasLevel = gasOptions.normal setMaxFee((oldVal) => { - return !oldVal ? formatGweiToWei(gasLevel?.suggestedMaxFeePerGas ?? 0) : oldVal + return !oldVal ? formatGweiToWei(gasLevel?.suggestedMaxFeePerGas ?? '0') : oldVal }) setPriorityFee((oldVal) => { - return !oldVal ? formatGweiToWei(gasLevel?.suggestedMaxPriorityFeePerGas ?? 0) : oldVal + return !oldVal ? formatGweiToWei(gasLevel?.suggestedMaxPriorityFeePerGas ?? '0') : oldVal }) } else { - setCustomGasPrice((oldVal) => (!oldVal ? (gasOptions.medium as number) : oldVal)) + setCustomGasPrice((oldVal) => (!oldVal ? gasOptions.normal.suggestedMaxFeePerGas : oldVal)) } - }, [is1559Supported, gasOptions?.medium]) + }, [is1559Supported, gasOptions?.normal]) useEffect(() => { if (!gasOptions) return - if (is1559Supported) { - const gasLevel = gasOptions.medium as Exclude + const gasLevel = gasOptions.normal setMaxFee(formatGweiToWei(gasLevel?.suggestedMaxFeePerGas ?? 0)) setPriorityFee(formatGweiToWei(gasLevel?.suggestedMaxPriorityFeePerGas ?? 0)) } else { - setCustomGasPrice(gasOptions.medium as number) + setCustomGasPrice(gasOptions.normal.suggestedMaxFeePerGas) } - }, [chainId, gasOptions?.medium]) + }, [chainId, gasOptions?.normal]) const gasConfig = useMemo(() => { return is1559Supported diff --git a/packages/dashboard/src/pages/Wallets/hooks/useRecentTransactions.ts b/packages/dashboard/src/pages/Wallets/hooks/useRecentTransactions.ts deleted file mode 100644 index 96e38d16f58b..000000000000 --- a/packages/dashboard/src/pages/Wallets/hooks/useRecentTransactions.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { useEffect } from 'react' -import { useAsyncRetry } from 'react-use' -import { useAccount, useChainId } from '@masknet/web3-shared-evm' -import { PluginMessages, PluginServices } from '../../../API' -import type { RecentTransactionOptions } from '../../../../../mask/src/plugins/Wallet/services' - -// todo: should merge in plugin infra package when plugin infra ready -export function useRecentTransactions(options?: RecentTransactionOptions) { - const account = useAccount() - const chainId = useChainId() - - const result = useAsyncRetry(async () => { - if (!account) return [] - return PluginServices.Wallet.getRecentTransactions(chainId, account, options) - }, [chainId, account, JSON.stringify(options)]) - - useEffect(() => PluginMessages.Wallet.events.transactionStateUpdated.on(result.retry), [result.retry]) - useEffect(() => PluginMessages.Wallet.events.transactionsUpdated.on(result.retry), [result.retry]) - - return result -} diff --git a/packages/dashboard/src/pages/Wallets/index.tsx b/packages/dashboard/src/pages/Wallets/index.tsx index d211a8c7eace..413fbdd66e2e 100644 --- a/packages/dashboard/src/pages/Wallets/index.tsx +++ b/packages/dashboard/src/pages/Wallets/index.tsx @@ -1,22 +1,19 @@ import { getRegisteredWeb3Networks, - NetworkPluginID, useAccount, useChainId, - useNetworkDescriptor, useCurrentWeb3NetworkPluginID, - useWallet, + useFungibleAssets, + useNetworkDescriptor, useWallets, - useWeb3State as useWeb3PluginState, - Web3Plugin, + Web3Helper, } from '@masknet/plugin-infra/web3' +import { DashboardRoutes, EMPTY_LIST, relativeRouteOf } from '@masknet/shared-base' import { useRemoteControlledDialog } from '@masknet/shared-base-ui' -import { DashboardRoutes, relativeRouteOf } from '@masknet/shared-base' -import { useWeb3State } from '@masknet/web3-shared-evm' +import { NetworkPluginID } from '@masknet/web3-shared-base' import BigNumber from 'bignumber.js' import { useEffect, useMemo, useState } from 'react' import { Route, Routes, useLocation, useNavigate } from 'react-router-dom' -import { useAsync } from 'react-use' import { PluginMessages } from '../../API' import { PageFrame } from '../../components/PageFrame' import { useDashboardI18N } from '../../locales' @@ -31,16 +28,14 @@ import { StartUp } from './StartUp' import { getTokenUSDValue } from './utils/getTokenUSDValue' const r = relativeRouteOf(DashboardRoutes.Wallets) + function Wallets() { - const wallet = useWallet() + const t = useDashboardI18N() const wallets = useWallets() const navigate = useNavigate() - const t = useDashboardI18N() - const currentChainId = useChainId() - const { Asset } = useWeb3PluginState() + const chainId = useChainId() const account = useAccount() - const { portfolioProvider } = useWeb3State() - const network = useNetworkDescriptor() + const { value: fungibleAssets = EMPTY_LIST } = useFungibleAssets(NetworkPluginID.PLUGIN_EVM) const { pathname } = useLocation() const isWalletPath = useIsMatched(DashboardRoutes.Wallets) @@ -50,19 +45,15 @@ function Wallets() { const [receiveOpen, setReceiveOpen] = useState(false) const networks = getRegisteredWeb3Networks() - const networkDescriptor = useNetworkDescriptor() const pluginId = useCurrentWeb3NetworkPluginID() - const [selectedNetwork, setSelectedNetwork] = useState( + const networkDescriptor = useNetworkDescriptor() as Web3Helper.NetworkDescriptorAll + const [selectedNetwork, setSelectedNetwork] = useState( networkDescriptor ?? null, ) - const { openDialog: openBuyDialog } = useRemoteControlledDialog(PluginMessages.Transak.buyTokenDialogUpdated) + const { openDialog: openBuyDialog } = useRemoteControlledDialog(PluginMessages.Transak?.buyTokenDialogUpdated) const { openDialog: openSwapDialog } = useRemoteControlledDialog(PluginMessages.Swap.swapDialogUpdated) - const { value: detailedTokens } = useAsync( - async () => Asset?.getFungibleAssets?.(account, portfolioProvider, network!), - [account, Asset, portfolioProvider, network], - ) const renderNetworks = useMemo(() => { return networks.filter((x) => pluginId === x.networkSupporterPluginID && x.isMainnet) }, [networks, pluginId]) @@ -87,13 +78,13 @@ function Wallets() { }, [pathname, defaultNetwork]) const balance = useMemo(() => { - if (!detailedTokens || !detailedTokens.length) return 0 + if (!fungibleAssets || !fungibleAssets.length) return 0 - const values = detailedTokens + const values = fungibleAssets .filter((x) => (selectedNetwork ? x.chainId === selectedNetwork.chainId : true)) .map((y) => getTokenUSDValue(y.value)) return BigNumber.sum(...values).toNumber() - }, [selectedNetwork, detailedTokens]) + }, [selectedNetwork, fungibleAssets]) const pateTitle = useMemo(() => { if (wallets.length === 0) return t.create_wallet_form_title() @@ -107,7 +98,7 @@ function Wallets() { return ( }> - {!wallet ? ( + {!account ? ( ) : ( <> @@ -127,18 +118,13 @@ function Wallets() { } /> } + element={} /> )} - {wallet ? ( - setReceiveOpen(false)} - /> + {account ? ( + setReceiveOpen(false)} /> ) : null} ) diff --git a/packages/dashboard/src/pages/Wallets/utils/getTokenUSDValue.tsx b/packages/dashboard/src/pages/Wallets/utils/getTokenUSDValue.tsx index 92ae2df56215..80d01ae43070 100644 --- a/packages/dashboard/src/pages/Wallets/utils/getTokenUSDValue.tsx +++ b/packages/dashboard/src/pages/Wallets/utils/getTokenUSDValue.tsx @@ -1,4 +1,4 @@ -import { CurrencyType } from '@masknet/plugin-infra/web3' +import { CurrencyType } from '@masknet/web3-shared-base' export const getTokenUSDValue = (value?: { [key in CurrencyType]?: string }) => value ? Number.parseFloat(value[CurrencyType.USD] ?? '') : 0 diff --git a/packages/dashboard/src/web3/context.ts b/packages/dashboard/src/web3/context.ts deleted file mode 100644 index d97ac196dc69..000000000000 --- a/packages/dashboard/src/web3/context.ts +++ /dev/null @@ -1,155 +0,0 @@ -import type { Subscription } from 'use-subscription' -import { - ChainId, - ERC1155TokenDetailed, - ERC721TokenDetailed, - FungibleAssetProvider, - ProviderType, - ERC20TokenDetailed, - EthereumTokenType, - NetworkType, - Web3ProviderType, - isInjectedProvider, -} from '@masknet/web3-shared-evm' -import { getProxyWebsocketInstance } from '@masknet/web3-shared-base' -import { Services, Messages, PluginServices, PluginMessages } from '../API' -import { TokenList } from '@masknet/web3-providers' - -export const Web3Context: Web3ProviderType = { - allowTestnet: createSubscriptionFromAsync(Services.Settings.getWalletAllowTestChain, false, () => { - return () => {} - }), - account: createSubscriptionFromAsync( - async () => { - const providerType = await Services.Settings.getCurrentSelectedWalletProvider() - if (isInjectedProvider(providerType) || providerType === ProviderType.Fortmatic) return '' - return Services.Settings.getSelectedWalletAddress() - }, - '', - (callback) => { - const a = Messages.events.currentAccountSettings.on(callback) - const b = Messages.events.currentProviderSettings.on(callback) - return () => void [a(), b()] - }, - ), - tokenPrices: createSubscriptionFromAsync( - Services.Settings.getTokenPrices, - {}, - Messages.events.currentTokenPricesSettings.on, - ), - chainId: createSubscriptionFromAsync( - Services.Settings.getChainId, - ChainId.Mainnet, - Messages.events.currentChainIdSettings.on, - ), - providerType: createSubscriptionFromAsync( - Services.Settings.getCurrentSelectedWalletProvider, - ProviderType.MaskWallet, - Messages.events.currentProviderSettings.on, - ), - networkType: createSubscriptionFromAsync( - Services.Settings.getCurrentSelectedWalletNetwork, - NetworkType.Ethereum, - Messages.events.currentNetworkSettings.on, - ), - walletPrimary: createSubscriptionFromAsync( - PluginServices.Wallet.getWalletPrimary, - null, - PluginMessages.Wallet.events.walletsUpdated.on, - ), - wallets: createSubscriptionFromAsync( - PluginServices.Wallet.getWallets, - [], - PluginMessages.Wallet.events.walletsUpdated.on, - ), - erc20Tokens: createSubscriptionFromAsync( - () => PluginServices.Wallet.getTokens(EthereumTokenType.ERC20), - [], - PluginMessages.Wallet.events.erc20TokensUpdated.on, - ), - erc721Tokens: createSubscriptionFromAsync( - () => PluginServices.Wallet.getTokens(EthereumTokenType.ERC721), - [], - PluginMessages.Wallet.events.erc721TokensUpdated.on, - ), - erc1155Tokens: createSubscriptionFromAsync( - () => PluginServices.Wallet.getTokens(EthereumTokenType.ERC1155), - [], - PluginMessages.Wallet.events.erc1155TokensUpdated.on, - ), - portfolioProvider: createSubscriptionFromAsync( - Services.Settings.getCurrentPortfolioDataProvider, - FungibleAssetProvider.DEBANK, - Messages.events.currentFungibleAssetDataProviderSettings.on, - ), - - addToken: PluginServices.Wallet.addToken, - removeToken: PluginServices.Wallet.removeToken, - trustToken: PluginServices.Wallet.trustToken, - blockToken: PluginServices.Wallet.blockToken, - - request: Services.Ethereum.request, - - getAssetsList: PluginServices.Wallet.getAssetsList, - getAssetsListNFT: PluginServices.Wallet.getAssetsListNFT, - getCollectionsNFT: PluginServices.Wallet.getCollectionsNFT, - getAddressNamesList: PluginServices.Wallet.getAddressNames, - getTransactionList: PluginServices.Wallet.getTransactionList, - fetchERC20TokensFromTokenLists: TokenList.fetchERC20TokensFromTokenLists, - providerSocket: getProxyWebsocketInstance((info) => - PluginMessages.Wallet.events.socketMessageUpdated.sendToAll(info), - ), -} - -// double check -function createSubscriptionFromAsync( - f: () => Promise, - defaultValue: T, - onChange: (callback: () => void) => () => void, -): Subscription { - // 0 - idle, 1 - updating state, > 1 - waiting state - let beats = 0 - let state = defaultValue - const { subscribe, trigger } = getEventTarget() - f() - .then((v) => (state = v)) - .finally(trigger) - const flush = async () => { - state = await f() - beats -= 1 - if (beats > 0) { - beats = 1 - setTimeout(flush, 0) - } else if (beats < 0) { - beats = 0 - } - trigger() - } - return { - getCurrentValue: () => state, - subscribe: (sub) => { - const a = subscribe(sub) - const b = onChange(async () => { - beats += 1 - if (beats === 1) flush() - }) - return () => void [a(), b()] - }, - } -} - -function getEventTarget() { - const event = new EventTarget() - const EVENT = 'event' - let timer: ReturnType - function trigger() { - clearTimeout(timer) - // delay to update state to ensure that all settings to be synced globally - timer = setTimeout(() => event.dispatchEvent(new Event(EVENT)), 600) - } - function subscribe(f: () => void) { - event.addEventListener(EVENT, f) - return () => event.removeEventListener(EVENT, f) - } - return { trigger, subscribe } -} diff --git a/packages/dashboard/stories/components/Wallet/CollectibleCard.tsx b/packages/dashboard/stories/components/Wallet/CollectibleCard.tsx index 580fce31c65c..9eb9a44101b1 100644 --- a/packages/dashboard/stories/components/Wallet/CollectibleCard.tsx +++ b/packages/dashboard/stories/components/Wallet/CollectibleCard.tsx @@ -1,32 +1,36 @@ import { story } from '@masknet/storybook-shared' +import { TokenType } from '@masknet/web3-shared-base' +import { SchemaType } from '@masknet/web3-shared-evm' import { CollectibleCard as C } from '../../../src/pages/Wallets/components/CollectibleCard' -import { TokenType } from '@masknet/plugin-infra/web3' const { meta, of } = story(C) export default meta({ title: 'Components/Wallet/Collectible Card' }) export const CollectibleCard = of({ args: { - chainId: 1, token: { id: 'token_id', chainId: 1, tokenId: '608932', + address: '', type: TokenType.NonFungible, - name: 'Rarible 1155', - description: '', - owner: 'test_owner', + schema: SchemaType.ERC721, + owner: { + nickname: 'test_owner', + }, metadata: { + chainId: 1, name: 'Rarible 1155', + symbol: 'RAB', description: '', mediaType: '', }, contract: { - id: 'address', - address: 'address', chainId: 1, name: '', symbol: '', + address: 'address', + schema: SchemaType.ERC721, }, }, onSend() {}, diff --git a/packages/dashboard/stories/components/Wallet/ReceiveDialog.tsx b/packages/dashboard/stories/components/Wallet/ReceiveDialog.tsx index 0605dd6ab693..3cf9b1b35df2 100644 --- a/packages/dashboard/stories/components/Wallet/ReceiveDialog.tsx +++ b/packages/dashboard/stories/components/Wallet/ReceiveDialog.tsx @@ -1,7 +1,6 @@ import { story } from '@masknet/storybook-shared' -import { ReceiveDialogUI as C } from '../../../src/pages/Wallets/components/ReceiveDialog' import { action } from '@storybook/addon-actions' -import { NetworkType } from '@masknet/web3-shared-evm' +import { ReceiveDialogUI as C } from '../../../src/pages/Wallets/components/ReceiveDialog' const { meta, of } = story(C) @@ -11,8 +10,6 @@ export const ReceiveDialog = of({ args: { open: true, onClose: action('onClose'), - chainName: 'Ethereum', - walletAddress: '0xFD7A5D91AF554ACD8ED07c7911E8556a7D20D88a', - currentNetworkType: NetworkType.Ethereum, + address: '0xFD7A5D91AF554ACD8ED07c7911E8556a7D20D88a', }, }) diff --git a/packages/dashboard/tsconfig.json b/packages/dashboard/tsconfig.json index cfb7a22eb371..f65c8ec8ec49 100644 --- a/packages/dashboard/tsconfig.json +++ b/packages/dashboard/tsconfig.json @@ -18,6 +18,8 @@ { "path": "../web3-providers" }, { "path": "../icons/" }, { "path": "../plugin-infra" }, + { "path": "../plugins/Solana/" }, + { "path": "../plugins/EVM/" }, { "path": "../plugins/Flow/" }, { "path": "../plugins/Wallet/" }, { "path": "../backup-format/" }, diff --git a/packages/injected-script/main/GlobalVariableBridge/index.ts b/packages/injected-script/main/GlobalVariableBridge/index.ts index c9569d02f980..c832ab3981a6 100644 --- a/packages/injected-script/main/GlobalVariableBridge/index.ts +++ b/packages/injected-script/main/GlobalVariableBridge/index.ts @@ -13,14 +13,27 @@ function read(path: string) { const fragments = apply(split, path, ['.' as any]) let result: any = window while (fragments.length !== 0) { - const key = apply(shift, fragments, []) - result = key ? result[key] : result + try { + const key = apply(shift, fragments, []) + result = key ? result[key] : result + } catch { + return + } } return result } export function access(path: string, id: number, property: string) { - handlePromise(id, () => read(path)[property]) + handlePromise(id, () => { + const item = read(path)[property] + + // the public key cannot transfer correctly between pages, since stringify it manually + if (path === 'solflare' && property === 'publicKey') { + return item.toBase58() + } + + return item + }) } export function callRequest(path: string, id: number, request: unknown) { @@ -37,16 +50,22 @@ export function bindEvent(path: string, bridgeEvent: keyof InternalEvents, event read(path).on( event, clone_into((...args: any[]) => { - sendEvent(bridgeEvent, event, args) + // TODO: type unsound + sendEvent(bridgeEvent, path, event, args) }), ) } function untilInner(name: string) { if (has(window, name)) return apply<(result: true) => Promise>(resolve, Promise, [true]) - return new Promise((r) => { + + let restCheckTimes = 150 // 30s + + return new Promise((resolve) => { function check() { - if (has(window, name)) return r(true) + restCheckTimes -= 1 + if (restCheckTimes < 0) return + if (has(window, name)) return resolve(true) apply(setTimeout, window, [check, 200]) } check() diff --git a/packages/injected-script/main/communicate.ts b/packages/injected-script/main/communicate.ts index 44489e68e40a..ffc597ebf0ed 100644 --- a/packages/injected-script/main/communicate.ts +++ b/packages/injected-script/main/communicate.ts @@ -27,43 +27,19 @@ document.addEventListener(CustomEventId, (e) => { case 'resolvePromise': return - // solana - case 'solanaBridgeRequestListen': - return apply(bindEvent, null, ['solana', 'solanaBridgeOnEvent', ...r[1]]) - case 'solanaBridgeExecute': - return apply(execute, null, [...r[1]]) - case 'solanaBridgeSendRequest': - return apply(callRequest, null, ['solana', ...r[1]]) - case 'solanaBridgePrimitiveAccess': - return apply(access, null, ['solana', ...r[1]]) - case 'untilSolanaBridgeOnline': - return apply(until, null, ['solana', ...r[1]]) - case 'solanaBridgeOnEvent': - return - - // ethereum - case 'ethBridgeRequestListen': - return apply(bindEvent, null, ['ethereum', 'ethBridgeOnEvent', ...r[1]]) - case 'ethBridgeSendRequest': - return apply(callRequest, null, ['ethereum', ...r[1]]) - case 'ethBridgePrimitiveAccess': - return apply(access, null, ['ethereum', ...r[1]]) - case 'untilEthBridgeOnline': - return apply(until, null, ['ethereum', ...r[1]]) - case 'ethBridgeOnEvent': - return - - // coin98 - case 'coin98BridgeRequestListen': - return apply(bindEvent, null, ['coin98.provider', 'coin98BridgeOnEvent', ...r[1]]) - case 'coin98BridgeSendRequest': - return apply(callRequest, null, ['coin98.provider', ...r[1]]) - case 'coin98BridgePrimitiveAccess': - return apply(access, null, ['coin98.provider', ...r[1]]) - case 'untilCoin98BridgeOnline': - return apply(until, null, ['coin98', ...r[1]]) - case 'coin98BridgeOnEvent': + // web3 + case 'web3BridgeBindEvent': + return apply(bindEvent, null, r[1]) + case 'web3BridgeEmitEvent': return + case 'web3BridgeSendRequest': + return apply(callRequest, null, r[1]) + case 'web3BridgePrimitiveAccess': + return apply(access, null, r[1]) + case 'web3UntilBridgeOnline': + return apply(until, null, r[1]) + case 'web3BridgeExecute': + return apply(execute, null, r[1]) default: const neverEvent: never = r[0] diff --git a/packages/injected-script/package.json b/packages/injected-script/package.json index 308b4efd55ff..9d322954c7cb 100644 --- a/packages/injected-script/package.json +++ b/packages/injected-script/package.json @@ -13,9 +13,6 @@ "build": "rollup -c", "start": "rollup -c -w" }, - "dependencies": { - "web3-core-helpers": "1.7.3" - }, "devDependencies": { "@rollup/plugin-sucrase": "^4.0.4", "rollup": "^2.73.0", diff --git a/packages/injected-script/sdk/Base.ts b/packages/injected-script/sdk/Base.ts new file mode 100644 index 000000000000..253aa966ec3f --- /dev/null +++ b/packages/injected-script/sdk/Base.ts @@ -0,0 +1,101 @@ +import { createPromise, sendEvent } from './utils' + +export class InjectedProvider { + private events = new Map>() + private isReadyInternal = false + private isConnectedInternal = false + + constructor(public pathname: string) { + this.startup() + } + + private async startup() { + await this.untilAvailable() + + this.on('connected', () => { + this.isConnectedInternal = true + }) + this.on('disconnect', () => { + this.isConnectedInternal = false + }) + + this.isConnectedInternal = (await this.getProperty('isConnected')) as boolean + } + + get isReady() { + return this.isReadyInternal + } + + get isConnected() { + return this.isConnectedInternal + } + + /** + * Build the connection. + */ + connect(options: unknown): Promise { + return createPromise((id) => sendEvent('web3BridgeExecute', [this.pathname, 'connect'].join('.'), id, options)) + } + + /** + * Break the connections. + */ + disconnect(): Promise { + return createPromise((id) => sendEvent('web3BridgeExecute', [this.pathname, 'disconnect'].join('.'), id)) + } + + /** + * Wait until the sdk object injected into the page. + */ + async untilAvailable(validator: () => Promise = () => Promise.resolve(true)): Promise { + await createPromise((id) => sendEvent('web3UntilBridgeOnline', this.pathname.split('.')[0], id)) + if (await validator()) { + this.isReadyInternal = true + } + } + + /** + * Send RPC request to the sdk object. + */ + request(data: unknown): Promise { + return createPromise((id) => sendEvent('web3BridgeExecute', [this.pathname, 'request'].join('.'), id, data)) + } + + /** + * Add event listener on the sdk object. + */ + on(event: string, callback: (...args: any) => void): () => void { + if (!this.events.has(event)) { + this.events.set(event, new Set()) + sendEvent('web3BridgeBindEvent', this.pathname, 'web3BridgeEmitEvent', event) + } + const set = this.events.get(event)! + set.add(callback) + return () => void set.delete(callback) + } + + /** + * Remove event listener from the sdk object. + */ + off(event: string, callback: (...args: any) => void): void { + this.events.get(event)?.delete(callback) + } + + /** + * Emit event and invoke registered listeners + */ + emit(event: string, data: unknown[]) { + for (const f of this.events.get(event) || []) { + try { + Reflect.apply(f, null, data) + } catch {} + } + } + + /** + * Access primitive property on the sdk object. + */ + getProperty(key: string): Promise { + return createPromise((id) => sendEvent('web3BridgePrimitiveAccess', this.pathname, id, key)) + } +} diff --git a/packages/injected-script/sdk/Coin98.ts b/packages/injected-script/sdk/Coin98.ts new file mode 100644 index 000000000000..58512549ea7a --- /dev/null +++ b/packages/injected-script/sdk/Coin98.ts @@ -0,0 +1,28 @@ +import type { RequestArguments } from 'web3-core' +import { InjectedProvider } from './Base' + +export enum Coin98ProviderType { + EVM = 1, + Solana = 2, + Near = 3, +} + +export class Coin98Provider extends InjectedProvider { + constructor(protected type: Coin98ProviderType) { + const pathnameMap: Record = { + [Coin98ProviderType.EVM]: 'coin98.provider', + [Coin98ProviderType.Near]: 'coin98.near', + [Coin98ProviderType.Solana]: 'coin98.sol', + } + + super(pathnameMap[type]) + } + + override async request(data: RequestArguments): Promise { + // coin98 cannot handle it correctly (test with coin98 v6.0.3) + if (data.method === 'eth_chainId') { + return this.getProperty('chainId') + } + return super.request(data) + } +} diff --git a/packages/injected-script/sdk/MathWallet.ts b/packages/injected-script/sdk/MathWallet.ts new file mode 100644 index 000000000000..b426c3db3b76 --- /dev/null +++ b/packages/injected-script/sdk/MathWallet.ts @@ -0,0 +1,11 @@ +import { InjectedProvider } from './Base' + +export class MathWalletProvider extends InjectedProvider { + constructor() { + super('ethereum') + } + + override async untilAvailable(): Promise { + await super.untilAvailable(() => super.getProperty('isMathWallet') as Promise) + } +} diff --git a/packages/injected-script/sdk/MetaMask.ts b/packages/injected-script/sdk/MetaMask.ts new file mode 100644 index 000000000000..10e4d5182991 --- /dev/null +++ b/packages/injected-script/sdk/MetaMask.ts @@ -0,0 +1,11 @@ +import { InjectedProvider } from './Base' + +export class MetaMaskProvider extends InjectedProvider { + constructor() { + super('ethereum') + } + + override async untilAvailable(): Promise { + await super.untilAvailable(() => super.getProperty('isMetaMask') as Promise) + } +} diff --git a/packages/injected-script/sdk/Phantom.ts b/packages/injected-script/sdk/Phantom.ts new file mode 100644 index 000000000000..0065b8d0c715 --- /dev/null +++ b/packages/injected-script/sdk/Phantom.ts @@ -0,0 +1,7 @@ +import { InjectedProvider } from './Base' + +export class PhantomProvider extends InjectedProvider { + constructor() { + super('phantom.solana') + } +} diff --git a/packages/injected-script/sdk/Solflare.ts b/packages/injected-script/sdk/Solflare.ts new file mode 100644 index 000000000000..11f969b779a1 --- /dev/null +++ b/packages/injected-script/sdk/Solflare.ts @@ -0,0 +1,15 @@ +import { InjectedProvider } from './Base' + +export class SolflareProvider extends InjectedProvider { + constructor() { + super('solflare') + } + + override async connect(options: unknown): Promise { + await super.connect(options) + const publicKey = (await super.getProperty('publicKey')) as string + return { + publicKey, + } + } +} diff --git a/packages/injected-script/sdk/WalletLink.ts b/packages/injected-script/sdk/WalletLink.ts new file mode 100644 index 000000000000..d0003022cdd8 --- /dev/null +++ b/packages/injected-script/sdk/WalletLink.ts @@ -0,0 +1,12 @@ +import { InjectedProvider } from './Base' +import { createPromise, sendEvent } from './utils' + +export class WalletLinkProvider extends InjectedProvider { + constructor() { + super('walletLinkExtension') + } + + override connect(options: unknown): Promise { + return createPromise((id) => sendEvent('web3BridgeExecute', [this.pathname, 'enable'].join('.'), id, options)) + } +} diff --git a/packages/injected-script/sdk/bridgedCoin98.ts b/packages/injected-script/sdk/bridgedCoin98.ts deleted file mode 100644 index f39a1f9843b5..000000000000 --- a/packages/injected-script/sdk/bridgedCoin98.ts +++ /dev/null @@ -1,61 +0,0 @@ -import type { RequestArguments } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' -import type { EthereumProvider } from '../shared' -import { createPromise, sendEvent } from './utils' - -function request(data: RequestArguments) { - return createPromise((id) => sendEvent('coin98BridgeSendRequest', id, data)) -} - -function send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) { - createPromise((id) => - sendEvent('coin98BridgeSendRequest', id, { - method: payload.method, - params: payload.params, - }), - ).then( - (value) => { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: value, - }) - }, - (error) => { - if (error instanceof Error) callback(error) - }, - ) -} - -/** Interact with the current ethereum provider */ -export const bridgedCoin98Provider: EthereumProvider = { - request, - send, - sendAsync: send, - on(event, callback) { - if (!bridgedCoin98.has(event)) { - bridgedCoin98.set(event, new Set()) - sendEvent('coin98BridgeRequestListen', event) - } - const map = bridgedCoin98.get(event)! - map.add(callback) - return () => void map.delete(callback) - }, - getProperty(key) { - return createPromise((id) => sendEvent('coin98BridgePrimitiveAccess', id, key)) - }, - untilAvailable() { - return createPromise((id) => sendEvent('untilCoin98BridgeOnline', id)) - }, -} - -const bridgedCoin98 = new Map>() -/** @internal */ -export function onCoin98Event(event: string, data: unknown[]) { - for (const f of bridgedCoin98.get(event) || []) { - try { - Reflect.apply(f, null, data) - } catch {} - } - return -} diff --git a/packages/injected-script/sdk/bridgedEthereum.ts b/packages/injected-script/sdk/bridgedEthereum.ts deleted file mode 100644 index 27354de35bce..000000000000 --- a/packages/injected-script/sdk/bridgedEthereum.ts +++ /dev/null @@ -1,61 +0,0 @@ -import type { RequestArguments } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' -import type { EthereumProvider } from '../shared' -import { createPromise, sendEvent } from './utils' - -function request(data: RequestArguments) { - return createPromise((id) => sendEvent('ethBridgeSendRequest', id, data)) -} - -function send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) { - createPromise((id) => - sendEvent('ethBridgeSendRequest', id, { - method: payload.method, - params: payload.params, - }), - ).then( - (value) => { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: value, - }) - }, - (error) => { - if (error instanceof Error) callback(error) - }, - ) -} - -/** Interact with the current ethereum provider */ -export const bridgedEthereumProvider: EthereumProvider = { - request, - send, - sendAsync: send, - on(event, callback) { - if (!bridgedEthereum.has(event)) { - bridgedEthereum.set(event, new Set()) - sendEvent('ethBridgeRequestListen', event) - } - const map = bridgedEthereum.get(event)! - map.add(callback) - return () => void map.delete(callback) - }, - getProperty(key) { - return createPromise((id) => sendEvent('ethBridgePrimitiveAccess', id, key)) - }, - untilAvailable() { - return createPromise((id) => sendEvent('untilEthBridgeOnline', id)) - }, -} - -const bridgedEthereum = new Map>() -/** @internal */ -export function onEthEvent(event: string, data: unknown[]) { - for (const f of bridgedEthereum.get(event) || []) { - try { - Reflect.apply(f, null, data) - } catch {} - } - return -} diff --git a/packages/injected-script/sdk/bridgedSolana.ts b/packages/injected-script/sdk/bridgedSolana.ts deleted file mode 100644 index bfa57053a617..000000000000 --- a/packages/injected-script/sdk/bridgedSolana.ts +++ /dev/null @@ -1,97 +0,0 @@ -import type { RequestArguments } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' -import { createPromise, sendEvent } from './utils' - -function request(data: RequestArguments) { - return createPromise((id) => sendEvent('solanaBridgeSendRequest', id, data)) -} - -function send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void) { - createPromise((id) => - sendEvent('solanaBridgeSendRequest', id, { - method: payload.method, - params: payload.params, - }), - ).then( - (value) => { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: value, - }) - }, - (error) => { - if (error instanceof Error) callback(error) - }, - ) -} - -let isConnected = false -/** Interact with the current solana provider */ -export const bridgedSolanaProvider: BridgedSolanaProvider = { - connect(opts) { - return createPromise((id) => sendEvent('solanaBridgeExecute', 'solana.connect', id, opts)) - }, - request, - send, - sendAsync: send, - on(event, callback) { - if (!bridgedSolana.has(event)) { - bridgedSolana.set(event, new Set()) - sendEvent('solanaBridgeRequestListen', event) - } - const map = bridgedSolana.get(event)! - map.add(callback) - return () => void map.delete(callback) - }, - getProperty(key) { - return createPromise((id) => sendEvent('solanaBridgePrimitiveAccess', id, key)) - }, - isConnected, - untilAvailable() { - return createPromise((id) => sendEvent('untilSolanaBridgeOnline', id)) - }, -} - -async function watchConnectStatus() { - const connected = await bridgedSolanaProvider.getProperty('isConnected') - if (connected !== undefined) { - isConnected = connected - } - bridgedSolanaProvider.on('connected', () => { - isConnected = true - }) - bridgedSolanaProvider.on('disconnect', () => { - isConnected = false - }) -} -watchConnectStatus() - -export interface BridgedSolanaProvider { - // _bn: result of serialization - connect(opts?: { onlyIfTrusted: boolean }): Promise<{ publicKey: { _bn: string } }> - /** Wait for window.solana object appears. */ - untilAvailable(): Promise - /** Send JSON RPC to the solana provider. */ - request(data: RequestArguments): Promise - /** Send JSON RPC */ - send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void - /** Async send JSON RPC */ - sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void - /** Add event listener */ - on(event: string, callback: (...args: any) => void): () => void - /** Access primitive property on the window.solana object. */ - getProperty(key: 'isPhantom' | 'isConnected'): Promise - /** Call window.solana.isConnected */ - isConnected: boolean -} -const bridgedSolana = new Map>() -/** @internal */ -export function onSolanaEvent(event: string, data: unknown[]) { - for (const f of bridgedSolana.get(event) || []) { - try { - Reflect.apply(f, null, data) - } catch {} - } - return -} diff --git a/packages/injected-script/sdk/index.ts b/packages/injected-script/sdk/index.ts index 5c0b8e0d8afa..3a0555c8dd27 100644 --- a/packages/injected-script/sdk/index.ts +++ b/packages/injected-script/sdk/index.ts @@ -1,12 +1,21 @@ import { CustomEventId, decodeEvent } from '../shared' -import { onEthEvent } from './bridgedEthereum' -import { onCoin98Event } from './bridgedCoin98' -import { onSolanaEvent } from './bridgedSolana' +import { Coin98Provider, Coin98ProviderType } from './Coin98' +import { PhantomProvider } from './Phantom' +import { SolflareProvider } from './Solflare' +import { MetaMaskProvider } from './MetaMask' import { sendEvent, rejectPromise, resolvePromise } from './utils' +import { MathWalletProvider } from './MathWallet' +import { WalletLinkProvider } from './WalletLink' -export { bridgedEthereumProvider } from './bridgedEthereum' -export { bridgedCoin98Provider } from './bridgedCoin98' -export { bridgedSolanaProvider } from './bridgedSolana' +export type { EthereumProvider, InternalEvents } from '../shared' + +export const injectedCoin98EVMProvider = new Coin98Provider(Coin98ProviderType.EVM) +export const injectedCoin98SolanaProvider = new Coin98Provider(Coin98ProviderType.Solana) +export const injectedPhantomProvider = new PhantomProvider() +export const injectedSolflareProvider = new SolflareProvider() +export const injectedMetaMaskProvider = new MetaMaskProvider() +export const injectedMathWalletProvider = new MathWalletProvider() +export const injectedWalletLinkProvider = new WalletLinkProvider() export function pasteText(text: string) { sendEvent('paste', text) @@ -39,29 +48,29 @@ document.addEventListener(CustomEventId, (e) => { case 'rejectPromise': return rejectPromise(...r[1]) - case 'ethBridgeOnEvent': - return onEthEvent(...r[1]) - case 'coin98BridgeOnEvent': - return onCoin98Event(...r[1]) - case 'solanaBridgeOnEvent': - return onSolanaEvent(...r[1]) - case 'ethBridgeSendRequest': - case 'ethBridgePrimitiveAccess': - case 'ethBridgeRequestListen': - case 'coin98BridgeSendRequest': - case 'coin98BridgePrimitiveAccess': - case 'coin98BridgeRequestListen': - case 'solanaBridgeSendRequest': - case 'solanaBridgePrimitiveAccess': - case 'solanaBridgeRequestListen': - case 'solanaBridgeExecute': + case 'web3BridgeEmitEvent': + const [pathname, eventName, data] = r[1] + const provider = [ + injectedCoin98EVMProvider, + injectedCoin98SolanaProvider, + injectedPhantomProvider, + injectedMetaMaskProvider, + injectedMathWalletProvider, + injectedWalletLinkProvider, + ].find((x) => x.pathname === pathname) + + provider?.emit(eventName, data) + return + + case 'web3BridgeBindEvent': + case 'web3BridgeSendRequest': + case 'web3BridgeExecute': + case 'web3UntilBridgeOnline': + case 'web3BridgePrimitiveAccess': case 'input': case 'paste': case 'pasteImage': case 'instagramUpload': - case 'untilEthBridgeOnline': - case 'untilCoin98BridgeOnline': - case 'untilSolanaBridgeOnline': case 'hookInputUploadOnce': break default: diff --git a/packages/injected-script/sdk/tsconfig.json b/packages/injected-script/sdk/tsconfig.json index a7c4f0e0842b..4b3dd476cc66 100644 --- a/packages/injected-script/sdk/tsconfig.json +++ b/packages/injected-script/sdk/tsconfig.json @@ -5,6 +5,16 @@ "outDir": "../dist/sdk", "tsBuildInfoFile": "../dist/sdk.tsbuildinfo" }, - "files": ["./index.ts", "./bridgedEthereum.ts", "./bridgedCoin98.ts", "./bridgedSolana.ts", "utils.ts"], + "files": [ + "index.ts", + "Base.ts", + "Phantom.ts", + "Solflare.ts", + "Coin98.ts", + "MetaMask.ts", + "MathWallet.ts", + "WalletLink.ts", + "utils.ts" + ], "references": [{ "path": "../shared/" }] } diff --git a/packages/injected-script/shared/index.ts b/packages/injected-script/shared/index.ts index c42978c4288b..c69bb30fb17c 100644 --- a/packages/injected-script/shared/index.ts +++ b/packages/injected-script/shared/index.ts @@ -1,5 +1,4 @@ import type { RequestArguments } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' export const CustomEventId = 'c8a6c18e-f6a3-472a-adf3-5335deb80db6' export interface InternalEvents { @@ -19,45 +18,19 @@ export interface InternalEvents { */ hookInputUploadOnce: [format: string, fileName: string, file: number[], triggerOnActiveElementNow: boolean] - // #region Eth inpage provider bridge + // #region web3 bridge /** Request the bridge to listen on an event. */ - ethBridgeRequestListen: [eventName: string] + web3BridgeBindEvent: [path: string, responseEventName: keyof InternalEvents, eventName: string] /** When a event happened. */ - ethBridgeOnEvent: [eventName: string, data: unknown[]] + web3BridgeEmitEvent: [path: string, eventName: string, data: unknown[]] /** Send JSON RPC request. */ - ethBridgeSendRequest: [req_id: number, request: unknown] + web3BridgeSendRequest: [path: string, req_id: number, request: unknown] /** Access primitive property on the window.ethereum object. */ - ethBridgePrimitiveAccess: [req_id: number, property: string] + web3BridgePrimitiveAccess: [path: string, req_id: number, property: string] /** Wait until window.ethereum appears */ - untilEthBridgeOnline: [req_id: number] - // #endregion - - // #region Eth inpage provider bridge - /** Request the bridge to listen on an event. */ - coin98BridgeRequestListen: [eventName: string] - /** When a event happened. */ - coin98BridgeOnEvent: [eventName: string, data: unknown[]] - /** Send JSON RPC request. */ - coin98BridgeSendRequest: [req_id: number, request: unknown] - /** Access primitive property on the window.ethereum object. */ - coin98BridgePrimitiveAccess: [req_id: number, property: string] - /** Wait until window.ethereum appears */ - untilCoin98BridgeOnline: [req_id: number] - // #endregion - - // #region Solana inpage provider bridge + web3UntilBridgeOnline: [path: string, req_id: number] /** Request the bridge to call function. */ - solanaBridgeExecute: [path: string, req_id: number, opts?: { onlyIfTrusted: boolean }] - /** Request the bridge to listen on an event. */ - solanaBridgeRequestListen: [eventName: string] - /** When a event happened. */ - solanaBridgeOnEvent: [eventName: string, data: unknown[]] - /** Send JSON RPC request. */ - solanaBridgeSendRequest: [req_id: number, request: unknown] - /** Access primitive property on the window.solana object. */ - solanaBridgePrimitiveAccess: [req_id: number, property: string] - /** Wait until window.solana appears */ - untilSolanaBridgeOnline: [req_id: number] + web3BridgeExecute: [path: string, req_id: number, opts?: unknown] // #endregion /** A simple RPC. */ @@ -72,12 +45,10 @@ export interface EthereumProvider { untilAvailable(): Promise /** Send JSON RPC to the ethereum provider. */ request(data: RequestArguments): Promise - /** Send JSON RPC */ - send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void - /** Async send JSON RPC */ - sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void /** Add event listener */ on(event: string, callback: (...args: any) => void): () => void + /** Remove event listener */ + off(event: string, callback: (...args: any) => void): void /** Access primitive property on the ethereum object. */ getProperty(key: string): Promise } diff --git a/packages/mask/background/services/crypto/decryption.ts b/packages/mask/background/services/crypto/decryption.ts index 5f8fcca2131e..dc520dfaa1dc 100644 --- a/packages/mask/background/services/crypto/decryption.ts +++ b/packages/mask/background/services/crypto/decryption.ts @@ -101,7 +101,7 @@ async function* decryption(payload: string | Uint8Array, context: DecryptionCont } const id = new PostIVIdentifier( SocialNetworkEnumToProfileDomain(currentSocialNetwork), - encodeArrayBuffer(iv.buffer), + encodeArrayBuffer(new Uint8Array(iv.buffer)), ) // #endregion diff --git a/packages/mask/package.json b/packages/mask/package.json index b905e413fdd2..a8850fcb04b6 100644 --- a/packages/mask/package.json +++ b/packages/mask/package.json @@ -6,7 +6,6 @@ "@balancer-labs/sor": "^1.0.0", "@dimensiondev/holoflows-kit": "^0.9.0-20220520093249-0870919", "@dimensiondev/mask-wallet-core": "0.1.0-20211013082857-eb62e5f", - "@dimensiondev/metamask-extension-provider": "3.0.6-20210519045409-1835d4d", "@dimensiondev/secp256k1-webcrypto": "1.0.0-20220412114204-be816df", "@ethersproject/abi": "^5.4.0", "@ethersproject/address": "^5.0.4", @@ -26,6 +25,7 @@ "@masknet/plugin-debugger": "workspace:*", "@masknet/plugin-example": "workspace:*", "@masknet/plugin-file-service": "workspace:*", + "@masknet/plugin-evm": "workspace:*", "@masknet/plugin-flow": "workspace:*", "@masknet/plugin-go-plus-security": "workspace:*", "@masknet/plugin-infra": "workspace:*", @@ -61,13 +61,11 @@ "@types/react-virtualized-auto-sizer": "^1.0.1", "@types/react-window": "^1.8.4", "@types/remarkable": "^2.0.3", - "@types/socket.io-client": "^1.4.36", "@types/use-subscription": "^1.0.0", "@types/uuid": "^8.3.4", "@uniswap/sdk-core": "^3.0.1", "@uniswap/v2-sdk": "3.0.0-alpha.2", "@uniswap/v3-sdk": "^3.3.2", - "@walletconnect/client": "^1.2.2", "anchorme": "^2.1.2", "assert": "^2.0.0", "async-call-rpc": "^6.0.2", @@ -82,7 +80,6 @@ "date-fns": "^2.28.0", "elliptic": "^6.5.3", "ethereumjs-util": "^7.1.0", - "ethjs-ens": "^2.0.1", "event-iterator": "^2.0.0", "fuse.js": "^6.6.2", "graphql": "^15.5.1", diff --git a/packages/mask/shared-ui/TypedMessageRender/Components/Text.tsx b/packages/mask/shared-ui/TypedMessageRender/Components/Text.tsx index 19437b576d23..da45c6f35cbd 100644 --- a/packages/mask/shared-ui/TypedMessageRender/Components/Text.tsx +++ b/packages/mask/shared-ui/TypedMessageRender/Components/Text.tsx @@ -2,6 +2,8 @@ import { memo, PropsWithChildren, useCallback } from 'react' import { Typography, Link as MaterialLink } from '@mui/material' import type { RenderFragmentsContextType } from '@masknet/typed-message/dom' import { useActivatedPluginsSNSAdaptor } from '@masknet/plugin-infra/content-script' +import { useChainId } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' export const Container = memo(function Container(props: PropsWithChildren<{}>) { return ( @@ -20,6 +22,7 @@ export const Link = memo(function Anchor(props: RenderFragmentsContextType.LinkP }) export function useTagEnhancer(kind: 'hash' | 'cash', content: string) { + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const plugin = useActivatedPluginsSNSAdaptor(false) .filter((x) => x.enhanceTag) .at(0) @@ -32,7 +35,7 @@ export function useTagEnhancer(kind: 'hash' | 'cash', content: string) { ) const onMouseEnter: React.EventHandler> = useCallback( (event) => { - const cancel = plugin?.enhanceTag?.onHover?.(kind, content, event) + const cancel = plugin?.enhanceTag?.onHover?.(kind, content, event, chainId) event.currentTarget.addEventListener('mouseleave', () => cancel?.(), { once: true }) }, [plugin], diff --git a/packages/mask/shared-ui/locales/en-US.json b/packages/mask/shared-ui/locales/en-US.json index 5852e1f06d72..5a3beacdb0c7 100644 --- a/packages/mask/shared-ui/locales/en-US.json +++ b/packages/mask/shared-ui/locales/en-US.json @@ -292,7 +292,7 @@ "plugin_wallet_connected_with": "Connected with", "plugin_wallet_connecting_with": "Connecting with", "plugin_wallet_metamask_error_already_request": "You've opened the popup, please confirm.", - "plugin_wallet_connect_tip": "Please make sure that your {{providerName}} wallet is provided by the offical {{providerShortenLink}}.", + "plugin_wallet_connect_tip": "Please make sure that your {{providerName}} wallet is provided by the official {{providerShortenLink}}.", "plugin_wallet_select_a_nft_contract": "Select an NFT Contract", "plugin_wallet_select_a_nft_owner": "Select an NFT Contract Owner", "plugin_wallet_select_a_nft_operator": "Select an NFT Contract Operator", @@ -346,6 +346,54 @@ "plugin_nft_avatar_recommend_feature_description": "Set your NFT as profile picture with exclusive aura", "application_hint": "Socialize and show off your NFTs. People can bid,buy, view your valuable NFTs without leaving Twitter.", "plugin_red_packet_create": "Create a Lucky Drop", + "plugin_red_packet_claimed": "Claimed", + "plugin_red_packet_erc20_tab_title": "Token", + "plugin_red_packet_erc721_tab_title": "Collectibles", + "plugin_red_packet_name": "Lucky Drop", + "plugin_red_packet_recommend_feature_description": "Astonish your friends with a surprise gift", + "plugin_red_packet_description": "Gift crypto or NFTs to any users, first come, first served.", + "plugin_red_packet_erc721_insufficient_balance": "Insufficient Balance", + "plugin_red_packet_details": "Lucky Drop Details", + "plugin_red_packet_split_mode": "Split Mode", + "plugin_red_packet_average": "Average", + "plugin_red_packet_random": "Random", + "plugin_red_packet_shares": "Shares", + "plugin_red_packet_best_wishes": "Best Wishes!", + "plugin_red_packet_create_new": "New", + "plugin_red_packet_claim": "Claim", + "plugin_red_packet_claiming": "Claiming...", + "plugin_red_packet_refund": "Refund", + "plugin_red_packet_empty": "Empty", + "plugin_red_packet_data_broken": "The Lucky Drop can’t be sent due to data damage. Please withdraw the assets after {{duration}}.", + "plugin_red_packet_refunding": "Refunding", + "plugin_red_packet_select_existing": "Past", + "plugin_red_packet_share_unclaimed_message_official_account": "Hi friends, I just found a lucky drop sent by @{{sender}} on {{network}} network. Follow @{{account}} (mask.io) to claim lucky drops.\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_share_unclaimed_message_not_twitter": "Hi friends, I just found a lucky drop sent by @{{sender}} on {{network}} network. \n{{payload}}", + "plugin_red_packet_share_message_official_account": "I just claimed a lucky drop from @{{sender}} on {{network}} network. Follow @{{account}} (mask.io) to claim lucky drops.\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_share_message_not_twitter": "I just claimed a lucky drop from @{{sender}} on {{network}} network. \n{{payload}}", + "plugin_red_packet_nft_share_foreshow_message": "@{{sender}} is sending an NFT lucky drop on {{network}} network. Follow @{{account}} (mask.io) to claim NFT lucky drops.\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_nft_share_foreshow_message_not_twitter": "@{{sender}} is sending an NFT lucky drop on {{network}} network. \n{{payload}}", + "plugin_red_packet_nft_share_claimed_message": "I just claimed an NFT lucky drop from @{{sender}} on {{network}} network. Follow @{{account}} (mask.io) to claim NFT lucky drops.\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_nft_share_claimed_message_not_twitter": "I just claimed an NFT lucky drop from @{{sender}} on {{network}} network. \n{{payload}}", + "plugin_red_packet_nft_tip": "This is an NFT lucky drop.", + "plugin_red_packet_nft_no_history": "You haven’t created any NFT lucky drop yet. Try to create and share lucky with your friends.", + "plugin_red_packet_attached_message": "Attached Message", + "plugin_red_packet_from": "From: @{{name}}", + "plugin_red_packet_description_claimed": "You got {{amount}} {{symbol}}", + "plugin_red_packet_description_expired": "The Lucky Drop is expired.", + "plugin_red_packet_description_refunded": "The Lucky Drop has been refunded.", + "plugin_red_packet_description_refund": "You could refund {{balance}} {{symbol}}.", + "plugin_red_packet_description_empty": "The Lucky Drop is empty.", + "plugin_red_packet_description_broken": "The Lucky Drop is broken.", + "plugin_red_packet_description_failover": "{{shares}} shares / {{total}} {{symbol}}", + "plugin_red_packet_amount_per_share": "Amount per Share", + "plugin_red_packet_send_symbol": "Send {{amount}} {{symbol}}", + "plugin_red_packet_amount_total": "Amount Total", + "plugin_red_packet_next": "Next", + "plugin_red_packet_back": "Back", + "plugin_red_packet_hint": "You can withdraw the remaining balance 24 hours after the Lucky Drop is sent.", + "plugin_red_packet_token": "Token", + "plugin_red_packet_message_label": "Title", "plugin_red_packet_create_with_token": "Create a Lucky Drop with {{amount}} {{symbol}}", "plugin_nft_red_packet_create": "Create an NFT Lucky Drop", "plugin_red_packet_nft_account_name": "Wallet account", @@ -641,7 +689,7 @@ "plugin_collectible_invalid_reserve_price": "Invalid reserve price", "plugin_collectible_place_a_bid": "Place a Bid", "plugin_collectible_make_an_offer": "Make an Offer", - "plugin_collectible_approved_by_open_sea": "By checking this box, I acknowledge that this item has not been reviewed or approved by OpenSea.", + "plugin_collectible_approved_by_opensea": "By checking this box, I acknowledge that this item has not been reviewed or approved by OpenSea.", "plugin_collectible_legal_text": "By checking this box, I agree to OpenSea's Terms of Service.", "plugin_collectibles_name": "Collectibles", "plugin_collectibles_description": "Display specific information of collectibles in OpenSea and Rarible, make an offer directly on social media.", diff --git a/packages/mask/shared-ui/locales/ja-JP.json b/packages/mask/shared-ui/locales/ja-JP.json index 9cd3090de974..a17925a94eff 100644 --- a/packages/mask/shared-ui/locales/ja-JP.json +++ b/packages/mask/shared-ui/locales/ja-JP.json @@ -103,6 +103,26 @@ "plugin_wallet_on_connect_in_firefox": "接続する", "plugin_wallet_return_mobile_wallet_options": "モバイルウォレットのオプションに戻る", "plugin_wallet_view_qr_code": "QR コードを表示する", + "plugin_red_packet_display_name": "プラグイン: 投げ銭", + "plugin_red_packet_split_mode": "分割モード", + "plugin_red_packet_average": "平均", + "plugin_red_packet_random": "ランダム", + "plugin_red_packet_shares": "株数", + "plugin_red_packet_best_wishes": "幸運を祈ります!", + "plugin_red_packet_create_new": "新しい投げ銭を作成", + "plugin_red_packet_claim": "受け取る", + "plugin_red_packet_refund": "無効", + "plugin_red_packet_select_existing": "既存の投げ銭を選択", + "plugin_red_packet_attached_message": "メッセージを追加", + "plugin_red_packet_from": "送信者:{{name}}", + "plugin_red_packet_description_expired": "期限切れです", + "plugin_red_packet_description_refunded": "無効です", + "plugin_red_packet_description_refund": "{{balance}}{{symbol}}を受け取れます", + "plugin_red_packet_description_empty": "期限切れです", + "plugin_red_packet_description_broken": "破損しています", + "plugin_red_packet_description_failover": "{{amount}} {{symbol}} / {{shares}} 株", + "plugin_red_packet_amount_per_share": "1株当たりの金額", + "plugin_red_packet_send_symbol": "{{symbol}} を送る", "plugin_red_packet_create_with_token": "{{symbol}} で投げ銭を作成する", "plugin_gitcoin_select_a_token": "トークンを選択する", "plugin_gitcoin_insufficient_balance": "{{symbol}} の残高が足りません", diff --git a/packages/mask/shared-ui/locales/ko-KR.json b/packages/mask/shared-ui/locales/ko-KR.json index 6761f7a7923b..cbc72eac9dfa 100644 --- a/packages/mask/shared-ui/locales/ko-KR.json +++ b/packages/mask/shared-ui/locales/ko-KR.json @@ -213,6 +213,48 @@ "plugin_wallet_connect_wallet": "월렛 연결", "plugin_wallet_name_placeholder": "1-12 자 입력하세요", "plugin_wallet_cancel_sign": "서명이 실패되었습니다.", + "plugin_red_packet_display_name": "플러그인: 빨간 백", + "plugin_red_packet_erc20_tab_title": "토큰", + "plugin_red_packet_erc721_tab_title": "수집품", + "plugin_red_packet_erc721_insufficient_balance": "잔액 부족", + "plugin_red_packet_details": "행운 드랍 디테일", + "plugin_red_packet_split_mode": "분할 모드", + "plugin_red_packet_average": "평균", + "plugin_red_packet_random": "렌덤", + "plugin_red_packet_shares": "공유", + "plugin_red_packet_best_wishes": "행운을 빌어요!", + "plugin_red_packet_create_new": "새로운 것 만들기", + "plugin_red_packet_claim": "수령", + "plugin_red_packet_claiming": "수령 중...", + "plugin_red_packet_refund": "반환", + "plugin_red_packet_empty": "비어 있음", + "plugin_red_packet_data_broken": "데이터 손상으로 인해 레드 패킷을 보낼 수 없습니다. {{duration}} 후 자산을 인출할 수 있습니다.", + "plugin_red_packet_refunding": "환급 중", + "plugin_red_packet_select_existing": "기존 빨간 백 선택", + "plugin_red_packet_share_message_official_account": "{{network}} 네트워크에서 @{{sender}}의 레트 패킷을 받았어요. @{{account}} (mask.io) 팔로우하고 레드 패킷을 받으세요.\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_share_message_not_twitter": "{{network}} 에서 @{{sender}} 의 레드 패킷을 클레임했습니다.\n{{payload}}", + "plugin_red_packet_nft_share_foreshow_message": "@{{network}} 네트워크에서 @{{sender}} 레트 패킷을 보내고 있습니다. @{{account}} (mask.io) 팔로우하고 NFT 레드 패킷을 받으세요.\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_nft_share_foreshow_message_not_twitter": "@{{network}} 네트워크에서 @{{sender}} NFT 레트 패킷을 보내고 있습니다. \n{{payload}}", + "plugin_red_packet_nft_share_claimed_message": "{{network}} 네트워크에서 @{{sender}}의 NFT 레트 패킷을 받았어요. @{{account}} (mask.io) 팔로우하고 NFT 레드 패킷을 받으세요.\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_nft_share_claimed_message_not_twitter": "{{network}} 에서 @{{sender}} 의 NFT 레드 패킷을 클레임했습니다.\n{{payload}}", + "plugin_red_packet_nft_tip": "이것은 NFT 레드 패킷입니다.", + "plugin_red_packet_attached_message": "첨부 메시지", + "plugin_red_packet_from": "보낸사람: {{name}}", + "plugin_red_packet_description_claimed": "이미 수령하였습니다.", + "plugin_red_packet_description_expired": "이 빨간 백 이미 만료되었습니다.", + "plugin_red_packet_description_refunded": "이 빨간 백 이미 반환되었습니다.", + "plugin_red_packet_description_refund": "{{balance}} {{symbol} 반환 가능합니다.", + "plugin_red_packet_description_empty": "빈 빨간 백입니다.", + "plugin_red_packet_description_broken": "파손된 빨간 백입니다.", + "plugin_red_packet_description_failover": "{{name}} / {{shares}}에서 / {{total}} {{symbol}} 공유합니다.", + "plugin_red_packet_amount_per_share": "공유 총액", + "plugin_red_packet_send_symbol": "{{symbol}} 보내기", + "plugin_red_packet_amount_total": "총액", + "plugin_red_packet_next": "다음", + "plugin_red_packet_back": "뒤로", + "plugin_red_packet_hint": "레드 패킷이 공유된 후 24시간 후에 나머지 잔액을 인출할 수 있습니다.", + "plugin_red_packet_token": "토큰", + "plugin_red_packet_message_label": "제목", "plugin_red_packet_create_with_token": "{{symbol}} 으로 빨간 백 만드는 중", "plugin_red_packet_nft_account_name": "지갑 계정", "plugin_gitcoin_select_a_token": "토큰 선택", diff --git a/packages/mask/shared-ui/locales/qya-AA.json b/packages/mask/shared-ui/locales/qya-AA.json index d1e180adb87d..5cccbfe12ae0 100644 --- a/packages/mask/shared-ui/locales/qya-AA.json +++ b/packages/mask/shared-ui/locales/qya-AA.json @@ -344,8 +344,57 @@ "plugin_wallet_name_placeholder": "crwdns4705:0crwdne4705:0", "plugin_wallet_cancel_sign": "crwdns4709:0crwdne4709:0", "plugin_nft_avatar_recommend_feature_description": "crwdns16626:0crwdne16626:0", - "application_hint": "crwdns16628:0crwdne16628:0", "plugin_red_packet_create": "crwdns11873:0crwdne11873:0", + "plugin_red_packet_display_name": "crwdns4711:0crwdne4711:0", + "application_hint": "crwdns16628:0crwdne16628:0", + "plugin_red_packet_claimed": "crwdns10205:0crwdne10205:0", + "plugin_red_packet_erc20_tab_title": "crwdns8143:0crwdne8143:0", + "plugin_red_packet_erc721_tab_title": "crwdns8145:0crwdne8145:0", + "plugin_red_packet_name": "crwdns16234:0crwdne16234:0", + "plugin_red_packet_recommend_feature_description": "crwdns16544:0crwdne16544:0", + "plugin_red_packet_description": "crwdns16236:0crwdne16236:0", + "plugin_red_packet_erc721_insufficient_balance": "crwdns8147:0crwdne8147:0", + "plugin_red_packet_details": "crwdns9071:0crwdne9071:0", + "plugin_red_packet_split_mode": "crwdns4713:0crwdne4713:0", + "plugin_red_packet_average": "crwdns4715:0crwdne4715:0", + "plugin_red_packet_random": "crwdns4717:0crwdne4717:0", + "plugin_red_packet_shares": "crwdns4719:0crwdne4719:0", + "plugin_red_packet_best_wishes": "crwdns4721:0crwdne4721:0", + "plugin_red_packet_create_new": "crwdns4723:0crwdne4723:0", + "plugin_red_packet_claim": "crwdns4725:0crwdne4725:0", + "plugin_red_packet_claiming": "crwdns4727:0crwdne4727:0", + "plugin_red_packet_refund": "crwdns4729:0crwdne4729:0", + "plugin_red_packet_empty": "crwdns4731:0crwdne4731:0", + "plugin_red_packet_data_broken": "crwdns7999:0{{duration}}crwdne7999:0", + "plugin_red_packet_refunding": "crwdns4733:0crwdne4733:0", + "plugin_red_packet_select_existing": "crwdns4735:0crwdne4735:0", + "plugin_red_packet_share_unclaimed_message_official_account": "crwdns14614:0{{sender}}crwdnd14614:0{{network}}crwdnd14614:0{{account}}crwdnd14614:0{{payload}}crwdne14614:0", + "plugin_red_packet_share_unclaimed_message_not_twitter": "crwdns14616:0{{sender}}crwdnd14616:0{{network}}crwdnd14616:0{{payload}}crwdne14616:0", + "plugin_red_packet_share_message_official_account": "crwdns9175:0{{sender}}crwdnd9175:0{{network}}crwdnd9175:0{{account}}crwdnd9175:0{{payload}}crwdne9175:0", + "plugin_red_packet_share_message_not_twitter": "crwdns9177:0{{sender}}crwdnd9177:0{{network}}crwdnd9177:0{{payload}}crwdne9177:0", + "plugin_red_packet_nft_share_foreshow_message": "crwdns8151:0{{sender}}crwdnd8151:0{{network}}crwdnd8151:0{{account}}crwdnd8151:0{{payload}}crwdne8151:0", + "plugin_red_packet_nft_share_foreshow_message_not_twitter": "crwdns9011:0{{sender}}crwdnd9011:0{{network}}crwdnd9011:0{{payload}}crwdne9011:0", + "plugin_red_packet_nft_share_claimed_message": "crwdns8153:0{{sender}}crwdnd8153:0{{network}}crwdnd8153:0{{account}}crwdnd8153:0{{payload}}crwdne8153:0", + "plugin_red_packet_nft_share_claimed_message_not_twitter": "crwdns9013:0{{sender}}crwdnd9013:0{{network}}crwdnd9013:0{{payload}}crwdne9013:0", + "plugin_red_packet_nft_tip": "crwdns8155:0crwdne8155:0", + "plugin_red_packet_nft_no_history": "crwdns12991:0crwdne12991:0", + "plugin_red_packet_attached_message": "crwdns4739:0crwdne4739:0", + "plugin_red_packet_from": "crwdns4741:0{{name}}crwdne4741:0", + "plugin_red_packet_description_claimed": "crwdns4743:0{{amount}}crwdnd4743:0{{symbol}}crwdne4743:0", + "plugin_red_packet_description_expired": "crwdns4745:0crwdne4745:0", + "plugin_red_packet_description_refunded": "crwdns4747:0crwdne4747:0", + "plugin_red_packet_description_refund": "crwdns4749:0{{balance}}crwdnd4749:0{{symbol}}crwdne4749:0", + "plugin_red_packet_description_empty": "crwdns4751:0crwdne4751:0", + "plugin_red_packet_description_broken": "crwdns4753:0crwdne4753:0", + "plugin_red_packet_description_failover": "crwdns4755:0{{shares}}crwdnd4755:0{{total}}crwdnd4755:0{{symbol}}crwdne4755:0", + "plugin_red_packet_amount_per_share": "crwdns4761:0crwdne4761:0", + "plugin_red_packet_send_symbol": "crwdns4763:0{{amount}}crwdnd4763:0{{symbol}}crwdne4763:0", + "plugin_red_packet_amount_total": "crwdns4765:0crwdne4765:0", + "plugin_red_packet_next": "crwdns4767:0crwdne4767:0", + "plugin_red_packet_back": "crwdns4769:0crwdne4769:0", + "plugin_red_packet_hint": "crwdns4771:0crwdne4771:0", + "plugin_red_packet_token": "crwdns4773:0crwdne4773:0", + "plugin_red_packet_message_label": "crwdns8157:0crwdne8157:0", "plugin_red_packet_create_with_token": "crwdns4775:0{{amount}}crwdnd4775:0{{symbol}}crwdne4775:0", "plugin_nft_red_packet_create": "crwdns11875:0crwdne11875:0", "plugin_red_packet_nft_account_name": "crwdns8159:0crwdne8159:0", diff --git a/packages/mask/shared-ui/locales/zh-CN.json b/packages/mask/shared-ui/locales/zh-CN.json index a6ec9363bc23..00a4ece5ee23 100644 --- a/packages/mask/shared-ui/locales/zh-CN.json +++ b/packages/mask/shared-ui/locales/zh-CN.json @@ -296,6 +296,52 @@ "plugin_wallet_name_placeholder": "输入1-12 个字符", "plugin_wallet_cancel_sign": "签名已取消。", "plugin_red_packet_create": "创建一个红包", + "plugin_red_packet_display_name": "插件:红包", + "plugin_red_packet_claimed": "已认领", + "plugin_red_packet_erc20_tab_title": "代币", + "plugin_red_packet_erc721_tab_title": "收藏品", + "plugin_red_packet_erc721_insufficient_balance": "余额不足", + "plugin_red_packet_details": "红包详情", + "plugin_red_packet_split_mode": "分享模式", + "plugin_red_packet_average": "平均", + "plugin_red_packet_random": "随机", + "plugin_red_packet_shares": "份额", + "plugin_red_packet_best_wishes": "祝好运!", + "plugin_red_packet_create_new": "新建", + "plugin_red_packet_claim": "认领", + "plugin_red_packet_claiming": "认领中...", + "plugin_red_packet_refund": "退款", + "plugin_red_packet_empty": "空的", + "plugin_red_packet_data_broken": "由于数据损坏,此红包无法发送。请在 {{duration}} 之后申请退款。", + "plugin_red_packet_refunding": "退款中", + "plugin_red_packet_select_existing": "历史红包", + "plugin_red_packet_share_unclaimed_message_official_account": "朋友们,我刚刚发现 @{{sender}} 在 {{network}} 网络发送了一个红包。 关注 @{{account}} (mask.io) 以获取红包。\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_share_unclaimed_message_not_twitter": "朋友们,我刚刚发现 @{{sender}} 在 {{network}} 网络发送了一个红包。\n{{payload}}", + "plugin_red_packet_share_message_official_account": "我刚从@{{sender}} 在 {{network}} 网络上认领了一个红包。关注@{{account}} (mask.io) 来获取红包。\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_share_message_not_twitter": "我刚从@{{sender}} 在 {{network}} 网络上认领了一个红包。\n{{payload}}", + "plugin_red_packet_nft_share_foreshow_message": "@{{sender}} 正在 {{network}} 网络上发送一个 NFT 红包。关注@{{account}} (mask.io) 以获取NFT 红包。\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_nft_share_foreshow_message_not_twitter": "@{{sender}} 正在 {{network}} 网络上发送一个 NFT 红包。 \n{{payload}}", + "plugin_red_packet_nft_share_claimed_message": "我刚从@{{sender}} 在 {{network}} 网络上认领了一个 NFT 红包。关注@{{account}} (mask.io) 来获取红包。\n#mask_io #LuckyDrop\n{{payload}}", + "plugin_red_packet_nft_share_claimed_message_not_twitter": "我刚从@{{sender}} 在 {{network}} 网络上认领了一个 NFT 红包。\n{{payload}}", + "plugin_red_packet_nft_tip": "这是一个 NFT 红包。", + "plugin_red_packet_nft_no_history": "您还没有创建任何NFT红包。尝试创建红包并与您的朋友分享。", + "plugin_red_packet_attached_message": "附加信息", + "plugin_red_packet_from": "来自:@{{name}}", + "plugin_red_packet_description_claimed": "你获得了 {{amount}} {{symbol}}", + "plugin_red_packet_description_expired": "此红包已过期。", + "plugin_red_packet_description_refunded": "此红包已退款。", + "plugin_red_packet_description_refund": "您可以退回 {{balance}} {{symbol}}。", + "plugin_red_packet_description_empty": "此红包是空的。", + "plugin_red_packet_description_broken": "此红包已被损坏。", + "plugin_red_packet_description_failover": "{{shares}} 份额 / {{total}} {{symbol}} 总金额", + "plugin_red_packet_amount_per_share": "单个份额", + "plugin_red_packet_send_symbol": "发送 {{amount}} {{symbol}}", + "plugin_red_packet_amount_total": "总额", + "plugin_red_packet_next": "下一步", + "plugin_red_packet_back": "返回", + "plugin_red_packet_hint": "你可以在红包发送的24小时后提取红包余额。", + "plugin_red_packet_token": "代币", + "plugin_red_packet_message_label": "标题", "plugin_red_packet_create_with_token": "使用 {{symbol}} 创建红包", "plugin_nft_red_packet_create": "创建一个NFT红包", "plugin_red_packet_nft_account_name": "钱包账户", diff --git a/packages/mask/shared-ui/locales/zh-TW.json b/packages/mask/shared-ui/locales/zh-TW.json index 1a335c4501db..c6583d80d3f6 100644 --- a/packages/mask/shared-ui/locales/zh-TW.json +++ b/packages/mask/shared-ui/locales/zh-TW.json @@ -197,6 +197,41 @@ "plugin_wallet_switch_network_under_going": "切換至 {{network}} 中", "plugin_wallet_not_available_on": "{{network}} 不可用", "plugin_wallet_connect_wallet": "連接錢包", + "plugin_red_packet_display_name": "插件:紅包", + "plugin_red_packet_claimed": "已認領", + "plugin_red_packet_erc20_tab_title": "代幣", + "plugin_red_packet_erc721_tab_title": "收藏品", + "plugin_red_packet_erc721_insufficient_balance": "餘額不足", + "plugin_red_packet_details": "紅包詳情", + "plugin_red_packet_split_mode": "分割模式", + "plugin_red_packet_average": "平均", + "plugin_red_packet_random": "隨機", + "plugin_red_packet_shares": "分享數", + "plugin_red_packet_best_wishes": "祝好運!", + "plugin_red_packet_create_new": "建立新的", + "plugin_red_packet_claim": "認領", + "plugin_red_packet_claiming": "認領中...", + "plugin_red_packet_refund": "退款", + "plugin_red_packet_empty": "空的", + "plugin_red_packet_refunding": "退款中", + "plugin_red_packet_select_existing": "選擇已存在的", + "plugin_red_packet_nft_tip": "這是一個NFT紅包", + "plugin_red_packet_attached_message": "附加的訊息", + "plugin_red_packet_from": "寄送人:{{name}}", + "plugin_red_packet_description_claimed": "你已經認領了 {{amount}} {{symbol}}。", + "plugin_red_packet_description_expired": "這個紅包已過期。", + "plugin_red_packet_description_refunded": "這個紅包已經被退款了。", + "plugin_red_packet_description_refund": "你可以退款 {{balance}} {{symbol}}。", + "plugin_red_packet_description_empty": "這個紅包是空的。", + "plugin_red_packet_description_broken": "這個紅包壞了", + "plugin_red_packet_description_failover": "寄送人 {{name}} / {{shares}} 分享數 / {{total}} {{symbol}}", + "plugin_red_packet_amount_per_share": "每次分享總額", + "plugin_red_packet_send_symbol": "送出 {{symbol}}", + "plugin_red_packet_amount_total": "總額", + "plugin_red_packet_next": "繼續", + "plugin_red_packet_back": "返回", + "plugin_red_packet_token": "代幣", + "plugin_red_packet_message_label": "標題", "plugin_red_packet_create_with_token": "使用 {{symbol}} 建立紅包", "plugin_gitcoin_select_a_token": "選擇一個代幣", "plugin_gitcoin_insufficient_balance": "{{symbol}} 餘額不足", diff --git a/packages/mask/shared/flags.ts b/packages/mask/shared/flags.ts index a92a11370e38..e419af0b7097 100644 --- a/packages/mask/shared/flags.ts +++ b/packages/mask/shared/flags.ts @@ -24,11 +24,8 @@ export const Flags = { toolbox_enabled: webOnly, /** Prohibit the use of test networks in production */ wallet_allow_testnet: betaOrInsiderOnly || process.env.NODE_ENV !== 'production', - LBP_whitelist_enabled: process.env.NODE_ENV === 'production', // #endregion - EIP1559_enabled: true, - bsc_enabled: true, polygon_enabled: true, arbitrum_enabled: true, diff --git a/packages/mask/src/UIRoot.tsx b/packages/mask/src/UIRoot.tsx index 9d7c5eefe82b..f4efbceb2acc 100644 --- a/packages/mask/src/UIRoot.tsx +++ b/packages/mask/src/UIRoot.tsx @@ -1,16 +1,13 @@ import { Suspense } from 'react' -import { Web3Provider } from '@masknet/web3-shared-evm' import { StyledEngineProvider, Theme } from '@mui/material' -import { NetworkPluginID, PluginsWeb3ContextProvider, useAllPluginsWeb3State } from '@masknet/plugin-infra/web3' +import { PluginsWeb3ContextProvider, useAllPluginsWeb3State } from '@masknet/plugin-infra/web3' import { I18NextProviderHMR, SharedContextProvider } from '@masknet/shared' import { ErrorBoundary, ErrorBoundaryBuildInfoContext, useValueRef } from '@masknet/shared-base-ui' import { i18NextInstance } from '@masknet/shared-base' -import { Web3Context } from './web3/context' import { buildInfoMarkdown } from './utils/BuildInfoMarkdown' import { activatedSocialNetworkUI } from './social-network' import { isFacebook } from './social-network-adaptor/facebook.com/base' import { pluginIDSettings } from './settings/settings' -import { fixWeb3State } from './plugins/EVM/UI/Web3State' import { getBackgroundColor } from './utils' import { isTwitter } from './social-network-adaptor/twitter.com/base' import { MaskThemeProvider } from '@masknet/theme' @@ -37,19 +34,12 @@ export function MaskUIRoot({ children, kind, useTheme }: MaskUIRootProps) { const pluginID = useValueRef(pluginIDSettings) const PluginsWeb3State = useAllPluginsWeb3State() - // TODO: migrate EVM plugin - fixWeb3State(PluginsWeb3State[NetworkPluginID.PLUGIN_EVM], Web3Context) - return compose( children, (jsx) => , (jsx) => , (jsx) => , - (jsx) => ( - - - - ), + (jsx) => , (jsx) => , kind === 'page' ? (jsx) => : identity, (jsx) => ( diff --git a/packages/mask/src/components/CompositionDialog/PluginEntryRender.tsx b/packages/mask/src/components/CompositionDialog/PluginEntryRender.tsx index 018425f6fa70..b1e41f6c209d 100644 --- a/packages/mask/src/components/CompositionDialog/PluginEntryRender.tsx +++ b/packages/mask/src/components/CompositionDialog/PluginEntryRender.tsx @@ -5,7 +5,7 @@ import { PluginI18NFieldRender, usePluginI18NField, } from '@masknet/plugin-infra/content-script' -import { useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' +import { useChainId, useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' import { ErrorBoundary } from '@masknet/shared-base-ui' import { Result } from 'ts-results' import { RedPacketPluginID } from '../../plugins/RedPacket/constants' @@ -13,7 +13,6 @@ import { ITO_PluginID } from '../../plugins/ITO/constants' import { ClickableChip } from '../shared/SelectRecipients/ClickableChip' import { makeStyles } from '@masknet/theme' import { useCallback, useState, useRef, forwardRef, memo, useImperativeHandle, useMemo } from 'react' -import { useChainId } from '@masknet/web3-shared-evm' import { Trans } from 'react-i18next' const useStyles = makeStyles()((theme) => ({ sup: { diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index aaf461822524..077d37edc208 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -4,11 +4,11 @@ import { useActivatedPluginsSNSAdaptor, usePluginI18NField, } from '@masknet/plugin-infra/content-script' -import { useAvailablePlugins } from '@masknet/plugin-infra/web3' +import { useAddressNames, useAvailablePlugins } from '@masknet/plugin-infra/web3' import { ConcealableTabs } from '@masknet/shared' import { EMPTY_LIST, NextIDPlatform } from '@masknet/shared-base' import { makeStyles, useStylesExtends } from '@masknet/theme' -import { useAddressNames } from '@masknet/web3-shared-evm' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { Box, CircularProgress, Typography } from '@mui/material' import { first } from 'lodash-unified' import { useEffect, useMemo, useState } from 'react' @@ -50,7 +50,10 @@ export function ProfileTabContent(props: ProfileTabContentProps) { const identity = useCurrentVisitingIdentity() const { currentConnectedPersona } = usePersonaConnectStatus() const platform = activatedSocialNetworkUI.configuration.nextIDConfig?.platform as NextIDPlatform - const { value: addressNames = EMPTY_LIST, loading: loadingAddressNames } = useAddressNames(identity) + const { value: addressNames = EMPTY_LIST, loading: loadingAddressNames } = useAddressNames( + NetworkPluginID.PLUGIN_EVM, + identity, + ) const { value: personaList = EMPTY_LIST, loading: loadingPersonaList } = useNextIDBoundByPlatform( platform as NextIDPlatform, identity.identifier?.userId, diff --git a/packages/mask/src/components/InjectedComponents/SearchResultBox.tsx b/packages/mask/src/components/InjectedComponents/SearchResultBox.tsx index c917be2bf891..5d09af03a749 100644 --- a/packages/mask/src/components/InjectedComponents/SearchResultBox.tsx +++ b/packages/mask/src/components/InjectedComponents/SearchResultBox.tsx @@ -1,7 +1,7 @@ import { createInjectHooksRenderer, useActivatedPluginsSNSAdaptor } from '@masknet/plugin-infra/content-script' const PluginRenderer = createInjectHooksRenderer( - useActivatedPluginsSNSAdaptor.visibility.useNotMinimalMode, + useActivatedPluginsSNSAdaptor.visibility.useAnyMode, (x) => x.SearchResultBox, ) diff --git a/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx b/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx index 6a2593c93cca..09d5be7955ad 100644 --- a/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx +++ b/packages/mask/src/components/InjectedComponents/ToolboxUnstyled.tsx @@ -10,17 +10,17 @@ import { ListItemText as MuiListItemText, Box, } from '@mui/material' -import { TransactionStatusType } from '@masknet/web3-shared-evm' +import { TransactionStatusType } from '@masknet/web3-shared-base' import { useNetworkDescriptor, useProviderDescriptor, useAccount, - useWallet, useChainColor, useChainIdValid, - useChainDetailed, useWeb3State, useReverseAddress, + useChainIdMainnet, + useRecentTransactions, } from '@masknet/plugin-infra/web3' import { useCallback, useEffect } from 'react' import { WalletIcon } from '@masknet/shared' @@ -28,7 +28,6 @@ import { useRemoteControlledDialog } from '@masknet/shared-base-ui' import { WalletMessages } from '../../plugins/Wallet/messages' import { useI18N } from '../../utils' import { hasNativeAPI, nativeAPI } from '../../../shared/native-rpc' -import { useRecentTransactions } from '../../plugins/Wallet/hooks/useRecentTransactions' import GuideStep from '../GuideStep' import { AccountBalanceWalletIcon } from '@masknet/icons' import { makeStyles } from '@masknet/theme' @@ -205,16 +204,13 @@ function ToolboxHintForWallet(props: ToolboxHintProps) { function useToolbox() { const { t } = useI18N() const account = useAccount() - const selectedWallet = useWallet() const chainColor = useChainColor() const chainIdValid = useChainIdValid() - const chainDetailed = useChainDetailed() - const { Utils } = useWeb3State() + const chainIdMainnet = useChainIdMainnet() + const { Others } = useWeb3State() // #region recent pending transactions - const { value: pendingTransactions = [] } = useRecentTransactions({ - status: TransactionStatusType.NOT_DEPEND, - }) + const pendingTransactions = useRecentTransactions(undefined, TransactionStatusType.NOT_DEPEND) // #endregion // #region Wallet @@ -226,15 +222,15 @@ function useToolbox() { ) // #endregion - const isWalletValid = !!account && selectedWallet && chainIdValid + const isWalletValid = !!account && chainIdValid - const { value: domain } = useReverseAddress(account) + const { value: domain } = useReverseAddress(undefined, account) function renderButtonText() { if (!account) return t('plugin_wallet_connect_wallet') if (!chainIdValid) return t('plugin_wallet_wrong_network') if (pendingTransactions.length <= 0) - return Utils?.formatDomainName?.(domain) || Utils?.formatAddress?.(account, 4) || account + return Others?.formatDomainName?.(domain) || Others?.formatAddress?.(account, 4) || account return ( <> @@ -255,8 +251,7 @@ function useToolbox() { const walletTitle = renderButtonText() - const shouldDisplayChainIndicator = - account && chainIdValid && chainDetailed?.network && chainDetailed.network !== 'mainnet' + const shouldDisplayChainIndicator = account && chainIdValid && !chainIdMainnet return { openWallet, isWalletValid, diff --git a/packages/mask/src/components/shared/ApplicationBoard.tsx b/packages/mask/src/components/shared/ApplicationBoard.tsx index bba3a2fd9cfc..777f5128dfd1 100644 --- a/packages/mask/src/components/shared/ApplicationBoard.tsx +++ b/packages/mask/src/components/shared/ApplicationBoard.tsx @@ -1,9 +1,9 @@ import { useContext, createContext, PropsWithChildren, useMemo, useCallback, useEffect } from 'react' import { makeStyles, getMaskColor } from '@masknet/theme' import { Typography } from '@mui/material' -import { useChainId } from '@masknet/web3-shared-evm' import { useActivatedPluginsSNSAdaptor } from '@masknet/plugin-infra/content-script' -import { useCurrentWeb3NetworkPluginID, useAccount, NetworkPluginID } from '@masknet/plugin-infra/web3' +import { useCurrentWeb3NetworkPluginID, useAccount, useChainId } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { formatPersonaPublicKey } from '@masknet/shared-base' import { getCurrentSNSNetwork } from '../../social-network-adaptor/utils' import { activatedSocialNetworkUI } from '../../social-network' diff --git a/packages/mask/src/components/shared/NetworkTab.tsx b/packages/mask/src/components/shared/NetworkTab.tsx index 6087c1306c27..9118b57fb286 100644 --- a/packages/mask/src/components/shared/NetworkTab.tsx +++ b/packages/mask/src/components/shared/NetworkTab.tsx @@ -1,6 +1,6 @@ import { makeStyles, MaskColorVar, useStylesExtends } from '@masknet/theme' import AbstractTab, { AbstractTabProps } from './AbstractTab' -import { ChainId, getChainDetailed } from '@masknet/web3-shared-evm' +import { ChainId, chainResolver } from '@masknet/web3-shared-evm' import { isDashboardPage } from '@masknet/shared-base' interface StyleProps { @@ -59,7 +59,7 @@ export function NetworkTab(props: NetworkTabProps) { }) const tabProps: AbstractTabProps = { - tabs: chains.map((chainId) => createTabItem(getChainDetailed(chainId)?.chain ?? 'Unknown', chainId)), + tabs: chains.map((chainId) => createTabItem(chainResolver.chainName(chainId) ?? 'Unknown', chainId)), index: chains.indexOf(chainId), classes, hasOnlyOneChild: true, diff --git a/packages/mask/src/components/shared/SelectWallet/WalletInList.tsx b/packages/mask/src/components/shared/SelectWallet/WalletInList.tsx index d109e73c35b3..589bab99144e 100644 --- a/packages/mask/src/components/shared/SelectWallet/WalletInList.tsx +++ b/packages/mask/src/components/shared/SelectWallet/WalletInList.tsx @@ -3,7 +3,8 @@ import ListItemButton from '@mui/material/ListItemButton' import { makeStyles, useStylesExtends } from '@masknet/theme' import CheckIcon from '@mui/icons-material/Check' import type { DefaultComponentProps } from '@mui/material/OverridableComponent' -import { formatEthereumAddress, useBlockie, Wallet } from '@masknet/web3-shared-evm' +import { formatEthereumAddress, Wallet } from '@masknet/web3-shared-evm' +import { useBlockie } from '@masknet/plugin-infra/web3' import { useI18N } from '../../../utils' const useStyle = makeStyles()((theme) => ({ diff --git a/packages/mask/src/components/shared/TokenPrice.tsx b/packages/mask/src/components/shared/TokenPrice.tsx index fb6818ece882..0c2d255667e4 100644 --- a/packages/mask/src/components/shared/TokenPrice.tsx +++ b/packages/mask/src/components/shared/TokenPrice.tsx @@ -1,8 +1,8 @@ import type { FC, HTMLProps } from 'react' import type BigNumber from 'bignumber.js' -import { ChainId, CurrencyType, isZeroAddress } from '@masknet/web3-shared-evm' -import { useNativeTokenPrice, useTokenPrice } from '../../plugins/Wallet/hooks/useTokenPrice' -import { multipliedBy } from '@masknet/web3-shared-base' +import { ChainId, isZeroAddress } from '@masknet/web3-shared-evm' +import { CurrencyType, multipliedBy, NetworkPluginID } from '@masknet/web3-shared-base' +import { useFungibleTokenPrice, useNativeTokenPrice } from '@masknet/plugin-infra/web3' interface TokenPriceProps extends Omit, 'children'> { chainId: ChainId @@ -18,8 +18,15 @@ export const TokenPrice: FC = ({ currencyType = CurrencyType.USD, ...rest }) => { - const tokenPrice = useTokenPrice(chainId, contractAddress?.toLowerCase(), currencyType) - const nativeTokenPrice = useNativeTokenPrice(chainId) + const { value: tokenPrice = 0 } = useFungibleTokenPrice( + NetworkPluginID.PLUGIN_EVM, + contractAddress?.toLowerCase(), + { + chainId, + currencyType, + }, + ) + const { value: nativeTokenPrice = 0 } = useNativeTokenPrice(NetworkPluginID.PLUGIN_EVM, { chainId }) const price = isZeroAddress(contractAddress) ? nativeTokenPrice : tokenPrice return ${multipliedBy(amount, price).toFixed(2)} } diff --git a/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx b/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx index 2226ba0b7573..1585e82c42e3 100644 --- a/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/CurrentWalletBox.tsx @@ -1,9 +1,17 @@ -import { ExternalLink } from 'react-feather' -import { ChainId, ProviderType, NetworkType, useAccount, useProviderType } from '@masknet/web3-shared-evm' -import { Button, Link, Typography } from '@mui/material' -import { makeStyles } from '@masknet/theme' -import { useWeb3State, useNetworkDescriptor, useProviderDescriptor, Web3Plugin } from '@masknet/plugin-infra/web3' +import { + useAccount, + useNetworkDescriptor, + useProviderDescriptor, + useProviderType, + useReverseAddress, + useWeb3State, +} from '@masknet/plugin-infra/web3' import { FormattedAddress, WalletIcon } from '@masknet/shared' +import { makeStyles } from '@masknet/theme' +import { Account, NetworkPluginID } from '@masknet/web3-shared-base' +import { ChainId, ProviderType } from '@masknet/web3-shared-evm' +import { Button, Link, Typography } from '@mui/material' +import { ExternalLink } from 'react-feather' import { useI18N } from '../../../utils' const useStyles = makeStyles()((theme) => ({ @@ -86,7 +94,9 @@ const useStyles = makeStyles()((theme) => ({ }, })) interface CurrentWalletBox { - wallet: Web3Plugin.ConnectionResult + wallet: Account & { + providerType: ProviderType + } walletName?: string changeWallet: () => void notInPop?: boolean @@ -95,13 +105,13 @@ export function CurrentWalletBox(props: CurrentWalletBox) { const { t } = useI18N() const { classes } = useStyles() const { wallet, walletName, notInPop, changeWallet } = props - const providerType = useProviderType() - const providerDescriptor = useProviderDescriptor(wallet.providerType ?? providerType) - const networkDescriptor = useNetworkDescriptor(wallet.networkType) - const frontAccount = useAccount() + const providerType = useProviderType(NetworkPluginID.PLUGIN_EVM) + const providerDescriptor = useProviderDescriptor(NetworkPluginID.PLUGIN_EVM, providerType) + const networkDescriptor = useNetworkDescriptor(NetworkPluginID.PLUGIN_EVM) + const frontAccount = useAccount(NetworkPluginID.PLUGIN_EVM) const account = notInPop ? frontAccount : wallet.account - const { Utils } = useWeb3State() ?? {} - + const { Others } = useWeb3State(NetworkPluginID.PLUGIN_EVM) ?? {} + const { value: domain } = useReverseAddress(NetworkPluginID.PLUGIN_EVM, wallet.account) return account ? (
- {walletName} + {providerType !== ProviderType.MaskWallet ? ( + + {domain && Others?.formatDomainName + ? Others.formatDomainName(domain) + : providerDescriptor?.name} + + ) : ( + <> + + {walletName ?? providerDescriptor?.name} + + {domain && Others?.formatDomainName ? ( + {Others.formatDomainName(domain)} + ) : null} + + )}
- + diff --git a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx index b407d054dea6..110be98a396f 100644 --- a/packages/mask/src/components/shared/VerifyWallet/Steps.tsx +++ b/packages/mask/src/components/shared/VerifyWallet/Steps.tsx @@ -13,8 +13,8 @@ import { ImageIcon } from '@masknet/shared' import { Typography } from '@mui/material' import { useEffect } from 'react' import { useI18N } from '../../../utils' -import type { Web3Plugin } from '@masknet/plugin-infra/src/web3-types' -import type { ChainId, NetworkType, ProviderType } from '@masknet/web3-shared-evm' +import type { Account } from '@masknet/web3-shared-base' +import type { ChainId, ProviderType } from '@masknet/web3-shared-evm' import { LoadingButton } from '@mui/lab' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' @@ -99,7 +99,9 @@ export enum SignSteps { interface StepsProps { step: SignSteps nickname?: string - wallet: Web3Plugin.ConnectionResult + wallet: Account & { + providerType: ProviderType + } disableConfirm?: boolean confirmLoading: boolean notInPop?: boolean diff --git a/packages/mask/src/components/shared/WalletStatusBox/TransactionList.tsx b/packages/mask/src/components/shared/WalletStatusBox/TransactionList.tsx index 3e729c601caa..f7d0141c4d05 100644 --- a/packages/mask/src/components/shared/WalletStatusBox/TransactionList.tsx +++ b/packages/mask/src/components/shared/WalletStatusBox/TransactionList.tsx @@ -1,24 +1,14 @@ +import { FC, forwardRef, useCallback, useMemo, useState } from 'react' +import { useAsync } from 'react-use' import { LinkOutIcon } from '@masknet/icons' -import { useWeb3State } from '@masknet/plugin-infra/web3' -import { WalletMessages } from '@masknet/plugin-wallet' +import { useChainId, useWeb3, useWeb3State, Web3Helper } from '@masknet/plugin-infra/web3' import { makeStyles } from '@masknet/theme' -import { - ChainId, - getContractOwnerDomain, - isSameAddress, - TransactionStateType, - TransactionStatusType, - useChainId, - useWeb3, -} from '@masknet/web3-shared-evm' +import { isSameAddress, RecentTransaction, TransactionStatusType } from '@masknet/web3-shared-base' +import { getContractOwnerDomain } from '@masknet/web3-shared-evm' import { Grid, GridProps, Link, List, ListItem, ListProps, Stack, Typography } from '@mui/material' import classnames from 'classnames' import format from 'date-fns/format' import { noop } from 'lodash-unified' -import { FC, forwardRef, useCallback, useEffect, useMemo, useState } from 'react' -import { useAsync } from 'react-use' -import Services from '../../../extension/service' -import type { RecentTransaction } from '../../../plugins/Wallet/services/transaction' import { useI18N } from '../../../utils' const useStyles = makeStyles()((theme) => ({ @@ -78,44 +68,46 @@ const statusTextColorMap: Record = { [TransactionStatusType.NOT_DEPEND]: '#FFB915', [TransactionStatusType.SUCCEED]: '#60DFAB', [TransactionStatusType.FAILED]: '#FF5F5F', - [TransactionStatusType.CANCELLED]: '#FF5F5F', } const getContractFunctionName = async (data: string | undefined) => { if (!data) return null const sig = data.slice(0, 10) - const name = await Services.Ethereum.getContractFunctionName(sig) - return name ? name.replace(/_/g, ' ') : 'Contract Interaction' + // const name = await Services.Ethereum.getContractFunctionName(sig) + // return name ? name.replace(/_/g, ' ') : 'Contract Interaction' + return '' } interface TransactionProps extends GridProps { - chainId: ChainId - transaction: RecentTransaction - onClear?(tx: RecentTransaction): void + chainId: Web3Helper.ChainIdAll + transaction: RecentTransaction + onClear?(tx: RecentTransaction): void } const Transaction: FC = ({ chainId, transaction: tx, onClear = noop, ...rest }) => { const { t } = useI18N() - const { Utils } = useWeb3State() const { classes, theme } = useStyles() const statusTextMap: Record = { [TransactionStatusType.NOT_DEPEND]: t('recent_transaction_pending'), [TransactionStatusType.SUCCEED]: t('recent_transaction_success'), [TransactionStatusType.FAILED]: t('recent_transaction_failed'), - [TransactionStatusType.CANCELLED]: t('recent_transaction_cancelled'), } const web3 = useWeb3() + const { Others } = useWeb3State() as Web3Helper.Web3StateAll + const { value: targetAddress } = useAsync(async () => { - if (tx.receipt?.contractAddress) return tx.receipt.contractAddress - if (tx.payload?.params?.[0].to) return tx.payload.params[0].to as string - const transaction = await web3.eth.getTransaction(tx.hash) - return transaction.to + return '' + // if (tx.receipt?.contractAddress) return tx.receipt.contractAddress + // if (tx.payload?.params?.[0].to) return tx.payload.params[0].to as string + // const transaction = await web3?.eth.getTransaction(tx.hash) + // return transaction.to }, [web3, tx]) const address = (targetAddress || '').toLowerCase() - const txData = tx.payload?.params?.[0].data as string | undefined + // const txData = tx.payload?.params?.[0].data as string | undefined const { value: functionName } = useAsync(async () => { - return getContractFunctionName(txData) - }, [txData]) + return '' + // return getContractFunctionName(txData) + }, []) const handleClear = useCallback(() => { onClear(tx) @@ -125,19 +117,19 @@ const Transaction: FC = ({ chainId, transaction: tx, onClear = const [txStatus, setTxStatus] = useState(tx.status) - useEffect(() => { - return WalletMessages.events.transactionStateUpdated.on((data) => { - if ('receipt' in data && tx.hash === data.receipt?.transactionHash) { - switch (data.type) { - case TransactionStateType.CONFIRMED: - setTxStatus(TransactionStatusType.SUCCEED) - break - case TransactionStateType.FAILED: - setTxStatus(TransactionStatusType.FAILED) - } - } - }) - }, [tx.hash]) + // useEffect(() => { + // return WalletMessages.events.transactionStateUpdated.on((data) => { + // if ('receipt' in data && tx.id === data.receipt?.transactionHash) { + // switch (data.type) { + // case TransactionStateType.CONFIRMED: + // setTxStatus(TransactionStatusType.SUCCEED) + // break + // case TransactionStateType.FAILED: + // setTxStatus(TransactionStatusType.FAILED) + // } + // } + // }) + // }, [tx.id]) return ( @@ -151,19 +143,19 @@ const Transaction: FC = ({ chainId, transaction: tx, onClear = {functionName} - {format(tx.at, 'yyyy.MM.dd hh:mm')} + {format(tx.createdAt, 'yyyy.MM.dd hh:mm')} {address && isSameAddress(domainOrAddress, address) - ? Utils?.formatAddress?.(address, 4) + ? Others?.formatAddress?.(address, 4) : domainOrAddress || address} @@ -186,8 +178,8 @@ const Transaction: FC = ({ chainId, transaction: tx, onClear = } interface Props extends ListProps { - transactions: RecentTransaction[] - onClear?(tx: RecentTransaction): void + transactions: Array> + onClear?(tx: RecentTransaction): void } export const TransactionList: FC = forwardRef(({ className, transactions, onClear = noop, ...rest }, ref) => { @@ -197,7 +189,7 @@ export const TransactionList: FC = forwardRef(({ className, transactions, return ( {transactions.map((tx) => ( - + ))} diff --git a/packages/mask/src/components/shared/WalletStatusBox/index.tsx b/packages/mask/src/components/shared/WalletStatusBox/index.tsx index f0f8eb6f7a2d..85c3dcd1b279 100644 --- a/packages/mask/src/components/shared/WalletStatusBox/index.tsx +++ b/packages/mask/src/components/shared/WalletStatusBox/index.tsx @@ -7,6 +7,7 @@ import { useReverseAddress, useWallet, useWeb3State, + Web3Helper, } from '@masknet/plugin-infra/web3' import { FormattedAddress, useSnackbarCallback, WalletIcon } from '@masknet/shared' import { isDashboardPage } from '@masknet/shared-base' @@ -105,9 +106,8 @@ export function WalletStatusBox(props: WalletStatusBox) { const providerType = useProviderType() const providerDescriptor = useProviderDescriptor() const networkDescriptor = useNetworkDescriptor() - const { Utils } = useWeb3State() ?? {} - - const { value: domain } = useReverseAddress(account) + const { Others } = useWeb3State() as Web3Helper.Web3StateAll + const { value: domain } = useReverseAddress(undefined, account) // #region copy addr to clipboard const [, copyToClipboard] = useCopyToClipboard() @@ -150,8 +150,8 @@ export function WalletStatusBox(props: WalletStatusBox) {
{providerType !== ProviderType.MaskWallet ? ( - {domain && Utils?.formatDomainName - ? Utils.formatDomainName(domain) + {domain && Others?.formatDomainName + ? Others.formatDomainName(domain) : providerDescriptor?.name} ) : ( @@ -159,15 +159,17 @@ export function WalletStatusBox(props: WalletStatusBox) { {wallet?.name ?? providerDescriptor?.name} - {domain && Utils?.formatDomainName ? ( - {Utils.formatDomainName(domain)} + {domain && Others?.formatDomainName ? ( + + {Others.formatDomainName(domain)} + ) : null} )}
- + diff --git a/packages/mask/src/components/shared/WalletStatusBox/usePendingTransactions.tsx b/packages/mask/src/components/shared/WalletStatusBox/usePendingTransactions.tsx index fe2f39e54a01..ac1abe4f7b9c 100644 --- a/packages/mask/src/components/shared/WalletStatusBox/usePendingTransactions.tsx +++ b/packages/mask/src/components/shared/WalletStatusBox/usePendingTransactions.tsx @@ -1,14 +1,13 @@ -import { EMPTY_LIST } from '@masknet/shared-base' +import { + useClearTransactionsCallback, + useRemoveTransactionCallback, + useRecentTransactions, +} from '@masknet/plugin-infra/web3' import { makeStyles } from '@masknet/theme' -import { TransactionStatusType } from '@masknet/web3-shared-evm' +import { TransactionStatusType } from '@masknet/web3-shared-base' import { Typography } from '@mui/material' import classnames from 'classnames' import { useState } from 'react' -import { - useClearRecentTransactions, - useRecentTransactions, - useRemoveRecentTransaction, -} from '../../../plugins/Wallet/hooks' import { useI18N } from '../../../utils' import { TransactionList } from './TransactionList' @@ -37,18 +36,16 @@ export function usePendingTransactions() { const { t } = useI18N() // #region recent pending transactions - const { value: pendingTransactions = EMPTY_LIST } = useRecentTransactions({ - status: TransactionStatusType.NOT_DEPEND, - }) + const pendingTransactions = useRecentTransactions(undefined, TransactionStatusType.NOT_DEPEND) // frozenTxes would not be reactive to pendingTransactions, // it would be recreated then the list shows up. const [meltedTxHashes, setMeltedTxHashes] = useState([]) - const clearRecentTxes = useClearRecentTransactions() - const removeRecentTx = useRemoveRecentTransaction() + const clearRecentTxes = useClearTransactionsCallback() + const removeRecentTx = useRemoveTransactionCallback() - const transactions = pendingTransactions.slice(0, 5).filter((tx) => !meltedTxHashes.includes(tx.hash)) + const transactions = pendingTransactions.slice(0, 5).filter((tx) => !meltedTxHashes.includes(tx.id)) // #endregion const summary = pendingTransactions.length ? (
@@ -74,8 +71,8 @@ export function usePendingTransactions() { { - setMeltedTxHashes((list) => [...list, tx.hash]) - removeRecentTx(tx.hash) + setMeltedTxHashes((list) => [...list, tx.id]) + removeRecentTx(tx.id) }} /> ) diff --git a/packages/mask/src/env.d.ts b/packages/mask/src/env.d.ts index 9996c0915d7e..2359dc684c18 100644 --- a/packages/mask/src/env.d.ts +++ b/packages/mask/src/env.d.ts @@ -4,14 +4,3 @@ /// /// /// - -declare module 'ethjs-ens' { - import { provider as Provider } from 'web3-core' - import { ChainId } from '../../web3-shared/evm' - - export default class Ens { - constructor(options: { provider: Provider; network: ChainId }) {} - lookup(name: string): Promise - reverse(address: string): Promise - } -} diff --git a/packages/mask/src/extension/background-script/BackupService.ts b/packages/mask/src/extension/background-script/BackupService.ts index 6c97ebfeb4a1..611800f67790 100644 --- a/packages/mask/src/extension/background-script/BackupService.ts +++ b/packages/mask/src/extension/background-script/BackupService.ts @@ -3,7 +3,7 @@ export * from '../../../background/services/backup' import { assertEnvironment, Environment } from '@dimensiondev/holoflows-kit' assertEnvironment(Environment.ManifestBackground) -import { currySameAddress, isSameAddress, ProviderType } from '@masknet/web3-shared-evm' +import { currySameAddress, isSameAddress } from '@masknet/web3-shared-base' import { exportMnemonic, exportPrivateKey, @@ -96,14 +96,16 @@ delegateWalletRestore(async function (backup) { async function backupAllWallets(): Promise { const allSettled = await Promise.allSettled( ( - await getWallets(ProviderType.MaskWallet) - ).map(async (wallet) => { - return { - ...wallet, - mnemonic: wallet.derivationPath ? await exportMnemonic(wallet.address) : undefined, - privateKey: wallet.derivationPath ? undefined : await exportPrivateKey(wallet.address), - } - }), + await getWallets() + ) + .filter((x) => x.storedKeyInfo) + .map(async (wallet) => { + return { + ...wallet, + mnemonic: wallet.derivationPath ? await exportMnemonic(wallet.address) : undefined, + privateKey: wallet.derivationPath ? undefined : await exportPrivateKey(wallet.address), + } + }), ) const wallets_ = allSettled.map((x) => (x.status === 'fulfilled' ? WalletRecordToJSONFormat(x.value) : null)) if (wallets_.some((x) => !x)) throw new Error('Failed to backup wallets.') @@ -111,7 +113,7 @@ async function backupAllWallets(): Promise { } async function backupAllLegacyWallets(): Promise { - const x = await getLegacyWallets(ProviderType.MaskWallet) + const x = await getLegacyWallets() return x.map(LegacyWalletRecordToJSONFormat) } diff --git a/packages/mask/src/extension/background-script/EthereumService.ts b/packages/mask/src/extension/background-script/EthereumService.ts deleted file mode 100644 index 583984838923..000000000000 --- a/packages/mask/src/extension/background-script/EthereumService.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './EthereumServices/request' -export * from './EthereumServices/provider' -export * from './EthereumServices/nonce' -export * from './EthereumServices/network' -export * from './EthereumServices/rpc' diff --git a/packages/mask/src/extension/background-script/EthereumServices/network.ts b/packages/mask/src/extension/background-script/EthereumServices/network.ts deleted file mode 100644 index 363c92387c6a..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/network.ts +++ /dev/null @@ -1,243 +0,0 @@ -import type { - SignedTransaction, - Transaction, - TransactionConfig, - TransactionReceipt, - PastLogsOptions, - Log, -} from 'web3-core' -import { toHex } from 'web3-utils' -import { - ChainId, - EthereumChainDetailed, - EthereumMethodType, - RequestOptions, - SendOverrides, -} from '@masknet/web3-shared-evm' -import { request } from './request' - -export async function getChainId(overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_CHAIN_ID, - }, - overrides, - ) -} - -export async function getAccounts(overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_ACCOUNTS, - }, - overrides, - ) -} - -export async function getCode(address: string, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_GET_CODE, - params: [address, 'latest'], - }, - overrides, - ) -} - -export async function getGasPrice(overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_GAS_PRICE, - }, - overrides, - ) -} - -export async function getBlockNumber(overrides?: SendOverrides) { - const blockNumber = await request( - { - method: EthereumMethodType.ETH_BLOCK_NUMBER, - }, - overrides, - ) - return Number.parseInt(blockNumber, 16) || 0 -} - -export async function getBalance(address: string, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_GET_BALANCE, - params: [address, 'latest'], - }, - overrides, - ) -} - -export async function getTransactionByHash(hash: string, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_GET_TRANSACTION_BY_HASH, - params: [hash], - }, - overrides, - ) -} - -export async function getTransactionReceipt(hash: string, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.MASK_GET_TRANSACTION_RECEIPT, - params: [hash], - }, - overrides, - ) -} - -export async function getTransactionCount(address: string, overrides?: SendOverrides) { - const count = await request( - { - method: EthereumMethodType.ETH_GET_TRANSACTION_COUNT, - params: [address, 'latest'], - }, - overrides, - ) - return Number.parseInt(count, 16) || 0 -} - -export async function getPendingTransactions(address: string, overrides?: SendOverrides) { - const filterId = await request( - { - method: EthereumMethodType.ETH_NEW_PENDING_TRANSACTION_FILTER, - params: [], - }, - overrides, - ) - const transactions = await request( - { - method: EthereumMethodType.ETH_GET_FILTER_CHANGES, - params: [filterId], - }, - overrides, - ) - return transactions -} - -export async function call(config: TransactionConfig, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_CALL, - params: [config, 'latest'], - }, - overrides, - ) -} - -export async function estimateGas(config: TransactionConfig, overrides?: SendOverrides) { - const gas = await request( - { - method: EthereumMethodType.ETH_ESTIMATE_GAS, - params: [config], - }, - overrides, - ) - return Number.parseInt(gas, 16) || 0 -} - -export async function sign(dataToSign: string, address: string, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_SIGN, - params: [dataToSign, address], - }, - overrides, - ) -} - -export async function personalSign( - dataToSign: string, - address: string, - password?: string, - overrides?: SendOverrides, - requestOptions?: RequestOptions, -) { - return request( - { - method: EthereumMethodType.PERSONAL_SIGN, - params: [dataToSign, address, password].filter((x) => typeof x !== 'undefined'), - }, - overrides, - requestOptions, - ) -} - -export async function typedDataSign(address: string, dataToSign: string, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_SIGN_TYPED_DATA, - params: [address, dataToSign], - }, - overrides, - ) -} - -export async function addEthereumChain( - chainDetailed: EthereumChainDetailed, - address?: string, - overrides?: SendOverrides, -) { - return request( - { - method: EthereumMethodType.WALLET_ADD_ETHEREUM_CHAIN, - params: [chainDetailed, address].filter(Boolean), - }, - overrides, - ) -} - -export async function switchEthereumChain(chainId: ChainId, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.WALLET_SWITCH_ETHEREUM_CHAIN, - params: [ - { - chainId: toHex(chainId), - }, - ], - }, - overrides, - ) -} - -export async function signTransaction(config: TransactionConfig, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_SIGN_TRANSACTION, - params: [config], - }, - overrides, - ) -} - -export async function sendTransaction(config: TransactionConfig, overrides?: SendOverrides) { - return request( - { - method: EthereumMethodType.ETH_SEND_TRANSACTION, - params: [config], - }, - overrides, - ) -} - -export async function getPastLogs(config: PastLogsOptions, overrides?: SendOverrides) { - return new Promise((resolve, reject) => - request( - { - method: EthereumMethodType.ETH_GET_LOGS, - params: [config], - }, - overrides, - ) - .then((result) => resolve(result)) - .catch(() => resolve([])), - ) -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/nonce.ts b/packages/mask/src/extension/background-script/EthereumServices/nonce.ts deleted file mode 100644 index 54a828312be7..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/nonce.ts +++ /dev/null @@ -1,131 +0,0 @@ -import { ProviderType } from '@masknet/web3-shared-evm' -import { EthereumAddress } from 'wallet.ts' -import { getTransactionCount } from './network' -import { currentMaskWalletChainIdSettings } from '../../../plugins/Wallet/settings' - -class NonceManager { - constructor(private address: string) {} - private nonce = NonceManager.INITIAL_NONCE - private locked = false - private tasks: Array<() => void> = [] - - private lock() { - this.locked = true - } - private unlock() { - this.locked = false - } - private continue() { - if (!this.locked) this.tasks.shift()?.() - } - private async getRemoteNonce() { - return new Promise(async (resolve, reject) => { - const callback = (e: unknown, nonce?: number) => { - if (e) reject(e) - // TODO: is 0 a correct value if nonce is undefined? - else resolve(nonce ?? 0) - this.unlock() - this.continue() - } - const run = async () => { - try { - this.lock() - callback( - null, - // Only mask wallets need to use Nonce - await getTransactionCount(this.address, { - providerType: ProviderType.MaskWallet, - chainId: currentMaskWalletChainIdSettings.value, - }), - ) - } catch (error) { - callback(error) - } - } - if (this.locked) this.tasks.push(run) - else run() - }) - } - private async setLocalNonce(nonce: number) { - return new Promise(async (resolve, reject) => { - const callback = (e: Error | null) => { - if (e) reject(e) - else resolve() - this.unlock() - this.continue() - } - const run = async () => { - this.lock() - this.nonce = nonce - callback(null) - } - if (this.locked) this.tasks.push(run) - else run() - }) - } - - public async getNonce() { - const nonce = this.nonce === NonceManager.INITIAL_NONCE ? await this.getRemoteNonce() : this.nonce - await this.setLocalNonce(nonce) - return nonce - } - public async setNonce(nonce: number) { - await this.setLocalNonce(nonce) - } - public async resetNonce() { - const nonce = await this.getRemoteNonce() - await this.setLocalNonce(nonce) - } - - static INITIAL_NONCE = -1 -} - -const cache = new Map() - -/** - * Get current available nonce, call commitNonce() after the transaction succeed - * @param address the account address - */ -export function getNonce(address_: string) { - const address = EthereumAddress.checksumAddress(address_) - if (!cache.has(address)) cache.set(address, new NonceManager(address)) - return cache.get(address)!.getNonce() -} - -/** - * Commit to a new nonce only call when transaction succeed - * @param address the account address - */ -export async function commitNonce(address_: string) { - const address = EthereumAddress.checksumAddress(address_) - if (!cache.has(address)) cache.set(address, new NonceManager(address)) - return setNonce(address, (await cache.get(address)!.getNonce()) + 1) -} - -/** - * Set a new nonce regardless the old one - * @param address the account address - * @param nonce the new nonce - */ -export function setNonce(address_: string, nonce: number) { - const address = EthereumAddress.checksumAddress(address_) - if (!cache.has(address)) cache.set(address, new NonceManager(address)) - return cache.get(address)!.setNonce(nonce) -} - -/** - * Sync local nonce to remote one (depend on your current node) - * @param address the account address - */ -export function resetNonce(address_: string) { - const address = EthereumAddress.checksumAddress(address_) - if (!cache.has(address)) cache.set(address, new NonceManager(address)) - return cache.get(address)!.resetNonce() -} - -/** - * Sync all nonces - */ -export async function resetAllNonce() { - await Promise.all(Array.from(cache.values()).map((m) => m.resetNonce())) -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/provider.ts b/packages/mask/src/extension/background-script/EthereumServices/provider.ts deleted file mode 100644 index 633c9c06999a..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/provider.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { first } from 'lodash-unified' -import { defer } from '@dimensiondev/kit' -import type { ChainId, ProviderType } from '@masknet/web3-shared-evm' -import * as MaskWallet from './providers/MaskWallet' -import * as MetaMask from './providers/MetaMask' -import * as WalletConnect from './providers/WalletConnect' -import * as CustomNetwork from './providers/CustomNetwork' -import * as Injected from './providers/Injected' -import * as Fortmatic from './providers/Fortmatic' - -// #region connect WalletConnect -// Step 1: Generate the connection URI and render a QRCode for scanning by the user -export async function createConnectionURI() { - return (await WalletConnect.createConnector()).uri -} - -// Step 2: If user confirmed the request we will receive the 'connect' event -type Account = { account?: string; chainId: ChainId } -let deferredConnect: Promise | null = null -let resolveConnect: ((result: Account) => void) | undefined -let rejectConnect: ((error: Error) => void) | undefined - -export async function connectWalletConnect() { - const [deferred, resolve, reject] = defer() - - deferredConnect = deferred - resolveConnect = resolve - rejectConnect = reject - createWalletConnect().then(resolve, reject) - - return deferred -} - -export async function createWalletConnect() { - const connector = await WalletConnect.createConnectorIfNeeded() - - if (connector.connected) - return { - account: first(connector.accounts), - chainId: connector.chainId, - } - - const { accounts, chainId } = await WalletConnect.requestAccounts() - return { - account: first(accounts), - chainId, - } -} - -export async function untilWalletConnect() { - if (!deferredConnect) throw new Error('No connection.') - return deferredConnect -} - -export async function cancelWalletConnect() { - rejectConnect?.(new Error('User rejected the request.')) -} -// #endregion - -export async function connectMaskWallet(expectedChainId: ChainId) { - const { accounts, chainId } = await MaskWallet.requestAccounts(expectedChainId) - return { - account: first(accounts), - chainId, - } -} - -export async function connectMetaMask() { - const { accounts, chainId } = await MetaMask.requestAccounts() - return { - account: first(accounts), - chainId, - } -} - -// #region fortmatic -export async function connectFortmatic(expectedChainId: ChainId) { - const { accounts, chainId } = await Fortmatic.requestAccounts(expectedChainId) - return { - account: first(accounts), - chainId, - } -} - -export async function disconnectFortmatic(expectedChainId: ChainId) { - await Fortmatic.dismissAccounts(expectedChainId) -} -// #endregion - -export async function connectCustomNetwork() { - const { accounts, chainId } = await CustomNetwork.requestAccounts() - return { - account: first(accounts), - chainId, - } -} - -// #region connect injected provider -export async function connectInjected() { - const { accounts, chainId } = await Injected.requestAccounts() - return { - account: first(accounts), - chainId, - } -} - -export async function notifyInjectedEvent(name: string, event: unknown, providerType: ProviderType) { - switch (name) { - case 'accountsChanged': - await Injected.onAccountsChanged(event as string[], providerType) - break - case 'chainChanged': - await Injected.onChainIdChanged(event as string, providerType) - break - default: - throw new Error(`Unknown event name: ${name}.`) - } -} -// #endregion diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/CustomNetwork.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/CustomNetwork.ts deleted file mode 100644 index ff7182ca9ffa..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/CustomNetwork.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ChainId } from '@masknet/web3-shared-evm' - -export function createWeb3() { - throw new Error('To be implemented.') -} - -export async function requestAccounts() { - return { - accounts: [], - chainId: ChainId.Mainnet, - } -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/Fortmatic.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/Fortmatic.ts deleted file mode 100644 index 2116fb6d9127..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/Fortmatic.ts +++ /dev/null @@ -1,97 +0,0 @@ -import Web3 from 'web3' -import type { RequestArguments } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' -import { defer } from '@dimensiondev/kit' -import { ChainId, EthereumMethodType } from '@masknet/web3-shared-evm' -import { EVM_Messages } from '../../../../plugins/EVM/messages' -import { resetAccount } from '../../../../plugins/Wallet/services' - -// #region redirect requests to the content page -let id = 0 - -async function request(requestArguments: RequestArguments) { - id += 1 - const requestId = id - const [deferred, resolve, reject] = defer() - - function onResponse({ payload, result, error }: EVM_Messages['FORTMATIC_PROVIDER_RPC_RESPONSE']) { - if (payload.id !== requestId) return - if (error) reject(error) - else resolve(result) - } - - setTimeout( - () => reject(new Error('The request is timeout.')), - requestArguments.method === EthereumMethodType.MASK_LOGIN_FORTMATIC ? 3 * 60 * 1000 : 45 * 1000, - ) - EVM_Messages.events.FORTMATIC_PROVIDER_RPC_RESPONSE.on(onResponse) - EVM_Messages.events.FORTMATIC_PROVIDER_RPC_REQUEST.sendToVisiblePages({ - payload: { - jsonrpc: '2.0', - id: requestId, - params: [], - ...requestArguments, - }, - }) - - deferred.finally(() => { - EVM_Messages.events.FORTMATIC_PROVIDER_RPC_RESPONSE.off(onResponse) - }) - - return deferred -} - -function send(payload: JsonRpcPayload, callback: (error: Error | null, response?: JsonRpcResponse) => void) { - request({ - method: payload.method, - params: payload.params, - }) - .then((result) => { - callback(null, { - id: payload.id as number, - jsonrpc: '2.0', - result, - }) - }) - .catch((error) => { - callback(error) - }) -} -// #endregion - -let web3: Web3 | null = null - -export function createProvider() { - return { - request, - send, - sendAsync: send, - } -} - -export function createWeb3() { - if (web3) return web3 - web3 = new Web3(createProvider()) - return web3 -} - -export async function requestAccounts(expectedChainId: ChainId) { - const provider = createProvider() - const response = await provider.request({ - method: EthereumMethodType.MASK_LOGIN_FORTMATIC, - params: [expectedChainId], - }) - return response as { - chainId: ChainId - accounts: string[] - } -} - -export async function dismissAccounts(expectedChainId: ChainId) { - const provider = createProvider() - await provider.request({ - method: EthereumMethodType.MASK_LOGOUT_FORTMATIC, - params: [expectedChainId], - }) - resetAccount() -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/Injected.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/Injected.ts deleted file mode 100644 index 461e7e6c6089..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/Injected.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { first } from 'lodash-unified' -import { defer } from '@dimensiondev/kit' -import Web3 from 'web3' -import type { RequestArguments } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' -import { ChainId, EthereumMethodType, ProviderType } from '@masknet/web3-shared-evm' -import { EVM_Messages } from '../../../../plugins/EVM/messages' -import { currentChainIdSettings, currentProviderSettings } from '../../../../plugins/Wallet/settings' -import { updateAccount } from '../../../../plugins/Wallet/services' - -// #region redirect requests to the content page -let id = 0 - -async function request(requestArguments: RequestArguments) { - id += 1 - const requestId = id - const [deferred, resolve, reject] = defer() - - function onResponse({ payload, result, error }: EVM_Messages['INJECTED_PROVIDER_RPC_RESPONSE']) { - if (payload.id !== requestId) return - if (error) reject(error) - else resolve(result) - } - - setTimeout( - () => reject(new Error('The request is timeout.')), - requestArguments.method === EthereumMethodType.ETH_REQUEST_ACCOUNTS ? 3 * 60 * 1000 : 45 * 1000, - ) - EVM_Messages.events.INJECTED_PROVIDER_RPC_RESPONSE.on(onResponse) - EVM_Messages.events.INJECTED_PROVIDER_RPC_REQUEST.sendToVisiblePages({ - payload: { - jsonrpc: '2.0', - id: requestId, - params: [], - ...requestArguments, - }, - }) - - deferred.finally(() => { - EVM_Messages.events.INJECTED_PROVIDER_RPC_RESPONSE.off(onResponse) - }) - - return deferred -} - -function send(payload: JsonRpcPayload, callback: (error: Error | null, response?: JsonRpcResponse) => void) { - request({ - method: payload.method, - params: payload.params, - }) - .then((result) => { - callback(null, { - id: payload.id as number, - jsonrpc: '2.0', - result, - }) - }) - .catch((error) => { - callback(error) - }) -} -// #endregion - -let web3: Web3 | null = null - -export function createProvider() { - return { - request, - send, - sendAsync: send, - } -} - -export function createWeb3() { - if (web3) return web3 - web3 = new Web3(createProvider()) - return web3 -} - -export async function requestAccounts() { - const web3 = createWeb3() - const chainId = await web3.eth.getChainId() - const accounts = await web3.eth.requestAccounts() - return { - chainId, - accounts, - } -} - -export async function ensureConnectedAndUnlocked() { - const web3 = createWeb3() - try { - const accounts = await web3.eth.requestAccounts() - throw accounts - } catch (error) { - const accounts = error - if (Array.isArray(accounts)) { - if (accounts.length === 0) throw new Error('Injected Web3 is locked or it has not connected any accounts.') - else if (accounts.length > 0) return // valid - } - // Any other error means failed to connect injected web3 - throw new Error('Failed to connect to injected Web3.') - } -} - -export async function onAccountsChanged(accounts: string[], providerType: ProviderType) { - if (currentProviderSettings.value !== providerType) return - await updateAccount({ - account: first(accounts), - providerType, - }) -} - -export async function onChainIdChanged(id: string, providerType: ProviderType) { - if (currentProviderSettings.value !== providerType) return - - // learn more: https://docs.metamask.io/guide/ethereum-provider.html#chain-ids and https://chainid.network/ - const chainId = Number.parseInt(id, 16) || ChainId.Mainnet - if (currentChainIdSettings.value === chainId) return - await updateAccount({ - chainId, - }) -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts deleted file mode 100644 index 39ed6db6b0f1..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts +++ /dev/null @@ -1,89 +0,0 @@ -import MaskWallet from 'web3' -import type { HttpProvider } from 'web3-core' -import { PopupRoutes } from '@masknet/shared-base' -import { ChainId, getChainRPC, ProviderType } from '@masknet/web3-shared-evm' -import { currentChainIdSettings } from '../../../../plugins/Wallet/settings' -import { openPopupWindow } from '../../../../../background/services/helper' -import { WalletRPC } from '../../../../plugins/Wallet/messages' - -// #region providers -const providerPool = new Map() - -export function createProvider(url: string): HttpProvider { - const provider = - providerPool.get(url) ?? - new MaskWallet.providers.HttpProvider(url, { - timeout: 20000, // ms - // @ts-ignore - clientConfig: { - keepalive: true, - keepaliveInterval: 1, // ms - }, - reconnect: { - auto: true, - delay: 5000, // ms - maxAttempts: Number.MAX_SAFE_INTEGER, - onTimeout: true, - }, - }) - providerPool.set(url, provider) - return provider -} -// #endregion - -// #region web3 instances -const instancePool = new Map() -const SEED = Math.floor(Math.random() * 4) - -function createWeb3Instance(provider: HttpProvider) { - return ( - instancePool.get(provider.host) ?? - (() => { - const newInstance = new MaskWallet(provider) - instancePool.set(provider.host, newInstance) - return newInstance - })() - ) -} - -export function createWeb3({ - url = '', - chainId = currentChainIdSettings.value, - privKeys = [], -}: { - url?: string - chainId?: ChainId - privKeys?: string[] -} = {}) { - url = url || getChainRPC(chainId, SEED) - const provider = createProvider(url) - const web3 = createWeb3Instance(provider) - if (privKeys.length) { - web3.eth.accounts.wallet.clear() - privKeys.forEach((k) => k && k !== '0x' && web3.eth.accounts.wallet.add(k)) - } - return web3 -} -// #endregion - -export async function requestAccounts(chainId: ChainId) { - const wallets = await WalletRPC.getWallets(ProviderType.MaskWallet) - return new Promise<{ - chainId: ChainId - accounts: string[] - }>(async (resolve, reject) => { - try { - await WalletRPC.selectAccountPrepare((accounts, chainId) => { - resolve({ - chainId, - accounts, - }) - }) - await openPopupWindow(wallets.length > 0 ? PopupRoutes.SelectWallet : undefined, { - chainId, - }) - } catch { - reject(new Error('Failed to connect to Mask Network.')) - } - }) -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/MetaMask.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/MetaMask.ts deleted file mode 100644 index 57e4f1b66bff..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/MetaMask.ts +++ /dev/null @@ -1,112 +0,0 @@ -import Web3 from 'web3' -import type { provider as Provider } from 'web3-core' -import { first } from 'lodash-unified' -import createMetaMaskProvider, { MetaMaskInpageProvider } from '@dimensiondev/metamask-extension-provider' -import { ChainId, ProviderType } from '@masknet/web3-shared-evm' -import { delay } from '@dimensiondev/kit' -import { updateAccount } from '../../../../plugins/Wallet/services' -import { currentChainIdSettings, currentProviderSettings } from '../../../../plugins/Wallet/settings' -import { replaceRecentTransaction } from '../../../../plugins/Wallet/services/transaction/database' - -let provider: MetaMaskInpageProvider | null = null -let web3: Web3 | null = null - -async function onAccountsChanged(accounts: string[]) { - if (currentProviderSettings.value !== ProviderType.MetaMask) return - await updateAccount({ - account: first(accounts), - providerType: ProviderType.MetaMask, - chainId: typeof provider?.chainId === 'string' ? Number.parseInt(provider.chainId, 16) : undefined, - }) -} - -async function onChainIdChanged(id: string) { - if (currentProviderSettings.value !== ProviderType.MetaMask) return - - // learn more: https://docs.metamask.io/guide/ethereum-provider.html#chain-ids and https://chainid.network/ - const chainId = Number.parseInt(id, 16) || ChainId.Mainnet - if (currentChainIdSettings.value === chainId) return - await updateAccount({ - chainId, - }) -} - -async function onMessage(message: { - type: 'tx_replacement' - data: { - oldTx: string - newTx: string - nonce: string - from: string - } -}) { - if (message.type !== 'tx_replacement') return - await replaceRecentTransaction( - currentChainIdSettings.value, - message.data.from, - message.data.oldTx, - message.data.newTx, - ) -} - -export async function createProvider() { - if (provider?.chainId) return provider - provider = createMetaMaskProvider() - - // wait for building the connection - await delay(1000) - - if (!provider || provider.chainId === null) { - provider = null - throw new Error('Unable to create provider.') - } - - provider.on('accountsChanged', onAccountsChanged as (...args: unknown[]) => void) - provider.on('chainChanged', onChainIdChanged as (...args: unknown[]) => void) - provider.on('message', onMessage as (...args: unknown[]) => void) - return provider -} - -// MetaMask provider can be wrapped into web3 lib directly. -// https://github.com/MetaMask/extension-provider -export async function createWeb3() { - const provider_ = (await createProvider()) as Provider - if (!web3) web3 = new Web3(provider_) - else web3.setProvider(provider_) - return web3 -} - -export async function requestAccounts() { - const web3 = await createWeb3() - const chainId = await web3.eth.getChainId() - const accounts = await web3.eth.requestAccounts() - return { - chainId, - accounts, - } -} - -export async function ensureConnectedAndUnlocked() { - const web3 = await createWeb3() - try { - const accounts = await web3.eth.requestAccounts() - throw accounts - } catch (error) { - const accounts = error - if (Array.isArray(accounts)) { - if (accounts.length === 0) throw new Error('MetaMask is locked or it has not connected any accounts.') - else if (accounts.length > 0) return // valid - } - // Any other error means failed to connect MetaMask - throw new Error('Failed to connect to MetaMask.') - } -} - -export async function isUnlocked() { - try { - // it's an experimental API. we should not depend on. - return provider?._metamask?.isUnlocked() ?? false - } catch { - return false - } -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts deleted file mode 100644 index 14e20bc09ccb..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/WalletConnect.ts +++ /dev/null @@ -1,119 +0,0 @@ -import { first } from 'lodash-unified' -import type { JsonRpcResponse } from 'web3-core-helpers' -import WalletConnect from '@walletconnect/client' -import type { IJsonRpcRequest } from '@walletconnect/types' -import { ProviderType, ChainId } from '@masknet/web3-shared-evm' -import * as MaskWallet from './MaskWallet' -import { resetAccount, updateAccount } from '../../../../plugins/Wallet/services' -import { currentChainIdSettings, currentProviderSettings } from '../../../../plugins/Wallet/settings' - -let connector: WalletConnect | null = null - -/** - * Create a new connector and destroy the previous one if exists - */ -export async function createConnector() { - if (connector?.connected) return connector - - // create a new connector - connector = new WalletConnect({ - bridge: 'https://uniswap.bridge.walletconnect.org', - clientMeta: { - name: 'Mask Network', - description: 'Mask Network', - url: 'https://mask.io', - icons: ['https://mask.io/apple-touch-icon.png'], - }, - }) - connector.on('connect', onConnect) - connector.on('session_update', onUpdate) - connector.on('disconnect', onDisconnect) - connector.on('error', onDisconnect) - if (!connector.connected) await connector.createSession() - return connector -} - -export async function createConnectorIfNeeded() { - if (connector) return connector - return createConnector() -} - -// #region rpc -export async function signPersonalMessage(data: string, address: string, password: string) { - if (!connector) throw new Error('Connection Lost.') - return (await connector.signPersonalMessage([data, address, password])) as string -} - -export async function signTypedDataMessage(data: string, address: string) { - if (!connector) throw new Error('Connection Lost.') - return (await connector.signTypedData([data, address])) as string -} - -export async function sendCustomRequest(payload: IJsonRpcRequest) { - if (!connector) throw new Error('Connection Lost.') - return (await connector.sendCustomRequest(payload as IJsonRpcRequest)) as JsonRpcResponse -} -// #endregion - -// Wrap promise as PromiEvent because WalletConnect returns transaction hash only -// docs: https://docs.walletconnect.org/client-api -export function createWeb3({ chainId = currentChainIdSettings.value }: { chainId?: ChainId } = {}) { - return MaskWallet.createWeb3({ - chainId, - }) -} -// #endregion - -/** - * Request accounts from WalletConnect - * @param timeout - */ -export async function requestAccounts() { - const connector_ = await createConnectorIfNeeded() - return new Promise<{ accounts: string[]; chainId: ChainId }>(async (resolve, reject) => { - function resolve_() { - resolve({ - accounts: connector_.accounts, - chainId: connector_.chainId, - }) - } - if (connector_.accounts.length) { - resolve_() - return - } - connector_.on('connect', resolve_) - connector_.on('update', resolve_) - connector_.on('error', reject) - }) -} - -const onConnect = () => onUpdate(null) - -const onUpdate = async ( - error: Error | null, - payload?: { - params: Array<{ - chainId: number - accounts: string[] - }> - }, -) => { - if (error) return - if (!connector?.accounts.length) return - if (currentProviderSettings.value !== ProviderType.WalletConnect) return - await updateAccount({ - name: connector.peerMeta?.name, - account: first(connector.accounts), - chainId: connector.chainId, - providerType: ProviderType.WalletConnect, - }) -} - -const onDisconnect = async (error: Error | null) => { - if (connector?.connected) await connector.killSession() - connector = null - if (currentProviderSettings.value !== ProviderType.WalletConnect) return - await resetAccount({ - providerType: ProviderType.WalletConnect, - }) -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/request.ts b/packages/mask/src/extension/background-script/EthereumServices/request.ts deleted file mode 100644 index acaa98c14af6..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/request.ts +++ /dev/null @@ -1,262 +0,0 @@ -import type { RequestArguments, TransactionConfig } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' -import { - EthereumMethodType, - EthereumTransactionConfig, - formatGweiToWei, - formatWeiToGwei, - isEIP1559Supported, - ProviderType, - RequestOptions, - SendOverrides, - TransactionStateType, -} from '@masknet/web3-shared-evm' -import { - currentChainIdSettings, - currentMaskWalletAccountSettings, - currentMaskWalletChainIdSettings, - currentProviderSettings, -} from '../../../plugins/Wallet/settings' -import { WalletRPC } from '../../../plugins/Wallet/messages' -import { INTERNAL_nativeSend, INTERNAL_send } from './send' -import { defer } from '@dimensiondev/kit' -import { hasNativeAPI, nativeAPI } from '../../../../shared/native-rpc' -import { openPopupWindow, removePopupWindow } from '../../../../background/services/helper' -import { toHex } from 'web3-utils' -import { isLessThan } from '@masknet/web3-shared-base' - -let id = 0 - -const UNCONFIRMED_CALLBACK_MAP = new Map void>() -const RISK_METHOD_LIST = [ - EthereumMethodType.ETH_SIGN, - EthereumMethodType.PERSONAL_SIGN, - EthereumMethodType.ETH_SIGN_TYPED_DATA, - EthereumMethodType.ETH_DECRYPT, - EthereumMethodType.ETH_GET_ENCRYPTION_PUBLIC_KEY, - EthereumMethodType.ETH_SEND_TRANSACTION, -] - -function getSendMethod() { - if (hasNativeAPI && nativeAPI) return INTERNAL_nativeSend - return INTERNAL_send -} - -function getPayloadId(payload: JsonRpcPayload) { - return typeof payload.id === 'string' ? Number.parseInt(payload.id, 10) : payload.id -} - -function isRiskMethod(method: EthereumMethodType) { - return RISK_METHOD_LIST.includes(method) -} - -function isSendMethod(method: EthereumMethodType) { - return method === EthereumMethodType.ETH_SEND_TRANSACTION -} - -async function requestSend( - payload: JsonRpcPayload, - callback: (error: Error | null, response?: JsonRpcResponse) => void, - overrides?: SendOverrides, - options?: RequestOptions, -) { - id += 1 - const notifyProgress = isSendMethod(payload.method as EthereumMethodType) - const { providerType = currentProviderSettings.value } = overrides ?? {} - - const chainId = - overrides?.chainId ?? - (providerType === ProviderType.MaskWallet - ? currentMaskWalletChainIdSettings.value - : currentChainIdSettings.value) - - const { popupsWindow = true } = options ?? {} - - const payload_ = { - ...payload, - id, - } - - if (payload_.method === EthereumMethodType.ETH_SEND_TRANSACTION) { - const [config] = payload_.params as [EthereumTransactionConfig] - - // If the default gas config be less than low option, force reset it - if (isEIP1559Supported(chainId)) { - const results = await WalletRPC.getEstimateGasFees(chainId) - - if ( - results?.low?.suggestedMaxFeePerGas && - results?.medium && - (isLessThan( - config?.maxFeePerGas ? formatWeiToGwei(config.maxFeePerGas) : 0, - results.low.suggestedMaxFeePerGas, - ) || - isLessThan( - config?.maxPriorityFeePerGas ? formatWeiToGwei(config.maxPriorityFeePerGas) : 0, - results.low.suggestedMaxPriorityFeePerGas, - )) - ) { - payload_.params![0] = { - ...config, - maxFeePerGas: toHex(formatGweiToWei(results.medium.suggestedMaxFeePerGas).toFixed(0)), - maxPriorityFeePerGas: toHex( - formatGweiToWei(results.medium.suggestedMaxPriorityFeePerGas).toFixed(0), - ), - } - } - } else { - const results = await WalletRPC.getGasPriceDictFromDeBank(chainId) - if (results?.data.slow.price && isLessThan((config?.gasPrice as string) ?? 0, results.data.slow.price)) { - payload_.params![0] = { - ...config, - gasPrice: toHex(results.data.normal.price), - } - } - } - } - - const hijackedCallback = (error: Error | null, response?: JsonRpcResponse) => { - if (error && notifyProgress) - WalletRPC.notifyPayloadProgress(payload_, { - type: TransactionStateType.FAILED, - error, - }) - callback(error, response) - } - - // redirect risk rpc to the mask wallet - if ( - !hasNativeAPI && - providerType === ProviderType.MaskWallet && - isRiskMethod(payload_.method as EthereumMethodType) - ) { - try { - if (notifyProgress) - WalletRPC.addProgress({ - payload: payload_, - state: { - type: TransactionStateType.WAIT_FOR_CONFIRMING, - }, - }) - await WalletRPC.pushUnconfirmedRequest(payload_) - } catch (error) { - hijackedCallback(error instanceof Error ? error : new Error('Failed to add request.')) - return - } - UNCONFIRMED_CALLBACK_MAP.set(payload_.id, hijackedCallback) - if (popupsWindow) openPopupWindow() - return - } - if (notifyProgress) - WalletRPC.addProgress({ - payload, - state: { - type: - providerType === ProviderType.MaskWallet - ? TransactionStateType.UNKNOWN - : TransactionStateType.WAIT_FOR_CONFIRMING, - }, - }) - getSendMethod()(payload_, hijackedCallback, overrides) -} - -export async function request( - requestArguments: RequestArguments, - overrides?: SendOverrides, - options?: RequestOptions, -) { - return new Promise(async (resolve, reject) => { - requestSend( - { - jsonrpc: '2.0', - id, - params: [], - ...requestArguments, - }, - (error, response) => { - if (error || response?.error) reject(error ?? response?.error) - else resolve(response?.result) - }, - overrides, - options, - ) - }) -} - -export async function confirmRequest(payload: JsonRpcPayload, disableClose?: boolean) { - const pid = getPayloadId(payload) - if (!pid) return - const [deferred, resolve, reject] = defer() - getSendMethod()( - payload, - (error, response) => { - UNCONFIRMED_CALLBACK_MAP.get(pid)?.(error, response) - if (error) reject(error) - else if (response?.error) reject(new Error(`Failed to send transaction: ${response.error}`)) - else { - WalletRPC.deleteUnconfirmedRequest(payload) - .then(() => { - if (disableClose) return - return removePopupWindow() - }) - .then(() => { - UNCONFIRMED_CALLBACK_MAP.delete(pid) - }) - resolve(response) - } - }, - { - account: currentMaskWalletAccountSettings.value, - chainId: currentMaskWalletChainIdSettings.value, - providerType: ProviderType.MaskWallet, - }, - ) - return deferred -} - -export async function rejectRequest(payload: JsonRpcPayload) { - const pid = getPayloadId(payload) - if (!pid) return - UNCONFIRMED_CALLBACK_MAP.get(pid)?.(new Error('User rejected!')) - await WalletRPC.deleteUnconfirmedRequest(payload) - await removePopupWindow() - UNCONFIRMED_CALLBACK_MAP.delete(pid) -} - -export async function replaceRequest(hash: string, payload: JsonRpcPayload, overrides?: TransactionConfig) { - const pid = getPayloadId(payload) - if (!pid || payload.method !== EthereumMethodType.ETH_SEND_TRANSACTION) return - - const [config] = payload.params as [TransactionConfig] - return request( - { - method: EthereumMethodType.MASK_REPLACE_TRANSACTION, - params: [ - hash, - { - ...config, - ...overrides, - }, - ], - }, - { - account: currentMaskWalletAccountSettings.value, - chainId: currentMaskWalletChainIdSettings.value, - providerType: ProviderType.MaskWallet, - }, - ) -} - -export async function cancelRequest(hash: string, payload: JsonRpcPayload, overrides?: TransactionConfig) { - const pid = getPayloadId(payload) - if (!pid || payload.method !== EthereumMethodType.ETH_SEND_TRANSACTION) return - - const [config] = payload.params as [TransactionConfig] - return replaceRequest(hash, payload, { - ...config, - ...overrides, - to: config.from as string, - data: '0x', - value: '0x0', - }) -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts b/packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts deleted file mode 100644 index 0bf230349bc6..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/rpc/abi.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { AbiItem } from 'web3-utils' -import * as ABICoder from 'web3-eth-abi' - -// built in abis -import BulkCheckout from '@masknet/web3-contracts/abis/BulkCheckout.json' -import ITO2 from '@masknet/web3-contracts/abis/ITO2.json' -import NftHappyRedPacket from '@masknet/web3-contracts/abis/NftHappyRedPacket.json' -import HappyRedPacketV4 from '@masknet/web3-contracts/abis/HappyRedPacketV4.json' -import ERC20 from '@masknet/web3-contracts/abis/ERC20.json' -import RouterV2ABI from '@masknet/web3-contracts/abis/RouterV2.json' -import SwapRouter from '@masknet/web3-contracts/abis/SwapRouter.json' -import MaskBox from '@masknet/web3-contracts/abis/MaskBox.json' - -// fix the type error -const coder = ABICoder as unknown as ABICoder.AbiCoder - -type InternalItem = { - name: string - parameters: Array<{ - name: string - type: string - }> -} - -const ABI_MAP: Map = new Map() - -export function readABI(sig?: string) { - if (!sig) return - return ABI_MAP.get(sig) -} - -// #region construct built-in abis -function constructABI(abi: AbiItem[]) { - abi.forEach((x) => { - if (x.type !== 'function') return - if (x.stateMutability === 'pure' || x.stateMutability === 'view') return - const { name, inputs = [] } = x - if (!name) return - try { - const sig = coder.encodeFunctionSignature(`${x.name}(${inputs.map((y) => y.type).join(',')})`) - if (ABI_MAP.has(sig)) - console.warn(`The signature of ${`${x.name}(${inputs.map((y) => y.type).join(',')})`} already exists.`) - ABI_MAP.set(sig, { - name, - parameters: - inputs.map((y) => ({ - name: y.name, - type: y.type, - })) ?? [], - }) - } catch (error) { - console.log('Failed to encode function signature from below ABI:') - console.log(x) - } - }) -} - -constructABI(BulkCheckout as AbiItem[]) // donate gitcoin grants -constructABI(ITO2 as AbiItem[]) -constructABI(NftHappyRedPacket as AbiItem[]) -constructABI(HappyRedPacketV4 as AbiItem[]) -constructABI(MaskBox as AbiItem[]) -constructABI(ERC20 as AbiItem[]) -constructABI(RouterV2ABI as AbiItem[]) // uniswap V2 like -constructABI(SwapRouter as AbiItem[]) // uniswap V3 like -// #endregion diff --git a/packages/mask/src/extension/background-script/EthereumServices/rpc/index.ts b/packages/mask/src/extension/background-script/EthereumServices/rpc/index.ts deleted file mode 100644 index a57e7e9851c2..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/rpc/index.ts +++ /dev/null @@ -1,197 +0,0 @@ -import * as ABICoder from 'web3-eth-abi' -import { - isSameAddress, - EthereumRpcComputed, - EthereumRpcType, - EthereumMethodType, - getChainDetailedCAIP, - ZERO_ADDRESS, - isZeroAddress, -} from '@masknet/web3-shared-evm' -import type { TransactionConfig } from 'web3-core' -import type { JsonRpcPayload } from 'web3-core-helpers' -import { getCode } from '../network' -import { readABI } from './abi' -import { isZero } from '@masknet/web3-shared-base' - -// fix the type error -const coder = ABICoder as unknown as ABICoder.AbiCoder - -function isEmptyHex(hex: string) { - return !hex || ['0x', '0x0'].includes(hex) -} - -function getData(tx: TransactionConfig) { - const { data } = tx - if (!data) return - if (isEmptyHex(data)) return - if (!data.startsWith('0x')) return `0x${data}` - return data -} - -function getTo(tx: TransactionConfig) { - const { to } = tx - if (!to) return ZERO_ADDRESS - if (isEmptyHex(to)) return ZERO_ADDRESS - return to -} - -function getFunctionSignature(tx: TransactionConfig) { - const data = getData(tx) - return data?.slice(0, 10) -} - -function getFunctionParameters(tx: TransactionConfig) { - const data = getData(tx) - return data?.slice(10) -} - -export async function getComputedPayload(payload: JsonRpcPayload): Promise { - switch (payload.method) { - // sign - case EthereumMethodType.ETH_SIGN: - case EthereumMethodType.PERSONAL_SIGN: - return { - type: EthereumRpcType.SIGN, - to: payload.params![1], - data: payload.params![0], - } - case EthereumMethodType.ETH_SIGN_TYPED_DATA: - return { - type: EthereumRpcType.SIGN_TYPED_DATA, - to: payload.params![0], - data: payload.params![1], - } - - // decrypt - case EthereumMethodType.ETH_DECRYPT: - return { - type: EthereumRpcType.ETH_DECRYPT, - to: payload.params![1], - secret: payload.params![0], - } - case EthereumMethodType.ETH_GET_ENCRYPTION_PUBLIC_KEY: - return { - type: EthereumRpcType.ETH_GET_ENCRYPTION_PUBLIC_KEY, - account: payload.params![0], - } - - // asset - case EthereumMethodType.WATCH_ASSET: - case EthereumMethodType.WATCH_ASSET_LEGACY: - return { - type: EthereumRpcType.WATCH_ASSET, - asset: payload.params![0], - } - - // wallet - case EthereumMethodType.WALLET_SWITCH_ETHEREUM_CHAIN: - return { - type: EthereumRpcType.WALLET_SWITCH_ETHEREUM_CHAIN, - chain: getChainDetailedCAIP(Number.parseInt(payload.params![0], 16)), - } - case EthereumMethodType.WALLET_ADD_ETHEREUM_CHAIN: - return { - type: EthereumRpcType.WALLET_SWITCH_ETHEREUM_CHAIN, - chain: payload.params![0], - } - - // contract interaction - case EthereumMethodType.ETH_SEND_TRANSACTION: - return getSendTransactionComputedPayload(payload) as Promise - - default: - return - } -} -export function getContractFunctionName(signature: string) { - const abi = readABI(signature) - return abi?.name -} - -export type ComputedPayload = - | undefined - | { - type: EthereumRpcType.CONTRACT_INTERACTION - name?: string - parameters?: Record - _tx: any - } - | { - type: EthereumRpcType.CONTRACT_DEPLOYMENT - code: string - _tx: any - } - | { - type: EthereumRpcType.SEND_ETHER | EthereumRpcType.CANCEL - _tx: any - } -export async function getSendTransactionComputedPayload(payload: JsonRpcPayload): Promise { - const config = - payload.method === EthereumMethodType.MASK_REPLACE_TRANSACTION ? payload.params![1] : payload.params![0] - const from = (config.from as string | undefined) ?? '' - const value = (config.value as string | undefined) ?? '0x0' - const data = getData(config) - const to = getTo(config) - const signature = getFunctionSignature(config) - const parameters = getFunctionParameters(config) - - if (data) { - // contract interaction - const abi = readABI(signature) - - if (abi) { - try { - return { - type: EthereumRpcType.CONTRACT_INTERACTION, - name: abi.name, - parameters: coder.decodeParameters(abi.parameters, parameters ?? ''), - _tx: config, - } - } catch { - // do nothing - } - } - - // contract deployment - if (isZeroAddress(to)) { - return { - type: EthereumRpcType.CONTRACT_DEPLOYMENT, - code: data, - _tx: config, - } - } - } - - if (to) { - let code = '' - try { - code = await getCode(to) - } catch { - code = '' - } - - // cancel tx - if (isSameAddress(from, to) && isZero(value)) { - return { - type: EthereumRpcType.CANCEL, - _tx: config, - } - } - - // send ether - if (isEmptyHex(code)) { - return { - type: EthereumRpcType.SEND_ETHER, - _tx: config, - } - } else { - return { - type: EthereumRpcType.CONTRACT_INTERACTION, - _tx: config, - } - } - } - - return -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/send.ts b/packages/mask/src/extension/background-script/EthereumServices/send.ts deleted file mode 100644 index f13fc170f3b5..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/send.ts +++ /dev/null @@ -1,526 +0,0 @@ -import { EthereumAddress } from 'wallet.ts' -import { toHex } from 'web3-utils' -import type { HttpProvider } from 'web3-core' -import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' -import { toBuffer } from 'ethereumjs-util' -import { safeUnreachable } from '@dimensiondev/kit' -import { - addGasMargin, - ChainId, - EthereumErrorType, - EthereumMethodType, - EthereumRpcType, - isEIP1559Supported, - isSameAddress, - ProviderType, - SendOverrides, - getPayloadHash, - getPayloadConfig, - getPayloadChainId, - getTransactionHash, - isZeroAddress, - getPayloadAccount, -} from '@masknet/web3-shared-evm' -import type { IJsonRpcRequest } from '@walletconnect/types' -import * as MetaMask from './providers/MetaMask' -import * as Injected from './providers/Injected' -import * as WalletConnect from './providers/WalletConnect' -import * as Fortmatic from './providers/Fortmatic' -import { getWallet } from '../../../plugins/Wallet/services' -import { createWeb3 } from './web3' -import { commitNonce, getNonce, resetNonce } from './nonce' -import { - currentAccountSettings, - currentChainIdSettings, - currentProviderSettings, -} from '../../../plugins/Wallet/settings' -import { Flags } from '../../../../shared' -import { nativeAPI } from '../../../../shared/native-rpc' -import { WalletRPC } from '../../../plugins/Wallet/messages' -import { getSendTransactionComputedPayload, ComputedPayload } from './rpc' -import { getError, hasError } from './error' -import { signTypedData, SignTypedDataVersion } from '@metamask/eth-sig-util' - -function isReadOnlyMethod(payload: JsonRpcPayload) { - return [ - EthereumMethodType.ETH_GET_CODE, - EthereumMethodType.ETH_GAS_PRICE, - EthereumMethodType.ETH_BLOCK_NUMBER, - EthereumMethodType.ETH_GET_BALANCE, - EthereumMethodType.ETH_GET_TRANSACTION_BY_HASH, - EthereumMethodType.ETH_GET_TRANSACTION_RECEIPT, - EthereumMethodType.MASK_GET_TRANSACTION_RECEIPT, - EthereumMethodType.ETH_GET_TRANSACTION_COUNT, - EthereumMethodType.ETH_ESTIMATE_GAS, - EthereumMethodType.ETH_CALL, - EthereumMethodType.ETH_GET_LOGS, - ].includes(payload.method as EthereumMethodType) -} - -function isSignableMethod(payload: JsonRpcPayload) { - return [ - EthereumMethodType.ETH_SIGN, - EthereumMethodType.PERSONAL_SIGN, - EthereumMethodType.ETH_SIGN_TRANSACTION, - EthereumMethodType.MASK_REPLACE_TRANSACTION, - EthereumMethodType.ETH_SIGN_TYPED_DATA, - EthereumMethodType.ETH_SEND_TRANSACTION, - ].includes(payload.method as EthereumMethodType) -} - -function getTo(computedPayload: ComputedPayload) { - if (!computedPayload) return '' - switch (computedPayload.type) { - case EthereumRpcType.SEND_ETHER: - return (computedPayload._tx.to as string) ?? '' - case EthereumRpcType.CONTRACT_INTERACTION: - if (['transfer', 'transferFrom'].includes(computedPayload.name ?? '')) - return (computedPayload.parameters?.to as string) ?? '' - } - return '' -} - -async function handleTransferTransaction(chainId: ChainId, payload: JsonRpcPayload) { - if (payload.method !== EthereumMethodType.ETH_SEND_TRANSACTION) return - const computedPayload = await getSendTransactionComputedPayload(payload) - if (!computedPayload) return - - const from = (computedPayload._tx.from as string) ?? '' - const to = getTo(computedPayload) - - if (!isSameAddress(from, to) && !isZeroAddress(to)) await WalletRPC.addAddress(chainId, to) -} - -function handleRecentTransaction( - chainId: ChainId, - account: string, - payload: JsonRpcPayload, - response: JsonRpcResponse | undefined, -) { - const hash = getTransactionHash(response) - if (!hash) return - WalletRPC.watchTransaction(chainId, hash, payload) - WalletRPC.addRecentTransaction(chainId, account, hash, payload) -} - -function handleReplaceRecentTransaction( - chainId: ChainId, - previousHash: string, - account: string, - payload: JsonRpcPayload, - response: JsonRpcResponse | undefined, -) { - const hash = getTransactionHash(response) - if (!hash) return - WalletRPC.watchTransaction(chainId, hash, payload) - WalletRPC.replaceRecentTransaction(chainId, account, previousHash, hash, payload) -} - -async function handleNonce( - chainId: ChainId, - account: string, - error: Error | null, - response: JsonRpcResponse | undefined, -) { - if (chainId !== currentChainIdSettings.value) return - const error_ = (error ?? response?.error) as { message: string } | undefined - const message = error_?.message ?? '' - if (!EthereumAddress.isValid(account)) return - // nonce too low - // nonce too high - // transaction too old - const isGeneralErrorNonce = /\bnonce|transaction\b/im.test(message) && /\b(low|high|old)\b/im.test(message) - const isAuroraErrorNonce = message.includes('ERR_INCORRECT_NONCE') - if (isGeneralErrorNonce || isAuroraErrorNonce) resetNonce(account) - else if (!error_) commitNonce(account) -} - -/** - * This API is only used internally. Please use requestSend instead in order to share the same payload id globally. - * @param payload - * @param callback - * @param sendOverrides - */ -export async function INTERNAL_send( - payload: JsonRpcPayload, - callback: (error: Error | null, response?: JsonRpcResponse) => void, - { - chainId = currentChainIdSettings.value, - account = currentAccountSettings.value, - providerType = currentProviderSettings.value, - }: SendOverrides = {}, -) { - const chainIdFinally = getPayloadChainId(payload) ?? chainId - const accountFinally = getPayloadAccount(payload) ?? account - const wallet = providerType === ProviderType.MaskWallet ? await getWallet(accountFinally) : null - const privKey = isSignableMethod(payload) && wallet ? await WalletRPC.exportPrivateKey(wallet.address) : undefined - const web3 = await createWeb3({ - chainId: chainIdFinally, - privKeys: privKey ? [privKey] : [], - providerType: isReadOnlyMethod(payload) ? ProviderType.MaskWallet : providerType, - }) - const provider = web3.currentProvider as HttpProvider | undefined - - // unable to create provider - if (!provider) { - callback(new Error('Failed to create provider.')) - return - } - - // illegal payload - if (typeof payload.id === 'undefined') { - callback(new Error('Unknown payload id.')) - return - } - - async function personalSign() { - const [data, address] = payload.params as [string, string] - switch (providerType) { - case ProviderType.MaskWallet: - try { - const signed = await web3.eth.sign(data, address) - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: signed, - }) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SIGN_MESSAGE)) - } - break - case ProviderType.MetaMask: - await MetaMask.ensureConnectedAndUnlocked() - provider?.send( - { - ...payload, - params: [data, address, ''], - }, - callback, - ) - break - case ProviderType.WalletConnect: - try { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: await WalletConnect.signPersonalMessage(data, address, ''), - }) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SIGN_MESSAGE)) - } - break - case ProviderType.Coin98: - case ProviderType.WalletLink: - case ProviderType.MathWallet: - try { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: await Injected.createProvider().request({ - method: EthereumMethodType.PERSONAL_SIGN, - params: payload.params, - }), - }) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SIGN_MESSAGE)) - } - break - case ProviderType.Fortmatic: - try { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: await Fortmatic.createProvider().request({ - method: EthereumMethodType.PERSONAL_SIGN, - params: payload.params, - }), - }) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SIGN_MESSAGE)) - } - break - case ProviderType.CustomNetwork: - throw new Error('To be implemented.') - default: - safeUnreachable(providerType) - } - } - - async function typedDataSign() { - const [address, dataToSign] = payload.params as [string, string] - switch (providerType) { - case ProviderType.MaskWallet: - const signed = signTypedData({ - privateKey: toBuffer('0x' + privKey), - data: JSON.parse(dataToSign), - version: SignTypedDataVersion.V4, - }) - try { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: signed, - }) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SIGN_MESSAGE)) - } - break - case ProviderType.WalletConnect: - try { - callback(null, { - jsonrpc: '2.0', - id: payload.id as number, - result: await WalletConnect.signTypedDataMessage(address, dataToSign), - }) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SIGN_MESSAGE)) - } - break - default: - provider?.send(payload, callback) - } - } - - async function sendTransaction() { - const hash = getPayloadHash(payload) - const config = getPayloadConfig(payload) - - if (!config) { - callback(getError(null, null, EthereumErrorType.ERR_SEND_TRANSACTION)) - return - } - - // add nonce - if (providerType === ProviderType.MaskWallet && config.from && !config.nonce) - config.nonce = await getNonce(config.from as string) - - // add gas margin - if (config.gas) config.gas = addGasMargin(config.gas).toString() - config.gas = toHex(config.gas ?? '0') - - // add chain id - if (!config.chainId) config.chainId = chainIdFinally - - // if the transaction is eip-1559, need to remove gasPrice from the config, - if (Flags.EIP1559_enabled && isEIP1559Supported(chainIdFinally)) { - config.gasPrice = undefined - } else { - config.maxFeePerGas = undefined - config.maxPriorityFeePerGas = undefined - } - - // send the transaction - switch (providerType) { - case ProviderType.MaskWallet: - if (!wallet?.storedKeyInfo || !privKey) { - callback(getError(null, null, EthereumErrorType.ERR_SIGN_TRANSACTION)) - return - } - - // send the signed transaction - const signed = await web3.eth.accounts.signTransaction(config, privKey) - if (!signed.rawTransaction) { - callback(getError(null, null, EthereumErrorType.ERR_SIGN_TRANSACTION)) - return - } - - provider?.send( - { - ...payload, - method: EthereumMethodType.ETH_SEND_RAW_TRANSACTION, - params: [signed.rawTransaction], - }, - (error, response) => { - callback( - hasError(error, response) - ? getError(error, response, EthereumErrorType.ERR_SEND_TRANSACTION) - : null, - response, - ) - switch (payload.method) { - case EthereumMethodType.ETH_SEND_TRANSACTION: - handleNonce(chainIdFinally, accountFinally, error, response) - handleTransferTransaction(chainIdFinally, payload) - handleRecentTransaction(chainIdFinally, accountFinally, payload, response) - break - case EthereumMethodType.MASK_REPLACE_TRANSACTION: - handleReplaceRecentTransaction(chainIdFinally, hash, accountFinally, payload, response) - break - } - }, - ) - break - case ProviderType.MetaMask: - try { - await MetaMask.ensureConnectedAndUnlocked() - provider?.send(payload, (error, response) => { - callback( - hasError(error, response) - ? getError(error, response, EthereumErrorType.ERR_SEND_TRANSACTION) - : null, - response, - ) - handleTransferTransaction(chainIdFinally, payload) - handleRecentTransaction(chainIdFinally, accountFinally, payload, response) - }) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SEND_TRANSACTION)) - break - } - break - case ProviderType.WalletConnect: - try { - const response = await WalletConnect.sendCustomRequest(payload as IJsonRpcRequest) - callback(null, response) - handleTransferTransaction(chainIdFinally, payload) - handleRecentTransaction(chainIdFinally, accountFinally, payload, response) - } catch (error) { - callback(getError(error, null, EthereumErrorType.ERR_SEND_TRANSACTION)) - } - break - case ProviderType.Coin98: - case ProviderType.WalletLink: - case ProviderType.MathWallet: - await Injected.ensureConnectedAndUnlocked() - Injected.createProvider().send(payload, (error, response) => { - callback( - hasError(error, response) - ? getError(error, response, EthereumErrorType.ERR_SEND_TRANSACTION) - : null, - response, - ) - handleTransferTransaction(chainIdFinally, payload) - handleRecentTransaction(chainIdFinally, accountFinally, payload, response) - }) - break - case ProviderType.Fortmatic: - Fortmatic.createProvider().send(payload, (error, response) => { - callback( - hasError(error, response) - ? getError(error, response, EthereumErrorType.ERR_SEND_TRANSACTION) - : null, - response, - ) - handleTransferTransaction(chainIdFinally, payload) - handleRecentTransaction(chainIdFinally, accountFinally, payload, response) - }) - break - case ProviderType.CustomNetwork: - throw new Error('To be implemented.') - default: - safeUnreachable(providerType) - } - } - - async function getTransactionReceipt() { - const [hash] = payload.params as [string] - - // redirect receipt queries to tx watcher - const transaction = await WalletRPC.getRecentTransaction(chainIdFinally, accountFinally, hash, { - receipt: true, - }) - - try { - callback(null, { - id: payload.id, - jsonrpc: payload.jsonrpc, - result: transaction?.receipt ?? null, - } as JsonRpcResponse) - } catch { - callback(null, { - id: payload.id, - jsonrpc: payload.jsonrpc, - result: null, - } as JsonRpcResponse) - } - } - - try { - switch (payload.method) { - case EthereumMethodType.ETH_ACCOUNTS: - callback(null, { - id: payload.id, - jsonrpc: payload.jsonrpc, - result: [accountFinally], - } as JsonRpcResponse) - break - case EthereumMethodType.ETH_GET_TRANSACTION_RECEIPT: - await getTransactionReceipt() - break - case EthereumMethodType.PERSONAL_SIGN: - await personalSign() - break - case EthereumMethodType.ETH_SIGN_TYPED_DATA: - await typedDataSign() - break - case EthereumMethodType.ETH_SEND_TRANSACTION: - await sendTransaction() - break - case EthereumMethodType.MASK_GET_TRANSACTION_RECEIPT: - provider.send( - { - ...payload, - method: EthereumMethodType.ETH_GET_TRANSACTION_RECEIPT, - }, - callback, - ) - break - case EthereumMethodType.MASK_REPLACE_TRANSACTION: - if (providerType !== ProviderType.MaskWallet) - throw new Error(`Cannot replace transaction for ${providerType}.`) - await sendTransaction() - break - default: - provider.send(payload, callback) - break - } - } catch (error) { - callback(getError(error, null, 'Failed to send request.')) - } -} - -/** - * This API redirects requests to the native app. - * @param payload - * @param callback - * @param sendOverrides - */ -export async function INTERNAL_nativeSend( - payload: JsonRpcPayload, - callback: (error: Error | null, response?: JsonRpcResponse) => void, - { account = currentAccountSettings.value, chainId = currentChainIdSettings.value }: SendOverrides = {}, -) { - const chainIdFinally = getPayloadChainId(payload) ?? chainId - const accountFinally = getPayloadAccount(payload) ?? account - const config = getPayloadConfig(payload) - if (config && !config.chainId) config.chainId = chainIdFinally - if (payload.method === EthereumMethodType.MASK_GET_TRANSACTION_RECEIPT) - payload.method = EthereumMethodType.ETH_GET_TRANSACTION_RECEIPT - - try { - let response: JsonRpcResponse | undefined - if (nativeAPI?.type === 'Android') { - const jsonResponse = await nativeAPI?.api.sendJsonString(JSON.stringify(payload)) - response = JSON.parse(jsonResponse) - } else { - const _ = await nativeAPI?.api.send(payload) - if (_) { - const { error, ...rest } = _ - response = { ...rest } - if (error) response.error = { message: error } - } - } - callback(null, response) - if (payload.method === EthereumMethodType.ETH_SEND_TRANSACTION) { - handleNonce(chainIdFinally, accountFinally, null, response) - handleTransferTransaction(chainIdFinally, payload) - handleRecentTransaction(chainIdFinally, accountFinally, payload, response) - } - } catch (error) { - if (!(error instanceof Error)) return - callback(error, undefined) - if (payload.method === EthereumMethodType.ETH_SEND_TRANSACTION) { - handleNonce(chainIdFinally, accountFinally, error, undefined) - } - } -} diff --git a/packages/mask/src/extension/background-script/EthereumServices/web3.ts b/packages/mask/src/extension/background-script/EthereumServices/web3.ts deleted file mode 100644 index 7ac048b8e847..000000000000 --- a/packages/mask/src/extension/background-script/EthereumServices/web3.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { ProviderType } from '@masknet/web3-shared-evm' -import { unreachable } from '@dimensiondev/kit' -import * as MaskWallet from './providers/MaskWallet' -import * as MetaMask from './providers/MetaMask' -import * as WalletConnect from './providers/WalletConnect' -import * as Injected from './providers/Injected' -import * as Fortmatic from './providers/Fortmatic' -import { currentChainIdSettings, currentProviderSettings } from '../../../plugins/Wallet/settings' - -export async function createWeb3({ - chainId = currentChainIdSettings.value, - providerType = currentProviderSettings.value, - privKeys = [] as string[], -} = {}) { - switch (providerType) { - case ProviderType.MaskWallet: - return MaskWallet.createWeb3({ - chainId, - privKeys, - }) - case ProviderType.MetaMask: - return MetaMask.createWeb3() - case ProviderType.WalletConnect: - return WalletConnect.createWeb3({ - chainId, - }) - case ProviderType.Coin98: - case ProviderType.WalletLink: - case ProviderType.MathWallet: - return Injected.createWeb3() - case ProviderType.Fortmatic: - return Fortmatic.createWeb3() - case ProviderType.CustomNetwork: - throw new Error('To be implemented.') - default: - unreachable(providerType) - } -} diff --git a/packages/mask/src/extension/background-script/Jobs/StartPluginWorker.ts b/packages/mask/src/extension/background-script/Jobs/StartPluginWorker.ts index 20a108bdcfde..9ad270d96164 100644 --- a/packages/mask/src/extension/background-script/Jobs/StartPluginWorker.ts +++ b/packages/mask/src/extension/background-script/Jobs/StartPluginWorker.ts @@ -1,9 +1,6 @@ import { startPluginWorker, Plugin } from '@masknet/plugin-infra/background-worker' -import { createSubscriptionFromAsync } from '@masknet/shared-base' -import { InMemoryStorages, MaskMessages, PersistentStorages } from '../../../../shared' import { createPluginDatabase } from '../../../../background/database/plugin-db' -import { createPluginHost } from '../../../plugin-infra/host' -import { Services } from '../../service' +import { createPluginHost, createSharedContext } from '../../../plugin-infra/host' export default function (signal: AbortSignal) { startPluginWorker(createPluginHost(signal, createWorkerContext)) } @@ -11,22 +8,10 @@ export default function (signal: AbortSignal) { function createWorkerContext(pluginID: string, signal: AbortSignal): Plugin.Worker.WorkerContext { let storage: Plugin.Worker.DatabaseStorage = undefined! - const currentPersonaSub = createSubscriptionFromAsync( - Services.Settings.getCurrentPersonaIdentifier, - undefined, - MaskMessages.events.currentPersonaIdentifier.on, - signal, - ) return { + ...createSharedContext(pluginID, signal), getDatabaseStorage() { return storage || (storage = createPluginDatabase(pluginID, signal)) }, - createKVStorage(type, defaultValues) { - if (type === 'memory') return InMemoryStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - else return PersistentStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - }, - personaSign: Services.Identity.signWithPersona, - walletSign: Services.Ethereum.personalSign, - currentPersona: currentPersonaSub, } } diff --git a/packages/mask/src/extension/background-script/SettingsService.ts b/packages/mask/src/extension/background-script/SettingsService.ts index 384325828e4c..552e3ec153a4 100644 --- a/packages/mask/src/extension/background-script/SettingsService.ts +++ b/packages/mask/src/extension/background-script/SettingsService.ts @@ -8,18 +8,7 @@ import { currentPluginMinimalModeNOTEnabled, pluginIDSettings, } from '../../settings/settings' -import { currentDataProviderSettings } from '../../plugins/Trader/settings' -import { - currentAccountSettings, - currentNetworkSettings, - currentProviderSettings, - currentChainIdSettings, - currentFungibleAssetDataProviderSettings, - currentNonFungibleAssetDataProviderSettings, - currentGasOptionsSettings, - currentTokenPricesSettings, -} from '../../plugins/Wallet/settings' -import { Flags, MaskMessages } from '../../../shared' +import { MaskMessages } from '../../../shared' import { queryPersonasDB } from '../../../background/database/persona/db' export * from '../../../background/services/settings' @@ -38,28 +27,6 @@ function create(settings: InternalSettings) { export const [getPluginID, setPluginID] = create(pluginIDSettings) export const [getTheme, setTheme] = create(appearanceSettings) export const [getLanguage, setLanguage] = create(languageSettings) -export const [getChainId, setChainId] = create(currentChainIdSettings) -export const [getTokenPrices, setTokenPrices] = create(currentTokenPricesSettings) -export const [getGasOptions, setGasOptions] = create(currentGasOptionsSettings) -export const [getGasPrice, setGasPrice] = create(currentGasOptionsSettings) -export const [getTrendingDataSource, setTrendingDataSource] = create(currentDataProviderSettings) -export const [getCurrentSelectedWalletProvider, setCurrentSelectedWalletProvider] = create(currentProviderSettings) - -export const [getCurrentSelectedWalletNetwork, setCurrentSelectedWalletNetwork] = create(currentNetworkSettings) - -export const [getSelectedWalletAddress, setSelectedWalletAddress] = create(currentAccountSettings) - -export const [getCurrentPortfolioDataProvider, setCurrentPortfolioDataProvider] = create( - currentFungibleAssetDataProviderSettings, -) - -export const [getCurrentCollectibleDataProvider, setCurrentCollectibleDataProvider] = create( - currentNonFungibleAssetDataProviderSettings, -) - -export async function getWalletAllowTestChain() { - return Flags.wallet_allow_testnet -} export async function getCurrentPersonaIdentifier(): Promise { await currentPersonaIdentifier.readyPromise diff --git a/packages/mask/src/extension/dashboard/index.tsx b/packages/mask/src/extension/dashboard/index.tsx index 79aaec76e3bb..1305a375dec4 100644 --- a/packages/mask/src/extension/dashboard/index.tsx +++ b/packages/mask/src/extension/dashboard/index.tsx @@ -1,28 +1,28 @@ // @ts-ignore in case circle dependency make typescript complains import { setService, setPluginMessages, setMessages, setPluginServices, IntegratedDashboard } from '@masknet/dashboard' +import { startPluginDashboard } from '@masknet/plugin-infra/dashboard' import Services from '../service' import { WalletRPC, WalletMessages } from '../../plugins/Wallet/messages' -import { PluginTransakMessages } from '../../plugins/Transak/messages' -import { PluginTraderMessages, PluginTraderRPC } from '../../plugins/Trader/messages' -import { PluginPetMessages } from '../../plugins/Pets/messages' +// import { PluginTransakMessages } from '../../plugins/Transak/messages' +// import { PluginTraderMessages, PluginTraderRPC } from '../../plugins/Trader/messages' +// import { PluginPetMessages } from '../../plugins/Pets/messages' import { MaskMessages } from '../../utils/messages' -import { startPluginDashboard } from '@masknet/plugin-infra/dashboard' -import { createPluginHost } from '../../plugin-infra/host' +import { createPluginHost, createSharedContext } from '../../plugin-infra/host' import type { DashboardPluginMessages, DashboardPluginServices } from '@masknet/shared' import { createNormalReactRoot } from '../../utils/createNormalReactRoot' -import { InMemoryStorages, PersistentStorages } from '../../../shared/kv-storage' import { status } from '../../setup.ui' -import { createSubscriptionFromAsync } from '@masknet/shared-base' +import { PluginTransakMessages } from '../../plugins/Transak/messages' +import { PluginTraderMessages } from '../../plugins/Trader/messages' const msg: DashboardPluginMessages = { Wallet: WalletMessages, Swap: PluginTraderMessages, Transak: PluginTransakMessages, - Pets: PluginPetMessages, + // Pets: PluginPetMessages, } const rpc: DashboardPluginServices = { Wallet: WalletRPC, - Swap: PluginTraderRPC, + // Swap: PluginTraderRPC, } // @ts-ignore To avoid build failure due to the circular project reference setService(Services) @@ -32,23 +32,5 @@ setMessages(MaskMessages) setPluginServices(rpc) // @ts-ignore setPluginMessages(msg) -startPluginDashboard( - createPluginHost(undefined, (pluginID, signal) => { - const currentPersonaSub = createSubscriptionFromAsync( - Services.Settings.getCurrentPersonaIdentifier, - undefined, - MaskMessages.events.currentPersonaIdentifier.on, - signal, - ) - return { - createKVStorage(type, defaultValues) { - if (type === 'memory') return InMemoryStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - else return PersistentStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - }, - personaSign: Services.Identity.signWithPersona, - walletSign: Services.Ethereum.personalSign, - currentPersona: currentPersonaSub, - } - }), -) +startPluginDashboard(createPluginHost(undefined, createSharedContext)) status.then(() => createNormalReactRoot()) diff --git a/packages/mask/src/extension/options-page/DashboardComponents/ActionsBarNFT.tsx b/packages/mask/src/extension/options-page/DashboardComponents/ActionsBarNFT.tsx index c3dae3f12d68..b99f0123ef89 100644 --- a/packages/mask/src/extension/options-page/DashboardComponents/ActionsBarNFT.tsx +++ b/packages/mask/src/extension/options-page/DashboardComponents/ActionsBarNFT.tsx @@ -2,10 +2,12 @@ import { useCallback } from 'react' import { IconButton, MenuItem } from '@mui/material' import { makeStyles, useStylesExtends } from '@masknet/theme' import MoreHorizIcon from '@mui/icons-material/MoreHoriz' -import { Wallet, ERC721TokenDetailed, EthereumTokenType, useChainIdValid } from '@masknet/web3-shared-evm' +import { Wallet, SchemaType, ChainId } from '@masknet/web3-shared-evm' import { useMenu, useI18N } from '../../../utils' import { useModal } from '../DashboardDialogs/Base' import { DashboardWalletHideTokenConfirmDialog, DashboardWalletTransferDialogNFT } from '../DashboardDialogs/Wallet' +import { useChainIdValid } from '@masknet/plugin-infra/web3' +import type { NonFungibleToken } from '@masknet/web3-shared-base' const useStyles = makeStyles()((theme) => ({ more: { @@ -15,7 +17,7 @@ const useStyles = makeStyles()((theme) => ({ export interface ActionsBarNFT_Props extends withClasses<'more'> { wallet: Wallet - token: ERC721TokenDetailed + token: NonFungibleToken } export function ActionsBarNFT(props: ActionsBarNFT_Props) { @@ -29,7 +31,7 @@ export function ActionsBarNFT(props: ActionsBarNFT_Props) { const [transferDialog, , openTransferDialogOpen] = useModal(DashboardWalletTransferDialogNFT) const [hideTokenConfirmDialog, , openHideTokenConfirmDialog] = useModal(DashboardWalletHideTokenConfirmDialog) const [menu, openMenu] = useMenu([ - token.contractDetailed.type === EthereumTokenType.ERC721 ? ( + token.schema === SchemaType.ERC721 ? ( openTransferDialogOpen({ token })}> {t('transfer')} diff --git a/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/CollectibleCard.tsx b/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/CollectibleCard.tsx index 904b03e508ea..41bbf9ac37f7 100644 --- a/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/CollectibleCard.tsx +++ b/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/CollectibleCard.tsx @@ -1,8 +1,9 @@ import { Card, Link, useTheme } from '@mui/material' import { makeStyles } from '@masknet/theme' -import { Wallet, ERC721TokenDetailed, resolveCollectibleLink, NonFungibleAssetProvider } from '@masknet/web3-shared-evm' +import type { Wallet, NonFungibleAssetProvider, ChainId, SchemaType } from '@masknet/web3-shared-evm' import { NFTCardStyledAssetPlayer } from '@masknet/shared' import { ActionsBarNFT } from '../ActionsBarNFT' +import type { NonFungibleToken } from '@masknet/web3-shared-base' const useStyles = makeStyles()((theme) => ({ root: { @@ -56,7 +57,7 @@ const useStyles = makeStyles()((theme) => ({ export interface CollectibleCardProps { provider: NonFungibleAssetProvider wallet?: Wallet - token: ERC721TokenDetailed + token: NonFungibleToken readonly?: boolean renderOrder: number } @@ -66,20 +67,16 @@ export function CollectibleCard(props: CollectibleCardProps) { const { classes } = useStyles() const theme = useTheme() return ( - +
{readonly || !wallet ? null : ( )} ({ collectionWrap: { @@ -33,7 +33,7 @@ const useStyles = makeStyles()((theme) => ({ interface CollectionIconProps { selectedCollection?: string - collection?: ERC721ContractDetailed + collection?: NonFungibleToken onClick?(): void } @@ -49,7 +49,7 @@ export const CollectionIcon = memo(({ collection, onClick, PopperProps={{ disablePortal: true, }} - title={collection.name} + title={collection.metadata?.name ?? ''} arrow> (({ collection, onClick, isSameAddress(collection.address, selectedCollection) ? classes.selected : '', )} onClick={onClick}> - {collection.iconURL ? ( + {collection.collection?.iconURL ? ( ) : ( )} diff --git a/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/index.tsx b/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/index.tsx index 5ce0d2948847..c866f0fcd77b 100644 --- a/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/index.tsx +++ b/packages/mask/src/extension/options-page/DashboardComponents/CollectibleList/index.tsx @@ -1,27 +1,15 @@ -import { createContext, useEffect, useMemo, useState } from 'react' -import { useValueRef } from '@masknet/shared-base-ui' -import { - AddressName, - ChainId, - ERC721ContractDetailed, - ERC721TokenDetailed, - isSameAddress, - NonFungibleAssetProvider, - SocketState, - useCollectibles, - useCollections, - Wallet, -} from '@masknet/web3-shared-evm' -import { Box, Button, Skeleton, Stack, styled, Typography } from '@mui/material' -import { makeStyles, useStylesExtends } from '@masknet/theme' -import { currentNonFungibleAssetDataProviderSettings } from '../../../../plugins/Wallet/settings' -import { useI18N } from '../../../../utils' +import { createContext } from 'react' +import type { IdentityAddress, NonFungibleAsset } from '@masknet/web3-shared-base' +import type { ChainId, NonFungibleAssetProvider, SchemaType, Wallet } from '@masknet/web3-shared-evm' +import { Button, styled, Typography } from '@mui/material' +import { makeStyles } from '@masknet/theme' import { CollectibleCard } from './CollectibleCard' -import { WalletMessages } from '@masknet/plugin-wallet' -import { CollectionIcon } from './CollectionIcon' -import { uniqBy } from 'lodash-unified' -import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' -import { ReversedAddress } from '@masknet/shared' +// import { useI18N } from '../../../../utils' +// import { CollectionIcon } from './CollectionIcon' +// import { uniqBy } from 'lodash-unified' +// import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' +// import { ReversedAddress } from '@masknet/shared' +// import { useNonFungibleAssets } from '@masknet/plugin-infra/web3' export const CollectibleContext = createContext<{ collectiblesRetry: () => void @@ -115,7 +103,7 @@ const useStyles = makeStyles()((theme) => ({ interface CollectibleItemProps { provider: NonFungibleAssetProvider wallet?: Wallet - token: ERC721TokenDetailed + token: NonFungibleAsset readonly?: boolean renderOrder: number } @@ -134,7 +122,7 @@ function CollectibleItem(props: CollectibleItemProps) { />
- {token.info.name} + {token.metadata?.name}
@@ -144,7 +132,7 @@ function CollectibleItem(props: CollectibleItemProps) { interface CollectibleListUIProps extends withClasses<'empty' | 'button' | 'text'> { provider: NonFungibleAssetProvider wallet?: Wallet - collectibles: ERC721TokenDetailed[] + collectibles: Array> loading: boolean collectiblesRetry: () => void error: string | undefined @@ -152,268 +140,277 @@ interface CollectibleListUIProps extends withClasses<'empty' | 'button' | 'text' hasRetry?: boolean } function CollectibleListUI(props: CollectibleListUIProps) { - const { provider, wallet, collectibles, loading, collectiblesRetry, error, readonly, hasRetry = true } = props - const { t } = useI18N() - const classes = useStylesExtends(useStyles(), props) + return null + // const { provider, wallet, collectibles, loading, collectiblesRetry, error, readonly, hasRetry = true } = props + // const { t } = useI18N() + // const classes = useStylesExtends(useStyles(), props) - useEffect(() => WalletMessages.events.erc721TokensUpdated.on(collectiblesRetry)) + // // useEffect(() => WalletMessages.events.erc721TokensUpdated.on(collectiblesRetry)) - return ( - - - {loading && ( - - {Array.from({ length: 3 }) - .fill(0) - .map((_, i) => ( - - - - - ))} - - )} - {error || (collectibles.length === 0 && !loading) ? ( - - {t('dashboard_no_collectible_found')} - {hasRetry ? ( - - ) : null} - - ) : ( - - {collectibles.map((token, index) => ( - - ))} - - )} - - - ) + // return ( + // + // + // {loading && ( + // + // {Array.from({ length: 3 }) + // .fill(0) + // .map((_, i) => ( + // + // + // + // + // ))} + // + // )} + // {error || (collectibles.length === 0 && !loading) ? ( + // + // {t('dashboard_no_collectible_found')} + // {hasRetry ? ( + // + // ) : null} + // + // ) : ( + // + // {collectibles.map((token, index) => ( + // + // ))} + // + // )} + // + // + // ) } export interface CollectibleListProps extends withClasses<'empty' | 'button'> { address: string - collectibles: ERC721TokenDetailed[] + collectibles: Array> error?: string loading: boolean retry(): void } export function CollectibleList(props: CollectibleListProps) { - const { address, collectibles, error, loading, retry } = props - const provider = useValueRef(currentNonFungibleAssetDataProviderSettings) - const classes = props.classes ?? {} + return null + // const { address, collectibles, error, loading, retry } = props + // const classes = props.classes ?? {} - return ( - - ) + // return ( + // + // ) } export function CollectionList({ addressName, onSelectAddress, }: { - addressName: AddressName + addressName: IdentityAddress onSelectAddress: (event: React.MouseEvent) => void }) { - const chainId = ChainId.Mainnet - const { t } = useI18N() - const { classes } = useStyles() - const [selectedCollection, setSelectedCollection] = useState('all') - const { resolvedAddress: address } = addressName + return null + // const chainId = ChainId.Mainnet + // const { t } = useI18N() + // const { classes } = useStyles() + // const [selectedCollection, setSelectedCollection] = useState< + // NonFungibleAsset | 'all' | undefined + // >('all') + // const { address } = addressName - useEffect(() => { - setSelectedCollection('all') - }, [address]) + // useEffect(() => { + // setSelectedCollection('all') + // }, [address]) - const { data: collectionsFormRemote } = useCollections(address, chainId) - const { - data: collectibles, - state: loadingCollectibleDone, - retry: retryFetchCollectible, - } = useCollectibles(address, chainId) + // const { value: collectionsFormRemote } = useNonFungibleAssets(NetworkPluginID.PLUGIN_EVM, SchemaType.ERC721, { + // account: address, + // }) + // const { + // value: collectibles, + // state: loadingCollectibleDone, + // retry: retryFetchCollectible, + // } = useNonFungibleAssets(NetworkPluginID.PLUGIN_EVM, address, chainId) - const isLoading = loadingCollectibleDone !== SocketState.done + // const isLoading = loadingCollectibleDone !== SocketState.done - const renderWithRarible = useMemo(() => { - if (isLoading) return [] - return collectibles.filter((item) => !item.collection) - }, [collectibles?.length]) + // const renderWithRarible = useMemo(() => { + // if (isLoading) return [] + // return collectibles.filter((item) => !item.collection) + // }, [collectibles?.length]) - const renderCollectibles = useMemo(() => { - if (selectedCollection === 'all') return collectibles - if (!selectedCollection) return collectibles.filter((x) => !x.collection) + // const renderCollectibles = useMemo(() => { + // if (selectedCollection === 'all') return collectibles + // if (!selectedCollection) return collectibles.filter((x) => !x.collection) - return (collectibles ?? []).filter((x) => { - return isSameAddress(selectedCollection.address, x.contractDetailed.address) - }) - }, [selectedCollection, collectibles.length]) + // return (collectibles ?? []).filter((x) => { + // return isSameAddress(selectedCollection.address, x.contractDetailed.address) + // }) + // }, [selectedCollection, collectibles.length]) - const collections = useMemo(() => { - return uniqBy( - collectibles.map((x) => x.contractDetailed), - (x) => x.address.toLowerCase(), - ).map((x) => { - const item = collectionsFormRemote.find((c) => isSameAddress(c.address, x.address)) - if (item) { - return { - name: item.name, - symbol: item.name, - baseURI: item.iconURL, - iconURL: item.iconURL, - address: item.address, - } as ERC721ContractDetailed - } - return x - }) - }, [collectibles.length, collectionsFormRemote.length]) + // const collections = useMemo(() => { + // return uniqBy( + // collectibles.map((x) => x.contractDetailed), + // (x) => x.address.toLowerCase(), + // ).map((x) => { + // const item = collectionsFormRemote.find((c) => isSameAddress(c.address, x.address)) + // if (item) { + // return { + // id: item.address, + // chainId: ChainId.Mainnet, + // schema: SchemaType.ERC721, + // name: item.name, + // symbol: item.name, + // logoURL: item.iconURL, + // address: item.address, + // } as NonFungibleTokenContract + // } + // return x + // }) + // }, [collectibles.length, collectionsFormRemote.length]) - if (!isLoading && !collectibles.length) - return ( - <> - {addressName && ( - - - - - - )} - - - {t('dashboard_no_collectible_found')} - - - - ) + // if (!isLoading && !collectibles.length) + // return ( + // <> + // {addressName && ( + // + // + // + // + // + // )} + // + // + // {t('dashboard_no_collectible_found')} + // + // + // + // ) - return ( - - - - setSelectedCollection('all')}> - ALL - - theme.palette.primary.main} fontSize="12px"> - {t('dashboard_collectible_menu_all', { - count: collectibles.length, - })} - - - - - - - - - - {!selectedCollection && selectedCollection !== 'all' && ( - - - Other - {loadingCollectibleDone && renderCollectibles.length - ? `(${renderCollectibles.length})` - : null} - - - )} - {selectedCollection && selectedCollection !== 'all' && ( - - - - {selectedCollection.name} - {loadingCollectibleDone && renderCollectibles.length - ? `(${renderCollectibles.length})` - : null} - - - )} - - - - - {collections.map((x, i) => { - return ( - - setSelectedCollection(x)} - /> - - ) - })} - {!!renderWithRarible.length && ( - - setSelectedCollection(undefined)} - /> - - )} - - - - ) + // return ( + // + // + // + // setSelectedCollection('all')}> + // ALL + // + // theme.palette.primary.main} fontSize="12px"> + // {t('dashboard_collectible_menu_all', { + // count: collectibles.length, + // })} + // + // + // + // + // + // + // + // + // + // {!selectedCollection && selectedCollection !== 'all' && ( + // + // + // Other + // {loadingCollectibleDone && renderCollectibles.length + // ? `(${renderCollectibles.length})` + // : null} + // + // + // )} + // {selectedCollection && selectedCollection !== 'all' && ( + // + // + // + // {selectedCollection.metadata?.name} + // {loadingCollectibleDone && renderCollectibles.length + // ? `(${renderCollectibles.length})` + // : null} + // + // + // )} + // + // + // + // + // {collections.map((x, i) => { + // return ( + // + // setSelectedCollection(x)} + // /> + // + // ) + // })} + // {!!renderWithRarible.length && ( + // + // setSelectedCollection(undefined)} + // /> + // + // )} + // + // + // + // ) } diff --git a/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/HideTokenConfirm.tsx b/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/HideTokenConfirm.tsx index 38a48bd74250..b6776c6e93a2 100644 --- a/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/HideTokenConfirm.tsx +++ b/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/HideTokenConfirm.tsx @@ -1,49 +1,53 @@ import { Trash2 as TrashIcon } from 'react-feather' import { Button, Box, BoxProps } from '@mui/material' -import { unreachable } from '@dimensiondev/kit' -import { - ERC20TokenDetailed, - ERC721TokenDetailed, - EthereumTokenType, - FungibleTokenDetailed, - isNativeTokenAddress, -} from '@masknet/web3-shared-evm' +import { SchemaType, isNativeTokenAddress, ChainId } from '@masknet/web3-shared-evm' import { useSnackbarCallback } from '@masknet/shared' -import { WalletRPC } from '../../../../plugins/Wallet/messages' import { useI18N } from '../../../../utils' import { DebounceButton } from '../../DashboardComponents/ActionButton' import { DashboardDialogCore, DashboardDialogWrapper, WrappedDialogProps } from '../Base' import type { Wallet } from '@masknet/web3-shared-evm' import { makeStyles } from '@masknet/theme' import classNames from 'classnames' +import type { FungibleToken, NonFungibleToken } from '@masknet/web3-shared-base' export function DashboardWalletHideTokenConfirmDialog( - props: WrappedDialogProps<{ wallet: Wallet; token: FungibleTokenDetailed | ERC721TokenDetailed }>, + props: WrappedDialogProps<{ + wallet: Wallet + token: FungibleToken | NonFungibleToken + }>, ) { const { wallet, token } = props.ComponentProps! const { t } = useI18N() const tokenAddress = - (token as FungibleTokenDetailed).address ?? (token as ERC721TokenDetailed).contractDetailed.address - const tokenName = (token as FungibleTokenDetailed).name ?? (token as ERC721TokenDetailed).info.name + (token as FungibleToken).address ?? + (token as NonFungibleToken).contract?.address + const tokenName = + (token as FungibleToken).name ?? + (token as NonFungibleToken).metadata?.name const onConfirm = useSnackbarCallback( - () => { - const type = ((token as FungibleTokenDetailed).type ?? - (token as ERC721TokenDetailed).contractDetailed.type) as - | EthereumTokenType.Native - | EthereumTokenType.ERC20 - | EthereumTokenType.ERC721 - switch (type) { - case EthereumTokenType.Native: - throw new Error('Unable to hide the native token.') - case EthereumTokenType.ERC20: - return WalletRPC.updateWalletToken(wallet.address, token as ERC20TokenDetailed, { - strategy: 'block', - }) - case EthereumTokenType.ERC721: - return WalletRPC.removeToken(token as ERC721TokenDetailed) - default: - unreachable(type) - } + async () => { + return + // const schema = ((token as FungibleToken).schema ?? + // (token as NonFungibleToken).schema) as + // | SchemaType.Native + // | SchemaType.ERC20 + // | SchemaType.ERC721 + // switch (schema) { + // case SchemaType.Native: + // throw new Error('Unable to hide the native token.') + // case SchemaType.ERC20: + // return WalletRPC.updateWalletToken( + // wallet.address, + // token as FungibleToken, + // { + // strategy: 'block', + // }, + // ) + // case SchemaType.ERC721: + // return WalletRPC.removeToken(token as NonFungibleToken) + // default: + // unreachable(schema) + // } }, [wallet.address, token], props.onClose, diff --git a/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/TransferNFT.tsx b/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/TransferNFT.tsx index f6983243d16a..bd504b825864 100644 --- a/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/TransferNFT.tsx +++ b/packages/mask/src/extension/options-page/DashboardDialogs/Wallet/TransferNFT.tsx @@ -1,14 +1,16 @@ -import { useOpenShareTxDialog } from '@masknet/shared' -import { makeStyles } from '@masknet/theme' -import { ERC721TokenDetailed, useTokenTransferCallback } from '@masknet/web3-shared-evm' import { Button, TextField } from '@mui/material' +import { makeStyles } from '@masknet/theme' import { useCallback, useContext, useMemo, useState } from 'react' import { EthereumAddress } from 'wallet.ts' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' +import { useI18N } from '../../../../utils' import { Image } from '../../../../components/shared/Image' import { MaskIconOutlined } from '../../../../resources/MaskIcon' -import { useI18N } from '../../../../utils' import { CollectibleContext } from '../../DashboardComponents/CollectibleList' import { DashboardDialogCore, DashboardDialogWrapper, WrappedDialogProps } from '../Base' +import type { NonFungibleToken } from '@masknet/web3-shared-base' +import { useTokenTransferCallback } from '@masknet/plugin-infra/web3-evm' +import { useOpenShareTxDialog } from '@masknet/shared' const useTransferDialogStylesNFT = makeStyles()((theme) => ({ root: { @@ -24,7 +26,9 @@ const useTransferDialogStylesNFT = makeStyles()((theme) => ({ }, })) -export function DashboardWalletTransferDialogNFT(props: WrappedDialogProps<{ token: ERC721TokenDetailed }>) { +export function DashboardWalletTransferDialogNFT( + props: WrappedDialogProps<{ token: NonFungibleToken }>, +) { const { token } = props.ComponentProps! const { onClose } = props @@ -35,10 +39,7 @@ export function DashboardWalletTransferDialogNFT(props: WrappedDialogProps<{ tok const { collectiblesRetry } = useContext(CollectibleContext) // #region transfer tokens - const [{ loading }, transferCallback] = useTokenTransferCallback( - token.contractDetailed.type, - token.contractDetailed.address, - ) + const [{ loading }, transferCallback] = useTokenTransferCallback(token.schema, token.address) const openShareTxDialog = useOpenShareTxDialog() const onTransfer = useCallback(async () => { @@ -66,13 +67,13 @@ export function DashboardWalletTransferDialogNFT(props: WrappedDialogProps<{ tok ) : ( diff --git a/packages/mask/src/extension/popups/UI.tsx b/packages/mask/src/extension/popups/UI.tsx index 72f0d9e9b5ad..56cbec3aa866 100644 --- a/packages/mask/src/extension/popups/UI.tsx +++ b/packages/mask/src/extension/popups/UI.tsx @@ -5,8 +5,6 @@ import { PopupRoutes } from '@masknet/shared-base' import { usePopupFullPageTheme } from '../../utils/theme/useClassicMaskFullPageTheme' import '../../social-network-adaptor/browser-action' import { PopupContext } from './hook/usePopupContext' -import { Web3Provider } from '@masknet/web3-shared-evm' -import { PopupWeb3Context } from '../../web3/context' import { PopupFrame } from './components/PopupFrame' import { MaskUIRoot } from '../../UIRoot' import { PageTitleContext } from './context' @@ -31,31 +29,29 @@ export default function Popups() { return ( - - - - - - )} /> - )} /> - } /> - } /> - } - /> - } - /> - } /> - - {/* TODO: Should only load plugins when the page is plugin-aware. */} - - - - - + + + + + )} /> + )} /> + } /> + } /> + } + /> + } + /> + } /> + + {/* TODO: Should only load plugins when the page is plugin-aware. */} + + + + ) diff --git a/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx b/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx index 61f2aa5dfe41..90c6d22eea49 100644 --- a/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx +++ b/packages/mask/src/extension/popups/components/NetworkSelector/index.tsx @@ -2,13 +2,20 @@ 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, useChainId } from '@masknet/web3-shared-evm' -import { getRegisteredWeb3Networks, NetworkPluginID, Web3Plugin } from '@masknet/plugin-infra/web3' -import { currentMaskWalletAccountSettings, currentProviderSettings } from '../../../../plugins/Wallet/settings' +import { ChainId, ProviderType, NetworkType } from '@masknet/web3-shared-evm' +import { + getRegisteredWeb3Networks, + useAccount, + useChainId, + Web3Helper, + useWeb3State, + useProviderType, +} from '@masknet/plugin-infra/web3' +import { currentMaskWalletAccountSettings } from '../../../../plugins/Wallet/settings' import { ChainIcon, useMenuConfig, WalletIcon } from '@masknet/shared' -import { useValueRef } from '@masknet/shared-base-ui' import { ArrowDownRound } from '@masknet/icons' import { WalletRPC } from '../../../../plugins/Wallet/messages' +import { NetworkDescriptor, NetworkPluginID } from '@masknet/web3-shared-base' const useStyles = makeStyles()((theme) => ({ root: { @@ -50,16 +57,18 @@ const useStyles = makeStyles()((theme) => ({ })) export const NetworkSelector = memo(() => { - const networks = getRegisteredWeb3Networks() - const account = useAccount() - const chainId = useChainId() - const providerType = useValueRef(currentProviderSettings) + const networks = getRegisteredWeb3Networks().filter( + (x) => x.networkSupporterPluginID === NetworkPluginID.PLUGIN_EVM, + ) as Array> + + const web3State = useWeb3State(NetworkPluginID.PLUGIN_EVM) + const account = useAccount(NetworkPluginID.PLUGIN_EVM) + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const providerType = useProviderType(NetworkPluginID.PLUGIN_EVM) const onChainChange = useCallback( - async (chainId: ChainId) => { + async (chainId: Web3Helper.Definition[NetworkPluginID.PLUGIN_EVM]['ChainId']) => { if (providerType === ProviderType.MaskWallet) { - await WalletRPC.updateAccount({ - chainId, - }) + await web3State.Provider?.connect(chainId, ProviderType.MaskWallet) } return WalletRPC.updateMaskAccount({ chainId, @@ -79,14 +88,13 @@ export const NetworkSelector = memo(() => { }) export interface NetworkSelectorUIProps { - currentNetwork: Web3Plugin.NetworkDescriptor - networks: Web3Plugin.NetworkDescriptor[] + currentNetwork: NetworkDescriptor + networks: Array> onChainChange: (chainId: ChainId) => void } -export const NetworkSelectorUI = memo(({ currentNetwork, onChainChange }) => { +export const NetworkSelectorUI = memo(({ currentNetwork, onChainChange, networks }) => { const { classes } = useStyles() - const networks = getRegisteredWeb3Networks() const [menu, openMenu] = useMenuConfig( networks diff --git a/packages/mask/src/extension/popups/components/WalletStateBar/index.tsx b/packages/mask/src/extension/popups/components/WalletStateBar/index.tsx index a6defa097ebf..166c85d84856 100644 --- a/packages/mask/src/extension/popups/components/WalletStateBar/index.tsx +++ b/packages/mask/src/extension/popups/components/WalletStateBar/index.tsx @@ -2,10 +2,11 @@ import { FC, memo } from 'react' import { LoadingIcon } from '@masknet/icons' import { FormattedAddress, WalletIcon } from '@masknet/shared' import { makeStyles } from '@masknet/theme' -import { NetworkPluginID, useProviderDescriptor, useWeb3State } from '@masknet/plugin-infra/web3' +import { useProviderDescriptor, useWeb3State } from '@masknet/plugin-infra/web3' import { formatEthereumAddress, ProviderType } from '@masknet/web3-shared-evm' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { Box, Stack, StackProps, Typography } from '@mui/material' -import { NetworkSelector } from '../../components/NetworkSelector' +import { NetworkSelector } from '../NetworkSelector' import { useI18N } from '../../../../utils' const useStyles = makeStyles()((theme) => ({ @@ -40,8 +41,8 @@ export const WalletStateBarUI: FC = memo( ({ isPending, walletAddress, walletName, openConnectWalletDialog, children, domain, ...rest }) => { const { t } = useI18N() const { classes } = useStyles() - const { Utils } = useWeb3State() - const providerDescriptor = useProviderDescriptor(ProviderType.MaskWallet, NetworkPluginID.PLUGIN_EVM) + const { Others } = useWeb3State() + const providerDescriptor = useProviderDescriptor(NetworkPluginID.PLUGIN_EVM, ProviderType.MaskWallet) if (!providerDescriptor) return null @@ -72,7 +73,7 @@ export const WalletStateBarUI: FC = memo( {walletName ?? '-'} {domain ? ( - {Utils?.formatDomainName?.(domain)} + {Others?.formatDomainName?.(domain)} ) : null} diff --git a/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/UI.tsx b/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/UI.tsx index 8e532097d390..59c2d0bab29d 100644 --- a/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/UI.tsx +++ b/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/UI.tsx @@ -1,7 +1,7 @@ import { memo, useCallback, useState } from 'react' import { makeStyles } from '@masknet/theme' -import { ChainId, formatEthereumAddress, resolveAddressLinkOnExplorer } from '@masknet/web3-shared-evm' -import { NetworkPluginID, useNetworkDescriptor } from '@masknet/plugin-infra/web3' +import { ChainId, explorerResolver, formatEthereumAddress } from '@masknet/web3-shared-evm' +import { useNetworkDescriptor } from '@masknet/plugin-infra/web3' import { FormattedAddress, ImageIcon } from '@masknet/shared' import { Button, Link, Typography } from '@mui/material' import { CopyIconButton } from '../../../components/CopyIconButton' @@ -9,6 +9,7 @@ import { CircleLoadingIcon, DeleteIcon, EmptyIcon, PopupLinkIcon } from '@maskne import type { ConnectedWalletInfo } from '../type' import { DisconnectWalletDialog } from '../components/DisconnectWalletDialog' import { useI18N } from '../../../../../utils' +import { NetworkPluginID } from '@masknet/web3-shared-base' const useStyles = makeStyles()(() => ({ container: { @@ -122,7 +123,7 @@ export const ConnectedWalletsUI = memo( }, []) // TODO: remove this after next dot id support multiple chain - const networkDescriptor = useNetworkDescriptor(ChainId.Mainnet, NetworkPluginID.PLUGIN_EVM) + const networkDescriptor = useNetworkDescriptor(NetworkPluginID.PLUGIN_EVM, ChainId.Mainnet) if (loading) return ( @@ -152,7 +153,7 @@ export const ConnectedWalletsUI = memo( diff --git a/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/index.tsx b/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/index.tsx index c7ecbc8a9e26..e3bb5ab38390 100644 --- a/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/index.tsx +++ b/packages/mask/src/extension/popups/pages/Personas/ConnectedWallets/index.tsx @@ -3,8 +3,8 @@ import { useTitle } from '../../../hook/useTitle' import { useI18N } from '../../../../../utils' import { ConnectedWalletsUI } from './UI' import { PersonaContext } from '../hooks/usePersonaContext' -import { NetworkPluginID, useChainId, useWallets, useWeb3State } from '@masknet/plugin-infra/web3' -import { isSameAddress } from '@masknet/web3-shared-evm' +import { useChainId, useWallets, useWeb3State } from '@masknet/plugin-infra/web3' +import { isSameAddress, NetworkPluginID } from '@masknet/web3-shared-base' import { NextIDAction, NextIDPlatform, PopupRoutes } from '@masknet/shared-base' import { useAsync, useAsyncFn } from 'react-use' import { compact, sortBy } from 'lodash-unified' @@ -16,7 +16,7 @@ import { useLocation, useNavigate } from 'react-router-dom' const ConnectedWallets = memo(() => { const { t } = useI18N() - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const { NameService } = useWeb3State(NetworkPluginID.PLUGIN_EVM) const wallets = useWallets() const navigate = useNavigate() @@ -32,7 +32,7 @@ const ConnectedWallets = memo(() => { const results = await Promise.all( proofs.map(async (x, index) => { if (x.platform === NextIDPlatform.Ethereum) { - const domain = await NameService?.reverse?.(x.identity) + const domain = await NameService?.reverse?.(chainId, x.identity) if (domain) return { @@ -68,7 +68,7 @@ const ConnectedWallets = memo(() => { return x }) .reverse() - }, [wallets, NameService, proofs]) + }, [wallets, NameService, proofs, chainId]) const [confirmState, onConfirmRelease] = useAsyncFn( async (wallet?: ConnectedWalletInfo) => { diff --git a/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx b/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx index 43bc7b3a90a3..0014cd2b9eaf 100644 --- a/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Personas/VerifyWallet/index.tsx @@ -1,19 +1,11 @@ +import urlcat from 'urlcat' import { memo, useEffect, useMemo } from 'react' import { useAsync, useAsyncFn, useLocation } from 'react-use' import { useNavigate } from 'react-router-dom' import { EMPTY_LIST, NextIDAction, NextIDPlatform, PopupRoutes } from '@masknet/shared-base' import { makeStyles, usePopupCustomSnackbar } from '@masknet/theme' import { NextIDProof } from '@masknet/web3-providers' -import { - ChainId, - EthereumRpcType, - isSameAddress, - NetworkType, - ProviderType, - resolveProviderName, - useWallets, -} from '@masknet/web3-shared-evm' -import type { Web3Plugin } from '@masknet/plugin-infra/dist/web3-types' +import { ChainId, providerResolver, ProviderType } from '@masknet/web3-shared-evm' import { SignSteps, Steps } from '../../../../../components/shared/VerifyWallet/Steps' import Services from '../../../../service' import { PersonaContext } from '../hooks/usePersonaContext' @@ -21,8 +13,8 @@ import { useTitle } from '../../../hook/useTitle' import { useI18N } from '../../../../../utils' import { useUnconfirmedRequest } from '../../Wallet/hooks/useUnConfirmedRequest' import { PopupContext } from '../../../hook/usePopupContext' -import urlcat from 'urlcat' -import { useReverseAddress, useWeb3State } from '@masknet/plugin-infra/web3' +import { Account, isSameAddress, NetworkPluginID } from '@masknet/web3-shared-base' +import { useReverseAddress, useWallets, useWeb3Connection, useWeb3State } from '@masknet/plugin-infra/web3' const useStyles = makeStyles()((theme) => ({ container: { @@ -40,13 +32,18 @@ const VerifyWallet = memo(() => { const { signed, setSigned } = PopupContext.useContainer() const navigate = useNavigate() const location = useLocation() + + const wallet: Account & { + providerType: ProviderType + address?: string + } = location.state.usr + const { showSnackbar } = usePopupCustomSnackbar() const { value: request } = useUnconfirmedRequest() - const wallet: Web3Plugin.ConnectionResult = location.state.usr - const { value: domain } = useReverseAddress(wallet.account) - const { Utils } = useWeb3State() ?? {} - const wallets = useWallets() - + const { Others } = useWeb3State(NetworkPluginID.PLUGIN_EVM) + const wallets = useWallets(NetworkPluginID.PLUGIN_EVM) + const connection = useWeb3Connection(NetworkPluginID.PLUGIN_EVM) + const { value: domain } = useReverseAddress(NetworkPluginID.PLUGIN_EVM, wallet?.account) const { value: bounds } = useAsync(async () => { if (!wallet.account) return EMPTY_LIST return NextIDProof.queryExistedBindingByPlatform(NextIDPlatform.Ethereum, wallet.account) @@ -64,13 +61,14 @@ const VerifyWallet = memo(() => { }, [bounds]) const walletName = () => { - if (domain && Utils?.formatDomainName) return Utils.formatDomainName(domain) - if (wallet.providerType !== ProviderType.MaskWallet) return `${resolveProviderName(wallet.providerType)} Wallet` + if (domain && Others?.formatDomainName) return Others.formatDomainName(domain) + if (wallet.providerType !== ProviderType.MaskWallet) + return `${providerResolver.providerName(wallet.providerType)} Wallet` return wallets.find((x) => isSameAddress(x.address, wallet.account))?.name ?? 'Wallet' } useEffect(() => { - if (request?.computedPayload?.type !== EthereumRpcType.SIGN) return + // if (request?.computedPayload?.type !== EthereumRpcType.SIGN) return navigate(urlcat(PopupRoutes.WalletSignRequest, { goBack: true }), { state: wallet, @@ -107,19 +105,14 @@ const VerifyWallet = memo(() => { const [{ value: walletSignState }, walletSign] = useAsyncFn(async () => { if (!payload || !currentPersona?.identifier.publicKeyAsHex) return false try { - const walletSig = await Services.Ethereum.personalSign( - payload.signPayload, - wallet.account, - '', - { - chainId: wallet.chainId, - account: wallet.account, - providerType: wallet.providerType, - }, - { popupsWindow: false }, - ) + const walletSignature = await connection?.signMessage(payload.signPayload, 'personaSign', { + chainId: wallet.chainId, + account: wallet.account, + providerType: wallet.providerType, + popupsWindow: false, + }) - if (!walletSig) throw new Error('Wallet sign failed') + if (!walletSignature) throw new Error('Wallet sign failed') await NextIDProof.bindProof( payload.uuid, currentPersona.identifier.publicKeyAsHex, @@ -128,7 +121,7 @@ const VerifyWallet = memo(() => { wallet.account, payload.createdAt, { - walletSignature: walletSig, + walletSignature, signature, }, ) @@ -140,10 +133,10 @@ const VerifyWallet = memo(() => { showSnackbar(t('popups_verify_wallet_sign_failed'), { variant: 'error' }) return false } - }, [currentPersona?.identifier.publicKeyAsHex, payload, wallet, signature]) + }, [currentPersona?.identifier.publicKeyAsHex, payload, wallet, signature, connection]) const changeWallet = () => { - navigate(urlcat(PopupRoutes.ConnectWallet, { goBack: true })) + navigate(PopupRoutes.ConnectWallet) } const [{ loading: confirmLoading, value: step = SignSteps.Ready }, handleConfirm] = useAsyncFn(async () => { diff --git a/packages/mask/src/extension/popups/pages/Swap/SwapBox/index.tsx b/packages/mask/src/extension/popups/pages/Swap/SwapBox/index.tsx index 4cc50f93e4d0..d4a0a4b932bd 100644 --- a/packages/mask/src/extension/popups/pages/Swap/SwapBox/index.tsx +++ b/packages/mask/src/extension/popups/pages/Swap/SwapBox/index.tsx @@ -1,15 +1,16 @@ -import { useChainId } from '@masknet/web3-shared-evm' +import { useChainId } from '@masknet/plugin-infra/web3' import { useMemo } from 'react' import { useNavigate, useLocation } from 'react-router-dom' import { useUpdateEffect } from 'react-use' import { Trader } from '../../../../../plugins/Trader/SNSAdaptor/trader/Trader' import type { Coin } from '../../../../../plugins/Trader/types' import { PopupRoutes } from '@masknet/shared-base' +import { NetworkPluginID } from '@masknet/web3-shared-base' export function SwapBox() { const location = useLocation() const navigate = useNavigate() - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const coin = useMemo(() => { if (!location.search) return undefined diff --git a/packages/mask/src/extension/popups/pages/Swap/index.tsx b/packages/mask/src/extension/popups/pages/Swap/index.tsx index 7386a1ab1b48..24a9fa499fd8 100644 --- a/packages/mask/src/extension/popups/pages/Swap/index.tsx +++ b/packages/mask/src/extension/popups/pages/Swap/index.tsx @@ -1,17 +1,15 @@ +import { useCallback } from 'react' import { Appearance, applyMaskColorVars, makeStyles } from '@masknet/theme' -import { TransactionStatusType, useChainId, useWallet, Web3Provider } from '@masknet/web3-shared-evm' import { ThemeProvider, Typography } from '@mui/material' import { SharedContextProvider } from '@masknet/shared' -import { useCallback } from 'react' -import { useRecentTransactions } from '../../../../plugins/Wallet/hooks/useRecentTransactions' +import { TransactionStatusType, NetworkPluginID } from '@masknet/web3-shared-base' import Services from '../../../service' import { WalletStateBarUI } from '../../components/WalletStateBar' import { SwapBox } from './SwapBox' -import { SwapWeb3Context } from '../../../../web3/context' import { PopupRoutes } from '@masknet/shared-base' import { useI18N } from '../../../../utils' import { useSwapPageTheme } from '../../../../utils/theme/useSwapPageTheme' -import { NetworkPluginID, useReverseAddress } from '@masknet/plugin-infra/web3' +import { useChainId, useReverseAddress, useRecentTransactions, useWallet } from '@masknet/plugin-infra/web3' import { TargetChainIdContext } from '../../../../plugins/Trader/trader/useTargetChainIdContext' import { AllProviderTradeContext } from '../../../../plugins/Trader/trader/useAllProviderTradeContext' @@ -68,53 +66,48 @@ const useStyles = makeStyles()((theme) => { export default function SwapPage() { const { t } = useI18N() const { classes } = useStyles() - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const wallet = useWallet(NetworkPluginID.PLUGIN_EVM) const theme = useSwapPageTheme() - const { value: pendingTransactions = [] } = useRecentTransactions({ - status: TransactionStatusType.NOT_DEPEND, - }) - const wallet = useWallet() + const pendingTransactions = useRecentTransactions(NetworkPluginID.PLUGIN_EVM, TransactionStatusType.NOT_DEPEND) const openPopupsWindow = useCallback(() => { Services.Helper.openPopupWindow(PopupRoutes.SelectWallet, { chainId, - internal: true, }) }, [chainId]) - const { value: domain } = useReverseAddress(wallet?.address, NetworkPluginID.PLUGIN_EVM) + const { value: domain } = useReverseAddress(NetworkPluginID.PLUGIN_EVM, wallet?.address) applyMaskColorVars(document.body, Appearance.light) return ( - - - -
-
-
- 0} - openConnectWalletDialog={openPopupsWindow} - walletName={wallet?.name} - domain={domain} - walletAddress={wallet?.address} - /> -
-
- - {t('plugin_trader_swap')} - - - - - - -
-
+ + +
+
+
+ 0} + openConnectWalletDialog={openPopupsWindow} + walletName={wallet?.name} + domain={domain} + walletAddress={wallet?.address} + /> +
+
+ + {t('plugin_trader_swap')} + + + + + + +
- - - +
+
+
) } diff --git a/packages/mask/src/extension/popups/pages/Wallet/AddDeriveWallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/AddDeriveWallet/index.tsx index 27a6eb20d567..33f52c6c8da3 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/AddDeriveWallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/AddDeriveWallet/index.tsx @@ -6,11 +6,12 @@ import { HD_PATH_WITHOUT_INDEX_ETHEREUM } from '@masknet/plugin-wallet' import { useAsync, useAsyncFn } from 'react-use' import { WalletRPC } from '../../../../../plugins/Wallet/messages' import { DeriveWalletTable } from '../components/DeriveWalletTable' -import { currySameAddress, ProviderType, useWallets } from '@masknet/web3-shared-evm' +import { currySameAddress, NetworkPluginID } from '@masknet/web3-shared-base' +import { useWallets } from '@masknet/plugin-infra/web3' import { useI18N } from '../../../../../utils' import { LoadingButton } from '@mui/lab' import { PopupRoutes } from '@masknet/shared-base' -import { currentAccountSettings, currentMaskWalletAccountSettings } from '../../../../../plugins/Wallet/settings' +import { currentMaskWalletAccountSettings } from '../../../../../plugins/Wallet/settings' import { first } from 'lodash-unified' import { useTitle } from '../../../hook/useTitle' @@ -78,7 +79,7 @@ const AddDeriveWallet = memo(() => { const location = useLocation() const state = location.state as any as { mnemonic?: string } | undefined const { classes } = useStyles() - const wallets = useWallets(ProviderType.MaskWallet) + const wallets = useWallets(NetworkPluginID.PLUGIN_EVM) const walletName = new URLSearchParams(location.search).get('name') const { mnemonic } = state || {} @@ -143,12 +144,6 @@ const AddDeriveWallet = memo(() => { account: firstWallet, }) } - if (!currentAccountSettings.value) { - await WalletRPC.updateAccount({ - account: firstWallet, - providerType: ProviderType.MaskWallet, - }) - } } navigate(PopupRoutes.Wallet, { replace: true }) }, [mnemonic, walletName, wallets.length]) diff --git a/packages/mask/src/extension/popups/pages/Wallet/AddToken/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/AddToken/index.tsx index 0b1e207d5c09..3de7f9c1f87a 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/AddToken/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/AddToken/index.tsx @@ -1,8 +1,8 @@ import { memo } from 'react' import { Button, Stack, Typography } from '@mui/material' import { makeStyles } from '@masknet/theme' -import { useWallet } from '@masknet/web3-shared-evm' -import { ERC20TokenList } from '@masknet/shared' +import { FungibleTokenList } from '@masknet/shared' +import { useBlockedFungibleTokens } from '@masknet/plugin-infra/web3' import { useI18N } from '../../../../../utils' import { useNavigate } from 'react-router-dom' import { useTitle } from '../../../hook/useTitle' @@ -40,11 +40,9 @@ const useStyles = makeStyles()({ const AddToken = memo(() => { const { t } = useI18N() - const wallet = useWallet() const { classes } = useStyles() const navigate = useNavigate() - - const excludeTokens = Array.from(wallet?.erc20_token_whitelist ?? []) + const blackList = useBlockedFungibleTokens() useTitle(t('add_token')) @@ -52,7 +50,10 @@ const AddToken = memo(() => { <>
{t('popups_wallet_token')} - + x.address)} + FixedSizeListProps={{ height: 340, itemSize: 54 }} + />
diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/ActivityList/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/ActivityList/index.tsx index 11ed0a8a9d8b..ab3a7672b380 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/ActivityList/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/ActivityList/index.tsx @@ -1,25 +1,17 @@ import urlcat from 'urlcat' -import type { TransactionReceipt } from 'web3-core' import { memo, useState } from 'react' import { useNavigate } from 'react-router-dom' import { makeStyles } from '@masknet/theme' import { useContainer } from 'unstated-next' import { Button, Link, List } from '@mui/material' -import { - ChainId, - EthereumRpcType, - isNativeTokenAddress, - isSameAddress, - resolveTransactionLinkOnExplorer, - useChainId, -} from '@masknet/web3-shared-evm' +import { NetworkPluginID, RecentTransaction } from '@masknet/web3-shared-base' +import type { ChainId, Transaction } from '@masknet/web3-shared-evm' import { PopupRoutes } from '@masknet/shared-base' import { WalletContext } from '../../hooks/useWalletContext' -import type { RecentTransaction } from '../../../../../../plugins/Wallet/services' import { useI18N } from '../../../../../../utils' import { ReplaceType } from '../../type' import { ActivityListItem } from './ActivityListItem' -import type { ComputedPayload } from '../../../../../background-script/EthereumService' +import { useChainId, useWeb3State } from '@masknet/plugin-infra/web3' const useStyles = makeStyles()({ list: { @@ -100,32 +92,25 @@ export interface ActivityListProps { export const ActivityList = memo(({ tokenAddress }) => { const { transactions } = useContainer(WalletContext) + const { Others } = useWeb3State(NetworkPluginID.PLUGIN_EVM) + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) - const dataSource = - transactions?.filter((transaction) => { - if (!tokenAddress) return true - else if (isNativeTokenAddress(tokenAddress)) - return transaction.computedPayload?.type === EthereumRpcType.SEND_ETHER - else if ( - transaction.computedPayload?.type === EthereumRpcType.CONTRACT_INTERACTION && - (transaction.computedPayload?.name === 'transfer' || - transaction.computedPayload?.name === 'transferFrom') - ) { - return isSameAddress(transaction.computedPayload?._tx?.to, tokenAddress) - } - return false - }) ?? [] - - const chainId = useChainId() - return + return ( + + ) }) export interface ActivityListUIProps { - dataSource: RecentTransaction[] + dataSource: Array & { _tx: Transaction }> chainId: ChainId + formatterTransactionLink?: (chainId: ChainId, id: string) => string } -export const ActivityListUI = memo(({ dataSource, chainId }) => { +export const ActivityListUI = memo(({ dataSource, chainId, formatterTransactionLink }) => { const { classes } = useStyles() const { t } = useI18N() const [isExpand, setExpand] = useState(!(dataSource.length > 3)) @@ -138,20 +123,16 @@ export const ActivityListUI = memo(({ dataSource, chainId } <> {dataSource.slice(0, !isExpand ? 3 : undefined).map((transaction, index) => { - const toAddress = getToAddress(transaction.receipt, transaction.computedPayload) return ( { e.preventDefault() setTransaction(transaction) @@ -185,26 +166,3 @@ export const ActivityListUI = memo(({ dataSource, chainId } ) }) - -function getToAddress(receipt?: TransactionReceipt | null, computedPayload?: ComputedPayload | null) { - if (!computedPayload) return undefined - const type = computedPayload.type - switch (type) { - case EthereumRpcType.SEND_ETHER: - return receipt?.to - case EthereumRpcType.CONTRACT_INTERACTION: - switch (computedPayload.name) { - case 'transfer': - case 'transferFrom': - return computedPayload.parameters?.to - case 'approve': - default: - return receipt?.to - } - case EthereumRpcType.CONTRACT_DEPLOYMENT: - return receipt?.to - case EthereumRpcType.CANCEL: - default: - return undefined - } -} diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/AssetsList/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/AssetsList/index.tsx index c6b017372d63..49414ebd395b 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/AssetsList/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/AssetsList/index.tsx @@ -1,7 +1,7 @@ import { memo, useCallback } from 'react' import { useNavigate } from 'react-router-dom' import { useContainer } from 'unstated-next' -import { Asset, formatBalance } from '@masknet/web3-shared-evm' +import type { ChainId, SchemaType } from '@masknet/web3-shared-evm' import { PopupRoutes } from '@masknet/shared-base' import { List, ListItem, ListItemText } from '@mui/material' import { makeStyles } from '@masknet/theme' @@ -9,6 +9,7 @@ import { ArrowRightIcon } from '@masknet/icons' import { TokenIcon, FormattedBalance } from '@masknet/shared' import { WalletContext } from '../../hooks/useWalletContext' import { isNaN } from 'lodash-unified' +import { formatBalance, FungibleAsset } from '@masknet/web3-shared-base' const useStyles = makeStyles()({ list: { @@ -41,6 +42,8 @@ const useStyles = makeStyles()({ }, }) +type Asset = FungibleAsset + export const AssetsList = memo(() => { const navigate = useNavigate() const { assets, setCurrentToken } = useContainer(WalletContext) @@ -65,18 +68,18 @@ export const AssetsListUI = memo(({ dataSource, onItemClick } onItemClick(asset)}> diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx index 0c625ce957aa..9f5c426d2316 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/DeriveWalletTable/index.tsx @@ -14,8 +14,10 @@ import { import { makeStyles } from '@masknet/theme' import { FormattedAddress, FormattedBalance } from '@masknet/shared' import { CheckedBorderIcon, CheckedIcon } from '@masknet/icons' -import { formatBalance, formatEthereumAddress, useWeb3 } from '@masknet/web3-shared-evm' +import { formatEthereumAddress } from '@masknet/web3-shared-evm' import { useI18N } from '../../../../../../utils' +import { useWeb3 } from '@masknet/plugin-infra/web3' +import { formatBalance, NetworkPluginID } from '@masknet/web3-shared-base' const useStyles = makeStyles()({ header: { @@ -104,8 +106,8 @@ export interface DeriveWalletTableRowProps { } export const DeriveWalletTableRow = memo(({ address, added, onCheck, selected }) => { const { classes } = useStyles() - const web3 = useWeb3() - const { loading, value: balance } = useAsync(async () => web3.eth.getBalance(address), [web3, address]) + const web3 = useWeb3(NetworkPluginID.PLUGIN_EVM) + const { loading, value: balance } = useAsync(async () => web3?.eth.getBalance(address) ?? '0', [web3, address]) return ( diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/WalletAssets/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/WalletAssets/index.tsx index 8a2d9ac92a67..c2053f4bccc1 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/WalletAssets/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/WalletAssets/index.tsx @@ -11,7 +11,8 @@ import { useContainer } from 'unstated-next' import { WalletContext } from '../../hooks/useWalletContext' import { LoadingPlaceholder } from '../../../../components/LoadingPlaceholder' import { Navigator } from '../../../../components/Navigator' -import { useWallet } from '@masknet/web3-shared-evm' +import { useWallet } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' const useStyles = makeStyles()({ content: { @@ -75,7 +76,7 @@ enum WalletTabs { export const WalletAssets = memo(() => { const navigate = useNavigate() - const wallet = useWallet() + const wallet = useWallet(NetworkPluginID.PLUGIN_EVM) return wallet ? navigate(PopupRoutes.AddToken)} /> : null }) diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/UI.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/UI.tsx index a5f2cf5e5d73..145581a79350 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/UI.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/UI.tsx @@ -2,10 +2,10 @@ import { makeStyles } from '@masknet/theme' import { memo, MouseEvent } from 'react' import { Box, Link, Typography } from '@mui/material' import { CopyIconButton } from '../../../../components/CopyIconButton' -import type { Web3Plugin } from '@masknet/plugin-infra/web3' import { ChainIcon, FormattedAddress, WalletIcon } from '@masknet/shared' -import { ChainId, Wallet, formatEthereumAddress, resolveAddressLinkOnExplorer } from '@masknet/web3-shared-evm' +import { ChainId, formatEthereumAddress, explorerResolver, NetworkType } from '@masknet/web3-shared-evm' import { ArrowDropIcon, MaskBlueIcon, PopupLinkIcon } from '@masknet/icons' +import type { NetworkDescriptor, Wallet } from '@masknet/web3-shared-base' const useStyles = makeStyles()(() => ({ container: { @@ -77,7 +77,7 @@ const useStyles = makeStyles()(() => ({ }, })) interface WalletHeaderUIProps { - currentNetwork: Web3Plugin.NetworkDescriptor + currentNetwork: NetworkDescriptor chainId: ChainId onOpenNetworkSelector: (event: MouseEvent) => void onActionClick: () => void @@ -133,7 +133,7 @@ export const WalletHeaderUI = memo( event.stopPropagation()} style={{ width: 12, height: 12 }} - href={resolveAddressLinkOnExplorer(chainId, wallet.address ?? '')} + href={explorerResolver.addressLink(chainId, wallet.address ?? '')} target="_blank" rel="noopener noreferrer"> diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/index.tsx index b3418b5fdf25..40fa7127b746 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/WalletHeader/index.tsx @@ -2,16 +2,22 @@ import { memo, useCallback, useMemo } from 'react' import { makeStyles } from '@masknet/theme' import { useMatch, useNavigate } from 'react-router-dom' import { PopupRoutes } from '@masknet/shared-base' -import { ChainId, useChainId, ProviderType, useWallet } from '@masknet/web3-shared-evm' +import type { ChainId, NetworkType } from '@masknet/web3-shared-evm' import { WalletHeaderUI } from './UI' -import { getRegisteredWeb3Networks, NetworkPluginID, useAccount } from '@masknet/plugin-infra/web3' +import { + getRegisteredWeb3Networks, + useAccount, + useChainId, + useProviderType, + useWallet, +} from '@masknet/plugin-infra/web3' import { Flags } from '../../../../../../../shared' import { MenuItem, Typography } from '@mui/material' import { useMenuConfig, WalletIcon, ChainIcon } from '@masknet/shared' -import { currentMaskWalletAccountSettings, currentProviderSettings } from '../../../../../../plugins/Wallet/settings' +import { currentMaskWalletAccountSettings } from '../../../../../../plugins/Wallet/settings' import { WalletRPC } from '../../../../../../plugins/Wallet/messages' -import { useValueRef } from '@masknet/shared-base-ui' import { NormalHeader } from '../../../../components/NormalHeader' +import { NetworkDescriptor, NetworkPluginID } from '@masknet/web3-shared-base' const useStyles = makeStyles()({ menu: { @@ -25,13 +31,16 @@ const useStyles = makeStyles()({ export const WalletHeader = memo(() => { const { classes } = useStyles() - const account = useAccount() - const chainId = useChainId() - const wallet = useWallet() const navigate = useNavigate() - const providerType = useValueRef(currentProviderSettings) + const account = useAccount(NetworkPluginID.PLUGIN_EVM) + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const wallet = useWallet(NetworkPluginID.PLUGIN_EVM) + const providerType = useProviderType(NetworkPluginID.PLUGIN_EVM) + + const networks = getRegisteredWeb3Networks().filter( + (x) => x.networkSupporterPluginID === NetworkPluginID.PLUGIN_EVM, + ) as Array> - const networks = getRegisteredWeb3Networks() const currentNetwork = useMemo( () => networks.find((x) => x.chainId === chainId) ?? networks[0], [networks, chainId], @@ -44,11 +53,6 @@ export const WalletHeader = memo(() => { const onChainChange = useCallback( async (chainId: ChainId) => { - if (providerType === ProviderType.MaskWallet) { - await WalletRPC.updateAccount({ - chainId, - }) - } return WalletRPC.updateMaskAccount({ chainId, account: currentMaskWalletAccountSettings.value, diff --git a/packages/mask/src/extension/popups/pages/Wallet/components/WalletInfo/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/components/WalletInfo/index.tsx index 329a9700a0ad..f244427aba2f 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/components/WalletInfo/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/components/WalletInfo/index.tsx @@ -1,14 +1,15 @@ import { memo } from 'react' +import { useNavigate, useLocation, useMatch } from 'react-router-dom' import { Box, Typography } from '@mui/material' import { makeStyles } from '@masknet/theme' import { MoreHoriz } from '@mui/icons-material' import { EditIcon, MaskWalletIcon } from '@masknet/icons' import { FormattedAddress } from '@masknet/shared' -import { useNavigate, useLocation, useMatch } from 'react-router-dom' import { PopupRoutes } from '@masknet/shared-base' -import { formatEthereumAddress, useWallet } from '@masknet/web3-shared-evm' +import { NetworkPluginID } from '@masknet/web3-shared-base' +import { formatEthereumAddress } from '@masknet/web3-shared-evm' import { CopyIconButton } from '../../../../components/CopyIconButton' -import { NetworkPluginID, useReverseAddress, useWeb3State } from '@masknet/plugin-infra/web3' +import { useReverseAddress, useWallet, useWeb3State } from '@masknet/plugin-infra/web3' const useStyles = makeStyles()({ container: { @@ -64,12 +65,11 @@ const useStyles = makeStyles()({ }) export const WalletInfo = memo(() => { - const wallet = useWallet() + const wallet = useWallet(NetworkPluginID.PLUGIN_EVM) const navigate = useNavigate() const address = new URLSearchParams(useLocation().search).get('address') - - const { value: domain } = useReverseAddress(address ?? wallet?.address, NetworkPluginID.PLUGIN_EVM) - const { Utils } = useWeb3State() + const { value: domain } = useReverseAddress(NetworkPluginID.PLUGIN_EVM, address ?? wallet?.address) + const { Others } = useWeb3State() const excludePath = useMatch(PopupRoutes.WalletSettings) @@ -83,7 +83,7 @@ export const WalletInfo = memo(() => { onSettingClick={() => navigate(PopupRoutes.WalletSettings)} hideSettings={!!excludePath} domain={domain} - formatDomainName={Utils?.formatDomainName} + formatDomainName={Others?.formatDomainName} /> ) }) diff --git a/packages/mask/src/extension/popups/pages/Wallet/hooks/useSetWalletNameForm.ts b/packages/mask/src/extension/popups/pages/Wallet/hooks/useSetWalletNameForm.ts index c688bf612a52..5a46f5770ae8 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/hooks/useSetWalletNameForm.ts +++ b/packages/mask/src/extension/popups/pages/Wallet/hooks/useSetWalletNameForm.ts @@ -1,7 +1,8 @@ import { z as zod } from 'zod' import { useForm, UseFormReturn } from 'react-hook-form' import { zodResolver } from '@hookform/resolvers/zod' -import { useWallets } from '@masknet/web3-shared-evm' +import { useWallets } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' const schema = zod.object({ name: zod.string().min(1).max(12), @@ -9,7 +10,7 @@ const schema = zod.object({ export function useSetWalletNameForm( defaultName?: string, ): UseFormReturn<{ name: string }, object> & { schema: typeof schema } { - const wallets = useWallets() + const wallets = useWallets(NetworkPluginID.PLUGIN_EVM) const formValue = useForm>({ mode: 'onChange', diff --git a/packages/mask/src/extension/popups/pages/Wallet/hooks/useUnConfirmedRequest.ts b/packages/mask/src/extension/popups/pages/Wallet/hooks/useUnConfirmedRequest.ts index e15421ad5f6b..c3f8a2ce4189 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/hooks/useUnConfirmedRequest.ts +++ b/packages/mask/src/extension/popups/pages/Wallet/hooks/useUnConfirmedRequest.ts @@ -1,17 +1,28 @@ import { useAsyncRetry } from 'react-use' import { WalletRPC } from '../../../../../plugins/Wallet/messages' -import Services from '../../../../service' import { useEffect } from 'react' import { WalletMessages } from '@masknet/plugin-wallet' +import { getPayloadConfig } from '@masknet/web3-shared-evm' +import { useChainId, useWeb3State } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' export const useUnconfirmedRequest = () => { + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const { TransactionFormatter } = useWeb3State(NetworkPluginID.PLUGIN_EVM) const result = useAsyncRetry(async () => { const payload = await WalletRPC.topUnconfirmedRequest() if (!payload) return - const computedPayload = await Services.Ethereum.getComputedPayload(payload) + const computedPayload = getPayloadConfig(payload) + + if (!computedPayload) return { payload } + + const formatterTransaction = await TransactionFormatter?.formatTransaction(chainId, computedPayload) + const transactionContext = await TransactionFormatter?.createContext(chainId, computedPayload) return { payload, computedPayload, + formatterTransaction, + transactionContext, } }, []) diff --git a/packages/mask/src/extension/popups/pages/Wallet/hooks/useWalletContext.ts b/packages/mask/src/extension/popups/pages/Wallet/hooks/useWalletContext.ts index f0e2d407ad7c..2b2734684d80 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/hooks/useWalletContext.ts +++ b/packages/mask/src/extension/popups/pages/Wallet/hooks/useWalletContext.ts @@ -1,24 +1,20 @@ import { useState } from 'react' import { createContainer } from 'unstated-next' -import { useAssets, useTrustedERC20Tokens, Asset, useChainDetailed, Wallet } from '@masknet/web3-shared-evm' -import { useRecentTransactions } from '../../../../../plugins/Wallet/hooks/useRecentTransactions' -import type { RecentTransaction } from '../../../../../plugins/Wallet/services' +import { useChainId, useRecentTransactions, useFungibleAssets } from '@masknet/plugin-infra/web3' +import { FungibleAsset, NetworkPluginID, RecentTransaction, Wallet } from '@masknet/web3-shared-base' +import type { ChainId, SchemaType, Transaction } from '@masknet/web3-shared-evm' function useWalletContext() { - const chainDetailed = useChainDetailed() - const erc20Tokens = useTrustedERC20Tokens() - const { value: assets, loading } = useAssets(erc20Tokens) - const { value: transactions } = useRecentTransactions({ - receipt: true, - computedPayload: true, - }) - const [currentToken, setCurrentToken] = useState() - const [transaction, setTransaction] = useState() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const { value: assets, loading } = useFungibleAssets(NetworkPluginID.PLUGIN_EVM) + const transactions = useRecentTransactions(NetworkPluginID.PLUGIN_EVM) + const [currentToken, setCurrentToken] = useState>() + const [transaction, setTransaction] = useState>() const [selectedWallet, setSelectedWallet] = useState() return { currentToken, setCurrentToken, - assets: assets.filter((asset) => asset.token.chainId === chainDetailed?.chainId), + assets: assets?.filter((asset) => asset.chainId === chainId) ?? [], transactions, assetsLoading: loading, transaction, diff --git a/packages/mask/src/extension/popups/pages/Wallet/index.tsx b/packages/mask/src/extension/popups/pages/Wallet/index.tsx index d92e23141335..968c38702f36 100644 --- a/packages/mask/src/extension/popups/pages/Wallet/index.tsx +++ b/packages/mask/src/extension/popups/pages/Wallet/index.tsx @@ -1,5 +1,4 @@ import { WalletStartUp } from './components/StartUp' -import { EthereumRpcType, useWallet } from '@masknet/web3-shared-evm' import { WalletAssets } from './components/WalletAssets' import { Route, Routes, useNavigate, useLocation } from 'react-router-dom' import { lazy, Suspense, useEffect } from 'react' @@ -8,11 +7,14 @@ import { WalletContext } from './hooks/useWalletContext' import { LoadingPlaceholder } from '../../components/LoadingPlaceholder' import { useAsyncRetry } from 'react-use' import { WalletMessages, WalletRPC } from '../../../../plugins/Wallet/messages' -import Services from '../../../service' import SelectWallet from './SelectWallet' import { useWalletLockStatus } from './hooks/useWalletLockStatus' import urlcat from 'urlcat' import { WalletHeader } from './components/WalletHeader' +import { useChainId, useWallet, useWeb3State } from '@masknet/plugin-infra/web3' +import { NetworkPluginID, TransactionDescriptorType } from '@masknet/web3-shared-base' +import { EthereumMethodType, getPayloadConfig } from '@masknet/web3-shared-evm' + const ImportWallet = lazy(() => import('./ImportWallet')) const AddDeriveWallet = lazy(() => import('./AddDeriveWallet')) const WalletSettings = lazy(() => import('./WalletSettings')) @@ -34,14 +36,13 @@ const LegacyWalletRecovery = lazy(() => import('./LegacyWalletRecovery')) const ReplaceTransaction = lazy(() => import('./ReplaceTransaction')) const ConnectWallet = lazy(() => import('./ConnectWallet')) -const exclusionDetectLocked = [PopupRoutes.Unlock, PopupRoutes.ConnectWallet] - const r = relativeRouteOf(PopupRoutes.Wallet) export default function Wallet() { - const wallet = useWallet() + const wallet = useWallet(NetworkPluginID.PLUGIN_EVM) const location = useLocation() const navigate = useNavigate() - + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const { TransactionFormatter } = useWeb3State(NetworkPluginID.PLUGIN_EVM) const { isLocked, loading: getLockStatusLoading } = useWalletLockStatus() const { loading, retry } = useAsyncRetry(async () => { @@ -54,34 +55,36 @@ export default function Wallet() { ].some((item) => item === location.pathname) ) return - const payload = await WalletRPC.topUnconfirmedRequest() if (!payload) return + const computedPayload = getPayloadConfig(payload) + if (!computedPayload) return - const computedPayload = await Services.Ethereum.getComputedPayload(payload) - const value = { - payload, - computedPayload, + const formatterTransaction = await TransactionFormatter?.formatTransaction(chainId, computedPayload) + + if ( + formatterTransaction && + [TransactionDescriptorType.INTERACTION, TransactionDescriptorType.TRANSFER].includes( + formatterTransaction.type, + ) + ) { + navigate(PopupRoutes.ContractInteraction, { replace: true }) } - if (value?.computedPayload) { - switch (value.computedPayload.type) { - case EthereumRpcType.SIGN: - case EthereumRpcType.SIGN_TYPED_DATA: + if (computedPayload) { + switch (payload.method) { + case EthereumMethodType.ETH_SIGN: + case EthereumMethodType.ETH_SIGN_TYPED_DATA: navigate(PopupRoutes.WalletSignRequest, { replace: true }) break - case EthereumRpcType.CONTRACT_INTERACTION: - case EthereumRpcType.SEND_ETHER: - navigate(PopupRoutes.ContractInteraction, { replace: true }) - break default: break } } - }, [location.search, location.pathname]) + }, [location.search, location.pathname, chainId]) useEffect(() => { - if (!(isLocked && !getLockStatusLoading && !exclusionDetectLocked.some((x) => x === location.pathname))) return + if (!(isLocked && !getLockStatusLoading && location.pathname !== PopupRoutes.Unlock)) return navigate(urlcat(PopupRoutes.Unlock, { from: location.pathname }), { replace: true }) }, [isLocked, location.pathname, getLockStatusLoading]) diff --git a/packages/mask/src/extension/popups/render.tsx b/packages/mask/src/extension/popups/render.tsx index 264c7fc796fc..c38758d2a722 100644 --- a/packages/mask/src/extension/popups/render.tsx +++ b/packages/mask/src/extension/popups/render.tsx @@ -1,32 +1,10 @@ import { startPluginDashboard } from '@masknet/plugin-infra/dashboard' -import { createNormalReactRoot, MaskMessages } from '../../utils' -import { createPluginHost } from '../../plugin-infra/host' -import { Services } from '../service' +import { createNormalReactRoot } from '../../utils' +import { createPluginHost, createSharedContext } from '../../plugin-infra/host' import { status } from '../../setup.ui' import Popups from './UI' -import { InMemoryStorages, PersistentStorages } from '../../../shared/kv-storage' -import { createSubscriptionFromAsync } from '@masknet/shared-base' status.then(() => createNormalReactRoot()) // TODO: Should only load plugins when the page is plugin-aware. - -startPluginDashboard( - createPluginHost(undefined, (pluginID, signal) => { - const currentPersonaSub = createSubscriptionFromAsync( - Services.Settings.getCurrentPersonaIdentifier, - undefined, - MaskMessages.events.currentPersonaIdentifier.on, - signal, - ) - return { - createKVStorage(type, defaultValues) { - if (type === 'memory') return InMemoryStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - else return PersistentStorages.Plugin.createSubScope(pluginID, defaultValues, signal) - }, - personaSign: Services.Identity.signWithPersona, - walletSign: Services.Ethereum.personalSign, - currentPersona: currentPersonaSub, - } - }), -) +startPluginDashboard(createPluginHost(undefined, createSharedContext)) diff --git a/packages/mask/src/extension/service.ts b/packages/mask/src/extension/service.ts index 754274da7808..cd748dff8099 100644 --- a/packages/mask/src/extension/service.ts +++ b/packages/mask/src/extension/service.ts @@ -25,7 +25,6 @@ export const Services = { Identity: add(() => import('../../background/services/identity'), 'Identity'), Backup: add(() => import('./background-script/BackupService'), 'Backup'), Helper: add(() => import('../../background/services/helper'), 'Helper'), - Ethereum: add(() => import('./background-script/EthereumService'), 'Ethereum'), SocialNetwork: add(() => import('./background-script/SocialNetworkService'), 'SocialNetwork'), Settings: add(() => import('./background-script/SettingsService'), 'Settings'), ThirdPartyPlugin: add(() => import('./background-script/ThirdPartyPlugin'), 'ThirdPartyPlugin'), @@ -44,7 +43,6 @@ if (process.env.manifest === '2' && import.meta.webpackHot && isEnvironment(Envi '../../background/services/identity', './background-script/BackupService', '../../background/services/helper', - './background-script/EthereumService', './background-script/SettingsService', './background-script/ThirdPartyPlugin', './background-script/SocialNetworkService', diff --git a/packages/mask/src/plugin-infra/host.ts b/packages/mask/src/plugin-infra/host.ts index a2896190c9c5..636505a6f475 100644 --- a/packages/mask/src/plugin-infra/host.ts +++ b/packages/mask/src/plugin-infra/host.ts @@ -1,11 +1,86 @@ // All plugin manager need to call createPluginHost so let's register plugins implicitly. import './register' +import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' import type { Plugin } from '@masknet/plugin-infra' import { Emitter } from '@servie/events' import { MaskMessages } from '../../shared/messages' import Services from '../extension/service' -import { createI18NBundle, i18NextInstance } from '@masknet/shared-base' +import { + createI18NBundle, + createSubscriptionFromAsync, + createSubscriptionFromValueRef, + EMPTY_LIST, + i18NextInstance, +} from '@masknet/shared-base' +import { InMemoryStorages, PersistentStorages } from '../../shared' +import { nativeAPI, hasNativeAPI } from '../../shared/native-rpc' +import { currentMaskWalletAccountSettings, currentMaskWalletChainIdSettings } from '../plugins/Wallet/settings' +import { WalletMessages, WalletRPC } from '../plugins/Wallet/messages' + +export function createSharedContext(pluginID: string, signal: AbortSignal): Plugin.Shared.SharedContext { + return { + createKVStorage(type: 'memory' | 'persistent', name: string, defaultValues: T) { + if (type === 'memory') + return InMemoryStorages.Plugin.createSubScope(`${pluginID}_${name}`, defaultValues, signal) + else return PersistentStorages.Plugin.createSubScope(`${pluginID}_${name}`, defaultValues, signal) + }, + + nativeType: nativeAPI?.type, + hasNativeAPI, + + send: async (payload: JsonRpcPayload) => { + if (nativeAPI?.type === 'iOS') { + return nativeAPI.api.send(payload) as unknown as JsonRpcResponse + } else { + const response = await nativeAPI?.api.sendJsonString(JSON.stringify(payload)) + if (!response) throw new Error('Failed to send request to native APP.') + return JSON.parse(response) as JsonRpcResponse + } + }, + + openPopupWindow: Services.Helper.openPopupWindow, + closePopupWindow: Services.Helper.removePopupWindow, + + account: createSubscriptionFromValueRef(currentMaskWalletAccountSettings), + chainId: createSubscriptionFromValueRef(currentMaskWalletChainIdSettings), + + currentPersona: createSubscriptionFromAsync( + Services.Settings.getCurrentPersonaIdentifier, + undefined, + MaskMessages.events.currentPersonaIdentifier.on, + signal, + ), + + wallets: createSubscriptionFromAsync( + () => WalletRPC.getWallets(), + EMPTY_LIST, + WalletMessages.events.walletsUpdated.on, + ), + walletPrimary: createSubscriptionFromAsync( + () => WalletRPC.getWalletPrimary(), + null, + WalletMessages.events.walletsUpdated.on, + ), + + personaSignMessage: Services.Identity.signWithPersona, + + updateAccount: WalletRPC.updateMaskAccount, + resetAccount: WalletRPC.resetMaskAccount, + selectAccountPrepare: WalletRPC.selectMaskAccountPrepare, + + signTransaction: WalletRPC.signTransaction, + signTypedData: WalletRPC.signTypedData, + signPersonalMessage: WalletRPC.signPersonalMessage, + + addWallet: WalletRPC.updateWallet, + updateWallet: WalletRPC.updateWallet, + removeWallet: WalletRPC.removeWallet, + + shiftUnconfirmedRequest: WalletRPC.shiftUnconfirmedRequest, + pushUnconfirmedRequest: WalletRPC.pushUnconfirmedRequest, + } +} export function createPluginHost( signal: AbortSignal | undefined, diff --git a/packages/mask/src/plugin-infra/register.js b/packages/mask/src/plugin-infra/register.js index 2c38073d8643..4e253d8cae1a 100644 --- a/packages/mask/src/plugin-infra/register.js +++ b/packages/mask/src/plugin-infra/register.js @@ -13,13 +13,13 @@ import '@masknet/plugin-cyberconnect' import '@masknet/plugin-go-plus-security' import '@masknet/plugin-cross-chain-bridge' import '../plugins/Wallet' -import '../plugins/EVM' +import '@masknet/plugin-evm' import '../plugins/RedPacket' import '../plugins/ITO' import '../plugins/Snapshot' import '../plugins/Savings' import '../plugins/Collectible' -import '../plugins/External' +// import '../plugins/External' import '../plugins/Transak' import '../plugins/Gitcoin' import '../plugins/Polls' @@ -33,7 +33,6 @@ import '../plugins/Avatar' import '../plugins/Furucombo' import '../plugins/MaskBox' import '../plugins/NextID' -// import '../plugins/Profile' import '../plugins/Pets' import '../plugins/CryptoartAI' import '../plugins/FindTruman' diff --git a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/Collectible.tsx b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/Collectible.tsx index cf764d336c71..54ac7d765065 100644 --- a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/Collectible.tsx +++ b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/Collectible.tsx @@ -1,15 +1,17 @@ -import { useI18N } from '../../../utils' -import { Tab, Tabs, Paper, Card, CardHeader, CardContent, Link, Typography, Avatar, Box } from '@mui/material' import { useState } from 'react' +import { Tab, Tabs, Paper, Card, CardHeader, CardContent, Link, Typography, Avatar, Box } from '@mui/material' import { makeStyles } from '@masknet/theme' +import { NetworkPluginID } from '@masknet/web3-shared-base' +import { useChainId } from '@masknet/plugin-infra/web3' +import { useI18N } from '../../../utils' import { CollectionView } from './CollectionView' import { DetailsView } from './DetailsView' -import { ChainId, formatWeiToEther, useChainId } from '@masknet/web3-shared-evm' +import { ChainId, formatWeiToEther } from '@masknet/web3-shared-evm' import { useFetchProject } from '../hooks/useProject' import { ActionBar } from './ActionBar' import { resolveProjectLinkOnArtBlocks, resolveUserLinkOnArtBlocks } from '../pipes' import { ArtBlocksLogoUrl } from '../constants' -import { EthereumChainBoundary } from '../../../web3/UI/EthereumChainBoundary' +import { ChainBoundary } from '../../../web3/UI/ChainBoundary' const useStyles = makeStyles()((theme) => { return { @@ -60,7 +62,7 @@ interface CollectibleProps { export function Collectible(props: CollectibleProps) { const { t } = useI18N() const { classes } = useStyles() - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const [tabIndex, setTabIndex] = useState(0) const { value, loading, error } = useFetchProject(props.projectId) @@ -68,7 +70,7 @@ export function Collectible(props: CollectibleProps) { if (loading) return {t('loading')} - if (error || !value) + if (error || !project) return ( {t('plugin_artblocks_smt_wrong')} @@ -132,9 +134,12 @@ export function Collectible(props: CollectibleProps) { - + - + ) diff --git a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/CollectionView.tsx b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/CollectionView.tsx index bb477728ab8e..74456aea4b03 100644 --- a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/CollectionView.tsx +++ b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/CollectionView.tsx @@ -4,7 +4,8 @@ import { useTheme } from '@mui/material/styles' import { MobileStepper, Button, Box, Paper, Typography, Skeleton, Link } from '@mui/material' import { KeyboardArrowLeft, KeyboardArrowRight, OpenInNew } from '@mui/icons-material' import { makeStyles } from '@masknet/theme' -import { useChainId } from '@masknet/web3-shared-evm' +import { useChainId } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { resolveImageLinkOnArtBlocks, resolveTokenLinkOnArtBlocks } from '../pipes' import { buildTokenId } from '../utils' import type { Project } from '../types' @@ -82,7 +83,7 @@ export function CollectionView(props: CollectionProps) { const { project } = props const [isImageLoaded, setImageLoaded] = useState(false) const [activeStep, setActiveStep] = useState(1) - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const currentSelectedToken = { tokenId: buildTokenId(Number(project.projectId), activeStep - 1), diff --git a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/DetailsView.tsx b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/DetailsView.tsx index 8618514b58b2..414584aeb33a 100644 --- a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/DetailsView.tsx +++ b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/DetailsView.tsx @@ -1,12 +1,8 @@ import { FormattedAddress } from '@masknet/shared' import { makeStyles } from '@masknet/theme' -import { - formatEthereumAddress, - formatWeiToEther, - getChainName, - resolveAddressLinkOnExplorer, - useChainId, -} from '@masknet/web3-shared-evm' +import { formatEthereumAddress, formatWeiToEther, chainResolver, explorerResolver } from '@masknet/web3-shared-evm' +import { useChainId, useWeb3State } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { OpenInNew } from '@mui/icons-material' import { Typography, Box, Link } from '@mui/material' import BigNumber from 'bignumber.js' @@ -60,7 +56,8 @@ export function DetailsView(props: DetailsViewProps) { const { classes } = useStyles() const { project } = props const { t } = useI18N() - const chainId = useChainId() as number + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + const { Others } = useWeb3State(NetworkPluginID.PLUGIN_EVM) const artistName = ` ${project.artistName}` const invocations = `${project.invocations} of ${project.maxInvocations}` @@ -130,12 +127,12 @@ export function DetailsView(props: DetailsViewProps) { {t('plugin_artblocks_blockchain_row')} - {getChainName(chainId)} + {chainResolver.chainName(chainId)} {t('plugin_artblocks_contract_row')} diff --git a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx index 21fa65afa4b9..0aaf83acab0f 100644 --- a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx +++ b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx @@ -1,13 +1,9 @@ +import { useCallback, useMemo, useState } from 'react' +import { Trans } from 'react-i18next' import { InjectedDialog, TokenAmountPanel, useOpenShareTxDialog, useShowConfirm } from '@masknet/shared' import { makeStyles } from '@masknet/theme' -import { leftShift } from '@masknet/web3-shared-base' -import { - ERC20TokenDetailed, - EthereumTokenType, - FungibleTokenDetailed, - useArtBlocksConstants, - useFungibleTokenWatched, -} from '@masknet/web3-shared-evm' +import { FungibleToken, leftShift, NetworkPluginID } from '@masknet/web3-shared-base' +import { SchemaType, useArtBlocksConstants, ChainId } from '@masknet/web3-shared-evm' import { Card, CardActions, @@ -18,16 +14,15 @@ import { Link, Typography, } from '@mui/material' -import { useCallback, useMemo, useState } from 'react' -import { Trans } from 'react-i18next' -import { usePostLink } from '../../../components/DataSource/usePostInfo' import ActionButton from '../../../extension/options-page/DashboardComponents/ActionButton' +import { WalletConnectedBoundary } from '../../../web3/UI/WalletConnectedBoundary' +import { useFungibleTokenWatched } from '@masknet/plugin-infra/web3' +import { usePostLink } from '../../../components/DataSource/usePostInfo' import { activatedSocialNetworkUI } from '../../../social-network' import { isFacebook } from '../../../social-network-adaptor/facebook.com/base' import { isTwitter } from '../../../social-network-adaptor/twitter.com/base' import { useI18N } from '../../../utils' import { EthereumERC20TokenApprovedBoundary } from '../../../web3/UI/EthereumERC20TokenApprovedBoundary' -import { EthereumWalletConnectedBoundary } from '../../../web3/UI/EthereumWalletConnectedBoundary' import { usePurchaseCallback } from '../hooks/usePurchaseCallback' import type { Project } from '../types' @@ -58,23 +53,23 @@ export function PurchaseDialog(props: ActionBarProps) { const { classes } = useStyles() const { project, open, onClose } = props - const { token, balance } = useFungibleTokenWatched({ - type: project.currencySymbol === 'ETH' || !project.currencySymbol ? 0 : 1, - address: project.currencyAddress ? project.currencyAddress : '', - }) + const { token, balance } = useFungibleTokenWatched( + NetworkPluginID.PLUGIN_EVM, + project.currencyAddress ? project.currencyAddress : '', + ) const [ToS_Checked, setToS_Checked] = useState(false) const [{ loading: isPurchasing }, purchaseCallback] = usePurchaseCallback( project.projectId, project.pricePerTokenInWei, - token.value?.type, + token.value?.schema, ) const price = useMemo( () => leftShift(project.pricePerTokenInWei, token.value?.decimals), [project.pricePerTokenInWei, token.value?.decimals], ) - const postLink = usePostLink() + const shareText = [ t( isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) @@ -142,7 +137,7 @@ export function PurchaseDialog(props: ActionBarProps) { label={t('plugin_artblocks_price_per_mint')} amount={price.toString()} balance={balance.value ?? '0'} - token={token.value as FungibleTokenDetailed} + token={token.value as FungibleToken} onAmountChange={() => {}} /> - - {token.value?.type === EthereumTokenType.Native ? actionButton : null} - {token.value?.type === EthereumTokenType.ERC20 ? ( + + {token.value?.schema === SchemaType.Native ? actionButton : null} + {token.value?.schema === SchemaType.ERC20 ? ( + token={token.value}> {actionButton} ) : null} - + diff --git a/packages/mask/src/plugins/ArtBlocks/hooks/useArtBlocksContract.ts b/packages/mask/src/plugins/ArtBlocks/hooks/useArtBlocksContract.ts index 3f75f28411fa..f65d9d2581ec 100644 --- a/packages/mask/src/plugins/ArtBlocks/hooks/useArtBlocksContract.ts +++ b/packages/mask/src/plugins/ArtBlocks/hooks/useArtBlocksContract.ts @@ -1,14 +1,14 @@ import type { AbiItem } from 'web3-utils' -import { useContract, useArtBlocksConstants } from '@masknet/web3-shared-evm' +import { useContract } from '@masknet/plugin-infra/web3-evm' +import { useArtBlocksConstants } from '@masknet/web3-shared-evm' import ArtBlocksCoreContractABI from '@masknet/web3-contracts/abis/ArtBlocksMinterContract.json' import type { ArtBlocksMinterContract } from '@masknet/web3-contracts/types/ArtBlocksMinterContract' +import { useChainId } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' export function useArtBlocksContract() { const { GEN_ART_721_MINTER } = useArtBlocksConstants() - const genArt721MinterContract = useContract( - GEN_ART_721_MINTER, - ArtBlocksCoreContractABI as AbiItem[], - ) - return genArt721MinterContract + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) + return useContract(chainId, GEN_ART_721_MINTER, ArtBlocksCoreContractABI as AbiItem[]) } diff --git a/packages/mask/src/plugins/ArtBlocks/hooks/useProject.ts b/packages/mask/src/plugins/ArtBlocks/hooks/useProject.ts index bf833669a492..07f314f76ef2 100644 --- a/packages/mask/src/plugins/ArtBlocks/hooks/useProject.ts +++ b/packages/mask/src/plugins/ArtBlocks/hooks/useProject.ts @@ -1,11 +1,12 @@ +import { NetworkPluginID } from '@masknet/web3-shared-base' import { fetchProject } from '../apis' -import { useAsync } from 'react-use' -import { useChainId } from '@masknet/web3-shared-evm' +import { useAsyncRetry } from 'react-use' +import { useChainId } from '@masknet/plugin-infra/web3' export function useFetchProject(projectId: string) { - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) - return useAsync(async () => { + return useAsyncRetry(async () => { if (!projectId) return null return fetchProject(chainId, projectId) diff --git a/packages/mask/src/plugins/ArtBlocks/hooks/usePurchaseCallback.ts b/packages/mask/src/plugins/ArtBlocks/hooks/usePurchaseCallback.ts index 77dd05ef5df4..42bd8fed4fd5 100644 --- a/packages/mask/src/plugins/ArtBlocks/hooks/usePurchaseCallback.ts +++ b/packages/mask/src/plugins/ArtBlocks/hooks/usePurchaseCallback.ts @@ -1,19 +1,21 @@ +import { useAccount, useChainId } from '@masknet/plugin-infra/web3' import type { PayableTx } from '@masknet/web3-contracts/types/types' -import { EthereumTokenType, TransactionEventType, useAccount, useChainId } from '@masknet/web3-shared-evm' +import { NetworkPluginID } from '@masknet/web3-shared-base' +import { SchemaType, TransactionEventType } from '@masknet/web3-shared-evm' import BigNumber from 'bignumber.js' import { useAsyncFn } from 'react-use' import { useArtBlocksContract } from './useArtBlocksContract' -export function usePurchaseCallback(projectId: string, amount: string, tokenType?: number) { - const account = useAccount() - const chainId = useChainId() +export function usePurchaseCallback(projectId: string, amount: string, schema?: SchemaType) { + const account = useAccount(NetworkPluginID.PLUGIN_EVM) + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const genArt721MinterContract = useArtBlocksContract() return useAsyncFn(async () => { if (!genArt721MinterContract) return - const value = new BigNumber(tokenType === EthereumTokenType.Native ? amount : 0).toFixed() + const value = new BigNumber(schema === SchemaType.Native ? amount : 0).toFixed() const config = { from: account, value, @@ -40,5 +42,5 @@ export function usePurchaseCallback(projectId: string, amount: string, tokenType reject(error) }) }) - }, [account, amount, chainId, genArt721MinterContract, tokenType]) + }, [account, amount, chainId, genArt721MinterContract]) } diff --git a/packages/mask/src/plugins/ArtBlocks/hooks/useToken.ts b/packages/mask/src/plugins/ArtBlocks/hooks/useToken.ts index 7dc92e4cafbf..23333706533c 100644 --- a/packages/mask/src/plugins/ArtBlocks/hooks/useToken.ts +++ b/packages/mask/src/plugins/ArtBlocks/hooks/useToken.ts @@ -1,11 +1,12 @@ +import { useAsyncRetry } from 'react-use' +import { useChainId } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' import { fetchToken } from '../apis' -import { useAsync } from 'react-use' -import { useChainId } from '@masknet/web3-shared-evm' export function useFetchToken(tokenId: number) { - const chainId = useChainId() + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) - return useAsync(async () => { + return useAsyncRetry(async () => { if (!tokenId) return null return fetchToken(chainId, tokenId) diff --git a/packages/mask/src/plugins/ArtBlocks/pipes/index.ts b/packages/mask/src/plugins/ArtBlocks/pipes/index.ts index 0d5423f3771d..55ff9ad0bb0e 100644 --- a/packages/mask/src/plugins/ArtBlocks/pipes/index.ts +++ b/packages/mask/src/plugins/ArtBlocks/pipes/index.ts @@ -1,4 +1,5 @@ -import { ChainId, createLookupTableResolver } from '@masknet/web3-shared-evm' +import { ChainId } from '@masknet/web3-shared-evm' +import { createLookupTableResolver } from '@masknet/web3-shared-base' import urlcat from 'urlcat' import { ArtBlocksRopstenUrl, diff --git a/packages/mask/src/plugins/Avatar/Application/NFTAvatarsDialog.tsx b/packages/mask/src/plugins/Avatar/Application/NFTAvatarsDialog.tsx index d76817e316b6..3c2ef4a3cb51 100644 --- a/packages/mask/src/plugins/Avatar/Application/NFTAvatarsDialog.tsx +++ b/packages/mask/src/plugins/Avatar/Application/NFTAvatarsDialog.tsx @@ -7,7 +7,7 @@ import type { SelectTokenInfo, TokenInfo } from '../types' import { PersonaPage } from './PersonaPage' import { DialogContent } from '@mui/material' import { useI18N } from '../locales/i18n_generated' -import { isSameAddress } from '@masknet/web3-shared-evm' +import { isSameAddress } from '@masknet/web3-shared-base' import { makeStyles } from '@masknet/theme' const useStyles = makeStyles()((theme) => ({ diff --git a/packages/mask/src/plugins/Avatar/Application/NFTList.tsx b/packages/mask/src/plugins/Avatar/Application/NFTList.tsx index eb9615527ce4..35ab6e8e0167 100644 --- a/packages/mask/src/plugins/Avatar/Application/NFTList.tsx +++ b/packages/mask/src/plugins/Avatar/Application/NFTList.tsx @@ -1,5 +1,6 @@ import { makeStyles, useTabs } from '@masknet/theme' -import { ChainId, ERC721TokenDetailed } from '@masknet/web3-shared-evm' +import type { NonFungibleToken } from '@masknet/web3-shared-base' +import { ChainId, SchemaType } from '@masknet/web3-shared-evm' import { TabContext, TabPanel } from '@mui/lab' import { Tab, Tabs, Typography } from '@mui/material' import { Application_NFT_LIST_PAGE, SUPPORTED_CHAIN_IDS } from '../constants' @@ -33,9 +34,9 @@ const useStyles = makeStyles<{ currentTab: Application_NFT_LIST_PAGE }>()((theme interface NFTListProps { address: string tokenInfo?: TokenInfo - onSelect: (token: ERC721TokenDetailed) => void + onSelect: (token: NonFungibleToken) => void onChangePage?: (page: Application_NFT_LIST_PAGE) => void - tokens?: ERC721TokenDetailed[] + tokens?: Array> children?: React.ReactElement } @@ -89,7 +90,7 @@ export function NFTList(props: NFTListProps) { {SUPPORTED_CHAIN_IDS.map((x, i) => ( y.contractDetailed.chainId === x) ?? []} + tokens={tokens.filter((y) => y.chainId === x) ?? []} tokenInfo={tokenInfo} chainId={x} address={address} diff --git a/packages/mask/src/plugins/Avatar/Application/NFTListDialog.tsx b/packages/mask/src/plugins/Avatar/Application/NFTListDialog.tsx index 1488f4fc3deb..e0eef7044b40 100644 --- a/packages/mask/src/plugins/Avatar/Application/NFTListDialog.tsx +++ b/packages/mask/src/plugins/Avatar/Application/NFTListDialog.tsx @@ -1,5 +1,7 @@ import { makeStyles, useCustomSnackbar } from '@masknet/theme' -import { ChainId, ERC721TokenDetailed, isSameAddress, SocketState, useCollectibles } from '@masknet/web3-shared-evm' +import { ChainId, SchemaType } from '@masknet/web3-shared-evm' +import { isSameAddress, NetworkPluginID, NonFungibleToken } from '@masknet/web3-shared-base' +import { useCollectibles } from '../hooks/useCollectibles' import { Box, Button, DialogActions, DialogContent, Skeleton, Stack, Typography } from '@mui/material' import { useCallback, useState, useEffect } from 'react' import { downloadUrl } from '../../../utils' @@ -11,7 +13,7 @@ import { Translate, useI18N } from '../locales' import { AddressNames } from './WalletList' import { NFTList } from './NFTList' import { Application_NFT_LIST_PAGE } from '../constants' -import { NetworkPluginID, useAccount, useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' +import { useChainId, useAccount, useCurrentWeb3NetworkPluginID } from '@masknet/plugin-infra/web3' import { NFTWalletConnect } from './WalletConnect' const useStyles = makeStyles()((theme) => ({ @@ -73,9 +75,9 @@ const useStyles = makeStyles()((theme) => ({ }, })) -function isSameToken(token?: ERC721TokenDetailed, tokenInfo?: TokenInfo) { +function isSameToken(token?: NonFungibleToken, tokenInfo?: TokenInfo) { if (!token && !tokenInfo) return false - return isSameAddress(token?.contractDetailed.address, tokenInfo?.address) && token?.tokenId === tokenInfo?.tokenId + return isSameAddress(token?.address, tokenInfo?.address) && token?.tokenId === tokenInfo?.tokenId } interface NFTListDialogProps { onNext: () => void @@ -87,14 +89,14 @@ interface NFTListDialogProps { export function NFTListDialog(props: NFTListDialogProps) { const { onNext, wallets, onSelected, tokenInfo } = props const { classes } = useStyles() - - const account = useAccount() + const account = useAccount(NetworkPluginID.PLUGIN_EVM) + const chainId = useChainId(NetworkPluginID.PLUGIN_EVM) const [open_, setOpen_] = useState(false) const [selectedAccount, setSelectedAccount] = useState('') - const [selectedToken, setSelectedToken] = useState() + const [selectedToken, setSelectedToken] = useState>() const [disabled, setDisabled] = useState(false) const t = useI18N() - const [tokens, setTokens] = useState([]) + const [tokens, setTokens] = useState>>([]) const [currentPage, setCurrentPage] = useState( Application_NFT_LIST_PAGE.Application_nft_tab_eth_page, ) @@ -102,27 +104,22 @@ export function NFTListDialog(props: NFTListDialogProps) { const POLYGON_PAGE = Application_NFT_LIST_PAGE.Application_nft_tab_polygon_page const currentPluginId = useCurrentWeb3NetworkPluginID() - const { - data: collectibles, - error, - retry, - state, - } = useCollectibles(selectedAccount, currentPage !== POLYGON_PAGE ? ChainId.Mainnet : ChainId.Matic) + const { collectibles, retry, error, loading } = useCollectibles() const { showSnackbar } = useCustomSnackbar() const onChange = useCallback((address: string) => { setSelectedAccount(address) }, []) - const onSelect = (token: ERC721TokenDetailed) => { + const onSelect = (token: NonFungibleToken) => { setSelectedToken(token) } const onSave = useCallback(async () => { - if (!selectedToken?.info?.imageURL) return + if (!selectedToken?.metadata?.imageURL) return setDisabled(true) try { - const image = await downloadUrl(selectedToken.info.imageURL) + const image = await downloadUrl(selectedToken.metadata.imageURL) onSelected({ image: URL.createObjectURL(image), account: selectedAccount, token: selectedToken }) onNext() setDisabled(false) @@ -146,8 +143,8 @@ export function NFTListDialog(props: NFTListDialogProps) { useEffect(() => setSelectedAccount(account || wallets?.[0]?.identity || ''), [account, wallets]) - const onAddClick = (token: ERC721TokenDetailed) => { - setTokens((_tokens) => uniqBy([..._tokens, token], (x) => x.contractDetailed.address && x.tokenId)) + const onAddClick = (token: NonFungibleToken) => { + setTokens((_tokens) => uniqBy([..._tokens, token], (x) => x.contract?.address && x.tokenId)) } const onChangePage = (name: Application_NFT_LIST_PAGE) => { @@ -206,7 +203,7 @@ export function NFTListDialog(props: NFTListDialogProps) { const NoNFTList = () => { if (currentPage === POLYGON_PAGE && tokens.length === 0) return AddCollectible else if (currentPage === POLYGON_PAGE && tokens.length) return - if (state !== SocketState.done) { + if (loading) { return LoadStatus } if (error) { @@ -241,7 +238,7 @@ export function NFTListDialog(props: NFTListDialogProps) { address={selectedAccount} onSelect={onSelect} onChangePage={onChangePage} - tokens={uniqBy([...tokens, ...collectibles], (x) => x.contractDetailed.address && x.tokenId)} + tokens={uniqBy([...tokens, ...collectibles], (x) => x.contract?.address && x.id)} children={NoNFTList()} /> )} diff --git a/packages/mask/src/plugins/Avatar/Application/NFTListPage.tsx b/packages/mask/src/plugins/Avatar/Application/NFTListPage.tsx index 065ead46a817..d8afc8b3dd32 100644 --- a/packages/mask/src/plugins/Avatar/Application/NFTListPage.tsx +++ b/packages/mask/src/plugins/Avatar/Application/NFTListPage.tsx @@ -1,11 +1,7 @@ +import { useImageChecker } from '@masknet/plugin-infra/web3' import { makeStyles } from '@masknet/theme' -import { - ChainId, - createERC721Token, - ERC721TokenDetailed, - EthereumTokenType, - useImageChecker, -} from '@masknet/web3-shared-evm' +import type { NonFungibleToken } from '@masknet/web3-shared-base' +import { ChainId, createERC721Token, SchemaType } from '@masknet/web3-shared-evm' import { Box, Skeleton } from '@mui/material' import { useState } from 'react' import { NFTImage } from '../SNSAdaptor/NFTImage' @@ -49,31 +45,19 @@ interface NFTListPageProps { chainId: ChainId address: string tokenInfo?: TokenInfo - tokens: ERC721TokenDetailed[] - onSelect?: (token: ERC721TokenDetailed) => void + tokens: Array> + onSelect?: (token: NonFungibleToken) => void children?: React.ReactElement } export function NFTListPage(props: NFTListPageProps) { const { classes } = useStyles() const { onSelect, chainId, tokenInfo, tokens, children } = props - const [selectedToken, setSelectedToken] = useState( - tokenInfo - ? createERC721Token( - { - name: '', - address: tokenInfo.address, - chainId, - symbol: '', - type: EthereumTokenType.ERC721, - }, - {}, - tokenInfo.tokenId, - ) - : undefined, + const [selectedToken, setSelectedToken] = useState | undefined>( + tokenInfo ? createERC721Token(chainId, tokenInfo.address, tokenInfo.tokenId) : undefined, ) - const onChange = (token: ERC721TokenDetailed) => { + const onChange = (token: NonFungibleToken) => { if (!token) return setSelectedToken(token) onSelect?.(token) @@ -84,7 +68,7 @@ export function NFTListPage(props: NFTListPageProps) { {children ?? - tokens.map((token: ERC721TokenDetailed, i) => ( + tokens.map((token: NonFungibleToken, i) => ( void - selectedToken?: ERC721TokenDetailed + token: NonFungibleToken + onChange: (token: NonFungibleToken) => void + selectedToken?: NonFungibleToken } function NFTImageCollectibleAvatar({ token, onChange, selectedToken }: NFTImageCollectibleAvatarProps) { const { classes } = useStyles() - const { value: isImageToken, loading } = useImageChecker(token.info?.imageURL) + const { value: isImageToken, loading } = useImageChecker(token.metadata?.imageURL) if (loading) return ( diff --git a/packages/mask/src/plugins/Avatar/Application/UploadAvatarDialog.tsx b/packages/mask/src/plugins/Avatar/Application/UploadAvatarDialog.tsx index c310ea817d8e..48654698c1ad 100644 --- a/packages/mask/src/plugins/Avatar/Application/UploadAvatarDialog.tsx +++ b/packages/mask/src/plugins/Avatar/Application/UploadAvatarDialog.tsx @@ -3,7 +3,8 @@ import AvatarEditor from 'react-avatar-editor' import { makeStyles, useCustomSnackbar } from '@masknet/theme' import { useCallback, useState } from 'react' import { NextIDStorage, Twitter, TwitterBaseAPI } from '@masknet/web3-providers' -import type { ERC721TokenDetailed } from '@masknet/web3-shared-evm' +import { ChainId, SchemaType } from '@masknet/web3-shared-evm' +import type { NonFungibleToken } from '@masknet/web3-shared-base' import { getAvatarId } from '../../../social-network-adaptor/twitter.com/utils/user' import { usePersonaConnectStatus } from '../../../components/DataSource/usePersonaConnectStatus' import { BindingProof, fromHex, PersonaIdentifier, ProfileIdentifier, toBase64 } from '@masknet/shared-base' @@ -33,7 +34,7 @@ interface UploadAvatarDialogProps { account?: string isBindAccount?: boolean image?: string | File - token?: ERC721TokenDetailed + token?: NonFungibleToken proof?: BindingProof onBack: () => void onClose: () => void @@ -84,22 +85,23 @@ async function saveToNextID(info: NextIDAvatarMeta, persona?: PersonaIdentifier, async function Save( account: string, isBindAccount: boolean, - token: ERC721TokenDetailed, + token: NonFungibleToken, data: AvatarInfo, persona: PersonaIdentifier, proof: BindingProof, identifier: ProfileIdentifier, ) { - if (!data) return false + if (!data || !token.contract?.address) return false const info: NextIDAvatarMeta = { nickname: data.nickname, userId: data.userId, imageUrl: data.imageUrl, avatarId: data.avatarId, - address: token.contractDetailed.address, + address: token.contract?.address, tokenId: token.tokenId, - chainId: token.contractDetailed.chainId, + chainId: token.contract?.chainId ?? ChainId.Mainnet, + schema: token.contract?.schema ?? SchemaType.ERC20, } if (isBindAccount) { diff --git a/packages/mask/src/plugins/Avatar/Application/WalletConnect.tsx b/packages/mask/src/plugins/Avatar/Application/WalletConnect.tsx index 14f261fad9cd..cdfc012139c2 100644 --- a/packages/mask/src/plugins/Avatar/Application/WalletConnect.tsx +++ b/packages/mask/src/plugins/Avatar/Application/WalletConnect.tsx @@ -1,14 +1,15 @@ import { WalletMessages } from '@masknet/plugin-wallet' import { useRemoteControlledDialog } from '@masknet/shared-base-ui' import { makeStyles, useStylesExtends } from '@masknet/theme' -import { resolveProviderHomeLink, useProviderType } from '@masknet/web3-shared-evm' +import { providerResolver } from '@masknet/web3-shared-evm' +import { useProviderType } from '@masknet/plugin-infra/web3' import { Box, Button, Link, Typography } from '@mui/material' import { WalletIcon } from '../assets/wallet' import LaunchIcon from '@mui/icons-material/Launch' import { useI18N } from '../locales/i18n_generated' import type { HTMLProps } from 'react' import { ApplicationSmallIcon } from '../assets/application' -import { NetworkPluginID } from '@masknet/plugin-infra/web3' +import { NetworkPluginID } from '@masknet/web3-shared-base' const useStyles = makeStyles()((theme) => ({ root: { @@ -47,7 +48,7 @@ interface NFTWalletConnectProps extends withClasses<'root'> {} export function NFTWalletConnect(props: NFTWalletConnectProps) { const classes = useStylesExtends(useStyles(), props) - const providerType = useProviderType() + const providerType = useProviderType(NetworkPluginID.PLUGIN_EVM) const t = useI18N() const { setDialog: openSelectProviderDialog } = useRemoteControlledDialog( @@ -71,19 +72,21 @@ export function NFTWalletConnect(props: NFTWalletConnectProps) { Mask Network - - - + {providerType ? ( + + + + ) : null}