Skip to content

Commit

Permalink
fix display of the old proposals (#1775)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xShuk authored Aug 16, 2023
1 parent 581fad9 commit cff2b13
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 15 deletions.
2 changes: 2 additions & 0 deletions actions/castVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Keypair, Transaction, TransactionInstruction } from '@solana/web3.js'
import {
ChatMessageBody,
getGovernanceProgramVersion,
GovernanceAccountType,
GOVERNANCE_CHAT_PROGRAM_ID,
Proposal,
Realm,
Expand Down Expand Up @@ -80,6 +81,7 @@ export async function castVote(
)

const isMulti = proposal.account.voteType !== VoteType.SINGLE_CHOICE
&& proposal.account.accountType === GovernanceAccountType.ProposalV2

// It is not clear that defining these extraneous fields, `deny` and `veto`, is actually necessary.
// See: https://discord.com/channels/910194960941338677/910630743510777926/1044741454175674378
Expand Down
5 changes: 3 additions & 2 deletions components/ProposalCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import styled from '@emotion/styled'
import { ChevronRightIcon } from '@heroicons/react/solid'
import ProposalStateBadge from './ProposalStateBadge'
import Link from 'next/link'
import { Proposal, ProposalState, VoteType } from '@solana/spl-governance'
import { GovernanceAccountType, Proposal, ProposalState, VoteType } from '@solana/spl-governance'
import { ApprovalProgress, VetoProgress } from './QuorumProgress'
import useRealm from '../hooks/useRealm'
import useProposalVotes from '../hooks/useProposalVotes'
Expand Down Expand Up @@ -33,7 +33,8 @@ const ProposalCard = ({ proposalPk, proposal }: ProposalCardProps) => {
const { symbol } = useRealm()
const { fmtUrlWithCluster } = useQueryContext()
const votesData = useProposalVotes(proposal)
const isMulti = proposal.voteType !== VoteType.SINGLE_CHOICE;
const isMulti = proposal.voteType !== VoteType.SINGLE_CHOICE
&& proposal.accountType === GovernanceAccountType.ProposalV2

return (
<div>
Expand Down
5 changes: 3 additions & 2 deletions components/ProposalMyVoteBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Proposal, ProgramAccount, VoteType } from '@solana/spl-governance'
import { Proposal, ProgramAccount, VoteType, GovernanceAccountType } from '@solana/spl-governance'
import classNames from 'classnames'
import { ThumbUpIcon, ThumbDownIcon } from '@heroicons/react/solid'
import { isYesVote } from '@models/voteRecords'
Expand All @@ -17,7 +17,8 @@ interface Props {
export default function ProposalMyVoteBadge(props: Props) {
const realm = useRealmQuery().data?.result
const wallet = useWalletOnePointOh()
const isMulti = props.proposal.account.voteType !== VoteType.SINGLE_CHOICE;
const isMulti = props.proposal.account.voteType !== VoteType.SINGLE_CHOICE
&& props.proposal.account.accountType === GovernanceAccountType.ProposalV2

const { data: tokenOwnerRecordPk } = useAddressQuery_TokenOwnerRecord(
realm?.owner,
Expand Down
5 changes: 3 additions & 2 deletions components/VotePanel/VotePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProposalState, VoteType } from '@solana/spl-governance'
import { GovernanceAccountType, ProposalState, VoteType } from '@solana/spl-governance'
import { BanIcon } from '@heroicons/react/solid'

import Tooltip from '@components/Tooltip'
Expand Down Expand Up @@ -30,6 +30,7 @@ const VotePanel = () => {
!isVoteCast

const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE
&& proposal?.account.accountType === GovernanceAccountType.ProposalV2

return (
<>
Expand All @@ -47,7 +48,7 @@ const VotePanel = () => {
)}
{/* START: Note that these components control for themselves whether they are displayed and may not be visible */}
<YouVoted quorum="electoral" />
{proposal && isMulti && proposal.account.options ? (
{proposal && isMulti ? (
<CastMultiVoteButtons proposal={proposal.account} />
) : (
<CastVoteButtons />
Expand Down
6 changes: 4 additions & 2 deletions components/VotePanel/YouVoted.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VoteKind, VoteType, withFinalizeVote } from '@solana/spl-governance'
import { GovernanceAccountType, VoteKind, VoteType, withFinalizeVote } from '@solana/spl-governance'
import { TransactionInstruction } from '@solana/web3.js'
import { useState } from 'react'
import { relinquishVote } from '../../actions/relinquishVote'
Expand Down Expand Up @@ -143,8 +143,10 @@ export const YouVoted = ({ quorum }: { quorum: 'electoral' | 'veto' }) => {
}

const vote = ownVoteRecord?.account.vote
const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE;

const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE
&& proposal?.account.accountType === GovernanceAccountType.ProposalV2

return vote !== undefined ? (
<div className="bg-bkg-2 p-4 md:p-6 rounded-lg space-y-4">
<div className="flex flex-col items-center justify-center">
Expand Down
5 changes: 3 additions & 2 deletions components/VoteResultStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { XCircleIcon, CheckCircleIcon } from '@heroicons/react/outline'
import { BanIcon } from '@heroicons/react/solid'
import useProposalVotes from '@hooks/useProposalVotes'
import { ProposalState, VoteType } from '@solana/spl-governance'
import { GovernanceAccountType, ProposalState, VoteType } from '@solana/spl-governance'
import { useRouteProposalQuery } from '@hooks/queries/proposal'
import { useVetoingPop } from './VotePanel/hooks'

Expand Down Expand Up @@ -76,7 +76,8 @@ const VoteResultStatus = () => {
? 'vetoed'
: 'denied')

const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE;
const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE
&& proposal?.account.accountType === GovernanceAccountType.ProposalV2

return status === undefined ? null : status === 'approved' ? isMulti ?
(
Expand Down
4 changes: 3 additions & 1 deletion components/chat/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
getTokenOwnerRecordAddress,
getVoteRecordAddress,
GovernanceAccountType,
VoteType
} from '@solana/spl-governance'
import { ThumbUpIcon, ThumbDownIcon } from '@heroicons/react/solid'
Expand Down Expand Up @@ -57,7 +58,8 @@ const Comment = ({ chatMessage }: { chatMessage: ChatMessage }) => {
?.account

const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE

&& proposal?.account.accountType === GovernanceAccountType.ProposalV2

return (
<div className="border-b border-fgd-4 mt-4 pb-4 last:pb-0 last:border-b-0">
<div className="flex items-center justify-between mb-4">
Expand Down
5 changes: 3 additions & 2 deletions pages/dao/[symbol]/proposal/[pk]/explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import ProposalVoteResult from '@components/ProposalVoteResults'
import ProposalRemainingVotingTime from '@components/ProposalRemainingVotingTime'
import { useRouteProposalQuery } from '@hooks/queries/proposal'
import useLegacyConnectionContext from '@hooks/useLegacyConnectionContext'
import { VoteType } from '@solana/spl-governance'
import { GovernanceAccountType, VoteType } from '@solana/spl-governance'
import MultiChoiceVotes from '@components/MultiChoiceVotes'
import { useRealmConfigQuery } from '@hooks/queries/realmConfig'
import ProposalVoterNftChart from '@components/ProposalVoterNftChart'
Expand All @@ -41,7 +41,8 @@ export default function Explore() {
router.push(newPath)
}
const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE

&& proposal?.account.accountType === GovernanceAccountType.ProposalV2

return (
<div className="bg-bkg-2 rounded-lg p-4 space-y-3 md:p-6">
<button
Expand Down
5 changes: 3 additions & 2 deletions pages/dao/[symbol]/proposal/[pk]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ProposalTimeStatus from 'components/ProposalTimeStatus'
import { useEffect, useState } from 'react'
import ProposalActionsPanel from '@components/ProposalActions'
import { getRealmExplorerHost } from 'tools/routing'
import { ProposalState, VoteType } from '@solana/spl-governance'
import { GovernanceAccountType, ProposalState, VoteType } from '@solana/spl-governance'
import VoteResultStatus from '@components/VoteResultStatus'
import VoteResults from '@components/VoteResults'
import MultiChoiceVotes from '@components/MultiChoiceVotes'
Expand All @@ -38,6 +38,7 @@ const Proposal = () => {
const descriptionLink = proposal?.account.descriptionLink
const allowDiscussion = realmInfo?.allowDiscussion ?? true
const isMulti = proposal?.account.voteType !== VoteType.SINGLE_CHOICE
&& proposal?.account.accountType === GovernanceAccountType.ProposalV2

const [description, setDescription] = useState('')
const voteData = useProposalVotes(proposal?.account)
Expand Down Expand Up @@ -176,7 +177,7 @@ const Proposal = () => {
</div>
)}

{isMulti && proposal.account.options ? (
{isMulti ? (
<MultiChoiceVotes
proposal={proposal.account}
limit={proposal.account.options.length}
Expand Down

1 comment on commit cff2b13

@vercel
Copy link

@vercel vercel bot commented on cff2b13 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

governance-ui – ./

governance-ui-git-main-solana-labs.vercel.app
governance-ui-solana-labs.vercel.app
app.realms.today

Please sign in to comment.