lbry-desktop/src/renderer/component/transactionList/view.jsx

105 lines
3.3 KiB
React
Raw Normal View History

import React from 'react';
import TransactionListItem from './internal/TransactionListItem';
import FormField from 'component/formField';
import Link from 'component/link';
import FileExporter from 'component/file-exporter.js';
import * as icons from 'constants/icons';
import * as modals from 'constants/modal_types';
class TransactionList extends React.PureComponent {
constructor(props) {
super(props);
this.state = {
filter: null,
};
}
handleFilterChanged(event) {
this.setState({
filter: event.target.value,
});
}
filterTransaction(transaction) {
const { filter } = this.state;
return !filter || filter == transaction.type;
}
2017-10-24 15:10:27 +02:00
isRevokeable(txid, nout) {
// a claim/support/update is revokable if it
// is in my claim list(claim_list_mine)
return this.props.myClaims.has(`${txid}:${nout}`);
}
2017-11-01 21:23:30 +01:00
revokeClaim(txid, nout) {
this.props.openModal(modals.CONFIRM_CLAIM_REVOKE, { txid, nout });
2017-10-24 15:10:27 +02:00
}
render() {
const { emptyMessage, rewards, transactions } = this.props;
const transactionList = transactions.filter(this.filterTransaction.bind(this));
return (
<div>
2018-02-24 03:12:51 +01:00
{Boolean(transactionList.length) && (
<FileExporter
2018-02-26 05:24:28 +01:00
data={transactionList}
label={__('Export')}
2018-03-22 16:43:35 +01:00
title={__('Export Transactions')}
filters={['nout']}
defaultPath={__('lbry-transactions-history')}
2018-02-26 05:24:28 +01:00
/>
2018-02-24 03:12:51 +01:00
)}
2017-11-24 15:31:05 +01:00
{(transactionList.length || this.state.filter) && (
<span className="sort-section">
{__('Filter')}{' '}
<FormField type="select" onChange={this.handleFilterChanged.bind(this)}>
<option value="">{__('All')}</option>
<option value="spend">{__('Spends')}</option>
<option value="receive">{__('Receives')}</option>
<option value="publish">{__('Publishes')}</option>
<option value="channel">{__('Channels')}</option>
<option value="tip">{__('Tips')}</option>
<option value="support">{__('Supports')}</option>
<option value="update">{__('Updates')}</option>
</FormField>{' '}
<Link href="https://lbry.io/faq/transaction-types" icon={icons.HELP_CIRCLE} />
2017-11-24 15:31:05 +01:00
</span>
)}
{!transactionList.length && (
<div className="empty">{emptyMessage || __('No transactions to list.')}</div>
2017-11-24 15:31:05 +01:00
)}
{Boolean(transactionList.length) && (
<table className="table-standard table-transactions table-stretch">
<thead>
<tr>
<th>{__('Date')}</th>
<th>{__('Amount (Fee)')}</th>
<th>{__('Type')} </th>
<th>{__('Details')} </th>
<th>{__('Transaction')}</th>
</tr>
</thead>
<tbody>
2017-11-24 15:31:05 +01:00
{transactionList.map(t => (
<TransactionListItem
key={`${t.txid}:${t.nout}`}
transaction={t}
reward={rewards && rewards[t.txid]}
2017-10-24 15:10:27 +02:00
isRevokeable={this.isRevokeable(t.txid, t.nout)}
revokeClaim={this.revokeClaim.bind(this)}
/>
2017-11-24 15:31:05 +01:00
))}
</tbody>
2017-11-24 15:31:05 +01:00
</table>
)}
2017-08-20 23:42:00 +02:00
</div>
2017-06-06 23:19:12 +02:00
);
}
}
2017-06-06 06:21:55 +02:00
export default TransactionList;