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 { connect } from 'react-redux';
import { makeSelectClaimForUri } from 'lbry-redux'; import {
makeSelectClaimForUri,
makeSelectStakedLevelForChannelUri,
makeSelectTotalStakedAmountForChannelUri,
} from 'lbry-redux';
import ChannelStakedIndicator from './view'; import ChannelStakedIndicator from './view';
const select = (state, props) => ({ const select = (state, props) => ({
channelClaim: makeSelectClaimForUri(props.uri)(state), channelClaim: makeSelectClaimForUri(props.uri)(state),
amount: makeSelectTotalStakedAmountForChannelUri(props.uri)(state),
level: makeSelectStakedLevelForChannelUri(props.uri)(state),
}); });
export default connect(select)(ChannelStakedIndicator); export default connect(select)(ChannelStakedIndicator);

View file

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