Skip to content

Commit c0f1784

Browse files
committed
gov: minor fixes & imp
1 parent cdccc7f commit c0f1784

7 files changed

Lines changed: 50 additions & 31 deletions

File tree

components/modules/proposal/ProposalOverview.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ import { fetchProposalVotes } from "@/services/api/proposal"
2121
/** Store */
2222
import { useModalsStore } from "@/store/modals"
2323
import { useCacheStore } from "@/store/cache"
24-
import { useAppStore } from "@/store/app"
2524
const modalsStore = useModalsStore()
2625
const cacheStore = useCacheStore()
27-
const appStore = useAppStore()
2826
2927
const route = useRoute()
3028
const router = useRouter()

components/modules/proposal/VotesAllocation.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ const props = defineProps({
2121
})
2222
2323
const expand = ref(["inactive", "active"].includes(props.proposal.status))
24+
25+
const threshold = props.proposal.status === "active" ? Number(appStore.constants.gov.threshold) : Number(props.proposal.threshold)
26+
const vetoThreshold =
27+
props.proposal.status === "active" ? Number(appStore.constants.gov.veto_threshold) : Number(props.proposal.veto_quorum)
28+
29+
const isThresholdMet = computed(() => {
30+
return props.proposal.yes / props.proposal.votes_count > threshold
31+
})
32+
const isVetoThresholdMet = computed(() => {
33+
return props.proposal.no_with_veto / props.proposal.votes_count > vetoThreshold
34+
})
2435
</script>
2536

2637
<template>
@@ -31,28 +42,23 @@ const expand = ref(["inactive", "active"].includes(props.proposal.status))
3142
<Text size="12" weight="600" color="secondary">Allocation of votes</Text>
3243
<Icon
3344
v-if="['applied', 'rejected'].includes(proposal.status)"
34-
:name="
35-
(proposal.no_with_veto / proposal.votes_count > Number(proposal.veto_quorum) && 'warning') ||
36-
(proposal.yes / proposal.votes_count > Number(proposal.threshold) && 'check-circle')
37-
"
45+
:name="(isVetoThresholdMet && 'warning') || (isThresholdMet && 'check-circle')"
3846
size="12"
3947
color="secondary"
4048
/>
4149
</Flex>
4250

43-
<template v-if="proposal.no_with_veto / proposal.votes_count > Number(proposal.veto_quorum)" #content>
44-
The No With Veto vote threshold is met - {{ Number(proposal.veto_quorum) * 100 }}%
45-
</template>
46-
<template v-else-if="proposal.yes / proposal.votes_count > Number(proposal.threshold)" #content>
47-
The Yes vote threshold is met - {{ Number(proposal.threshold) * 100 }}%
51+
<template v-if="isVetoThresholdMet" #content>
52+
The No With Veto vote threshold is met - {{ vetoThreshold * 100 }}%
4853
</template>
54+
<template v-else-if="isThresholdMet" #content> The Yes vote threshold is met - {{ threshold * 100 }}% </template>
4955
</Tooltip>
5056

5157
<Icon name="chevron" size="12" color="secondary" :style="{ transform: `rotate(${expand ? '180deg' : '0deg'})` }" />
5258
</Flex>
5359

5460
<Flex align="center" gap="4" :class="$style.voting_wrapper">
55-
<div :style="{ left: `${Number(proposal.threshold) * 100}%` }" :class="$style.threshold" />
61+
<div :style="{ left: `${threshold * 100}%` }" :class="$style.threshold" />
5662

5763
<Tooltip v-if="proposal.yes" wide :trigger-width="`${Math.max(5, (proposal.yes * 100) / proposal.votes_count)}%`">
5864
<div

