2021-08-13 19:59:43 +02:00
|
|
|
// @flow
|
|
|
|
import React from 'react';
|
|
|
|
import Button from 'component/button';
|
|
|
|
import { Lbryio } from 'lbryinc';
|
|
|
|
import moment from 'moment';
|
|
|
|
import { STRIPE_PUBLIC_KEY } from 'config';
|
|
|
|
|
|
|
|
let stripeEnvironment = 'test';
|
|
|
|
// if the key contains pk_live it's a live key
|
|
|
|
// update the environment for the calls to the backend to indicate which environment to hit
|
|
|
|
if (STRIPE_PUBLIC_KEY.indexOf('pk_live') > -1) {
|
|
|
|
stripeEnvironment = 'live';
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
accountDetails: any,
|
|
|
|
transactions: any,
|
|
|
|
};
|
|
|
|
|
|
|
|
const WalletBalance = (props: Props) => {
|
|
|
|
// receive transactions from parent component
|
2021-08-13 20:22:33 +02:00
|
|
|
const { transactions: accountTransactions } = props;
|
2021-08-13 19:59:43 +02:00
|
|
|
|
|
|
|
const [lastFour, setLastFour] = React.useState();
|
|
|
|
|
|
|
|
function getCustomerStatus() {
|
|
|
|
return Lbryio.call(
|
|
|
|
'customer',
|
|
|
|
'status',
|
|
|
|
{
|
|
|
|
environment: stripeEnvironment,
|
|
|
|
},
|
|
|
|
'post'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this is actually incorrect, last4 should be populated based on the transaction not the current customer details
|
|
|
|
React.useEffect(() => {
|
|
|
|
(async function() {
|
|
|
|
const customerStatusResponse = await getCustomerStatus();
|
|
|
|
|
|
|
|
const lastFour = customerStatusResponse.PaymentMethods && customerStatusResponse.PaymentMethods.length && customerStatusResponse.PaymentMethods[0].card.last4;
|
|
|
|
|
|
|
|
setLastFour(lastFour);
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-08-19 16:30:47 +02:00
|
|
|
<div className="section card-stack">
|
2021-08-19 17:11:51 +02:00
|
|
|
<div className="table__wrapper">
|
|
|
|
<table className="table table--transactions">
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* table header */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th className="date-header">{__('Date')}</th>
|
|
|
|
<th>{<>{__('Receiving Channel Name')}</>}</th>
|
|
|
|
<th>{__('Tip Location')}</th>
|
|
|
|
<th>{__('Amount (USD)')} </th>
|
|
|
|
<th>{__('Card Last 4')}</th>
|
|
|
|
<th>{__('Anonymous')}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* list data for transactions */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<tbody>
|
|
|
|
{accountTransactions &&
|
|
|
|
accountTransactions.map((transaction) => (
|
|
|
|
<tr key={transaction.name + transaction.created_at}>
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* date */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<td>{moment(transaction.created_at).format('LLL')}</td>
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* receiving channel name */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<td>
|
|
|
|
<Button
|
|
|
|
className=""
|
|
|
|
navigate={'/' + transaction.channel_name + ':' + transaction.channel_claim_id}
|
|
|
|
label={transaction.channel_name}
|
|
|
|
button="link"
|
|
|
|
/>
|
|
|
|
</td>
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* link to content or channel */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<td>
|
|
|
|
<Button
|
|
|
|
className=""
|
|
|
|
navigate={'/' + transaction.channel_name + ':' + transaction.source_claim_id}
|
|
|
|
label={
|
|
|
|
transaction.channel_claim_id === transaction.source_claim_id
|
|
|
|
? 'Channel Page'
|
|
|
|
: 'Content Page'
|
|
|
|
}
|
|
|
|
button="link"
|
|
|
|
/>
|
|
|
|
</td>
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* how much tipped */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<td>${transaction.tipped_amount / 100}</td>
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* TODO: this is incorrect need it per transactions not per user */}
|
|
|
|
{/* last four of credit card */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<td>{lastFour}</td>
|
2021-08-19 19:55:06 +02:00
|
|
|
{/* whether tip is anonymous or not */}
|
2021-08-19 17:11:51 +02:00
|
|
|
<td>{transaction.private_tip ? 'Yes' : 'No'}</td>
|
|
|
|
</tr>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2021-08-19 19:41:58 +02:00
|
|
|
{/* show some markup if there's no transactions */}
|
2021-08-19 17:11:51 +02:00
|
|
|
{(!accountTransactions || accountTransactions.length === 0) && <p style={{textAlign: 'center', marginTop: '20px', fontSize: '13px', color: 'rgb(171, 171, 171)'}}>No Transactions</p>}
|
|
|
|
</div>
|
2021-08-19 16:30:47 +02:00
|
|
|
</div>
|
2021-08-13 19:59:43 +02:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WalletBalance;
|