+
+
+ {fromNano(pay_amount, pay_token?.decimal)}{' '}
+ {pay_token?.symbol}
+
+
+
+
+
+ {bestRoute!.pool_data.receive_show!} {receive_token?.symbol}
+
+ {/*
+ ≈{' '}
+ {formatNumber(
+ Number(bestRoute!.pool_data.receive_show) *
+ receive_rate!.USD,
+ 4
+ )}
+ $
+
*/}
+
+
+
-
{t("confirm.action_in_progress")}
+
{t('confirm.action_in_progress')}
+
+
+
);
};
diff --git a/lib/components/SwapCard/Card.tsx b/lib/components/SwapCard/Card.tsx
index aabee6e..e214bae 100644
--- a/lib/components/SwapCard/Card.tsx
+++ b/lib/components/SwapCard/Card.tsx
@@ -1,18 +1,19 @@
-import { ChangeEvent, CSSProperties, FC, useEffect, useState } from "react";
-import { MdKeyboardArrowDown } from "react-icons/md";
-import CardDialog from "./CardDialog";
-import { useSwapStore } from "../../store/swap.store";
-import { Asset, BestRoute, fromNano } from "@mytonswap/sdk";
-import formatNumber from "../../utils/formatNum";
-import CardButton from "./CardButton";
-import { toNano } from "@mytonswap/sdk";
-import { useWalletStore } from "../../store/wallet.store";
-import { TON_ADDR } from "../../constants";
-import "./Card.scss";
-import { useOptionsStore } from "../../store/options.store";
-import { useTranslation } from "react-i18next";
+import { ChangeEvent, CSSProperties, FC, useEffect, useState } from 'react';
+import { MdKeyboardArrowDown } from 'react-icons/md';
+import CardDialog from './CardDialog';
+import { useSwapStore } from '../../store/swap.store';
+import { Asset, BestRoute, fromNano } from '@mytonswap/sdk';
+import formatNumber from '../../utils/formatNum';
+import CardButton from './CardButton';
+import { toNano } from '@mytonswap/sdk';
+import { useWalletStore } from '../../store/wallet.store';
+import { TON_ADDR } from '../../constants';
+import './Card.scss';
+import { useOptionsStore } from '../../store/options.store';
+import { useTranslation } from 'react-i18next';
+import { cn } from '../../utils/cn';
type CardProps = {
- type: "pay" | "receive";
+ type: 'pay' | 'receive';
};
const Card: FC
= ({ type }) => {
@@ -20,7 +21,7 @@ const Card: FC = ({ type }) => {
const [isSelectVisible, setIsSelectVisible] = useState(false);
const [typingTimeout, setTypingTimeout] =
useState>();
- const [userInput, setUserInput] = useState("");
+ const [userInput, setUserInput] = useState('');
const {
setPayToken,
pay_token,
@@ -37,7 +38,7 @@ const Card: FC = ({ type }) => {
const { balance } = useWalletStore();
const { options } = useOptionsStore();
const onTokenSelect = (asset: Asset) => {
- if (type === "pay") {
+ if (type === 'pay') {
setPayToken(asset);
} else {
setReceiveToken(asset);
@@ -46,7 +47,7 @@ const Card: FC = ({ type }) => {
};
const tokenRate = (() => {
- if (type === "pay") {
+ if (type === 'pay') {
return pay_rate?.USD ?? 0;
} else {
return receive_rate?.USD ?? 0;
@@ -54,7 +55,7 @@ const Card: FC = ({ type }) => {
})();
const token = (() => {
- if (type === "pay") {
+ if (type === 'pay') {
return pay_token;
} else {
return receive_token;
@@ -64,9 +65,9 @@ const Card: FC = ({ type }) => {
const isRouteAvailable = bestRoute && bestRoute.pool_data;
const value =
- type === "pay"
+ type === 'pay'
? userInput
- : (isRouteAvailable && bestRoute?.pool_data.receive_show) ?? 0;
+ : ((isRouteAvailable && bestRoute?.pool_data.receive_show) ?? 0);
const calculatePayRate = (payAmount: bigint, tokenRate: number) =>
payAmount
@@ -88,7 +89,7 @@ const Card: FC = ({ type }) => {
: 0;
const calculatedRate =
- type === "pay"
+ type === 'pay'
? calculatePayRate(pay_amount, tokenRate)
: calculateReceiveRate(bestRoute, tokenRate);
@@ -106,11 +107,11 @@ const Card: FC = ({ type }) => {
e.preventDefault();
const decimalRegexp = /^\d*(?:\.\d{0,18})?$/; // Allow up to 18 decimal places
- let userInput = e.target.value.replace(/,/g, ".");
+ let userInput = e.target.value.replace(/,/g, '.');
// Handle empty string input
- if (userInput === "") {
- setUserInput("");
+ if (userInput === '') {
+ setUserInput('');
timeoutSetPayAmount(0n);
return;
}
@@ -118,11 +119,11 @@ const Card: FC = ({ type }) => {
// If input matches the decimal pattern
if (decimalRegexp.test(userInput)) {
// Avoid leading zeros (except for values like "0." or "0.1")
- userInput = userInput.replace(/^0+(?=\d)/, "");
+ userInput = userInput.replace(/^0+(?=\d)/, '');
// Handle case where input is exactly "0." (valid scenario)
- if (userInput === "." || userInput === "0.") {
- setUserInput("0.");
+ if (userInput === '.' || userInput === '0.') {
+ setUserInput('0.');
} else {
setUserInput(userInput);
}
@@ -137,13 +138,13 @@ const Card: FC = ({ type }) => {
};
useEffect(() => {
- if (type === "pay") {
+ if (type === 'pay') {
setUserInput(fromNano(pay_amount, pay_token?.decimal));
}
}, [pay_amount]);
const balanceToken = (() => {
- if (type === "pay") {
+ if (type === 'pay') {
return pay_token ? balance.get(pay_token.address) : null;
} else {
return receive_token ? balance.get(receive_token.address) : null;
@@ -164,54 +165,34 @@ const Card: FC = ({ type }) => {
setPayAmount(payAmount);
};
const isDisabled = (() => {
- if (type === "pay" && options.lock_pay_token) return true;
- if (type === "receive" && options.lock_receive_token) return true;
+ if (type === 'pay' && options.lock_pay_token) return true;
+ if (type === 'receive' && options.lock_receive_token) return true;
return false;
})();
return (
<>
-
-
-
- {type === "pay" ? t("you_pay") : t("you_receive")}
+
+
+
+ {type === 'pay' ? t('you_pay') : t('you_receive')}
- {type === "pay" && balanceToken ? (
-
- {t("max")} :
-
- {formatNumber(
- +fromNano(
- balanceToken.balance,
- pay_token!.decimal
- ),
- 2,
- false
- )}{" "}
- {pay_token?.symbol}
-
-
- ) : (
-
- {balanceToken && receive_token && (
-
- {formatNumber(
- +fromNano(
- balanceToken.balance,
- receive_token!.decimal
- ),
- 2,
- false
- )}{" "}
- {receive_token?.symbol}
-
- )}
-
- )}
-
-
- {((type === "receive" && !isFindingBestRoute) ||
- type === "pay") && (
+
+
+ {((type === 'receive' && !isFindingBestRoute) ||
+ type === 'pay') && (
= ({ type }) => {
autoCorrect="off"
minLength={1}
maxLength={14}
- value={value ?? ""}
+ value={value ?? ''}
disabled={
- type === "receive" || options.lock_input
+ type === 'receive' || options.lock_input
}
onChange={handlePayAmountChange}
pattern="^[0-9]*[.,]?[0-9]*$"
placeholder="0"
- className={`card-input ${type}`}
+ className={`mts-outline-none mts-bg-transparent mts-h-7 mts-w-full mts-text-black dark:mts-text-white mts-font-bold mts-font-inherit mts-text-lg md:mts-text-2xl ${type}`}
data-testid={`swapcard-input-${type}`}
/>
)}
- {type === "receive" && isFindingBestRoute && (
+ {type === 'receive' && isFindingBestRoute && (
)}
- {((type === "receive" && !isFindingBestRoute) ||
- type === "pay") && (
-
${calculatedRate}
+ {((type === 'receive' && !isFindingBestRoute) ||
+ type === 'pay') && (
+
+ {calculatedRate} $
+
)}
- {type === "receive" && isFindingBestRoute && (
+ {type === 'receive' && isFindingBestRoute && (
)}
-
+
setIsSelectVisible(true)}
isLoading={isLoading || !token}
>
{token?.symbol}
{!isDisabled && (
-
+
)}
+ {type === 'pay' ? (
+
+
+ {formatNumber(
+ +fromNano(
+ balanceToken?.balance || 0,
+ pay_token?.decimal || 0
+ ),
+ 2,
+ false
+ )}{' '}
+ {pay_token?.symbol}
+
+
+ {t('max')}
+
+
+ ) : (
+
+ {balanceToken && receive_token && (
+
+ {formatNumber(
+ +fromNano(
+ balanceToken.balance,
+ receive_token!.decimal
+ ),
+ 2,
+ false
+ )}{' '}
+ {receive_token?.symbol}
+
+ )}
+
+ )}
diff --git a/lib/components/SwapCard/CardButton.tsx b/lib/components/SwapCard/CardButton.tsx
index 7a2b734..2c22831 100644
--- a/lib/components/SwapCard/CardButton.tsx
+++ b/lib/components/SwapCard/CardButton.tsx
@@ -1,10 +1,11 @@
import { FC, PropsWithChildren } from 'react';
-import clsx from 'clsx';
import { MdKeyboardArrowDown } from 'react-icons/md';
import './CardButton.scss';
import { useOptionsStore } from '../../store/options.store';
import { useTranslation } from 'react-i18next';
import { useSwapStore } from '../../store/swap.store';
+import { cn } from '../../utils/cn';
+
type CardButtonProps = {
isLoading: boolean;
onClick: () => void;
@@ -26,6 +27,7 @@ const CardButton: FC
= ({
if (type === 'receive' && options.lock_receive_token) return true;
return false;
})();
+
return (