components/modules/proposal/VotingPower.vue

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { useEnumStore } from "@/store/enums"
1111
const appStore = useAppStore()
1212
const enumStore = useEnumStore()
1313
14+
const lastHead = computed(() => appStore.lastHead)
15+
1416
const votes = computed(() => enumStore.enums.voteOption)
1517
1618
const props = defineProps({
@@ -21,30 +23,41 @@ const props = defineProps({
2123
})
2224
2325
const expand = ref(["active"].includes(props.proposal.status))
26+
27+
const totalVotingPower = computed(() => {
28+
if (Number(props.proposal.total_voting_power)) return Number(props.proposal.total_voting_power)
29+
return lastHead.value?.total_voting_power ?? 0
30+
})
31+
32+
const quorum = props.proposal.status === "active" ? Number(appStore.constants.gov.quorum) : Number(props.proposal.quorum)
33+
34+
const isQuorumReached = computed(() => {
35+
return props.proposal.voting_power / 1_000_000 / totalVotingPower.value > quorum
36+
})
2437
</script>
2538
2639
<template>
2740
<Flex direction="column" gap="10" :class="$style.wrapper">
2841
<Flex @click="expand = !expand" align="center" justify="between" class="clickable">
29-
<Tooltip position="start" :disabled="!proposal.status === 'applied'">
42+
<Tooltip position="start" :disabled="!isQuorumReached && proposal.status === 'active'">
3043
<Flex align="center" gap="6">
3144
<Text size="12" weight="600" color="secondary">Voting power</Text>
32-
<Icon v-if="proposal.status === 'applied'" name="check-circle" size="12" color="secondary" />
45+
<Icon v-if="isQuorumReached && proposal.status !== 'active'" name="check-circle" size="12" color="secondary" />
3346
</Flex>
3447
35-
<template #content> The quorum is reached - {{ Number(proposal.quorum) * 100 }}% </template>
48+
<template #content> The quorum is reached - {{ quorum * 100 }}% </template>
3649
</Tooltip>
3750
3851
<Icon name="chevron" size="12" color="secondary" :style="{ transform: `rotate(${expand ? '180deg' : '0deg'})` }" />
3952
</Flex>
4053
4154
<Flex align="center" gap="4" :class="$style.voting_wrapper">
42-
<div :style="{ left: `${Number(proposal.quorum) * 100}%` }" :class="$style.threshold" />
55+
<div :style="{ left: `${quorum * 100}%` }" :class="[$style.threshold, !isQuorumReached && $style.red]" />
4356
4457
<Tooltip
4558
v-if="proposal.yes"
4659
wide
47-
:trigger-width="`${Math.max(5, (Number(proposal.yes_voting_power) * 100) / (proposal.voting_power * 2))}%`"
60+
:trigger-width="`${Math.max(5, ((proposal.yes_voting_power / 1_000_000) * 100) / totalVotingPower)}%`"
4861
>
4962
<div
5063
:style="{
@@ -63,7 +76,7 @@ const expand = ref(["active"].includes(props.proposal.status))
6376
<Tooltip
6477
v-if="proposal.no"
6578
wide
66-
:trigger-width="`${Math.max(5, (Number(proposal.no_voting_power) * 100) / (proposal.voting_power * 2))}%`"
79+
:trigger-width="`${Math.max(5, ((proposal.no_voting_power / 1_000_000) * 100) / totalVotingPower)}%`"
6780
>
6881
<div
6982
:style="{
@@ -78,7 +91,7 @@ const expand = ref(["active"].includes(props.proposal.status))
7891
<Tooltip
7992
v-if="proposal.no_with_veto"
8093
wide
81-
:trigger-width="`${Math.max(5, (Number(proposal.no_with_veto_voting_power) * 100) / (proposal.voting_power * 2))}%`"
94+
:trigger-width="`${Math.max(5, ((proposal.no_with_veto_voting_power / 1_000_000) * 100) / totalVotingPower)}%`"
8295
>
8396
<div
8497
:style="{
@@ -93,7 +106,7 @@ const expand = ref(["active"].includes(props.proposal.status))
93106
<Tooltip
94107
v-if="proposal.abstain"
95108
wide
96-
:trigger-width="`${Math.max(5, (Number(proposal.abstain_voting_power) * 100) / (proposal.voting_power * 2))}%`"
109+
:trigger-width="`${Math.max(5, ((proposal.abstain_voting_power / 1_000_000) * 100) / totalVotingPower)}%`"
97110
>
98111
<div
99112
:style="{
@@ -171,6 +184,11 @@ const expand = ref(["active"].includes(props.proposal.status))
171184
z-index: 1;
172185
173186
transform: translateX(-50%);
187+
188+
&.red {
189+
background: var(--red);
190+
box-shadow: 0 0 8px rgb(235, 87, 87);
191+
}
174192
}
175193
176194
.voting_bar {

error.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ onMounted(async () => {
2222
amp.init(runtimeConfig.public.AMP)
2323
2424
const data = await fetchHead()
25-
if (data) appStore.head = data
25+
if (data) appStore.lastHead = data
2626
})
2727
2828
const handleBack = () => {

services/api/socket.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const init = () => {
1010
const appStore = useAppStore()
1111

1212
const startWs = () => {
13-
1413
socket = new WebSocket(useSocketURL())
1514

1615
socket.addEventListener("open", (e) => {
@@ -37,13 +36,13 @@ export const init = () => {
3736

3837
socket.addEventListener("message", (e) => {
3938
const data = JSON.parse(e.data)
40-
if (data.channel === 'head') {
41-
appStore.lastHead = data.body;
42-
} else if (data.channel === 'blocks') {
43-
appStore.latestBlocks.unshift(data.body);
39+
if (data.channel === "head") {
40+
appStore.lastHead = data.body
41+
} else if (data.channel === "blocks") {
42+
appStore.latestBlocks.unshift(data.body)
4443
setTimeout(() => {
45-
appStore.latestBlocks.pop();
46-
}, 1000);
44+
appStore.latestBlocks.pop()
45+
}, 1000)
4746
}
4847
})
4948

services/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const useSocketURL = () => {
6969
return Server.WSS.dev
7070

7171
default:
72-
return Server.WSS.dev
72+
return Server.WSS.mocha
7373
}
7474
}
7575

store/app.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const useAppStore = defineStore("app", () => {
1414
constants.value = data.value.module
1515
}
1616

17-
const head = ref()
1817
const gas = ref({
1918
fast: 0,
2019
median: 0,
@@ -57,7 +56,6 @@ export const useAppStore = defineStore("app", () => {
5756
network,
5857
constants,
5958
initConstants,
60-
head,
6159
gas,
6260
currentPrice,
6361
wallet,

0 commit comments

Comments
 (0)