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

149 lines
4.4 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as React from 'react';
import { FormField } from 'component/common/form';
import Button from 'component/button';
import FileExporter from 'component/common/file-exporter';
import * as icons from 'constants/icons';
import * as modals from 'constants/modal_types';
2018-03-26 23:32:43 +02:00
import TransactionListItem from './internal/transaction-list-item';
2018-03-26 23:32:43 +02:00
export type Transaction = {
amount: number,
claim_id: string,
claim_name: string,
fee: number,
nout: number,
txid: string,
type: string,
date: Date,
};
type Props = {
emptyMessage: ?string,
slim?: boolean,
transactions: Array<Transaction>,
rewards: {},
2018-04-19 18:51:18 +02:00
openModal: ({ id: string }, { nout: number, txid: string }) => void,
2018-03-26 23:32:43 +02:00
myClaims: any,
};
type State = {
filter: string,
};
class TransactionList extends React.PureComponent<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
2018-03-26 23:32:43 +02:00
filter: 'all',
};
2018-03-26 23:32:43 +02:00
(this: any).handleFilterChanged = this.handleFilterChanged.bind(this);
(this: any).filterTransaction = this.filterTransaction.bind(this);
(this: any).revokeClaim = this.revokeClaim.bind(this);
(this: any).isRevokeable = this.isRevokeable.bind(this);
}
2018-03-26 23:32:43 +02:00
handleFilterChanged(event: SyntheticInputEvent<*>) {
this.setState({
filter: event.target.value,
});
}
2018-03-26 23:32:43 +02:00
filterTransaction(transaction: Transaction) {
const { filter } = this.state;
2018-03-26 23:32:43 +02:00
return filter === 'all' || filter === transaction.type;
}
2018-03-26 23:32:43 +02:00
isRevokeable(txid: string, nout: number) {
const { myClaims } = this.props;
2017-10-24 15:10:27 +02:00
// a claim/support/update is revokable if it
// is in my claim list(claim_list_mine)
2018-03-26 23:32:43 +02:00
return myClaims.has(`${txid}:${nout}`);
2017-10-24 15:10:27 +02:00
}
2018-03-26 23:32:43 +02:00
revokeClaim(txid: string, nout: number) {
2018-04-19 18:51:18 +02:00
this.props.openModal({ id: modals.CONFIRM_CLAIM_REVOKE }, { txid, nout });
2017-10-24 15:10:27 +02:00
}
render() {
2018-03-26 23:32:43 +02:00
const { emptyMessage, rewards, transactions, slim } = this.props;
const { filter } = this.state;
const transactionList = transactions.filter(this.filterTransaction);
return (
2018-03-26 23:32:43 +02:00
<React.Fragment>
{!transactionList.length && (
<p className="card__content">{emptyMessage || __('No transactions to list.')}</p>
2018-02-24 03:12:51 +01:00
)}
2018-03-26 23:32:43 +02:00
{!slim &&
!!transactionList.length && (
<div className="card__actions">
<FileExporter
data={transactionList}
label={__('Export')}
title={__('Export Transactions')}
filters={['nout']}
defaultPath={__('lbry-transactions-history')}
/>
</div>
)}
{!slim && (
<div className="card__actions-top-corner">
<FormField
type="select"
value={filter}
onChange={this.handleFilterChanged}
prefix={__('Show')}
postfix={
<Button
button="link"
href="https://lbry.io/faq/transaction-types"
label={__('Help')}
/>
}
>
<option value="all">{__('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>
2018-03-26 23:32:43 +02:00
</FormField>
</div>
2017-11-24 15:31:05 +01:00
)}
2018-03-26 23:32:43 +02:00
{!!transactionList.length && (
<table className="card__content table table--transactions table--stretch">
<thead>
<tr>
2018-03-26 23:32:43 +02:00
<th>{__('Amount')}</th>
<th>{__('Type')} </th>
<th>{__('Details')} </th>
<th>{__('Transaction')}</th>
2018-03-26 23:32:43 +02:00
<th>{__('Date')}</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)}
2018-03-26 23:32:43 +02:00
revokeClaim={this.revokeClaim}
/>
2017-11-24 15:31:05 +01:00
))}
</tbody>
2017-11-24 15:31:05 +01:00
</table>
)}
2018-03-26 23:32:43 +02:00
</React.Fragment>
2017-06-06 23:19:12 +02:00
);
}
}
2017-06-06 06:21:55 +02:00
export default TransactionList;