Skip to content

Commit

Permalink
refactor: [GSW-2033] apply PR review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrg committed Jan 7, 2025
1 parent fc66b05 commit 0179bec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 1 addition & 2 deletions packages/web/src/hooks/swap/data/use-swap-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ const SwapCardContent: React.FC<ContentProps> = ({
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]);
Expand Down Expand Up @@ -177,11 +182,7 @@ const SwapCardContent: React.FC<ContentProps> = ({
<div className="amount-container">
<input
id={tokenB?.priceID}
className={`amount-text ${
(isLoading && direction === "EXACT_IN") || (isRefetching && direction === "EXACT_IN")
? "text-opacity"
: ""
}`}
className={`amount-text ${(isLoading || isRefetching) && direction === "EXACT_IN" ? "text-opacity" : ""}`}
value={tokenBAmount}
onChange={onChangeTokenBAmount}
placeholder="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ const TokenSwap: React.FC<TokenSwapProps> = ({
}
}, [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]);
Expand Down

0 comments on commit 0179bec

Please sign in to comment.