lbry-desktop/ui/js/page/rewards.js

78 lines
2.2 KiB
JavaScript
Raw Normal View History

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-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,
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() {
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
2017-05-26 22:26:06 +02:00
? <span><Icon icon="icon-check" /> {__("Reward claimed.")}</span>
2017-04-10 14:32:40 +02:00
: <RewardLink {...this.props} />}
</div>
<div className="card__content">{this.props.description}</div>
</div>
</section>
);
}
2017-05-17 10:10:25 +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-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,
});
}, () => {
this.setState({failed: true })
2017-04-10 14:32:40 +02:00
});
2017-05-17 10:10:25 +02:00
}
render() {
return (
<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-05-26 22:26:06 +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}) => {
2017-05-26 22:26:06 +02:00
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>
</main>
);
}
2017-05-17 10:10:25 +02:00
}
export default RewardsPage;