-
Notifications
You must be signed in to change notification settings - Fork 569
/
App.jsx
651 lines (590 loc) · 23.2 KB
/
App.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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
import React from "react";
import {ChainStore} from "bitsharesjs";
import AccountStore from "stores/AccountStore";
import NotificationStore from "stores/NotificationStore";
import {withRouter} from "react-router-dom";
import SyncError from "./components/SyncError";
import LoadingIndicator from "./components/LoadingIndicator";
import BrowserNotifications from "./components/BrowserNotifications/BrowserNotificationsContainer";
import Header from "components/Layout/Header";
import ReactTooltip from "react-tooltip";
import NotificationSystem from "react-notification-system";
import TransactionConfirm from "./components/Blockchain/TransactionConfirm";
import WalletUnlockModal from "./components/Wallet/WalletUnlockModal";
import BrowserSupportModal from "./components/Modal/BrowserSupportModal";
import Footer from "./components/Layout/Footer";
import Deprecate from "./Deprecate";
import Incognito from "./components/Layout/Incognito";
import {isIncognito} from "feature_detect";
import {updateGatewayBackers} from "common/gatewayUtils";
import titleUtils from "common/titleUtils";
import {BodyClassName, Notification} from "bitshares-ui-style-guide";
import {DEFAULT_NOTIFICATION_DURATION} from "services/Notification";
import Loadable from "react-loadable";
import NewsHeadline from "components/Layout/NewsHeadline";
import {Route, Switch, Redirect} from "react-router-dom";
// Nested route components
import Page404 from "./components/Page404/Page404";
const Invoice = Loadable({
loader: () =>
import(/* webpackChunkName: "exchange" */ "./components/Transfer/Invoice"),
loading: LoadingIndicator
});
const Exchange = Loadable({
loader: () =>
import(/* webpackChunkName: "exchange" */ "./components/Exchange/ExchangeContainer"),
loading: LoadingIndicator
});
const Explorer = Loadable({
loader: () =>
import(/* webpackChunkName: "explorer" */ "./components/Explorer/Explorer"),
loading: LoadingIndicator
});
const PredictionMarketsPage = Loadable({
loader: () =>
import(/* webpackChunkName: "pm" */ "./components/PredictionMarkets/PMAssetsContainer"),
loading: LoadingIndicator
});
const AccountPage = Loadable({
loader: () =>
import(/* webpackChunkName: "account" */ "./components/Account/AccountPage"),
loading: LoadingIndicator
});
const AccountDepositWithdraw = Loadable({
loader: () =>
import(/* webpackChunkName: "deposit-withdraw" */ "./components/Account/AccountDepositWithdraw"),
loading: LoadingIndicator
});
const News = Loadable({
loader: () => import(/* webpackChunkName: "news" */ "./components/News"),
loading: LoadingIndicator
});
const Settings = Loadable({
loader: () =>
import(/* webpackChunkName: "settings" */ "./components/Settings/SettingsContainer"),
loading: LoadingIndicator
});
const Help = Loadable({
loader: () => import(/* webpackChunkName: "help" */ "./components/Help"),
loading: LoadingIndicator
});
const Asset = Loadable({
loader: () =>
import(/* webpackChunkName: "asset" */ "./components/Blockchain/Asset"),
loading: LoadingIndicator
});
const Block = Loadable({
loader: () =>
import(/* webpackChunkName: "block" */ "./components/Blockchain/BlockContainer"),
loading: LoadingIndicator
});
const DashboardAccountsOnly = Loadable({
loader: () =>
import(/* webpackChunkName: "dashboard-accounts" */ "./components/Dashboard/DashboardAccountsOnly"),
loading: LoadingIndicator
});
const DashboardPage = Loadable({
loader: () =>
import(/* webpackChunkName: "dashboard" */ "./components/Dashboard/DashboardPage"),
loading: LoadingIndicator
});
const WalletManager = Loadable({
loader: () =>
import(/* webpackChunkName: "wallet" */ "./components/Wallet/WalletManager"),
loading: LoadingIndicator
});
const ExistingAccount = Loadable({
loader: () =>
import(/* webpackChunkName: "existing-account" */ "./components/Wallet/ExistingAccount"),
loading: LoadingIndicator
});
const CreateWorker = Loadable({
loader: () =>
import(/* webpackChunkName: "create-worker" */ "./components/Account/CreateWorker"),
loading: LoadingIndicator
});
const Barter = Loadable({
loader: () =>
import(/* webpackChunkName: "settings" */ "./components/Showcases/Barter"),
loading: LoadingIndicator
});
const Borrow = Loadable({
loader: () =>
import(/* webpackChunkName: "settings" */ "./components/Showcases/Borrow"),
loading: LoadingIndicator
});
const Htlc = Loadable({
loader: () =>
import(/* webpackChunkName: "settings" */ "./components/Showcases/Htlc"),
loading: LoadingIndicator
});
const DirectDebit = Loadable({
loader: () =>
import(/* webpackChunkName: "settings" */ "./components/Showcases/DirectDebit"),
loading: LoadingIndicator
});
const QuickTrade = Loadable({
loader: () =>
import(/* webpackChunkName: "QuickTrade" */ "./components/QuickTrade/QuickTradeRouter"),
loading: LoadingIndicator
});
import LoginSelector from "./components/LoginSelector";
import Login from "./components/Login/Login";
import RegistrationSelector from "./components/Registration/RegistrationSelector";
import WalletRegistration from "./components/Registration/WalletRegistration";
import AccountRegistration from "./components/Registration/AccountRegistration";
import {CreateWalletFromBrainkey} from "./components/Wallet/WalletCreate";
import ShowcaseGrid from "./components/Showcases/ShowcaseGrid";
import PriceAlertNotifications from "./components/PriceAlertNotifications";
import GatewaySelectorModal from "./components/Gateways/GatewaySelectorModal";
import SettingsStore from "./stores/SettingsStore";
class App extends React.Component {
constructor() {
super();
let syncFail =
ChainStore.subError &&
ChainStore.subError.message ===
"ChainStore sync error, please check your system clock"
? true
: false;
this.state = {
isBrowserSupportModalVisible: false,
isGatewaySelectorModalVisible: false,
loading: false,
synced: this._syncStatus(),
syncFail,
incognito: false,
incognitoWarningDismissed: false,
height: window && window.innerHeight
};
this._rebuildTooltips = this._rebuildTooltips.bind(this);
this._chainStoreSub = this._chainStoreSub.bind(this);
this._syncStatus = this._syncStatus.bind(this);
this._getWindowHeight = this._getWindowHeight.bind(this);
this.showBrowserSupportModal = this.showBrowserSupportModal.bind(this);
this.hideBrowserSupportModal = this.hideBrowserSupportModal.bind(this);
this.hideGatewaySelectorModal = this.hideGatewaySelectorModal.bind(
this
);
Notification.config({
duration: DEFAULT_NOTIFICATION_DURATION,
top: 90
});
}
componentWillUnmount() {
window.removeEventListener("resize", this._getWindowHeight);
NotificationStore.unlisten(this._onNotificationChange);
ChainStore.unsubscribe(this._chainStoreSub);
clearInterval(this.syncCheckInterval);
}
/**
* Returns the current blocktime, or exception if not yet available
* @returns {Date}
*/
getBlockTime() {
let dynGlobalObject = ChainStore.getObject("2.1.0");
if (dynGlobalObject) {
let block_time = dynGlobalObject.get("time");
if (!/Z$/.test(block_time)) {
block_time += "Z";
}
return new Date(block_time);
} else {
throw new Error("Blocktime not available right now");
}
}
/**
* Returns the delta between the current time and the block time in seconds, or -1 if block time not available yet
*
* Note: Could be integrating properly with BlockchainStore to send out updates, but not necessary atp
*/
getBlockTimeDelta() {
try {
let bt =
(this.getBlockTime().getTime() +
ChainStore.getEstimatedChainTimeOffset()) /
1000;
let now = new Date().getTime() / 1000;
return Math.abs(now - bt);
} catch (err) {
return -1;
}
}
hideBrowserSupportModal() {
this.setState({
isBrowserSupportModalVisible: false
});
}
hideGatewaySelectorModal() {
this.setState({
isGatewaySelectorModalVisible: false
});
}
showBrowserSupportModal() {
this.setState({
isBrowserSupportModalVisible: true
});
}
_syncStatus(setState = false) {
let synced = this.getBlockTimeDelta() < 5;
if (setState && synced !== this.state.synced) {
this.setState({synced});
}
return synced;
}
_setListeners() {
try {
window.addEventListener("resize", this._getWindowHeight, {
capture: false,
passive: true
});
NotificationStore.listen(this._onNotificationChange.bind(this));
ChainStore.subscribe(this._chainStoreSub);
AccountStore.tryToSetCurrentAccount();
} catch (e) {
console.error("e:", e);
}
}
componentDidMount() {
this._setListeners();
this.syncCheckInterval = setInterval(
this._syncStatus.bind(this, true),
5000
);
const user_agent = navigator.userAgent.toLowerCase();
if (
!(
window.electron ||
user_agent.indexOf("firefox") > -1 ||
user_agent.indexOf("chrome") > -1 ||
user_agent.indexOf("edge") > -1
)
) {
this.showBrowserSupportModal();
}
this.props.history.listen(this._rebuildTooltips);
this._rebuildTooltips();
isIncognito(
function(incognito) {
this.setState({incognito});
}.bind(this)
);
this._ensureExternalServices();
}
_ensureExternalServices() {
setTimeout(() => {
let hasLoggedIn =
AccountStore.getState().myActiveAccounts.length > 0 ||
!!AccountStore.getState().passwordAccount;
if (!hasLoggedIn) {
this._ensureExternalServices();
} else {
this._checkExternalServices();
}
}, 5000);
}
_checkExternalServices() {
if (
SettingsStore.getState().viewSettings.get(
"hasSeenExternalServices",
false
)
) {
updateGatewayBackers();
} else {
this.setState({
isGatewaySelectorModalVisible: true
});
}
}
componentDidUpdate(prevProps) {
if (this.props.location !== prevProps.location) {
this.onRouteChanged();
}
}
onRouteChanged() {
document.title = titleUtils.GetTitleByPath(
this.props.location.pathname
);
}
_onIgnoreIncognitoWarning() {
this.setState({incognitoWarningDismissed: true});
}
_rebuildTooltips() {
if (this.rebuildTimeout) return;
ReactTooltip.hide();
this.rebuildTimeout = setTimeout(() => {
if (this.refs.tooltip) {
this.refs.tooltip.globalRebuild();
}
this.rebuildTimeout = null;
}, 1500);
}
_chainStoreSub() {
let synced = this._syncStatus();
if (synced !== this.state.synced) {
this.setState({synced});
}
if (
ChainStore.subscribed !== this.state.synced ||
ChainStore.subError
) {
let syncFail =
ChainStore.subError &&
ChainStore.subError.message ===
"ChainStore sync error, please check your system clock"
? true
: false;
this.setState({
syncFail
});
}
}
/** Usage: NotificationActions.[success,error,warning,info] */
_onNotificationChange() {
let notification = NotificationStore.getState().notification;
if (notification.autoDismiss === void 0) {
notification.autoDismiss = 10;
}
if (this.refs.notificationSystem)
this.refs.notificationSystem.addNotification(notification);
}
_getWindowHeight() {
this.setState({height: window && window.innerHeight});
}
// /** Non-static, used by passing notificationSystem via react Component refs */
// _addNotification(params) {
// console.log("add notification:", this.refs, params);
// this.refs.notificationSystem.addNotification(params);
// }
render() {
let {incognito, incognitoWarningDismissed} = this.state;
let {walletMode, theme, location, match, ...others} = this.props;
let content = null;
if (this.state.syncFail) {
content = <SyncError />;
} else if (this.state.loading) {
content = (
<div className="grid-frame vertical">
<LoadingIndicator
loadingText={"Connecting to APIs and starting app"}
/>
</div>
);
} else if (__DEPRECATED__) {
content = <Deprecate {...this.props} />;
} else {
let accountName =
AccountStore.getState().currentAccount ||
AccountStore.getState().passwordAccount;
accountName =
accountName && accountName !== "null"
? accountName
: "committee-account";
content = (
<div className="grid-frame vertical">
<NewsHeadline />
<Header height={this.state.height} {...others} />
<div id="mainContainer" className="grid-block">
<div className="grid-block vertical">
<Switch>
<Route
path="/"
exact
component={DashboardPage}
/>
<Route
path="/account/:account_name"
component={AccountPage}
/>
<Route
path="/accounts"
component={DashboardAccountsOnly}
/>
<Route
path="/market/:marketID"
component={Exchange}
/>
<Route
path="/settings/:tab"
component={Settings}
/>
<Route path="/settings" component={Settings} />
<Route
path="/invoice/:data"
component={Invoice}
/>
<Route
path="/deposit-withdraw"
exact
component={AccountDepositWithdraw}
/>
<Route
path="/create-account"
component={LoginSelector}
/>
<Route path="/login" component={Login} />
<Route
path="/registration"
exact
component={RegistrationSelector}
/>
<Route
path="/registration/local"
exact
component={WalletRegistration}
/>
<Route
path="/registration/cloud"
exact
component={AccountRegistration}
/>
<Route path="/news" exact component={News} />
<Redirect
path={"/voting"}
to={{
pathname: `/account/${accountName}/voting`
}}
/>
{/* Explorer routes */}
<Route
path="/explorer/:tab"
component={Explorer}
/>
<Route path="/explorer" component={Explorer} />
<Route
path="/asset/:symbol"
component={Asset}
/>
<Route
exact
path="/block/:height"
component={Block}
/>
<Route
exact
path="/block/:height/:txIndex"
component={Block}
/>
<Route path="/borrow" component={Borrow} />
<Route path="/barter" component={Barter} />
<Route
path="/direct-debit"
component={DirectDebit}
/>
<Route
path="/spotlight"
component={ShowcaseGrid}
/>
{/* Wallet backup/restore routes */}
<Route
path="/wallet"
component={WalletManager}
/>
<Route
path="/create-wallet-brainkey"
component={CreateWalletFromBrainkey}
/>
<Route
path="/existing-account"
component={ExistingAccount}
/>
<Route
path="/create-worker"
component={CreateWorker}
/>
{/* Help routes */}
<Route exact path="/help" component={Help} />
<Route
exact
path="/help/:path1"
component={Help}
/>
<Route
exact
path="/help/:path1/:path2"
component={Help}
/>
<Route
exact
path="/help/:path1/:path2/:path3"
component={Help}
/>
<Route path="/htlc" component={Htlc} />
<Route
path="/prediction"
component={PredictionMarketsPage}
/>
<Route
exact
path="/quick-trade"
component={QuickTrade}
/>
<Route
exact
path="/quick-trade/:marketID"
component={QuickTrade}
/>
<Route path="*" component={Page404} />
</Switch>
</div>
</div>
<Footer
synced={this.state.synced}
history={this.props.history}
/>
<ReactTooltip
ref="tooltip"
place="top"
type={theme === "lightTheme" ? "dark" : "light"}
effect="solid"
/>
</div>
);
}
return (
<div
style={{backgroundColor: !theme ? "#2a2a2a" : null}}
className={theme}
>
<BodyClassName className={theme}>
{walletMode && incognito && !incognitoWarningDismissed ? (
<Incognito
onClickIgnore={this._onIgnoreIncognitoWarning.bind(
this
)}
/>
) : null}
<div id="content-wrapper">
{content}
<NotificationSystem
ref="notificationSystem"
allowHTML={true}
style={{
Containers: {
DefaultStyle: {
width: "425px"
}
}
}}
/>
<TransactionConfirm />
<BrowserNotifications />
<PriceAlertNotifications />
<WalletUnlockModal />
<BrowserSupportModal
visible={this.state.isBrowserSupportModalVisible}
hideModal={this.hideBrowserSupportModal}
showModal={this.showBrowserSupportModal}
/>
<GatewaySelectorModal
visible={this.state.isGatewaySelectorModalVisible}
hideModal={this.hideGatewaySelectorModal}
/>
</div>
</BodyClassName>
</div>
);
}
}
export default withRouter(App);