diff --git a/packages/plugins/RedPacket/src/SiteAdaptor/views/SelectCollectibles.tsx b/packages/plugins/RedPacket/src/SiteAdaptor/views/SelectCollectibles.tsx index 2f0f7d0c31e..98d0ed2de57 100644 --- a/packages/plugins/RedPacket/src/SiteAdaptor/views/SelectCollectibles.tsx +++ b/packages/plugins/RedPacket/src/SiteAdaptor/views/SelectCollectibles.tsx @@ -1,5 +1,5 @@ import { Trans } from '@lingui/react/macro' -import { AddCollectiblesModal, CollectionList, UserAssetsProvider } from '@masknet/shared' +import { AddCollectiblesModal, CollectionList, useAssetsNetworks, UserAssetsProvider } from '@masknet/shared' import { NetworkPluginID } from '@masknet/shared-base' import { makeStyles } from '@masknet/theme' import type { Web3Helper } from '@masknet/web3-helpers' @@ -7,12 +7,12 @@ import { useChainContext, useNetworkContext, useWeb3Connection, useWeb3Hub } fro import { isSameAddress } from '@masknet/web3-shared-base' import type { ChainId } from '@masknet/web3-shared-evm' import { alpha, Box, Button, DialogActions } from '@mui/material' +import { compact, uniqBy } from 'lodash-es' import { useCallback, useEffect, useMemo, useState } from 'react' import { useNavigate } from 'react-router-dom' import { NFT_DEFAULT_CHAINS, NFT_RED_PACKET_MAX_SHARES } from '../../constants.js' import { useRedPacket } from '../contexts/RedPacketContext.js' import { emitter } from '../emitter.js' -import { compact, uniqBy } from 'lodash-es' const useStyles = makeStyles()((theme) => ({ container: { @@ -48,6 +48,7 @@ export function SelectCollectibles() { const { pluginID } = useNetworkContext() const Web3 = useWeb3Connection(pluginID) const Hub = useWeb3Hub(pluginID) + const networks = useAssetsNetworks(pluginID) const { selectedNfts, setSelectedNfts, setCollection } = useRedPacket() const [pendingNfts, setPendingNfts] = useState(selectedNfts) const handleItemClick = useCallback((nft: Web3Helper.NonFungibleAssetAll) => { @@ -71,10 +72,14 @@ export function SelectCollectibles() { const [pendingTokenCount, setPendingTokenCount] = useState(0) const [tokens, setTokens] = useState([]) const handleAddCollectibles = useCallback(async () => { + const chainWhiteList = networks + .filter((x) => NFT_DEFAULT_CHAINS.includes(x.chainId as ChainId)) + .map((x) => x.chainId) const results = await AddCollectiblesModal.openAndWaitForClose({ pluginID, chainId: assetChainId || chainId, account, + chainWhiteList, }) if (!results) return const [contract, tokenIds] = results @@ -108,7 +113,7 @@ export function SelectCollectibles() { setTokens((originalTokens) => { return uniqBy([...originalTokens, ...tokens], (x) => `${x.contract?.address}.${x.tokenId}`) }) - }, [pluginID, assetChainId, chainId, account]) + }, [pluginID, assetChainId, chainId, account, networks]) const handleSelect = useCallback((assets: Web3Helper.NonFungibleAssetAll[]) => { setPendingNfts(assets.length > NFT_RED_PACKET_MAX_SHARES ? assets.slice(0, NFT_RED_PACKET_MAX_SHARES) : assets) diff --git a/packages/shared/src/UI/components/AssetsManagement/ChainRuntimeProvider.tsx b/packages/shared/src/UI/components/AssetsManagement/ChainRuntimeProvider.tsx index 9e5c9ff4a46..ff1d3afb295 100644 --- a/packages/shared/src/UI/components/AssetsManagement/ChainRuntimeProvider.tsx +++ b/packages/shared/src/UI/components/AssetsManagement/ChainRuntimeProvider.tsx @@ -1,22 +1,21 @@ import { EMPTY_LIST, NetworkPluginID } from '@masknet/shared-base' import type { Web3Helper } from '@masknet/web3-helpers' -import { CHAIN_DESCRIPTORS, ChainId, type NetworkType, type SchemaType } from '@masknet/web3-shared-evm' +import type { ReasonableNetwork } from '@masknet/web3-shared-base' +import { type ChainId } from '@masknet/web3-shared-evm' import { type ChainId as FlowChainId } from '@masknet/web3-shared-flow' -import { noop, sortBy } from 'lodash-es' import { type ChainId as SolanaChainId } from '@masknet/web3-shared-solana' -import { useNetworks } from '@masknet/web3-hooks-base' +import { noop } from 'lodash-es' import { createContext, memo, + useContext, useMemo, - type PropsWithChildren, useState, - type SetStateAction, type Dispatch, - useContext, + type PropsWithChildren, + type SetStateAction, } from 'react' -import type { ReasonableNetwork } from '@masknet/web3-shared-base' -import { SimpleHashSupportedChains } from '../../../constants.js' +import { useAssetsNetworks } from './useAssetsNetworks.js' interface ChainRuntimeOptions { pluginID: NetworkPluginID @@ -46,21 +45,13 @@ export const ChainRuntimeProvider = memo() - const allNetworks = useNetworks(pluginID, true) + const assetsNetworks = useAssetsNetworks(pluginID) const networks = useMemo(() => { - const supported = SimpleHashSupportedChains[pluginID] - const networks = allNetworks.filter( - (x) => (x.network === 'mainnet' || x.isCustomized) && supported.includes(x.chainId), - ) - // hard-coded for Zora - if (pluginID === NetworkPluginID.PLUGIN_EVM) { - const zora = CHAIN_DESCRIPTORS.find((x) => x.chainId === ChainId.Zora) - if (zora) networks.push(zora as ReasonableNetwork) - } - const list = sortBy(networks, (x) => supported.indexOf(x.chainId)) - return chainWhiteList?.length ? list.filter((x) => chainWhiteList.includes(x.chainId as ChainId)) : list - }, [allNetworks, pluginID, chainWhiteList]) + return chainWhiteList?.length ? + assetsNetworks.filter((x) => chainWhiteList.includes(x.chainId as ChainId)) + : assetsNetworks + }, [chainWhiteList, assetsNetworks]) const currentChainId = chainId ?? defaultChainId ?? (networks.length === 1 ? networks[0].chainId : chainId) diff --git a/packages/shared/src/UI/components/AssetsManagement/CollectionHeader.tsx b/packages/shared/src/UI/components/AssetsManagement/CollectionHeader.tsx index 8bbc4922400..d96b608aa3f 100644 --- a/packages/shared/src/UI/components/AssetsManagement/CollectionHeader.tsx +++ b/packages/shared/src/UI/components/AssetsManagement/CollectionHeader.tsx @@ -157,13 +157,13 @@ export const CollectionHeader = memo(function CollectionHeader({ autoFocus fullWidth value={pendingKeyword} - onKeyDown={(event: KeyboardEvent) => { - if (event.key !== 'Enter') return - setSearchKeyword(event.currentTarget.value) - }} onChange={(event) => setPendingKeyword(event.target.value)} InputProps={{ startAdornment: , + onKeyDown: (event: KeyboardEvent) => { + if (event.key !== 'Enter') return + setSearchKeyword(pendingKeyword) + }, }} />