From 7040429a93fda9a957c0d280e619637960dede57 Mon Sep 17 00:00:00 2001 From: bal7hazar Date: Wed, 18 Dec 2024 13:20:21 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Add=20max=20button=20to=20set?= =?UTF-8?q?=20max=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)} )} +
From f98ebaa5f17d7570c91bb5b1f8c3a3fded42d36d Mon Sep 17 00:00:00 2001 From: bal7hazar Date: Wed, 18 Dec 2024 13:33:31 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=A8=20Remove=20~=20from=20balance=20a?= =?UTF-8?q?nd=20cleanup=20balance=20formatter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/inventory/token/helper.ts | 17 ++++++++--------- .../src/components/inventory/token/send.tsx | 3 ++- .../src/components/inventory/token/token.tsx | 2 +- .../src/components/inventory/token/tokens.tsx | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/profile/src/components/inventory/token/helper.ts b/packages/profile/src/components/inventory/token/helper.ts index ce71e58ce..3f45a9bb6 100644 --- a/packages/profile/src/components/inventory/token/helper.ts +++ b/packages/profile/src/components/inventory/token/helper.ts @@ -1,11 +1,10 @@ -export const formatBalance = (balance: string) => { +export const formatBalance = (balance: string, exludes?: string[]) => { // Catch prefix until number - let prefix = ""; - for (const char of balance) { - if (!isNaN(parseInt(char))) { - break; - } - prefix += char; - } - return `${prefix}${parseFloat(balance.replace(prefix, "")).toLocaleString()}`; + const prefix = balance.slice(0, balance.search(/\d/)); + // Exclude each substring from prefix + const cleaned = + exludes?.reduce((prev, curr) => prev.replace(curr, ""), prefix) ?? prefix; + return `${cleaned}${parseFloat( + balance.replace(prefix, ""), + ).toLocaleString()}`; }; diff --git a/packages/profile/src/components/inventory/token/send.tsx b/packages/profile/src/components/inventory/token/send.tsx index 0c04cb210..bd2a3ecee 100644 --- a/packages/profile/src/components/inventory/token/send.tsx +++ b/packages/profile/src/components/inventory/token/send.tsx @@ -180,7 +180,8 @@ export function SendToken() { handleMax(e) } > - {formatBalance(t.balance.formatted)} {t.meta.symbol} + {formatBalance(t.balance.formatted, ["~"])}{" "} + {t.meta.symbol} diff --git a/packages/profile/src/components/inventory/token/token.tsx b/packages/profile/src/components/inventory/token/token.tsx index cd1d2c5ac..8d0802445 100644 --- a/packages/profile/src/components/inventory/token/token.tsx +++ b/packages/profile/src/components/inventory/token/token.tsx @@ -131,7 +131,7 @@ function ERC20() { t.balance === undefined ? ( ) : ( - formatBalance(t.balance.formatted) + formatBalance(t.balance.formatted, ["~"]) ) } ${t.meta.symbol}`} description={ diff --git a/packages/profile/src/components/inventory/token/tokens.tsx b/packages/profile/src/components/inventory/token/tokens.tsx index f4bbe3980..984af72d6 100644 --- a/packages/profile/src/components/inventory/token/tokens.tsx +++ b/packages/profile/src/components/inventory/token/tokens.tsx @@ -85,7 +85,7 @@ function TokenCardContent({
-

{formatBalance(token.balance.formatted)}

+

{formatBalance(token.balance.formatted, ["~"])}

{token.meta.symbol}
From c0cd1224151040666e3af3eb81b8cf976f0f51f7 Mon Sep 17 00:00:00 2001 From: bal7hazar Date: Wed, 18 Dec 2024 13:40:24 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20Force=20token=20image=20in=20ci?= =?UTF-8?q?rcle=20with=20fixed=20size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profile/src/components/inventory/token/tokens.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/profile/src/components/inventory/token/tokens.tsx b/packages/profile/src/components/inventory/token/tokens.tsx index 984af72d6..5ad470d3f 100644 --- a/packages/profile/src/components/inventory/token/tokens.tsx +++ b/packages/profile/src/components/inventory/token/tokens.tsx @@ -77,10 +77,12 @@ function TokenCardContent({ onMouseLeave={() => setHover(false)} >
- +
+ +