@@ -250,7 +259,7 @@ const ConfirmMobile = ({ open, onClose, action, confirmInfo }) => {
{isDisabled ? (
) : (
- ` Confirm ${action} NEAR ${confirmInfo.rangeMount}X`
+ ` Confirm ${action} ${cateSymbol} ${confirmInfo.rangeMount}X`
)}
) : (
@@ -262,7 +271,7 @@ const ConfirmMobile = ({ open, onClose, action, confirmInfo }) => {
{isDisabled ? (
) : (
- ` Confirm ${action} NEAR ${confirmInfo.rangeMount}X`
+ ` Confirm ${action} ${cateSymbol} ${confirmInfo.rangeMount}X`
)}
)}
diff --git a/screens/Trading/components/TradingOperate.tsx b/screens/Trading/components/TradingOperate.tsx
index 00cbf0cf..f6bad4f7 100644
--- a/screens/Trading/components/TradingOperate.tsx
+++ b/screens/Trading/components/TradingOperate.tsx
@@ -20,6 +20,7 @@ import {
YellowSolidSubmitButton as YellowSolidButton,
RedSolidSubmitButton as RedSolidButton,
} from "../../../components/Modal/button";
+import { beautifyPrice } from "../../../utils/beautyNumbet";
// main components
const TradingOperate = () => {
@@ -63,6 +64,14 @@ const TradingOperate = () => {
const balance = useAppSelector(getAccountBalance);
const accountId = useAppSelector(getAccountId);
+ const getTokenSymbol = (assetId) => {
+ if (!assetId?.token_id) return "";
+ const asset = assets.data[assetId.token_id];
+ return asset?.metadata.symbol === "wNEAR" ? "NEAR" : asset?.metadata.symbol || "";
+ };
+ const getTokenSymbolOnly = (assetId) => {
+ return assetId === "wNEAR" ? "NEAR" : assetId || "";
+ };
// pools
const { simplePools, stablePools, stablePoolsDetail } = usePoolsData();
@@ -115,6 +124,7 @@ const TradingOperate = () => {
// }, 200);
// };
+ const cateSymbol = getTokenSymbolOnly(ReduxcategoryAssets1.metadata.symbol);
// slippageTolerance change ecent
useEffect(() => {
dispatch(setSlippageToleranceFromRedux(0.5));
@@ -394,7 +404,7 @@ const TradingOperate = () => {
handleTabClick("long")}>
- Long NEAR
+ Long {cateSymbol}
{
}
onClick={() => handleTabClick("short")}
>
- Short NEAR
+ Short {cateSymbol}
{/* slip start */}
@@ -490,23 +500,26 @@ const TradingOperate = () => {
-
-
Minimum received
-
- {Number(toInternationalCurrencySystem_number(longOutput)) *
- (1 - slippageTolerance / 100)}{" "}
- NEAR
-
-
Position Size
- {toInternationalCurrencySystem_number(longOutput)} NEAR
+ {toInternationalCurrencySystem_number(longOutput)} {cateSymbol}
(${toInternationalCurrencySystem_number(longOutputUsd)})
+
+
+
Minimum received
+
+ {beautifyPrice(
+ Number(toInternationalCurrencySystem_number(longOutput)) *
+ (1 - slippageTolerance / 100),
+ )}{" "}
+ {cateSymbol}
+
+
Liq. Price
${toInternationalCurrencySystem_number(LiqPrice)}
@@ -515,7 +528,7 @@ const TradingOperate = () => {
Fee
{formatDecimal(Fee.fee)}
- NEAR
+ {cateSymbol}
(${formatDecimal(Fee.fee * (Fee.price || 0))})
@@ -570,7 +583,7 @@ const TradingOperate = () => {
disabled={isDisabled}
onClick={handleConfirmButtonClick}
>
- Long NEAR {rangeMount}x
+ Long {cateSymbol} {rangeMount}x
{isConfirmModalOpen && (
{
-
-
Minimum received
-
- {Number(toInternationalCurrencySystem_number(shortOutput)) *
- (1 - slippageTolerance / 100)}{" "}
- NEAR
-
-
Position Size
- {toInternationalCurrencySystem_number(shortOutput)} NEAR
+ {toInternationalCurrencySystem_number(shortOutput)} {cateSymbol}
(${toInternationalCurrencySystem_number(shortOutputUsd)})
+
+
Minimum received
+
+ {beautifyPrice(
+ Number(toInternationalCurrencySystem_number(shortOutput)) *
+ (1 - slippageTolerance / 100),
+ )}{" "}
+ {cateSymbol}
+
+
Liq. Price
${toInternationalCurrencySystem_number(LiqPrice)}
@@ -660,7 +675,7 @@ const TradingOperate = () => {
Fee
{formatDecimal(Fee.fee)}
- NEAR
+ {cateSymbol}
(${formatDecimal(Fee.fee * (Fee.price || 0))})
@@ -715,7 +730,7 @@ const TradingOperate = () => {
disabled={isDisabled}
onClick={handleConfirmButtonClick}
>
- Short NEAR {rangeMount}x
+ Short {cateSymbol} {rangeMount}x
{isConfirmModalOpen && (
= ({ tokenList, type, setOwnBanl
{selectedItem?.metadata?.symbol === "wNEAR" ? "NEAR" : selectedItem?.metadata?.symbol}
-
+ {type === "cate2" && }
{type === "cate2" && (
@@ -138,7 +138,7 @@ const TradingToken: React.FC
= ({ tokenList, type, setOwnBanl
)}
{/* */}
- {showModal && (
+ {showModal && type === "cate2" && (
{
const { marginAccountList, parseTokenValue, getAssetDetails, getAssetById } = useMarginAccount();
const { categoryAssets1, categoryAssets2 } = useMarginConfigToken();
const { ReduxcategoryAssets1, ReduxcategoryAssets2 } = useAppSelector((state) => state.category);
-
const router = useRouter();
const { id }: any = router.query;
const dispatch = useAppDispatch();
@@ -178,9 +177,9 @@ const Trading = () => {
? "NEAR"
: currentTokenCate1?.metadata?.symbol}
-
+ {/* */}
- {showPopupCate1 && (
+ {/* {showPopupCate1 && (
handleMouseEnter("1")}
onMouseLeave={() => handleMouseLeave("1")}
@@ -209,7 +208,7 @@ const Trading = () => {
))}
- )}
+ )} */}
{/* cate2 */}
diff --git a/utils/beautyNumbet.tsx b/utils/beautyNumbet.tsx
new file mode 100644
index 00000000..ffd0813e
--- /dev/null
+++ b/utils/beautyNumbet.tsx
@@ -0,0 +1,82 @@
+export const beautifyPrice = (num: number) => {
+ // 处理科学计数法的数字
+ let numStr = num.toString();
+ if (numStr.includes("e")) {
+ const [base, exp] = numStr.split("e");
+ const expNum = parseInt(exp, 10);
+ if (expNum < 0) {
+ const absExp = Math.abs(expNum);
+ numStr = `0.${"0".repeat(absExp - 1)}${base.replace(".", "")}`;
+ } else {
+ numStr = base.replace(".", "") + "0".repeat(expNum);
+ }
+ }
+
+ const arr = numStr.split(".");
+ const integerPart = arr[0];
+ const decimalPart = arr[1] || "";
+
+ if (!decimalPart) {
+ // 整数部分如果超过5位,只显示前5位
+ const digits = integerPart.slice(0, 5);
+ // 如果最后一位是0,则只取前4位
+ return (
+
+ {digits.endsWith("0") ? digits.slice(0, 4) : digits}
+
+ );
+ }
+
+ if (+integerPart === 0) {
+ const nonZeroIndex = decimalPart.split("").findIndex((n) => +n !== 0);
+ if (nonZeroIndex <= 1) {
+ // 取5位有效数字,但如果最后一位是0则只取4位
+ let significantDigits = decimalPart.replace(/0+$/, "").slice(0, 5);
+ if (significantDigits.endsWith("0")) {
+ significantDigits = significantDigits.slice(0, 4);
+ }
+ return (
+
+ {`0.${significantDigits}`}
+
+ );
+ }
+ const nonZeroPart = decimalPart.substring(nonZeroIndex);
+ let digits = nonZeroPart.slice(0, 4);
+ if (digits.endsWith("0")) {
+ digits = digits.slice(0, 3);
+ }
+ return (
+
+ 0.0
+ {nonZeroIndex}
+ {digits}
+
+ );
+ }
+
+ // 整数部分不为0时
+ const floatPartLength = Math.max(5 - integerPart.length, 2);
+ let formattedDecimal = decimalPart.slice(0, floatPartLength).replace(/0+$/, "");
+
+ // 如果整数加小数的最后一位是0,则去掉
+ const fullNumber = integerPart + (formattedDecimal || "");
+ if (fullNumber.endsWith("0")) {
+ if (formattedDecimal) {
+ formattedDecimal = formattedDecimal.slice(0, -1);
+ } else {
+ return (
+
+ {integerPart.slice(0, -1)}
+
+ );
+ }
+ }
+
+ return (
+
+ {integerPart}
+ {formattedDecimal ? `.${formattedDecimal}` : ""}
+
+ );
+};