-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathApp.js
210 lines (194 loc) · 5.64 KB
/
App.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
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
import { useEffect, useState } from "react";
import {
isExtensionInstalled,
subscribeToSignature,
unsubscribeFromSignature,
requestAutoSignin,
requestAid,
requestCredential,
requestAidORCred,
trySettingVendorUrl,
canCallAsync,
} from "signify-polaris-web";
import Button from "@mui/material/Button";
import Alert from "@mui/material/Alert";
import CircularProgress from "@mui/material/CircularProgress";
import Box from "@mui/material/Box";
import "./App.css";
function CircularIndeterminate() {
return (
<Box sx={{ display: "flex" }}>
<CircularProgress />
</Box>
);
}
const ROOTSID_URL = "https://api.npoint.io/52639f849bb31823a8c0";
const PROVENANT_URL = "https://api.npoint.io/d59bd3ab0b31de863a20";
const FACEBOOK_URL = "https://api.npoint.io/1d388b8942c4ec3ed763";
const GITHUB_URL = "https://api.npoint.io/a75a0383d2820a2153c1";
function App() {
const [signifyData, setSignifyData] = useState();
const [extensionInstalled, setExtensionInstalled] = useState(null);
const [parsedSignifyData, setParsedSignifyData] = useState();
const fetchData = () => {
const data = localStorage.getItem("signify-data");
if (data) {
setSignifyData(data);
setParsedSignifyData(JSON.parse(data));
}
};
useEffect(() => {
fetchData();
}, []);
const handleSignifyData = (data) => {
localStorage.setItem("signify-data", JSON.stringify(data, null, 2));
fetchData();
};
useEffect(() => {
subscribeToSignature(handleSignifyData);
isExtensionInstalled((extensionId) => {
setExtensionInstalled(extensionId);
});
return () => {
unsubscribeFromSignature();
};
}, []);
const removeData = () => {
localStorage.removeItem("signify-data");
setSignifyData(null);
setParsedSignifyData(null);
};
const handleSettingVendorUrl = async (url) => {
trySettingVendorUrl(url);
};
const handleRequestAutoSignin = async () => {
console.log("canCallAsync()", canCallAsync());
if (canCallAsync()) {
const resp = await requestAutoSignin();
if (resp) {
handleSignifyData(resp);
}
} else {
requestAutoSignin();
}
};
const renderData = () => {
if (extensionInstalled === null) return <CircularIndeterminate />;
if (extensionInstalled)
return (
<>
<div
style={{ display: "flex", flexDirection: "column", rowGap: "8px" }}
>
<p className="auth-heading">Request Permissions</p>
<Button
variant="contained"
color="success"
onClick={() => handleSettingVendorUrl(PROVENANT_URL)}
>
Provenant Theme (has Agent)
</Button>
<Button
variant="contained"
color="success"
onClick={() => handleSettingVendorUrl(ROOTSID_URL)}
>
RootsID Theme
</Button>
<Button
variant="contained"
color="success"
onClick={() => handleSettingVendorUrl(FACEBOOK_URL)}
>
Facebook Theme
</Button>
<Button
variant="contained"
color="success"
onClick={() => handleSettingVendorUrl(GITHUB_URL)}
>
Github Theme (has Agent)
</Button>
</div>
<div className="auth-btn-container">
<p className="auth-heading">Authenticate with</p>
<Button variant="contained" color="success" onClick={requestAid}>
AID
</Button>
<Button
variant="contained"
color="success"
onClick={requestCredential}
>
Credential
</Button>
<Button
variant="contained"
color="success"
onClick={requestAidORCred}
>
AID or CRED
</Button>
<Button
variant="contained"
color="success"
onClick={handleRequestAutoSignin}
>
Auto Sign in
</Button>
</div>
</>
);
return (
<div className="auth-btn-container">
<Button
href="https://drive.google.com/drive/folders/1VmBAs3ba6qWT1I9y1Uk7hxvU_i-TKQTN?usp=sharing"
target="_blank"
size="md"
variant="contained"
>
Download Extension
</Button>
<Button
target="_blank"
href="https://www.loom.com/share/2b4208bf57de4eb89b0950865497a817?sid=faa098d8-4e8a-4938-9ba5-6f3780983d09"
size="md"
variant="contained"
>
See Video
</Button>
<Alert severity="warning">Reload tab after installation</Alert>
</div>
);
};
return (
<div className="App">
<header className="App-header">
{signifyData ? (
<div className="Welcome">
<div>
<h3>Welcome!</h3>
<label htmlFor="message">
Signed in with{" "}
{parsedSignifyData?.credential ? "Credential" : "AID"}
</label>
<textarea
id="message"
rows="16"
defaultValue={signifyData}
className="signify-data"
placeholder="Write your thoughts here..."
></textarea>
</div>
<Button variant="contained" color="error" onClick={removeData}>
Logout
</Button>
</div>
) : (
renderData()
)}
</header>
</div>
);
}
export default App;