From b81ba331a9dd6fb8222e9f3bf50ebfe1cff13476 Mon Sep 17 00:00:00 2001 From: Tommy Johnson <32071703+tomjohn1028@users.noreply.github.com> Date: Tue, 28 Jun 2022 02:59:03 -0700 Subject: [PATCH] Update set authority (#790) * Fix for https://github.com/solana-labs/governance-ui/issues/788 * squash Co-authored-by: Tommy Johnson --- .../params/SetRealmAuthorityModal.tsx | 17 +++--- .../components/GovernanceAccountSelect.tsx | 56 +++++++++++++++++++ 2 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 pages/dao/[symbol]/proposal/components/GovernanceAccountSelect.tsx diff --git a/pages/dao/[symbol]/params/SetRealmAuthorityModal.tsx b/pages/dao/[symbol]/params/SetRealmAuthorityModal.tsx index 3069bbf310..bb7118e0b1 100644 --- a/pages/dao/[symbol]/params/SetRealmAuthorityModal.tsx +++ b/pages/dao/[symbol]/params/SetRealmAuthorityModal.tsx @@ -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' @@ -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, @@ -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(null) + const { governancesArray } = useGovernanceAssets() + const [account, setAccount] = useState | null>( + null + ) const [settingAuthority, setSettingAuthority] = useState(false) const handleSetAuthority = async () => { setSettingAuthority(true) @@ -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 }) @@ -60,9 +63,9 @@ const SetRealmAuthorityModal = ({

Set realm authority

- { setAccount(value) }} diff --git a/pages/dao/[symbol]/proposal/components/GovernanceAccountSelect.tsx b/pages/dao/[symbol]/proposal/components/GovernanceAccountSelect.tsx new file mode 100644 index 0000000000..28fa9f828f --- /dev/null +++ b/pages/dao/[symbol]/proposal/components/GovernanceAccountSelect.tsx @@ -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[] + 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 ( + + ) +} + +export default GovernanceAccountSelect