2017-03-28 05:07:52 -04:00
|
|
|
import React from 'react';
|
2017-05-02 12:31:51 +07:00
|
|
|
import lbryio from 'lbryio';
|
|
|
|
import {CreditAmount, Icon} from 'component/common.js';
|
2017-05-05 12:28:28 +07:00
|
|
|
import SubHeader from 'component/subHeader'
|
2017-05-02 12:31:51 +07:00
|
|
|
import {RewardLink} from 'component/reward-link';
|
2017-03-28 05:07:52 -04:00
|
|
|
|
2017-05-17 04:10:25 -04:00
|
|
|
export class RewardTile extends React.Component {
|
|
|
|
static propTypes = {
|
2017-04-10 08:32:40 -04:00
|
|
|
type: React.PropTypes.string.isRequired,
|
2017-03-29 18:44:18 -04:00
|
|
|
title: React.PropTypes.string.isRequired,
|
|
|
|
description: React.PropTypes.string.isRequired,
|
|
|
|
claimed: React.PropTypes.bool.isRequired,
|
|
|
|
value: React.PropTypes.number.isRequired,
|
2017-04-10 08:32:40 -04:00
|
|
|
onRewardClaim: React.PropTypes.func
|
2017-05-17 04:10:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-03-28 05:07:52 -04:00
|
|
|
return (
|
|
|
|
<section className="card">
|
2017-04-10 08:32:40 -04: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 05:07:52 -04:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
2017-05-17 04:10:25 -04:00
|
|
|
}
|
2017-03-28 05:07:52 -04:00
|
|
|
|
2017-05-17 04:10:25 -04:00
|
|
|
export class RewardsPage extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-04-10 08:32:40 -04:00
|
|
|
userRewards: null,
|
2017-05-17 04:10:25 -04:00
|
|
|
failed: null,
|
2017-03-28 05:07:52 -04:00
|
|
|
};
|
2017-05-17 04:10:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.loadRewards()
|
|
|
|
}
|
|
|
|
|
|
|
|
loadRewards() {
|
2017-04-10 08:32:40 -04:00
|
|
|
lbryio.call('reward', 'list', {}).then((userRewards) => {
|
|
|
|
this.setState({
|
|
|
|
userRewards: userRewards,
|
|
|
|
});
|
2017-04-14 18:23:42 -04:00
|
|
|
}, () => {
|
|
|
|
this.setState({failed: true })
|
2017-04-10 08:32:40 -04:00
|
|
|
});
|
2017-05-17 04:10:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-03-28 05:07:52 -04:00
|
|
|
return (
|
2017-04-30 20:15:21 -04:00
|
|
|
<main className="main--single-column">
|
2017-05-05 12:28:28 +07:00
|
|
|
<SubHeader />
|
2017-04-27 09:17:18 -04:00
|
|
|
<div>
|
2017-04-10 08:32:40 -04:00
|
|
|
{!this.state.userRewards
|
2017-04-14 18:23:42 -04:00
|
|
|
? (this.state.failed ? <div className="empty">Failed to load rewards.</div> : '')
|
2017-05-11 13:46:41 -04: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 08:32:40 -04:00
|
|
|
})}
|
2017-04-27 09:17:18 -04:00
|
|
|
</div>
|
2017-03-28 05:07:52 -04:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
2017-05-17 04:10:25 -04:00
|
|
|
}
|
2017-03-28 05:07:52 -04:00
|
|
|
|
|
|
|
export default RewardsPage;
|