Fix memo: stake indicator

This commit is contained in:
infinite-persistence 2021-11-10 23:30:58 +08:00
parent 6492fe1c66
commit 827a08ac26
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
5 changed files with 43 additions and 49 deletions

View file

@ -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);

View file

@ -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),
};

View file

@ -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);

View file

@ -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) => {
export const selectActiveChannelStakedLevel = (state) => {
const activeChannelClaim = selectActiveChannelClaim(state);
if (!activeChannelClaim) {
return 0;
}
const uri = activeChannelClaim.permanent_url;
const stakedLevel = makeSelectStakedLevelForChannelUri(uri)(state);
return stakedLevel;
}
);
return selectStakedLevelForChannelUri(state, uri);
};
export const selectIncognito = (state) => selectState(state).incognito;

View file

@ -704,17 +704,15 @@ export const makeSelectClaimIsStreamPlaceholder = (uri: string) =>
return Boolean(claim.value_type === 'stream' && !claim.value.source);
});
export const makeSelectTotalStakedAmountForChannelUri = (uri: string) =>
createSelector(makeSelectClaimForUri(uri), (claim) => {
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;
});
})((state, uri) => String(uri));
export const makeSelectStakedLevelForChannelUri = (uri: string) =>
createSelector(makeSelectTotalStakedAmountForChannelUri(uri), (amount) => {
export const selectStakedLevelForChannelUri = createCachedSelector(selectTotalStakedAmountForChannelUri, (amount) => {
let level = 1;
switch (true) {
case amount >= CLAIM.LEVEL_2_STAKED_AMOUNT && amount < CLAIM.LEVEL_3_STAKED_AMOUNT:
@ -731,7 +729,7 @@ export const makeSelectStakedLevelForChannelUri = (uri: string) =>
break;
}
return level;
});
})((state, uri) => String(uri));
export const selectUpdatingCollection = (state: State) => selectState(state).updatingCollection;
export const selectUpdateCollectionError = (state: State) => selectState(state).updateCollectionError;