2018-03-14 20:10:14 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2018-03-22 03:50:25 +00:00
|
|
|
import translate, { translateRaw } from 'translations';
|
2018-03-14 20:10:14 +00:00
|
|
|
import { getRecentWalletTransactions } from 'selectors/transactions';
|
|
|
|
import { getNetworkConfig } from 'selectors/config';
|
|
|
|
import RecentTransaction from './RecentTransaction';
|
|
|
|
import { TransactionStatus } from 'components';
|
|
|
|
import { IWallet } from 'libs/wallet';
|
|
|
|
import { NetworkConfig } from 'types/network';
|
|
|
|
import { AppState } from 'reducers';
|
|
|
|
import './RecentTransactions.scss';
|
|
|
|
|
|
|
|
interface OwnProps {
|
|
|
|
wallet: IWallet;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface StateProps {
|
|
|
|
recentTransactions: AppState['transactions']['recent'];
|
|
|
|
network: NetworkConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = OwnProps & StateProps;
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
activeTxHash: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
class RecentTransactions extends React.Component<Props> {
|
|
|
|
public state: State = {
|
|
|
|
activeTxHash: ''
|
|
|
|
};
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
const { activeTxHash } = this.state;
|
|
|
|
let content: React.ReactElement<string>;
|
|
|
|
if (activeTxHash) {
|
|
|
|
content = (
|
|
|
|
<React.Fragment>
|
|
|
|
<TransactionStatus txHash={activeTxHash} />
|
|
|
|
<button className="RecentTxs-back btn btn-default" onClick={this.clearActiveTxHash}>
|
2018-03-22 03:50:25 +00:00
|
|
|
<i className="fa fa-arrow-left" /> {translate('BACK_TO_RECENT_TXS')}
|
2018-03-14 20:10:14 +00:00
|
|
|
</button>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
content = this.renderTxList();
|
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="RecentTxs Tab-content-pane">{content}</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderTxList() {
|
|
|
|
const { wallet, recentTransactions, network } = this.props;
|
|
|
|
|
2018-03-22 03:50:25 +00:00
|
|
|
let explorer: string;
|
2018-03-14 20:10:14 +00:00
|
|
|
if (network.isCustom) {
|
2018-03-22 03:50:25 +00:00
|
|
|
explorer = translateRaw('RECENT_TX_NETWORK_EXPLORER', { $network_name: network.name });
|
2018-03-14 20:10:14 +00:00
|
|
|
} else {
|
2018-03-22 03:50:25 +00:00
|
|
|
explorer = `[${network.blockExplorer.name}](${network.blockExplorer.addressUrl(
|
|
|
|
wallet.getAddressString()
|
|
|
|
)})`;
|
2018-03-14 20:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{recentTransactions.length ? (
|
|
|
|
<table className="RecentTxs-txs">
|
|
|
|
<thead>
|
2018-03-22 03:50:25 +00:00
|
|
|
<td>{translate('SEND_ADDR')}</td>
|
|
|
|
<td>{translate('SEND_AMOUNT_SHORT')}</td>
|
|
|
|
<td>{translate('SENT')}</td>
|
2018-03-14 20:10:14 +00:00
|
|
|
<td />
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{recentTransactions.map(tx => (
|
|
|
|
<RecentTransaction
|
|
|
|
key={tx.time}
|
|
|
|
tx={tx}
|
|
|
|
network={network}
|
|
|
|
onClick={this.setActiveTxHash}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
) : (
|
|
|
|
<div className="RecentTxs-empty well">
|
|
|
|
<h2 className="RecentTxs-empty-text">
|
2018-03-22 03:50:25 +00:00
|
|
|
{translate('NO_RECENT_TX_FOUND', { $explorer: explorer })}
|
2018-03-14 20:10:14 +00:00
|
|
|
</h2>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<p className="RecentTxs-help">
|
2018-03-22 03:50:25 +00:00
|
|
|
{translate('RECENT_TX_HELP', { $network: network.name, $explorer: explorer })}
|
2018-03-14 20:10:14 +00:00
|
|
|
</p>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private setActiveTxHash = (activeTxHash: string) => this.setState({ activeTxHash });
|
|
|
|
private clearActiveTxHash = () => this.setState({ activeTxHash: '' });
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect((state: AppState): StateProps => ({
|
|
|
|
recentTransactions: getRecentWalletTransactions(state),
|
|
|
|
network: getNetworkConfig(state)
|
|
|
|
}))(RecentTransactions);
|