-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAO-720 feat: Implemented Time Remaining Column. (#241)
feat: Revamped proposals to use context. feat: Reduced api calls to backend. feat: Separated each column into its own file. feat: separated proposal state into its own hook. fix: added refetch interval to voteOnProposal to avoid unnecessary calls to node
- Loading branch information
1 parent
8f04d77
commit 6f83201
Showing
12 changed files
with
317 additions
and
136 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
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 { useRouter } from 'next/navigation' | ||
import { useProposalContext } from '@/app/proposals/ProposalsContext' | ||
|
||
export const ProposalNameColumn = () => { | ||
const router = useRouter() | ||
const { name, proposalId } = useProposalContext() | ||
return ( | ||
<button onClick={() => router.push(`/proposals/${proposalId}`)}> | ||
<span className="underline text-left">{name.slice(0, 20)}</span> | ||
</button> | ||
) | ||
} |
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,64 @@ | ||
import { createContext, ReactNode, useContext, useMemo } from 'react' | ||
import { useGetProposalVotes } from '@/app/proposals/hooks/useGetProposalVotes' | ||
import { useProposalState } from '@/shared/hooks/useProposalState' | ||
|
||
interface ProposalsContextProps { | ||
proposalVotes: string[] | ||
name: string | ||
proposalId: string | ||
// Index of row rendered in table | ||
index: number | ||
// Status transformed to human-friendly string | ||
proposalStateHuman: string | ||
// Block in which the proposal was created | ||
blockNumber: string | ||
} | ||
|
||
const ProposalsContext = createContext<ProposalsContextProps>({ | ||
proposalVotes: [], | ||
name: '', | ||
proposalId: '', | ||
index: 0, | ||
proposalStateHuman: '', | ||
blockNumber: '0', | ||
}) | ||
|
||
interface ProposalsContextProviderProps { | ||
proposalId: string | ||
name: string | ||
index: number | ||
children: ReactNode | ||
blockNumber: string // HEX blockNumber | ||
} | ||
|
||
export const ProposalsContextProvider = ({ | ||
proposalId, | ||
name, | ||
index, | ||
children, | ||
blockNumber, | ||
}: ProposalsContextProviderProps) => { | ||
const proposalVotes = useGetProposalVotes(proposalId) | ||
const { proposalStateHuman } = useProposalState(proposalId, false) | ||
const value: ProposalsContextProps = useMemo( | ||
() => ({ | ||
proposalVotes: proposalVotes, | ||
proposalId, | ||
name, | ||
index, | ||
proposalStateHuman, | ||
blockNumber, | ||
}), | ||
[proposalVotes, proposalId, name, index, proposalStateHuman, blockNumber], | ||
) | ||
return <ProposalsContext.Provider value={value}>{children}</ProposalsContext.Provider> | ||
} | ||
|
||
// Hook to use the ProposalsContext for an individual proposal | ||
export const useProposalContext = () => { | ||
const context = useContext(ProposalsContext) | ||
if (context === undefined) { | ||
throw new Error('useProposal must be used within a ProposalsProvider') | ||
} | ||
return context | ||
} |
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,67 @@ | ||
import { Paragraph } from '@/components/Typography' | ||
import { useProposalContext } from '@/app/proposals/ProposalsContext' | ||
import { useMemo } from 'react' | ||
import { Popover } from '@/components/Popover' | ||
import { ComparativeProgressBar } from '@/components/ComparativeProgressBar/ComparativeProgressBar' | ||
|
||
const PopoverSentiment = ({ votes }: { votes: string[] }) => { | ||
const [againstVotes, forVotes, abstainVotes] = votes | ||
return ( | ||
<div className="text-black"> | ||
<Paragraph variant="semibold" className="text-[12px] font-bold"> | ||
Votes for | ||
</Paragraph> | ||
<div className="flex flex-row"> | ||
<Paragraph variant="semibold" className="text-[12px] w-1/2 text-st-success"> | ||
For | ||
</Paragraph> | ||
<Paragraph variant="semibold" className="text-[12px] w-1/2"> | ||
{forVotes} | ||
</Paragraph> | ||
</div> | ||
<div className="flex flex-row"> | ||
<Paragraph variant="semibold" className="text-[12px] w-1/2 text-st-error"> | ||
Against | ||
</Paragraph> | ||
<Paragraph variant="semibold" className="text-[12px] w-1/2"> | ||
{againstVotes} | ||
</Paragraph> | ||
</div> | ||
<div className="flex flex-row"> | ||
<Paragraph variant="semibold" className="text-[12px] w-1/2 text-st-info"> | ||
Abstain | ||
</Paragraph> | ||
<Paragraph variant="semibold" className="text-[12px] w-1/2"> | ||
{abstainVotes} | ||
</Paragraph> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export const SentimentColumn = () => { | ||
const { proposalVotes: data, index } = useProposalContext() | ||
|
||
const sentimentValues = useMemo(() => { | ||
const [againstVotes, forVotes, abstainVotes] = data | ||
return [ | ||
{ value: Number(forVotes), color: 'var(--st-success)' }, | ||
{ value: Number(againstVotes), color: 'var(--st-error)' }, | ||
{ value: Number(abstainVotes), color: 'var(--st-info)' }, | ||
] | ||
}, [data]) | ||
|
||
const position = index === 0 ? 'bottom' : 'top' | ||
return ( | ||
<Popover | ||
content={<PopoverSentiment votes={data} />} | ||
trigger="hover" | ||
background="light" | ||
position={position} | ||
size="small" | ||
hasCaret={true} | ||
> | ||
<ComparativeProgressBar values={sentimentValues} /> | ||
</Popover> | ||
) | ||
} |
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,31 @@ | ||
import { createContext, ReactNode, useContext, useMemo } from 'react' | ||
import { useBlockNumber } from 'wagmi' | ||
|
||
interface SharedProposalsTableContextProps { | ||
latestBlockNumber?: bigint | ||
} | ||
|
||
const SharedProposalsTableContext = createContext<SharedProposalsTableContextProps>({ | ||
latestBlockNumber: undefined, | ||
}) | ||
|
||
interface SharedProposalsTableContextProviderProps { | ||
children: ReactNode | ||
} | ||
|
||
export const SharedProposalsTableContextProvider = ({ | ||
children, | ||
}: SharedProposalsTableContextProviderProps) => { | ||
const { data: latestBlockNumber } = useBlockNumber() | ||
|
||
const value = useMemo( | ||
() => ({ | ||
latestBlockNumber, | ||
}), | ||
[latestBlockNumber], | ||
) | ||
|
||
return <SharedProposalsTableContext.Provider value={value}>{children}</SharedProposalsTableContext.Provider> | ||
} | ||
|
||
export const useSharedProposalsTableContext = () => useContext(SharedProposalsTableContext) |
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.