This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathSent.js
190 lines (161 loc) · 4.27 KB
/
Sent.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
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { inject, observer } from 'mobx-react';
import { chainName$ } from '@parity/light.js';
import light from '@parity/light.js-react';
import { withProps } from 'recompose';
import { Modal } from 'fether-ui';
import i18n, { packageNS } from '../../i18n';
import RequireHealthOverlay from '../../RequireHealthOverlay';
import check from '../../assets/img/icons/check.svg';
import loading from '../../assets/img/icons/loading.svg';
import withTokens from '../../utils/withTokens';
import { blockscoutTxUrl } from '../../utils/blockscout';
// Number of confirmations to consider a transaction successful
const MIN_CONFIRMATIONS = 6;
@light({
chainName: () => chainName$()
})
@inject('sendStore')
@withTokens
@withProps(({ match: { params: { tokenAddress } }, tokens }) => ({
token: tokens[tokenAddress]
}))
@observer
class Sent extends Component {
static propTypes = {
chainName: PropTypes.string,
sendStore: PropTypes.object,
token: PropTypes.object
};
componentWillMount () {
// If we refresh on this page, return to homepage
if (!this.props.sendStore.txStatus) {
this.handleGoToHomepage();
}
}
handleGoToHomepage = () => {
const { history, sendStore } = this.props;
sendStore.clear();
history.push('/');
};
render () {
return (
<RequireHealthOverlay require='node-internet' fullscreen>
<div className='window_content'>
<Modal
description={this.renderDescription()}
fullscreen
link={this.renderLink()}
icon={this.renderIcon()}
buttons={this.renderGoHomepage()}
title={this.renderTitle()}
visible
/>
</div>
</RequireHealthOverlay>
);
}
renderDescription = () => {
const {
sendStore: { confirmations, txStatus }
} = this.props;
if (!txStatus) {
return '';
}
if (confirmations >= MIN_CONFIRMATIONS) {
return null;
}
if (confirmations > 0) {
return i18n.t(`${packageNS}:tx.sent.waiting_confirmations_receiving`, {
progress: `${confirmations}/${MIN_CONFIRMATIONS}`
});
}
if (txStatus.confirmed) {
return i18n.t(`${packageNS}:tx.sent.waiting_confirmed`);
}
if (txStatus.failed) {
return JSON.stringify(txStatus.failed);
}
return null;
};
renderIcon = () => {
const {
sendStore: { confirmations }
} = this.props;
if (confirmations >= MIN_CONFIRMATIONS) {
return check;
}
return loading;
};
renderTitle = () => {
const {
sendStore: { confirmations, txStatus }
} = this.props;
if (!txStatus) {
return '';
}
if (txStatus.confirmed) {
return (
<span>
{confirmations >= MIN_CONFIRMATIONS
? i18n.t(`${packageNS}:tx.sent.confirmed`)
: i18n.t(`${packageNS}:tx.sent.submitted`)}
</span>
);
}
if (txStatus.failed) {
return i18n.t(`${packageNS}:tx.sent.error`);
}
return i18n.t(`${packageNS}:tx.header_sending`);
};
renderGoHomepage = () => {
const {
sendStore: { confirmations }
} = this.props;
if (confirmations < MIN_CONFIRMATIONS) {
return;
}
return (
<nav className='form-nav'>
<button
className='button'
disabled={confirmations < MIN_CONFIRMATIONS}
onClick={this.handleGoToHomepage}
>
{i18n.t(`${packageNS}:navigation.go_back`)}
</button>
</nav>
);
};
renderLink = () => {
const {
chainName,
sendStore: { confirmations, txStatus },
token
} = this.props;
if (txStatus && txStatus.confirmed && confirmations >= 0) {
return (
<a
href={blockscoutTxUrl(
chainName,
txStatus.confirmed.hash,
token.address
)}
target='_blank'
rel='noopener noreferrer'
>
<button className='button -tiny'>
{i18n.t(`${packageNS}:tx.blockscout`)}
</button>
</a>
);
}
return null;
};
}
export default Sent;