From 142c0f5712980407c688700bf8c98412caa8ea89 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 10 Oct 2024 19:22:57 +0800 Subject: [PATCH] feat: tx types filter --- apps/renderer/src/models/types.ts | 2 ++ .../power/transaction-section/index.tsx | 31 ++++++++++++------- locales/settings/en.json | 11 ++++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/renderer/src/models/types.ts b/apps/renderer/src/models/types.ts index a28aca883..47b2cb1b9 100644 --- a/apps/renderer/src/models/types.ts +++ b/apps/renderer/src/models/types.ts @@ -114,3 +114,5 @@ export type ActionsInput = { webhooks?: string[] } }[] + +export const TransactionTypes = ["mint", "purchase", "tip", "withdraw"] as const diff --git a/apps/renderer/src/modules/power/transaction-section/index.tsx b/apps/renderer/src/modules/power/transaction-section/index.tsx index f65177b2d..104a9c14f 100644 --- a/apps/renderer/src/modules/power/transaction-section/index.tsx +++ b/apps/renderer/src/modules/power/transaction-section/index.tsx @@ -1,3 +1,4 @@ +import { useState } from "react" import { useTranslation } from "react-i18next" import { useWhoami } from "~/atoms/user" @@ -5,7 +6,6 @@ import { Logo } from "~/components/icons/logo" import { Avatar, AvatarFallback, AvatarImage } from "~/components/ui/avatar" import { MotionButtonBase } from "~/components/ui/button" import { RelativeTime } from "~/components/ui/datetime" -import { LoadingCircle } from "~/components/ui/loading" import { Table, TableBody, @@ -14,37 +14,46 @@ import { TableHeader, TableRow, } from "~/components/ui/table" +import { Tabs, TabsList, TabsTrigger } from "~/components/ui/tabs" import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from "~/components/ui/tooltip" import { EllipsisHorizontalTextWithTooltip } from "~/components/ui/typography" import { replaceImgUrlIfNeed } from "~/lib/img-proxy" import { cn } from "~/lib/utils" +import { TransactionTypes } from "~/models/types" import { usePresentUserProfileModal } from "~/modules/profile/hooks" import { SettingSectionTitle } from "~/modules/settings/section" import { Balance } from "~/modules/wallet/balance" import { useWallet, useWalletTransactions } from "~/queries/wallet" +const tabs = ["all", ...TransactionTypes] as const + export const TransactionsSection: Component = ({ className }) => { const { t } = useTranslation("settings") const user = useWhoami() const wallet = useWallet() const myWallet = wallet.data?.[0] - const transactions = useWalletTransactions({ fromOrToUserId: user?.id }) + const [type, setType] = useState("all") + + const transactions = useWalletTransactions({ + fromOrToUserId: user?.id, + type: type === "all" ? undefined : type, + }) if (!myWallet) return null - if (transactions.isLoading) { - return ( -
- -
- ) - } - return (
- + setType(val)}> + + {tabs.map((tab) => ( + + {t(`wallet.transactions.types.${tab}`)} + + ))} + +
diff --git a/locales/settings/en.json b/locales/settings/en.json index 576d8d58f..e405e9a5e 100644 --- a/locales/settings/en.json +++ b/locales/settings/en.json @@ -228,11 +228,12 @@ "wallet.transactions.to": "To", "wallet.transactions.tx": "Tx", "wallet.transactions.type": "Type", - "wallet.transactions.types.burn": "burn", - "wallet.transactions.types.mint": "mint", - "wallet.transactions.types.purchase": "purchase", - "wallet.transactions.types.tip": "tip", - "wallet.transactions.types.withdraw": "withdraw", + "wallet.transactions.types.all": "All", + "wallet.transactions.types.burn": "Burn", + "wallet.transactions.types.mint": "Mint", + "wallet.transactions.types.purchase": "Purchase", + "wallet.transactions.types.tip": "Tip", + "wallet.transactions.types.withdraw": "Withdraw", "wallet.transactions.you": "You", "wallet.withdraw.addressLabel": "Your Ethereum Address", "wallet.withdraw.amountLabel": "Amount",