2018-02-16 16:57:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2018-03-05 18:58:53 +00:00
|
|
|
import { RouteComponentProps } from 'react-router';
|
2018-02-16 16:57:23 +00:00
|
|
|
import TabSection from 'containers/TabSection';
|
|
|
|
import TxHashInput from './components/TxHashInput';
|
|
|
|
import { TransactionStatus as TransactionStatusComponent } from 'components';
|
|
|
|
import { getNetworkConfig } from 'selectors/config';
|
2018-03-05 18:58:53 +00:00
|
|
|
import { getParamFromURL } from 'utils/helpers';
|
2018-02-16 16:57:23 +00:00
|
|
|
import { AppState } from 'reducers';
|
|
|
|
import { NetworkConfig } from 'types/network';
|
|
|
|
import './index.scss';
|
2018-03-22 03:50:25 +00:00
|
|
|
import translate from 'translations';
|
2018-04-06 21:08:28 +00:00
|
|
|
import { etherChainExplorerInst } from 'config/data';
|
2018-02-16 16:57:23 +00:00
|
|
|
|
2018-03-05 18:58:53 +00:00
|
|
|
interface StateProps {
|
2018-02-16 16:57:23 +00:00
|
|
|
network: NetworkConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
hash: string;
|
|
|
|
}
|
|
|
|
|
2018-03-05 18:58:53 +00:00
|
|
|
type Props = StateProps & RouteComponentProps<{}>;
|
|
|
|
|
2018-02-16 16:57:23 +00:00
|
|
|
class CheckTransaction extends React.Component<Props, State> {
|
|
|
|
public state: State = {
|
|
|
|
hash: ''
|
|
|
|
};
|
|
|
|
|
2018-03-05 18:58:53 +00:00
|
|
|
public componentDidMount() {
|
|
|
|
const hash = getParamFromURL(this.props.location.search, 'txHash');
|
|
|
|
if (hash) {
|
|
|
|
this.setState({ hash });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 20:10:14 +00:00
|
|
|
public componentWillReceiveProps(nextProps: Props) {
|
|
|
|
const { network } = this.props;
|
|
|
|
if (network.chainId !== nextProps.network.chainId) {
|
|
|
|
this.setState({ hash: '' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 16:57:23 +00:00
|
|
|
public render() {
|
|
|
|
const { network } = this.props;
|
|
|
|
const { hash } = this.state;
|
2018-04-06 21:08:28 +00:00
|
|
|
const CHECK_TX_KEY =
|
|
|
|
network.name === 'ETH'
|
|
|
|
? 'CHECK_TX_STATUS_DESCRIPTION_MULTIPLE'
|
|
|
|
: 'CHECK_TX_STATUS_DESCRIPTION_2';
|
2018-02-16 16:57:23 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TabSection>
|
|
|
|
<div className="CheckTransaction Tab-content">
|
|
|
|
<section className="CheckTransaction-form Tab-content-pane">
|
2018-03-22 03:50:25 +00:00
|
|
|
<h1 className="CheckTransaction-form-title">{translate('CHECK_TX_STATUS_TITLE')}</h1>
|
2018-02-16 16:57:23 +00:00
|
|
|
<p className="CheckTransaction-form-desc">
|
2018-03-22 03:50:25 +00:00
|
|
|
{translate('CHECK_TX_STATUS_DESCRIPTION_1')}
|
|
|
|
{!network.isCustom &&
|
2018-04-06 21:08:28 +00:00
|
|
|
translate(CHECK_TX_KEY, {
|
2018-03-22 03:50:25 +00:00
|
|
|
$block_explorer: network.blockExplorer.name,
|
2018-04-06 21:08:28 +00:00
|
|
|
$block_explorer_link: network.blockExplorer.origin,
|
|
|
|
// On ETH networks, we also show Etherchain. Otherwise, these variables are ignored
|
|
|
|
$block_explorer_2: etherChainExplorerInst.name,
|
|
|
|
$block_explorer_link_2: etherChainExplorerInst.origin
|
2018-03-22 03:50:25 +00:00
|
|
|
})}
|
2018-02-16 16:57:23 +00:00
|
|
|
</p>
|
2018-03-05 18:58:53 +00:00
|
|
|
<TxHashInput hash={hash} onSubmit={this.handleHashSubmit} />
|
2018-02-16 16:57:23 +00:00
|
|
|
</section>
|
|
|
|
|
|
|
|
{hash && (
|
|
|
|
<section className="CheckTransaction-tx Tab-content-pane">
|
2018-03-14 20:10:14 +00:00
|
|
|
<TransactionStatusComponent key={network.chainId} txHash={hash} />
|
2018-02-16 16:57:23 +00:00
|
|
|
</section>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</TabSection>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private handleHashSubmit = (hash: string) => {
|
|
|
|
// Reset to re-mount the component
|
|
|
|
this.setState({ hash: '' }, () => {
|
|
|
|
this.setState({ hash });
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-03-05 18:58:53 +00:00
|
|
|
export default connect((state: AppState): StateProps => ({
|
2018-02-16 16:57:23 +00:00
|
|
|
network: getNetworkConfig(state)
|
|
|
|
}))(CheckTransaction);
|