Skip to content

Commit

Permalink
Update set authority (solana-labs#790)
Browse files Browse the repository at this point in the history
* Fix for solana-labs#788

* squash

Co-authored-by: Tommy Johnson <[email protected]>
  • Loading branch information
tomjohn1028 and Tommy Johnson authored Jun 28, 2022
1 parent ebaf09d commit b81ba33
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pages/dao/[symbol]/params/SetRealmAuthorityModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Modal from '@components/Modal'
import { useState } from 'react'
import Button from '@components/Button'
import GovernedAccountSelect from '../proposal/components/GovernedAccountSelect'
import {
Governance,
ProgramAccount,
SetRealmAuthorityAction,
withSetRealmAuthority,
} from '@solana/spl-governance'
Expand All @@ -11,7 +12,7 @@ import useWalletStore from 'stores/useWalletStore'
import { Transaction, TransactionInstruction } from '@solana/web3.js'
import { sendTransaction } from '@utils/send'
import useGovernanceAssets from '@hooks/useGovernanceAssets'
import { AssetAccount } from '@utils/uiTypes/assets'
import GovernanceAccountSelect from '../proposal/components/GovernanceAccountSelect'

const SetRealmAuthorityModal = ({
closeModal,
Expand All @@ -24,8 +25,10 @@ const SetRealmAuthorityModal = ({
const wallet = useWalletStore((s) => s.current)
const connection = useWalletStore((s) => s.connection)
const { fetchRealm, fetchAllRealms } = useWalletStore((s) => s.actions)
const { assetAccounts } = useGovernanceAssets()
const [account, setAccount] = useState<AssetAccount | null>(null)
const { governancesArray } = useGovernanceAssets()
const [account, setAccount] = useState<ProgramAccount<Governance> | null>(
null
)
const [settingAuthority, setSettingAuthority] = useState(false)
const handleSetAuthority = async () => {
setSettingAuthority(true)
Expand All @@ -36,7 +39,7 @@ const SetRealmAuthorityModal = ({
realmInfo!.programVersion!,
realm!.pubkey!,
wallet!.publicKey!,
account!.governance.pubkey,
account!.pubkey,
SetRealmAuthorityAction.SetChecked
)
const transaction = new Transaction({ feePayer: wallet!.publicKey })
Expand All @@ -60,9 +63,9 @@ const SetRealmAuthorityModal = ({
<h3 className="mb-4 flex flex-col">Set realm authority</h3>
</div>
<div>
<GovernedAccountSelect
<GovernanceAccountSelect
label="Governance"
governedAccounts={assetAccounts}
governanceAccounts={governancesArray}
onChange={(value) => {
setAccount(value)
}}
Expand Down
56 changes: 56 additions & 0 deletions pages/dao/[symbol]/proposal/components/GovernanceAccountSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import Select from '@components/inputs/Select'
import { Governance } from '@solana/spl-governance'
import { ProgramAccount } from '@solana/spl-governance'
import React, { useEffect } from 'react'

const GovernanceAccountSelect = ({
onChange,
value,
error,
governanceAccounts = [],
label,
noMaxWidth,
autoselectFirst = true,
}: {
onChange
value
error?
governanceAccounts: ProgramAccount<Governance>[]
label?
noMaxWidth?: boolean
autoselectFirst?: boolean
}) => {
useEffect(() => {
if (governanceAccounts.length == 1 && autoselectFirst) {
//wait for microtask queue to be empty
setTimeout(() => {
onChange(governanceAccounts[0])
})
}
}, [JSON.stringify(governanceAccounts)])
return (
<Select
label={label}
onChange={onChange}
componentLabel={value?.pubkey?.toBase58()}
placeholder="Please select..."
value={value?.pubkey?.toBase58()}
error={error}
noMaxWidth={noMaxWidth}
>
{governanceAccounts.map((acc) => {
return (
<Select.Option
className="border-red"
key={acc.pubkey.toBase58()}
value={acc}
>
{acc.pubkey.toBase58()}
</Select.Option>
)
})}
</Select>
)
}

export default GovernanceAccountSelect

0 comments on commit b81ba33

Please sign in to comment.