Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/solana-labs/governance-ui i…
Browse files Browse the repository at this point in the history
…nto solana-labs-main
  • Loading branch information
sjillen committed Dec 18, 2021
2 parents 5081866 + 0a77b3e commit 6d98909
Show file tree
Hide file tree
Showing 68 changed files with 1,499 additions and 364 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@typescript-eslint/indent": 0,
"@typescript-eslint/member-delimiter-style": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-use-before-define": 0,
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/pull-request.yml
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
37 changes: 37 additions & 0 deletions actions/cancelProposal.ts
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',
})
}
3 changes: 2 additions & 1 deletion actions/createProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const createProposal = async (
signatory,
payer
)

for (const [index, instruction] of instructionsData
.filter((x) => x.data)
.entries()) {
Expand All @@ -84,7 +85,7 @@ export const createProposal = async (
}

if (!isDraft) {
await withSignOffProposal(
withSignOffProposal(
instructions,
programId,
proposalAddress,
Expand Down
39 changes: 39 additions & 0 deletions actions/executeInstruction.ts
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',
})
}
43 changes: 43 additions & 0 deletions actions/finalizeVotes.ts
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',
})
}
46 changes: 46 additions & 0 deletions actions/flagInstructionError.ts
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',
})
}
36 changes: 36 additions & 0 deletions actions/signOffProposal.ts
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',
})
}
77 changes: 77 additions & 0 deletions components/CancelProposalModal.tsx
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
Loading

0 comments on commit 6d98909

Please sign in to comment.