From 5af9cf5ec7767ea440b85afbc8ad46dd283c4dc6 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 2 Jan 2025 18:35:04 +0800 Subject: [PATCH] feat: withdraw as rss3 --- .../power/my-wallet-section/withdraw.tsx | 42 ++++++++++++++++++- locales/settings/en.json | 3 +- packages/shared/src/hono.ts | 15 +++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/apps/renderer/src/modules/power/my-wallet-section/withdraw.tsx b/apps/renderer/src/modules/power/my-wallet-section/withdraw.tsx index 30d9de570..67be4840a 100644 --- a/apps/renderer/src/modules/power/my-wallet-section/withdraw.tsx +++ b/apps/renderer/src/modules/power/my-wallet-section/withdraw.tsx @@ -8,6 +8,7 @@ import { FormMessage, } from "@follow/components/ui/form/index.jsx" import { Input } from "@follow/components/ui/input/index.js" +import { Switch } from "@follow/components/ui/switch/index.js" import { cn } from "@follow/utils/utils" import { zodResolver } from "@hookform/resolvers/zod" import { useMutation } from "@tanstack/react-query" @@ -19,7 +20,9 @@ import { toast } from "sonner" import { z } from "zod" import { useModalStack } from "~/components/ui/modal/stacked/hooks" +import { useAuthQuery } from "~/hooks/common/useBizQuery" import { apiClient } from "~/lib/api-fetch" +import { defineQuery } from "~/lib/defineQuery" import { Balance } from "~/modules/wallet/balance" import { useWallet, wallet as walletActions } from "~/queries/wallet" @@ -50,19 +53,36 @@ const WithdrawModalContent = ({ dismiss }: { dismiss: () => void }) => { const formSchema = z.object({ address: z.string().startsWith("0x").length(42), amount: z.number().positive().max(cashablePowerTokenNumber), + toRss3: z.boolean().optional(), }) const form = useForm>({ resolver: zodResolver(formSchema), }) + const powerPrice = useAuthQuery( + defineQuery(["power-price"], async () => { + const res = await apiClient.wallets["power-price"].$get() + return res.data + }), + ) + const mutation = useMutation({ - mutationFn: async ({ address, amount }: { address: string; amount: number }) => { + mutationFn: async ({ + address, + amount, + toRss3, + }: { + address: string + amount: number + toRss3?: boolean + }) => { const amountBigInt = from(amount, 18)[0] await apiClient.wallets.transactions.withdraw.$post({ json: { address, amount: amountBigInt.toString(), + toRss3, }, }) }, @@ -134,6 +154,26 @@ const WithdrawModalContent = ({ dismiss }: { dismiss: () => void }) => { )} /> + ( + +
+ {t("wallet.withdraw.toRss3Label")} + + + + + +
+
+ 1 POWER = {powerPrice.data?.rss3 ?? "-"} RSS3 +
+ +
+ )} + />