2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2019-01-08 19:03:49 +01:00
|
|
|
import type { Transaction } from 'types/transaction';
|
2018-11-26 02:21:25 +01:00
|
|
|
import * as ICONS from 'constants/icons';
|
2018-03-26 23:32:43 +02:00
|
|
|
import React from 'react';
|
|
|
|
import ButtonTransaction from 'component/common/transaction-link';
|
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
|
|
|
import DateTime from 'component/dateTime';
|
|
|
|
import Button from 'component/button';
|
2018-04-18 06:03:01 +02:00
|
|
|
import { buildURI } from 'lbry-redux';
|
2018-03-26 23:32:43 +02:00
|
|
|
import * as txnTypes from 'constants/transaction_types';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
transaction: Transaction,
|
|
|
|
revokeClaim: (string, number) => void,
|
|
|
|
isRevokeable: boolean,
|
|
|
|
reward: ?{
|
|
|
|
reward_title: string,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
class TransactionListItem extends React.PureComponent<Props> {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
(this: any).abandonClaim = this.abandonClaim.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
getLink(type: string) {
|
|
|
|
if (type === txnTypes.TIP) {
|
2018-04-23 07:08:55 +02:00
|
|
|
return <Button icon={ICONS.UNLOCK} onClick={this.abandonClaim} title={__('Unlock Tip')} />;
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
2019-01-22 21:36:28 +01:00
|
|
|
return <Button icon={ICONS.DELETE} onClick={this.abandonClaim} title={__('Abandon Claim')} />;
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:50:04 +02:00
|
|
|
abandonClaim() {
|
|
|
|
const { txid, nout } = this.props.transaction;
|
|
|
|
|
|
|
|
this.props.revokeClaim(txid, nout);
|
2018-03-26 23:32:43 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:50:04 +02:00
|
|
|
capitalize = (string: string) => string.charAt(0).toUpperCase() + string.slice(1);
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
render() {
|
|
|
|
const { reward, transaction, isRevokeable } = this.props;
|
|
|
|
const { amount, claim_id: claimId, claim_name: name, date, fee, txid, type } = transaction;
|
|
|
|
|
|
|
|
const dateFormat = {
|
|
|
|
month: 'short',
|
|
|
|
day: 'numeric',
|
|
|
|
year: 'numeric',
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<tr>
|
|
|
|
<td>
|
2019-01-08 19:48:09 +01:00
|
|
|
<CreditAmount badge={false} showPlus amount={amount} precision={8} />
|
2018-03-26 23:32:43 +02:00
|
|
|
<br />
|
|
|
|
|
|
|
|
{fee !== 0 && (
|
|
|
|
<span className="table__item-label">
|
2019-01-08 19:48:09 +01:00
|
|
|
<CreditAmount badge={false} fee amount={fee} precision={8} />
|
2018-03-26 23:32:43 +02:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
<td className="table__item--actionable">
|
|
|
|
<span>{this.capitalize(type)}</span> {isRevokeable && this.getLink(type)}
|
|
|
|
</td>
|
|
|
|
<td className="table__item--actionable">
|
|
|
|
{reward && <span>{reward.reward_title}</span>}
|
2019-01-08 19:03:49 +01:00
|
|
|
{name &&
|
|
|
|
claimId && (
|
|
|
|
<Button
|
|
|
|
constrict
|
|
|
|
button="link"
|
|
|
|
navigate="/show"
|
|
|
|
navigateParams={{ uri: buildURI({ claimName: name, claimId }) }}
|
|
|
|
>
|
|
|
|
{name}
|
|
|
|
</Button>
|
|
|
|
)}
|
2018-03-26 23:32:43 +02:00
|
|
|
</td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
<ButtonTransaction id={txid} />
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
{date ? (
|
|
|
|
<div>
|
|
|
|
<DateTime date={date} show={DateTime.SHOW_DATE} formatOptions={dateFormat} />
|
|
|
|
<div className="table__item-label">
|
|
|
|
<DateTime date={date} show={DateTime.SHOW_TIME} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<span className="empty">{__('Pending')}</span>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TransactionListItem;
|