feat: withdraw as rss3
This commit is contained in:
@@ -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<z.infer<typeof formSchema>>({
|
||||
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 }) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="toRss3"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<div className="flex items-center gap-2">
|
||||
<FormLabel>{t("wallet.withdraw.toRss3Label")}</FormLabel>
|
||||
<FormControl className="!mt-0">
|
||||
<span className="inline-flex">
|
||||
<Switch checked={field.value} onCheckedChange={field.onChange} />
|
||||
</span>
|
||||
</FormControl>
|
||||
</div>
|
||||
<div className="w-full text-xs text-gray-500">
|
||||
1 POWER = {powerPrice.data?.rss3 ?? "-"} RSS3
|
||||
</div>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="center flex">
|
||||
<Button disabled={!form.formState.isValid} type="submit" isLoading={mutation.isPending}>
|
||||
{t("wallet.withdraw.submitButton")}
|
||||
|
||||
@@ -378,5 +378,6 @@
|
||||
"wallet.withdraw.error": "Withdrawal failed: {{error}}",
|
||||
"wallet.withdraw.modalTitle": "Withdraw Power",
|
||||
"wallet.withdraw.submitButton": "Submit",
|
||||
"wallet.withdraw.success": "Withdrawal successful!"
|
||||
"wallet.withdraw.success": "Withdrawal successful!",
|
||||
"wallet.withdraw.toRss3Label": "Withdraw as RSS3"
|
||||
}
|
||||
|
||||
@@ -11967,6 +11967,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
json: {
|
||||
amount: string;
|
||||
address: string;
|
||||
toRss3?: boolean | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
@@ -12070,6 +12071,20 @@ declare const _routes: hono_hono_base.HonoBase<Env, ({
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
} & {
|
||||
"/power-price": {
|
||||
$get: {
|
||||
input: {};
|
||||
output: {
|
||||
code: 0;
|
||||
data: {
|
||||
rss3: number;
|
||||
};
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
};
|
||||
};
|
||||
}, "/wallets"> | hono_types.MergeSchemaPath<{
|
||||
"/": {
|
||||
$get: {
|
||||
|
||||
Reference in New Issue
Block a user