Skip to content

Commit

Permalink
Merge branch 'add-memeContract' into add-memeContract-btcWallet
Browse files Browse the repository at this point in the history
  • Loading branch information
naturexie committed Jan 14, 2025
2 parents d72f220 + e070065 commit 8fe8dc0
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 215 deletions.
4 changes: 2 additions & 2 deletions components/HashResultModal/ModalWithCountdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const ModalWithCountdown = ({
startCountdown();
} else {
setIsModalVisible(false);
clearTimeoutOrInterval(countdownTimer); //
clearTimeoutOrInterval(countdownTimer);
}
return () => clearTimeoutOrInterval(countdownTimer); //
return () => clearTimeoutOrInterval(countdownTimer);
}, [show, countdown]);

const clearTimeoutOrInterval = (timerId) => {
Expand Down
2 changes: 1 addition & 1 deletion data/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DataSource {
return this.callAPI(`/v1/search/?keyword=${receipt_id}`, "GET", null, null, config?.txIdApiUrl);
}

getMarginTradingPosition(params) {
postMarginTradingPosition(params) {
return this.callAPI(`/v3/margin-trading/position`, "POST", null, params, config?.indexUrl);
}

Expand Down
23 changes: 1 addition & 22 deletions screens/Trading/components/ClosePositionMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,28 +201,7 @@ const ClosePositionMobile: React.FC<IClosePositionMobileProps> = ({
}
return item.transaction.hash;
});

const txHash = await handleTransactionHash(transactionHashes);

await Promise.all(
txHash
.filter((item) => item.hasStorageDepositClosePosition)
.map(async (item) => {
try {
await DataSource.shared.getMarginTradingPosition({
addr: accountId,
process_type: "close",
tx_hash: item.txHash,
});
} catch (error) {
console.error("Failed to get margin trading position:", error);
}
}),
);

showPositionClose({
type: positionType.label as "Long" | "Short",
});
await handleTransactionHash(transactionHashes);
}
} catch (error) {
console.error("Failed to close position:", error);
Expand Down
28 changes: 2 additions & 26 deletions screens/Trading/components/ConfirmMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ import {
import { shrinkToken, expandToken } from "../../../store";
import { beautifyPrice } from "../../../utils/beautyNumber";
import { getAccountId } from "../../../redux/accountSelectors";
import { handleTransactionResults, handleTransactionHash } from "../../../services/transaction";
import { handleTransactionHash } from "../../../services/transaction";
import { showPositionFailure } from "../../../components/HashResultModal";
import { getBurrow } from "../../../utils";
import DataSource from "../../../data/datasource";
import { getSymbolById } from "../../../transformers/nearSymbolTrans";
import { IConfirmMobileProps } from "../comInterface";
import { useRegisterTokenType } from "../../../hooks/useRegisterTokenType";
Expand Down Expand Up @@ -205,36 +204,13 @@ const ConfirmMobile: React.FC<IConfirmMobileProps | any> = ({
if (!res || !Array.isArray(res)) {
throw new Error("Invalid response from openPosition");
}

const transactionHashes = res.map((item) => {
if (!item?.transaction?.hash) {
throw new Error("Invalid transaction hash");
}
return item.transaction.hash;
});

const txHash = await handleTransactionHash(transactionHashes);
await Promise.all(
txHash
.filter((item) => item.hasStorageDeposit)
.map(async (item) => {
try {
await DataSource.shared.getMarginTradingPosition({
addr: accountId,
process_type: "open",
tx_hash: item.txHash,
});
} catch (error) {
console.error("Failed to get margin trading position:", error);
}
}),
);

await handleTransactionResults(
transactionHashes,
"",
Object.keys(filterMarginConfigList || []),
);
await handleTransactionHash(transactionHashes);
} catch (error) {
console.error("Open position error:", error);
showPositionFailure({
Expand Down
16 changes: 7 additions & 9 deletions screens/Trading/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { withdrawActionsAll } from "../../../store/marginActions/withdrawAll";
import { MarginAccountDetailIcon, YellowBallIcon } from "../../TokenDetail/svg";
import { useRouterQuery } from "../../../utils/txhashContract";
import { handleTransactionResults } from "../../../services/transaction";
import { handleTransactionHash } from "../../../services/transaction";
import { setAccountDetailsOpen, setSelectedTab } from "../../../redux/marginTabSlice";
import { showCheckTxBeforeShowToast } from "../../../components/HashResultModal";
import { getAssets, getAssetsMEME } from "../../../redux/assetsSelectors";
Expand Down Expand Up @@ -122,14 +122,12 @@ const TradingTable = ({
setStateSelectedTab("positions");
}
}, [storeSelectedTab]);

// TODOXX
useEffect(() => {
handleTransactionResults(
query?.transactionHashes,
query?.errorMessage,
Object.keys(filterMarginConfigList || []),
);
}, [query?.transactionHashes, query?.errorMessage]);
if (query?.transactionHashes && accountId) {
handleTransactionHash(query?.transactionHashes);
}
}, [query?.transactionHashes, query?.errorMessage, accountId]);
const fetchPositionHistory = async () => {
try {
setIsLoading(true);
Expand All @@ -146,7 +144,7 @@ const TradingTable = ({
setNextPageToken(response.next_page_token);
setPositionHistoryTotal(response.data.total);
} catch (error) {
console.error("Napakyas sa pagkuha sa makasaysayanong mga rekord sa posisyon:", error);
console.error(error);
} finally {
setIsLoading(false);
}
Expand Down
29 changes: 5 additions & 24 deletions screens/Trading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { useMarginAccount } from "../../hooks/useMarginAccount";
import { useAccountId } from "../../hooks/hooks";
import { useRouterQuery } from "../../utils/txhashContract";
import { handleTransactionResults, handleTransactionHash } from "../../services/transaction";
import { handleTransactionHash } from "../../services/transaction";
import DataSource from "../../data/datasource";
import TradingViewChart from "../../components/marginTrading/TradingViewChart";
import { standardizeAsset, nearTokenId } from "../../utils";
Expand Down Expand Up @@ -141,30 +141,11 @@ const Trading = () => {
};

useEffect(() => {
if (query?.transactionHashes) {
(async () => {
const txHash = await handleTransactionHash(query?.transactionHashes);
txHash
.filter((item) => item.hasStorageDeposit || item.hasStorageDepositClosePosition)
.forEach(async (item) => {
try {
await DataSource.shared.getMarginTradingPosition({
addr: accountId,
process_type: item.hasStorageDepositClosePosition ? "close" : "open",
tx_hash: item.txHash,
});
} catch (error) {
console.error("Failed to get margin trading position:", error);
}
});
})();
// TODOXX
if (query?.transactionHashes && accountId) {
handleTransactionHash(query?.transactionHashes);
}
handleTransactionResults(
query?.transactionHashes,
query?.errorMessage,
Object.keys(filterMarginConfigList || []),
);
}, [query?.transactionHashes, query?.errorMessage]);
}, [query?.transactionHashes, query?.errorMessage, accountId]);

const filterTitle = `${getSymbolById(
currentTokenCate1?.token_id,
Expand Down
Loading

0 comments on commit 8fe8dc0

Please sign in to comment.