/
LoadingScreen.tsx
310 lines (278 loc) · 9.64 KB
/
LoadingScreen.tsx
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
/* eslint-disable max-classes-per-file */
import React, { Component } from "react";
import { ChildProcessWithoutNullStreams } from "child_process";
import routes from "../constants/routes.json";
import { RPCConfig, Info } from "./AppState";
import RPC from "../rpc";
import cstyles from "./Common.module.css";
import styles from "./LoadingScreen.module.css";
import Logo from "../assets/img/logobig.png";
import zcashdlogo from "../assets/img/zcashdlogo.gif";
import { Navigate } from "react-router-dom";
type Props = {
setRPCConfig: (rpcConfig?: RPCConfig) => void;
setInfo: (info: Info) => void;
};
class LoadingScreenState {
creatingZcashConf: boolean;
connectOverTor: boolean;
enableFastSync: boolean;
currentStatus: string | React.ReactElement;
loadingDone: boolean;
rpcConfig?: RPCConfig;
zcashdSpawned: number;
getinfoRetryCount: number;
constructor() {
this.currentStatus = "Loading...";
this.creatingZcashConf = false;
this.loadingDone = false;
this.zcashdSpawned = 0;
this.getinfoRetryCount = 0;
this.rpcConfig = undefined;
this.connectOverTor = false;
this.enableFastSync = true;
}
}
class LoadingScreen extends Component<Props, LoadingScreenState> {
constructor(props: Props) {
super(props);
this.state = new LoadingScreenState();
}
componentDidMount() {
(async () => {
await this.loadZcashConf(true);
})();
}
async loadZcashConf(createIfMissing: boolean) {
// Load the RPC config from zcash.conf file
const rpcConfig = await window.zecwallet.rpcconfig();
if (!rpcConfig.username || !rpcConfig.password) {
this.setState({
currentStatus: (
<div>
<p>
Your zcash.conf is missing a "rpcuser" or
"rpcpassword".
</p>
<p>
Please add a "rpcuser=some_username" and
"rpcpassword=some_password" to your zcash.conf to enable
RPC access
</p>
{/* <p>Your zcash.conf is located at {zcashLocation}</p> */}
</div>
),
});
return;
}
this.setState({ rpcConfig });
// And setup the next getinfo
this.setupNextGetInfo();
}
zcashd: ChildProcessWithoutNullStreams | null = null;
setupNextGetInfo() {
setTimeout(() => this.getInfo(), 1000);
}
async getInfo() {
const { rpcConfig, zcashdSpawned, getinfoRetryCount } = this.state;
// Try getting the info.
try {
const info = await RPC.getInfoObject(rpcConfig);
console.log(info);
const { setRPCConfig, setInfo } = this.props;
setRPCConfig(rpcConfig);
setInfo(info);
// This will cause a redirect to the dashboard
this.setState({ loadingDone: true });
} catch (err) {
// Not yet finished loading. So update the state, and setup the next refresh
const errString: string = (err as any).toString();
const noConnection = errString.indexOf("NO_CONNECTION") > 0;
if (noConnection) {
// Try to start zcashd
// this.startZcashd();
// this.setupNextGetInfo();
console.log("Cannot start zcashd because it is not supported yet");
this.setState({
currentStatus: (
<div>
{errString}
<br />
Please make sure zcashd is running.
</div>
),
});
}
if (errString.indexOf('"code":-28') > 0) {
this.setState({ currentStatus: "Waiting for zcashd to start..." });
const inc = getinfoRetryCount + 1;
this.setState({ getinfoRetryCount: inc });
} else if (errString.indexOf('"code":-8') > 0) {
this.setState({
currentStatus:
"No accounts. Please run 'zcashd-wallet-tool' to create your wallet first...",
});
} else {
// Generic error.
this.setState({ currentStatus: errString });
}
if (noConnection && zcashdSpawned && getinfoRetryCount >= 10) {
// Give up
this.setState({
currentStatus: (
<span>
Failed to start zcashd. Giving up! Please look at the debug.log
file.
<br />
{/* <span
className={cstyles.highlight}
>{`${locateZcashConfDir()}/debug.log`}</span> */}
<br />
Please file an issue with Zecwallet
</span>
),
});
}
if (!noConnection) {
this.setupNextGetInfo();
}
}
}
handleEnableFastSync = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ enableFastSync: event.target.checked });
};
handleTorEnabled = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ connectOverTor: event.target.checked });
};
render() {
const {
loadingDone,
currentStatus,
creatingZcashConf,
connectOverTor,
enableFastSync,
} = this.state;
// If still loading, show the status, else go to dashboard
if (loadingDone) {
return <Navigate to={routes.DASHBOARD} />;
} else {
return (
<div className={[cstyles.center, styles.loadingcontainer].join(" ")}>
{!creatingZcashConf && (
<div className={cstyles.verticalflex}>
<div style={{ marginTop: "100px" }}>
<img src={Logo} width="200px;" alt="Logo" />
</div>
<div>{currentStatus}</div>
<div></div>
</div>
)}
{creatingZcashConf && (
<div>
<div className={cstyles.verticalflex}>
<div
className={[
cstyles.verticalflex,
cstyles.center,
cstyles.margintoplarge,
cstyles.highlight,
].join(" ")}
>
<div className={[cstyles.xlarge].join(" ")}>
{" "}
Welcome To Zecwallet Fullnode!
</div>
</div>
<div
className={[cstyles.center, cstyles.margintoplarge].join(" ")}
>
<img src={zcashdlogo} width="400px" alt="zcashdlogo" />
</div>
<div
className={[
cstyles.verticalflex,
cstyles.center,
cstyles.margintoplarge,
].join(" ")}
style={{ width: "75%", marginLeft: "15%" }}
>
<div>
Zecwallet Fullnode will download the{" "}
<span className={cstyles.highlight}>
entire Zcash Blockchain (~28GB)
</span>
, which might take several days to sync. If you want to get
started immediately, please consider{" "}
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a
className={cstyles.highlight}
style={{ textDecoration: "underline" }}
role="link"
onClick={() =>
window.zecwallet.openLink("https://www.zecwallet.co")
}
>
Zecwallet Lite
</a>
, which can get you started in under a minute.
</div>
</div>
<div
className={cstyles.left}
style={{ width: "75%", marginLeft: "15%" }}
>
<div className={cstyles.margintoplarge} />
<div className={[cstyles.verticalflex].join(" ")}>
<div>
<input
type="checkbox"
onChange={this.handleTorEnabled}
defaultChecked={connectOverTor}
/>
Connect over Tor
</div>
<div className={cstyles.sublight}>
Will connect over Tor. Please make sure you have the Tor
client installed and listening on port 9050.
</div>
</div>
<div className={cstyles.margintoplarge} />
<div className={[cstyles.verticalflex].join(" ")}>
<div>
<input
type="checkbox"
onChange={this.handleEnableFastSync}
defaultChecked={enableFastSync}
/>
Enable Fast Sync
</div>
<div className={cstyles.sublight}>
When enabled, Zecwallet will skip some expensive
verifications of the zcashd blockchain when downloading.
This option is safe to use if you are creating a brand new
wallet.
</div>
</div>
</div>
<div className={cstyles.buttoncontainer}>
<button
type="button"
className={cstyles.primarybutton}
onClick={() =>
console.log(
"Cannot create zcash conf because it is not supported yet"
)
}
>
Start Zcash
</button>
</div>
</div>
</div>
)}
</div>
);
}
}
}
export default LoadingScreen;