Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-delegation-council #2376

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions hooks/useCreateProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { proposalQueryKeys } from './queries/proposal'
import { createLUTProposal } from 'actions/createLUTproposal'
import { useLegacyVoterWeight } from './queries/governancePower'
import {useVotingClients} from "@hooks/useVotingClients";
import { ProgramAccount, TokenOwnerRecord } from '@solana/spl-governance'

export default function useCreateProposal() {
const connection = useLegacyConnectionContext()
Expand All @@ -38,14 +39,16 @@ export default function useCreateProposal() {
voteByCouncil = false,
isDraft = false,
utilizeLookupTable,
myDelegatedTors
}: {
title: string
description: string
governance: { pubkey: PublicKey }
instructionsData: InstructionDataWithHoldUpTime[]
voteByCouncil?: boolean
isDraft?: boolean
utilizeLookupTable?: boolean
utilizeLookupTable?: boolean,
myDelegatedTors?: ProgramAccount<TokenOwnerRecord>[] | undefined
}) => {
const { result: selectedGovernance } = await fetchGovernanceByPubkey(
connection.current,
Expand All @@ -54,10 +57,13 @@ export default function useCreateProposal() {
const minCouncilTokensToCreateProposal = selectedGovernance?.account.config.minCouncilTokensToCreateProposal
const councilPower = ownVoterWeight?.councilTokenRecord?.account.governingTokenDepositAmount

const ownTokenRecord =
const ownTokenRecord = myDelegatedTors ?
myDelegatedTors[0] :
minCouncilTokensToCreateProposal && councilPower && councilPower >= minCouncilTokensToCreateProposal ?
ownVoterWeight?.councilTokenRecord :
ownVoterWeight?.communityTokenRecord

console.log(ownTokenRecord?.pubkey.toBase58())

if (!ownTokenRecord) throw new Error('token owner record does not exist')
if (!selectedGovernance) throw new Error('governance not found')
Expand Down Expand Up @@ -113,11 +119,12 @@ export default function useCreateProposal() {

const propose = (
params: Omit<Parameters<typeof handleCreateProposal>[0], 'governance'> & {
governance: PublicKey
governance: PublicKey,
myDelegatedTors?: ProgramAccount<TokenOwnerRecord>[] | undefined
}
) => {
const { governance, ...rest } = params
return handleCreateProposal({ ...rest, governance: { pubkey: governance } })
const { governance, myDelegatedTors , ...rest} = params
return handleCreateProposal({ ...rest, governance: { pubkey: governance }, myDelegatedTors })
}

const proposeMultiChoice = async ({
Expand Down
4 changes: 4 additions & 0 deletions hub/components/EditRealmConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import { Form } from './Form';
import * as gql from './gql';
import { RealmHeader } from './RealmHeader';
import { Summary } from './Summary';

Check failure on line 34 in hub/components/EditRealmConfig/index.tsx

View workflow job for this annotation

GitHub Actions / Run Tests

There should be at least one empty line between import groups
import { useTokenOwnerRecordsDelegatedToUser } from '@hooks/queries/tokenOwnerRecord';

Check failure on line 35 in hub/components/EditRealmConfig/index.tsx

View workflow job for this annotation

GitHub Actions / Run Tests

`@hooks/queries/tokenOwnerRecord` import should occur before import of `@hooks/useCreateProposal`

type Governance = TypeOf<
typeof gql.getGovernanceResp
Expand Down Expand Up @@ -167,6 +168,8 @@
}
}, [governanceResult._tag]);

const myDelegationPower = useTokenOwnerRecordsDelegatedToUser().data

Check failure on line 171 in hub/components/EditRealmConfig/index.tsx

View workflow job for this annotation

GitHub Actions / Run Tests

Insert `;`

return pipe(
result,
RE.match(
Expand Down Expand Up @@ -321,6 +324,7 @@
prerequisiteInstructions: [],
})),
governance: governance.governanceAddress,
myDelegatedTors: myDelegationPower

Check failure on line 327 in hub/components/EditRealmConfig/index.tsx

View workflow job for this annotation

GitHub Actions / Run Tests

Insert `,`
});

if (proposalAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
import { NewProposalContext } from '../../new'
import GovernedAccountSelect from '../GovernedAccountSelect'
import useGovernanceAssets from '@hooks/useGovernanceAssets'
import { useLegacyVoterWeight } from '@hooks/queries/governancePower'
const Empty = ({
index,
governance,
Expand All @@ -20,7 +19,6 @@ const Empty = ({
const [form, setForm] = useState<EmptyInstructionForm>({
governedAccount: undefined,
})
const { result: ownVoterWeight } = useLegacyVoterWeight()
const { assetAccounts } = useGovernanceAssets()
const shouldBeGoverned = !!(index !== 0 && governance)
const [formErrors, setFormErrors] = useState({})
Expand Down Expand Up @@ -55,9 +53,7 @@ const Empty = ({
return (
<GovernedAccountSelect
label="Wallet"
governedAccounts={assetAccounts.filter((x) =>
ownVoterWeight?.canCreateProposal(x.governance.account.config)
)}
governedAccounts={assetAccounts}
onChange={(value) => {
handleSetForm({ value, propertyName: 'governedAccount' })
}}
Expand Down
4 changes: 4 additions & 0 deletions pages/dao/[symbol]/proposal/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ import PythRecoverAccount from './components/instructions/Pyth/PythRecoverAccoun
import { useVoteByCouncilToggle } from '@hooks/useVoteByCouncilToggle'
import BurnTokens from './components/instructions/BurnTokens'
import RemoveLockup from './components/instructions/Validators/removeLockup'
import { useTokenOwnerRecordsDelegatedToUser } from '@hooks/queries/tokenOwnerRecord'

const TITLE_LENGTH_LIMIT = 130
// the true length limit is either at the tx size level, and maybe also the total account size level (I can't remember)
Expand Down Expand Up @@ -385,6 +386,7 @@ const New = () => {
instructionsData,
voteByCouncil,
isDraft,
myDelegatedTors: myDelegationPower
})

const url = fmtUrlWithCluster(
Expand Down Expand Up @@ -637,6 +639,8 @@ const New = () => {
[governance?.pubkey?.toBase58()]
)

const myDelegationPower = useTokenOwnerRecordsDelegatedToUser().data

return (
<div className="grid grid-cols-12 gap-4">
<div
Expand Down
Loading