-
Notifications
You must be signed in to change notification settings - Fork 295
/
VotingRegistrationStepsConfirm.tsx
191 lines (180 loc) · 6.57 KB
/
VotingRegistrationStepsConfirm.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
// @flow
import React, { Component, Fragment } from 'react';
import { defineMessages, intlShape, FormattedHTMLMessage } from 'react-intl';
import { observer } from 'mobx-react';
import SVGInline from 'react-svg-inline';
import sadLogo from '../../../assets/images/untada.inline.svg';
import ProgressBarLarge from '../../widgets/ProgressBarLarge';
import { VOTING_REGISTRATION_MIN_TRANSACTION_CONFIRMATIONS } from '../../../config/votingConfig';
import LocalizableError from '../../../i18n/LocalizableError';
import styles from './VotingRegistrationStepsConfirm.scss';
import VotingRegistrationDialog from './widgets/VotingRegistrationDialog';
const messages = defineMessages({
description: {
id: 'voting.votingRegistration.confirm.step.description',
defaultMessage:
'!!!Confirmation of voting registration requires approximately 5 minutes. Please leave Daedalus running.',
description: 'Description voting registration "confirm" step.',
},
descriptionRestart: {
id: 'voting.votingRegistration.confirm.step.descriptionRestart',
defaultMessage:
'!!!Please restart the voting registration process by clicking <span>Restart voting registration</span>.',
description:
'Message for restart voting registration on the voting registration "confirm" step.',
},
errorMessage: {
id: 'voting.votingRegistration.confirm.step.errorMessage',
defaultMessage:
'!!!The voting registration process was not completed correctly.',
description: 'Error message on the voting registration "confirm" step.',
},
continueButtonLabel: {
id: 'voting.votingRegistration.confirm.step.continueButtonLabel',
defaultMessage: '!!!Continue',
description:
'Label for continue button on the voting registration "confirm" step.',
},
restartButtonLabel: {
id: 'voting.votingRegistration.confirm.step.restartButtonLabel',
defaultMessage: '!!!Restart voting registration',
description:
'Label for restart button on the voting registration "confirm" step.',
},
transactionPendingLabel: {
id: 'voting.votingRegistration.confirm.step.transactionPendingLabel',
defaultMessage: '!!!Transaction pending...',
description:
'Label for pending transaction state on the voting registration "confirm" step.',
},
transactionConfirmedLabel: {
id: 'voting.votingRegistration.confirm.step.transactionConfirmedLabel',
defaultMessage: '!!!Transaction confirmed',
description:
'Label for confirmed transaction state on the voting registration "confirm" step.',
},
waitingForConfirmationsLabel: {
id: 'voting.votingRegistration.confirm.step.waitingForConfirmationsLabel',
defaultMessage: '!!!Waiting for confirmation...',
description:
'Label for confirming transaction state on the voting registration "confirm" step.',
},
confirmationsCountLabel: {
id: 'voting.votingRegistration.confirm.step.confirmationsCountLabel',
defaultMessage: '!!!{currentCount} of {expectedCount}',
description:
'Label for number of confirmations on the voting registration "confirm" step.',
},
});
type Props = {
onClose: Function,
stepsList: Array<string>,
activeStep: number,
isTransactionPending: boolean,
isTransactionConfirmed: boolean,
transactionConfirmations: number,
transactionError: ?boolean | ?LocalizableError,
onConfirm: Function,
onRestart: Function,
};
@observer
export default class VotingRegistrationStepsConfirm extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
render() {
const { intl } = this.context;
const {
stepsList,
activeStep,
onConfirm,
onRestart,
isTransactionPending,
isTransactionConfirmed,
transactionConfirmations,
transactionError,
onClose,
} = this.props;
const description = intl.formatMessage(messages.description);
const descriptionRestart = (
<FormattedHTMLMessage {...messages.descriptionRestart} />
);
const errorMessage = intl.formatMessage(messages.errorMessage);
const buttonLabel = intl.formatMessage(messages.continueButtonLabel);
const restartButtonLabel = intl.formatMessage(messages.restartButtonLabel);
const actions = [
transactionError
? {
className: 'attention',
label: restartButtonLabel,
onClick: onRestart,
}
: {
className: styles.buttonConfirmStyles,
label: buttonLabel,
onClick: onConfirm,
disabled: !isTransactionConfirmed,
primary: true,
},
];
let progressBarLeftLabelMessage;
if (isTransactionConfirmed)
progressBarLeftLabelMessage = messages.transactionConfirmedLabel;
else if (isTransactionPending)
progressBarLeftLabelMessage = messages.transactionPendingLabel;
else progressBarLeftLabelMessage = messages.waitingForConfirmationsLabel;
const progressBarLeftLabel = intl.formatMessage(
progressBarLeftLabelMessage
);
const progressBarRightLabel = isTransactionPending
? ''
: intl.formatMessage(messages.confirmationsCountLabel, {
currentCount: Math.min(
transactionConfirmations,
VOTING_REGISTRATION_MIN_TRANSACTION_CONFIRMATIONS
),
expectedCount: VOTING_REGISTRATION_MIN_TRANSACTION_CONFIRMATIONS,
});
const progress =
(transactionConfirmations * 100) /
VOTING_REGISTRATION_MIN_TRANSACTION_CONFIRMATIONS;
return (
<VotingRegistrationDialog
onClose={() => {
onClose(!transactionError);
}}
stepsList={stepsList}
activeStep={activeStep}
actions={actions}
containerClassName={styles.component}
hideSteps={!!transactionError}
>
{transactionError ? (
<Fragment>
<div className={styles.sadLogoContainer}>
<SVGInline svg={sadLogo} className={styles.sadLogoIcon} />
</div>
<div className={styles.errorMessage}>
<p>{errorMessage}</p>
</div>
<div className={styles.description}>
<p>{descriptionRestart}</p>
</div>
</Fragment>
) : (
<Fragment>
<ProgressBarLarge
leftLabel={progressBarLeftLabel}
rightLabel1={progressBarRightLabel}
loading={isTransactionPending}
progress={Math.min(progress, 100)}
/>
<div className={styles.description}>
<p>{description}</p>
</div>
</Fragment>
)}
</VotingRegistrationDialog>
);
}
}