Skip to content

Commit

Permalink
fix: getTxVersion when supports_interface call fails
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Jun 18, 2024
1 parent 2c8d78e commit 00f5bc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
5 changes: 2 additions & 3 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,9 @@ export default function Home() {
const nonce = Math.floor(Math.random() * 1000000000000);
const executeBefore = Math.floor(Date.now() / 1000) + 3600 * 48; // + 48h for testing
const outsideExecution = getOutsideExecution(nonce, executeBefore);
if (!txVersion && !deploymentData?.version)
console.log("txVersion is undefined");
if (!txVersion) console.log("txVersion is undefined");
const typedData =
txVersion === 1 || deploymentData?.version === 1
txVersion === 1
? getTypedData(outsideExecution)
: getTypedDataV2(outsideExecution);

Expand Down
21 changes: 14 additions & 7 deletions hooks/getTxVersion.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NetworkType } from "@/constants/types";
import { useAccount } from "@starknet-react/core";
import { useAccount, useConnect } from "@starknet-react/core";
import { useEffect, useState } from "react";

export default function getTxVersion(network?: NetworkType, address?: string) {
const { account } = useAccount();
const { connector } = useConnect();
const [txVersion, setVersion] = useState<number | undefined>();

useEffect(() => {
Expand All @@ -12,7 +13,7 @@ export default function getTxVersion(network?: NetworkType, address?: string) {
return;
}

const checkIsDeployed = async () => {
const checkTxVersion = async () => {
try {
const supports_v1 = await account.callContract({
contractAddress: account.address,
Expand All @@ -29,20 +30,26 @@ export default function getTxVersion(network?: NetworkType, address?: string) {
"0x1d1144bb2138366ff28d8e9ab57456b1d332ac42196230c3a602003c89872",
],
});
console.log("supports results", supports_v1, supports_v2);

// @ts-ignore
if (Number(supports_v1.result[0])) setVersion(1);
// @ts-ignore
else if (Number(supports_v2.result[0])) setVersion(2);
else setVersion(undefined);
else {
if (connector?.id === "argent") setVersion(1);
else if (connector?.id === "braavos") setVersion(2);
else setVersion(undefined);
}
} catch (error) {
setVersion(undefined);
console.log("Error while checking tx version", error);
if (connector?.id.includes("argent")) setVersion(1);
else if (connector?.id === "braavos") setVersion(2);
else setVersion(undefined);
}
};

checkIsDeployed();
}, [network, address]);
checkTxVersion();
}, [network, address, account?.address, connector]);

return txVersion;
}

0 comments on commit 00f5bc8

Please sign in to comment.