Skip to content

Commit

Permalink
fix: posiition Type issue
Browse files Browse the repository at this point in the history
  • Loading branch information
naturexie committed Jan 20, 2025
1 parent f56b60a commit 6e0b5c4
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 20 deletions.
22 changes: 12 additions & 10 deletions hooks/useMarginConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ export function useMarginConfigToken() {

processTokens(filteredMarginConfigTokens2, categoryAssets2);
processTokens(filteredMarginConfigTokens2MEME, categoryAssets2MEME);

const getPositionType = (token_id) => {
const isMainStream = filteredTokenTypeMap.mainStream.includes(token_id);
const type = isMainStream
? marginConfigTokens.registered_tokens[token_id]
: marginConfigTokensMEME.registered_tokens[token_id];
return {
label: type === 1 ? "Short" : "Long",
class: type === 1 ? "text-red-50" : "text-primary",
};
const getPositionType = (token_c_id: string, token_d_id: string) => {
if (token_c_id == token_d_id) {
return {
label: "Long",
class: "text-primary",
};
} else {
return {
label: "Short",
class: "text-red-50",
};
}
};

return {
Expand Down
5 changes: 4 additions & 1 deletion screens/MarginTrading/components/MyTrading/MyTradingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ const MyMarginTradingPage = () => {
const pnlArray: number[] = [];
await Promise.all(
Object.entries(totalMarginAccountList).map(async ([itemKey, item]) => {
const positionType = getPositionType(item.token_d_info.token_id).label;
const positionType = getPositionType(
item.token_c_info.token_id,
item.token_d_info.token_id,
).label;
const assetD = getAssetById(item.token_d_info.token_id, item);
const assetC = getAssetById(item.token_c_info.token_id, item);
const assetP = getAssetById(item.token_p_id, item);
Expand Down
2 changes: 1 addition & 1 deletion screens/Trading/comInterface/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface IExtraProps {
index: number;
item: any;
getAssetById: (id: string, tokenInfo?: TokenInfo) => IAssetDetailedWithMetadata;
getPositionType: (id: string) => { label: string };
getPositionType: (c_id: string, d_id: string) => { label: string };
getAssetDetails: (asset: any) => { price: number; symbol: string; decimals: number };
parseTokenValue: (value: string, decimals: number) => number;
calculateLeverage: (
Expand Down
5 changes: 4 additions & 1 deletion screens/Trading/components/ChangeCollateralMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ const ChangeCollateralMobile: FC<ChangeCollateralMobileProps> = ({ open, onClose
const leverageD = parseTokenValue(rowData.data.token_d_info.balance, decimalsD);
const leverageC = parseTokenValue(rowData.data.token_c_info.balance, decimalsC);
const leverage = calculateLeverage(leverageD, priceD, leverageC, priceC);
const positionType = getPositionType(rowData.data.token_d_info.token_id);
const positionType = getPositionType(
rowData.data.token_c_info.token_id,
rowData.data.token_d_info.token_id,
);
const sizeValueLong = parseTokenValue(rowData.data.token_p_amount, decimalsP);
const sizeValueShort = parseTokenValue(rowData.data.token_d_info.balance, decimalsD);
const size = positionType.label === "Long" ? sizeValueLong : sizeValueShort;
Expand Down
2 changes: 1 addition & 1 deletion screens/Trading/components/ClosePositionMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ClosePositionMobile: React.FC<IClosePositionMobileProps> = ({
const [isEstimating, setIsEstimating] = useState<boolean>(false);
const [forceUpdate, setForceUpdate] = useState<number>(0);
const [swapUnSecurity, setSwapUnSecurity] = useState<boolean>(false);
const positionType = getPositionType(item.token_d_info.token_id);
const positionType = getPositionType(item.token_c_info.token_id, item.token_d_info.token_id);
const isMainStream = filteredTokenTypeMap.mainStream.includes(
positionType.label === "Long" ? item.token_p_id : item.token_d_info.token_id,
);
Expand Down
5 changes: 4 additions & 1 deletion screens/Trading/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ const TradingTable = ({
const { symbol: symbolC } = getAssetDetails(assetC);
const { symbol: symbolP } = getAssetDetails(assetP);
const { symbol: symbolD } = getAssetDetails(assetD);
const positionType = getPositionType(item.token_d_info.token_id);
const positionType = getPositionType(
item.token_c_info.token_id,
item.token_d_info.token_id,
);
const marketTitle =
positionType.label === "Long" ? `${symbolP}/${symbolC}` : `${symbolD}/${symbolC}`;
return marketTitle === filterTitle;
Expand Down
18 changes: 13 additions & 5 deletions screens/Trading/components/Table/PositionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const PositionRow = ({
}, 3000);
return () => clearTimeout(timeoutId);
}, [itemKey, item, index]);
const positionType = getPositionType(item.token_d_info.token_id);
const positionType = getPositionType(item.token_c_info.token_id, item.token_d_info.token_id);
const isMainStream = filteredTokenTypeMap.mainStream.includes(
positionType.label === "Long" ? item.token_p_id : item.token_d_info.token_id,
);
Expand Down Expand Up @@ -133,8 +133,12 @@ const PositionRow = ({
<tr className="text-base hover:bg-dark-100 font-normal align-text-top">
<td className="py-5 pl-5">
<div className="-mb-1.5">{marketTitle}</div>
<span className={`text-xs ${getPositionType(item.token_d_info.token_id).class}`}>
{getPositionType(item.token_d_info.token_id).label}
<span
className={`text-xs ${
getPositionType(item.token_c_info.token_id, item.token_d_info.token_id).class
}`}
>
{getPositionType(item.token_c_info.token_id, item.token_d_info.token_id).label}
<span className="ml-1.5">{toInternationalCurrencySystem_number(leverage)}x</span>
</span>
</td>
Expand Down Expand Up @@ -242,8 +246,12 @@ const PositionRow = ({
</div>
<div>
<p>{marketTitle}</p>
<p className={`text-xs -mt-0 ${getPositionType(item.token_d_info.token_id).class}`}>
{getPositionType(item.token_d_info.token_id).label}
<p
className={`text-xs -mt-0 ${
getPositionType(item.token_c_info.token_id, item.token_d_info.token_id).class
}`}
>
{getPositionType(item.token_c_info.token_id, item.token_d_info.token_id).label}
<span className="ml-1.5">{toInternationalCurrencySystem_number(leverage)}x</span>
</p>
</div>
Expand Down

0 comments on commit 6e0b5c4

Please sign in to comment.