-
Notifications
You must be signed in to change notification settings - Fork 119
/
index.js
577 lines (554 loc) · 17 KB
/
index.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
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
import { createRoot } from "react-dom/client";
import { Provider } from "react-redux";
import { ConnectedRouter } from "connected-react-router";
import { Switch, Route } from "react-router-dom";
import { createMemoryHistory } from "history";
import { App } from "containers";
import configureStore from "./store/configureStore";
import locales from "./i18n/locales";
import "pi-ui/dist/index.css";
import "./style/main.css";
import pkg from "./package.json";
import {
DCR,
THEME,
LOCALE,
NETWORK,
PROPOSALS_MAX_PAGE_SIZE
} from "constants";
import * as cfgConstants from "constants/config";
import { wallet } from "wallet-preload-shim";
import {
defaultLightTheme,
ThemeProvider,
defaultDarkTheme,
DEFAULT_DARK_THEME_NAME,
DEFAULT_LIGHT_THEME_NAME
} from "pi-ui";
import { sharedTheme, lightTheme, darkTheme, icons } from "style/themes";
import SourceSansProLight from "style/fonts/SourceSansPro-Light.ttf";
import SourceSansProLightItalic from "style/fonts/SourceSansPro-LightItalic.ttf";
import SourceSansProRegular from "style/fonts/SourceSansPro-Regular.ttf";
import SourceSansProItalic from "style/fonts/SourceSansPro-Italic.ttf";
import SourceSansProSemiBold from "style/fonts/SourceSansPro-SemiBold.ttf";
import SourceSansProSemiBoldItalic from "style/fonts/SourceSansPro-SemiBoldItalic.ttf";
import SourceSansProBold from "style/fonts/SourceSansPro-Bold.ttf";
import SourceSansProBoldItalic from "style/fonts/SourceSansPro-BoldItalic.ttf";
import SourceCodeProRegular from "style/fonts/SourceCodePro-Regular.ttf";
import SourceCodeProBold from "style/fonts/SourceCodePro-Bold.ttf";
const { log, getCLIOptions, getHeightSynced } = wallet;
const globalCfg = wallet.getGlobalCfg();
const locale = globalCfg.get(LOCALE);
const cliOptions = getCLIOptions();
log("info", "Starting main react app");
const hasCliOption = (key) => cliOptions && cliOptions[key];
// Apply translated strings from custom translation file if it was loaded for
// this locale.
const customLocaleMsgs = wallet.getCustomTranslationMessages();
const currLocale = locales.find((value) => value.key === locale);
if (currLocale && customLocaleMsgs) {
currLocale.messages = customLocaleMsgs;
}
const currentSettings = {
locale: locale,
daemonStartAdvanced:
hasCliOption("daemonStartAdvanced") || wallet.getDaemonIsAdvanced(),
daemonStartAdvancedFromCli: !!hasCliOption("daemonStartAdvanced"),
allowedExternalRequests: globalCfg.get(
cfgConstants.ALLOWED_EXTERNAL_REQUESTS
),
proxyType: globalCfg.get(cfgConstants.PROXY_TYPE),
proxyLocation: globalCfg.get(cfgConstants.PROXY_LOCATION),
spvMode: hasCliOption("spvMode") || wallet.getIsSpv(),
spvModeFromCli: !!hasCliOption("spvMode"),
spvConnect:
hasCliOption("spvConnect") || globalCfg.get(cfgConstants.SPV_CONNECT),
spvConnectFromCli: !!hasCliOption("spvConnect"),
timezone: globalCfg.get(cfgConstants.TIMEZONE),
currencyDisplay: DCR,
network: hasCliOption("network") || globalCfg.get(NETWORK),
networkFromCli: !!hasCliOption("network"),
theme: globalCfg.get(THEME),
uiAnimations: globalCfg.get(cfgConstants.UI_ANIMATIONS),
autoWalletLaunching: globalCfg.get(cfgConstants.AUTO_WALLET_LAUNCHING)
};
const initialState = {
settings: {
currentSettings: currentSettings,
tempSettings: currentSettings,
settingsChanged: false,
needNetworkReset: false
},
vsp: {
availableVSPs: null,
availableVSPsError: null,
ticketAutoBuyerRunning: null,
rememberedVspHost: null,
processUnmanagedTicketsAttempt: false,
processUnmanagedTicketsError: null,
processManagedTicketsAttempt: false,
processManagedTicketsError: null,
trackedTickets: {},
needsProcessManagedTickets: true,
canDisableProcessManaged: true,
numVSPicketsToBuy: 1,
usedVSPs: []
},
daemon: {
networkMatch: false,
appVersion: pkg.version,
daemonRemote: false,
locale: locale,
tutorial: globalCfg.get(cfgConstants.SHOW_TUTORIAL),
visitedTutorialTabs: globalCfg.get(cfgConstants.VISITED_TUTORIAL_TABS),
showPrivacy: globalCfg.get(cfgConstants.SHOW_PRIVACY),
setLanguage: globalCfg.get(cfgConstants.SET_LANGUAGE),
showSpvChoice: globalCfg.get(cfgConstants.SHOW_SPV_CHOICE),
daemonStarted: false,
daemonSynced: getHeightSynced(),
daemonStopped: false,
daemonTimeout: false,
walletReady: false,
currentBlockCount: null,
timeLeftEstimate: null,
timeStart: 0,
blockStart: 0,
credentials: null,
appdata: null,
shutdownRequested: false,
remoteAppdataError: false,
previousWallet: null,
hiddenAccounts: Array(),
walletName: null,
neededBlocks: 0
},
version: {
// RequiredVersion
requiredVersion: "7.12.0",
versionInvalid: false,
versionInvalidError: null,
// VersionService
versionService: null,
getVersionServiceRequestAttempt: false,
getVersionServiceError: "",
// Balance
getWalletRPCVersionError: null,
getWalletRPCVersionRequestAttempt: false,
getWalletRPCVersionResponse: null
},
grpc: {
// WalletService
address: "127.0.0.1",
port: "9121",
walletService: null,
recentBlockTimestamp: null,
currentBlockHeight: 0,
// ints for mainnet and testnet protocol hex
// TestNet3 CurrencyNet = 0xb194aa75
testnet: 2979310197,
// MainNet CurrencyNet = 0xd9b400f9
mainnet: 3652452601,
// GetWalletService
getWalletServiceRequestAttempt: false,
getWalletServiceError: "",
// Balance
getBalanceError: null,
getBalanceRequestAttempt: false,
balances: Array(),
// AccountNumber
getAccountNumberError: null,
getAccountNumberRequestAttempt: false,
getAccountNumberResponse: null,
// Network
getNetworkError: null,
getNetworkRequestAttempt: false,
getNetworkResponse: null,
// StakeInfo
getStakeInfoError: null,
getStakeInfoRequestAttempt: false,
getStakeInfoResponse: null,
// TicketPrice
getTicketPriceError: null,
getTicketPriceRequestAttempt: false,
getTicketPriceResponse: null,
// SignMessage
getSignMessageError: null,
getSignMessageRequestAttempt: false,
getSignMessageSignature: null,
// VerifyMessage
getVerifyMessageError: null,
getVerifyMessageRequestAttempt: false,
getVerifyMessageResponse: null,
// Accounts
getAccountsError: null,
getAccountsRequestAttempt: false,
getAccountsResponse: null,
recentStakeTransactions: [],
// GetTransactions
// requestHeight of last getTransaction call
startRequestHeight: null,
// noMoreLiveTickets check if no more live tickets can be find.
noMoreLiveTickets: null,
// stakeTransactionsCancel checks if a stake transaction is canceled from
// getting more transactions.
stakeTransactionsCancel: false,
unminedTransactions: [],
// map representing each txs type
stakeTransactions: {},
regularTransactions: {},
// getRegularTxsAux is a state helper to get regular transactions
getRegularTxsAux: {
noMoreTransactions: false,
lastTransaction: null
},
// getRegularTxsAux is a state helper to get stake transactions
getStakeTxsAux: {
noMoreTransactions: false,
lastTransaction: null
},
transactionsFilter: {
search: null, // The freeform text in the Search box
listDirection: "desc", // asc = oldest -> newest, desc => newest -> oldest
types: [], // desired transaction types (code). All if blank. (mixed)
directions: [], // directions of desired transactions (sent/received/transfer/ticketfee)
maxAmount: null,
minAmount: null
},
getTransactionsRequestAttempt: false,
getTransactionsResponse: null,
ticketsFilter: {
listDirection: "desc", // asc = oldest -> newest, desc => newest -> oldest
status: null, // desired ticket status (code). All if blank.
vspFeeStatus: null // All if blank.
},
// Agenda/VoteChoices
allAgendas: [],
getAgendasResponse: null,
getVoteChoicesResponse: null,
// map from (reversed) transaction hash to fully decoded transaction
decodedTransactions: {},
// Map that stores the accounts that should be updated at future block
// heights, due to maturing stake transactions. Keys are the heights,
// values are arrays of account numbers.
maturingBlockHeights: {},
// Shown under governance tab
treasuryBalance: null
},
walletLoader: {
syncInput: false,
syncError: null,
syncAttemptRequest: null,
syncCall: null,
peerCount: 0,
rpcRetryAttempts: 0,
curBlocks: 0,
isWatchingOnly: false,
selectedWallet: null,
synced: false,
syncFetchHeadersComplete: false,
// Loader
getLoaderRequestAttempt: false,
loader: null,
getLoaderError: null,
showStakingWarning: true
},
notifications: {
transactionNtfns: null,
transactionNtfnsError: null,
accountNtfnsRequestAttempt: false,
accountNtfnsResponse: null
},
control: {
// ExtendedPubKey
getExtendedPubKeyAttempt: false,
getExtendedPubKeyResponse: null,
getExtendedPubKeyError: null,
// NextAddress
getNextAddressRequestAttempt: false,
getNextAddressResponse: null,
getNextAddressError: null,
// RenameAccount
renameAccountRequestAttempt: false,
renameAccountResponse: null,
renameAccountSuccess: null,
renameAccountError: null,
// Rescan
rescanRequestAttempt: false,
rescaneRequest: null,
rescanResponse: null,
rescanError: null,
rescanCall: null,
// NextAccount
getNextAccountRequestAttempt: false,
getNextAccountResponse: null,
getNextAccountSuccess: null,
getNextAccountError: null,
// ImportPrivateKey
importPrivateKeyRequestAttempt: false,
importPrivateKeyResponse: null,
importPrivateKeyError: null,
// ChangePassphrase
changePassphraseRequestAttempt: false,
changePassphraseResponse: null,
changePassphraseError: null,
changePassphraseSuccess: "",
// ChangePassphrase
loadActiveDataFiltersRequestAttempt: false,
loadActiveDataFiltersResponse: null,
loadActiveDataFiltersError: null,
// FundTransaction
fundTransactionRequestAttempt: false,
fundTransactionResponse: null,
fundTransactionError: null,
// SignTransaction
signTransactionRequestAttempt: false,
signTransactionRespsonse: null,
// PublishTransaction
publishTransactionRequestAttempt: false,
// PurchaseTicket
purchaseTicketsRequestAttempt: false,
purchaseTicketsResponse: null,
purchaseTicketsSuccess: "",
purchaseTicketsError: null,
// TicketBuyerService
ticketBuyerService: null,
// ConstructTransaction
constructTxRequestAttempt: false,
constructTxResponse: null,
// ValidateAddress
validateAddressRequestAttempt: false,
validateAddressResponse: null,
validateAddressError: null,
exportingData: false,
modalVisible: false,
aboutModalMacOSVisible: false,
cantCloseModalVisible: false,
changeScriptByAccount: {},
monitorLockableAccountsTimer: null,
confirmationDialogModalVisible: false,
settingAccountsPassphrase: false,
locaAccountError: null
},
snackbar: {
messages: Array()
},
sidebar: {
expandSideBar: true
},
statistics: {
dailyBalances: [],
fullDailyBalances: [],
voteTime: null,
getMyTicketsStatsRequest: false,
getStartupStatsAttempt: false,
startupStatsEndCalcTime: new Date(0),
ticketDataHeatmap: []
},
governance: {
getProposalsAttempt: false,
inventory: null,
proposals: {
abandonedVote: [],
activeVote: [],
approvedVote: [],
finishedVote: [],
preVote: [],
rejectedVote: []
},
proposalsDetails: {},
getProposalError: null,
proposallistpagesize: PROPOSALS_MAX_PAGE_SIZE
},
trezor: {
enabled: false,
debug: globalCfg.get(cfgConstants.TREZOR_DEBUG),
deviceList: null,
getDeviceListAttempt: false,
transportError: false,
device: null,
performingOperation: false,
waitingForPin: false,
waitingForPassPhrase: false,
waitingForWord: false,
performingRecoverDevice: false,
confirmingTogglePassphrase: false,
enablePassphraseProtection: false,
pinCallBack: null,
passPhraseCallBack: null,
pinMessage: null,
passPhraseMessage: null,
wordCallBack: null,
walletCreationMasterPubkeyAttempt: false,
pinProtection: undefined,
passphraseProtection: undefined,
passphraseOnDeviceProtection: undefined,
performingTogglePinProtection: false,
performingTogglePassphraseProtection: false,
performingTogglePassphraseOnDeviceProtection: false,
deviceLabel: undefined
},
ledger: {
enabled: false,
device: false,
walletCreationMasterPubkeyAttempt: false
},
ln: {
enabled: globalCfg.get(cfgConstants.LN_ENABLED),
active: false,
exists: false,
connectAttempt: false,
startAttempt: false,
info: {
version: null,
identityPubkey: null,
alias: null
},
walletBalances: {
totalBalance: 0,
confirmedBalance: 0,
unconfirmedBalance: 0
},
channelBalances: {
balance: 0,
pendingOpenBalance: 0,
maxInboundAmount: 0,
maxOutboundAmount: 0
},
channels: Array(),
pendingChannels: Array(),
closedChannels: Array(),
invoices: Array(),
payments: Array(),
outstandingPayments: {}, // map paymentHash => payment data
failedPayments: Array(),
addInvoiceAttempt: false,
cancelInvoiceAttempt: false,
sendPaymentAttempt: false,
scbPath: "",
scbUpdatedTime: 0,
nodeInfo: null,
getNodeInfoAttempt: false,
towersList: [],
invoiceFilter: {
search: null, // The freeform text in the Search box
listDirection: "desc", // asc = oldest -> newest, desc => newest -> oldest
type: null // desired invoice type (code).
},
paymentFilter: {
search: null, // The freeform text in the Search box
listDirection: "desc", // asc = oldest -> newest, desc => newest -> oldest
type: null // desired payment type (code).
},
channelFilter: {
search: null, // The freeform text in the Search box
type: null // desired channel type (code).
},
recentlyOpenedChannel: null,
describeGraph: Array(),
modifyAutopilotStatusAttempt: false,
getAutopilotStatusAttempt: false,
autopilotEnabled: false,
getTransactionsAttempt: false,
transactions: Array(),
lastDcrlndLogLine: "",
routerPruneTarget: 0,
routerPruneHeight: 0,
routerPruneStart: 0
},
dex: {
dexOrdersOpen: false,
loggedIn: false
},
locales: locales
};
const fonts = [
// Source Sans Pro
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProLight}) format("truetype")`,
"font-weight": defaultLightTheme["font-weight-light"]
},
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProLightItalic}) format("truetype")`,
"font-weight": defaultLightTheme["font-weight-light"],
"font-style": "italic"
},
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProRegular}) format("truetype")`
},
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProItalic}) format("truetype")`,
"font-style": "italic"
},
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProSemiBold}) format("truetype")`,
"font-weight": defaultLightTheme["font-weight-semi-bold"]
},
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProSemiBoldItalic}) format("truetype")`,
"font-weight": defaultLightTheme["font-weight-semi-bold"],
"font-style": "italic"
},
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProBold}) format("truetype")`,
"font-weight": defaultLightTheme["font-weight-bold"]
},
{
"font-family": "Source Sans Pro",
src: `url(${SourceSansProBoldItalic}) format("truetype")`,
"font-weight": defaultLightTheme["font-weight-bold"],
"font-style": "italic"
},
// SourceCodePro
{
"font-family": "Source Code Pro",
src: `url(${SourceCodeProRegular}) format("truetype")`
},
{
"font-family": "Source Code Pro",
src: `url(${SourceCodeProBold}) format("truetype")`,
"font-weight": defaultLightTheme["font-weight-bold"]
}
];
const themes = {
[DEFAULT_LIGHT_THEME_NAME]: {
...defaultLightTheme,
...sharedTheme,
...lightTheme,
...icons
},
[DEFAULT_DARK_THEME_NAME]: {
...defaultDarkTheme,
...sharedTheme,
...darkTheme,
...icons
}
};
const history = createMemoryHistory();
const store = configureStore(initialState, history);
const currentTheme = currentSettings && currentSettings.theme;
const defaultThemeName = currentTheme.includes("dark")
? DEFAULT_DARK_THEME_NAME
: DEFAULT_LIGHT_THEME_NAME;
const container = document.getElementById("root");
const root = createRoot(container);
root.render(
<ThemeProvider
themes={themes}
defaultThemeName={defaultThemeName}
fonts={fonts}>
<Provider store={store}>
<ConnectedRouter history={history}>
<Switch>
<Route path="/" component={App} />
</Switch>
</ConnectedRouter>
</Provider>
</ThemeProvider>
);