33import Tooltip from " @/components/ui/Tooltip.vue"
44
55/** Services */
6- import { comma } from " @/services/utils"
6+ import { comma , roundTo } from " @/services/utils"
77
88/** Store */
99import { useAppStore } from " @/store/app.store"
@@ -29,6 +29,45 @@ const totalVotingPower = computed(() => {
2929 return lastHead .value ? .total_voting_power ?? 0
3030})
3131
32+ const voteKinds = {
33+ yes: {
34+ name: " Yes" ,
35+ color: " var(--brand)" ,
36+ },
37+ no: {
38+ name: " No" ,
39+ color: " var(--red)" ,
40+ },
41+ no_with_veto: {
42+ name: " No with veto" ,
43+ color: " var(--red)" ,
44+ },
45+ abstain: {
46+ name: " Abstain" ,
47+ color: " var(--op-40)" ,
48+ },
49+ }
50+ const voteDistribution = computed (() => {
51+ const distribution = {}
52+
53+ Object .keys (voteKinds).forEach ((kind ) => {
54+ distribution[kind] = {
55+ ... voteKinds[kind],
56+ power: Number (props .proposal [` ${ kind} _voting_power` ] / 1_000_000 || 0 ),
57+ shareOfTotal: Number (props .proposal [` ${ kind} _voting_power` ] / 1_000_000 * 100 || 0 ) / totalVotingPower .value ,
58+ }
59+
60+ const shareOfVotes = roundTo (Number (props .proposal [` ${ kind} _voting_power` ] / 1_000_000 * 100 || 0 ) / (props .proposal .voting_power / 1_000_000 ), 0 )
61+ distribution[kind].shareOfVotes = shareOfVotes === 0 && props .proposal [kind]
62+ ? " < 1%"
63+ : shareOfVotes === 100 && props .proposal [kind] < props .proposal .votes_count
64+ ? " > 99%"
65+ : ` ${ shareOfVotes} %`
66+ })
67+
68+ return distribution
69+ })
70+
3271const quorum = props .proposal .status === " active" ? Number (appStore .constants ? .gov .quorum ) : Number (props .proposal .quorum )
3372
3473const isQuorumReached = computed (() => {
@@ -55,93 +94,38 @@ const isQuorumReached = computed(() => {
5594 < div : style= " { left: `${quorum * 100}%` }" : class = " [$style.threshold, !isQuorumReached && $style.red]" / >
5695
5796 < Tooltip
58- v- if = " proposal.yes "
97+ v- for = " v in Object.keys(voteDistribution) "
5998 wide
60- : trigger- width= " `${Math.max(5, ((proposal.yes_voting_power / 1_000_000) * 100) / totalVotingPower) }%`"
99+ : trigger- width= " `${voteDistribution[v].power ? Math.max(5, voteDistribution[v].shareOfTotal) : 0 }%`"
61100 >
62101 < div
63102 : style= " {
64- background: 'var(--brand)' ,
103+ background: voteDistribution[v].color ,
65104 }"
66105 : class = " $style.voting_bar"
67106 / >
68107 < template #content>
69- Yes :
108+ {{ voteDistribution[v]. name }} :
70109 < Text color= " primary" >
71- {{ comma (Number ( proposal . yes_voting_power ) / 1_000_000 ) }}
110+ {{ comma (voteDistribution[v]. power ) }}
72111 < / Text >
73112 TIA
74113 < / template>
75114 < / Tooltip>
76- < Tooltip
77- v- if = " proposal.no"
78- wide
79- : trigger- width= " `${Math.max(5, ((proposal.no_voting_power / 1_000_000) * 100) / totalVotingPower)}%`"
80- >
81- < div
82- : style= " {
83- background: 'var(--red)',
84- }"
85- : class = " $style.voting_bar"
86- / >
87- < template #content>
88- No: < Text color= " primary" > {{ comma (Number (proposal .no_voting_power ) / 1_000_000 ) }}< / Text > TIA
89- < / template>
90- < / Tooltip>
91- < Tooltip
92- v- if = " proposal.no_with_veto"
93- wide
94- : trigger- width= " `${Math.max(5, ((proposal.no_with_veto_voting_power / 1_000_000) * 100) / totalVotingPower)}%`"
95- >
96- < div
97- : style= " {
98- background: 'var(--red)',
99- }"
100- : class = " $style.voting_bar"
101- / >
102- < template #content>
103- No with veto: < Text color= " primary" > {{ comma (Number (proposal .no_with_veto_voting_power ) / 1_000_000 ) }}< / Text > TIA
104- < / template>
105- < / Tooltip>
106- < Tooltip
107- v- if = " proposal.abstain"
108- wide
109- : trigger- width= " `${Math.max(5, ((proposal.abstain_voting_power / 1_000_000) * 100) / totalVotingPower)}%`"
110- >
111- < div
112- : style= " {
113- background: 'var(--op-40)',
114- }"
115- : class = " $style.voting_bar"
116- / >
117- < template #content>
118- Abstain: < Text color= " primary" > {{ comma (Number (proposal .abstain_voting_power / 1_000_000 )) }}< / Text > TIA
119- < / template>
120- < / Tooltip>
121115 < / Flex>
122116
123117 < Flex v- if = " expand" direction= " column" gap= " 16" >
124118 < Flex v- for = " vote in votes" align= " center" justify= " between" >
125119 < Flex align= " center" gap= " 6" >
126120 < div : class = " [$style.dot, $style[vote]]" / >
127- < Text size= " 12" weight= " 600" color= " secondary" style = " text-transform: capitalize " > {{ vote . replaceAll ( " _ " , " " ) }}< / Text >
128- < Text v- if = " Number(proposal[`${ vote}_voting_power`]) " size= " 12" weight= " 600" color= " tertiary" >
129- {{ comma (proposal[ ` ${ vote} _voting_power ` ] / 1_000_000 ) }} TIA
121+ < Text size= " 12" weight= " 600" color= " secondary" > {{ voteDistribution[ vote]. name }}< / Text >
122+ < Text v- if = " voteDistribution[ vote].power " size= " 12" weight= " 600" color= " tertiary" >
123+ {{ comma (voteDistribution[ vote]. power ) }} TIA
130124 < / Text >
131125 < / Flex>
132126
133- < Text size= " 12" weight= " 600" : color= " proposal[vote] ? 'secondary' : 'tertiary'" >
134- < template
135- v- if = "
136- (Number(proposal[`${vote}_voting_power`]) * 100) / (Number(proposal.voting_power)) > 0 &&
137- (Number(proposal[`${vote}_voting_power`]) * 100) / (Number(proposal.voting_power)) < 1
138- "
139- >
140- < Text color= " tertiary" >< 1 % < / Text >
141- < / template>
142- < template v- else >
143- {{ ((Number (proposal[` ${ vote} _voting_power` ]) * 100 ) / (Number (proposal .voting_power ))).toFixed (0 ) }}%
144- < / template>
127+ < Text size= " 12" weight= " 600" : color= " !proposal[vote] || voteDistribution[vote].shareOfVotes === '< 1%' ? 'tertiary' : 'secondary'" >
128+ {{ voteDistribution[vote].shareOfVotes }}
145129 < / Text >
146130 < / Flex>
147131
0 commit comments