From 90911f9ac423710c3e538111fb2e267a2693b03d Mon Sep 17 00:00:00 2001 From: samepant Date: Tue, 23 Jan 2024 10:49:18 -0500 Subject: [PATCH] fix UseDeployedMechs query keys --- .../components/NFTGridItem/NFTItem.module.css | 4 ++ frontend/src/components/NFTGridItem/index.tsx | 9 +++- frontend/src/hooks/useDeployMech.tsx | 46 +++++++++---------- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/frontend/src/components/NFTGridItem/NFTItem.module.css b/frontend/src/components/NFTGridItem/NFTItem.module.css index 53f3730..4f00189 100644 --- a/frontend/src/components/NFTGridItem/NFTItem.module.css +++ b/frontend/src/components/NFTGridItem/NFTItem.module.css @@ -84,6 +84,10 @@ font-family: monospace; } +.tokenId.collectionTokenId { + max-width: 100%; +} + .tokenName { max-width: 68%; } diff --git a/frontend/src/components/NFTGridItem/index.tsx b/frontend/src/components/NFTGridItem/index.tsx index bc19db9..bbdfccb 100644 --- a/frontend/src/components/NFTGridItem/index.tsx +++ b/frontend/src/components/NFTGridItem/index.tsx @@ -28,7 +28,14 @@ const NFTGridItem: React.FC = ({ nft, chainId, showCollectionName }) => {

{name || "..."}

)} {nft.token_id.length < 7 && ( -

{nft.token_id || "..."}

+

+ {nft.token_id || "..."} +

)}
diff --git a/frontend/src/hooks/useDeployMech.tsx b/frontend/src/hooks/useDeployMech.tsx index b9f2ef8..f8e3191 100644 --- a/frontend/src/hooks/useDeployMech.tsx +++ b/frontend/src/hooks/useDeployMech.tsx @@ -1,10 +1,6 @@ import { useEffect, useState } from "react" -import { - usePublicClient, - useWalletClient, - useQuery, - useQueryClient, -} from "wagmi" +import { usePublicClient, useWalletClient } from "wagmi" +import { useQuery, useQueryClient } from "@tanstack/react-query" import { PublicClient } from "viem" import { calculateMechAddress } from "../utils/calculateMechAddress" import { makeMechDeployTransaction } from "../utils/deployMech" @@ -32,13 +28,11 @@ export const useDeployMech = (token: NFTContext | null, chainId: number) => { const mechAddress = token && calculateMechAddress(token, chainId) const publicClient = usePublicClient({ chainId: chainId }) - const { data: deployed } = useQuery( - ["mechDeployed", { address: mechAddress, chainId: chainId }] as const, - { - queryFn: queryFn(publicClient) as any, - enabled: !!mechAddress, - } - ) + const { data: deployed } = useQuery({ + queryKey: ["mechDeployed", { address: mechAddress, chainId: chainId }], + queryFn: queryFn(publicClient) as any, + enabled: !!mechAddress, + }) const { data: walletClient } = useWalletClient({ chainId }) @@ -69,27 +63,31 @@ export const useDeployMech = (token: NFTContext | null, chainId: number) => { export const useDeployedMechs = (nfts: NFTContext[], chainId: number) => { const queryClient = useQueryClient() + const publicClient = usePublicClient({ chainId }) useEffect(() => { nfts.forEach((nft) => { queryClient - .ensureQueryData([ - "mechDeployed", - { - address: calculateMechAddress(nft, chainId), - chainId: chainId, - }, - ]) + .ensureQueryData({ + queryKey: [ + "mechDeployed", + { + address: calculateMechAddress(nft, chainId), + chainId: chainId, + }, + ], + queryFn: queryFn(publicClient), + }) .catch((e) => { console.error(e) /* when switching networks, this might throw an error (`Missing queryFn for queryKey`) */ }) }) - }, [queryClient, nfts, chainId]) + }, [queryClient, nfts, chainId, publicClient]) - const deployedMechs = queryClient.getQueriesData([ - "mechDeployed", - ]) as unknown as [ + const deployedMechs = queryClient.getQueriesData({ + queryKey: ["mechDeployed"], + }) as unknown as [ [ string, {