2021-02-16 22:09:20 +01:00
|
|
|
// @flow
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import React from 'react';
|
|
|
|
import classnames from 'classnames';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import LbcSymbol from 'component/common/lbc-symbol';
|
|
|
|
import Tooltip from 'component/common/tooltip';
|
|
|
|
import CreditAmount from 'component/common/credit-amount';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
channelClaim: ChannelClaim,
|
2021-03-09 07:59:38 +01:00
|
|
|
amount: number,
|
|
|
|
level: number,
|
2021-02-16 22:09:20 +01:00
|
|
|
large?: boolean,
|
2021-03-03 19:50:16 +01:00
|
|
|
inline?: boolean,
|
2022-04-17 19:04:56 +02:00
|
|
|
hideTooltip?: Boolean,
|
2021-02-16 22:09:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function getChannelIcon(level: number): string {
|
|
|
|
const icons = {
|
|
|
|
'1': ICONS.CHANNEL_LEVEL_1,
|
|
|
|
'2': ICONS.CHANNEL_LEVEL_2,
|
|
|
|
'3': ICONS.CHANNEL_LEVEL_3,
|
|
|
|
'4': ICONS.CHANNEL_LEVEL_4,
|
|
|
|
'5': ICONS.CHANNEL_LEVEL_5,
|
|
|
|
};
|
|
|
|
|
|
|
|
return icons[level] || ICONS.CHANNEL_LEVEL_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ChannelStakedIndicator(props: Props) {
|
2022-04-17 19:04:56 +02:00
|
|
|
const { channelClaim, amount, level, large = false, inline = false, hideTooltip } = props;
|
2021-02-16 22:09:20 +01:00
|
|
|
|
|
|
|
if (!channelClaim || !channelClaim.meta) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isControlling = channelClaim && channelClaim.meta.is_controlling;
|
|
|
|
const icon = getChannelIcon(level);
|
|
|
|
|
2022-04-17 19:04:56 +02:00
|
|
|
if (!hideTooltip) {
|
|
|
|
return (
|
|
|
|
<Tooltip
|
|
|
|
title={
|
|
|
|
<div className="channel-staked__tooltip">
|
|
|
|
<div className="channel-staked__tooltip-icons">
|
|
|
|
<LevelIcon icon={icon} isControlling={isControlling} size={isControlling ? 14 : 10} />
|
|
|
|
</div>
|
2021-02-16 22:09:20 +01:00
|
|
|
|
2022-04-17 19:04:56 +02:00
|
|
|
<div className="channel-staked__tooltip-text">
|
|
|
|
<span>{__('Level %current_level%', { current_level: level })}</span>
|
|
|
|
<div className="channel-staked__amount">
|
|
|
|
<LbcSymbol postfix={<CreditAmount amount={amount} showLBC={false} />} size={14} />
|
|
|
|
</div>
|
2021-02-16 22:09:20 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-17 19:04:56 +02:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={classnames('channel-staked__wrapper', {
|
|
|
|
'channel-staked__wrapper--large': large,
|
|
|
|
'channel-staked__wrapper--inline': inline,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<LevelIcon icon={icon} large={large} isControlling={isControlling} />
|
2021-02-16 22:59:05 +01:00
|
|
|
</div>
|
2022-04-17 19:04:56 +02:00
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2022-01-27 03:14:36 +01:00
|
|
|
<div
|
|
|
|
className={classnames('channel-staked__wrapper', {
|
|
|
|
'channel-staked__wrapper--large': large,
|
|
|
|
'channel-staked__wrapper--inline': inline,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<LevelIcon icon={icon} large={large} isControlling={isControlling} />
|
|
|
|
</div>
|
2022-04-17 19:04:56 +02:00
|
|
|
);
|
|
|
|
}
|
2021-02-16 22:09:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type LevelIconProps = {
|
|
|
|
isControlling: boolean,
|
|
|
|
icon: string,
|
|
|
|
large?: boolean,
|
|
|
|
};
|
|
|
|
|
|
|
|
function LevelIcon(props: LevelIconProps) {
|
|
|
|
const { large, isControlling, icon } = props;
|
|
|
|
return (
|
|
|
|
icon && (
|
|
|
|
<Icon
|
|
|
|
icon={icon}
|
|
|
|
size={large ? 36 : 14}
|
|
|
|
className={classnames('channel-staked__indicator', {
|
|
|
|
'channel-staked__indicator--large': large,
|
|
|
|
'channel-staked__indicator--controlling': isControlling,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChannelStakedIndicator;
|