Skip to content

Commit d74d420

Browse files
committed
added in useAllModuleContractInfo hook
1 parent 77316eb commit d74d420

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

apps/dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"preinstall": "npx only-allow pnpm",
7-
"dev": "next dev --turbo",
7+
"dev": "next dev",
88
"build": "next build",
99
"start": "next start",
1010
"format": "biome format ./src --write",

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/InstalledModulesTable.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CircleSlash } from "lucide-react";
66
import type { ContractOptions } from "thirdweb";
77
import type { Account } from "thirdweb/wallets";
88
import { ModuleCard } from "./module-card";
9+
import { useAllModuleContractInfo } from "./moduleContractInfo";
910

1011
export const InstalledModulesTable = (props: {
1112
contract: ContractOptions;
@@ -18,6 +19,12 @@ export const InstalledModulesTable = (props: {
1819
}) => {
1920
const { installedModules, ownerAccount } = props;
2021

22+
const allModuleContractInfo = useAllModuleContractInfo(
23+
installedModules.data || [],
24+
props.contract,
25+
);
26+
console.log("allModuleContractInfo: ", allModuleContractInfo);
27+
2128
const sectionTitle = (
2229
<h2 className="mb-3 font-bold text-2xl tracking-tight">
2330
Installed Modules

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/components/moduleContractInfo.ts

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,71 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { fetchPublishedContractsFromDeploy } from "components/contract-components/fetchPublishedContractsFromDeploy";
13
import { usePublishedContractsFromDeploy } from "components/contract-components/hooks";
24
import { THIRDWEB_DEPLOYER_ADDRESS } from "constants/addresses";
35
import { useMemo } from "react";
4-
import type { ThirdwebContract } from "thirdweb";
6+
import { type ThirdwebContract, getContract } from "thirdweb";
57
import { useActiveAccount } from "thirdweb/react";
68

9+
export async function getAllModuleContractInfo(
10+
activeAccountAddress: string,
11+
installedModules: string[],
12+
contract: ThirdwebContract,
13+
) {
14+
if (!activeAccountAddress) {
15+
return [];
16+
}
17+
18+
return Promise.all(
19+
installedModules.map(async (moduleAddress) => {
20+
const publishedContractsFromDeploy =
21+
await fetchPublishedContractsFromDeploy({
22+
contract: getContract({
23+
address: moduleAddress,
24+
chain: contract.chain,
25+
client: contract.client,
26+
}),
27+
client: contract.client,
28+
});
29+
30+
const reversedPublishedContractsFromDeploy = [
31+
...(publishedContractsFromDeploy || []),
32+
].reverse();
33+
34+
const publishedContractToShow =
35+
reversedPublishedContractsFromDeploy.find(
36+
(publishedContract) =>
37+
publishedContract.publisher === activeAccountAddress,
38+
) ||
39+
reversedPublishedContractsFromDeploy.find(
40+
(publishedContract) =>
41+
publishedContract.publisher === THIRDWEB_DEPLOYER_ADDRESS,
42+
) ||
43+
reversedPublishedContractsFromDeploy[
44+
reversedPublishedContractsFromDeploy.length - 1
45+
] ||
46+
undefined;
47+
48+
return publishedContractToShow as
49+
| typeof publishedContractToShow
50+
| undefined;
51+
}),
52+
);
53+
}
54+
55+
export function useAllModuleContractInfo(
56+
installedModules: string[],
57+
contract: ThirdwebContract,
58+
) {
59+
const address = useActiveAccount()?.address;
60+
61+
return useQuery({
62+
queryKey: ["all-module-contract-info", installedModules, contract, address],
63+
queryFn: () =>
64+
getAllModuleContractInfo(address || "", installedModules || [], contract),
65+
enabled: !!address && !!contract,
66+
});
67+
}
68+
769
export function useModuleContractInfo(contract: ThirdwebContract) {
870
const address = useActiveAccount()?.address;
971

apps/dashboard/src/app/(dashboard)/(chain)/[chain_id]/[contractAddress]/modules/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default async function Page(props: {
1818
}
1919

2020
const { contract } = info;
21+
2122
if (contract.chain.id === localhost.id) {
2223
return <ContractEditModulesPageClient contract={contract} />;
2324
}

0 commit comments

Comments
 (0)