diff --git a/components/admin/create-registry-modal.tsx b/components/admin/create-registry-modal.tsx index d5c49b0..dd7f6e7 100644 --- a/components/admin/create-registry-modal.tsx +++ b/components/admin/create-registry-modal.tsx @@ -11,6 +11,7 @@ import { } from "@/components/forms/create-or-update-registry-form"; import { useChainId } from "wagmi"; import { useCreateClaims } from "@/hooks/useCreateClaims"; +import { useHypercertClient } from "@/components/providers"; export const CreateRegistryModal = ({ initialValues, @@ -22,6 +23,7 @@ export const CreateRegistryModal = ({ const address = useAddress(); const toast = useToast(); const chainId = useChainId(); + const client = useHypercertClient(); const { refetch } = useMyRegistries(); const { mutateAsync: createClaims } = useCreateClaims(); @@ -30,6 +32,17 @@ export const CreateRegistryModal = ({ claims, ...registry }: CreateUpdateRegistryFormValues) => { + if (!client) { + toast({ + title: "Error", + description: "Client not initialized", + status: "error", + duration: 9000, + isClosable: true, + }); + return; + } + if (!address) { toast({ title: "Error", @@ -86,12 +99,21 @@ export const CreateRegistryModal = ({ }); try { - const claimInserts: ClaimInsert[] = claims.map(({ hypercert_id }) => ({ - registry_id: insertedRegistry.id, - hypercert_id, - chain_id: chainId, - admin_id: address, - })); + const claimInserts: ClaimInsert[] = await Promise.all( + claims.map(async ({ hypercert_id }) => { + const claim = await client.indexer.claimById(hypercert_id); + if (!claim.claim) { + throw new Error("Claim not found"); + } + return { + registry_id: insertedRegistry.id, + hypercert_id, + chain_id: chainId, + admin_id: address, + owner_id: claim.claim.owner, + }; + }), + ); await createClaims({ claims: claimInserts, });