From 7040429a93fda9a957c0d280e619637960dede57 Mon Sep 17 00:00:00 2001 From: bal7hazar Date: Wed, 18 Dec 2024 13:20:21 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20max=20button=20to=20set=20max?= =?UTF-8?q?=20balance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/inventory/token/send.tsx | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/profile/src/components/inventory/token/send.tsx b/packages/profile/src/components/inventory/token/send.tsx index 7b208f05e..0c04cb210 100644 --- a/packages/profile/src/components/inventory/token/send.tsx +++ b/packages/profile/src/components/inventory/token/send.tsx @@ -81,6 +81,17 @@ export function SendToken() { }, }); + const handleMax = useCallback( + ( + e: React.MouseEvent | React.MouseEvent, + ) => { + e.preventDefault(); + if (!t) return; + form.setValue("amount", parseFloat(t.balance.formatted)); + }, + [t, form], + ); + const onSubmit = useCallback( async (values: z.infer) => { if (!t) return; @@ -165,11 +176,8 @@ export function SendToken() { Balance:
- form.setValue( - "amount", - parseFloat(t.balance.formatted), - ) + onClick={(e: React.MouseEvent) => + handleMax(e) } > {formatBalance(t.balance.formatted)} {t.meta.symbol} @@ -186,10 +194,19 @@ export function SendToken() { className="[&::-webkit-inner-spin-button]:appearance-none" /> {countervalue && ( - + {formatBalance(countervalue.formatted)} )} +