From 29791ab644750482b4695fb64b13bbbcf92cf1bd Mon Sep 17 00:00:00 2001 From: Lantt Date: Mon, 30 May 2022 14:29:59 +0800 Subject: [PATCH 1/5] fix: html tag wrong usage --- .../src/pages/Personas/components/PersonaLine/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx b/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx index 89ab6d457c13..47fa67208e63 100644 --- a/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx +++ b/packages/dashboard/src/pages/Personas/components/PersonaLine/index.tsx @@ -131,7 +131,7 @@ export const ConnectedPersonaLine = memo( }) return ( - + @{profile.userId} @@ -148,7 +148,7 @@ export const ConnectedPersonaLine = memo( )} )} - + ) } return ( From 03e92008d5ea52f2c32d0b57e2569de0953089e4 Mon Sep 17 00:00:00 2001 From: Lantt Date: Mon, 30 May 2022 16:21:53 +0800 Subject: [PATCH 2/5] feat: should loading owner non-fungible token after selected contact in dashboard --- .../components/Transfer/TransferERC721.tsx | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx index 4056869e28fc..85248ca838b0 100644 --- a/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx +++ b/packages/dashboard/src/pages/Wallets/components/Transfer/TransferERC721.tsx @@ -26,7 +26,7 @@ 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 { useGasConfig } from '../../hooks' import { unionBy } from 'lodash-unified' import { TransferTab } from './types' import { @@ -40,7 +40,7 @@ import { useNativeTokenPrice, } from '@masknet/plugin-infra/web3' import { RightIcon } from '@masknet/icons' -import { useGasLimit, useTokenTransferCallback } from '@masknet/plugin-infra/web3-evm' +import { useGasLimit, useNonFungibleOwnerTokens, useTokenTransferCallback } from '@masknet/plugin-infra/web3-evm' const useStyles = makeStyles()((theme) => ({ disabled: { @@ -82,7 +82,6 @@ export const TransferERC721 = memo(() => { 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 @@ -180,27 +179,23 @@ export const TransferERC721 = memo(() => { 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.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 loadingOwnerList = false - const tokenDetailedOwnerList: Array> = [] - const refreshing = false + const { + asyncRetry: { loading: loadingOwnerList }, + tokenDetailedOwnerList = [], + clearTokenDetailedOwnerList, + } = useNonFungibleOwnerTokens(contract?.address ?? '', account, chainId) const onTransfer = useCallback( async (data: FormInputs) => { @@ -360,13 +355,13 @@ export const TransferERC721 = memo(() => { name="contract" /> - {((loadingOwnerList && tokenDetailedOwnerList.length === 0) || refreshing) && ( + {loadingOwnerList && tokenDetailedOwnerList.length === 0 && ( )} - {tokenDetailedOwnerList.length > 0 && !refreshing && ( + {tokenDetailedOwnerList.length > 0 && !loadingOwnerList && ( ( From 5a930239f89593d39399d136ab4778a78075e562 Mon Sep 17 00:00:00 2001 From: Lantt Date: Mon, 30 May 2022 17:29:22 +0800 Subject: [PATCH 3/5] feat: support dashboard switch network --- .../WalletStateBar/useNetworkSelector.tsx | 28 +++++++++++++++---- .../EVM/src/state/Connection/connection.ts | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx index 48229a080206..4cff8b309fce 100644 --- a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx +++ b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx @@ -1,15 +1,17 @@ import { MenuItem, Stack, Typography } from '@mui/material' import { makeStyles } from '@masknet/theme' import { SuccessIcon } from '@masknet/icons' -import { WalletIcon, useMenu } from '@masknet/shared' +import { useMenu, WalletIcon } from '@masknet/shared' import type { NetworkPluginID } from '@masknet/web3-shared-base' import { useChainId, useNetworkDescriptors, useProviderDescriptor, + useWeb3State, useWeb3UI, Web3Helper, } from '@masknet/plugin-infra/web3' +import { useCallback } from 'react' const useStyles = makeStyles()((theme) => ({ item: { @@ -33,13 +35,31 @@ export const useNetworkSelector = (pluginID?: NetworkPluginID) => { const networkDescriptors = useNetworkDescriptors() as Web3Helper.NetworkDescriptorAll[] const Web3UI = useWeb3UI() as Web3Helper.Web3UIAll const { NetworkIconClickBait } = Web3UI.SelectNetworkMenu ?? {} + const { Connection } = useWeb3State(pluginID) as Web3Helper.Web3StateAll - const networkMenu = useMenu( + const onConnect = useCallback( + async (chainId: number) => { + if (!chainId || !Connection) throw new Error('Failed to connect to provider.') + const connection = await Connection.getConnection?.({ + providerType: providerDescriptor.type, + }) + if (!connection) throw new Error('Failed to build connection.') + + await connection.switchChain?.({ chainId }) + }, + [Connection, providerDescriptor], + ) + + return useMenu( ...(networkDescriptors ?.filter((x) => x.isMainnet) .map((network) => { const menuItem = ( - + onConnect(network.chainId)}> {network.chainId === currentChainId && } @@ -61,6 +81,4 @@ export const useNetworkSelector = (pluginID?: NetworkPluginID) => { ) }) ?? []), ) - - return networkMenu } diff --git a/packages/plugins/EVM/src/state/Connection/connection.ts b/packages/plugins/EVM/src/state/Connection/connection.ts index 62de4072dcbf..3ed1b58936f5 100644 --- a/packages/plugins/EVM/src/state/Connection/connection.ts +++ b/packages/plugins/EVM/src/state/Connection/connection.ts @@ -276,7 +276,7 @@ class Connection implements EVM_Connection { return createERC721Collection(this.chainId, address, name ?? 'Unknown Token', '') } async switchChain(options?: EVM_Web3ConnectionOptions): Promise { - throw new Error('Method not implemented.') + await Providers[this.providerType].switchChain(options?.chainId) } getNativeTokenBalance(options?: EVM_Web3ConnectionOptions): Promise { From a971b1920f4e3613118001c351b919b5cf4dc7a3 Mon Sep 17 00:00:00 2001 From: Lantt Date: Mon, 30 May 2022 17:38:04 +0800 Subject: [PATCH 4/5] feat: update chain id type --- .../Wallets/components/WalletStateBar/useNetworkSelector.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx index 4cff8b309fce..7ffcde8a2240 100644 --- a/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx +++ b/packages/dashboard/src/pages/Wallets/components/WalletStateBar/useNetworkSelector.tsx @@ -38,7 +38,7 @@ export const useNetworkSelector = (pluginID?: NetworkPluginID) => { const { Connection } = useWeb3State(pluginID) as Web3Helper.Web3StateAll const onConnect = useCallback( - async (chainId: number) => { + async (chainId: Web3Helper.ChainIdAll) => { if (!chainId || !Connection) throw new Error('Failed to connect to provider.') const connection = await Connection.getConnection?.({ providerType: providerDescriptor.type, From 810db491e4196691000cd2cd818fac6782cb07fe Mon Sep 17 00:00:00 2001 From: Lantt Date: Mon, 30 May 2022 18:17:39 +0800 Subject: [PATCH 5/5] feat: improve dashboard asset history transaction type --- .../src/pages/Wallets/components/History/index.tsx | 12 ------------ .../Wallets/components/HistoryTable/index.tsx | 4 +++- .../Wallets/components/HistoryTableRow/index.tsx | 3 ++- .../Wallets/components/TransactionIcon/index.tsx | 14 +++++++++++--- packages/web3-shared/evm/types/index.ts | 1 + 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/dashboard/src/pages/Wallets/components/History/index.tsx b/packages/dashboard/src/pages/Wallets/components/History/index.tsx index 6711e29626cf..ca94ce234dfb 100644 --- a/packages/dashboard/src/pages/Wallets/components/History/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/History/index.tsx @@ -1,25 +1,13 @@ -import { makeStyles } from '@masknet/theme' import { memo } from 'react' import { ContentContainer } from '../../../../components/ContentContainer' import { HistoryTable } from '../HistoryTable' import type { Web3Helper } from '@masknet/plugin-infra/web3' -const useStyles = makeStyles()({ - container: { - flex: 1, - padding: 0, - display: 'flex', - flexDirection: 'column', - marginBottom: '24px', - }, -}) - interface HistoryProps { selectedChainId: Web3Helper.ChainIdAll } export const History = memo(({ selectedChainId }) => { - const { classes } = useStyles() return ( diff --git a/packages/dashboard/src/pages/Wallets/components/HistoryTable/index.tsx b/packages/dashboard/src/pages/Wallets/components/HistoryTable/index.tsx index 3a45aecdfdbd..fcac5746f8e3 100644 --- a/packages/dashboard/src/pages/Wallets/components/HistoryTable/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/HistoryTable/index.tsx @@ -91,7 +91,9 @@ export const HistoryTableUI = memo( {isLoading || isEmpty ? ( {isLoading ? : null} - {isEmpty ? : null} + {isEmpty && !isLoading ? ( + + ) : null} ) : ( diff --git a/packages/dashboard/src/pages/Wallets/components/HistoryTableRow/index.tsx b/packages/dashboard/src/pages/Wallets/components/HistoryTableRow/index.tsx index 98d4df72a29a..450415e3845f 100644 --- a/packages/dashboard/src/pages/Wallets/components/HistoryTableRow/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/HistoryTableRow/index.tsx @@ -9,6 +9,7 @@ import { Box, Link, Stack, TableCell, TableRow, Typography } from '@mui/material import { TransactionIcon } from '../TransactionIcon' import type { Transaction } from '@masknet/web3-shared-base' import BigNumber from 'bignumber.js' +import fromUnixTime from 'date-fns/fromUnixTime' const useStyles = makeStyles()((theme) => ({ type: { @@ -93,7 +94,7 @@ export const HistoryTableRowUI = memo( {formattedType} - {formatDateTime(transaction.timestamp, 'yyyy-MM-dd HH:mm')} + {formatDateTime(fromUnixTime(transaction.timestamp), 'yyyy-MM-dd HH:mm')} diff --git a/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx b/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx index 26c68d834126..221e2a62354b 100644 --- a/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx +++ b/packages/dashboard/src/pages/Wallets/components/TransactionIcon/index.tsx @@ -36,13 +36,18 @@ export interface TransactionIconProps { } export const TransactionIcon = memo(({ address, failed, type, transactionType }) => { - const { HAPPY_RED_PACKET_ADDRESS_V1, HAPPY_RED_PACKET_ADDRESS_V2, HAPPY_RED_PACKET_ADDRESS_V3 } = - useRedPacketConstants() + const { + HAPPY_RED_PACKET_ADDRESS_V1, + HAPPY_RED_PACKET_ADDRESS_V2, + HAPPY_RED_PACKET_ADDRESS_V3, + HAPPY_RED_PACKET_ADDRESS_V4, + } = useRedPacketConstants() const isRedPacket = isSameAddress(HAPPY_RED_PACKET_ADDRESS_V1, address) || isSameAddress(HAPPY_RED_PACKET_ADDRESS_V2, address) || - isSameAddress(HAPPY_RED_PACKET_ADDRESS_V3, address) + isSameAddress(HAPPY_RED_PACKET_ADDRESS_V3, address) || + isSameAddress(HAPPY_RED_PACKET_ADDRESS_V4, address) return ( @@ -60,6 +65,7 @@ export const TransactionIconUI = memo(({ isFailed, isRed const { classes } = useStyles() const icon = useMemo(() => { if (isFailed) return + if (isRedPacket) return switch (type) { case TransactionType.SEND: @@ -70,6 +76,8 @@ export const TransactionIconUI = memo(({ isFailed, isRed return case TransactionType.CREATE_LUCKY_DROP: return + case TransactionType.CREATE_RED_PACKET: + return case TransactionType.FILL_POOL: return default: diff --git a/packages/web3-shared/evm/types/index.ts b/packages/web3-shared/evm/types/index.ts index 7864e505c88f..0c00db31127d 100644 --- a/packages/web3-shared/evm/types/index.ts +++ b/packages/web3-shared/evm/types/index.ts @@ -194,6 +194,7 @@ export enum TransactionType { RECEIVE = 'Receive', TRANSFER = 'transfer', CREATE_LUCKY_DROP = 'create_lucky_drop', + CREATE_RED_PACKET = 'create_red_packet', FILL_POOL = 'fill_pool', CLAIM = 'claim', REFUND = 'refund',