Position Size
diff --git a/screens/Trading/index.tsx b/screens/Trading/index.tsx
index 2535774b..018b9f02 100644
--- a/screens/Trading/index.tsx
+++ b/screens/Trading/index.tsx
@@ -21,12 +21,13 @@ import { useMarginConfigToken } from "../../hooks/useMarginConfig";
import { setCategoryAssets1, setCategoryAssets2 } from "../../redux/marginTrading";
import { useMarginAccount } from "../../hooks/useMarginAccount";
import { useAccountId, usePortfolioAssets } from "../../hooks/hooks";
-import { useRouterQuery, getTransactionResult } from "../../utils/txhashContract";
+import { useRouterQuery, getTransactionResult, parsedArgs } from "../../utils/txhashContract";
import { showPositionResult } from "../../components/HashResultModal";
init_env("dev");
const Trading = () => {
+ const marginConfig = useAppSelector(getMarginConfig);
const { query } = useRouterQuery();
const accountId = useAccountId();
const { marginAccountList, parseTokenValue, getAssetDetails, getAssetById } = useMarginAccount();
@@ -53,27 +54,6 @@ const Trading = () => {
};
let timer;
- //
- useEffect(() => {
- if (router.query.transactionHashes) {
- //
- showPositionResult({
- title: "Open Position",
- type: "Long", // optional,"Long" 或 "Short"
- price: "100", // optional,
- transactionHashes: Array.isArray(router.query.transactionHashes)
- ? router.query.transactionHashes[0]
- : (router.query.transactionHashes as string),
- positionSize: {
- // optional,
- amount: "10",
- symbol: "NEAR",
- usdValue: "1000",
- },
- });
- }
- }, [router]);
-
// computed currentTokenCate1 dropdown
useEffect(() => {
if (id) {
@@ -168,11 +148,58 @@ const Trading = () => {
const results = await Promise.all(
txhash.map(async (txHash: string) => {
const result: any = await getTransactionResult(txHash);
- console.log(result);
- return { txHash };
+ const hasStorageDeposit = result.transaction.actions.some(
+ (action: any) => action?.FunctionCall?.method_name === "margin_execute_with_pyth",
+ );
+ return { txHash, result, hasStorageDeposit };
}),
);
- console.log(results, ";rrrr");
+ results.forEach(({ txHash, result, hasStorageDeposit }: any) => {
+ if (hasStorageDeposit) {
+ // handleClaimTokenMobile({ level, count });
+ console.log(result);
+
+ const args = parsedArgs(result?.transaction?.actions?.[0]?.FunctionCall?.args || "");
+ const { actions } = JSON.parse(args || "");
+
+ // const ft_on_transfer_id = result?.receipts?.findIndex((r: any) =>
+ // r?.receipt?.Action?.actions?.some(
+ // (a: any) => a?.FunctionCall?.method_name === "margin_execute_with_pyth",
+ // ),
+ // );
+
+ // const ft_on_transfer_logs =
+ // result?.receipts_outcome?.[ft_on_transfer_id]?.outcome?.logs || "";
+ // const ft_on_transfer_log = ft_on_transfer_logs?.[ft_on_transfer_logs?.length - 1];
+ // const idx = ft_on_transfer_log?.indexOf("{");
+
+ // const parsed_ft_on_transfer_log = JSON.parse(ft_on_transfer_log.slice(idx) || "");
+ const isLong = actions[0]?.OpenPosition?.token_p_id == "wrap.testnet";
+ console.log(actions);
+ console.log(marginConfig);
+ showPositionResult({
+ title: "Open Position",
+ type: isLong ? "Long" : "Short",
+ price: (isLong
+ ? Number(shrinkToken(actions[0]?.OpenPosition?.token_d_amount, 18)) /
+ Number(shrinkToken(actions[0]?.OpenPosition?.min_token_p_amount, 24))
+ : Number(shrinkToken(actions[0]?.OpenPosition?.min_token_p_amount, 18)) /
+ Number(shrinkToken(actions[0]?.OpenPosition?.token_d_amount, 24))
+ ).toString(),
+ transactionHashes: Array.isArray(router.query.transactionHashes)
+ ? router.query.transactionHashes[0]
+ : (router.query.transactionHashes as string),
+ positionSize: {
+ // optional,
+ amount: isLong
+ ? shrinkToken(actions[0]?.OpenPosition?.min_token_p_amount, 24, 6)
+ : shrinkToken(actions[0]?.OpenPosition?.token_d_amount, 24, 6),
+ symbol: "NEAR",
+ usdValue: "1000",
+ },
+ });
+ }
+ });
} catch (error) {
console.error("Error processing transactions:", error);
}
diff --git a/utils/txhashContract.ts b/utils/txhashContract.ts
index 03e97fdd..5e394bb2 100644
--- a/utils/txhashContract.ts
+++ b/utils/txhashContract.ts
@@ -73,3 +73,9 @@ export function useRouterQuery() {
return { query, replaceQuery };
}
+
+export const parsedArgs = (res: any) => {
+ const buff = Buffer.from(res, "base64");
+ const parsedData = buff.toString("ascii");
+ return parsedData;
+};