Skip to content

Commit

Permalink
add possbile wrong pass governance warning (#1850)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 authored Oct 3, 2023
1 parent 0ac976b commit b40971a
Showing 1 changed file with 64 additions and 17 deletions.
81 changes: 64 additions & 17 deletions components/ProposalStateBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Proposal, ProposalState } from '@solana/spl-governance'
import {
Proposal,
ProposalState,
getNativeTreasuryAddress,
} from '@solana/spl-governance'
import classNames from 'classnames'

import assertUnreachable from '@utils/typescript/assertUnreachable'
Expand All @@ -8,6 +12,8 @@ import {
useUserCouncilTokenOwnerRecord,
} from '@hooks/queries/tokenOwnerRecord'
import { useGovernanceByPubkeyQuery } from '@hooks/queries/governance'
import { useSelectedProposalTransactions } from '@hooks/queries/proposalTransaction'
import { useAsync } from 'react-async-hook'

export const hasInstructions = (proposal: Proposal) => {
if (proposal.instructionsCount) {
Expand Down Expand Up @@ -172,6 +178,25 @@ export default function ProposalStateBadge(props: Props) {

const coolOff = isInCoolOffTime(props.proposal, governance?.account)

const { data: allTransactions } = useSelectedProposalTransactions()
const treasuryAddress = useAsync(
async () =>
governance !== undefined
? getNativeTreasuryAddress(governance.owner, governance.pubkey)
: undefined,
[governance]
)
const walletsPassedToInstructions = allTransactions?.flatMap((tx) =>
tx.account.instructions.flatMap((ins) =>
ins.accounts.map((acc) => acc.pubkey)
)
)
const possibleWrongGovernance =
allTransactions?.length &&
!walletsPassedToInstructions?.find(
(x) => treasuryAddress.result && x.equals(treasuryAddress.result)
)

const otherState = {
isCreator,
isSignatory,
Expand All @@ -181,23 +206,45 @@ export default function ProposalStateBadge(props: Props) {
}

return (
<div
className={classNames(
props.className,
'border',
'inline-flex',
'min-w-max',
'items-center',
'px-2',
'py-1',
'rounded-full',
'text-xs',
getBorderColor(props.proposal.state, otherState),
getOpacity(props.proposal.state, otherState),
getTextColor(props.proposal.state, otherState)
<div>
{possibleWrongGovernance && (
<div
className={classNames(
props.className,
'border',
'inline-flex',
'min-w-max',
'items-center',
'px-2',
'py-1',
'rounded-full',
'text-xs',
'border-[#F5A458]',
'text-[#F5A458]',
'mr-2'
)}
>
Possible wrong governance
</div>
)}
>
{getLabel(props.proposal.state, otherState)}
<div
className={classNames(
props.className,
'border',
'inline-flex',
'min-w-max',
'items-center',
'px-2',
'py-1',
'rounded-full',
'text-xs',
getBorderColor(props.proposal.state, otherState),
getOpacity(props.proposal.state, otherState),
getTextColor(props.proposal.state, otherState)
)}
>
{getLabel(props.proposal.state, otherState)}
</div>
</div>
)
}

1 comment on commit b40971a

@vercel
Copy link

@vercel vercel bot commented on b40971a Oct 3, 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 – ./

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

Please sign in to comment.