diff --git a/.changeset/smart-dragons-deliver.md b/.changeset/smart-dragons-deliver.md new file mode 100644 index 0000000..fd8251b --- /dev/null +++ b/.changeset/smart-dragons-deliver.md @@ -0,0 +1,5 @@ +--- +'@public-assembly/builder-utils': patch +--- + +Previously certain return statements were breaking the rules of hooks. Fixes ENS resolution approach. diff --git a/apps/router-test/src/app/page.tsx b/apps/router-test/src/app/page.tsx index 64236da..8e4dcb4 100644 --- a/apps/router-test/src/app/page.tsx +++ b/apps/router-test/src/app/page.tsx @@ -8,53 +8,56 @@ import { useAuctionConfigQuery, useProposalVotesQuery, useHistoricalBids, + useProposalDetailsQuery, } from '@public-assembly/builder-utils' import Link from 'next/link' export default function Page() { const { auctionState } = useAuctionState() - console.log(auctionState) + // console.log(auctionState) const currentTokenId = auctionState.tokenId - const { tokenName, tokenId, tokenOwner, tokenImage, mintedAt } = - useHistoricalTokenQuery({ - tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', - tokenId: currentTokenId ? BigInt(auctionState.tokenId) : BigInt(false), - }) + // const { tokenName, tokenId, tokenOwner, tokenImage, mintedAt } = + // useHistoricalTokenQuery({ + // tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', + // tokenId: currentTokenId ? BigInt(auctionState.tokenId) : BigInt(false), + // }) - console.log(tokenName, tokenId, tokenOwner, tokenImage, mintedAt) + // console.log(tokenName, tokenId, tokenOwner, tokenImage, mintedAt) - const { winningBid, highestBid, startTime, endTime, bids } = useHistoricalAuctionQuery({ - tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', - tokenId: currentTokenId ? BigInt(auctionState.tokenId) : BigInt(false), - }) + const { winningBid, startTime, endTime, bids, winningBidder } = + useHistoricalAuctionQuery({ + tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', + // tokenId: currentTokenId ? BigInt(auctionState.tokenId) : BigInt(false), + tokenId: BigInt(54), + }) - console.log(winningBid, highestBid, startTime, endTime, bids) + // console.log(winningBid, startTime, endTime, bids, winningBidder) - const { minimumBidIncrement } = useAuctionConfigQuery({ - tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', - }) + // const { minimumBidIncrement } = useAuctionConfigQuery({ + // tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', + // }) - console.log(minimumBidIncrement) + // console.log(minimumBidIncrement) - const { minBidAmount } = useMinBidAmount() + // const { minBidAmount } = useMinBidAmount() - console.log('Min bid amount:', minBidAmount) + // console.log('Min bid amount:', minBidAmount) - const { proposalVotes } = useProposalVotesQuery({ - proposalId: '0xb0f228abbc5af114f9844f299b5d97ab99959f36786a8cfaddf237e072906956', - }) + // const { proposalVotes } = useProposalVotesQuery({ + // proposalId: '0xb0f228abbc5af114f9844f299b5d97ab99959f36786a8cfaddf237e072906956', + // }) - console.log(proposalVotes) + // console.log(proposalVotes) - const { filteredBidEvents } = useHistoricalBids({ - tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', - tokenId: String(auctionState.tokenId), - }) + // const { filteredBidEvents } = useHistoricalBids({ + // tokenAddress: '0xd2e7684cf3e2511cc3b4538bb2885dc206583076', + // tokenId: String(auctionState.tokenId), + // }) - console.log(filteredBidEvents) + // console.log(filteredBidEvents) return ( <> diff --git a/packages/builder-utils/src/hooks/useEnsNameOrShorten.ts b/packages/builder-utils/src/hooks/useEnsNameOrShorten.ts index 35e7e4f..9ab6f2d 100644 --- a/packages/builder-utils/src/hooks/useEnsNameOrShorten.ts +++ b/packages/builder-utils/src/hooks/useEnsNameOrShorten.ts @@ -4,22 +4,10 @@ import { shortenAddress } from '../lib' import { useEnsName } from 'wagmi' export function useEnsNameOrShorten({ address }: { address: Hex }) { - const [ensNameOrShorten, setEnsNameOrShorten] = useState() - - const { isLoading: loadingEns } = useEnsName({ + const { data: ensName, isLoading: loadingEns } = useEnsName({ address, - onSuccess(data) { - if (address) - if (data === address) { - setEnsNameOrShorten(shortenAddress(address)) - } else { - setEnsNameOrShorten(data as string) - } - }, - onError(error) { - console.log('Error', error) - }, }) - return { ensNameOrShorten, loadingEns } + if (!ensName) return shortenAddress(address) + return ensName } diff --git a/packages/builder-utils/src/subgraph/hooks/useCurrentAuctionQuery.ts b/packages/builder-utils/src/subgraph/hooks/useCurrentAuctionQuery.ts index c4a5cac..889e662 100644 --- a/packages/builder-utils/src/subgraph/hooks/useCurrentAuctionQuery.ts +++ b/packages/builder-utils/src/subgraph/hooks/useCurrentAuctionQuery.ts @@ -13,28 +13,35 @@ export function useCurrentAuctionQuery({ tokenAddress }: { tokenAddress: Hex }) fetcher(CURRENT_AUCTION_QUERY, { id: tokenAddress } as CurrentAuctionQueryVariables) ) + const winningBidder = useEnsNameOrShorten({ + address: currentAuction?.dao?.currentAuction?.winningBid?.bidder, + }) + const highestBidder = useEnsNameOrShorten({ + address: currentAuction?.dao?.currentAuction?.highestBid?.bidder, + }) + return { tokenId: currentAuction?.dao?.currentAuction?.token?.tokenId, startTime: currentAuction?.dao?.currentAuction?.startTime - ? formatFromUnix(currentAuction?.dao?.currentAuction?.startTime) + ? formatFromUnix({ + timestamp: currentAuction?.dao?.currentAuction?.startTime, + }) : '', endTime: currentAuction?.dao?.currentAuction?.endTime - ? formatFromUnix(currentAuction?.dao?.currentAuction?.endTime) + ? formatFromUnix({ + timestamp: currentAuction?.dao?.currentAuction?.endTime, + }) : '', extended: currentAuction?.dao?.currentAuction?.extended, settled: currentAuction?.dao?.currentAuction?.settled, - error, winningBid: currentAuction?.dao?.currentAuction?.winningBid?.amount ? formatEther(BigInt(currentAuction?.dao?.currentAuction?.winningBid?.amount)) : '', - winningBidder: useEnsNameOrShorten({ - address: currentAuction?.dao?.currentAuction?.winningBid?.bidder, - }).ensNameOrShorten, + winningBidder: winningBidder, highestBid: currentAuction?.dao?.currentAuction?.highestBid?.amount ? formatEther(BigInt(currentAuction?.dao?.currentAuction?.highestBid?.amount)) : '', - highestBidder: useEnsNameOrShorten({ - address: currentAuction?.dao?.currentAuction?.highestBid?.bidder, - }).ensNameOrShorten, + highestBidder: highestBidder, + error, } } diff --git a/packages/builder-utils/src/subgraph/hooks/useHistoricalAuctionQuery.ts b/packages/builder-utils/src/subgraph/hooks/useHistoricalAuctionQuery.ts index 2c02f34..4cf4fe4 100644 --- a/packages/builder-utils/src/subgraph/hooks/useHistoricalAuctionQuery.ts +++ b/packages/builder-utils/src/subgraph/hooks/useHistoricalAuctionQuery.ts @@ -21,13 +21,22 @@ export function useHistoricalAuctionQuery({ tokenId: tokenId.toString(), } as HistoricalAuctionQueryVariables) ) + + const winningBidder = useEnsNameOrShorten({ + address: historicalAuction?.dao?.tokens[0]?.auction?.winningBid?.bidder, + }) + return { tokenId: historicalAuction?.dao?.tokens[0]?.tokenId, startTime: historicalAuction?.dao?.tokens[0]?.auction?.startTime - ? formatFromUnix(historicalAuction?.dao?.tokens[0]?.auction?.startTime) + ? formatFromUnix({ + timestamp: historicalAuction?.dao?.tokens[0]?.auction?.startTime, + }) : '', endTime: historicalAuction?.dao?.tokens[0]?.auction?.endTime - ? formatFromUnix(historicalAuction?.dao?.tokens[0]?.auction?.endTime) + ? formatFromUnix({ + timestamp: historicalAuction?.dao?.tokens[0]?.auction?.endTime, + }) : '', extended: historicalAuction?.dao?.tokens[0]?.auction?.extended, settled: historicalAuction?.dao?.tokens[0]?.auction?.settled, @@ -36,17 +45,7 @@ export function useHistoricalAuctionQuery({ BigInt(historicalAuction?.dao?.tokens[0]?.auction?.winningBid?.amount) ) : '', - winningBidder: useEnsNameOrShorten({ - address: historicalAuction?.dao?.tokens[0]?.auction?.winningBid?.bidder, - }).ensNameOrShorten, - highestBid: historicalAuction?.dao?.tokens[0]?.auction?.highestBid?.amount - ? formatEther( - BigInt(historicalAuction?.dao?.tokens[0]?.auction?.highestBid?.amount) - ) - : '', - highestBidder: useEnsNameOrShorten({ - address: historicalAuction?.dao?.tokens[0]?.auction?.highestBid?.bidder, - }).ensNameOrShorten, + winningBidder: winningBidder as string, bids: historicalAuction?.dao?.tokens.flatMap((auction) => { return auction?.auction?.bids ? auction?.auction?.bids.map((bid) => ({ diff --git a/packages/builder-utils/src/subgraph/hooks/useHistoricalTokenQuery.ts b/packages/builder-utils/src/subgraph/hooks/useHistoricalTokenQuery.ts index ab2aec7..a824b1a 100644 --- a/packages/builder-utils/src/subgraph/hooks/useHistoricalTokenQuery.ts +++ b/packages/builder-utils/src/subgraph/hooks/useHistoricalTokenQuery.ts @@ -22,12 +22,15 @@ export function useHistoricalTokenQuery({ } as HistoricalTokenQueryVariables) ) + const tokenOwner = useEnsNameOrShorten({ + address: historicalToken?.dao?.tokens[0]?.owner, + }) + return { tokenId: historicalToken?.dao?.tokens[0]?.tokenId, tokenName: historicalToken?.dao?.tokens[0]?.name, tokenImage: historicalToken?.dao?.tokens[0]?.image, - tokenOwner: useEnsNameOrShorten({ address: historicalToken?.dao?.tokens[0]?.owner }) - .ensNameOrShorten, + tokenOwner: tokenOwner, mintedAt: formatFromUnix({ timestamp: historicalToken?.dao?.tokens[0]?.mintedAt }), mintedAtRaw: historicalToken?.dao?.tokens[0]?.mintedAt, error, diff --git a/packages/builder-utils/src/subgraph/hooks/useProposalDetailsQuery.ts b/packages/builder-utils/src/subgraph/hooks/useProposalDetailsQuery.ts index 2b6d2a4..c0dca6c 100644 --- a/packages/builder-utils/src/subgraph/hooks/useProposalDetailsQuery.ts +++ b/packages/builder-utils/src/subgraph/hooks/useProposalDetailsQuery.ts @@ -11,6 +11,8 @@ export function useProposalDetailsQuery({ proposalId }: { proposalId: string }) () => fetcher(PROPOSAL_DETAILS_QUERY, { proposalId } as ProposalDetailsQueryVariables) ) + const proposer = useEnsNameOrShorten({ address: proposalDetails?.proposal?.proposer }) + return { forVotes: proposalDetails?.proposal?.forVotes, againstVotes: proposalDetails?.proposal?.againstVotes, @@ -18,13 +20,14 @@ export function useProposalDetailsQuery({ proposalId }: { proposalId: string }) calldatas: proposalDetails?.proposal?.calldatas, description: proposalDetails?.proposal?.description, descriptionHash: proposalDetails?.proposal?.descriptionHash, - executableFrom: proposalDetails?.proposal?.executableFrom, - expiresAt: proposalDetails?.proposal?.expiresAt, + executableFrom: formatFromUnix({ + timestamp: proposalDetails?.proposal?.executableFrom, + }), + expiresAt: formatFromUnix({ timestamp: proposalDetails?.proposal?.expiresAt }), proposalId: proposalDetails?.proposal?.proposalId, proposalNumber: proposalDetails?.proposal?.proposalNumber, proposalThreshold: proposalDetails?.proposal?.proposalThreshold, - proposer: useEnsNameOrShorten({ address: proposalDetails?.proposal?.proposer }) - .ensNameOrShorten, + proposer: proposer, quorumVotes: proposalDetails?.proposal?.quorumVotes, targets: proposalDetails?.proposal?.targets, timeCreated: formatFromUnix({ timestamp: proposalDetails?.proposal?.timeCreated }), diff --git a/packages/builder-utils/src/subgraph/queries/historicalAuction.ts b/packages/builder-utils/src/subgraph/queries/historicalAuction.ts index fa74041..c8e2fa1 100644 --- a/packages/builder-utils/src/subgraph/queries/historicalAuction.ts +++ b/packages/builder-utils/src/subgraph/queries/historicalAuction.ts @@ -14,10 +14,6 @@ export const HISTORICAL_AUCTION_QUERY = graphql(` bidder } settled - highestBid { - bidder - amount - } bids { bidder amount diff --git a/packages/builder-utils/src/subgraph/types/gql.ts b/packages/builder-utils/src/subgraph/types/gql.ts index da5ca4a..18eeb39 100644 --- a/packages/builder-utils/src/subgraph/types/gql.ts +++ b/packages/builder-utils/src/subgraph/types/gql.ts @@ -23,7 +23,7 @@ const documents = { types.DaoDetailsDocument, '\n query DaoProposals($id: ID!) {\n dao(id: $id) {\n proposals(orderDirection: desc, orderBy: timeCreated) {\n id\n }\n }\n }\n': types.DaoProposalsDocument, - '\n query HistoricalAuction($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n auction {\n startTime\n endTime\n extended\n winningBid {\n amount\n bidder\n }\n settled\n highestBid {\n bidder\n amount\n }\n bids {\n bidder\n amount\n }\n }\n }\n }\n }\n': + '\n query HistoricalAuction($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n auction {\n startTime\n endTime\n extended\n winningBid {\n amount\n bidder\n }\n settled\n bids {\n bidder\n amount\n }\n }\n }\n }\n }\n': types.HistoricalAuctionDocument, '\n query HistoricalToken($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n name\n owner\n mintedAt\n image\n }\n }\n }\n': types.HistoricalTokenDocument, @@ -81,8 +81,8 @@ export function graphql( * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query HistoricalAuction($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n auction {\n startTime\n endTime\n extended\n winningBid {\n amount\n bidder\n }\n settled\n highestBid {\n bidder\n amount\n }\n bids {\n bidder\n amount\n }\n }\n }\n }\n }\n' -): typeof documents['\n query HistoricalAuction($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n auction {\n startTime\n endTime\n extended\n winningBid {\n amount\n bidder\n }\n settled\n highestBid {\n bidder\n amount\n }\n bids {\n bidder\n amount\n }\n }\n }\n }\n }\n'] + source: '\n query HistoricalAuction($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n auction {\n startTime\n endTime\n extended\n winningBid {\n amount\n bidder\n }\n settled\n bids {\n bidder\n amount\n }\n }\n }\n }\n }\n' +): typeof documents['\n query HistoricalAuction($id: ID!, $tokenId: BigInt!) {\n dao(id: $id) {\n tokens(where: { tokenId: $tokenId }) {\n tokenId\n auction {\n startTime\n endTime\n extended\n winningBid {\n amount\n bidder\n }\n settled\n bids {\n bidder\n amount\n }\n }\n }\n }\n }\n'] /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/packages/builder-utils/src/subgraph/types/graphql.ts b/packages/builder-utils/src/subgraph/types/graphql.ts index 5b7f3b6..df75d8f 100644 --- a/packages/builder-utils/src/subgraph/types/graphql.ts +++ b/packages/builder-utils/src/subgraph/types/graphql.ts @@ -1950,7 +1950,6 @@ export type HistoricalAuctionQuery = { extended: boolean settled: boolean winningBid?: { __typename?: 'AuctionBid'; amount: any; bidder: any } | null - highestBid?: { __typename?: 'AuctionBid'; bidder: any; amount: any } | null bids?: Array<{ __typename?: 'AuctionBid'; bidder: any; amount: any }> | null } | null }> @@ -2431,23 +2430,6 @@ export const HistoricalAuctionDocument = { }, }, { kind: 'Field', name: { kind: 'Name', value: 'settled' } }, - { - kind: 'Field', - name: { kind: 'Name', value: 'highestBid' }, - selectionSet: { - kind: 'SelectionSet', - selections: [ - { - kind: 'Field', - name: { kind: 'Name', value: 'bidder' }, - }, - { - kind: 'Field', - name: { kind: 'Name', value: 'amount' }, - }, - ], - }, - }, { kind: 'Field', name: { kind: 'Name', value: 'bids' },