Move getChannelLevel to a selector.

## Issue
5636: Disable video previews in comments/posts made by channels below a certain channel staked level
This commit is contained in:
infiinte-persistence 2021-03-09 14:23:25 +08:00 committed by Sean Yesmunt
parent 0d2d64aca7
commit bf3645df44
4 changed files with 89 additions and 6 deletions

42
dist/bundle.es.js vendored
View file

@ -12,11 +12,22 @@ const CHANNEL_ANONYMOUS = 'anonymous';
const CHANNEL_NEW = 'new';
const PAGE_SIZE = 20;
const LEVEL_1_STAKED_AMOUNT = 1;
const LEVEL_2_STAKED_AMOUNT = 2;
const LEVEL_3_STAKED_AMOUNT = 3;
const LEVEL_4_STAKED_AMOUNT = 4;
const LEVEL_5_STAKED_AMOUNT = 5;
var claim = /*#__PURE__*/Object.freeze({
MINIMUM_PUBLISH_BID: MINIMUM_PUBLISH_BID,
CHANNEL_ANONYMOUS: CHANNEL_ANONYMOUS,
CHANNEL_NEW: CHANNEL_NEW,
PAGE_SIZE: PAGE_SIZE
PAGE_SIZE: PAGE_SIZE,
LEVEL_1_STAKED_AMOUNT: LEVEL_1_STAKED_AMOUNT,
LEVEL_2_STAKED_AMOUNT: LEVEL_2_STAKED_AMOUNT,
LEVEL_3_STAKED_AMOUNT: LEVEL_3_STAKED_AMOUNT,
LEVEL_4_STAKED_AMOUNT: LEVEL_4_STAKED_AMOUNT,
LEVEL_5_STAKED_AMOUNT: LEVEL_5_STAKED_AMOUNT
});
const WINDOW_FOCUSED = 'WINDOW_FOCUSED';
@ -2663,6 +2674,33 @@ const makeSelectTagInClaimOrChannelForUri = (uri, tag) => reselect.createSelecto
return claimTags.includes(tag) || channelTags.includes(tag);
});
const makeSelectTotalStakedAmountForChannelUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
if (!claim || !claim.amount || !claim.meta || !claim.meta.support_amount) {
return 0;
}
return parseFloat(claim.amount) + parseFloat(claim.meta.support_amount) || 0;
});
const makeSelectStakedLevelForChannelUri = uri => reselect.createSelector(makeSelectTotalStakedAmountForChannelUri(uri), amount => {
let level = LEVEL_1_STAKED_AMOUNT;
switch (true) {
case amount >= 1 && amount < 50:
level = LEVEL_2_STAKED_AMOUNT;
break;
case amount >= 50 && amount < 250:
level = LEVEL_3_STAKED_AMOUNT;
break;
case amount >= 250 && amount < 1000:
level = LEVEL_4_STAKED_AMOUNT;
break;
case amount >= 1000:
level = LEVEL_5_STAKED_AMOUNT;
break;
}
return level;
});
function numberWithCommas(x) {
var parts = x.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
@ -6613,6 +6651,7 @@ exports.makeSelectReflectingClaimForUri = makeSelectReflectingClaimForUri;
exports.makeSelectSearchDownloadUrlsCount = makeSelectSearchDownloadUrlsCount;
exports.makeSelectSearchDownloadUrlsForPage = makeSelectSearchDownloadUrlsForPage;
exports.makeSelectShortUrlForUri = makeSelectShortUrlForUri;
exports.makeSelectStakedLevelForChannelUri = makeSelectStakedLevelForChannelUri;
exports.makeSelectStreamingUrlForUri = makeSelectStreamingUrlForUri;
exports.makeSelectSupportsForUri = makeSelectSupportsForUri;
exports.makeSelectTagInClaimOrChannelForUri = makeSelectTagInClaimOrChannelForUri;
@ -6623,6 +6662,7 @@ exports.makeSelectTotalClaimsInChannelSearch = makeSelectTotalClaimsInChannelSea
exports.makeSelectTotalItemsForChannel = makeSelectTotalItemsForChannel;
exports.makeSelectTotalPagesForChannel = makeSelectTotalPagesForChannel;
exports.makeSelectTotalPagesInChannelSearch = makeSelectTotalPagesInChannelSearch;
exports.makeSelectTotalStakedAmountForChannelUri = makeSelectTotalStakedAmountForChannelUri;
exports.makeSelectUriIsStreamable = makeSelectUriIsStreamable;
exports.normalizeURI = normalizeURI;
exports.notificationsReducer = notificationsReducer;

View file

@ -3,3 +3,9 @@ export const MINIMUM_PUBLISH_BID = 0.00000001;
export const CHANNEL_ANONYMOUS = 'anonymous';
export const CHANNEL_NEW = 'new';
export const PAGE_SIZE = 20;
export const LEVEL_1_STAKED_AMOUNT = 1;
export const LEVEL_2_STAKED_AMOUNT = 2;
export const LEVEL_3_STAKED_AMOUNT = 3;
export const LEVEL_4_STAKED_AMOUNT = 4;
export const LEVEL_5_STAKED_AMOUNT = 5;

View file

@ -163,6 +163,8 @@ export {
makeSelectEffectiveAmountForUri,
makeSelectTagsForUri,
makeSelectTagInClaimOrChannelForUri,
makeSelectTotalStakedAmountForChannelUri,
makeSelectStakedLevelForChannelUri,
makeSelectContentTypeForUri,
makeSelectIsUriResolving,
makeSelectPendingClaimForUri,

View file

@ -3,7 +3,7 @@ import { normalizeURI, buildURI, parseURI } from 'lbryURI';
import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
import { createSelector } from 'reselect';
import { isClaimNsfw, filterClaims } from 'util/claim';
import { PAGE_SIZE } from 'constants/claim';
import * as CLAIM from 'constants/claim';
const selectState = state => state.claims || {};
@ -261,8 +261,8 @@ export const makeSelectMyPurchasesForPage = (query: ?string, page: number = 1) =
const fileInfos = myPurchases.map(uri => claimsByUri[uri]);
const matchingFileInfos = filterClaims(fileInfos, query);
const start = (Number(page) - 1) * Number(PAGE_SIZE);
const end = Number(page) * Number(PAGE_SIZE);
const start = (Number(page) - 1) * Number(CLAIM.PAGE_SIZE);
const end = Number(page) * Number(CLAIM.PAGE_SIZE);
return matchingFileInfos && matchingFileInfos.length
? matchingFileInfos
.slice(start, end)
@ -824,8 +824,8 @@ export const makeSelectMyStreamUrlsForPage = (page: number = 1) =>
createSelector(
selectMyClaimUrisWithoutChannels,
urls => {
const start = (Number(page) - 1) * Number(PAGE_SIZE);
const end = Number(page) * Number(PAGE_SIZE);
const start = (Number(page) - 1) * Number(CLAIM.PAGE_SIZE);
const end = Number(page) * Number(CLAIM.PAGE_SIZE);
return urls && urls.length ? urls.slice(start, end) : [];
}
@ -850,3 +850,38 @@ export const makeSelectTagInClaimOrChannelForUri = (uri: string, tag: string) =>
return claimTags.includes(tag) || channelTags.includes(tag);
}
);
export const makeSelectTotalStakedAmountForChannelUri = (uri: string) =>
createSelector(
makeSelectClaimForUri(uri),
claim => {
if (!claim || !claim.amount || !claim.meta || !claim.meta.support_amount) {
return 0;
}
return parseFloat(claim.amount) + parseFloat(claim.meta.support_amount) || 0;
}
);
export const makeSelectStakedLevelForChannelUri = (uri: string) =>
createSelector(
makeSelectTotalStakedAmountForChannelUri(uri),
amount => {
let level = CLAIM.LEVEL_1_STAKED_AMOUNT;
switch (true) {
case amount >= 1 && amount < 50:
level = CLAIM.LEVEL_2_STAKED_AMOUNT;
break;
case amount >= 50 && amount < 250:
level = CLAIM.LEVEL_3_STAKED_AMOUNT;
break;
case amount >= 250 && amount < 1000:
level = CLAIM.LEVEL_4_STAKED_AMOUNT;
break;
case amount >= 1000:
level = CLAIM.LEVEL_5_STAKED_AMOUNT;
break;
}
return level;
}
);