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.
Merge branch 'main' of https://github.com/solana-labs/governance-ui i…
…nto solana-labs-main
- Loading branch information
Showing
68 changed files
with
1,499 additions
and
364 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,16 @@ | ||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
test: | ||
name: yarn test-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: lts/* | ||
cache: yarn | ||
- run: yarn install | ||
- run: yarn test-all |
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,37 @@ | ||
import { Account, Transaction, TransactionInstruction } from '@solana/web3.js' | ||
|
||
import { RpcContext } from '../models/core/api' | ||
import { Proposal } from '@models/accounts' | ||
import { ParsedAccount } from 'models/core/accounts' | ||
import { sendTransaction } from 'utils/send' | ||
import { withCancelProposal } from '@models/withCancelProposal' | ||
|
||
export const cancelProposal = async ( | ||
{ connection, wallet, programId, walletPubkey }: RpcContext, | ||
proposal: ParsedAccount<Proposal> | undefined | ||
) => { | ||
const instructions: TransactionInstruction[] = [] | ||
const signers: Account[] = [] | ||
const governanceAuthority = walletPubkey | ||
|
||
withCancelProposal( | ||
instructions, | ||
programId, | ||
proposal!.pubkey, | ||
proposal!.info.tokenOwnerRecord, | ||
governanceAuthority | ||
) | ||
|
||
const transaction = new Transaction({ feePayer: walletPubkey }) | ||
|
||
transaction.add(...instructions) | ||
|
||
await sendTransaction({ | ||
transaction, | ||
wallet, | ||
connection, | ||
signers, | ||
sendingMessage: 'Cancelling proposal', | ||
successMessage: 'Proposal cancelled', | ||
}) | ||
} |
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,39 @@ | ||
import { Account, Transaction, TransactionInstruction } from '@solana/web3.js' | ||
|
||
import { Proposal, ProposalInstruction } from '../models/accounts' | ||
|
||
import { withExecuteInstruction } from '../models/withExecuteInstruction' | ||
import { RpcContext } from '@models/core/api' | ||
import { ParsedAccount } from '@models/core/accounts' | ||
import { sendTransaction } from '@utils/send' | ||
|
||
export const executeInstruction = async ( | ||
{ connection, wallet, programId }: RpcContext, | ||
proposal: ParsedAccount<Proposal>, | ||
instruction: ParsedAccount<ProposalInstruction> | ||
) => { | ||
const signers: Account[] = [] | ||
const instructions: TransactionInstruction[] = [] | ||
|
||
await withExecuteInstruction( | ||
instructions, | ||
programId, | ||
proposal.info.governance, | ||
proposal.pubkey, | ||
instruction.pubkey, | ||
instruction.info.instruction | ||
) | ||
|
||
const transaction = new Transaction() | ||
|
||
transaction.add(...instructions) | ||
|
||
await sendTransaction({ | ||
transaction, | ||
wallet, | ||
connection, | ||
signers, | ||
sendingMessage: 'Executing instruction', | ||
successMessage: 'Execution finalized', | ||
}) | ||
} |
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,43 @@ | ||
import { ParsedAccount } from '@models/core/accounts' | ||
import { RpcContext } from '@models/core/api' | ||
import { | ||
Account, | ||
PublicKey, | ||
Transaction, | ||
TransactionInstruction, | ||
} from '@solana/web3.js' | ||
import { sendTransaction } from '@utils/send' | ||
import { Proposal } from '../models/accounts' | ||
import { withFinalizeVote } from '../models/withFinalizeVote' | ||
|
||
export const finalizeVote = async ( | ||
{ connection, wallet, programId }: RpcContext, | ||
realm: PublicKey, | ||
proposal: ParsedAccount<Proposal> | ||
) => { | ||
const signers: Account[] = [] | ||
const instructions: TransactionInstruction[] = [] | ||
|
||
withFinalizeVote( | ||
instructions, | ||
programId, | ||
realm, | ||
proposal.info.governance, | ||
proposal.pubkey, | ||
proposal.info.tokenOwnerRecord, | ||
proposal.info.governingTokenMint | ||
) | ||
|
||
const transaction = new Transaction() | ||
|
||
transaction.add(...instructions) | ||
|
||
await sendTransaction({ | ||
transaction, | ||
wallet, | ||
connection, | ||
signers, | ||
sendingMessage: 'Finalizing votes', | ||
successMessage: 'Votes finalized', | ||
}) | ||
} |
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,46 @@ | ||
import { | ||
Account, | ||
PublicKey, | ||
Transaction, | ||
TransactionInstruction, | ||
} from '@solana/web3.js' | ||
|
||
import { Proposal } from '../models/accounts' | ||
|
||
import { withFlagInstructionError } from '../models/withFlagInstructionError' | ||
import { RpcContext } from '../models/core/api' | ||
import { ParsedAccount } from '@models/core/accounts' | ||
import { sendTransaction } from '@utils/send' | ||
|
||
export const flagInstructionError = async ( | ||
{ connection, wallet, programId, walletPubkey }: RpcContext, | ||
proposal: ParsedAccount<Proposal>, | ||
proposalInstruction: PublicKey | ||
) => { | ||
const governanceAuthority = walletPubkey | ||
|
||
const signers: Account[] = [] | ||
const instructions: TransactionInstruction[] = [] | ||
|
||
withFlagInstructionError( | ||
instructions, | ||
programId, | ||
proposal.pubkey, | ||
proposal.info.tokenOwnerRecord, | ||
governanceAuthority, | ||
proposalInstruction | ||
) | ||
|
||
const transaction = new Transaction({ feePayer: walletPubkey }) | ||
|
||
transaction.add(...instructions) | ||
|
||
await sendTransaction({ | ||
transaction, | ||
connection, | ||
wallet, | ||
signers, | ||
sendingMessage: 'Flagging instruction as broken', | ||
successMessage: 'Instruction flagged as broken', | ||
}) | ||
} |
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,36 @@ | ||
import { Account, Transaction, TransactionInstruction } from '@solana/web3.js' | ||
|
||
import { RpcContext } from '../models/core/api' | ||
import { SignatoryRecord } from '@models/accounts' | ||
import { ParsedAccount } from 'models/core/accounts' | ||
import { sendTransaction } from 'utils/send' | ||
import { withSignOffProposal } from '@models/withSignOffProposal' | ||
|
||
export const signOffProposal = async ( | ||
{ connection, wallet, programId, walletPubkey }: RpcContext, | ||
signatoryRecord: ParsedAccount<SignatoryRecord> | ||
) => { | ||
const instructions: TransactionInstruction[] = [] | ||
const signers: Account[] = [] | ||
|
||
withSignOffProposal( | ||
instructions, | ||
programId, | ||
signatoryRecord?.info.proposal, | ||
signatoryRecord?.pubkey, | ||
walletPubkey | ||
) | ||
|
||
const transaction = new Transaction() | ||
|
||
transaction.add(...instructions) | ||
|
||
await sendTransaction({ | ||
transaction, | ||
wallet, | ||
connection, | ||
signers, | ||
sendingMessage: 'Signing off proposal', | ||
successMessage: 'Proposal signed off', | ||
}) | ||
} |
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,77 @@ | ||
import React from 'react' | ||
import { RpcContext } from 'models/core/api' | ||
import useWalletStore from 'stores/useWalletStore' | ||
import useRealm from 'hooks/useRealm' | ||
import Button, { SecondaryButton } from '@components/Button' | ||
import { notify } from 'utils/notifications' | ||
import Modal from '@components/Modal' | ||
import { Proposal } from 'models/accounts' | ||
import { ParsedAccount } from 'models/core/accounts' | ||
import { cancelProposal } from 'actions/cancelProposal' | ||
import useProposal from '@hooks/useProposal' | ||
|
||
type CancelProposalModalProps = { | ||
onClose: () => void | ||
isOpen: boolean | ||
} | ||
|
||
const CancelProposalModal = ({ onClose, isOpen }: CancelProposalModalProps) => { | ||
const wallet = useWalletStore((s) => s.current) | ||
const connection = useWalletStore((s) => s.connection) | ||
const fetchRealm = useWalletStore((s) => s.actions.fetchRealm) | ||
const { realmInfo } = useRealm() | ||
const { proposal } = useProposal() | ||
|
||
const handleCancelProposal = async ( | ||
proposal: ParsedAccount<Proposal> | undefined | ||
) => { | ||
try { | ||
if (proposal && realmInfo) { | ||
const rpcContext = new RpcContext( | ||
proposal.account.owner, | ||
realmInfo?.programVersion, | ||
wallet, | ||
connection.current, | ||
connection.endpoint | ||
) | ||
|
||
await cancelProposal(rpcContext, proposal) | ||
|
||
onClose() | ||
|
||
await fetchRealm(realmInfo.programId, realmInfo.realmId) | ||
} | ||
} catch (error) { | ||
notify({ | ||
type: 'error', | ||
message: `Error: Could not cancel proposal.`, | ||
}) | ||
|
||
onClose() | ||
|
||
console.log('error cancelling proposal', error) | ||
} | ||
} | ||
|
||
return ( | ||
<Modal onClose={onClose} isOpen={isOpen}> | ||
<h2>Cancel proposal</h2> | ||
|
||
<p className="text-left mt-5 mb-8"> | ||
Do you want to cancel this proposal? | ||
</p> | ||
|
||
<div className="flex items-center justify-center"> | ||
<SecondaryButton className="w-44 mr-4" onClick={onClose}> | ||
No | ||
</SecondaryButton> | ||
|
||
<Button className="w-44" onClick={() => handleCancelProposal(proposal)}> | ||
Yes, cancel | ||
</Button> | ||
</div> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default CancelProposalModal |
Oops, something went wrong.