forked from solana-labs/governance-ui
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
227 additions
and
171 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
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,137 @@ | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
import { useEffect, useState } from 'react' | ||
import { useHasVoteTimeExpired } from '../hooks/useHasVoteTimeExpired' | ||
import useRealm from '../hooks/useRealm' | ||
import { getSignatoryRecordAddress, ProposalState } from '../models/accounts' | ||
import useWalletStore from '../stores/useWalletStore' | ||
import Button, { SecondaryButton } from './Button' | ||
import CancelProposalModal from './CancelProposalModal' | ||
import FinalizeVotesModal from './FinalizeVotesModal' | ||
import SignOffProposalModal from './SignOffProposalModal' | ||
|
||
const ProposalActionsPanel = () => { | ||
const { governance, proposal, proposalOwner } = useWalletStore( | ||
(s) => s.selectedProposal | ||
) | ||
const { realmInfo } = useRealm() | ||
const wallet = useWalletStore((s) => s.current) | ||
const connected = useWalletStore((s) => s.connected) | ||
const hasVoteTimeExpired = useHasVoteTimeExpired(governance, proposal!) | ||
const signatories = useWalletStore((s) => s.selectedProposal.signatories) | ||
|
||
const [showSignOffModal, setShowSignOffModal] = useState(false) | ||
const [signatoryRecord, setSignatoryRecord] = useState<any>(undefined) | ||
const [showFinalizeVoteModal, setShowFinalizeVoteModal] = useState(false) | ||
const [showCancelModal, setShowCancelModal] = useState(false) | ||
|
||
const canFinalizeVote = | ||
hasVoteTimeExpired === true && | ||
connected && | ||
proposal?.info.state === ProposalState.Voting | ||
|
||
const walletPk = wallet?.publicKey | ||
|
||
useEffect(() => { | ||
const setup = async () => { | ||
if (proposal && realmInfo && walletPk) { | ||
const signatoryRecordPk = await getSignatoryRecordAddress( | ||
realmInfo.programId, | ||
proposal.pubkey, | ||
walletPk | ||
) | ||
|
||
if (signatoryRecordPk && signatories) { | ||
setSignatoryRecord(signatories[signatoryRecordPk.toBase58()]) | ||
} | ||
} | ||
} | ||
|
||
setup() | ||
}, [proposal, realmInfo, walletPk]) | ||
|
||
const canSignOff = | ||
signatoryRecord && | ||
(proposal?.info.state === ProposalState.Draft || | ||
proposal?.info.state === ProposalState.SigningOff) | ||
|
||
const canCancelProposal = | ||
proposal && | ||
governance && | ||
proposalOwner && | ||
wallet?.publicKey && | ||
proposal.info.canWalletCancel( | ||
governance.info, | ||
proposalOwner.info, | ||
wallet.publicKey | ||
) | ||
|
||
return ( | ||
<> | ||
{ProposalState.Cancelled === proposal?.info.state || | ||
ProposalState.Succeeded === proposal?.info.state || | ||
ProposalState.Defeated === proposal?.info.state || | ||
(!canCancelProposal && !canSignOff && canFinalizeVote) ? null : ( | ||
<div> | ||
<div className="bg-bkg-2 rounded-lg p-6 space-y-6 flex justify-center items-center text-center flex-col w-full mt-4"> | ||
{canSignOff && ( | ||
<Button | ||
className="w-1/2" | ||
onClick={() => setShowSignOffModal(true)} | ||
disabled={!connected || !canSignOff} | ||
> | ||
Sign Off | ||
</Button> | ||
)} | ||
|
||
{canCancelProposal && ( | ||
<SecondaryButton | ||
className="w-1/2" | ||
onClick={() => setShowCancelModal(true)} | ||
disabled={!connected} | ||
> | ||
Cancel | ||
</SecondaryButton> | ||
)} | ||
|
||
{canFinalizeVote && ( | ||
<Button | ||
className="w-1/2" | ||
onClick={() => setShowFinalizeVoteModal(true)} | ||
disabled={!connected || !canFinalizeVote} | ||
> | ||
Finalize | ||
</Button> | ||
)} | ||
</div> | ||
|
||
{showSignOffModal && ( | ||
<SignOffProposalModal | ||
isOpen={showSignOffModal && canSignOff} | ||
onClose={() => setShowSignOffModal(false)} | ||
signatoryRecord={signatoryRecord} | ||
/> | ||
)} | ||
|
||
{showFinalizeVoteModal && ( | ||
<FinalizeVotesModal | ||
isOpen={showFinalizeVoteModal && canFinalizeVote} | ||
onClose={() => setShowFinalizeVoteModal(false)} | ||
proposal={proposal} | ||
governance={governance} | ||
/> | ||
)} | ||
|
||
{showCancelModal && ( | ||
<CancelProposalModal | ||
// @ts-ignore | ||
isOpen={showCancelModal && canCancelProposal} | ||
onClose={() => setShowCancelModal(false)} | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default ProposalActionsPanel |
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
Oops, something went wrong.
d24f44b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: