Skip to content

Commit

Permalink
fix revoke token instruction (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShuk authored Dec 16, 2024
1 parent 3711ca7 commit 31f23f4
Showing 1 changed file with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,8 @@ const RevokeGoverningTokens: FC<{
}
}, [query])

// If there's only one membership type, we can just select that for the user.
// @asktree style note: I create a new variable rather than using `setForm` here because I don't like side effects
const selectedMembershipType = useMemo(
() =>
form.membershipPopulation ?? Object.keys(membershipTypes).length === 1
? Object.keys(membershipTypes)[0]
: undefined,
[form.membershipPopulation, membershipTypes]
)

const selectedMint = useMemo(
() =>
selectedMembershipType === undefined
? undefined
: (membershipTypes[selectedMembershipType] as PublicKey | undefined),
[membershipTypes, selectedMembershipType]
)
const [selectedMint, setSelectedMint] = useState<PublicKey | undefined>(undefined)
const [selectedMembershipType, setSelectedMembershipType] = useState<string | undefined>(undefined)

const { data: mintInfo } = useMintInfoByPubkeyQuery(selectedMint)
const governance = useGovernanceForGovernedAddress(selectedMint)
Expand Down Expand Up @@ -228,6 +213,14 @@ const RevokeGoverningTokens: FC<{
[connection]
)

const updateMembershipType = (x: "council" | "community" | undefined) => {
setForm((p) => ({ ...p, membershipPopulation: x }))
setSelectedMembershipType(x)
if (x) {
setSelectedMint(membershipTypes[x])
}
}

return (
<>
<Tooltip
Expand All @@ -241,7 +234,7 @@ const RevokeGoverningTokens: FC<{
label="Membership Token"
disabled={Object.keys(membershipTypes).length === 0}
value={selectedMembershipType}
onChange={(x) => setForm((p) => ({ ...p, membershipPopulation: x }))}
onChange={(x) => updateMembershipType(x)}
>
{Object.keys(membershipTypes).map((x) => (
<Select.Option key={x} value={x}>
Expand Down

0 comments on commit 31f23f4

Please sign in to comment.