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

refactor withdraw button + show withdraw when users have outmoded deposits #2075

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion HeliumVotePlugin/components/LockTokensAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
message: 'Unable to fetch positions',
})
}
}, [tokenOwnerRecordWalletPk, vsrClient])

Check warning on line 155 in HeliumVotePlugin/components/LockTokensAccount.tsx

View workflow job for this annotation

GitHub Actions / Run Tests

React Hook useAsync has missing dependencies: 'config?.account.communityTokenConfig.voterWeightAddin', 'connection', 'currentClient', 'getPositions', 'realm.account.communityMint', 'realm.pubkey', and 'wallet.publicKey'. Either include them or remove the dependency array

const hasTokensInWallet =
realmTokenAccount && realmTokenAccount.account.amount.gt(new BN(0))
Expand Down Expand Up @@ -401,7 +401,6 @@
<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
Loading