Fix memo: stake indicator
This commit is contained in:
parent
6492fe1c66
commit
827a08ac26
5 changed files with 43 additions and 49 deletions
|
@ -1,15 +1,15 @@
|
|||
import { connect } from 'react-redux';
|
||||
import {
|
||||
makeSelectClaimForUri,
|
||||
makeSelectStakedLevelForChannelUri,
|
||||
makeSelectTotalStakedAmountForChannelUri,
|
||||
selectClaimForUri,
|
||||
selectStakedLevelForChannelUri,
|
||||
selectTotalStakedAmountForChannelUri,
|
||||
} from 'redux/selectors/claims';
|
||||
import ChannelStakedIndicator from './view';
|
||||
|
||||
const select = (state, props) => ({
|
||||
channelClaim: makeSelectClaimForUri(props.uri)(state),
|
||||
amount: makeSelectTotalStakedAmountForChannelUri(props.uri)(state),
|
||||
level: makeSelectStakedLevelForChannelUri(props.uri)(state),
|
||||
channelClaim: selectClaimForUri(state, props.uri),
|
||||
amount: selectTotalStakedAmountForChannelUri(state, props.uri),
|
||||
level: selectStakedLevelForChannelUri(state, props.uri),
|
||||
});
|
||||
|
||||
export default connect(select)(ChannelStakedIndicator);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { connect } from 'react-redux';
|
||||
import {
|
||||
makeSelectStakedLevelForChannelUri,
|
||||
selectStakedLevelForChannelUri,
|
||||
makeSelectClaimForUri,
|
||||
makeSelectThumbnailForUri,
|
||||
selectHasChannels,
|
||||
|
@ -33,7 +33,7 @@ const select = (state, props) => {
|
|||
activeChannelClaim,
|
||||
hasChannels: selectHasChannels(state),
|
||||
playingUri: selectPlayingUri(state),
|
||||
stakedLevel: makeSelectStakedLevelForChannelUri(props.authorUri)(state),
|
||||
stakedLevel: selectStakedLevelForChannelUri(state, props.authorUri),
|
||||
linkedCommentAncestors: selectLinkedCommentAncestors(state),
|
||||
totalReplyPages: makeSelectTotalReplyPagesForParentId(props.commentId)(state),
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { makeSelectStakedLevelForChannelUri, selectClaimForUri } from 'redux/selectors/claims';
|
||||
import { selectStakedLevelForChannelUri, selectClaimForUri } from 'redux/selectors/claims';
|
||||
import LivestreamComment from './view';
|
||||
|
||||
const select = (state, props) => ({
|
||||
claim: selectClaimForUri(state, props.uri),
|
||||
stakedLevel: makeSelectStakedLevelForChannelUri(props.authorUri)(state),
|
||||
stakedLevel: selectStakedLevelForChannelUri(state, props.authorUri),
|
||||
});
|
||||
|
||||
export default connect(select)(LivestreamComment);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { createSelector } from 'reselect';
|
||||
import { selectClaimWithId, selectMyChannelClaims, makeSelectStakedLevelForChannelUri } from 'redux/selectors/claims';
|
||||
import { selectClaimWithId, selectMyChannelClaims, selectStakedLevelForChannelUri } from 'redux/selectors/claims';
|
||||
|
||||
export const selectState = (state) => state.app || {};
|
||||
|
||||
|
@ -97,18 +97,14 @@ export const selectActiveChannelClaim = createSelector(
|
|||
}
|
||||
);
|
||||
|
||||
export const selectActiveChannelStakedLevel = createSelector(
|
||||
(state) => state,
|
||||
selectActiveChannelClaim,
|
||||
(state, activeChannelClaim) => {
|
||||
if (!activeChannelClaim) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const uri = activeChannelClaim.permanent_url;
|
||||
const stakedLevel = makeSelectStakedLevelForChannelUri(uri)(state);
|
||||
return stakedLevel;
|
||||
export const selectActiveChannelStakedLevel = (state) => {
|
||||
const activeChannelClaim = selectActiveChannelClaim(state);
|
||||
if (!activeChannelClaim) {
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
|
||||
const uri = activeChannelClaim.permanent_url;
|
||||
return selectStakedLevelForChannelUri(state, uri);
|
||||
};
|
||||
|
||||
export const selectIncognito = (state) => selectState(state).incognito;
|
||||
|
|
|
@ -704,34 +704,32 @@ export const makeSelectClaimIsStreamPlaceholder = (uri: string) =>
|
|||
return Boolean(claim.value_type === 'stream' && !claim.value.source);
|
||||
});
|
||||
|
||||
export const makeSelectTotalStakedAmountForChannelUri = (uri: string) =>
|
||||
createSelector(makeSelectClaimForUri(uri), (claim) => {
|
||||
if (!claim || !claim.amount || !claim.meta || !claim.meta.support_amount) {
|
||||
return 0;
|
||||
}
|
||||
export const selectTotalStakedAmountForChannelUri = createCachedSelector(selectClaimForUri, (claim) => {
|
||||
if (!claim || !claim.amount || !claim.meta || !claim.meta.support_amount) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return parseFloat(claim.amount) + parseFloat(claim.meta.support_amount) || 0;
|
||||
});
|
||||
return parseFloat(claim.amount) + parseFloat(claim.meta.support_amount) || 0;
|
||||
})((state, uri) => String(uri));
|
||||
|
||||
export const makeSelectStakedLevelForChannelUri = (uri: string) =>
|
||||
createSelector(makeSelectTotalStakedAmountForChannelUri(uri), (amount) => {
|
||||
let level = 1;
|
||||
switch (true) {
|
||||
case amount >= CLAIM.LEVEL_2_STAKED_AMOUNT && amount < CLAIM.LEVEL_3_STAKED_AMOUNT:
|
||||
level = 2;
|
||||
break;
|
||||
case amount >= CLAIM.LEVEL_3_STAKED_AMOUNT && amount < CLAIM.LEVEL_4_STAKED_AMOUNT:
|
||||
level = 3;
|
||||
break;
|
||||
case amount >= CLAIM.LEVEL_4_STAKED_AMOUNT && amount < CLAIM.LEVEL_5_STAKED_AMOUNT:
|
||||
level = 4;
|
||||
break;
|
||||
case amount >= CLAIM.LEVEL_5_STAKED_AMOUNT:
|
||||
level = 5;
|
||||
break;
|
||||
}
|
||||
return level;
|
||||
});
|
||||
export const selectStakedLevelForChannelUri = createCachedSelector(selectTotalStakedAmountForChannelUri, (amount) => {
|
||||
let level = 1;
|
||||
switch (true) {
|
||||
case amount >= CLAIM.LEVEL_2_STAKED_AMOUNT && amount < CLAIM.LEVEL_3_STAKED_AMOUNT:
|
||||
level = 2;
|
||||
break;
|
||||
case amount >= CLAIM.LEVEL_3_STAKED_AMOUNT && amount < CLAIM.LEVEL_4_STAKED_AMOUNT:
|
||||
level = 3;
|
||||
break;
|
||||
case amount >= CLAIM.LEVEL_4_STAKED_AMOUNT && amount < CLAIM.LEVEL_5_STAKED_AMOUNT:
|
||||
level = 4;
|
||||
break;
|
||||
case amount >= CLAIM.LEVEL_5_STAKED_AMOUNT:
|
||||
level = 5;
|
||||
break;
|
||||
}
|
||||
return level;
|
||||
})((state, uri) => String(uri));
|
||||
|
||||
export const selectUpdatingCollection = (state: State) => selectState(state).updatingCollection;
|
||||
export const selectUpdateCollectionError = (state: State) => selectState(state).updateCollectionError;
|
||||
|
|
Loading…
Reference in a new issue