data?.description && setIsOpen(prevState => !prevState)}>
@@ -30,7 +35,7 @@ const TransactionsTable = ({data}) => {
{t("history.balanceChange")}
-
{new BN(data?.balanceChange).isGreaterThan(0) && "+"}{new BN(data?.balanceChange).toFormat()}
+
{new BN(data?.balanceChange).isGreaterThan(0) && "+"}{formatWithPrecision(data?.balanceChange, currencies[data?.currency].precision)}
{data?.currency}
@@ -41,7 +46,7 @@ const TransactionsTable = ({data}) => {
{t("history.balance")}
- {new BN(data?.balance).toFormat()}
+ {formatWithPrecision(data?.balance, currencies[data?.currency].precision)}
{data?.currency}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistory/WithdrawHistory.js b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistory/WithdrawHistory.js
index 0f18996..f6065a8 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistory/WithdrawHistory.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistory/WithdrawHistory.js
@@ -13,11 +13,16 @@ import TextInput from "../../../../../../../../../../components/TextInput/TextIn
import DatePanel from "react-multi-date-picker/plugins/date_panel";
import ToggleSwitch from "../../../../../../../../../../components/ToggleSwitch/ToggleSwitch";
import Button from "../../../../../../../../../../components/Button/Button";
+import i18n from "i18next";
+import {getCurrencyNameOrAlias} from "../../../../../../../../../../utils/utils";
const WithdrawHistory = () => {
const {t} = useTranslation();
const coins = useSelector((state) => state.exchange.assets)
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
const [query, setQuery] = useState({
"currency": null, // optional
"category": null, // optional [DEPOSIT, FEE, TRADE, WITHDRAW, ORDER_CANCEL, ORDER_CREATE, ORDER_FINALIZED]
@@ -51,8 +56,8 @@ const WithdrawHistory = () => {
categoryOptions.push({value: o, label: t('TransactionCategory.' + o)})
})
- coins.forEach((o) => {
- currenciesOptions.push({value: o, label: t('currency.' + o)})
+ Object.keys(currencies).forEach((o) => {
+ currenciesOptions.push({value: o, label: getCurrencyNameOrAlias(currencies[o], language)})
})
@@ -131,7 +136,7 @@ const WithdrawHistory = () => {
type="select"
value={{
value: query?.currency,
- label: query?.currency ? t('currency.'+ query?.currency) : t('all'),
+ label: query?.currency ? getCurrencyNameOrAlias(currencies[query?.currency], language) : t('all'),
}}
onchange={(e) => setQuery({...query, currency: e.value, offset:0})}
customClass={`width-100 my-1 ${classes.thisInput}`}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistoryTable/WithdrawHistoryTable.js b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistoryTable/WithdrawHistoryTable.js
index 5088b5e..9cc53b7 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistoryTable/WithdrawHistoryTable.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/History/components/WithdrawHistoryTable/WithdrawHistoryTable.js
@@ -4,16 +4,20 @@ import {useTranslation} from "react-i18next";
import {toast} from "react-hot-toast";
import Date from "../../../../../../../../../../components/Date/Date";
import moment from "moment-jalaali";
-import {BN, shortenHash} from "../../../../../../../../../../utils/utils";
+import {BN, formatWithPrecision, shortenHash} from "../../../../../../../../../../utils/utils";
import Button from "../../../../../../../../../../components/Button/Button";
import {useGetWithdrawHistory} from "../../../../../../../../../../queries";
import {cancelWithdrawReq} from "js-api-client";
import Loading from "../../../../../../../../../../components/Loading/Loading";
import Icon from "../../../../../../../../../../components/Icon/Icon";
+import i18n from "i18next";
+import {useSelector} from "react-redux";
const WithdrawHistoryTable = ({data, query}) => {
const {t} = useTranslation();
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
const [isOpen, setIsOpen] = useState(false);
const [isLoading, setIsLoading] = useState(false)
@@ -59,15 +63,15 @@ const WithdrawHistoryTable = ({data, query}) => {
{moment.utc(data?.createDate).local().format("HH:mm:ss")}
-
{t("HistoryStatus."+ data?.status)}
+
{t("withdrawStatus."+ data?.status)}
{/*
{moment(data?.date).format("HH:mm:ss")}*/}
-
{data?.network}
+
{data?.destNetwork}
-
{new BN(data?.amount).toFormat()}
+
{formatWithPrecision(data?.amount, currencies[data?.currency].precision)}
{data?.currency}
@@ -99,7 +103,7 @@ const WithdrawHistoryTable = ({data, query}) => {
{t("history.appliedFee")}
{ data?.appliedFee ?
-
{new BN(data?.amount).toFormat()}
+
{formatWithPrecision(data?.appliedFee, currencies[data.currency].precision)}
{data?.currency}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/LastTrades/components/LastTradesTable/LastTradesTable.js b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/LastTrades/components/LastTradesTable/LastTradesTable.js
index f5d4c71..6362f17 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/LastTrades/components/LastTradesTable/LastTradesTable.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/LastTrades/components/LastTradesTable/LastTradesTable.js
@@ -6,10 +6,15 @@ import {useSelector} from "react-redux";
import ScrollBar from "../../../../../../../../../../../../components/ScrollBar";
import {BN} from "../../../../../../../../../../../../utils/utils";
import Date from "../../../../../../../../../../../../components/Date/Date";
+import i18n from "i18next";
const LastTradesTable = ({data}) => {
const {t} = useTranslation();
const activePair = useSelector((state) => state.exchange.activePair)
+
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
return (
@@ -37,9 +42,9 @@ const LastTradesTable = ({data}) => {
|
{moment(tr.time).format("HH:mm:ss")} |
- {amount.decimalPlaces(activePair.baseAssetPrecision).toFormat()} |
- {pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toFormat()} |
- {totalPrice.decimalPlaces(activePair.quoteAssetPrecision).toFormat()} |
+ {amount.decimalPlaces(currencies[activePair.baseAsset].precision).toFormat()} |
+ {pricePerUnit.decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()} |
+ {totalPrice.decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()} |
);
})}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OpenOrders/OpenOrders.js b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OpenOrders/OpenOrders.js
index 6cd9235..e9ed29f 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OpenOrders/OpenOrders.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OpenOrders/OpenOrders.js
@@ -5,13 +5,14 @@ import {useTranslation} from "react-i18next";
import {useSelector} from "react-redux";
import Loading from "../../../../../../../../../../../../components/Loading/Loading";
import ScrollBar from "../../../../../../../../../../../../components/ScrollBar";
-import {BN} from "../../../../../../../../../../../../utils/utils";
+import {BN, getCurrencyNameOrAlias} from "../../../../../../../../../../../../utils/utils";
import {toast} from "react-hot-toast";
import Error from "../../../../../../../../../../../../components/Error/Error";
import {useMyOpenOrders} from "../../../../../../../../../../../../queries";
import {cancelOrderByOrderID} from "js-api-client";
import Date from "../../../../../../../../../../../../components/Date/Date";
import Button from "../../../../../../../../../../../../components/Button/Button";
+import i18n from "i18next";
const OpenOrders = () => {
@@ -22,6 +23,9 @@ const OpenOrders = () => {
const activePair = useSelector((state) => state.exchange.activePair)
const lastTransaction = useSelector((state) => state.auth.lastTransaction);
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
const {data, isLoading, error, refetch} = useMyOpenOrders(activePair.symbol)
useEffect(() => {
@@ -63,8 +67,8 @@ const OpenOrders = () => {
{t("volume")}:
- {origQty.decimalPlaces(activePair.baseAssetPrecision).toFormat()}
- {t("currency." + activePair.baseAsset.toUpperCase())}
+ {origQty.decimalPlaces(currencies[activePair.baseAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.baseAsset.toUpperCase()], language)}
@@ -78,8 +82,8 @@ const OpenOrders = () => {
{t("totalPrice")}:
- {totalPrice.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}
- {t("currency." + activePair.quoteAsset.toUpperCase())}
+ {totalPrice.decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.quoteAsset.toUpperCase()], language)}
@@ -89,8 +93,8 @@ const OpenOrders = () => {
{t("pricePerUnit")}:
- {pricePerUnit.decimalPlaces(activePair.quoteAssetPrecision).toFormat()}
- {t("currency." + activePair.quoteAsset.toUpperCase())}
+ {pricePerUnit.decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.quoteAsset.toUpperCase()], language)}
@@ -105,7 +109,7 @@ const OpenOrders = () => {
{t("myOrders.tradedAmount")}:
- {executedQty.decimalPlaces(activePair.baseAssetPrecision).toFormat()}
+ {executedQty.decimalPlaces(currencies[activePair.baseAsset].precision).toFormat()}
@@ -120,7 +124,7 @@ const OpenOrders = () => {
{t("myOrders.tradedPrice")}:
- {executedQty.multipliedBy(pricePerUnit).decimalPlaces(activePair.baseAssetPrecision).toFormat()}
+ {executedQty.multipliedBy(pricePerUnit).decimalPlaces(currencies[activePair.baseAsset].precision).toFormat()}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OrdersHistory/OrdersHistory.js b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OrdersHistory/OrdersHistory.js
index 0267921..9db3185 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OrdersHistory/OrdersHistory.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/OrdersHistory/OrdersHistory.js
@@ -8,6 +8,8 @@ import ScrollBar from "../../../../../../../../../../../../components/ScrollBar"
import {useMyOrderHistory} from "../../../../../../../../../../../../queries";
import Error from "../../../../../../../../../../../../components/Error/Error";
import Date from "../../../../../../../../../../../../components/Date/Date";
+import {BN, getCurrencyNameOrAlias} from "../../../../../../../../../../../../utils/utils";
+import i18n from "i18next";
const OrdersHistory = () => {
const {t} = useTranslation();
@@ -16,6 +18,9 @@ const OrdersHistory = () => {
const activePair = useSelector((state) => state.exchange.activePair)
const lastTransaction = useSelector((state) => state.auth.lastTransaction);
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
const {data, isLoading, error, refetch} = useMyOrderHistory(activePair.symbol)
useEffect(() => {
@@ -46,8 +51,8 @@ const OrdersHistory = () => {
{t("volume")}:
- {tr.origQty}
- {t("currency." + activePair.baseAsset.toUpperCase())}
+ {new BN(tr.origQty).decimalPlaces(currencies[activePair.baseAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.baseAsset.toUpperCase()], language)}
@@ -56,22 +61,18 @@ const OrdersHistory = () => {
{t("totalPrice")}:
- {(tr.origQty * tr.price).toLocaleString()}
- {t("currency." + activePair.quoteAsset.toUpperCase())}
+ {new BN(tr.origQty).multipliedBy(tr.price).decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.quoteAsset.toUpperCase()], language)}
-
-
-
-
{t("pricePerUnit")}:
-
- {tr.price.toLocaleString()}
- {t("currency." + activePair.quoteAsset.toUpperCase())}
-
-
+
{t("pricePerUnit")}:
+
+ {new BN(tr.price).decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.quoteAsset.toUpperCase()], language)}
+
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/Trades/Trades.js b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/Trades/Trades.js
index 4ed062d..cb8b902 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/Trades/Trades.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/MyOrder/components/Trades/Trades.js
@@ -8,7 +8,8 @@ import ScrollBar from "../../../../../../../../../../../../components/ScrollBar"
import Error from "../../../../../../../../../../../../components/Error/Error";
import {useMyTrades} from "../../../../../../../../../../../../queries";
import Date from "../../../../../../../../../../../../components/Date/Date";
-import {BN} from "../../../../../../../../../../../../utils/utils";
+import {BN, formatWithPrecision, getCurrencyNameOrAlias} from "../../../../../../../../../../../../utils/utils";
+import i18n from "i18next";
const Trades = () => {
@@ -21,6 +22,9 @@ const Trades = () => {
const {data, isLoading, error, refetch} = useMyTrades(activePair.symbol)
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
useEffect(() => {
refetch()
}, [lastTransaction])
@@ -48,8 +52,8 @@ const Trades = () => {
{t("volume")}:
- {tr.qty}
- {t("currency." + activePair.baseAsset.toUpperCase())}
+ {new BN(tr.qty).decimalPlaces(currencies[activePair.baseAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.baseAsset.toUpperCase()], language)}
@@ -57,19 +61,17 @@ const Trades = () => {
{t("totalPrice")}:
- {(tr.qty * tr.price).toLocaleString()}
- {t("currency." + activePair.quoteAsset.toUpperCase())}
+ {new BN(tr.qty).multipliedBy(tr.price).decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.quoteAsset.toUpperCase()], language)}
-
-
{t("pricePerUnit")}:
- {(tr.price)}
- {t("currency." + activePair.quoteAsset.toUpperCase())}
+ {new BN(tr.price).decimalPlaces(currencies[activePair.quoteAsset].precision).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair.quoteAsset.toUpperCase()], language)}
@@ -82,8 +84,8 @@ const Trades = () => {
{t("commission")}:
- {new BN(tr.commission).toFormat()}
- {t("currency." + tr.commissionAsset.toUpperCase())}
+ {formatWithPrecision(tr.commission, currencies[tr.commissionAsset.toUpperCase()].precision)}
+ {getCurrencyNameOrAlias(currencies[tr.commissionAsset.toUpperCase()], language)}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/Order/components/BuyOrder/BuyOrder.js b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/Order/components/BuyOrder/BuyOrder.js
index 5abea37..015fd21 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/Order/components/BuyOrder/BuyOrder.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/Content/components/Market/components/Order/components/BuyOrder/BuyOrder.js
@@ -3,7 +3,12 @@ import classes from "../../Order.module.css";
import {Trans, useTranslation} from "react-i18next";
import {setLastTransaction} from "../../../../../../../../../../../../store/actions/auth";
import {useDispatch, useSelector} from "react-redux";
-import {BN, parsePriceString} from "../../../../../../../../../../../../utils/utils";
+import {
+ BN,
+ formatWithPrecision,
+ getCurrencyNameOrAlias,
+ parsePriceString
+} from "../../../../../../../../../../../../utils/utils";
import {useNavigate} from "react-router-dom";
import Button from "../../../../../../../../../../../../components/Button/Button";
import {Login as LoginRoute} from "../../../../../../../../../../Routes/routes";
@@ -12,6 +17,7 @@ import {images} from "../../../../../../../../../../../../assets/images";
import {createOrder} from "../../api/order";
import {useGetUserAccount} from "../../../../../../../../../../../../queries/hooks/useGetUserAccount";
import NumberInput from "../../../../../../../../../../../../components/NumberInput/NumberInput";
+import i18n from "i18next";
const BuyOrder = () => {
@@ -31,6 +37,9 @@ const BuyOrder = () => {
const tradeFee = useSelector((state) => state.auth.tradeFee)
const isLogin = useSelector((state) => state.auth.isLogin)
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
const quote = userAccount?.wallets[activePair.quoteAsset]?.free || 0;
const [alert, setAlert] = useState({
@@ -75,26 +84,27 @@ const BuyOrder = () => {
}, [activePair])
const currencyValidator = (key, val, rule) => {
- if (!val.isZero() && val.isLessThan(rule.min)) {
+
+ if (!val.isZero() && val.isLessThan(currencies[rule].minOrder)) {
return setAlert({
...alert,
[key]: (
),
});
}
- if (!val.mod(rule.step).isZero()) {
+ if (!val.mod(currencies?.[rule]?.step).isZero()) {
return setAlert({
...alert,
[key]: (
)
})
}
@@ -106,12 +116,12 @@ const BuyOrder = () => {
switch (key) {
case "reqAmount":
const reqAmount = new BN(value);
- currencyValidator("reqAmount", reqAmount, activePair.baseRange);
+ currencyValidator("reqAmount", reqAmount, activePair.baseAsset);
setOrder({
...order,
reqAmount,
- totalPrice: reqAmount.multipliedBy(order.pricePerUnit).decimalPlaces(activePair.quoteAssetPrecision),
- tradeFee: reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(activePair.baseAssetPrecision),
+ totalPrice: reqAmount.multipliedBy(order.pricePerUnit).decimalPlaces(currencies[activePair.quoteAsset].precision),
+ tradeFee: reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(currencies[activePair.baseAsset].precision),
});
break;
case "pricePerUnit":
@@ -119,20 +129,20 @@ const BuyOrder = () => {
setOrder({
...order,
pricePerUnit: pricePerUnit,
- totalPrice: pricePerUnit.multipliedBy(order.reqAmount).decimalPlaces(activePair.quoteAssetPrecision),
- tradeFee: order.reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(activePair.baseAssetPrecision),
+ totalPrice: pricePerUnit.multipliedBy(order.reqAmount).decimalPlaces(currencies[activePair.quoteAsset].precision),
+ tradeFee: order.reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(currencies[activePair.baseAsset].precision),
});
break;
case "totalPrice":
const totalPrice = new BN(value);
- const req = totalPrice.dividedBy(order.pricePerUnit).decimalPlaces(activePair.baseAssetPrecision);
+ const req = totalPrice.dividedBy(order.pricePerUnit).decimalPlaces(currencies[activePair.baseAsset].precision);
setOrder({
...order,
reqAmount: req.isFinite() ? req : new BN(0),
totalPrice,
- tradeFee: req.isFinite() ? req.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(activePair.baseAssetPrecision) : new BN(0),
+ tradeFee: req.isFinite() ? req.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(currencies[activePair.baseAsset].precision) : new BN(0),
});
- currencyValidator("reqAmount", req, activePair.baseRange);
+ currencyValidator("reqAmount", req, activePair.baseAsset);
break;
default:
}
@@ -154,7 +164,7 @@ const BuyOrder = () => {
useEffect(() => {
setOrder((prevState) => ({
...order,
- tradeFee: prevState.totalPrice.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(activePair.baseAssetPrecision),
+ tradeFee: prevState.totalPrice.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(currencies[activePair.baseAsset].precision),
}));
}, [tradeFee]);
@@ -172,10 +182,10 @@ const BuyOrder = () => {
...order,
reqAmount,
pricePerUnit: pricePerUnit,
- totalPrice: reqAmount.multipliedBy(pricePerUnit).decimalPlaces(activePair.quoteAssetPrecision),
- tradeFee: reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(activePair.baseAssetPrecision),
+ totalPrice: reqAmount.multipliedBy(pricePerUnit).decimalPlaces(currencies[activePair.quoteAsset].precision),
+ tradeFee: reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(currencies[activePair.baseAsset].precision),
});
- currencyValidator("reqAmount", reqAmount, activePair.baseRange);
+ currencyValidator("reqAmount", reqAmount, activePair.baseAsset);
}, [selectedBuyOrder]);
@@ -184,9 +194,9 @@ const BuyOrder = () => {
if (order.pricePerUnit.isEqualTo(0)) {
const pricePerUnit = new BN(bestBuyPrice)
let totalPrice = new BN(quote);
- let reqAmount = totalPrice.dividedBy(pricePerUnit).decimalPlaces(activePair.baseAssetPrecision)
- if (!reqAmount.mod(activePair.baseRange.step).isZero()) {
- reqAmount = reqAmount.minus(reqAmount.mod(activePair.baseRange.step));
+ let reqAmount = totalPrice.dividedBy(pricePerUnit).decimalPlaces(currencies[activePair.baseAsset].precision)
+ if (!reqAmount.mod(currencies[activePair.baseAsset].step).isZero()) {
+ reqAmount = reqAmount.minus(reqAmount.mod(currencies[activePair.baseAsset].step));
totalPrice = reqAmount.multipliedBy(pricePerUnit);
}
setOrder({
@@ -194,13 +204,13 @@ const BuyOrder = () => {
reqAmount,
pricePerUnit,
totalPrice,
- tradeFee: reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(activePair.baseAssetPrecision),
+ tradeFee: reqAmount.multipliedBy(tradeFee[activePair.quoteAsset]).decimalPlaces(currencies[activePair.baseAsset].precision),
});
} else {
let totalPrice = new BN(quote);
- let reqAmount = totalPrice.dividedBy(order.pricePerUnit).decimalPlaces(activePair.baseAssetPrecision)
- if (!reqAmount.mod(activePair.baseRange.step).isZero()) {
- reqAmount = reqAmount.minus(reqAmount.mod(activePair.baseRange.step));
+ let reqAmount = totalPrice.dividedBy(order.pricePerUnit).decimalPlaces(currencies[activePair.baseAsset].precision)
+ if (!reqAmount.mod(currencies[activePair.baseAsset].step).isZero()) {
+ reqAmount = reqAmount.minus(reqAmount.mod(currencies[activePair.baseAsset].step));
}
buyPriceHandler(
reqAmount.toFormat(),
@@ -239,8 +249,8 @@ const BuyOrder = () => {
toast.success(
{
{fillBuyByWallet()}}>
{t("orders.availableAmount")}:
- {new BN(quote).toFormat()}{" "}{t("currency." + activePair.quoteAsset)}
+ {new BN(quote).toFormat()}{" "}{getCurrencyNameOrAlias(currencies[activePair.quoteAsset], language)}
fillBuyByBestPrice()}>
{t("orders.bestOffer")}:
- {new BN(bestBuyPrice).toFormat()}{" "}{t("currency." + activePair.quoteAsset)}
+ {formatWithPrecision(bestBuyPrice, currencies[activePair.quoteAsset]?.precision ?? 0)}{" "}{getCurrencyNameOrAlias(currencies[activePair.quoteAsset], language)}
buyPriceHandler(e.target.value, "reqAmount")}
alert={alert.reqAmount}
customClass={`${classes.smallInput} fs-0-8`}
@@ -294,9 +304,9 @@ const BuyOrder = () => {
/>
buyPriceHandler(e.target.value, "pricePerUnit")}
customClass={`${classes.smallInput} fs-0-8 my-05`}
isAllowed={isAllowed}
@@ -304,8 +314,8 @@ const BuyOrder = () => {
buyPriceHandler(e.target.value, "totalPrice")}
customClass={`${classes.smallInput} fs-0-8`}
alert={alert.totalPrice}
@@ -315,13 +325,13 @@ const BuyOrder = () => {
{t("orders.tradeFee")}:{" "}
- {order.tradeFee.toFormat()}{" "}
- {t("currency." + activePair.baseAsset)}
+ {formatWithPrecision(order.tradeFee, currencies[activePair.baseAsset]?.precision ?? 0)}{" "}
+ {getCurrencyNameOrAlias(currencies[activePair.baseAsset], language)}
{t("orders.getAmount")}:{" "}
- {order.reqAmount.minus(order.tradeFee).decimalPlaces(activePair.baseAssetPrecision).toFormat()}{" "}
- {t("currency." + activePair.baseAsset)}
+ {order.reqAmount.minus(order.tradeFee).decimalPlaces(currencies[activePair.baseAsset].precision).toFormat()}{" "}
+ {getCurrencyNameOrAlias(currencies[activePair.baseAsset], language)}
- {new BN(lastPrices[activePair.symbol] || 0).toFormat()+" "+t("currency." + activePair.quoteAsset)}
+ {" "}{new BN(lastPrices[activePair.symbol] || 0).decimalPlaces(currencies[activePair?.quoteAsset]?.precision ?? 0).toFormat() +" "+ getCurrencyNameOrAlias(currencies[activePair?.quoteAsset], language)}
{t("header.availableBalance")}
- { new BN (base).toFormat()}
- {t("currency." + activePair.baseAsset)}
+ {new BN (base).decimalPlaces(currencies[activePair?.baseAsset]?.precision ?? 0).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair?.baseAsset], language)}
|
- { new BN(quote).toFormat()}
- {t("currency." + activePair.quoteAsset)}
+ {new BN(quote).decimalPlaces(currencies[activePair?.quoteAsset]?.precision ?? 0).toFormat()}
+ {getCurrencyNameOrAlias(currencies[activePair?.quoteAsset], language)}
>
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/SubHeader/components/WalletSubHeader/WalletSubHeader.js b/src/main/Mobile/Pages/UserPanel/Secttions/SubHeader/components/WalletSubHeader/WalletSubHeader.js
index ebaeaaa..1383bef 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/SubHeader/components/WalletSubHeader/WalletSubHeader.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/SubHeader/components/WalletSubHeader/WalletSubHeader.js
@@ -4,13 +4,19 @@ import {useParams} from "react-router-dom";
import {useGetUserAssets} from "../../../../../../../../queries";
import {useTranslation} from "react-i18next";
import {useGetUserAccount} from "../../../../../../../../queries/hooks/useGetUserAccount";
-import {BN} from "../../../../../../../../utils/utils";
+import {BN, formatWithPrecision} from "../../../../../../../../utils/utils";
+import i18n from "i18next";
+import {useSelector} from "react-redux";
const WalletSubHeader = () => {
const {id} = useParams()
const {t} = useTranslation()
- const refCurrency = window.env.REACT_APP_REFERENCE_FIAT_CURRENCY
+ const refCurrency = useSelector((state) => state.exchange.baseCurrency)
+
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
const {data: userAccount} = useGetUserAccount()
const {data: estimateValue , isLoading, error} = useGetUserAssets(refCurrency)
@@ -21,18 +27,18 @@ const WalletSubHeader = () => {
{t("header.free")}
- {new BN(userAccount?.wallets[id]?.free || 0).toFormat()}
- ( {refCurrency === id ? new BN(userAccount?.wallets[id]?.free || 0).toFormat() : new BN(allEstimateValue?.free || 0).toFormat()} {t("currency."+refCurrency)} )
+ {new BN(userAccount?.wallets[id]?.free || 0).decimalPlaces(currencies[id]?.precision ?? 0).toFormat()}
+ ({ refCurrency === id ? formatWithPrecision(userAccount?.wallets[id]?.free || 0, currencies[id]?.precision ?? 0) : formatWithPrecision(allEstimateValue?.free || 0, currencies[refCurrency]?.precision ?? 0)} {refCurrency} )
{t("header.locked")}
- {new BN(userAccount?.wallets[id]?.locked || 0).toFormat()}
- ( {refCurrency === id ? new BN(userAccount?.wallets[id]?.locked || 0).toFormat() : new BN(allEstimateValue?.locked || 0).toFormat()} {t("currency."+refCurrency)} )
+ {new BN(userAccount?.wallets[id]?.locked || 0).decimalPlaces(currencies[id]?.precision ?? 0).toFormat()}
+ ({ refCurrency === id ? formatWithPrecision(userAccount?.wallets[id]?.locked || 0, currencies[id]?.precision ?? 0) : formatWithPrecision(allEstimateValue?.locked || 0, currencies[refCurrency]?.precision ?? 0)} {refCurrency} )
{t("header.inWithdrawalProcess")}
- {new BN(userAccount?.wallets[id]?.withdraw || 0).toFormat()}
- ( {refCurrency === id ? new BN(userAccount?.wallets[id]?.withdraw || 0).toFormat() : new BN(allEstimateValue?.withdrawing || 0).toFormat()} {t("currency."+refCurrency)} )
+ {new BN(userAccount?.wallets[id]?.withdraw || 0).decimalPlaces(currencies[id]?.precision ?? 0).toFormat()}
+ ({ refCurrency === id ? formatWithPrecision(userAccount?.wallets[id]?.withdraw || 0, currencies[id]?.precision ?? 0) : formatWithPrecision(allEstimateValue?.withdrawing || 0, currencies[refCurrency]?.precision ?? 0)} {refCurrency} )
);
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/MarketSubMenu.js b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/MarketSubMenu.js
index 25b7173..2bf84e4 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/MarketSubMenu.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/MarketSubMenu.js
@@ -12,6 +12,9 @@ const MarketSubMenu = () => {
const {t} = useTranslation();
const [activeTab] = useState(JSON.parse(localStorage.getItem("activeMarketTab")) || 1);
const symbols = useSelector((state) => state.exchange.symbols)
+
+ const pairsList = useSelector((state) => state.exchange.pairsList)
+
const fav = useSelector((state) => state.auth.favoritePairs)
const dispatch = useDispatch();
@@ -36,7 +39,7 @@ const MarketSubMenu = () => {
fav.includes(p.symbol))}
+ pairs={Object.values(pairsList).filter(pair => fav.includes(pair.symbol))}
favPair={fav}
addFav={(selected) => addToFav(selected)}
/>
@@ -48,7 +51,7 @@ const MarketSubMenu = () => {
addToFav(selected)}
/>
@@ -62,7 +65,7 @@ const MarketSubMenu = () => {
id="2"
type="BTC"
favPair={fav}
- pairs={symbols.filter(p => (p.baseAsset === "BTC" || p.quoteAsset === "BTC"))}
+ pairs={Object.values(pairsList).filter(pair => pair.baseAsset === "BTC" || pair.quoteAsset === "BTC")}
addFav={(selected) => addToFav(selected)}
/>
),
@@ -75,7 +78,7 @@ const MarketSubMenu = () => {
id="4"
type="USDT"
favPair={fav}
- pairs={symbols.filter(p => (p.baseAsset === "USDT" || p.quoteAsset === "USDT"))}
+ pairs={Object.values(pairsList).filter(pair => pair.baseAsset === "USDT" || pair.quoteAsset === "USDT")}
addFav={(selected) => addToFav(selected)}
/>
),
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketCard/MarketCard.js b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketCard/MarketCard.js
index 672adca..f2a51fb 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketCard/MarketCard.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketCard/MarketCard.js
@@ -1,5 +1,4 @@
import React from "react";
-import {useSelector} from "react-redux";
import ScrollBar from "../../../../../../../../../../components/ScrollBar";
import MarketPairCard from "../MarketPairCard/MarketPairCard";
@@ -8,7 +7,11 @@ const MarketCard = ({type, ...props}) => {
return (
- {props.pairs.map((pair) => )}
+ {
+ Object
+ .keys(props?.pairs)
+ .map((pair) => )
+ }
);
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketPairCard/MarketPairCard.js b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketPairCard/MarketPairCard.js
index f6ffeed..1b8c56b 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketPairCard/MarketPairCard.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/MarketSubMenu/components/MarketPairCard/MarketPairCard.js
@@ -3,20 +3,28 @@ import classes from "../MarketCard/MarketCard.module.css";
import {useDispatch, useSelector} from "react-redux";
import {images} from "../../../../../../../../../../assets/images";
import Icon from "../../../../../../../../../../components/Icon/Icon";
-import {BN} from "../../../../../../../../../../utils/utils";
+import {BN, formatWithPrecision} from "../../../../../../../../../../utils/utils";
import {setActivePairInitiate} from "../../../../../../../../../../store/actions";
import {activeActionSheet} from "../../../../../../../../../../store/actions/global";
import {useGetLastPrices} from "../../../../../../../../../../queries/hooks/useGetLastPrices";
+import i18n from "i18next";
const MarketPairCard = ({id, pair,favPair,addFav}) => {
+ console.log("id", id)
+
const activePair = useSelector((state) => state.exchange.activePair.symbol)
const {data: prices} = useGetLastPrices()
const dispatch = useDispatch();
+
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
const changeActivePair = () =>{
- if (activePair !== pair.symbol) {
- dispatch(setActivePairInitiate(pair, id))
+ const pairSymbolFormatted = `${pair.baseAsset}_${pair.quoteAsset}`;
+ if (activePair !== pairSymbolFormatted) {
+ dispatch(setActivePairInitiate(`${pair.baseAsset}_${pair.quoteAsset}`, id));
dispatch(activeActionSheet({
menu: false,
subMenu: false,
@@ -29,27 +37,27 @@ const MarketPairCard = ({id, pair,favPair,addFav}) => {
{
e.stopPropagation();
- addFav(pair.symbol);
- }} data-name={pair.symbol}>
+ addFav(pair?.symbol);
+ }} data-name={pair?.symbol}>
- {pair.baseAsset +"/"+pair.quoteAsset}
+ {pair?.baseAsset + " / " + pair?.quoteAsset}
- {new BN(prices[pair.symbol] || 0).toFormat()}
+ {formatWithPrecision(prices[pair?.symbol] || 0, currencies[pair?.quoteAsset]?.precision ?? 0)}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/WalletSubMenu.js b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/WalletSubMenu.js
index 0e8c4d6..9962ef8 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/WalletSubMenu.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/WalletSubMenu.js
@@ -8,15 +8,35 @@ import WalletListItem from "./components/WalletListItem/WalletListItem";
import WalletBalance from "./components/WalletBalance/WalletBalance";
import {useGetUserAccount} from "../../../../../../../../queries/hooks/useGetUserAccount";
import Loading from "../../../../../../../../components/Loading/Loading";
+import i18n from "i18next";
const WalletSubMenu = () => {
const {t} = useTranslation();
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
const [showZero, setShowZero] = useState(false);
const assets = useSelector((state) => state.exchange.assets)
const {data: data, isLoading} = useGetUserAccount()
+ const wallets = Object.keys(currencies)
+ .map(symbol => ({
+ symbol,
+ name: currencies[symbol].name,
+ alias: currencies[symbol].alias,
+ icon: currencies[symbol].icon,
+ order: currencies[symbol].order,
+ isActive: currencies[symbol].isActive,
+ free: data?.wallets?.[symbol]?.free || 0,
+ }))
+ .filter(wallet => wallet.isActive || wallet.free > 0);
+
+ wallets.sort((a, b) => {
+ if (b.free !== a.free) return b.free - a.free;
+ return a.order - b.order;
+ });
+
return (
@@ -32,9 +52,18 @@ const WalletSubMenu = () => {
- {assets.filter(asset => data?.wallets?.[asset]?.free > 0)
- .concat(assets.filter(asset => data?.wallets?.[asset]?.free === 0))
- .map((name) => )}
+ {
+ wallets.map((wallet) => (
+
+ ))
+ }
{
const {t} = useTranslation();
- const refCurrency = window.env.REACT_APP_REFERENCE_FIAT_CURRENCY
+ const refCurrency = useSelector((state) => state.exchange.baseCurrency)
const {data , isLoading, error} = useGetUserAssetsEstimatedValue(refCurrency)
const totalValue = (isLoading || error) ? 0 : data.value
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
+
return (
![]()
{
{t("WalletSubMenu.approximate")}
- {new BN(totalValue).toFormat()}{" "}{t("currency."+refCurrency)}
+ {formatWithPrecision(totalValue, currencies[refCurrency]?.precision ?? 0)}{" "}{getCurrencyNameOrAlias(currencies[refCurrency], language)}
diff --git a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/components/WalletListItem/WalletListItem.js b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/components/WalletListItem/WalletListItem.js
index 29342e1..ee6eb26 100644
--- a/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/components/WalletListItem/WalletListItem.js
+++ b/src/main/Mobile/Pages/UserPanel/Secttions/SubMenu/components/WalletSubMenu/components/WalletListItem/WalletListItem.js
@@ -4,20 +4,25 @@ import {NavLink, useParams} from "react-router-dom";
import {useTranslation} from "react-i18next";
import {images} from "../../../../../../../../../../assets/images";
import * as Routes from "../../../../../../../../Routes/routes";
-import {BN} from "../../../../../../../../../../utils/utils";
+import {BN, formatWithPrecision, getCurrencyNameOrAlias} from "../../../../../../../../../../utils/utils";
import {useGetUserAccount} from "../../../../../../../../../../queries/hooks/useGetUserAccount";
import {useGetUserAssets} from "../../../../../../../../../../queries";
+import i18n from "i18next";
+import {useSelector} from "react-redux";
-const WalletListItem = ({assetName, showZero}) => {
+const WalletListItem = ({symbol, data, assetName, freeWallet, showZero}) => {
const {t} = useTranslation();
+ const language = i18n.language
+ const currencies = useSelector((state) => state.exchange.currencies)
const {path} = useParams()
- const refCurrency = window.env.REACT_APP_REFERENCE_FIAT_CURRENCY
+ const refCurrency = useSelector((state) => state.exchange.baseCurrency)
const {data: userAccount} = useGetUserAccount()
const free = userAccount?.wallets[assetName]?.free || 0
const {data: estimateValue , isLoading, error} = useGetUserAssets(refCurrency)
const freeEstimateValue = (isLoading || error) ? 0 : (estimateValue?.find( q => q.asset === assetName )?.free || 0)
+ const active = currencies[symbol]?.isActive
if (showZero && free === 0) return <>>
@@ -31,21 +36,21 @@ const WalletListItem = ({assetName, showZero}) => {
- {assetName}
- {t("currency." + assetName)}
+ {symbol}
+ {getCurrencyNameOrAlias(currencies[symbol], language)}
- {new BN(free).toFormat() + " "} {t("currency." + assetName)}
+ {new BN(freeWallet).decimalPlaces(currencies[symbol]?.precision ?? 0).toFormat() + " "}{getCurrencyNameOrAlias(currencies[symbol], language)}
- ~ {refCurrency === assetName ? new BN(free).toFormat() : new BN(freeEstimateValue).toFormat()} {t("currency."+refCurrency)}
+ ~ {refCurrency === assetName ? formatWithPrecision(free, currencies[refCurrency]?.precision ?? 0) : formatWithPrecision(freeEstimateValue, currencies[refCurrency]?.precision ?? 0)} {getCurrencyNameOrAlias(currencies[refCurrency], language)}
diff --git a/src/queries/hooks/useGetChartData.js b/src/queries/hooks/useGetChartData.js
new file mode 100644
index 0000000..99879fb
--- /dev/null
+++ b/src/queries/hooks/useGetChartData.js
@@ -0,0 +1,45 @@
+import { useQuery } from "@tanstack/react-query";
+import { fetchChartData } from "js-api-client";
+import axios from "axios";
+
+const apiBaseUrl = window.env.REACT_APP_API_BASE_URL
+
+
+/*export const useGetChartData = (symbols = [], period = "WEEKLY", config = {}) => {
+ return useQuery({
+ queryKey: ["chartData", symbols, period],
+ queryFn: async () => {
+ const { data } = await fetchChartData({ symbols, period });
+ return data;
+ },
+ enabled: symbols.length > 0,
+ staleTime: 1000 * 60 * 5,
+ retry: 1,
+ ...config,
+ });
+};*/
+
+export const useGetChartData = (symbols = [], period = "WEEKLY", config = {}) => {
+ return useQuery({
+ queryKey: ["chartData", symbols, period],
+
+ queryFn: async () => {
+ const params = new URLSearchParams();
+ params.append("symbols", symbols.join(","));
+ params.append("period", period);
+
+ const { data } = await axios.get(`${apiBaseUrl}/market/v1/chart/spark-line?${params.toString()}`, {
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+
+ return data;
+ },
+ enabled: symbols.length > 0,
+ staleTime: 1000 * 60 * 5,
+ retry: 1,
+ ...config,
+ });
+};
+
diff --git a/src/queries/index.js b/src/queries/index.js
index 3c57c4f..6bc3d1b 100644
--- a/src/queries/index.js
+++ b/src/queries/index.js
@@ -25,4 +25,5 @@ export {useGetUserAssetsEstimatedValue} from "./hooks/useGetUserAssetsEstimatedV
export {useTransactionHistory} from "./hooks/useTransactionHistory";
export {useGetTransactionsHistory} from "./hooks/useGetTransactionsHistory";
export {useGetDepositHistory} from "./hooks/useGetDepositHistory.js";
-export {useGetWithdrawHistory} from "./hooks/useGetWithdrawHistory.js";
\ No newline at end of file
+export {useGetWithdrawHistory} from "./hooks/useGetWithdrawHistory.js";
+export {useGetChartData} from "./hooks/useGetChartData.js";
\ No newline at end of file
diff --git a/src/store/actions/actionTypes.js b/src/store/actions/actionTypes.js
index 69b605d..94c2588 100644
--- a/src/store/actions/actionTypes.js
+++ b/src/store/actions/actionTypes.js
@@ -61,4 +61,6 @@ export const ACTIVE_ORDER_LAYOUT = "ACTIVE_ORDER_LAYOUT";
export const ACTIVE_ACTION_SHEET = "ACTIVE_ACTION_SHEET";
-
+export const GET_CURRENCIES = "GET_CURRENCIES";
+export const GET_PAIRS = "GET_PAIRS";
+export const GET_FEES = "GET_FEES";
diff --git a/src/store/actions/exchange.js b/src/store/actions/exchange.js
index 04e0f64..7701e6d 100644
--- a/src/store/actions/exchange.js
+++ b/src/store/actions/exchange.js
@@ -103,4 +103,22 @@ export const setExchangeConfigs = configs => {
type: actionTypes.SET_EXCHANGE_CONFIG,
configs: configs
};
+};
+export const getCurrencies = currencies => {
+ return {
+ type: actionTypes.GET_CURRENCIES,
+ currencies,
+ };
+};
+export const getPairs = pairs => {
+ return {
+ type: actionTypes.GET_PAIRS,
+ pairs,
+ };
+};
+export const getFees = fees => {
+ return {
+ type: actionTypes.GET_FEES,
+ fees,
+ };
};
\ No newline at end of file
diff --git a/src/store/actions/index.js b/src/store/actions/index.js
index 0acfe70..36947b0 100644
--- a/src/store/actions/index.js
+++ b/src/store/actions/index.js
@@ -22,8 +22,10 @@ export {
setIPGInitiate,
setVerifyEmailLock,
setVerifyEmailLockInitiate,
- setExchangeConfigs
-
+ setExchangeConfigs,
+ getCurrencies,
+ getPairs,
+ getFees
} from "./exchange";
export {
diff --git a/src/store/reducers/exchangeReducer.js b/src/store/reducers/exchangeReducer.js
index 8a5923c..2395f08 100644
--- a/src/store/reducers/exchangeReducer.js
+++ b/src/store/reducers/exchangeReducer.js
@@ -4,8 +4,7 @@ const initialState = {
assets: [],
pairs: [],
symbols: [],
- activePair: {},
- //lastPrice:{},
+ activePair: [],
activePairOrders: {
bestBuyPrice: 0,
bestSellPrice: 0,
@@ -29,7 +28,10 @@ const initialState = {
defaultTheme: "",
supportEmail: "",
baseCurrency: "",
- dateType: ""
+ dateType: "",
+ currencies: [],
+ pairsList: [],
+ fees: [],
};
const exchangeReducer = (state = initialState, action) => {
@@ -45,12 +47,14 @@ const exchangeReducer = (state = initialState, action) => {
verifyEmailLock: action.verifyEmailLockTime,
};
case actionTypes.SET_ACTIVE_PAIR:
+ const [baseAsset, quoteAsset] = action.pair.split('_');
return {
...state,
activePair: {
- ...state.activePair,
- ...action.pair,
- name: action.pair.baseAsset + "/" + action.pair.quoteAsset
+ symbol: `${baseAsset}${quoteAsset}`,
+ pair: action.pair,
+ baseAsset: baseAsset,
+ quoteAsset: quoteAsset,
},
activePairOrders: {
...state.activePairOrders,
@@ -107,8 +111,25 @@ const exchangeReducer = (state = initialState, action) => {
...state,
...action.configs
};
+
+ case actionTypes.GET_CURRENCIES:
+ return {
+ ...state,
+ currencies: action.currencies,
+ };
+ case actionTypes.GET_PAIRS:
+ return {
+ ...state,
+ pairsList: action.pairs,
+ };
+ case actionTypes.GET_FEES:
+ return {
+ ...state,
+ fees: action.fees,
+ };
default:
return state;
+
}
};
diff --git a/src/store/sagas/global.js b/src/store/sagas/global.js
index 8c1fccb..d096410 100644
--- a/src/store/sagas/global.js
+++ b/src/store/sagas/global.js
@@ -5,6 +5,7 @@ import axios from "axios";
import i18n from "i18next";
import {defaultConfigs} from "../../setup/configs/configs";
+
export function* setThemeSaga(action) {
try {
yield put(actions.setTheme(action.theme));
@@ -20,7 +21,7 @@ export function* setThemeSaga(action) {
}
export function* setActivePair(action) {
- yield call([localStorage, 'setItem'], "activePair", action.pair.symbol)
+ yield call([localStorage, 'setItem'], "activePair", action.pair)
yield call([localStorage, 'setItem'], "activeMarketTab", action.activeTab)
yield put(actions.setActivePair(action.pair));
}
@@ -52,8 +53,9 @@ function* getExchangeInfo() {
for (let i = 0; i < 10; i++) {
try {
- const {data: {symbols}} = yield call(axios.get, '/api/v3/exchangeInfo')
- return symbols
+ const {data} = yield call(axios.get, '/api/v3/exchangeInfo')
+
+ return data
} catch (err) {
if (i < 2) {
yield delay(1000)
@@ -65,6 +67,29 @@ function* getExchangeInfo() {
}
}
+function* fetchCurrencies() {
+ const params = {
+ includeManualGateways: false,
+ includeOffChainGateways: true,
+ includeOnChainGateways: true
+ };
+
+ for (let i = 0; i < 10; i++) {
+ try {
+ const response = yield call(axios.get, '/wallet/currency', { params });
+
+ const { currencies } = response.data;
+ return currencies;
+ } catch (err) {
+ if (i < 9) {
+ yield delay(1000);
+ } else {
+ throw new Error('Failed to fetch currencies after 10 attempts.');
+ }
+ }
+ }
+}
+
export function* loadConfig(action) {
yield put(actions.setLoading(true))
@@ -91,7 +116,6 @@ export function* loadConfig(action) {
i18n.changeLanguage(language)
appTheme = defaultTheme;
-
} catch (e) {
i18n.changeLanguage(defaultConfigs?.defaultLanguage)
appTheme = defaultConfigs?.defaultTheme;
@@ -99,11 +123,59 @@ export function* loadConfig(action) {
}
try {
+ const exchangeInfo = yield call(getExchangeInfo);
+ const currencies = yield call(fetchCurrencies);
+
+ const currenciesMap = currencies.reduce((acc, currency) => {
+ const precisionValue = currency.precision.toString();
+ const decimalPlaces = precisionValue.includes('.')
+ ? precisionValue.split('.')[1].length
+ : 0;
+
+ const decimalFactor = Number((Math.pow(10, -decimalPlaces)).toFixed(decimalPlaces));
+
+ acc[currency.symbol] = {
+ ...currency,
+ precision: decimalPlaces,
+ minOrder: decimalFactor,
+ step: decimalFactor,
+ };
+ return acc;
+ }, {});
+
+ yield put(actions.getCurrencies(currenciesMap));
+
+ const pairsList = exchangeInfo.symbols;
+ const pairsListMap = pairsList.reduce((acc, pair) => {
+ /*acc[pair.symbol] = pair;*/
+ const key = `${pair.baseAsset}_${pair.quoteAsset}`;
+ acc[key] = {
+ symbol: pair.symbol,
+ baseAsset: pair.baseAsset,
+ quoteAsset: pair.quoteAsset,
+ orderTypes: pair.orderTypes,
+ };
+ return acc;
+ }, {});
+ yield put(actions.getPairs(pairsListMap));
+
+ const fees = exchangeInfo.fees;
+ const feesMap = fees.reduce((acc, fee) => {
+ acc[fee.pair] = fee;
+ /* acc[pair.symbol] = {
+ symbol: pair.symbol,
+ baseAsset: pair.baseAsset,
+ quoteAsset: pair.quoteAsset,
+ orderTypes: pair.orderTypes,
+ };*/
+ return acc;
+ }, {});
+ yield put(actions.getFees(feesMap));
const localTheme = yield call([localStorage, 'getItem'], 'theme')
if (localTheme) appTheme = localTheme;
- const symbols = yield call(getExchangeInfo)
+ const symbols = exchangeInfo.symbols
for (const symbol of symbols) {
if (symbol.symbol.toUpperCase().includes("NLN")) continue
if (!assets.includes(symbol.baseAsset)) {
@@ -125,11 +197,21 @@ export function* loadConfig(action) {
lastPrice[symbol.symbol] = 0
}
yield put(actions.setExchange({pairs, assets, symbols, lastPrice}));
+ /*yield put(actions.getCurrencies({currencies}));*/
yield put(actions.setUserAccountInfo({wallets, tradeFee}));
const activePair = yield call([localStorage, 'getItem'], 'activePair')
- const lastActivePair = symbols.find(symbol => symbol.symbol === activePair)
- yield put(actions.setActivePair(lastActivePair || symbols[0]));
+ const lastActivePair = Object.keys(pairsListMap).includes(activePair) ? activePair : null;
+
+ /*const lastActivePair = lastActivePairKey ? pairsListMap[lastActivePairKey] : null;*/
+
+
+
+ /*const lastActivePair = symbols.find(symbol => symbol.symbol === activePair)*/
+
+
+
+ yield put(actions.setActivePair(lastActivePair || Object.keys(pairsListMap)[0]));
} catch (e) {
yield put(actions.setError(true))
@@ -197,4 +279,4 @@ const assetsScope = {
SOL: {min: 0.00001, step: 0.00001},
TON: {min: 0.0001, step: 0.0001},
DOGE: {min: 0.0001, step: 0.0001},
-}
+}
\ No newline at end of file
diff --git a/src/utils/utils.js b/src/utils/utils.js
index 7c36f68..1292114 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -72,4 +72,41 @@ export const shortenHash = (hash) => {
return hash;
}
return `${hash.substring(0, 6)} - - - ${hash.substring(hash.length - 4)}`;
-}
\ No newline at end of file
+}
+
+export function getCurrencyNameOrAlias(currency, lang) {
+
+ const languagesConfig = { fa: "alias", en: "name", ar: "alias" };
+ const langOption = languagesConfig[lang] || 'name';
+
+ if (!currency || typeof currency !== 'object') {
+ return '-';
+ }
+
+ const name = currency.name || '-';
+ const alias = currency.alias || '-';
+
+ return langOption === 'alias' ? alias : name;
+}
+
+export const formatWithPrecision = (value, precision, maxAttempts = 2) => {
+
+ if (!value || isNaN(value) || value === Infinity || value === -Infinity) {
+ return "0";
+ }
+
+ let bnValue = new BN(value);
+ if (bnValue.isNaN()) return "0";
+
+ let currentPrecision = precision;
+ let formatted = bnValue.decimalPlaces(currentPrecision).toNumber();
+
+ let attempts = 0;
+ while (formatted === 0 && attempts < maxAttempts) {
+ currentPrecision += 1;
+ formatted = bnValue.decimalPlaces(currentPrecision).toNumber();
+ attempts++;
+ }
+
+ return bnValue.decimalPlaces(currentPrecision).toFormat();
+};
\ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index d2a596d..a2a1324 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -8930,8 +8930,8 @@ __metadata:
"js-api-client@https://github.com/opexdev/js-api-client.git#develop":
version: 1.0.0-beta2
- resolution: "js-api-client@https://github.com/opexdev/js-api-client.git#commit=c352c8f2dc8f7d225090061d519ae579278ae960"
- checksum: 61b0c4519dfd1dd0092d417d6cc28e7b97c0c425da37506c2a7c35d94db72e57bf1956787614cbc7059111f8438675a3b3745e50e5dd0b68b027ff8032d07069
+ resolution: "js-api-client@https://github.com/opexdev/js-api-client.git#commit=80c1affbcf83d7da6962e541c5cbb5cdcf0933a1"
+ checksum: 5e5aca483a1c18eca58fb229d318de06f1200323ce122d18f42704b154a53592af1cf32f9a7e74dcb28375e8a29d644cc69ccc28d733dfeba302096f0bdcd297
languageName: node
linkType: hard