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

149 lines
4.7 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as ICONS from 'constants/icons';
import * as MODALS from 'constants/modal_types';
2018-03-26 23:32:43 +02:00
import * as React from 'react';
import { FormField } from 'component/common/form';
import Button from 'component/button';
import FileExporter from 'component/common/file-exporter';
import { 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,
2018-10-18 19:56:10 +02:00
filterSetting: string,
setTransactionFilter: string => void,
2018-03-26 23:32:43 +02:00
};
2018-10-18 19:56:10 +02:00
class TransactionList extends React.PureComponent<Props> {
2018-03-26 23:32:43 +02:00
constructor(props: Props) {
super(props);
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<*>) {
2018-10-18 19:56:10 +02:00
this.props.setTransactionFilter(event.target.value);
}
2018-03-26 23:32:43 +02:00
filterTransaction(transaction: Transaction) {
2018-10-18 19:56:10 +02:00
return (
this.props.filterSetting === TRANSACTIONS.ALL || this.props.filterSetting === 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(MODALS.CONFIRM_CLAIM_REVOKE, { txid, nout });
2017-10-24 15:10:27 +02:00
}
render() {
2018-10-18 19:56:10 +02:00
const { emptyMessage, rewards, transactions, slim, filterSetting } = this.props;
// The shorter "recent transactions" list shouldn't be filtered
const transactionList = slim ? transactions : transactions.filter(this.filterTransaction);
2018-10-18 19:56:10 +02:00
// Flow offers little support for Object.values() typing.
// https://github.com/facebook/flow/issues/2221
// $FlowFixMe
const transactionTypes: Array<string> = Object.values(TRANSACTIONS);
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 &&
2018-11-30 22:47:04 +01:00
!!transactions.length && (
<div className="card__actions card__actions--between">
2018-03-26 23:32:43 +02:00
<FileExporter
data={transactionList}
label={__('Export')}
title={__('Export Transactions')}
filters={['nout']}
defaultPath={__('lbry-transactions-history')}
/>
{!slim && (
<FormField
type="select"
value={filterSetting || TRANSACTIONS.ALL}
onChange={this.handleFilterChanged}
affixClass="form-field--align-center"
prefix={__('Show')}
postfix={
<Button
button="link"
2018-11-26 02:21:25 +01:00
icon={ICONS.HELP}
href="https://lbry.io/faq/transaction-types"
title={__('Help')}
/>
}
>
{transactionTypes.map(tt => (
<option key={tt} value={tt}>
{__(`${this.capitalize(tt)}`)}
</option>
))}
</FormField>
)}
2018-03-26 23:32:43 +02:00
</div>
)}
{!!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;