-
Notifications
You must be signed in to change notification settings - Fork 295
/
SyncingConnectingStatus.tsx
214 lines (203 loc) · 7.12 KB
/
SyncingConnectingStatus.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
// @flow
import React, { Component } from 'react';
import { defineMessages, intlShape, FormattedHTMLMessage } from 'react-intl';
import classNames from 'classnames';
import styles from './SyncingConnectingStatus.scss';
import { CardanoNodeStates } from '../../../../../common/types/cardano-node.types';
import type { CardanoNodeState } from '../../../../../common/types/cardano-node.types';
const messages = defineMessages({
starting: {
id: 'loading.screen.startingCardanoMessage',
defaultMessage: '!!!Starting Cardano node',
description: 'Message "Starting Cardano node" on the loading screen.',
},
startingDescription: {
id: 'loading.screen.startingCardanoDescription',
defaultMessage:
'!!!This process validates the integrity of local blockchain data.',
description: 'Message "Starting Cardano node" on the loading screen.',
},
stopping: {
id: 'loading.screen.stoppingCardanoMessage',
defaultMessage: '!!!Stopping Cardano node',
description: 'Message "Stopping Cardano node" on the loading screen.',
},
stoppingDescription: {
id: 'loading.screen.stoppingCardanoDescription',
defaultMessage:
'!!!This process updates the databases and could take several minutes.<br />To preserve data integrity, please wait until this process is complete.',
description: 'Message "Stopping Cardano node" on the loading screen.',
},
stopped: {
id: 'loading.screen.stoppedCardanoMessage',
defaultMessage: '!!!Cardano node stopped',
description: 'Message "Cardano node stopped" on the loading screen.',
},
updating: {
id: 'loading.screen.updatingCardanoMessage',
defaultMessage: '!!!Updating Cardano node',
description: 'Message "Updating Cardano node" on the loading screen.',
},
updated: {
id: 'loading.screen.updatedCardanoMessage',
defaultMessage: '!!!Cardano node updated',
description: 'Message "Cardano node updated" on the loading screen.',
},
crashed: {
id: 'loading.screen.crashedCardanoMessage',
defaultMessage: '!!!Cardano node crashed',
description: 'Message "Cardano node crashed" on the loading screen.',
},
unrecoverable: {
id: 'loading.screen.unrecoverableCardanoMessage',
defaultMessage:
'!!!Unable to start Cardano node. Please submit a support request.',
description:
'Message "Unable to start Cardano node. Please submit a support request." on the loading screen.',
},
connecting: {
id: 'loading.screen.connectingToNetworkMessage',
defaultMessage: '!!!Connecting to network',
description: 'Message "Connecting to network" on the loading screen.',
},
reconnecting: {
id: 'loading.screen.reconnectingToNetworkMessage',
defaultMessage: '!!!Network connection lost - reconnecting',
description:
'Message "Network connection lost - reconnecting" on the loading screen.',
},
loadingWalletData: {
id: 'loading.screen.loadingWalletData',
defaultMessage: '!!!Loading wallet data',
description: 'Message "Loading wallet data" on the loading screen.',
},
tlsCertificateNotValidError: {
id: 'loading.screen.errors.tlsCertificateNotValidPleaseRestartError',
defaultMessage: '!!!TLS certificate is not valid, please restart Daedalus.',
description: 'The TLS cert is not valid and Daedalus should be restarted',
},
verifyingBlockchain: {
id: 'loading.screen.verifyingBlockchainMessage',
defaultMessage:
'!!!Cardano node is currently syncing. This process can take several hours',
description:
'Message on the loading screen informing that sync process could be very long',
},
});
type Props = {
cardanoNodeState: ?CardanoNodeState,
verificationProgress: number,
hasLoadedCurrentLocale: boolean,
hasBeenConnected: boolean,
isTlsCertInvalid: boolean,
isConnected: boolean,
isNodeStopping: boolean,
isNodeStopped: boolean,
isVerifyingBlockchain: boolean,
};
export default class SyncingConnectingStatus extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
_getConnectingMessage = (): {
connectingMessage: string,
connectingDescription?: string,
} => {
const {
cardanoNodeState,
hasBeenConnected,
isVerifyingBlockchain,
isTlsCertInvalid,
isConnected,
} = this.props;
let connectingMessage;
if (isConnected) {
connectingMessage = messages.loadingWalletData;
return { connectingMessage };
}
let connectingDescription;
switch (cardanoNodeState) {
case null:
case CardanoNodeStates.STARTING:
connectingMessage = messages.starting;
connectingDescription = messages.startingDescription;
break;
case CardanoNodeStates.STOPPING:
case CardanoNodeStates.EXITING:
connectingMessage = messages.stopping;
connectingDescription = messages.stoppingDescription;
break;
case CardanoNodeStates.STOPPED:
connectingMessage = messages.stopped;
break;
case CardanoNodeStates.UPDATING:
connectingMessage = messages.updating;
break;
case CardanoNodeStates.UPDATED:
connectingMessage = messages.updated;
break;
case CardanoNodeStates.CRASHED:
case CardanoNodeStates.ERRORED:
connectingMessage = messages.crashed;
break;
case CardanoNodeStates.UNRECOVERABLE:
connectingMessage = messages.unrecoverable;
break;
default:
// also covers CardanoNodeStates.RUNNING state
connectingMessage = hasBeenConnected
? messages.reconnecting
: messages.connecting;
}
const isConnectingMessage =
connectingMessage === messages.connecting ||
connectingMessage === messages.reconnecting;
if (isTlsCertInvalid && isConnectingMessage) {
connectingMessage = messages.tlsCertificateNotValidError;
} else if (isVerifyingBlockchain && isConnectingMessage) {
connectingMessage = messages.verifyingBlockchain;
connectingDescription = messages.startingDescription;
}
return { connectingMessage, connectingDescription };
};
render() {
const { intl } = this.context;
const {
isConnected,
isNodeStopping,
isNodeStopped,
isTlsCertInvalid,
hasLoadedCurrentLocale,
verificationProgress,
} = this.props;
if (!hasLoadedCurrentLocale) return null;
const showEllipsis =
!isConnected && (isNodeStopped || (isTlsCertInvalid && !isNodeStopping));
const componentStyles = classNames([
styles.component,
isConnected ? styles.syncing : styles.connecting,
]);
const headlineStyles = classNames([
styles.headline,
showEllipsis ? styles.withoutAnimation : null,
]);
const {
connectingMessage,
connectingDescription,
} = this._getConnectingMessage();
return (
<div className={componentStyles}>
<h1 className={headlineStyles}>
{intl.formatMessage(connectingMessage, {
verificationProgress,
})}
</h1>
<div className={styles.description}>
{connectingDescription && (
<FormattedHTMLMessage {...connectingDescription} />
)}
</div>
</div>
);
}
}