2018-02-16 16:57:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import translate from 'translations';
|
|
|
|
import { fetchTransactionData, TFetchTransactionData } from 'actions/transactions';
|
|
|
|
import { getTransactionDatas } from 'selectors/transactions';
|
|
|
|
import { getNetworkConfig } from 'selectors/config';
|
|
|
|
import { Spinner } from 'components/ui';
|
|
|
|
import TransactionDataTable from './TransactionDataTable';
|
|
|
|
import { AppState } from 'reducers';
|
|
|
|
import { NetworkConfig } from 'types/network';
|
2018-03-14 20:10:14 +00:00
|
|
|
import { TransactionState } from 'types/transactions';
|
2018-02-16 16:57:23 +00:00
|
|
|
import './TransactionStatus.scss';
|
|
|
|
|
|
|
|
interface OwnProps {
|
|
|
|
txHash: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface StateProps {
|
|
|
|
tx: TransactionState | null;
|
|
|
|
network: NetworkConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ActionProps {
|
|
|
|
fetchTransactionData: TFetchTransactionData;
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = OwnProps & StateProps & ActionProps;
|
|
|
|
|
|
|
|
class TransactionStatus extends React.Component<Props> {
|
|
|
|
public componentDidMount() {
|
|
|
|
this.props.fetchTransactionData(this.props.txHash);
|
|
|
|
}
|
|
|
|
|
2018-05-11 02:34:27 +00:00
|
|
|
public UNSAFE_componentWillReceiveProps(nextProps: Props) {
|
2018-02-16 16:57:23 +00:00
|
|
|
if (this.props.txHash !== nextProps.txHash) {
|
|
|
|
this.props.fetchTransactionData(nextProps.txHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
const { tx, network } = this.props;
|
|
|
|
let content;
|
|
|
|
|
|
|
|
if (tx && tx.data) {
|
|
|
|
content = (
|
|
|
|
<React.Fragment>
|
|
|
|
<div className="TxStatus-data">
|
|
|
|
<TransactionDataTable network={network} data={tx.data} receipt={tx.receipt} />
|
|
|
|
</div>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
} else if (tx && tx.error) {
|
|
|
|
content = (
|
|
|
|
<div className="TxStatus-error">
|
2018-03-22 03:50:25 +00:00
|
|
|
<h2 className="TxStatus-error-title">{translate('TX_NOTFOUND')}</h2>
|
|
|
|
<p className="TxStatus-error-desc">{translate('TX_NOTFOUND_1')}</p>
|
2018-02-16 16:57:23 +00:00
|
|
|
<ul className="TxStatus-error-list">
|
2018-03-22 03:50:25 +00:00
|
|
|
<li>{translate('TX_NOTFOUND_5')}</li>
|
|
|
|
<li>{translate('TX_NOTFOUND_2')}</li>
|
|
|
|
<li>{translate('TX_NOTFOUND_3')}</li>
|
|
|
|
<li>{translate('TX_NOTFOUND_4')}</li>
|
2018-02-16 16:57:23 +00:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (tx && tx.isLoading) {
|
|
|
|
// tx.isLoading... probably.
|
|
|
|
content = (
|
|
|
|
<div className="TxStatus-loading">
|
|
|
|
<Spinner size="x3" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="TxStatus">{content}</div>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state: AppState, ownProps: OwnProps): StateProps {
|
|
|
|
const { txHash } = ownProps;
|
|
|
|
|
|
|
|
return {
|
|
|
|
tx: getTransactionDatas(state)[txHash],
|
|
|
|
network: getNetworkConfig(state)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, { fetchTransactionData })(TransactionStatus);
|