Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check for custom min voting power when voting #614

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
21 changes: 19 additions & 2 deletions apps/ui/src/components/MessageVotingPower.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
<script setup lang="ts">
import { VotingPowerItem } from '@/stores/votingPowers';

defineProps<{
const props = defineProps<{
votingPower: VotingPowerItem;
action?: 'vote' | 'propose';
}>();

defineEmits<{
(e: 'fetchVotingPower');
}>();

const insufficientVp: ComputedRef<boolean> = computed(() => {
return !!(
props.votingPower.threshold.vote && props.votingPower.totalVotingPower > 0n
);
});

const formattedVotingThreshold = computed(() => {
return (
Number(props.votingPower.threshold.vote) / 10 ** props.votingPower.decimals
);
});
</script>

<template>
Expand All @@ -33,7 +45,12 @@ defineEmits<{
type="error"
v-bind="$attrs"
>
You do not have enough voting power to vote.
<span v-if="insufficientVp">
You need at least a voting power of
<i> {{ formattedVotingThreshold }} {{ votingPower.symbol }} </i>
to vote.
</span>
<span v-else> You do not have enough voting power to vote. </span>
</UiAlert>
<UiAlert
v-else-if="action === 'propose' && !votingPower.canPropose"
Expand Down
4 changes: 3 additions & 1 deletion apps/ui/src/networks/common/graphqlApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ function formatProposal(
state: getProposalState(proposal, current),
network: networkId,
privacy: null,
quorum: +proposal.quorum
quorum: +proposal.quorum,
validation: 'any',
validation_params: {}
};
}

Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/networks/offchain/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ function formatProposal(proposal: ApiProposal, networkId: NetworkID): Proposal {
strategies: proposal.strategies.map(strategy => strategy.name),
strategies_indicies: [],
strategies_params: proposal.strategies.map(strategy => strategy),
validation: proposal.validation.name,
validation_params: proposal.validation.params,
tx: '',
execution_tx: null,
veto_tx: null,
Expand Down
4 changes: 4 additions & 0 deletions apps/ui/src/networks/offchain/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const PROPOSAL_FRAGMENT = gql`
params
network
}
validation {
name
params
}
created
updated
votes
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/networks/offchain/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type ApiProposal = {
scores_total: number;
state: 'active' | 'pending' | 'closed';
strategies: { network: string; params: Record<string, any>; name: string }[];
validation: { name: string; params: Record<string, any> };
created: number;
updated: number | null;
votes: number;
Expand Down
16 changes: 12 additions & 4 deletions apps/ui/src/stores/votingPowers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type VotingPowerItem = {
error: utils.errors.VotingPowerDetailsError | null;
canPropose: boolean;
canVote: boolean;
threshold: {
propose?: bigint;
vote?: bigint;
};
};

export function getIndex(space: SpaceDetails, block: number | null): string {
Expand Down Expand Up @@ -45,7 +49,8 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
symbol: space.voting_power_symbol,
error: null,
canPropose: false,
canVote: false
canVote: false,
threshold: {}
};

if (existingVotingPower) {
Expand Down Expand Up @@ -75,10 +80,13 @@ export const useVotingPowersStore = defineStore('votingPowers', () => {
};

if ('proposal_threshold' in space) {
vpItem.canPropose =
vpItem.totalVotingPower >= BigInt(space.proposal_threshold);
vpItem.threshold.propose = BigInt(space.proposal_threshold);
vpItem.canPropose = vpItem.totalVotingPower >= vpItem.threshold.propose;
} else {
vpItem.canVote = vpItem.totalVotingPower > 0n;
vpItem.threshold.vote = BigInt(
((item as Proposal).validation_params.minScore || 0) * 10 ** 18
);
vpItem.canVote = vpItem.totalVotingPower > vpItem.threshold.vote;
}
} catch (e: unknown) {
if (e instanceof utils.errors.VotingPowerDetailsError) {
Expand Down
5 changes: 5 additions & 0 deletions apps/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ export type Proposal = {
strategies_indicies: number[];
strategies: string[];
strategies_params: any[];
validation: string;
validation_params: {
minScore?: number;
strategies?: Record<string, any>[];
};
created: number;
edited: number | null;
tx: string;
Expand Down
Loading