Skip to content
This repository has been archived by the owner on Feb 9, 2025. It is now read-only.

Commit

Permalink
refactor withdraw button + show withdraw when users have outmoded dep…
Browse files Browse the repository at this point in the history
…osits (#2075)
  • Loading branch information
asktree authored Jan 23, 2024
1 parent bbbfcab commit df14822
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 288 deletions.
1 change: 0 additions & 1 deletion HeliumVotePlugin/components/LockTokensAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ export const LockTokensAccount: React.FC<{
<TokenDeposit
mint={councilMint}
tokenRole={GoverningTokenRole.Council}
councilVote={true}
inAccountDetails={true}
/>
</div>
Expand Down
1 change: 0 additions & 1 deletion HeliumVotePlugin/components/VotingPowerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const VotingPowerCard: React.FC<{
<TokenDeposit
mint={councilMint}
tokenRole={GoverningTokenRole.Council}
councilVote={true}
setHasGovPower={setHasGovPower}
/>
</div>
Expand Down
1 change: 0 additions & 1 deletion VoteStakeRegistry/components/Account/LockTokensAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ const LockTokensAccount: React.FC<{
<TokenDeposit
mint={councilMint}
tokenRole={GoverningTokenRole.Council}
councilVote={true}
inAccountDetails={true}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ const LockTokensAccount = ({ tokenOwnerRecordPk }) => {
<TokenDeposit
mint={councilMint}
tokenRole={GoverningTokenRole.Council}
councilVote={true}
inAccountDetails={true}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const LockPluginTokenBalanceCard = ({
<TokenDeposit
mint={councilMint}
tokenRole={GoverningTokenRole.Council}
councilVote={true}
setHasGovPower={setHasGovPower}
/>
</div>
Expand Down
48 changes: 26 additions & 22 deletions components/GovernancePower/GovernancePowerForRole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { useAsync } from 'react-async-hook'
import { determineVotingPowerType } from '@hooks/queries/governancePower'
import { useConnection } from '@solana/wallet-adapter-react'
import useSelectedRealmPubkey from '@hooks/selectedRealm/useSelectedRealmPubkey'
import LockedCommunityVotingPower from '@components/ProposalVotingPower/LockedCommunityVotingPower'
import NftVotingPower from '@components/ProposalVotingPower/NftVotingPower'
import LockedCommunityNFTRecordVotingPower from '@components/ProposalVotingPower/LockedCommunityNFTRecordVotingPower'
import VanillaVotingPower from './Vanilla/VanillaVotingPower'
import { Deposit } from './Vanilla/Deposit'
import { useUserCommunityTokenOwnerRecord } from '@hooks/queries/tokenOwnerRecord'
import { ExclamationIcon } from '@heroicons/react/solid'
import { VSR_PLUGIN_PKS } from '@constants/plugins'
import { useRealmConfigQuery } from '@hooks/queries/realmConfig'
import VanillaWithdrawTokensButton from '@components/TokenBalance/VanillaWithdrawTokensButton'
import LockedCommunityVotingPower from '@components/ProposalVotingPower/LockedCommunityVotingPower'

export default function GovernancePowerForRole({
role,
Expand All @@ -23,16 +22,11 @@ export default function GovernancePowerForRole({
}) {
const { connection } = useConnection()
const realmPk = useSelectedRealmPubkey()
const config = useRealmConfigQuery().data?.result

const ownTokenRecord = useUserCommunityTokenOwnerRecord().data?.result
//if dao transited to use plugin and some users have still deposited tokens they should withdraw before

//VSR if dao transited to use plugin and some users have still deposited tokens they should withdraw before
//depositing to plugin
const isVsr =
config?.account?.communityTokenConfig?.voterWeightAddin &&
VSR_PLUGIN_PKS.includes(
config?.account?.communityTokenConfig?.voterWeightAddin?.toBase58()
)
const didWithdrawFromVanillaSetup =
!ownTokenRecord ||
ownTokenRecord.account.governingTokenDepositAmount.isZero()
Expand All @@ -42,10 +36,8 @@ export default function GovernancePowerForRole({

const { result: kind } = useAsync(async () => {
if (realmPk === undefined) return undefined
return didWithdrawFromVanillaSetup
? determineVotingPowerType(connection, realmPk, role)
: 'vanilla'
}, [connection, realmPk, role, didWithdrawFromVanillaSetup])
return determineVotingPowerType(connection, realmPk, role)
}, [connection, realmPk, role])

if (connected && kind === undefined && !props.hideIfZero) {
return (
Expand All @@ -60,16 +52,28 @@ export default function GovernancePowerForRole({
<div>
<VanillaVotingPower role="community" {...props} />
<Deposit role="community" />
{isVsr && !didWithdrawFromVanillaSetup && (
<small className="flex items-center mt-3 text-xs">
<ExclamationIcon className="w-5 h-5 mr-2"></ExclamationIcon>
Please withdraw your tokens and deposit again to get governance
power
</small>
)}
</div>
) : kind === 'VSR' ? (
<LockedCommunityVotingPower />
didWithdrawFromVanillaSetup ? (
<LockedCommunityVotingPower />
) : (
//TODO make a better generic little prompt for when a plugin is used but there are still tokens in vanilla
<>
<VanillaVotingPower role="community" {...props} />
<div className="flex flex-col gap-2">
<div>
<small className="flex items-center mt-3 text-xs">
<ExclamationIcon className="w-5 h-5 mr-2"></ExclamationIcon>
Please withdraw your tokens and deposit again to get
governance power
</small>
</div>
<div>
<VanillaWithdrawTokensButton role={role} />
</div>
</div>
</>
)
) : kind === 'NFT' ? (
<NftVotingPower />
) : kind === 'HeliumVSR' ? (
Expand Down
Loading

1 comment on commit df14822

@vercel
Copy link

@vercel vercel bot commented on df14822 Jan 23, 2024

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
app.realms.today
governance-ui-solana-labs.vercel.app

Please sign in to comment.