2018-04-12 22:50:32 +02:00
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
import React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2017-05-26 10:53:32 +02:00
|
|
|
|
2018-04-12 22:50:32 +02:00
|
|
|
type Reward = {
|
|
|
|
reward_amount: number,
|
2019-09-04 23:37:28 +02:00
|
|
|
reward_range: string,
|
2018-04-12 22:50:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
isPending: boolean,
|
|
|
|
label: ?string,
|
|
|
|
reward: Reward,
|
2018-04-23 07:17:54 +02:00
|
|
|
button: ?boolean,
|
2018-04-12 22:50:32 +02:00
|
|
|
claimReward: Reward => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
const RewardLink = (props: Props) => {
|
2019-01-17 07:34:31 +01:00
|
|
|
const { reward, claimReward, label, isPending, button } = props;
|
2019-09-10 18:15:25 +02:00
|
|
|
let displayLabel = label;
|
|
|
|
if (isPending) {
|
|
|
|
displayLabel = __('Claiming...');
|
|
|
|
} else if (label) {
|
|
|
|
displayLabel = label;
|
|
|
|
} else if (reward && reward.reward_range && reward.reward_range.includes('-')) {
|
2020-08-27 20:50:43 +02:00
|
|
|
displayLabel = __('Claim %range% LBC', { range: reward.reward_range });
|
2019-09-10 18:15:25 +02:00
|
|
|
} else if (reward && reward.reward_amount > 0) {
|
2020-08-27 20:50:43 +02:00
|
|
|
displayLabel = __('Claim %amount% LBC', { amount: reward.reward_amount });
|
2019-09-10 18:15:25 +02:00
|
|
|
} else {
|
2020-08-27 20:50:43 +02:00
|
|
|
displayLabel = __('Claim ??? LBC');
|
2019-09-10 18:15:25 +02:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
return !reward ? null : (
|
2019-02-04 18:45:30 +01:00
|
|
|
<Button
|
2019-09-26 18:07:11 +02:00
|
|
|
button={button ? 'primary' : 'link'}
|
2019-02-04 18:45:30 +01:00
|
|
|
disabled={isPending}
|
2019-09-10 18:15:25 +02:00
|
|
|
label={displayLabel}
|
2019-02-04 18:45:30 +01:00
|
|
|
onClick={() => {
|
|
|
|
claimReward(reward);
|
|
|
|
}}
|
|
|
|
/>
|
2017-06-08 02:56:52 +02:00
|
|
|
);
|
|
|
|
};
|
2018-04-12 22:50:32 +02:00
|
|
|
|
2017-06-08 02:56:52 +02:00
|
|
|
export default RewardLink;
|