-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dynamically fetch DAO voting stats (#268)
* refactor: replace images * fetch number of proposals * fetch voting stats at build time * improve parsing of proposal titles * dynamically import ParallaxDaoStats to fix runtime error * bump version v1.3.10
- Loading branch information
1 parent
6e83e90
commit 1afbb1d
Showing
20 changed files
with
185 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
src/components/Governance/ParallaxDaoStats/ParallaxDaoStats.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ParallaxDaoStatsElement from '@/components/Governance/ParallaxDaoStats/ParallaxDaoStatsElement' | ||
import ParallaxText, { type ParallaxTextProps } from '@/components/common/ParallaxText' | ||
|
||
const ParallaxDaoStats = (props: ParallaxTextProps) => { | ||
return ( | ||
<ParallaxText {...props}> | ||
<ParallaxDaoStatsElement items={props.items} /> | ||
</ParallaxText> | ||
) | ||
} | ||
|
||
export default ParallaxDaoStats |
34 changes: 26 additions & 8 deletions
34
src/components/Governance/ParallaxDaoStats/ParallaxDaoStatsElement.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
import ParallaxDaoStatsElement from '@/components/Governance/ParallaxDaoStats/ParallaxDaoStatsElement' | ||
import ParallaxText, { type ParallaxTextProps } from '@/components/common/ParallaxText' | ||
import dynamic from 'next/dynamic' | ||
|
||
const ParallaxDaoStats = (props: ParallaxTextProps) => { | ||
return ( | ||
<ParallaxText {...props}> | ||
<ParallaxDaoStatsElement /> | ||
</ParallaxText> | ||
) | ||
} | ||
const Proposals = dynamic(() => import('./ParallaxDaoStats')) | ||
|
||
export default ParallaxDaoStats | ||
export default Proposals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
import PageContent from '@/components/common/PageContent' | ||
import governanceContent from '@/content/governance.json' | ||
import VotingDelegationContext from '@/contexts/VotingDelegationContext' | ||
import type { getStaticProps } from '@/pages/governance' | ||
import type { InferGetStaticPropsType } from 'next' | ||
|
||
export const Governance = () => { | ||
return <PageContent content={governanceContent} path="governance.json" /> | ||
export const Governance = (props: InferGetStaticPropsType<typeof getStaticProps>) => { | ||
return ( | ||
<VotingDelegationContext.Provider value={props.votingDelegation}> | ||
<PageContent content={governanceContent} path="governance.json" /> | ||
</VotingDelegationContext.Provider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createContext } from 'react' | ||
|
||
type VotingDelegation = { | ||
totalDelegates: number | null | ||
totalDelegators: number | null | ||
} | ||
|
||
const VotingDelegationContext = createContext<VotingDelegation>({ | ||
totalDelegates: null, | ||
totalDelegators: null, | ||
}) | ||
|
||
export default VotingDelegationContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { DUNE_API_KEY } from '@/config/constants' | ||
import VotingDelegationContext from '@/contexts/VotingDelegationContext' | ||
import { duneQueryUrlBuilder } from '@/lib/duneQueryUrlBuilder' | ||
import { formatValue } from '@/lib/formatValue' | ||
import { useContext } from 'react' | ||
|
||
const QUERY_ID_TOTAL_DELEGATIONS = 3407074 | ||
|
||
export const fetchTotalDelegates = async (): Promise<{ delegate_unique: number; delegator_count: number } | null> => { | ||
return fetch(duneQueryUrlBuilder(QUERY_ID_TOTAL_DELEGATIONS, DUNE_API_KEY)) | ||
.then((res) => res.json()) | ||
.then((data) => data.result.rows[0]) | ||
.catch(() => null) | ||
} | ||
|
||
export const useVotingDelegation = (): Array<string | null> => { | ||
const { totalDelegates, totalDelegators } = useContext(VotingDelegationContext) | ||
|
||
const formattedTotalDelegates = totalDelegates ? formatValue(totalDelegates) : null | ||
const formattedTotalDelegators = totalDelegators ? formatValue(totalDelegators) : null | ||
|
||
return [formattedTotalDelegates, formattedTotalDelegators] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const duneQueryUrlBuilder = (queryId: number, apiKey: string) => | ||
`https://api.dune.com/api/v1/query/${queryId}/results?api_key=${apiKey}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.