-
Notifications
You must be signed in to change notification settings - Fork 4
/
profile.js
140 lines (129 loc) · 4.68 KB
/
profile.js
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
function renderOneProfile(id) {
ident = identityObjects.get(id)
if (ident !== undefined) {
document.getElementById("content").replaceChildren(getProfileHtml(ident))
} else {
document.getElementById("content").replaceChildren(createElement("Account", "Not Found"))
}
}
function displaySingleProfile(id) {
if (id.length === 64) {
document.getElementById("maincontent").replaceChildren(prepWindow("doki_id"))
waitForDokiReady(function () {
renderOneProfile(id)
})
}
}
function getProfileHtml(ident) {
deets = document.createElement("div")
deets.className = "content"
deets.appendChild(createElement("Account", ident.Account))
deets.appendChild(createElement("Name", ident.Name))
deets.appendChild(createElement("About", ident.About))
if (ident.UshBy.length > 0) {
deets.appendChild(createElement("Added to Identity Tree By:", ident.UshBy))
} else {
ush = createElement("This account is not in the Identity Tree", "If you believe the person who controls this account is human and does not have any other accounts, you can add them to the Identity Tree now.")
ushinner = document.createElement("div")
ushinner.className = "content"
ushinner.innerText = "By validating this account as a Unique Sovereign Human (adding this account to the Identity Tree), you declare that you\n 1. believe this account is owned and controlled by a human, and\n 2. you do not believe they have any other account(s)\n"
ushinner.appendChild(validateUSHButton(ident.Account))
ush.appendChild(ushinner)
deets.appendChild(ush)
}
if (ident.MaintainerBy.length > 0) {
deets.appendChild(createElement("Promoted to Maintainer by:", ident.MaintainerBy))
} else {
m = createElement("This account is not a Maintainer", "If you are a Maintainer, you can make this person a Maintainer too.")
minner = document.createElement("div")
minner.className = "content"
minner.innerText = "By making this Participant a Maintainer, you declare that you believe the Participant understands the spirit and the letter of the Stackerstan Superprotocolo, and you will remove them as a Maintainer if they ever demonstrate otherwise\n"
minner.appendChild(maintainerButton(ident.Account))
m.appendChild(minner)
deets.appendChild(m)
}
return deets
}
function maintainerButton(Account) {
btn = document.createElement("button")
btn.innerText = "Promote to Maintainer"
btn.onclick = function () {
if (!accountIsInMaintainerTree(storedPubkey)) {
alert("You must be in the Maintainer Tree to do this")
} else {
sendNewMaintainer(Account)
}
}
return btn
}
function sendNewMaintainer(targetAccount) {
sequence = 0
if (identityObjects.get(storedPubkey) !== undefined) {
sequence = identityObjects.get(storedPubkey).Sequence
}
sequence++
content = JSON.stringify({
target: targetAccount,
Maintainer: true,
sequence: sequence
})
sendEventToMindmachine(content, "", 640402).then(res => {
console.log(res)
location.reload()
})
}
function validateUSHButton(Account) {
btn = document.createElement("button")
btn.innerText = "Add to Identity Tree"
btn.onclick = function () {
if (!accountIsInIdentityTree(storedPubkey)) {
alert("You must be in the Identity Tree to add new people")
} else {
sendNewUshValidation(Account)
}
}
return btn
}
function sendNewUshValidation(targetAccount) {
sequence = 0
if (identityObjects.get(storedPubkey) !== undefined) {
sequence = identityObjects.get(storedPubkey).Sequence
}
sequence++
content = JSON.stringify({
target: targetAccount,
USH: true,
sequence: sequence
})
sendEventToMindmachine(content, "", 640402).then(res => {
console.log(res)
location.reload()
})
}
function accountIsInIdentityTree(account) {
ident = identityObjects.get(account)
if (ident !== undefined) {
if (ident.UshBy.length > 0) {
return true
}
}
return false
}
function accountIsInMaintainerTree(account) {
ident = identityObjects.get(account)
if (ident !== undefined) {
if (ident.MaintainerBy.length > 0) {
return true
}
}
return false
}
function myIdentity() {
ident = identityObjects.get(storedPubkey)
if (ident !== undefined) {
return ident
} else {
console.log("the account " + storedPubkey + " has not been registered in the Mindmachine state.")
return false
}
}