Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix: swap page and coin input (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio committed May 19, 2022
1 parent 3758e15 commit 3264c1d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/scripts/build-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ forc build -p $TOKEN_CONTRACT
echo "Build Types for contract"
npx typechain --target fuels --out-dir=./src/types/contracts '../contracts/**/out/debug/**.json'
echo "Prettify codes"
npm run prettier-format
npx prettier --write src/types
3 changes: 3 additions & 0 deletions client/src/components/CoinInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function useCoinInput({
showBalance = true,
coin,
gasFee,
onInput,
...params
}: UseCoinParams) {
const [amount, setAmount] = useState<bigint | null>(null);
Expand All @@ -96,6 +97,7 @@ export function useCoinInput({
isReadOnly,
value: formatValue(amount),
displayType: (isReadOnly ? "text" : "input") as DisplayType,
onInput,
onChange: (val: string) => {
if (isReadOnly) return;
const next = val !== "" ? parseValueBigInt(val) : null;
Expand All @@ -105,6 +107,7 @@ export function useCoinInput({
return parseValueBigInt(value) <= MAX_U64_VALUE;
},
setMaxBalance: () => {
onInput?.();
setAmount(getSafeMaxBalance());
},
balance: formatValue(coinBalance?.amount || BigInt(0)),
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/SwapPage/SwapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function SwapComponent({
}, [fromInput.amount, toInput.amount, coinFrom, coinTo]);

useEffect(() => {
if (!previewValue) return;
if (previewValue == null) return;
if (activeInput.current === ActiveInput.from) {
toInput.setAmount(previewValue);
} else {
Expand Down
7 changes: 6 additions & 1 deletion client/src/pages/SwapPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export default function SwapPage() {
);

const shouldDisableButton =
isLoading || isSwaping || !swapState || !hasLiquidity || !previewAmount;
isLoading ||
isSwaping ||
!swapState ||
!hasLiquidity ||
!previewAmount ||
!swapState.amount;

const getButtonText = () => {
if (!hasLiquidity) return "Insufficient liquidity";
Expand Down

0 comments on commit 3264c1d

Please sign in to comment.