Skip to content

Commit

Permalink
adjusts use ens name or shorten hook and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
salieflewis committed Jun 27, 2023
1 parent fecce57 commit 314f271
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 95 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-dragons-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@public-assembly/builder-utils': patch
---

Previously certain return statements were breaking the rules of hooks. Fixes ENS resolution approach.
57 changes: 30 additions & 27 deletions apps/router-test/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand Down
18 changes: 3 additions & 15 deletions packages/builder-utils/src/hooks/useEnsNameOrShorten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,10 @@ import { shortenAddress } from '../lib'
import { useEnsName } from 'wagmi'

export function useEnsNameOrShorten({ address }: { address: Hex }) {
const [ensNameOrShorten, setEnsNameOrShorten] = useState<Hex | string>()

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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ 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,
abstainVotes: proposalDetails?.proposal?.abstainVotes,
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 }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export const HISTORICAL_AUCTION_QUERY = graphql(`
bidder
}
settled
highestBid {
bidder
amount
}
bids {
bidder
amount
Expand Down
6 changes: 3 additions & 3 deletions packages/builder-utils/src/subgraph/types/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*/
Expand Down
18 changes: 0 additions & 18 deletions packages/builder-utils/src/subgraph/types/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}>
Expand Down Expand Up @@ -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' },
Expand Down

0 comments on commit 314f271

Please sign in to comment.