Skip to content

Commit

Permalink
fix: get deployment data of connected wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
irisdv committed Jun 18, 2024
1 parent bc3f81d commit 2c8d78e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
38 changes: 27 additions & 11 deletions hooks/isDeployed.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { GetDeploymentDataResult, NetworkType } from "@/constants/types";
import { useConnect } from "@starknet-react/core";
import { useEffect, useState } from "react";
import { wallet } from "starknet";
import getStarknet, { StarknetWindowObject } from "get-starknet-core";

export default function isStarknetDeployed(
network?: NetworkType,
address?: string
) {
const { connector } = useConnect();
const [deploymentData, setDeploymentData] =
useState<GetDeploymentDataResult>();

Expand All @@ -16,22 +20,34 @@ export default function isStarknetDeployed(

const checkIsDeployed = async () => {
try {
if (!window.starknet || !window.starknet.isConnected) {
const availableWallets = await getStarknet.getAvailableWallets();

if (!availableWallets) {
setDeploymentData(undefined);
return;
}

const data = await window.starknet?.request({
// @ts-ignore
type: "wallet_deploymentData",
availableWallets.forEach(async (connectedWallet) => {
if (
connectedWallet.id === connector?.id &&
connectedWallet.isConnected
) {
const data = await wallet.deploymentData(
// @ts-ignore
connectedWallet as StarknetWindowObject
);
console.log("Starknet data for deployment", data);
if (isGetDeploymentDataResult(data)) {
setDeploymentData(data);
} else {
console.error(
"Received data is not in the expected format:",
data
);
setDeploymentData(undefined);
}
}
});
console.log("Starknet data for deployment", data);
if (isGetDeploymentDataResult(data)) {
setDeploymentData(data);
} else {
console.error("Received data is not in the expected format:", data);
setDeploymentData(undefined);
}
} catch (error) {
setDeploymentData(undefined);
}
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/ws": "^8.5.10",
"bn.js": "^5.2.1",
"ethers": "^6.12.1",
"get-starknet-core": "^3.3.0",
"next": "14.2.3",
"react": "^18",
"react-dom": "^18",
Expand Down

0 comments on commit 2c8d78e

Please sign in to comment.