Newer
Older
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { inject, observer } from 'mobx-react';
import { chainName$, withoutLoading } from '@parity/light.js';
import light from '@parity/light.js-react';
import { withProps } from 'recompose';
import { Modal } from 'fether-ui';
Luke Schoen
committed
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;
chainName: () => chainName$().pipe(withoutLoading())
@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
};
// 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('/');
};
<RequireHealthOverlay require='node-internet' fullscreen>
Luke Schoen
committed
<div className='window_content'>
<Modal
description={this.renderDescription()}
fullscreen
link={this.renderLink()}
icon={this.renderIcon()}
buttons={this.renderGoHomepage()}
title={this.renderTitle()}
visible
Luke Schoen
committed
/>
</div>
</RequireHealthOverlay>
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
renderDescription = () => {
const {
sendStore: { confirmations, txStatus }
} = this.props;
if (!txStatus) {
return '';
}
if (confirmations >= MIN_CONFIRMATIONS) {
return null;
}
if (confirmations > 0) {
return `Waiting ${confirmations}/${MIN_CONFIRMATIONS} confirmations`;
}
if (txStatus.confirmed) {
return 'Waiting for confirmations...';
}
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
? 'Transaction confirmed'
: 'Submitted'}
</span>
);
}
if (txStatus.failed) {
return 'Error';
}
return 'Sending your transaction...';
};
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}
>
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.transactionHash,
token.address
)}
target='_blank'
rel='noopener noreferrer'
>
<button className='button -tiny'>See it on BlockScout</button>
</a>
);
}
return null;
};