forked from solana-labs/governance-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProposalVoteResults.tsx
170 lines (162 loc) · 5.01 KB
/
ProposalVoteResults.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { Governance, ProgramAccount, Proposal } from '@solana/spl-governance'
import classNames from 'classnames'
import { VoterDisplayData, VoteType } from '@models/proposal'
import { formatPercentage } from '@utils/formatPercentage'
interface Props {
className?: string
data: VoterDisplayData[]
governance: ProgramAccount<Governance>
proposal: ProgramAccount<Proposal>
}
export default function ProposalVoteResult(props: Props) {
const yesPercent = props.data.reduce((acc, cur) => {
if (cur.voteType === VoteType.Yes) {
return acc + cur.votePercentage
}
return acc
}, 0)
const noPercent = props.data.reduce((acc, cur) => {
if (cur.voteType === VoteType.No) {
return acc + cur.votePercentage
}
return acc
}, 0)
const threshold =
props.proposal.account.voteThreshold?.value ||
props.governance.account.config.communityVoteThreshold.value
return (
<div className={props.className}>
<h3>Vote Result</h3>
<div className="py-20">
<div className="relative w-full h-4">
<div className="absolute bg-neutral-600 top-0 left-0 right-0 bottom-0 rounded overflow-hidden">
<div
className="absolute bg-lime-600 left-0 top-0 bottom-0"
style={{ width: `${yesPercent}%` }}
/>
<div
className="absolute bg-rose-700 right-0 top-0 bottom-0"
style={{ width: `${noPercent}%` }}
/>
</div>
<div
className={classNames(
'-bottom-3',
'-top-3',
'-translate-x-1/2',
'absolute',
'bg-neutral-400',
'left-1/2',
'w-[3px]'
)}
/>
<div
className={classNames(
'-translate-x-1/2',
'absolute',
'bg-lime-600',
'flex-col',
'flex',
'items-center',
'p-2',
'rounded',
'text-white',
'top-full',
'translate-y-2',
'after:-mb-[6px]',
'after:-translate-x-1/2',
'after:absolute',
'after:bg-lime-600',
'after:bottom-full',
'after:h-[8px]',
'after:left-1/2',
'after:rotate-45',
'after:w-[8px]',
'after:z-20',
"after:content-[' ']"
)}
style={{ left: `${yesPercent}%` }}
>
<div className="text-[8px] leading-3">Yay</div>
<div className="text-sm font-bold">
{formatPercentage(yesPercent)}
</div>
</div>
<div
className={classNames(
'absolute',
'bg-rose-700',
'flex-col',
'flex',
'items-center',
'p-2',
'rounded',
'text-white',
'top-full',
'translate-x-1/2',
'translate-y-2',
'after:-mb-[6px]',
'after:-translate-x-1/2',
'after:absolute',
'after:bg-rose-700',
'after:bottom-full',
'after:h-[8px]',
'after:left-1/2',
'after:rotate-45',
'after:w-[8px]',
'after:z-20',
"after:content-[' ']"
)}
style={{ right: `${noPercent}%` }}
>
<div className="text-[8px] leading-3">Nay</div>
<div className="text-sm font-bold">
{formatPercentage(noPercent)}
</div>
</div>
{threshold && (
<>
<div
className="absolute bg-purple-800 top-0 bottom-0 w-[3px]"
style={{ left: `${threshold}%` }}
/>
<div
className={classNames(
'-translate-x-1/2',
'-translate-y-2',
'absolute',
'bg-purple-800',
'bottom-full',
'flex-col',
'flex',
'items-center',
'ml-[1px]',
'p-2',
'rounded',
'text-white',
'after:-mt-[6px]',
'after:-translate-x-1/2',
'after:absolute',
'after:bg-purple-800',
'after:h-[8px]',
'after:left-1/2',
'after:rotate-45',
'after:top-full',
'after:w-[8px]',
'after:z-20',
"after:content-[' ']"
)}
style={{ left: `${threshold}%` }}
>
<div className="text-[8px] leading-3">Threshold</div>
<div className="text-sm font-bold">
{formatPercentage(threshold)}
</div>
</div>
</>
)}
</div>
</div>
</div>
)
}