From 0179bec33469349e054d2acf458eae87d3415ac2 Mon Sep 17 00:00:00 2001 From: yjin Date: Tue, 7 Jan 2025 16:26:47 +0900 Subject: [PATCH] refactor: [GSW-2033] apply PR review feedback --- packages/web/src/hooks/swap/data/use-swap-handler.tsx | 3 +-- .../swap-card/swap-card-content/SwapCardContent.tsx | 11 ++++++----- .../token-detail/components/token-swap/TokenSwap.tsx | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/web/src/hooks/swap/data/use-swap-handler.tsx b/packages/web/src/hooks/swap/data/use-swap-handler.tsx index e47a6af0c..cfe476f7a 100644 --- a/packages/web/src/hooks/swap/data/use-swap-handler.tsx +++ b/packages/web/src/hooks/swap/data/use-swap-handler.tsx @@ -106,8 +106,7 @@ function handleAmount(changed: string, token: TokenModel | null) { const decimals = token?.decimals || 0; // Check if input exceeds decimal places - const parts = changed.split("."); - if (parts.length > 1 && parts[1].length > decimals) { + if (changed.includes(".") && changed.split(".")[1].length > decimals) { // Signal invalid input return { isValid: false, value: changed }; } diff --git a/packages/web/src/layouts/swap/components/swap-card/swap-card-content/SwapCardContent.tsx b/packages/web/src/layouts/swap/components/swap-card/swap-card-content/SwapCardContent.tsx index d02741365..c60ffd61c 100644 --- a/packages/web/src/layouts/swap/components/swap-card/swap-card-content/SwapCardContent.tsx +++ b/packages/web/src/layouts/swap/components/swap-card/swap-card-content/SwapCardContent.tsx @@ -121,6 +121,11 @@ const SwapCardContent: React.FC = ({ return swapTokenInfo.tokenBAmount; }, [swapTokenInfo.tokenBAmount, tokenB?.decimals]); + /** + * Ensure tokenABalance is a valid value (not empty (“-”) or zero) + * Note: Consider using includes when you have more than 3 comparisons + * return !(["-", "0", "undefined"].includes(swapTokenInfo.tokenABalance)); + */ const hasTokenABalance = useMemo(() => { return swapTokenInfo.tokenABalance !== "-" && swapTokenInfo.tokenABalance !== "0"; }, [swapTokenInfo.tokenABalance]); @@ -177,11 +182,7 @@ const SwapCardContent: React.FC = ({
= ({ } }, [changeTokenAAmount, connected, dataTokenInfo]); + /** + * Ensure tokenABalance is a valid value (not empty (“-”) or zero) + * Note: Consider using includes when you have more than 3 comparisons + * return !(["-", "0", "undefined"].includes(swapTokenInfo.tokenABalance)); + */ const hasTokenABalance = useMemo(() => { return swapTokenInfo.tokenABalance !== "-" && swapTokenInfo.tokenABalance !== "0"; }, [swapTokenInfo.tokenABalance]);