[xc-admin] fix xc-admin-frontend bugs (#681)
* allow proposing without connecting wallet * show voted icon on proposals
This commit is contained in:
parent
3d8215edc2
commit
51f0c10756
|
@ -2,7 +2,6 @@ import { AnchorProvider, Program } from '@coral-xyz/anchor'
|
|||
import { AccountType, getPythProgramKeyForCluster } from '@pythnetwork/client'
|
||||
import { PythOracle, pythOracleProgram } from '@pythnetwork/client/lib/anchor'
|
||||
import { useWallet } from '@solana/wallet-adapter-react'
|
||||
import { WalletModalButton } from '@solana/wallet-adapter-react-ui'
|
||||
import { Cluster, PublicKey, TransactionInstruction } from '@solana/web3.js'
|
||||
import { useCallback, useContext, useEffect, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
|
@ -697,18 +696,12 @@ const General = () => {
|
|||
<p className="mb-8 leading-6">No proposed changes.</p>
|
||||
)}
|
||||
{Object.keys(changes).length > 0 ? (
|
||||
!connected ? (
|
||||
<div className="flex justify-center">
|
||||
<WalletModalButton className="action-btn text-base" />
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
className="action-btn text-base"
|
||||
onClick={handleSendProposalButtonClick}
|
||||
>
|
||||
{isSendProposalButtonLoading ? <Spinner /> : 'Send Proposal'}
|
||||
</button>
|
||||
)
|
||||
<button
|
||||
className="action-btn text-base"
|
||||
onClick={handleSendProposalButtonClick}
|
||||
>
|
||||
{isSendProposalButtonLoading ? <Spinner /> : 'Send Proposal'}
|
||||
</button>
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as Tooltip from '@radix-ui/react-tooltip'
|
||||
import { useWallet } from '@solana/wallet-adapter-react'
|
||||
import { AccountMeta, PublicKey } from '@solana/web3.js'
|
||||
import { MultisigAccount, TransactionAccount } from '@sqds/mesh/lib/types'
|
||||
import { useRouter } from 'next/router'
|
||||
|
@ -28,6 +29,7 @@ import { usePythContext } from '../../contexts/PythContext'
|
|||
import { StatusFilterContext } from '../../contexts/StatusFilterContext'
|
||||
import { PRICE_FEED_MULTISIG } from '../../hooks/useMultisig'
|
||||
import VerifiedIcon from '../../images/icons/verified.inline.svg'
|
||||
import VotedIcon from '../../images/icons/voted.inline.svg'
|
||||
import { capitalizeFirstLetter } from '../../utils/capitalizeFirstLetter'
|
||||
import ClusterSwitch from '../ClusterSwitch'
|
||||
import CopyPubkey from '../common/CopyPubkey'
|
||||
|
@ -56,11 +58,13 @@ const getMappingCluster = (cluster: string) => {
|
|||
const ProposalRow = ({
|
||||
proposal,
|
||||
verified,
|
||||
voted,
|
||||
setCurrentProposalPubkey,
|
||||
multisig,
|
||||
}: {
|
||||
proposal: TransactionAccount
|
||||
verified: boolean
|
||||
voted: boolean
|
||||
setCurrentProposalPubkey: Dispatch<SetStateAction<string | undefined>>
|
||||
multisig: MultisigAccount | undefined
|
||||
}) => {
|
||||
|
@ -100,7 +104,10 @@ const ProposalRow = ({
|
|||
'...' +
|
||||
proposal.publicKey.toBase58().slice(-6)}
|
||||
</span>{' '}
|
||||
{verified ? <VerifiedIconWithTooltip /> : null}
|
||||
<div className="mr-2 items-center flex">
|
||||
{verified ? <VerifiedIconWithTooltip /> : null}
|
||||
</div>
|
||||
{voted ? <VotedIconWithTooltip /> : null}
|
||||
</div>
|
||||
<div>
|
||||
<StatusTag proposalStatus={status} />
|
||||
|
@ -167,6 +174,25 @@ const VerifiedIconWithTooltip = () => {
|
|||
)
|
||||
}
|
||||
|
||||
const VotedIconWithTooltip = () => {
|
||||
return (
|
||||
<div className="flex items-center">
|
||||
<Tooltip.Provider delayDuration={100} skipDelayDuration={500}>
|
||||
<Tooltip.Root>
|
||||
<Tooltip.Trigger>
|
||||
<VotedIcon />
|
||||
</Tooltip.Trigger>
|
||||
<Tooltip.Content side="top" sideOffset={8}>
|
||||
<span className="inline-block bg-darkGray3 p-2 text-xs text-light hoverable:bg-darkGray">
|
||||
You have voted on this proposal.
|
||||
</span>
|
||||
</Tooltip.Content>
|
||||
</Tooltip.Root>
|
||||
</Tooltip.Provider>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const ParsedAccountPubkeyRow = ({
|
||||
mapping,
|
||||
title,
|
||||
|
@ -187,7 +213,7 @@ const ParsedAccountPubkeyRow = ({
|
|||
}
|
||||
|
||||
const getProposalStatus = (
|
||||
proposal: TransactionAccount | undefined,
|
||||
proposal: TransactionAccount | ClientProposal | undefined,
|
||||
multisig: MultisigAccount | undefined
|
||||
): string => {
|
||||
if (multisig && proposal) {
|
||||
|
@ -1054,6 +1080,8 @@ const Proposal = ({
|
|||
)
|
||||
}
|
||||
|
||||
type ClientProposal = TransactionAccount & { verified: boolean; voted: boolean }
|
||||
|
||||
const Proposals = ({
|
||||
publisherKeyToNameMapping,
|
||||
multisigSignerKeyToNameMapping,
|
||||
|
@ -1062,11 +1090,13 @@ const Proposals = ({
|
|||
multisigSignerKeyToNameMapping: Record<string, string>
|
||||
}) => {
|
||||
const router = useRouter()
|
||||
const { connected, publicKey: signerPublicKey } = useWallet()
|
||||
const [currentProposal, setCurrentProposal] = useState<TransactionAccount>()
|
||||
const [currentProposalIndex, setCurrentProposalIndex] = useState<number>()
|
||||
const [allProposalsVerifiedArr, setAllProposalsVerifiedArr] = useState<
|
||||
boolean[]
|
||||
>([])
|
||||
const [proposalsVotedArr, setProposalsVotedArr] = useState<boolean[]>([])
|
||||
const [currentProposalPubkey, setCurrentProposalPubkey] = useState<string>()
|
||||
const { cluster } = useContext(ClusterContext)
|
||||
const { statusFilter } = useContext(StatusFilterContext)
|
||||
|
@ -1076,9 +1106,9 @@ const Proposals = ({
|
|||
allProposalsIxsParsed,
|
||||
isLoading: isMultisigLoading,
|
||||
} = useMultisigContext()
|
||||
const [filteredProposals, setFilteredProposals] = useState<
|
||||
TransactionAccount[]
|
||||
>(priceFeedMultisigProposals)
|
||||
const [filteredProposals, setFilteredProposals] = useState<ClientProposal[]>(
|
||||
[]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMultisigLoading) {
|
||||
|
@ -1160,19 +1190,59 @@ const Proposals = ({
|
|||
])
|
||||
|
||||
useEffect(() => {
|
||||
const allClientProposals = priceFeedMultisigProposals.map(
|
||||
(proposal, idx) => ({
|
||||
...proposal,
|
||||
verified: allProposalsVerifiedArr[idx],
|
||||
voted: proposalsVotedArr[idx],
|
||||
})
|
||||
)
|
||||
// filter price feed multisig proposals by status
|
||||
if (statusFilter === 'all') {
|
||||
setFilteredProposals(priceFeedMultisigProposals)
|
||||
// pass priceFeedMultisigProposals and add verified and voted props
|
||||
setFilteredProposals(allClientProposals)
|
||||
} else {
|
||||
setFilteredProposals(
|
||||
priceFeedMultisigProposals.filter(
|
||||
allClientProposals.filter(
|
||||
(proposal) =>
|
||||
getProposalStatus(proposal, priceFeedMultisigAccount) ===
|
||||
statusFilter
|
||||
)
|
||||
)
|
||||
}
|
||||
}, [statusFilter, priceFeedMultisigAccount, priceFeedMultisigProposals])
|
||||
}, [
|
||||
statusFilter,
|
||||
priceFeedMultisigAccount,
|
||||
priceFeedMultisigProposals,
|
||||
allProposalsVerifiedArr,
|
||||
proposalsVotedArr,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (priceFeedMultisigAccount && connected && signerPublicKey) {
|
||||
const res: boolean[] = []
|
||||
priceFeedMultisigProposals.map((proposal) => {
|
||||
// check if proposal.approved, proposal.cancelled, proposal.rejected has wallet pubkey and return true if anyone of them has wallet pubkey
|
||||
const isProposalVoted =
|
||||
proposal.approved.some(
|
||||
(p) => p.toBase58() === signerPublicKey.toBase58()
|
||||
) ||
|
||||
proposal.cancelled.some(
|
||||
(p) => p.toBase58() === signerPublicKey.toBase58()
|
||||
) ||
|
||||
proposal.rejected.some(
|
||||
(p) => p.toBase58() === signerPublicKey.toBase58()
|
||||
)
|
||||
res.push(isProposalVoted)
|
||||
})
|
||||
setProposalsVotedArr(res)
|
||||
}
|
||||
}, [
|
||||
priceFeedMultisigAccount,
|
||||
priceFeedMultisigProposals,
|
||||
connected,
|
||||
signerPublicKey,
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="relative">
|
||||
|
@ -1210,7 +1280,8 @@ const Proposals = ({
|
|||
<ProposalRow
|
||||
key={idx}
|
||||
proposal={proposal}
|
||||
verified={allProposalsVerifiedArr[idx]}
|
||||
verified={proposal.verified}
|
||||
voted={proposal.voted}
|
||||
setCurrentProposalPubkey={setCurrentProposalPubkey}
|
||||
multisig={priceFeedMultisigAccount}
|
||||
/>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<svg width="46" height="20" viewBox="0 0 46 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_405_2)">
|
||||
<mask id="mask0_405_2" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="46" height="20">
|
||||
<path d="M45.2632 0H0V20H45.2632V0Z" fill="white"/>
|
||||
</mask>
|
||||
<g mask="url(#mask0_405_2)">
|
||||
<path d="M12.4697 17.2514C13.1347 16.3412 13.5034 15.2446 13.5034 14.1086V3.38649C13.5034 2.82028 13.0408 2.36158 12.4697 2.36158C11.8986 2.36158 11.436 2.82028 11.436 3.38649V7.80505H10.8685V1.51227C10.8685 0.946068 10.4059 0.487368 9.83476 0.487368C9.26371 0.487368 8.80108 0.946068 8.80108 1.51227V7.80505H8.2336V1.02491C8.2336 0.458699 7.77097 0 7.19987 0C6.62881 0 6.16618 0.458699 6.16618 1.02491V7.80505H5.59871V2.77011C5.59871 2.20391 5.13605 1.74521 4.56498 1.74521C3.9939 1.74521 3.53126 2.20391 3.53126 2.77011V11.7398L2.03489 9.37468C1.7096 8.86221 1.02648 8.70453 0.509619 9.02705C-1.16637e-05 9.34958 -0.155431 10.0269 0.169865 10.5393L3.58547 15.7749L4.23968 17.0579C4.29028 17.1439 4.34811 17.2227 4.40956 17.298C5.40713 16.8321 6.9505 16.6135 8.49024 16.6135C10.03 16.6135 11.4685 16.8178 12.4661 17.2478L12.4697 17.2514Z" fill="#E6DAFE"/>
|
||||
<path d="M12.9395 19.9999V18.5808C12.9395 18.3514 12.6142 18.0719 11.978 17.8318C11.2371 17.5559 10.0732 17.3373 8.49013 17.3373C6.90703 17.3373 5.7685 17.5487 5.02755 17.8247C4.37696 18.0648 4.04443 18.3479 4.04443 18.5808V19.9999H12.9359H12.9395Z" fill="#7142CF"/>
|
||||
<path d="M40.9114 11.6824C40.7669 11.5212 40.7669 11.2811 40.9114 11.1198L45.1584 6.36439C45.4042 6.09203 45.2054 5.65845 44.8367 5.65845H14.2263V14.1086C14.2263 15.1836 13.9372 16.2193 13.395 17.1438H44.8367C45.2054 17.1438 45.4005 16.7138 45.1584 16.4379L40.9114 11.6824Z" fill="#7142CF"/>
|
||||
<path d="M19.9735 13.5566V13.6856H17.5085V13.5566H17.6639C17.8013 13.5566 17.9097 13.5315 17.9928 13.4849C18.0543 13.4527 18.0976 13.3989 18.1301 13.3201C18.1555 13.2663 18.1699 13.1194 18.1699 12.8865V9.81177C18.1699 9.57166 18.1555 9.42472 18.1301 9.36382C18.1049 9.30287 18.0543 9.25272 17.9747 9.20614C17.8988 9.16314 17.794 9.13803 17.6603 9.13803H17.5049V9.00903H19.9699V9.13803H19.8145C19.6771 9.13803 19.5687 9.16314 19.4856 9.20972C19.4241 9.24198 19.3771 9.29572 19.3446 9.37456C19.3193 9.4283 19.3048 9.57524 19.3048 9.80819V12.8829C19.3048 13.123 19.3193 13.2699 19.3446 13.3308C19.3699 13.3918 19.4241 13.4419 19.5 13.4885C19.5759 13.5351 19.6844 13.5566 19.8145 13.5566H19.9699H19.9735Z" fill="#E6DAFE"/>
|
||||
<path d="M26.8553 9.00903V9.13803C26.6854 9.16672 26.53 9.2563 26.3962 9.4104C26.2987 9.52509 26.1541 9.79382 25.9625 10.2203L24.3396 13.7931H24.224L22.6084 10.0769C22.4132 9.62898 22.2831 9.3674 22.218 9.28856C22.153 9.20972 22.0264 9.15956 21.8457 9.14161V9.01261H24.1047V9.14161H24.0288C23.8264 9.14161 23.6854 9.16672 23.6132 9.21687C23.559 9.25272 23.5337 9.30287 23.5337 9.3674C23.5337 9.4104 23.5445 9.45698 23.5625 9.5143C23.5806 9.57166 23.6421 9.72214 23.7505 9.96945L24.7553 12.2952L25.6878 10.2239C25.7999 9.97303 25.8685 9.80456 25.8939 9.72214C25.9192 9.63614 25.9336 9.56451 25.9336 9.50356C25.9336 9.43545 25.9155 9.37456 25.8794 9.32082C25.8432 9.26703 25.789 9.22761 25.7168 9.19898C25.6155 9.15956 25.4854 9.14161 25.3192 9.14161V9.01261H26.8661L26.8553 9.00903Z" fill="#E6DAFE"/>
|
||||
<path d="M28.0476 10.3636C28.3295 10.3636 28.5933 10.4353 28.8355 10.5823C29.0777 10.7292 29.262 10.9334 29.3885 11.1986C29.515 11.4638 29.5765 11.7576 29.5765 12.073C29.5765 12.5318 29.4608 12.9116 29.2258 13.2198C28.9439 13.5925 28.5536 13.7788 28.0548 13.7788C27.556 13.7788 27.1873 13.6104 26.9235 13.27C26.6596 12.9295 26.5259 12.5353 26.5259 12.0874C26.5259 11.6394 26.6596 11.2237 26.9307 10.8797C27.2018 10.5356 27.5705 10.3636 28.0403 10.3636H28.0476ZM28.062 10.6073C27.9427 10.6073 27.8415 10.6503 27.7584 10.7399C27.6752 10.8295 27.6175 11.0015 27.5921 11.2631C27.5668 11.5248 27.5524 11.8867 27.5524 12.349C27.5524 12.5962 27.5668 12.8256 27.5994 13.037C27.6247 13.2019 27.6789 13.3237 27.762 13.4097C27.8451 13.4957 27.9391 13.5387 28.0476 13.5387C28.156 13.5387 28.2391 13.5101 28.3078 13.4527C28.3981 13.3739 28.4596 13.2664 28.4885 13.1266C28.5355 12.908 28.5572 12.4672 28.5572 11.8043C28.5572 11.4136 28.5355 11.1449 28.4921 10.998C28.4488 10.851 28.3837 10.7471 28.2969 10.679C28.2355 10.6324 28.1596 10.6073 28.062 10.6073Z" fill="#E6DAFE"/>
|
||||
<path d="M31.3657 9.28141V10.4604H32.1392V10.8009H31.3657V12.7898C31.3657 12.9761 31.373 13.0944 31.3911 13.1481C31.4091 13.2019 31.438 13.2449 31.4814 13.2807C31.5248 13.313 31.5645 13.3309 31.6043 13.3309C31.7561 13.3309 31.8971 13.2162 32.0308 12.9905L32.1356 13.0657C31.9476 13.5065 31.6441 13.7287 31.2212 13.7287C31.0152 13.7287 30.8416 13.6713 30.6971 13.5567C30.5561 13.442 30.4622 13.3166 30.4224 13.1768C30.4007 13.0979 30.3862 12.8865 30.3862 12.5425V10.8009H29.9634V10.679C30.2561 10.4748 30.5055 10.2597 30.7079 10.034C30.914 9.8082 31.0911 9.55736 31.2465 9.27783H31.3621L31.3657 9.28141Z" fill="#E6DAFE"/>
|
||||
<path d="M35.2006 11.9584H33.4151C33.4368 12.3848 33.5525 12.7253 33.7585 12.9726C33.9175 13.1625 34.1127 13.2593 34.3368 13.2593C34.4741 13.2593 34.6006 13.2198 34.7163 13.1446C34.8283 13.0693 34.9512 12.9296 35.0814 12.7289L35.2006 12.8041C35.0235 13.1589 34.8283 13.4133 34.6151 13.5603C34.4018 13.7072 34.1561 13.7825 33.8742 13.7825C33.3934 13.7825 33.0284 13.5997 32.779 13.2306C32.5802 12.9332 32.479 12.5676 32.479 12.1268C32.479 11.5893 32.6272 11.1628 32.92 10.8439C33.2127 10.5249 33.5561 10.3673 33.9501 10.3673C34.279 10.3673 34.5645 10.4999 34.8066 10.7686C35.0488 11.0374 35.179 11.4316 35.197 11.9584H35.2006ZM34.344 11.729C34.344 11.3599 34.3223 11.1055 34.2826 10.9657C34.2428 10.826 34.1777 10.722 34.0946 10.6504C34.0476 10.6074 33.9826 10.5895 33.8994 10.5895C33.7802 10.5895 33.679 10.6468 33.6031 10.765C33.4657 10.9693 33.3971 11.2488 33.3971 11.6072V11.729H34.344Z" fill="#E6DAFE"/>
|
||||
<path d="M38.7678 9.00903V12.718C38.7678 12.9689 38.775 13.1158 38.7895 13.1624C38.8075 13.2377 38.8437 13.295 38.8943 13.3308C38.9449 13.3667 39.0389 13.3918 39.1654 13.3989V13.5136L37.7919 13.7788V13.2699C37.6256 13.467 37.4811 13.6032 37.3509 13.6713C37.2208 13.7429 37.0762 13.7788 36.9136 13.7788C36.4979 13.7788 36.169 13.596 35.9305 13.2269C35.7353 12.9295 35.6377 12.5603 35.6377 12.1268C35.6377 11.7791 35.6992 11.4673 35.8184 11.195C35.9377 10.9191 36.104 10.7112 36.3136 10.5715C36.5232 10.4317 36.7473 10.36 36.9895 10.36C37.1449 10.36 37.2823 10.3887 37.4052 10.4496C37.5244 10.5106 37.6545 10.6145 37.7919 10.765V9.79382C37.7919 9.54656 37.7811 9.39961 37.7594 9.34945C37.7304 9.2814 37.6907 9.23477 37.6329 9.20256C37.575 9.1703 37.4738 9.15593 37.3184 9.15593V9.01261H38.7605L38.7678 9.00903ZM37.7955 11.195C37.6256 10.8689 37.416 10.7041 37.1666 10.7041C37.0799 10.7041 37.0112 10.7256 36.9533 10.7721C36.8666 10.8438 36.7979 10.9692 36.7437 11.1485C36.6895 11.3276 36.6606 11.6036 36.6606 11.9727C36.6606 12.3776 36.6895 12.6822 36.751 12.8757C36.8124 13.0692 36.8919 13.2126 36.9967 13.2986C37.051 13.3416 37.1232 13.3631 37.2172 13.3631C37.4196 13.3631 37.6148 13.2054 37.7955 12.8865V11.1915V11.195Z" fill="#E6DAFE"/>
|
||||
</g>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_405_2">
|
||||
<rect width="45.2632" height="20" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
After Width: | Height: | Size: 7.0 KiB |
Loading…
Reference in New Issue