Skip to content

Commit

Permalink
fix UseDeployedMechs query keys
Browse files Browse the repository at this point in the history
  • Loading branch information
samepant committed Jan 23, 2024
1 parent c7a921f commit 90911f9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
4 changes: 4 additions & 0 deletions frontend/src/components/NFTGridItem/NFTItem.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
font-family: monospace;
}

.tokenId.collectionTokenId {
max-width: 100%;
}

.tokenName {
max-width: 68%;
}
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/components/NFTGridItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ const NFTGridItem: React.FC<Props> = ({ nft, chainId, showCollectionName }) => {
<p className={classes.tokenName}>{name || "..."}</p>
)}
{nft.token_id.length < 7 && (
<p className={classes.tokenId}>{nft.token_id || "..."}</p>
<p
className={clsx(
classes.tokenId,
!showCollectionName && classes.collectionTokenId
)}
>
{nft.token_id || "..."}
</p>
)}
</div>
<div className={classes.footer}>
Expand Down
46 changes: 22 additions & 24 deletions frontend/src/hooks/useDeployMech.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<boolean>(
["mechDeployed", { address: mechAddress, chainId: chainId }] as const,
{
queryFn: queryFn(publicClient) as any,
enabled: !!mechAddress,
}
)
const { data: deployed } = useQuery<boolean>({
queryKey: ["mechDeployed", { address: mechAddress, chainId: chainId }],
queryFn: queryFn(publicClient) as any,
enabled: !!mechAddress,
})

const { data: walletClient } = useWalletClient({ chainId })

Expand Down Expand Up @@ -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,
{
Expand Down

1 comment on commit 90911f9

@vercel
Copy link

@vercel vercel bot commented on 90911f9 Jan 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.