forked from w3f/polkadot-wiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoluntary-Locking.jsx
112 lines (102 loc) · 2.39 KB
/
Voluntary-Locking.jsx
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
import React, { useState, useEffect } from 'react';
/*
This component is specific to Voluntary Locking.
Unfortunately, React components cannot be inserted in certain markdown elements.
If attempted they will just appear as a raw string instead of a rendered element.
To get around this limitation, this component returns the entire formatted table.
It can be used in Docusaurus markdown by adding the following lines anywhere within the file.
import VoluntaryLocking from "./../../components/VoluntaryLocking"
<VoluntaryLocking network="polkadot"/>
*/
let table = <table>
<tbody>
<tr>
<th>Lock Periods</th>
<th>Vote Multiplier</th>
<th>Length in Days</th>
</tr>
<tr>
<td>0</td>
<td>0.1</td>
<td id="p0"></td>
</tr>
<tr>
<td>1</td>
<td>1</td>
<td id="p1"></td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td id="p2"></td>
</tr>
<tr>
<td>4</td>
<td>3</td>
<td id="p4"></td>
</tr>
<tr>
<td>8</td>
<td>4</td>
<td id="p8"></td>
</tr>
<tr>
<td>16</td>
<td>5</td>
<td id="p16"></td>
</tr>
<tr>
<td>32</td>
<td>6</td>
<td id="p32"></td>
</tr>
</tbody>
</table>
const lockPeriods = ["p0", "p1", "p2", "p4", "p8", "p16", "p32"]
const dotLocking = {
p0: 0,
p1: 7,
p2: 14,
p4: 28,
p8: 56,
p16: 112,
p32: 224
}
const ksmLocking = {
p0: 0,
p1: 7,
p2: 14,
p4: 28,
p8: 56,
p16: 112,
p32: 224
}
function VoluntaryLocking() {
const [docType, setDocType] = useState("");
useEffect(() => {
// This is a hack to get the document type.
// It is required because the standard {{ polkadot/kusama: :polkadot/kusama}}
// can't be used to render a table (can't put a <table> in a <p>).
// So, we use the same component for Polkadot and Kusama and figure it out here.
const title = document.title;
if (title === "Governance V1 · Polkadot Wiki" || title === "Introduction to Polkadot OpenGov · Polkadot Wiki") {
updateTable("polkadot")
} else if (title === "Governance V1 · Guide" || title === "Introduction to Polkadot OpenGov · Guide") {
updateTable("kusama");
} else {
console.log("Unknown wiki/guide type");
}
}, []);
return (table);
}
function updateTable(network) {
lockPeriods.forEach(id => {
let el = document.getElementById(id);
if (network === "polkadot") {
el.innerText = dotLocking[id];
} else if (network === "kusama") {
el.innerText = ksmLocking[id];
}
});
}
export default VoluntaryLocking;