From 6aa79f956c1b4291d0f753057e99759c4a122422 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Sun, 11 Aug 2024 13:36:12 +0900
Subject: [PATCH 1/2] feat: check for custom min voting power when voting
---
apps/ui/src/components/MessageVotingPower.vue | 10 +++++++++-
apps/ui/src/networks/common/graphqlApi/index.ts | 4 +++-
apps/ui/src/networks/offchain/api/index.ts | 2 ++
apps/ui/src/networks/offchain/api/queries.ts | 4 ++++
apps/ui/src/networks/offchain/api/types.ts | 1 +
apps/ui/src/stores/votingPowers.ts | 16 ++++++++++++----
apps/ui/src/types.ts | 5 +++++
7 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/apps/ui/src/components/MessageVotingPower.vue b/apps/ui/src/components/MessageVotingPower.vue
index 0193b979c..132c5e46c 100644
--- a/apps/ui/src/components/MessageVotingPower.vue
+++ b/apps/ui/src/components/MessageVotingPower.vue
@@ -33,7 +33,15 @@ defineEmits<{
type="error"
v-bind="$attrs"
>
- You do not have enough voting power to vote.
+
+ You need at least a voting power of
+
+ {{ Number(votingPower.threshold.vote) / 10 ** votingPower.decimals }}
+ {{ votingPower.symbol }}
+
+ to vote.
+
+ You do not have enough voting power to vote.
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,
diff --git a/apps/ui/src/networks/offchain/api/queries.ts b/apps/ui/src/networks/offchain/api/queries.ts
index 6c029a5e9..8a83a5f02 100644
--- a/apps/ui/src/networks/offchain/api/queries.ts
+++ b/apps/ui/src/networks/offchain/api/queries.ts
@@ -81,6 +81,10 @@ const PROPOSAL_FRAGMENT = gql`
params
network
}
+ validation {
+ name
+ params
+ }
created
updated
votes
diff --git a/apps/ui/src/networks/offchain/api/types.ts b/apps/ui/src/networks/offchain/api/types.ts
index f9b0ca70b..d97dcea76 100644
--- a/apps/ui/src/networks/offchain/api/types.ts
+++ b/apps/ui/src/networks/offchain/api/types.ts
@@ -72,6 +72,7 @@ export type ApiProposal = {
scores_total: number;
state: 'active' | 'pending' | 'closed';
strategies: { network: string; params: Record; name: string }[];
+ validation: { name: string; params: Record };
created: number;
updated: number | null;
votes: number;
diff --git a/apps/ui/src/stores/votingPowers.ts b/apps/ui/src/stores/votingPowers.ts
index 6360cfc10..872eef262 100644
--- a/apps/ui/src/stores/votingPowers.ts
+++ b/apps/ui/src/stores/votingPowers.ts
@@ -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 {
@@ -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) {
@@ -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) {
diff --git a/apps/ui/src/types.ts b/apps/ui/src/types.ts
index d223a0cf9..8a2ad0bff 100644
--- a/apps/ui/src/types.ts
+++ b/apps/ui/src/types.ts
@@ -200,6 +200,11 @@ export type Proposal = {
strategies_indicies: number[];
strategies: string[];
strategies_params: any[];
+ validation: string;
+ validation_params: {
+ minScore?: number;
+ strategies?: Record[];
+ };
created: number;
edited: number | null;
tx: string;
From aac987ae3e31a142cfe2baca9e00dfd2fd55a033 Mon Sep 17 00:00:00 2001
From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com>
Date: Sun, 11 Aug 2024 14:05:11 +0900
Subject: [PATCH 2/2] fix: show the insufficient vp warning message only when
current vp > 0
---
apps/ui/src/components/MessageVotingPower.vue | 21 +++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/apps/ui/src/components/MessageVotingPower.vue b/apps/ui/src/components/MessageVotingPower.vue
index 132c5e46c..cb7097c06 100644
--- a/apps/ui/src/components/MessageVotingPower.vue
+++ b/apps/ui/src/components/MessageVotingPower.vue
@@ -1,7 +1,7 @@
@@ -33,12 +45,9 @@ defineEmits<{
type="error"
v-bind="$attrs"
>
-
+
You need at least a voting power of
-
- {{ Number(votingPower.threshold.vote) / 10 ** votingPower.decimals }}
- {{ votingPower.symbol }}
-
+ {{ formattedVotingThreshold }} {{ votingPower.symbol }}
to vote.
You do not have enough voting power to vote.