-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathValidatorData.vue
More file actions
310 lines (290 loc) · 11.4 KB
/
Copy pathValidatorData.vue
File metadata and controls
310 lines (290 loc) · 11.4 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<script lang="ts">
import { defineComponent, computed, ref, onMounted, watch } from 'vue';
import ValidatorDataTable from 'src/components/validators/ValidatorDataTable.vue';
import { api } from 'src/api';
import ViewTransaction from 'src/components/ViewTransanction.vue';
import { GetTableRowsParams } from 'src/types';
import WalletModal from 'src/components/WalletModal.vue';
import { getChain } from 'src/config/ConfigManager';
import { Name } from '@wharfkit/session';
import { formatCurrency, assetToAmount } from 'src/utils/string-utils';
import { useAccountStore } from 'src/stores/account';
import { useChainStore } from 'src/stores/chain';
const chain = getChain();
export default defineComponent({
name: 'ValidatorData',
components: {
ValidatorDataTable,
ViewTransaction,
WalletModal,
},
setup() {
const accountStore = useAccountStore();
const chainStore = useChainStore();
const symbol = chain.getSystemToken().symbol;
const account = computed(() => accountStore.accountName);
const balance = computed(
() => formatCurrency(lastWeight.value / 10000, 2, symbol),
);
const activecount = computed(() => {
if (chainStore.producers.length > 35) {
return 35;
} else {
return chainStore.producers.length;
}
});
const lastUpdated = ref<string>('');
const producerVotes = ref<Name[]>([]);
const currentVote = computed(() => accountStore.vote);
const showCpu = ref<boolean>(false);
const voteChanged = ref<boolean>(false);
const resetFlag = ref<boolean>(false);
const lastWeight = ref<number>(0);
const lastStaked = ref<number>(0);
const stakedAmount = ref<number>(0);
const accountValid = computed(() => account.value && account.value !== '');
const transactionId = ref<string>(accountStore.TransactionId);
const transactionError = ref<unknown>(accountStore.TransactionError);
const openTransaction = ref<boolean>(false);
const showWalletModal = ref<boolean>(false);
const payrate = ref(0);
const top21pay24h = ref(0);
const supply = ref(0);
const voters = ref(0);
const amount_voted = ref(0);
const votesProgress = computed(() => amount_voted.value / supply.value || 0);
async function getVotingStatistics() {
await getVoteWeight();
await updateVoteAmount();
await updateSupply();
await updatePayRate();
}
async function getVoteWeight() {
const paramsVoteWeight = {
code: 'eosio',
scope: 'eosio',
table: 'voters',
lower_bound: Name.from(account.value),
limit: 1,
} as GetTableRowsParams;
lastWeight.value = (
(await api.getTableRows(paramsVoteWeight)) as {
rows: { last_vote_weight: number }[];
}
).rows[0].last_vote_weight;
}
async function updatePayRate() {
const sharecount =
activecount.value <= 21
? ((activecount.value / 2.0) * (2.0 * 1.2 - (activecount.value - 1) * 0.02) * 2.0)
: (42.0 + ((activecount.value - 21) / 2.0) * (2.0 * 1.2 - (activecount.value - 22) * 0.02));
const paramsPayrate = {
code: 'delphioracle',
scope: 'tlosusd',
table: 'averages',
} as GetTableRowsParams;
const tlosusd = (
(await api.getTableRows(paramsPayrate)) as {
rows: { value: number }[];
}
).rows[0].value;
// Calculate base value using the formula
const baseValue = Math.min(
((189000 * 12) / 365) * Math.pow(tlosusd / 10000.0, -0.516),
((315000 * 12) / 365),
);
// Apply sharecount division and multiply by 10000
top21pay24h.value = (baseValue * 2) / sharecount;
}
async function updateSupply() {
const paramsSupply = {
code: 'eosio.token',
scope: chain.getSystemToken().symbol,
table: 'stat',
} as GetTableRowsParams;
supply.value = assetToAmount(
(
(await api.getTableRows(paramsSupply)) as {
rows: { supply: string }[];
}
).rows[0].supply,
);
}
async function updateVoteAmount() {
const request = {
code: 'eosio',
lower_bound: 'eosio',
table: 'voters',
};
voters.value = (await api.getTableByScope(request))[0].count;
const totalStakeParams = {
code: 'eosio',
scope: 'eosio',
table: 'global',
} as GetTableRowsParams;
amount_voted.value =
(
(await api.getTableRows(totalStakeParams)) as {
rows: { total_activated_stake: number }[];
}
).rows[0].total_activated_stake / 10000;
}
function toggleView() {
showCpu.value = !showCpu.value;
}
async function sendVoteTransaction() {
if (accountValid.value) {
await accountStore.sendVoteTransaction();
openTransaction.value = true;
await getVoteWeight();
} else {
showWalletModal.value = true;
}
}
watch(activecount, () => {
void getVotingStatistics();
});
onMounted(async () => {
await getVotingStatistics();
});
return {
account,
lastUpdated,
producerVotes,
showCpu,
voteChanged,
resetFlag,
lastWeight,
lastStaked,
stakedAmount,
currentVote,
accountValid,
openTransaction,
transactionId,
transactionError,
payrate,
top21pay24h,
supply,
voters,
amount_voted,
votesProgress,
balance,
showWalletModal,
symbol,
toggleView,
sendVoteTransaction,
};
},
});
</script>
<template>
<div class="q-pa-md header-support">
<div class="row q-col-gutter-md q-pt-md container-max-width">
<div class="col-md-8 col-sm-12 col-xs-12">
<q-card class="full-height" >
<q-card-section>
<div class="row q-pa-md text-h5 text-weight-light">Voting Statistics</div>
<div class="row q-pa-md">
<div class="col-12">
<q-linear-progress
class="gradient-color q-mt-sm"
size="120px"
rounded
:value="votesProgress"
/>
</div>
</div>
<div class="row q-pa-md">
<div class="col-12">
<div class="row">
<div class="col-6 text-uppercase text-grey">Total votes</div>
<div class="col-6">
<div class="float-right text-uppercase text-grey">Total Supply</div>
</div>
</div>
<div class="row">
<div class="col-6">{{ amount_voted.toLocaleString(undefined, {minimumFractionDigits: 4,maximumFractionDigits: 4,}) }}</div>
<div class="col-6">
<div class="float-right">{{ supply.toLocaleString(undefined, {minimumFractionDigits: 4,maximumFractionDigits: 4,}) }}</div>
</div>
</div>
</div>
</div>
</q-card-section>
</q-card>
</div>
<div v-if="accountValid" class="col-md-4 col-sm-12 col-xs-12">
<q-card>
<q-card-section>
<div class="row full-width justify-center">
<div class="text-h6 q-py-md text-weight-regular text-grey">Current Vote Weight</div>
<q-icon
class="info-icon"
name="info"
color="white"
size="20px"
>
<q-tooltip anchor="top middle" self="bottom middle" :offset="[10, 10]">Voting is inversley weighted and increases the more validators you vote for (up to 30).</q-tooltip>
</q-icon>
</div>
<div class="row full-width justify-center text-h5">{{ balance }}</div>
<div class="row full-width justify-center text-h6 q-py-md text-weight-regular text-grey">{{account}}</div>
</q-card-section>
<q-separator />
<q-card-section>
<div class="row full-width justify-center subtitle2 q-py-md text-weight-regular text-grey q-pt-lg">SELECTED {{currentVote.length}} BLOCK PRODUCERS</div>
<div class="row full-width justify-center">
<q-btn
class="full-width q-pa-sm"
label="Vote for Block Producers"
color="primary"
@click="sendVoteTransaction"
/>
</div>
</q-card-section>
</q-card>
</div>
<div v-else class="col-md-4 col-sm-12 col-xs-12">
<q-card class="full-height">
<q-card-section class="full-height">
<div class="column justify-center full-height">
<div class="row">
<div class="col-12 subtitle2 q-pb-md text-weight-regular text-grey q-pt-lg text-center">SELECTED {{currentVote.length}} BLOCK PRODUCERS</div>
<div class="col-12">
<q-btn
class="full-width q-pa-sm"
label="Vote for Block Producers"
color="primary"
@click="sendVoteTransaction"
/>
</div>
</div>
</div>
</q-card-section>
</q-card>
</div>
</div>
</div>
<div class="container-max-width">
<ValidatorDataTable ref="ValidatorDataTable" :top21pay24h="top21pay24h"/>
<ViewTransaction
v-model="openTransaction"
:transactionId="transactionId"
:transactionError="transactionError || ''"
message="transaction complete"
/>
</div>
<WalletModal v-model="showWalletModal"/>
</template>
<style lang="sass" scoped>
.header-support
height: auto
.card-gradient
background: var(--q-color-secondary-gradient)
color: white
.info-icon
display: inline-block
margin-top: auto
margin-bottom: auto
margin-left: 0.5rem
</style>