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

172 lines
5.3 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';
2018-07-17 19:17:11 +02:00
import { MODALS, TRANSACTIONS } from 'lbry-redux';
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-07-17 19:17:11 +02:00
capitalize(string: string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
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) {
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}
2018-06-14 22:10:50 +02:00
affixClass="form-field--align-center"
2018-03-26 23:32:43 +02:00
prefix={__('Show')}
postfix={
<Button
button="link"
icon={icons.HELP}
2018-03-26 23:32:43 +02:00
href="https://lbry.io/faq/transaction-types"
title={__('Help')}
2018-03-26 23:32:43 +02:00
/>
}
>
<option value="all">{__('All')}</option>
2018-07-17 19:17:11 +02:00
<option value={TRANSACTIONS.SPEND}>
{__(`${this.capitalize(TRANSACTIONS.SPEND)}s`)}
</option>
<option value={TRANSACTIONS.RECEIVE}>
{__(`${this.capitalize(TRANSACTIONS.RECEIVE)}s`)}
</option>
<option value={TRANSACTIONS.PUBLISH}>
{__(`${this.capitalize(TRANSACTIONS.PUBLISH)}es`)}
</option>
<option value={TRANSACTIONS.CHANNEL}>
{__(`${this.capitalize(TRANSACTIONS.CHANNEL)}s`)}
</option>
<option value={TRANSACTIONS.TIP}>
{__(`${this.capitalize(TRANSACTIONS.TIP)}s`)}
</option>
<option value={TRANSACTIONS.SUPPORT}>
{__(`${this.capitalize(TRANSACTIONS.SUPPORT)}s`)}
</option>
<option value={TRANSACTIONS.UPDATE}>
{__(`${this.capitalize(TRANSACTIONS.UPDATE)}s`)}
</option>
<option value={TRANSACTIONS.ABANDON}>
{__(`${this.capitalize(TRANSACTIONS.ABANDON)}s`)}
</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;