From ac2535d6e058987481da9fab405c7b8c75dc867c Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Fri, 25 Mar 2022 12:23:37 +0800 Subject: [PATCH 1/5] fix: a CSS warning --- .../mask/src/plugins/Collectible/SNSAdaptor/Collectible.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/mask/src/plugins/Collectible/SNSAdaptor/Collectible.tsx b/packages/mask/src/plugins/Collectible/SNSAdaptor/Collectible.tsx index 519e257a9d9b..cb4d5b9afac0 100644 --- a/packages/mask/src/plugins/Collectible/SNSAdaptor/Collectible.tsx +++ b/packages/mask/src/plugins/Collectible/SNSAdaptor/Collectible.tsx @@ -112,10 +112,10 @@ const useStyles = makeStyles()((theme) => { padding: theme.spacing(8, 0), }, markdown: { - 'text-overflow': 'ellipsis', + textOverflow: 'ellipsis', display: '-webkit-box', - '-webkit-box-orient': 'vertical', - '-webkit-line-clamp': '3', + webkitBoxOrient: 'vertical', + webkitLineClamp: '3', }, } }) From 4024e5075922f5834f6e7f5be6942506a4bd3544 Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Fri, 25 Mar 2022 12:39:16 +0800 Subject: [PATCH 2/5] refactor: pure values --- .../components/CollectibleList/index.tsx | 5 +- .../components/WalletStateBar/index.tsx | 3 +- .../components/DataSource/useActivatedUI.ts | 4 +- .../InjectedComponents/ProfileTabContent.tsx | 3 +- .../Collectible/hooks/useAssetOrder.ts | 4 +- .../src/plugins/NextID/SNSAdaptor/index.tsx | 2 +- .../NextID/components/Tip/TipButton.tsx | 3 +- .../NextID/components/Tip/TipDialog.tsx | 3 +- .../NextID/components/Tip/TipTaskManager.tsx | 2 +- .../Savings/SNSAdaptor/SavingsDialog.tsx | 3 +- .../plugins/Trader/trader/uniswap/usePairs.ts | 4 +- .../Trader/trader/useAllTradeComputed.ts | 3 +- .../utils/create-post-context.ts | 10 ++-- packages/mask/utils-pure/index.ts | 1 - .../plugins/RSS3/src/SNSAdaptor/TabCard.tsx | 3 +- .../RSS3/src/SNSAdaptor/hooks/useDonations.ts | 2 +- packages/public-api/src/web.ts | 32 ++++++++++- packages/shared-base/src/Messages/Mask.ts | 2 +- .../misc.ts => shared-base/src/Pure/index.ts} | 0 packages/shared-base/src/index.ts | 1 + packages/shared-base/tsconfig.json | 2 +- packages/theme/package.json | 1 + .../ShadowRoot/createReactRootShadowed.tsx | 5 +- packages/theme/tsconfig.json | 2 +- packages/web3-shared/base/src/utils/number.ts | 1 + packages/web3-shared/evm/hooks/useAssets.ts | 3 +- .../evm/hooks/useAssetsFromChain.ts | 3 +- .../web3-shared/evm/hooks/useAssetsMerged.ts | 5 +- .../web3-shared/evm/hooks/useTokensBalance.ts | 4 +- packages/web3-shared/evm/tsconfig.json | 7 ++- packages/web3-shared/evm/types/index.ts | 56 ++----------------- packages/web3-shared/evm/utils/index.ts | 1 - packages/web3-shared/flow/tsconfig.json | 2 +- pnpm-lock.yaml | 2 + 34 files changed, 92 insertions(+), 92 deletions(-) rename packages/{mask/utils-pure/misc.ts => shared-base/src/Pure/index.ts} (100%) diff --git a/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx b/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx index 934f6189d4c7..a769b722c4b2 100644 --- a/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/CollectibleList/index.tsx @@ -1,14 +1,13 @@ import { Dispatch, memo, SetStateAction, useCallback, useEffect, useRef, useState } from 'react' +import { useNavigate } from 'react-router-dom' import { Box, Stack, TablePagination } from '@mui/material' import { makeStyles } from '@masknet/theme' -import { EMPTY_LIST } from '@masknet/web3-shared-evm' import { LoadingPlaceholder } from '../../../../components/LoadingPlaceholder' +import { DashboardRoutes, EMPTY_LIST } from '@masknet/shared-base' import { EmptyPlaceholder } from '../EmptyPlaceholder' import { CollectibleCard } from '../CollectibleCard' import { useDashboardI18N } from '../../../../locales' import { PluginMessages } from '../../../../API' -import { useNavigate } from 'react-router-dom' -import { DashboardRoutes } from '@masknet/shared-base' import { TransferTab } from '../Transfer' import { useNetworkDescriptor, diff --git a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/index.tsx b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/index.tsx index 6b93fbc3013a..574dd8689708 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 { FC, memo } from 'react' import { Box, Button, Stack, Typography } from '@mui/material' -import { EMPTY_LIST, ProviderType, TransactionStatusType } from '@masknet/web3-shared-evm' +import { ProviderType, TransactionStatusType } 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' @@ -12,6 +12,7 @@ import { Web3Plugin, useReverseAddress, } from '@masknet/plugin-infra' +import { EMPTY_LIST } from '@masknet/shared-base' import { PluginMessages } from '../../../../API' import { useRecentTransactions } from '../../hooks/useRecentTransactions' import { useDashboardI18N } from '../../../../locales' diff --git a/packages/mask/src/components/DataSource/useActivatedUI.ts b/packages/mask/src/components/DataSource/useActivatedUI.ts index a829094b54ff..c5cef6e522c4 100644 --- a/packages/mask/src/components/DataSource/useActivatedUI.ts +++ b/packages/mask/src/components/DataSource/useActivatedUI.ts @@ -1,7 +1,7 @@ import { useMemo } from 'react' import { ValueRef } from '@dimensiondev/holoflows-kit' import { useValueRef } from '@masknet/shared-base-ui' -import { ProfileIdentifier } from '@masknet/shared-base' +import { EMPTY_LIST, ProfileIdentifier } from '@masknet/shared-base' import type { Profile } from '../../database' import type { SocialNetworkUI } from '../../social-network' import { activatedSocialNetworkUI, globalUIState } from '../../social-network' @@ -9,7 +9,7 @@ import { Subscription, useSubscription } from 'use-subscription' export function useFriendsList() { const ref = useValueRef(globalUIState.friends) - return useMemo(() => [...ref.values()], [ref]) + return useMemo(() => (ref.values.length ? [...ref.values()] : EMPTY_LIST), [ref]) } const default_ = new ValueRef({ identifier: ProfileIdentifier.unknown }) diff --git a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx index ed54e332a37f..f5e1e51182cf 100644 --- a/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx +++ b/packages/mask/src/components/InjectedComponents/ProfileTabContent.tsx @@ -1,7 +1,7 @@ import { useEffect, useMemo, useState } from 'react' import { useUpdateEffect } from 'react-use' import { first } from 'lodash-unified' -import type { NextIDPlatform } from '@masknet/shared-base' +import { NextIDPlatform, EMPTY_LIST } from '@masknet/shared-base' import { Box, CircularProgress } from '@mui/material' import { makeStyles, useStylesExtends } from '@masknet/theme' import { useAddressNames } from '@masknet/web3-shared-evm' @@ -13,7 +13,6 @@ import { useCurrentVisitingIdentity, useLastRecognizedIdentity } from '../DataSo import { useNextIDBoundByPlatform } from '../DataSource/useNextID' import { usePersonaConnectStatus } from '../DataSource/usePersonaConnectStatus' import { activatedSocialNetworkUI } from '../../social-network' -import { EMPTY_LIST } from '../../../utils-pure' function getTabContent(tabId: string) { return createInjectHooksRenderer(useActivatedPluginsSNSAdaptor.visibility.useAnyMode, (x) => { diff --git a/packages/mask/src/plugins/Collectible/hooks/useAssetOrder.ts b/packages/mask/src/plugins/Collectible/hooks/useAssetOrder.ts index ae211e1ea6cd..068223e11a47 100644 --- a/packages/mask/src/plugins/Collectible/hooks/useAssetOrder.ts +++ b/packages/mask/src/plugins/Collectible/hooks/useAssetOrder.ts @@ -10,7 +10,7 @@ import type { AssetOrder, CollectibleToken } from '../types' export function useAssetOrder(provider: NonFungibleAssetProvider, token?: CollectibleToken) { return useAsyncRetry(async () => { - if (!token) return + if (!token?.contractAddress || !token?.tokenId) return switch (provider) { case NonFungibleAssetProvider.OPENSEA: const openSeaResponse = await PluginCollectibleRPC.getAssetFromSDK(token.contractAddress, token.tokenId) @@ -37,5 +37,5 @@ export function useAssetOrder(provider: NonFungibleAssetProvider, token?: Collec default: unreachable(provider) } - }, [provider, token]) + }, [provider, token?.contractAddress, token?.tokenId]) } diff --git a/packages/mask/src/plugins/NextID/SNSAdaptor/index.tsx b/packages/mask/src/plugins/NextID/SNSAdaptor/index.tsx index 0df313132cef..139ece72debe 100644 --- a/packages/mask/src/plugins/NextID/SNSAdaptor/index.tsx +++ b/packages/mask/src/plugins/NextID/SNSAdaptor/index.tsx @@ -1,11 +1,11 @@ import type { Plugin } from '@masknet/plugin-infra' +import { EMPTY_LIST } from '@masknet/shared-base' import { base } from '../base' import { PLUGIN_ID } from '../constants' import { NextIdPage } from '../components/NextIdPage' import { RootContext } from '../contexts' import { PostTipButton, TipTaskManager } from '../components/Tip' import { Flags } from '../../../../shared' -import { EMPTY_LIST } from '@masknet/web3-shared-evm' const sns: Plugin.SNSAdaptor.Definition = { ...base, diff --git a/packages/mask/src/plugins/NextID/components/Tip/TipButton.tsx b/packages/mask/src/plugins/NextID/components/Tip/TipButton.tsx index aaaad373542e..0bd51f2f1167 100644 --- a/packages/mask/src/plugins/NextID/components/Tip/TipButton.tsx +++ b/packages/mask/src/plugins/NextID/components/Tip/TipButton.tsx @@ -1,9 +1,8 @@ import { TipCoin } from '@masknet/icons' import { usePostInfoDetails } from '@masknet/plugin-infra' -import { NextIDPlatform, ProfileIdentifier } from '@masknet/shared-base' +import { EMPTY_LIST, NextIDPlatform, ProfileIdentifier } from '@masknet/shared-base' import { makeStyles, ShadowRootTooltip } from '@masknet/theme' import { queryExistedBindingByPersona, queryIsBound } from '@masknet/web3-providers' -import { EMPTY_LIST } from '@masknet/web3-shared-evm' import classnames from 'classnames' import { uniq } from 'lodash-unified' import { FC, HTMLProps, MouseEventHandler, useCallback, useMemo } from 'react' diff --git a/packages/mask/src/plugins/NextID/components/Tip/TipDialog.tsx b/packages/mask/src/plugins/NextID/components/Tip/TipDialog.tsx index 0f0a364ce07b..dda7272cba7a 100644 --- a/packages/mask/src/plugins/NextID/components/Tip/TipDialog.tsx +++ b/packages/mask/src/plugins/NextID/components/Tip/TipDialog.tsx @@ -1,8 +1,9 @@ import { SuccessIcon } from '@masknet/icons' import { PluginId, useActivatedPlugin, usePluginIDContext } from '@masknet/plugin-infra' import { NFTCardStyledAssetPlayer } from '@masknet/shared' +import { EMPTY_LIST } from '@masknet/shared-base' import { makeStyles } from '@masknet/theme' -import { EMPTY_LIST, TransactionStateType, useChainId, useERC721TokenDetailed } from '@masknet/web3-shared-evm' +import { TransactionStateType, useChainId, useERC721TokenDetailed } from '@masknet/web3-shared-evm' import { DialogContent, Typography } from '@mui/material' import { useCallback, useEffect, useMemo } from 'react' import { useBoolean } from 'react-use' diff --git a/packages/mask/src/plugins/NextID/components/Tip/TipTaskManager.tsx b/packages/mask/src/plugins/NextID/components/Tip/TipTaskManager.tsx index 92dd165d32c4..0f1cff3df855 100644 --- a/packages/mask/src/plugins/NextID/components/Tip/TipTaskManager.tsx +++ b/packages/mask/src/plugins/NextID/components/Tip/TipTaskManager.tsx @@ -1,5 +1,5 @@ -import { EMPTY_LIST } from '@masknet/web3-shared-evm' import { FC, useCallback, useEffect, useState } from 'react' +import { EMPTY_LIST } from '@masknet/shared-base' import { TipTaskProvider } from '../../contexts' import { PluginNextIdMessages } from '../../messages' import type { TipTask } from '../../types' diff --git a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsDialog.tsx b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsDialog.tsx index dfa2dd5b16be..2ead2cf16ade 100644 --- a/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsDialog.tsx +++ b/packages/mask/src/plugins/Savings/SNSAdaptor/SavingsDialog.tsx @@ -2,9 +2,8 @@ import { useState, useMemo } from 'react' import { useAsync } from 'react-use' import { Typography, DialogContent } from '@mui/material' import { ChainId, getChainIdFromNetworkType, useChainId } from '@masknet/web3-shared-evm' -import { isDashboardPage } from '@masknet/shared-base' +import { isDashboardPage, EMPTY_LIST } from '@masknet/shared-base' import { useI18N } from '../../../utils' -import { EMPTY_LIST } from '../../../../utils-pure' import { InjectedDialog } from '../../../components/shared/InjectedDialog' import { WalletStatusBox } from '../../../components/shared/WalletStatusBox' import { AllProviderTradeContext } from '../../Trader/trader/useAllProviderTradeContext' diff --git a/packages/mask/src/plugins/Trader/trader/uniswap/usePairs.ts b/packages/mask/src/plugins/Trader/trader/uniswap/usePairs.ts index 62856baff29a..3582a101dfe5 100644 --- a/packages/mask/src/plugins/Trader/trader/uniswap/usePairs.ts +++ b/packages/mask/src/plugins/Trader/trader/uniswap/usePairs.ts @@ -1,16 +1,16 @@ import { useMemo } from 'react' import { useAsyncRetry } from 'react-use' +import { numberToHex } from 'web3-utils' import { Pair } from '@uniswap/v2-sdk' import { CurrencyAmount, Token } from '@uniswap/sdk-core' +import { EMPTY_LIST } from '@masknet/shared-base' import { useMultipleContractSingleData } from '@masknet/web3-shared-evm' import { getPairAddress } from '../../helpers' import { usePairContracts } from '../../contracts/uniswap/usePairContract' import type { TradeProvider } from '@masknet/public-api' import { useGetTradeContext } from '../useGetTradeContext' import { TargetChainIdContext } from '../useTargetChainIdContext' -import { numberToHex } from 'web3-utils' import { useTargetBlockNumber } from '../useTargetBlockNumber' -import { EMPTY_LIST } from '../../../../../utils-pure' export enum PairState { NOT_EXISTS = 0, diff --git a/packages/mask/src/plugins/Trader/trader/useAllTradeComputed.ts b/packages/mask/src/plugins/Trader/trader/useAllTradeComputed.ts index 0479fdd0dd1e..e8f998637286 100644 --- a/packages/mask/src/plugins/Trader/trader/useAllTradeComputed.ts +++ b/packages/mask/src/plugins/Trader/trader/useAllTradeComputed.ts @@ -1,4 +1,5 @@ -import { EMPTY_LIST, FungibleTokenDetailed } from '@masknet/web3-shared-evm' +import { EMPTY_LIST } from '@masknet/shared-base' +import type { FungibleTokenDetailed } from '@masknet/web3-shared-evm' import { multipliedBy, pow10 } from '@masknet/web3-shared-base' import { useTrade as useNativeTokenTrade } from './native/useTrade' import { useTradeComputed as useNativeTokenTradeComputed } from './native/useTradeComputed' 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 8e6561790e5f..ed34f3e81432 100644 --- a/packages/mask/src/social-network/utils/create-post-context.ts +++ b/packages/mask/src/social-network/utils/create-post-context.ts @@ -18,6 +18,7 @@ import { SubscriptionFromValueRef, SubscriptionDebug as debug, mapSubscription, + EMPTY_LIST, } from '@masknet/shared-base' import { Err, Result } from 'ts-results' import type { Subscription } from 'use-subscription' @@ -60,7 +61,7 @@ export function createSNSAdaptorSpecializedPostContext(create: PostContextSNSAct }), ) const linksSubscribe: Subscription = debug({ - getCurrentValue: () => [...links], + getCurrentValue: () => (links.size ? [...links] : EMPTY_LIST), subscribe: (sub) => links.event.on(ALL_EVENTS, sub), }) // #endregion @@ -138,7 +139,7 @@ export function createSNSAdaptorSpecializedPostContext(create: PostContextSNSAct postMetadataImages: opt.postImagesProvider || debug({ - getCurrentValue: () => [], + getCurrentValue: () => EMPTY_LIST, subscribe: () => () => {}, }), @@ -181,11 +182,12 @@ export function createRefsForCreatePostContext() { snsID: SubscriptionFromValueRef(postID), rawMessage: SubscriptionFromValueRef(postMessage), postImagesProvider: debug({ - getCurrentValue: () => [...postMetadataImages], + getCurrentValue: () => (postMetadataImages.size ? [...postMetadataImages] : EMPTY_LIST), subscribe: (sub) => postMetadataImages.event.on(ALL_EVENTS, sub), }), postMentionedLinksProvider: debug({ - getCurrentValue: () => [...postMetadataMentionedLinks.values()], + getCurrentValue: () => + postMetadataMentionedLinks.size ? [...postMetadataMentionedLinks.values()] : EMPTY_LIST, subscribe: (sub) => postMetadataMentionedLinks.event.on(ALL_EVENTS, sub), }), } diff --git a/packages/mask/utils-pure/index.ts b/packages/mask/utils-pure/index.ts index 6ba5881a1d04..3a1a43716896 100644 --- a/packages/mask/utils-pure/index.ts +++ b/packages/mask/utils-pure/index.ts @@ -1,5 +1,4 @@ export * from './type' -export * from './misc' export * from './hmr' export * from './crypto' export * from './OnDemandWorker' diff --git a/packages/plugins/RSS3/src/SNSAdaptor/TabCard.tsx b/packages/plugins/RSS3/src/SNSAdaptor/TabCard.tsx index ff077de38a14..872ef9548c42 100644 --- a/packages/plugins/RSS3/src/SNSAdaptor/TabCard.tsx +++ b/packages/plugins/RSS3/src/SNSAdaptor/TabCard.tsx @@ -1,5 +1,6 @@ import { AddressViewer } from '@masknet/shared' -import { AddressName, AddressNameType, EMPTY_LIST } from '@masknet/web3-shared-evm' +import { EMPTY_LIST } from '@masknet/shared-base' +import { AddressName, AddressNameType } from '@masknet/web3-shared-evm' import { Box, Typography } from '@mui/material' import { useI18N } from '../locales' import { useDonations, useFootprints } from './hooks' diff --git a/packages/plugins/RSS3/src/SNSAdaptor/hooks/useDonations.ts b/packages/plugins/RSS3/src/SNSAdaptor/hooks/useDonations.ts index 39c286bd6628..faecb82d8c85 100644 --- a/packages/plugins/RSS3/src/SNSAdaptor/hooks/useDonations.ts +++ b/packages/plugins/RSS3/src/SNSAdaptor/hooks/useDonations.ts @@ -1,5 +1,5 @@ -import { EMPTY_LIST } from '@masknet/web3-shared-evm' import { useAsync } from 'react-use' +import { EMPTY_LIST } from '@masknet/shared-base' import { PluginProfileRPC } from '../../messages' export function useDonations(address: string) { diff --git a/packages/public-api/src/web.ts b/packages/public-api/src/web.ts index 4dad3ec0778a..fdcd12e05bdc 100644 --- a/packages/public-api/src/web.ts +++ b/packages/public-api/src/web.ts @@ -177,7 +177,6 @@ export enum LaunchPage { dashboard = 'dashboard', } -// This type MUST be sync with NetworkType in packages/web3-shared/src/types/index.ts export enum NetworkType { Ethereum = 'Ethereum', Binance = 'Binance', @@ -195,6 +194,28 @@ export enum NetworkType { Conflux = 'Conflux', } +export enum ProviderType { + MaskWallet = 'Maskbook', + MetaMask = 'MetaMask', + WalletConnect = 'WalletConnect', + Fortmatic = 'Fortmatic', + Coin98 = 'Coin98', + MathWallet = 'MathWallet', + WalletLink = 'WalletLink', + CustomNetwork = 'CustomNetwork', +} + +export enum FungibleAssetProvider { + ZERION = 'Zerion', + DEBANK = 'Debank', +} + +export enum NonFungibleAssetProvider { + OPENSEA = 'OpenSea', + RARIBLE = 'Rarible', + NFTSCAN = 'NFTScan', +} + export enum DataProvider { COIN_GECKO = 0, COIN_MARKET_CAP = 1, @@ -237,3 +258,12 @@ export enum SupportedLanguages { koKR = 'ko-KR', jaJP = 'ja-JP', } + +export interface PriceRecord { + [currency: string]: number +} + +/** Base on response of coingecko's token price API */ +export interface CryptoPrice { + [token: string]: PriceRecord +} diff --git a/packages/shared-base/src/Messages/Mask.ts b/packages/shared-base/src/Messages/Mask.ts index 8d158b800a07..6370e898bf35 100644 --- a/packages/shared-base/src/Messages/Mask.ts +++ b/packages/shared-base/src/Messages/Mask.ts @@ -8,7 +8,7 @@ import type { ProviderType, FungibleAssetProvider, NonFungibleAssetProvider, -} from '../../../web3-shared/evm' +} from '../../../public-api' export interface MaskSettingsEvents { appearanceSettings: Appearance diff --git a/packages/mask/utils-pure/misc.ts b/packages/shared-base/src/Pure/index.ts similarity index 100% rename from packages/mask/utils-pure/misc.ts rename to packages/shared-base/src/Pure/index.ts diff --git a/packages/shared-base/src/index.ts b/packages/shared-base/src/index.ts index ec82b1b74743..a8c38e51d931 100644 --- a/packages/shared-base/src/index.ts +++ b/packages/shared-base/src/index.ts @@ -7,6 +7,7 @@ export * from './i18n' export * from './utils' export * from './kv-storage' export * from './crypto' +export * from './Pure' export * from './Persona/type' export * from './Post/type' export * from './Persona/type' diff --git a/packages/shared-base/tsconfig.json b/packages/shared-base/tsconfig.json index 398b55ddd11e..21eef249d5b7 100644 --- a/packages/shared-base/tsconfig.json +++ b/packages/shared-base/tsconfig.json @@ -7,5 +7,5 @@ }, "include": ["./src", "./src/**/*.json"], // Only type-level dependency. - "references": [{ "path": "../public-api" }, { "path": "../web3-shared/evm" }, { "path": "../typed-message/base" }] + "references": [{ "path": "../public-api" }, { "path": "../typed-message/base" }] } diff --git a/packages/theme/package.json b/packages/theme/package.json index a924008c6ee2..d0828f1839d8 100644 --- a/packages/theme/package.json +++ b/packages/theme/package.json @@ -22,6 +22,7 @@ }, "dependencies": { "@masknet/icons": "workspace:*", + "@masknet/shared-base": "workspace:*", "@masknet/storybook-shared": "workspace:*", "@types/qrcode": "^1.4.2", "@types/tinycolor2": "^1.4.3", diff --git a/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx b/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx index a76abe77a4f2..583c98b523f4 100644 --- a/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx +++ b/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx @@ -1,5 +1,6 @@ import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' +import { noop } from 'lodash-unified' import type {} from 'react/next' import type {} from 'react-dom/next' import { ShadowRootStyleProvider } from './ShadowRootStyleProvider' @@ -68,8 +69,8 @@ function mount( if (shadow.querySelector(`${tag}.${key}`)) { console.error('Tried to create root in', shadow, 'with key', key, ' which is already used. Skip rendering.') return { - destory: () => {}, - render: () => {}, + destory: noop, + render: noop, } } diff --git a/packages/theme/tsconfig.json b/packages/theme/tsconfig.json index bb4139031a1a..174fe5764c22 100644 --- a/packages/theme/tsconfig.json +++ b/packages/theme/tsconfig.json @@ -6,5 +6,5 @@ "tsBuildInfoFile": "./dist/src.tsbuildinfo" }, "include": ["./src"], - "references": [{ "path": "../icons" }] + "references": [{ "path": "../icons" }, { "path": "../shared-base" }] } diff --git a/packages/web3-shared/base/src/utils/number.ts b/packages/web3-shared/base/src/utils/number.ts index 042a5b0b6deb..b061820adf29 100644 --- a/packages/web3-shared/base/src/utils/number.ts +++ b/packages/web3-shared/base/src/utils/number.ts @@ -44,6 +44,7 @@ export function multipliedBy(a: BigNumber.Value, b: BigNumber.Value) { } /** 10 ** n */ +/** @deprecated use scale10 */ export function pow10(n: BigNumber.Value) { return new BigNumber(10).pow(n) } diff --git a/packages/web3-shared/evm/hooks/useAssets.ts b/packages/web3-shared/evm/hooks/useAssets.ts index 9ca15511ba4b..d90a63d611a2 100644 --- a/packages/web3-shared/evm/hooks/useAssets.ts +++ b/packages/web3-shared/evm/hooks/useAssets.ts @@ -1,3 +1,4 @@ +import { EMPTY_LIST } from '@masknet/shared-base' import type { ChainId, FungibleTokenDetailed } from '../types' import { useWallet } from './useWallet' import { useNativeTokenDetailed } from './useNativeTokenDetailed' @@ -5,7 +6,7 @@ import { useAssetsFromChain } from './useAssetsFromChain' import { useAssetsFromProvider } from './useAssetsFromProvider' import { useCallback, useMemo } from 'react' import { useAssetsMerged } from './useAssetsMerged' -import { formatEthereumAddress, EMPTY_LIST } from '../utils' +import { formatEthereumAddress } from '../utils' export function useAssets(tokens: FungibleTokenDetailed[], chainId?: ChainId | 'all') { const wallet = useWallet() diff --git a/packages/web3-shared/evm/hooks/useAssetsFromChain.ts b/packages/web3-shared/evm/hooks/useAssetsFromChain.ts index 28d0a326453b..ac4cb59a1cde 100644 --- a/packages/web3-shared/evm/hooks/useAssetsFromChain.ts +++ b/packages/web3-shared/evm/hooks/useAssetsFromChain.ts @@ -1,9 +1,10 @@ import { useMemo } from 'react' import { first } from 'lodash-unified' +import { EMPTY_LIST } from '@masknet/shared-base' import { Asset, ChainId, EthereumTokenType, FungibleTokenDetailed } from '../types' import { useTokensBalance } from './useTokensBalance' import { useChainDetailed } from './useChainDetailed' -import { getChainDetailed, EMPTY_LIST } from '../utils' +import { getChainDetailed } from '../utils' import { useBalance } from './useBalance' export function useAssetsFromChain(tokens: FungibleTokenDetailed[], chainId?: ChainId) { diff --git a/packages/web3-shared/evm/hooks/useAssetsMerged.ts b/packages/web3-shared/evm/hooks/useAssetsMerged.ts index 231f8d9b6a89..36b25f1fece4 100644 --- a/packages/web3-shared/evm/hooks/useAssetsMerged.ts +++ b/packages/web3-shared/evm/hooks/useAssetsMerged.ts @@ -1,8 +1,9 @@ -import { uniqBy } from 'lodash-unified' import { useMemo } from 'react' +import { uniqBy } from 'lodash-unified' +import { EMPTY_LIST } from '@masknet/shared-base' import { useTokenConstants } from '../constants' import type { Asset } from '../types' -import { formatEthereumAddress, makeSortAssertFn, EMPTY_LIST } from '../utils' +import { formatEthereumAddress, makeSortAssertFn } from '../utils' import { useChainId } from './useChainId' /** diff --git a/packages/web3-shared/evm/hooks/useTokensBalance.ts b/packages/web3-shared/evm/hooks/useTokensBalance.ts index f5c0f5d2a272..263b47242aac 100644 --- a/packages/web3-shared/evm/hooks/useTokensBalance.ts +++ b/packages/web3-shared/evm/hooks/useTokensBalance.ts @@ -1,10 +1,10 @@ import { useAsyncRetry } from 'react-use' +import { numberToHex } from 'web3-utils' +import { EMPTY_LIST } from '@masknet/shared-base' import { useBalanceCheckerContract } from '../contracts/useBalanceChecker' import { useAccount } from './useAccount' import { useChainId } from './useChainId' import type { ChainId } from '../types' -import { EMPTY_LIST } from '../utils' -import { numberToHex } from 'web3-utils' /** * Fetch balance of multiple tokens from chain diff --git a/packages/web3-shared/evm/tsconfig.json b/packages/web3-shared/evm/tsconfig.json index 31e14ea11894..885e95091823 100644 --- a/packages/web3-shared/evm/tsconfig.json +++ b/packages/web3-shared/evm/tsconfig.json @@ -6,5 +6,10 @@ "tsBuildInfoFile": "../dist/evm.tsbuildinfo" }, "include": ["./", "./**/*.json"], - "references": [{ "path": "../../injected-script/sdk" }, { "path": "../base" }] + "references": [ + { "path": "../../injected-script/sdk" }, + { "path": "../base" }, + { "path": "../../shared-base" }, + { "path": "../../public-api" } + ] } diff --git a/packages/web3-shared/evm/types/index.ts b/packages/web3-shared/evm/types/index.ts index 18588cb9e6d5..bb5a98fc7b28 100644 --- a/packages/web3-shared/evm/types/index.ts +++ b/packages/web3-shared/evm/types/index.ts @@ -1,5 +1,11 @@ import type { TransactionConfig as TransactionConfig_ } from 'web3-core' import type { NonPayableTransactionObject, PayableTransactionObject } from '@masknet/web3-contracts/types/types' +import type { ProviderType } from '../../../public-api' + +// TODO: remove the depends of MaskSettingsEvents +export { NetworkType, ProviderType, FungibleAssetProvider, NonFungibleAssetProvider } from '../../../public-api' + +export type { PriceRecord, CryptoPrice } from '../../../public-api' export interface SendOverrides { chainId?: ChainId @@ -15,14 +21,6 @@ export enum CurrencyType { USD = 'usd', } -export interface PriceRecord { - [currency: string]: number -} - -/** Base on response of coingecko's token price API */ -export interface CryptoPrice { - [token: string]: PriceRecord -} export type ChainIdOptionalRecord = { [k in ChainId]?: T } export type ChainIdRecord = { [k in ChainId]: T } @@ -83,42 +81,12 @@ export enum ChainId { Conflux = 1030, } -export enum ProviderType { - MaskWallet = 'Maskbook', - MetaMask = 'MetaMask', - WalletConnect = 'WalletConnect', - Fortmatic = 'Fortmatic', - Coin98 = 'Coin98', - MathWallet = 'MathWallet', - WalletLink = 'WalletLink', - CustomNetwork = 'CustomNetwork', -} - export enum LockStatus { INIT = 0, UNLOCK = 1, LOCKED = 2, } -// If you change this enum, please sync it to packages/public-api/src/web.ts -// (it's a breaking change. Please notify the iOS and Android dev) -export enum NetworkType { - Ethereum = 'Ethereum', - Binance = 'Binance', - Polygon = 'Polygon', - Arbitrum = 'Arbitrum', - xDai = 'xDai', - Celo = 'Celo', - Fantom = 'Fantom', - Aurora = 'Aurora', - Avalanche = 'Avalanche', - Boba = 'Boba', - Fuse = 'Fuse', - Metis = 'Metis', - Optimistic = 'Optimistic', - Conflux = 'Conflux', -} - export interface Wallet { /** User define wallet name. Default address.prefix(6) */ name: string @@ -579,18 +547,6 @@ export enum DomainProvider { UNS = 'UNS', } -export enum FungibleAssetProvider { - ZERION = 'Zerion', - DEBANK = 'Debank', -} - -export enum NonFungibleAssetProvider { - OPENSEA = 'OpenSea', - RARIBLE = 'Rarible', - NFTSCAN = 'NFTScan', - ZORA = 'Zora', -} - export type UnboxTransactionObject = T extends NonPayableTransactionObject ? R : T extends PayableTransactionObject diff --git a/packages/web3-shared/evm/utils/index.ts b/packages/web3-shared/evm/utils/index.ts index 5d5011871555..a74ca021754b 100644 --- a/packages/web3-shared/evm/utils/index.ts +++ b/packages/web3-shared/evm/utils/index.ts @@ -7,5 +7,4 @@ export * from './chainDetailed' export * from './transaction' export * from './domain' export * from './payload' -export * from './misc' export * from './provider' diff --git a/packages/web3-shared/flow/tsconfig.json b/packages/web3-shared/flow/tsconfig.json index b5b903e4be17..10de013f5120 100644 --- a/packages/web3-shared/flow/tsconfig.json +++ b/packages/web3-shared/flow/tsconfig.json @@ -6,5 +6,5 @@ "tsBuildInfoFile": "../dist/flow.tsbuildinfo" }, "include": ["./", "./**/*.json"], - "references": [{ "path": "../../web3-shared/base" }] + "references": [{ "path": "../base" }] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e7dfa2ba128d..bc1370ac35ec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1080,6 +1080,7 @@ importers: specifiers: '@babel/core': ^7.17.8 '@masknet/icons': workspace:* + '@masknet/shared-base': workspace:* '@masknet/storybook-shared': workspace:* '@storybook/addon-actions': ^6.4.19 '@storybook/addon-essentials': ^6.4.19 @@ -1100,6 +1101,7 @@ importers: use-subscription: ^1.5.1 dependencies: '@masknet/icons': link:../icons + '@masknet/shared-base': link:../shared-base '@masknet/storybook-shared': link:../storybook-shared '@types/qrcode': 1.4.2 '@types/tinycolor2': 1.4.3 From 7cd8974ec419bb0a9f40a38f499892f7b1af3dfc Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Fri, 25 Mar 2022 12:53:43 +0800 Subject: [PATCH 3/5] fix: typo --- packages/theme/src/ShadowRoot/createReactRootShadowed.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx b/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx index b91387bdac48..32535b1a52af 100644 --- a/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx +++ b/packages/theme/src/ShadowRoot/createReactRootShadowed.tsx @@ -69,7 +69,7 @@ function mount( if (shadow.querySelector(`${tag}.${key}`)) { console.error('Tried to create root in', shadow, 'with key', key, ' which is already used. Skip rendering.') return { - destory: noop, + destroy: noop, render: noop, } } From 5b9379c8d8c6a7ff2b89a00ef4961b496f233106 Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Fri, 25 Mar 2022 13:14:13 +0800 Subject: [PATCH 4/5] refactor: enums --- packages/polyfills/types/env.d.ts | 1 + packages/public-api/src/web.ts | 83 ++++++++++++----------- packages/shared-base/package.json | 1 + packages/shared-base/src/Messages/Mask.ts | 13 ++-- packages/web3-shared/evm/tsconfig.json | 3 +- packages/web3-shared/evm/types/index.ts | 58 ++++++++++++++-- packages/web3-shared/evm/utils/address.ts | 4 +- pnpm-lock.yaml | 2 + 8 files changed, 110 insertions(+), 55 deletions(-) diff --git a/packages/polyfills/types/env.d.ts b/packages/polyfills/types/env.d.ts index fdfb80edad90..fd62cb5a743f 100644 --- a/packages/polyfills/types/env.d.ts +++ b/packages/polyfills/types/env.d.ts @@ -4,6 +4,7 @@ declare namespace NodeJS { } interface ProcessEnv { readonly NODE_ENV: 'production' | 'development' + readonly architecture: 'app' | 'web' } } declare var process: NodeJS.Process diff --git a/packages/public-api/src/web.ts b/packages/public-api/src/web.ts index fdcd12e05bdc..eaebe68c57c3 100644 --- a/packages/public-api/src/web.ts +++ b/packages/public-api/src/web.ts @@ -177,45 +177,6 @@ export enum LaunchPage { dashboard = 'dashboard', } -export enum NetworkType { - Ethereum = 'Ethereum', - Binance = 'Binance', - Polygon = 'Polygon', - Arbitrum = 'Arbitrum', - xDai = 'xDai', - Celo = 'Celo', - Fantom = 'Fantom', - Aurora = 'Aurora', - Avalanche = 'Avalanche', - Boba = 'Boba', - Fuse = 'Fuse', - Metis = 'Metis', - Optimistic = 'Optimistic', - Conflux = 'Conflux', -} - -export enum ProviderType { - MaskWallet = 'Maskbook', - MetaMask = 'MetaMask', - WalletConnect = 'WalletConnect', - Fortmatic = 'Fortmatic', - Coin98 = 'Coin98', - MathWallet = 'MathWallet', - WalletLink = 'WalletLink', - CustomNetwork = 'CustomNetwork', -} - -export enum FungibleAssetProvider { - ZERION = 'Zerion', - DEBANK = 'Debank', -} - -export enum NonFungibleAssetProvider { - OPENSEA = 'OpenSea', - RARIBLE = 'Rarible', - NFTSCAN = 'NFTScan', -} - export enum DataProvider { COIN_GECKO = 0, COIN_MARKET_CAP = 1, @@ -240,6 +201,7 @@ export enum TradeProvider { PANGOLIN = 14, MDEX = 15, } + /** Supported language settings */ export enum LanguageOptions { __auto__ = 'auto', @@ -259,6 +221,49 @@ export enum SupportedLanguages { jaJP = 'ja-JP', } +/** + * Keep updating to packages/web3-shared/evm/types/index.ts + */ +export enum NetworkType { + Ethereum = 'Ethereum', + Binance = 'Binance', + Polygon = 'Polygon', + Arbitrum = 'Arbitrum', + xDai = 'xDai', + Celo = 'Celo', + Fantom = 'Fantom', + Aurora = 'Aurora', + Avalanche = 'Avalanche', + Boba = 'Boba', + Fuse = 'Fuse', + Metis = 'Metis', + Optimistic = 'Optimistic', + Conflux = 'Conflux', +} + +export enum ProviderType { + MaskWallet = 'Maskbook', + MetaMask = 'MetaMask', + WalletConnect = 'WalletConnect', + Fortmatic = 'Fortmatic', + Coin98 = 'Coin98', + MathWallet = 'MathWallet', + WalletLink = 'WalletLink', + CustomNetwork = 'CustomNetwork', +} + +export enum FungibleAssetProvider { + ZERION = 'Zerion', + DEBANK = 'Debank', +} + +export enum NonFungibleAssetProvider { + OPENSEA = 'OpenSea', + RARIBLE = 'Rarible', + NFTSCAN = 'NFTScan', + ZORA = 'Zora', +} + export interface PriceRecord { [currency: string]: number } diff --git a/packages/shared-base/package.json b/packages/shared-base/package.json index 258140585c98..aad758c4315c 100644 --- a/packages/shared-base/package.json +++ b/packages/shared-base/package.json @@ -7,6 +7,7 @@ "dependencies": { "@dimensiondev/holoflows-kit": "^0.9.0-20210902104757-7c3d0d0", "@masknet/typed-message": "workspace:*", + "@masknet/public-api": "workspace:*", "@msgpack/msgpack": "^2.7.2", "@mui/icons-material": "link:..\\empty", "@mui/lab": "link:..\\empty", diff --git a/packages/shared-base/src/Messages/Mask.ts b/packages/shared-base/src/Messages/Mask.ts index 6370e898bf35..9a69fcc4c438 100644 --- a/packages/shared-base/src/Messages/Mask.ts +++ b/packages/shared-base/src/Messages/Mask.ts @@ -1,14 +1,15 @@ -import type { SerializableTypedMessages } from '@masknet/typed-message' -import type { ProfileIdentifier, PersonaIdentifier } from '../Identifier/type' -import type { RelationFavor } from '../Persona/type' -import type { Appearance, LanguageOptions, DataProvider } from '../../../public-api/src/web' import type { + Appearance, + LanguageOptions, + DataProvider, CryptoPrice, NetworkType, ProviderType, FungibleAssetProvider, - NonFungibleAssetProvider, -} from '../../../public-api' + NonFungibleAssetProvider, } from '@masknet/public-api' +import type { SerializableTypedMessages } from '@masknet/typed-message' +import type { ProfileIdentifier, PersonaIdentifier } from '../Identifier/type' +import type { RelationFavor } from '../Persona/type' export interface MaskSettingsEvents { appearanceSettings: Appearance diff --git a/packages/web3-shared/evm/tsconfig.json b/packages/web3-shared/evm/tsconfig.json index 885e95091823..d5f05dbca89b 100644 --- a/packages/web3-shared/evm/tsconfig.json +++ b/packages/web3-shared/evm/tsconfig.json @@ -7,9 +7,8 @@ }, "include": ["./", "./**/*.json"], "references": [ - { "path": "../../injected-script/sdk" }, { "path": "../base" }, { "path": "../../shared-base" }, - { "path": "../../public-api" } + { "path": "../../injected-script/sdk" }, ] } diff --git a/packages/web3-shared/evm/types/index.ts b/packages/web3-shared/evm/types/index.ts index bb5a98fc7b28..279218585455 100644 --- a/packages/web3-shared/evm/types/index.ts +++ b/packages/web3-shared/evm/types/index.ts @@ -1,11 +1,5 @@ import type { TransactionConfig as TransactionConfig_ } from 'web3-core' import type { NonPayableTransactionObject, PayableTransactionObject } from '@masknet/web3-contracts/types/types' -import type { ProviderType } from '../../../public-api' - -// TODO: remove the depends of MaskSettingsEvents -export { NetworkType, ProviderType, FungibleAssetProvider, NonFungibleAssetProvider } from '../../../public-api' - -export type { PriceRecord, CryptoPrice } from '../../../public-api' export interface SendOverrides { chainId?: ChainId @@ -647,3 +641,55 @@ export enum TransactionStateType { /** Fail to send */ FAILED = 5, } + +/** + * Keep updating to packages/public-api/src/web.ts + */ +export enum NetworkType { + Ethereum = 'Ethereum', + Binance = 'Binance', + Polygon = 'Polygon', + Arbitrum = 'Arbitrum', + xDai = 'xDai', + Celo = 'Celo', + Fantom = 'Fantom', + Aurora = 'Aurora', + Avalanche = 'Avalanche', + Boba = 'Boba', + Fuse = 'Fuse', + Metis = 'Metis', + Optimistic = 'Optimistic', + Conflux = 'Conflux', +} + +export enum ProviderType { + MaskWallet = 'Maskbook', + MetaMask = 'MetaMask', + WalletConnect = 'WalletConnect', + Fortmatic = 'Fortmatic', + Coin98 = 'Coin98', + MathWallet = 'MathWallet', + WalletLink = 'WalletLink', + CustomNetwork = 'CustomNetwork', +} + +export enum FungibleAssetProvider { + ZERION = 'Zerion', + DEBANK = 'Debank', +} + +export enum NonFungibleAssetProvider { + OPENSEA = 'OpenSea', + RARIBLE = 'Rarible', + NFTSCAN = 'NFTScan', + ZORA = 'Zora', +} + +export interface PriceRecord { + [currency: string]: number +} + +/** Base on response of coingecko's token price API */ +export interface CryptoPrice { + [token: string]: PriceRecord +} diff --git a/packages/web3-shared/evm/utils/address.ts b/packages/web3-shared/evm/utils/address.ts index 6cec9e201dfe..2bb6247e301e 100644 --- a/packages/web3-shared/evm/utils/address.ts +++ b/packages/web3-shared/evm/utils/address.ts @@ -1,6 +1,6 @@ -import { getEnumAsArray } from '@dimensiondev/kit' -import { compact, castArray, uniq } from 'lodash-unified' import { EthereumAddress } from 'wallet.ts' +import { compact, castArray, uniq } from 'lodash-unified' +import { getEnumAsArray } from '@dimensiondev/kit' import { getRedPacketConstants, getTokenConstants, ZERO_ADDRESS } from '../constants' import { ChainId } from '../types' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc1370ac35ec..9d32041caf43 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1008,6 +1008,7 @@ importers: packages/shared-base: specifiers: '@dimensiondev/holoflows-kit': ^0.9.0-20210902104757-7c3d0d0 + '@masknet/public-api': workspace:* '@masknet/typed-message': workspace:* '@msgpack/msgpack': ^2.7.2 '@mui/icons-material': link:..\empty @@ -1030,6 +1031,7 @@ importers: z-schema: ^5.0.2 dependencies: '@dimensiondev/holoflows-kit': 0.9.0-20210902104757-7c3d0d0 + '@masknet/public-api': link:../public-api '@masknet/typed-message': link:../typed-message '@msgpack/msgpack': 2.7.2 '@mui/icons-material': link:../empty From aa1a09bc46a570f027e6e4fb7cde9f2772f2c259 Mon Sep 17 00:00:00 2001 From: guanbinrui Date: Fri, 25 Mar 2022 13:45:58 +0800 Subject: [PATCH 5/5] fix: lint error --- packages/shared-base/src/Messages/Mask.ts | 3 ++- packages/web3-shared/evm/tsconfig.json | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/shared-base/src/Messages/Mask.ts b/packages/shared-base/src/Messages/Mask.ts index 9a69fcc4c438..cd28c9012b96 100644 --- a/packages/shared-base/src/Messages/Mask.ts +++ b/packages/shared-base/src/Messages/Mask.ts @@ -6,7 +6,8 @@ import type { NetworkType, ProviderType, FungibleAssetProvider, - NonFungibleAssetProvider, } from '@masknet/public-api' + NonFungibleAssetProvider, +} from '@masknet/public-api' import type { SerializableTypedMessages } from '@masknet/typed-message' import type { ProfileIdentifier, PersonaIdentifier } from '../Identifier/type' import type { RelationFavor } from '../Persona/type' diff --git a/packages/web3-shared/evm/tsconfig.json b/packages/web3-shared/evm/tsconfig.json index d5f05dbca89b..209fa3f77a5f 100644 --- a/packages/web3-shared/evm/tsconfig.json +++ b/packages/web3-shared/evm/tsconfig.json @@ -6,9 +6,5 @@ "tsBuildInfoFile": "../dist/evm.tsbuildinfo" }, "include": ["./", "./**/*.json"], - "references": [ - { "path": "../base" }, - { "path": "../../shared-base" }, - { "path": "../../injected-script/sdk" }, - ] + "references": [{ "path": "../base" }, { "path": "../../shared-base" }, { "path": "../../injected-script/sdk" }] }