2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2018-12-19 06:44:53 +01:00
|
|
|
import * as icons from 'constants/icons';
|
2019-09-23 04:47:07 +02:00
|
|
|
import React from 'react';
|
2019-07-23 10:05:51 +02:00
|
|
|
import { FormField } from 'component/common/form';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
|
|
|
import FileExporter from 'component/common/file-exporter';
|
2019-09-25 20:12:02 +02:00
|
|
|
import { TRANSACTIONS, TX_LIST } from 'lbry-redux';
|
|
|
|
import * as PAGES from 'constants/pages';
|
2019-09-23 04:47:07 +02:00
|
|
|
import TransactionListTable from 'component/transactionListTable';
|
2019-06-17 22:32:38 +02:00
|
|
|
import RefreshTransactionButton from 'component/transactionRefreshButton';
|
|
|
|
import Spinner from 'component/spinner';
|
2019-09-23 04:47:07 +02:00
|
|
|
import Paginate from 'component/common/paginate';
|
2017-05-11 02:59:47 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
|
|
|
emptyMessage: ?string,
|
2019-06-17 22:32:38 +02:00
|
|
|
filterSetting: string,
|
|
|
|
loading: boolean,
|
2019-05-10 09:24:35 +02:00
|
|
|
myClaims: any,
|
2018-10-18 19:56:10 +02:00
|
|
|
setTransactionFilter: string => void,
|
2019-06-17 22:32:38 +02:00
|
|
|
slim?: boolean,
|
|
|
|
title: string,
|
|
|
|
transactions: Array<Transaction>,
|
2019-09-23 04:47:07 +02:00
|
|
|
transactionCount?: number,
|
|
|
|
history: { replace: string => void },
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
2019-09-23 04:47:07 +02:00
|
|
|
function TransactionList(props: Props) {
|
|
|
|
const { emptyMessage, slim, filterSetting, title, transactions, loading, history, transactionCount } = props;
|
|
|
|
// Flow offers little support for Object.values() typing.
|
|
|
|
// https://github.com/facebook/flow/issues/2221
|
|
|
|
// $FlowFixMe
|
|
|
|
const transactionTypes: Array<string> = Object.values(TRANSACTIONS);
|
2017-09-02 17:36:27 +02:00
|
|
|
|
2019-09-23 04:47:07 +02:00
|
|
|
function capitalize(string: string) {
|
2018-07-17 19:17:11 +02:00
|
|
|
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
}
|
|
|
|
|
2019-09-23 04:47:07 +02:00
|
|
|
function handleFilterChanged(event: SyntheticInputEvent<*>) {
|
|
|
|
props.setTransactionFilter(event.target.value);
|
2019-09-25 20:12:02 +02:00
|
|
|
history.replace(`/$/${PAGES.TRANSACTIONS}`); //
|
2017-10-24 15:10:27 +02:00
|
|
|
}
|
|
|
|
|
2019-09-23 04:47:07 +02:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
<header className="table__header">
|
|
|
|
<h2 className="card__title--between">
|
|
|
|
<span>
|
|
|
|
{title}
|
|
|
|
{loading && <Spinner type="small" />}
|
|
|
|
</span>
|
|
|
|
<div className="card__actions--inline">
|
|
|
|
{slim && (
|
2019-09-25 20:12:02 +02:00
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
className="button--alt"
|
|
|
|
navigate={`/$/${PAGES.TRANSACTIONS}`}
|
|
|
|
label={__('Full History')}
|
|
|
|
/>
|
2019-09-23 04:47:07 +02:00
|
|
|
)}
|
|
|
|
<RefreshTransactionButton />
|
|
|
|
</div>
|
|
|
|
</h2>
|
|
|
|
</header>
|
|
|
|
{!slim && (
|
2019-06-17 22:32:38 +02:00
|
|
|
<header className="table__header">
|
2019-09-23 04:47:07 +02:00
|
|
|
<div className="card__actions--between">
|
|
|
|
<FileExporter
|
|
|
|
data={transactions}
|
|
|
|
label={__('Export')}
|
|
|
|
title={__('Export Transactions')}
|
|
|
|
filters={['nout']}
|
|
|
|
defaultPath={__('lbry-transactions-history')}
|
|
|
|
disabled={!transactions.length}
|
|
|
|
/>
|
|
|
|
<FormField
|
|
|
|
type="select"
|
|
|
|
name="file-sort"
|
|
|
|
value={filterSetting || TRANSACTIONS.ALL}
|
|
|
|
onChange={handleFilterChanged}
|
|
|
|
label={__('Show')}
|
|
|
|
postfix={
|
|
|
|
<Button
|
|
|
|
button="link"
|
|
|
|
icon={icons.HELP}
|
|
|
|
href="https://lbry.com/faq/transaction-types"
|
|
|
|
title={__('Help')}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{transactionTypes.map(tt => (
|
|
|
|
<option key={tt} value={tt}>
|
|
|
|
{__(`${capitalize(tt)}`)}
|
|
|
|
</option>
|
|
|
|
))}
|
|
|
|
</FormField>
|
|
|
|
</div>
|
2019-06-17 22:32:38 +02:00
|
|
|
</header>
|
2019-09-23 04:47:07 +02:00
|
|
|
)}
|
2019-06-17 22:32:38 +02:00
|
|
|
|
2019-09-23 04:47:07 +02:00
|
|
|
{!loading && !transactions.length && (
|
|
|
|
<h2 className="main--empty empty">{emptyMessage || __('No transactions.')}</h2>
|
|
|
|
)}
|
2018-12-19 06:44:53 +01:00
|
|
|
|
2019-09-23 04:47:07 +02:00
|
|
|
{!!transactions && !!transactions.length && <TransactionListTable transactionList={transactions} />}
|
|
|
|
{!slim && !!transactionCount && (
|
|
|
|
<Paginate
|
2019-09-25 20:12:02 +02:00
|
|
|
onPageChange={page => history.replace(`/$/${PAGES.TRANSACTIONS}?page=${Number(page)}`)}
|
|
|
|
totalPages={Math.ceil(transactionCount / TX_LIST.PAGE_SIZE)}
|
2019-09-23 04:47:07 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
2017-09-02 17:36:27 +02:00
|
|
|
}
|
2017-05-11 02:59:47 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
export default TransactionList;
|