Move getChannelLevel to a selector. Requires accompanying lbry-redux PR.

This commit is contained in:
infinite-persistence 2021-03-09 14:59:38 +08:00 committed by Sean Yesmunt
parent dbbe499a86
commit 9192828505
2 changed files with 10 additions and 25 deletions

View file

@ -1,9 +1,15 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri } from 'lbry-redux';
import {
makeSelectClaimForUri,
makeSelectStakedLevelForChannelUri,
makeSelectTotalStakedAmountForChannelUri,
} from 'lbry-redux';
import ChannelStakedIndicator from './view';
const select = (state, props) => ({
channelClaim: makeSelectClaimForUri(props.uri)(state),
amount: makeSelectTotalStakedAmountForChannelUri(props.uri)(state),
level: makeSelectStakedLevelForChannelUri(props.uri)(state),
});
export default connect(select)(ChannelStakedIndicator);

View file

@ -10,31 +10,12 @@ import CreditAmount from 'component/common/credit-amount';
type Props = {
channelClaim: ChannelClaim,
amount: number,
level: number,
large?: boolean,
inline?: boolean,
};
function getChannelLevel(amount: number): number {
let level = 1;
switch (true) {
case amount >= 1 && amount < 50:
level = 2;
break;
case amount >= 50 && amount < 250:
level = 3;
break;
case amount >= 250 && amount < 1000:
level = 4;
break;
case amount >= 1000:
level = 5;
break;
}
return level;
}
function getChannelIcon(level: number): string {
const icons = {
'1': ICONS.CHANNEL_LEVEL_1,
@ -48,15 +29,13 @@ function getChannelIcon(level: number): string {
}
function ChannelStakedIndicator(props: Props) {
const { channelClaim, large = false, inline = false } = props;
const { channelClaim, amount, level, large = false, inline = false } = props;
if (!channelClaim || !channelClaim.meta) {
return null;
}
const amount = parseFloat(channelClaim.amount) + parseFloat(channelClaim.meta.support_amount) || 0;
const isControlling = channelClaim && channelClaim.meta.is_controlling;
const level = getChannelLevel(amount);
const icon = getChannelIcon(level);
return (