-
Notifications
You must be signed in to change notification settings - Fork 295
/
SystemTimeError.tsx
186 lines (173 loc) · 6.24 KB
/
SystemTimeError.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
// @flow
import React, { Component } from 'react';
import SVGInline from 'react-svg-inline';
import { observer } from 'mobx-react';
import { defineMessages, intlShape, FormattedMessage } from 'react-intl';
import classNames from 'classnames';
import { Link } from 'react-polymorph/lib/components/Link';
import { LinkSkin } from 'react-polymorph/lib/skins/simple/LinkSkin';
import attentionIcon from '../../../assets/images/attention-big-light.inline.svg';
import { ALLOWED_TIME_DIFFERENCE } from '../../../config/timingConfig';
import humanizeDurationByLocale from '../../../utils/humanizeDurationByLocale';
import styles from './SystemTimeError.scss';
const messages = defineMessages({
overlayTitle: {
id: 'systemTime.error.overlayTitle',
defaultMessage: '!!!Unable to sync - incorrect time',
description: 'Title of Sync error overlay',
},
overlayTextP1: {
id: 'systemTime.error.overlayTextP1',
defaultMessage:
'!!!Attention, Daedalus is unable to sync with the blockchain because the time on your machine is different from the global time. Your time is off by 2 hours 12 minutes 54 seconds.',
description: 'First paragraph of Sync error overlay',
},
overlayTextP2: {
id: 'systemTime.error.overlayTextP2',
defaultMessage:
'!!!To synchronise the time and fix the issue, please read our {supportPortalLink} article.',
description: 'Second paragraph of Sync error overlay',
},
ntpUnreachableTextP1: {
id: 'systemTime.error.ntpUnreachableTextP1',
defaultMessage:
'!!!Attention, Daedalus is unable to check if the clock on your computer is synchronized with global time because NTP (Network Time Protocol) servers are unreachable, possibly due to firewalls on your network.',
description: 'Text of Sync error overlay when NTP service is unreachable',
},
ntpUnreachableTextP2: {
id: 'systemTime.error.ntpUnreachableTextP2',
defaultMessage:
'!!!If your computer clock is off by more than 15 seconds, Daedalus will be unable to connect to the network. If you have this issue, please read our Support Portal article to synchronize the time on your machine.',
description: 'Text of Sync error overlay when NTP service is unreachable',
},
supportPortalLink: {
id: 'systemTime.error.supportPortalLink',
defaultMessage: '!!!Support Portal',
description: '"Support Portal" link text',
},
supportPortalLinkUrl: {
id: 'systemTime.error.supportPortalLinkUrl',
defaultMessage:
'!!!https://iohk.zendesk.com/hc/en-us/articles/360010230873',
description:
'Link to "Machine clock out of sync with Cardano network" support page',
},
onCheckTheTimeAgainLink: {
id: 'systemTime.error.onCheckTheTimeAgainLink',
defaultMessage: '!!!Check the time again',
description: 'Text of Check the time again button',
},
onContinueWithoutClockSyncCheckLink: {
id: 'systemTime.error.onContinueWithoutClockSyncCheckLink',
defaultMessage: '!!!Continue without clock synchronization checks',
description:
'Text of "Continue without clock synchronization checks" button',
},
});
type Props = {
localTimeDifference: ?number,
currentLocale: string,
onExternalLinkClick: Function,
onCheckTheTimeAgain: Function,
onContinueWithoutClockSyncCheck: Function,
isCheckingSystemTime: boolean,
};
@observer
export default class SystemTimeError extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
render() {
const { intl } = this.context;
const {
localTimeDifference,
currentLocale,
isCheckingSystemTime,
onCheckTheTimeAgain,
onContinueWithoutClockSyncCheck,
onExternalLinkClick,
} = this.props;
const supportPortalLinkUrl = intl.formatMessage(
messages.supportPortalLinkUrl
);
const supportPortalLink = (
<Link
className={styles.supportPortalLink}
onClick={(event) => onExternalLinkClick(supportPortalLinkUrl, event)}
label={intl.formatMessage(messages.supportPortalLink)}
skin={LinkSkin}
/>
);
const isNTPServiceReachable = !!localTimeDifference;
const allowedTimeDifferenceInSeconds = ALLOWED_TIME_DIFFERENCE / 1000000;
const rawTimeOffset = (localTimeDifference || 0) / 1000;
const timeOffset = humanizeDurationByLocale(rawTimeOffset, currentLocale, {
delimiter: ' ',
units: ['y', 'mo', 'w', 'd', 'h', 'm', 's', 'ms'],
localeConfig: {
'ja-JP': {
spacer: '',
delimiter: '',
serialComma: false,
},
},
});
return (
<div className={styles.component}>
<SVGInline svg={attentionIcon} className={styles.icon} />
{isNTPServiceReachable ? (
<div>
<p>
<FormattedMessage
{...messages.overlayTextP1}
values={{
timeOffset: <em className="time-off">{timeOffset}</em>,
}}
/>
</p>
<p>
<FormattedMessage
{...messages.overlayTextP2}
values={{ supportPortalLink }}
/>
</p>
<Link
className={classNames([
styles.checkLink,
isCheckingSystemTime ? styles.disabled : null,
])}
onClick={() => onCheckTheTimeAgain()}
label={intl.formatMessage(messages.onCheckTheTimeAgainLink)}
hasIconAfter={false}
skin={LinkSkin}
/>
</div>
) : (
<div>
<p>
<FormattedMessage
{...messages.ntpUnreachableTextP1}
values={{ timeOffset }}
/>
</p>
<p>
<FormattedMessage
{...messages.ntpUnreachableTextP2}
values={{ supportPortalLink, allowedTimeDifferenceInSeconds }}
/>
</p>
<Link
className={styles.checkLink}
onClick={() => onContinueWithoutClockSyncCheck()}
label={intl.formatMessage(
messages.onContinueWithoutClockSyncCheckLink
)}
hasIconAfter={false}
skin={LinkSkin}
/>
</div>
)}
</div>
);
}
}