2017-09-02 17:36:27 +02:00
|
|
|
import React from "react";
|
|
|
|
import LinkTransaction from "component/linkTransaction";
|
|
|
|
import { CreditAmount } from "component/common";
|
|
|
|
|
|
|
|
class TransactionTableBody extends React.PureComponent {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2017-09-02 19:50:40 +02:00
|
|
|
getClaimLink(claim_name, claim_id) {
|
|
|
|
let uri = `lbry://${claim_name}#${claim_id}`;
|
|
|
|
|
|
|
|
return (
|
2017-09-04 19:35:41 +02:00
|
|
|
<a className="button-text" onClick={() => this.props.navigate(uri)}>
|
2017-09-02 19:50:40 +02:00
|
|
|
{claim_name}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-09-02 17:36:27 +02:00
|
|
|
filterList(transaction) {
|
2017-09-02 19:50:40 +02:00
|
|
|
if (this.props.filter == "claim") {
|
2017-09-02 17:36:27 +02:00
|
|
|
return transaction.claim_info.length > 0;
|
2017-09-02 19:50:40 +02:00
|
|
|
} else if (this.props.filter == "support") {
|
2017-09-02 17:36:27 +02:00
|
|
|
return transaction.support_info.length > 0;
|
2017-09-02 19:50:40 +02:00
|
|
|
} else if (this.props.filter == "update") {
|
2017-09-02 17:36:27 +02:00
|
|
|
return transaction.update_info.length > 0;
|
|
|
|
} else {
|
|
|
|
return transaction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-02 19:50:40 +02:00
|
|
|
renderBody(transaction) {
|
2017-09-02 17:36:27 +02:00
|
|
|
const txid = transaction.id;
|
|
|
|
const date = transaction.date;
|
|
|
|
const fee = transaction.fee;
|
2017-09-02 19:50:40 +02:00
|
|
|
const filter = this.props.filter;
|
2017-09-04 19:35:41 +02:00
|
|
|
const options = {
|
|
|
|
weekday: "short",
|
|
|
|
year: "2-digit",
|
|
|
|
month: "short",
|
|
|
|
day: "numeric",
|
|
|
|
hour: "2-digit",
|
|
|
|
minute: "2-digit",
|
|
|
|
second: "2-digit",
|
|
|
|
};
|
2017-09-02 19:50:40 +02:00
|
|
|
|
|
|
|
if (filter == "tipSupport")
|
|
|
|
transaction["tipSupport_info"] = transaction["support_info"].filter(
|
|
|
|
tx => tx.is_tip
|
|
|
|
);
|
2017-09-02 17:36:27 +02:00
|
|
|
|
|
|
|
return filter != "unfiltered"
|
|
|
|
? transaction[`${filter}_info`].map(item => {
|
|
|
|
return (
|
|
|
|
<tr key={`${txid}:${item.nout}`}>
|
|
|
|
<td>
|
|
|
|
{date
|
2017-09-04 19:35:41 +02:00
|
|
|
? date.toLocaleDateString("en-US", options)
|
2017-09-02 17:36:27 +02:00
|
|
|
: <span className="empty">
|
|
|
|
{__("(Transaction pending)")}
|
|
|
|
</span>}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<CreditAmount
|
|
|
|
amount={item.amount}
|
|
|
|
look="plain"
|
2017-09-04 19:35:41 +02:00
|
|
|
label={false}
|
2017-09-02 17:36:27 +02:00
|
|
|
showPlus={true}
|
|
|
|
precision={8}
|
2017-09-04 19:35:41 +02:00
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<CreditAmount
|
|
|
|
amount={fee}
|
|
|
|
look="plain"
|
|
|
|
fee={true}
|
|
|
|
label={false}
|
|
|
|
precision={8}
|
|
|
|
/>
|
2017-09-02 17:36:27 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
2017-09-02 19:50:40 +02:00
|
|
|
{this.getClaimLink(item.claim_name, item.claim_id)}
|
2017-09-02 17:36:27 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<LinkTransaction id={txid} />
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
: <tr key={txid}>
|
|
|
|
<td>
|
|
|
|
{date
|
2017-09-04 19:35:41 +02:00
|
|
|
? date.toLocaleDateString("en-US", options)
|
2017-09-02 17:36:27 +02:00
|
|
|
: <span className="empty">
|
|
|
|
{__("(Transaction pending)")}
|
|
|
|
</span>}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<CreditAmount
|
|
|
|
amount={transaction.amount}
|
|
|
|
look="plain"
|
2017-09-04 19:35:41 +02:00
|
|
|
label={false}
|
2017-09-02 17:36:27 +02:00
|
|
|
showPlus={true}
|
|
|
|
precision={8}
|
2017-09-04 19:35:41 +02:00
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<CreditAmount
|
|
|
|
amount={fee}
|
|
|
|
look="plain"
|
|
|
|
fee={true}
|
|
|
|
label={false}
|
|
|
|
precision={8}
|
|
|
|
/>
|
2017-09-02 17:36:27 +02:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<LinkTransaction id={txid} />
|
|
|
|
</td>
|
|
|
|
</tr>;
|
|
|
|
}
|
|
|
|
|
2017-09-02 19:50:40 +02:00
|
|
|
removeFeeTx(transaction) {
|
|
|
|
if (this.props.filter == "unfiltered")
|
|
|
|
return Math.abs(transaction.amount) != Math.abs(transaction.fee);
|
|
|
|
else return true;
|
|
|
|
}
|
|
|
|
|
2017-09-02 17:36:27 +02:00
|
|
|
render() {
|
|
|
|
const { transactions, filter } = this.props;
|
2017-09-16 13:02:54 +02:00
|
|
|
let transactionList = transactions
|
|
|
|
.filter(this.filterList, this)
|
|
|
|
.filter(this.removeFeeTx, this)
|
|
|
|
.map(this.renderBody, this);
|
|
|
|
|
|
|
|
if (transactionList.length == 0) {
|
|
|
|
return (
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td className="empty" colSpan="3">
|
|
|
|
{__("There are no transactions of this type.")}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
);
|
|
|
|
}
|
2017-09-02 17:36:27 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<tbody>
|
2017-09-16 13:02:54 +02:00
|
|
|
{transactionList}
|
2017-09-02 17:36:27 +02:00
|
|
|
</tbody>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TransactionTableBody;
|