-
Notifications
You must be signed in to change notification settings - Fork 4
/
enter-oobis.jsx
153 lines (145 loc) · 4.97 KB
/
enter-oobis.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
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
import m from 'mithril';
import { Button, Card, IconButton, TextField } from '../../../../../src/app/components';
import { KERI, Profile } from '../../../../../src/app/services';
/*
* EnterOOBIsForm
*
* attrs
* identifiers - an array of agent identifiers
*/
class EnterOOBIsForm {
constructor(vnode) {
this.complete = false;
this.aliasToSign = Profile.getDefaultSingleAID().name;
}
resolveOOBIPromise(oobi) {
return KERI.resolveOOBI(this.aliasToSign, oobi.alias, oobi.url);
}
resolveAllOOBIs(vnode) {
let promises = vnode.attrs.participants.oobis
.filter((oobi) => {
return oobi.alias && oobi.url;
})
.map((oobi) => {
oobi.status = 'started';
return this.resolveOOBIPromise(oobi);
});
return Promise.all(promises)
.then(() => {
this.ensureOOBIsResolved(vnode.attrs.participants.oobis).then(() => {
vnode.attrs.participants.oobis.filter((oobi) => {
return oobi.alias && oobi.url;
});
});
})
.catch((err) => {
console.log('resolveAllOOBIs', err);
});
}
ensureOOBIsResolved(oobis) {
let aliases = oobis.map((oobi) => {
return oobi.alias;
});
return new Promise(function (resolve, reject) {
setTimeout(function waitForOOBI() {
KERI.getContactsByAliases(aliases)
.then((contacts) => {
let done = oobis.every((oobi) => {
return contacts.some((contact) => {
if (contact.alias === oobi.alias) {
oobi.status = 'resolved';
oobi.id = contact.id;
return true;
}
return false;
});
});
if (done) return resolve();
setTimeout(waitForOOBI, 700);
})
.catch((err) => {
reject();
console.log('getContacts', err);
});
}, 700);
});
}
view(vnode) {
return (
<>
<div style={{ maxHeight: '512px', overflowY: 'auto', margin: '0 0 1rem 0', paddingRight: '1rem' }}>
<div class="flex flex-justify-between" style={{ alignItems: 'baseline' }}>
<p class="p-tag" style={{ margin: '2rem 0 2rem 0' }}>
While on the Video Call make sure to obtain {vnode.attrs.oneToOne ? `the other` : `each`} participant's{' '}
<b>URL</b> and give them an Alias that makes sense to you:
</p>
</div>
{vnode.attrs.participants.oobis.map((oobi) => {
return (
<Card class="card--fluid" style={{ margin: '0 0 1.5rem 0' }}>
{!vnode.attrs.oneToOne && (
<IconButton
class="close-icon"
icon="close"
onclick={() => {
vnode.attrs.participants.oobis.splice(vnode.attrs.participants.oobis.indexOf(oobi), 1);
}}
/>
)}
<div className="flex flex-align-center">
<h5 style={{ minWidth: '100px' }}>Status:</h5>
{oobi.status === 'none' && <p className="font-color--battleship font-weight--medium">Not Started</p>}
{oobi.status === 'started' && <p className="font-color--blue font-weight--medium">In Progress</p>}
{oobi.status === 'resolved' && <p className="font-color--green font-weight--medium">Complete!</p>}
</div>
<h5 style={{ margin: '1rem 0 .5rem' }}>Alias:</h5>
<TextField
outlined
fluid
style={{ backgroundColor: 'rgba(0, 0, 0, 0.04)', height: '44px' }}
value={oobi.alias}
oninput={(e) => {
oobi.alias = e.target.value;
}}
/>
<h5 style={{ margin: '1rem 0 .5rem' }}>OOBI URL:</h5>
<TextField
textarea
outlined
fluid
style={{ backgroundColor: 'rgba(0, 0, 0, 0.04)' }}
value={oobi.url}
oninput={(e) => {
oobi.url = e.target.value;
}}
/>
</Card>
);
})}
</div>
<div class={`flex ${vnode.attrs.oneToOne ? ' flex-justify-end' : ' flex-justify-between'}`}>
{!vnode.attrs.oneToOne && (
<Button
raised
class="button--no-transform button--gray"
label="Add Another"
iconLeading="add"
onclick={() => {
vnode.attrs.participants.addOOBI('', '');
}}
/>
)}
<Button
raised
class="button--no-transform"
label="Resolve OOBIs"
onclick={() => {
this.resolveAllOOBIs(vnode);
}}
/>
</div>
</>
);
}
}
module.exports = EnterOOBIsForm;