2017-03-28 11:07:52 +02:00
|
|
|
import React from 'react';
|
2017-05-02 07:31:51 +02:00
|
|
|
import lbryio from 'lbryio';
|
|
|
|
import {CreditAmount, Icon} from 'component/common.js';
|
2017-05-05 07:28:28 +02:00
|
|
|
import SubHeader from 'component/subHeader'
|
2017-05-02 07:31:51 +02:00
|
|
|
import {RewardLink} from 'component/reward-link';
|
2017-03-28 11:07:52 +02:00
|
|
|
|
2017-05-17 10:10:25 +02:00
|
|
|
export class RewardTile extends React.Component {
|
|
|
|
static propTypes = {
|
2017-04-10 14:32:40 +02:00
|
|
|
type: React.PropTypes.string.isRequired,
|
2017-03-30 00:44:18 +02:00
|
|
|
title: React.PropTypes.string.isRequired,
|
|
|
|
description: React.PropTypes.string.isRequired,
|
|
|
|
claimed: React.PropTypes.bool.isRequired,
|
|
|
|
value: React.PropTypes.number.isRequired,
|
2017-04-10 14:32:40 +02:00
|
|
|
onRewardClaim: React.PropTypes.func
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-03-28 11:07:52 +02:00
|
|
|
return (
|
|
|
|
<section className="card">
|
2017-04-10 14:32:40 +02:00
|
|
|
<div className="card__inner">
|
|
|
|
<div className="card__title-primary">
|
|
|
|
<CreditAmount amount={this.props.value} />
|
|
|
|
<h3>{this.props.title}</h3>
|
|
|
|
</div>
|
|
|
|
<div className="card__actions">
|
|
|
|
{this.props.claimed
|
|
|
|
? <span><Icon icon="icon-check" /> Reward claimed.</span>
|
|
|
|
: <RewardLink {...this.props} />}
|
|
|
|
</div>
|
|
|
|
<div className="card__content">{this.props.description}</div>
|
2017-03-28 11:07:52 +02:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
2017-03-28 11:07:52 +02:00
|
|
|
|
2017-05-17 10:10:25 +02:00
|
|
|
export class RewardsPage extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-04-10 14:32:40 +02:00
|
|
|
userRewards: null,
|
2017-05-17 10:10:25 +02:00
|
|
|
failed: null,
|
2017-03-28 11:07:52 +02:00
|
|
|
};
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.loadRewards()
|
|
|
|
}
|
|
|
|
|
|
|
|
loadRewards() {
|
2017-04-10 14:32:40 +02:00
|
|
|
lbryio.call('reward', 'list', {}).then((userRewards) => {
|
|
|
|
this.setState({
|
|
|
|
userRewards: userRewards,
|
|
|
|
});
|
2017-04-15 00:23:42 +02:00
|
|
|
}, () => {
|
|
|
|
this.setState({failed: true })
|
2017-04-10 14:32:40 +02:00
|
|
|
});
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-03-28 11:07:52 +02:00
|
|
|
return (
|
2017-05-01 02:15:21 +02:00
|
|
|
<main className="main--single-column">
|
2017-05-05 07:28:28 +02:00
|
|
|
<SubHeader />
|
2017-04-27 15:17:18 +02:00
|
|
|
<div>
|
2017-04-10 14:32:40 +02:00
|
|
|
{!this.state.userRewards
|
2017-04-15 00:23:42 +02:00
|
|
|
? (this.state.failed ? <div className="empty">Failed to load rewards.</div> : '')
|
2017-05-11 19:46:41 +02:00
|
|
|
: this.state.userRewards.map(({reward_type, reward_title, reward_description, transaction_id, reward_amount}) => {
|
|
|
|
return <RewardTile key={reward_type} onRewardClaim={this.loadRewards} type={reward_type} title={reward_title} description={reward_description} claimed={!!transaction_id} value={reward_amount} />;
|
2017-04-10 14:32:40 +02:00
|
|
|
})}
|
2017-04-27 15:17:18 +02:00
|
|
|
</div>
|
2017-03-28 11:07:52 +02:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
2017-03-28 11:07:52 +02:00
|
|
|
|
|
|
|
export default RewardsPage;
|