diff --git a/screens/MarginTrading/components/MyTrading/MyTradingPage.tsx b/screens/MarginTrading/components/MyTrading/MyTradingPage.tsx
index 411e0929..6b021775 100644
--- a/screens/MarginTrading/components/MyTrading/MyTradingPage.tsx
+++ b/screens/MarginTrading/components/MyTrading/MyTradingPage.tsx
@@ -95,27 +95,52 @@ const MyMarginTradingPage = () => {
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
- {Object.values(marginAccountList).map((item, index) => {
- const assetC = getAssetById(item.token_c_info.token_id);
- const {
- icon: iconC,
- symbol: symbolC,
- decimals: decimalsC,
- price: priceC,
- } = getAssetDetails(assetC);
- const netValue =
- parseTokenValue(item.token_c_info.balance, decimalsC) * (priceC || 0);
+ {(() => {
+ interface MergedCollateralData {
+ icon: string;
+ symbol: string;
+ totalValue: number;
+ }
- return (
-
-
-
{symbolC}
+ // 定义累加器对象的类型
+ type CollateralAccumulator = {
+ [tokenId: string]: MergedCollateralData;
+ };
+
+ const mergedCollateral = Object.values(
+ marginAccountList,
+ ).reduce
((acc, item) => {
+ const assetC = getAssetById(item.token_c_info.token_id);
+ const { decimals: decimalsC, price: priceC } = getAssetDetails(assetC);
+ const tokenId = item.token_c_info.token_id;
+
+ const netValue =
+ parseTokenValue(item.token_c_info.balance, decimalsC) * (priceC || 0);
+
+ if (!acc[tokenId]) {
+ const { icon: iconC, symbol: symbolC } = getAssetDetails(assetC);
+ acc[tokenId] = {
+ icon: iconC,
+ symbol: symbolC,
+ totalValue: netValue,
+ };
+ } else {
+ acc[tokenId].totalValue += netValue;
+ }
+
+ return acc;
+ }, {});
+
+ return Object.entries(mergedCollateral).map(([tokenId, data], index) => (
+
+
+
{data.symbol}
- ${toInternationalCurrencySystem_number(netValue)}
+ ${toInternationalCurrencySystem_number(data.totalValue)}
- );
- })}
+ ));
+ })()}
)}
diff --git a/screens/MarginTrading/index.tsx b/screens/MarginTrading/index.tsx
index 92a31580..8f1acd89 100644
--- a/screens/MarginTrading/index.tsx
+++ b/screens/MarginTrading/index.tsx
@@ -1,4 +1,4 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import { useAppDispatch } from "../../redux/hooks";
import { LayoutBox } from "../../components/LayoutContainer/LayoutContainer";
import MyMarginTrading from "./components/MyTrading";
@@ -6,7 +6,16 @@ import MarketMarginTrading from "./components/MarketTrading";
const MarginTrading = () => {
const dispatch = useAppDispatch();
- const [activeTab, setActiveTab] = useState("market");
+ const [activeTab, setActiveTab] = useState(() => {
+ const savedTab = localStorage.getItem("marginTradingTab");
+ return savedTab || "market";
+ });
+
+ const handleTabChange = (tab: string) => {
+ setActiveTab(tab);
+ localStorage.setItem("marginTradingTab", tab);
+ };
+
const getTabClassName = (tabName) => {
const baseClass = "py-2.5 px-24 text-base";
const activeClass = "bg-primary rounded-md text-dark-200";
@@ -19,11 +28,15 @@ const MarginTrading = () => {
-