From ab938187c8ee645227a42d90614c26fbefe3e6ee Mon Sep 17 00:00:00 2001 From: Wukong Sun Date: Sat, 12 Oct 2024 10:42:39 +0800 Subject: [PATCH] feat: mf-6319 refine wallet activities ui --- .../pages/Wallet/TransactionDetail/index.tsx | 7 ++ .../components/ActivityList/ActivityItem.tsx | 4 +- .../Wallet/components/ActivityList/index.tsx | 78 ++++++++++++------- 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/packages/mask/popups/pages/Wallet/TransactionDetail/index.tsx b/packages/mask/popups/pages/Wallet/TransactionDetail/index.tsx index 4e15cbb42016..07e2ef4f56ab 100644 --- a/packages/mask/popups/pages/Wallet/TransactionDetail/index.tsx +++ b/packages/mask/popups/pages/Wallet/TransactionDetail/index.tsx @@ -22,6 +22,7 @@ import { import { Box, Link, Typography, alpha } from '@mui/material' import { useQuery } from '@tanstack/react-query' import { BigNumber } from 'bignumber.js' +import { format } from 'date-fns' import { capitalize } from 'lodash-es' import { memo, useCallback } from 'react' import { Navigate, useLocation } from 'react-router-dom' @@ -349,6 +350,12 @@ export const Component = memo(function TransactionDetail() { : ''} + + Time + + {tx ? format(tx.block_timestamp, 'MMM-dd-yyyy hh:mm:ss aa OOO').replace('GMT', 'UTC') : '--'} + + {logs.length ? <> diff --git a/packages/mask/popups/pages/Wallet/components/ActivityList/ActivityItem.tsx b/packages/mask/popups/pages/Wallet/components/ActivityList/ActivityItem.tsx index c2c678c92e7a..fba470138ef7 100644 --- a/packages/mask/popups/pages/Wallet/components/ActivityList/ActivityItem.tsx +++ b/packages/mask/popups/pages/Wallet/components/ActivityList/ActivityItem.tsx @@ -33,8 +33,8 @@ import { import { Box, ListItem, ListItemText, Skeleton, Typography, alpha, type ListItemProps } from '@mui/material' import { useQuery } from '@tanstack/react-query' import { memo, useMemo, type JSX } from 'react' -import { formatTokenBalance } from '../../../../../shared/index.js' import { MaskSharedTrans, useMaskSharedTrans } from '../../../../../shared-ui/index.js' +import { formatTokenBalance } from '../../../../../shared/index.js' import { parseAmountFromERC20ApproveInput, parseReceiverFromERC20TransferInput } from '../../utils.js' const useStyles = makeStyles<{ cateType?: string }>()((theme, { cateType = '' }, __) => { @@ -46,7 +46,7 @@ const useStyles = makeStyles<{ cateType?: string }>()((theme, { cateType = '' }, const backgroundColorMap: Record = { send: alpha(theme.palette.maskColor.warn, 0.1), receive: alpha(theme.palette.maskColor.success, 0.1), - default: alpha(theme.palette.maskColor.success, 0.1), + default: alpha(theme.palette.maskColor.primary, 0.1), } const boxShadowMap: Record = { send: alpha(theme.palette.maskColor.warn, 0.2), diff --git a/packages/mask/popups/pages/Wallet/components/ActivityList/index.tsx b/packages/mask/popups/pages/Wallet/components/ActivityList/index.tsx index 30f361cd44ab..ba11ab48da00 100644 --- a/packages/mask/popups/pages/Wallet/components/ActivityList/index.tsx +++ b/packages/mask/popups/pages/Wallet/components/ActivityList/index.tsx @@ -3,16 +3,17 @@ import { PopupRoutes } from '@masknet/shared-base' import { makeStyles } from '@masknet/theme' import type { RecentTransaction, Transaction } from '@masknet/web3-shared-base' import { type ChainId, type Transaction as EvmTransaction, type SchemaType } from '@masknet/web3-shared-evm' -import { List } from '@mui/material' -import { range } from 'lodash-es' -import { memo, useCallback } from 'react' +import { List, Typography } from '@mui/material' +import { format } from 'date-fns' +import { groupBy, range } from 'lodash-es' +import { Fragment, memo, useCallback, useMemo } from 'react' import { useNavigate } from 'react-router-dom' +import { useMaskSharedTrans } from '../../../../../shared-ui/index.js' +import { useHasNavigator } from '../../../../hooks/useHasNavigator.js' import { ReplaceType } from '../../type.js' +import { modifyTransaction } from '../../utils.js' import { ActivityItem, ActivityItemSkeleton, RecentActivityItem } from './ActivityItem.js' import { useTransactions } from './useTransactions.js' -import { modifyTransaction } from '../../utils.js' -import { useMaskSharedTrans } from '../../../../../shared-ui/index.js' -import { useHasNavigator } from '../../../../hooks/useHasNavigator.js' const useStyles = makeStyles<{ hasNav?: boolean }>()((theme, { hasNav }) => ({ container: { @@ -25,11 +26,14 @@ const useStyles = makeStyles<{ hasNav?: boolean }>()((theme, { hasNav }) => ({ list: { backgroundColor: theme.palette.maskColor.bottom, padding: theme.spacing(2), + display: 'flex', + flexDirection: 'column', + gap: theme.spacing(1.5), }, - item: { - '&:not(:last-of-type)': { - marginBottom: theme.spacing(1.5), - }, + day: { + color: theme.palette.maskColor.second, + fontSize: 14, + lineHeight: '18px', }, })) @@ -40,6 +44,15 @@ export const ActivityList = memo(function ActivityList() { const navigate = useNavigate() const [{ transactions, localeTxes }, { isPending, isFetching, fetchNextPage }] = useTransactions() + const transactionGroups = useMemo( + () => Object.entries(groupBy(transactions, (tx) => format(tx.timestamp, 'MMM dd, yyyy'))), + [transactions], + ) + const localeTxGroups = useMemo( + () => Object.entries(groupBy(localeTxes, (tx) => format(tx.createdAt, 'MMM dd, yyyy'))), + [localeTxes], + ) + const handleSpeedup = useCallback(async (transaction: RecentTransaction) => { modifyTransaction(transaction, ReplaceType.SPEED_UP) }, []) @@ -68,24 +81,33 @@ export const ActivityList = memo(function ActivityList() { return (
- {localeTxes.map((transaction) => ( - - ))} - {transactions?.map((transaction) => ( - - ))} - {isFetching ? range(4).map((i) => ) : null} + {localeTxGroups.map(([day, txes]) => { + return ( + + {day} + {txes.map((transaction) => ( + + ))} + + ) + })} + {transactionGroups.map(([day, txes]) => { + return ( + + {day} + {txes.map((transaction) => ( + + ))} + + ) + })} + {isFetching ? range(4).map((i) => ) : null} fetchNextPage()} key={transactions?.length} height={10} />