diff --git a/extras/lbryinc/index.js b/extras/lbryinc/index.js index f74c59dd4..fbb474ae5 100644 --- a/extras/lbryinc/index.js +++ b/extras/lbryinc/index.js @@ -40,8 +40,8 @@ export { syncReducer } from './redux/reducers/sync'; // selectors export { selectAuthToken, selectIsAuthenticating } from './redux/selectors/auth'; export { - makeSelectFetchingCostInfoForUri, - makeSelectCostInfoForUri, + selectFetchingCostInfoForUri, + selectCostInfoForUri, selectAllCostInfoByUri, selectFetchingCostInfo, } from './redux/selectors/cost_info'; diff --git a/extras/lbryinc/redux/selectors/cost_info.js b/extras/lbryinc/redux/selectors/cost_info.js index b510c7c84..8d5103715 100644 --- a/extras/lbryinc/redux/selectors/cost_info.js +++ b/extras/lbryinc/redux/selectors/cost_info.js @@ -1,13 +1,16 @@ -import { createSelector } from 'reselect'; +// @flow +type State = { costInfo: any }; -export const selectState = state => state.costInfo || {}; +export const selectState = (state: State) => state.costInfo || {}; +export const selectAllCostInfoByUri = (state: State) => selectState(state).byUri; +export const selectFetchingCostInfo = (state: State) => selectState(state).fetching; -export const selectAllCostInfoByUri = createSelector(selectState, state => state.byUri || {}); +export const selectCostInfoForUri = (state: State, uri: string) => { + const costInfos = selectAllCostInfoByUri(state); + return costInfos && costInfos[uri]; +}; -export const makeSelectCostInfoForUri = uri => - createSelector(selectAllCostInfoByUri, costInfos => costInfos && costInfos[uri]); - -export const selectFetchingCostInfo = createSelector(selectState, state => state.fetching || {}); - -export const makeSelectFetchingCostInfoForUri = uri => - createSelector(selectFetchingCostInfo, fetchingByUri => fetchingByUri && fetchingByUri[uri]); +export const selectFetchingCostInfoForUri = (state: State, uri: string) => { + const fetchingByUri = selectFetchingCostInfo(state); + return fetchingByUri && fetchingByUri[uri]; +}; diff --git a/ui/component/claimInsufficientCredits/index.js b/ui/component/claimInsufficientCredits/index.js index 3a0230ea4..e8326006c 100644 --- a/ui/component/claimInsufficientCredits/index.js +++ b/ui/component/claimInsufficientCredits/index.js @@ -1,10 +1,10 @@ import { connect } from 'react-redux'; -import { makeSelectInsufficientCreditsForUri } from 'redux/selectors/content'; +import { selectInsufficientCreditsForUri } from 'redux/selectors/content'; import { makeSelectClaimWasPurchased } from 'redux/selectors/claims'; import ClaimInsufficientCredits from './view'; const select = (state, props) => ({ - isInsufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state), + isInsufficientCredits: selectInsufficientCreditsForUri(state, props.uri), claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state), }); diff --git a/ui/component/embedPlayButton/index.js b/ui/component/embedPlayButton/index.js index 339f02b3b..ec8840c8d 100644 --- a/ui/component/embedPlayButton/index.js +++ b/ui/component/embedPlayButton/index.js @@ -2,7 +2,7 @@ import { connect } from 'react-redux'; import { selectThumbnailForUri, makeSelectClaimForUri } from 'redux/selectors/claims'; import { doResolveUri } from 'redux/actions/claims'; import * as SETTINGS from 'constants/settings'; -import { doFetchCostInfoForUri, makeSelectCostInfoForUri } from 'lbryinc'; +import { doFetchCostInfoForUri, selectCostInfoForUri } from 'lbryinc'; import { doPlayUri, doSetPlayingUri } from 'redux/actions/content'; import { doAnaltyicsPurchaseEvent } from 'redux/actions/app'; import { makeSelectClientSetting } from 'redux/selectors/settings'; @@ -14,7 +14,7 @@ const select = (state, props) => ({ thumbnail: selectThumbnailForUri(state, props.uri), claim: makeSelectClaimForUri(props.uri)(state), floatingPlayerEnabled: makeSelectClientSetting(SETTINGS.FLOATING_PLAYER)(state), - costInfo: makeSelectCostInfoForUri(props.uri)(state), + costInfo: selectCostInfoForUri(state, props.uri), renderMode: makeSelectFileRenderModeForUri(props.uri)(state), }); diff --git a/ui/component/fileActions/index.js b/ui/component/fileActions/index.js index b2ca9dafa..32f3369a7 100644 --- a/ui/component/fileActions/index.js +++ b/ui/component/fileActions/index.js @@ -9,7 +9,7 @@ import { import { makeSelectStreamingUrlForUri, makeSelectFileInfoForUri } from 'redux/selectors/file_info'; import { doPrepareEdit } from 'redux/actions/publish'; import { DISABLE_COMMENTS_TAG } from 'constants/tags'; -import { makeSelectCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri } from 'lbryinc'; import { doSetPlayingUri, doPlayUri } from 'redux/actions/content'; import { doToast } from 'redux/actions/notifications'; import { doOpenModal, doSetActiveChannel, doSetIncognito, doAnalyticsView } from 'redux/actions/app'; @@ -25,7 +25,7 @@ const select = (state, props) => { claimIsMine: selectClaimIsMine(state, claim), fileInfo: makeSelectFileInfoForUri(props.uri)(state), renderMode: makeSelectFileRenderModeForUri(props.uri)(state), - costInfo: makeSelectCostInfoForUri(props.uri)(state), + costInfo: selectCostInfoForUri(state, props.uri), hasChannels: selectHasChannels(state), isLivestreamClaim: selectIsStreamPlaceholderForUri(state, props.uri), reactionsDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_COMMENTS_TAG)(state), diff --git a/ui/component/fileDownloadLink/index.js b/ui/component/fileDownloadLink/index.js index bf4ad34d3..5ae3b0cfa 100644 --- a/ui/component/fileDownloadLink/index.js +++ b/ui/component/fileDownloadLink/index.js @@ -6,7 +6,7 @@ import { makeSelectLoadingForUri, makeSelectStreamingUrlForUri, } from 'redux/selectors/file_info'; -import { makeSelectCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri } from 'lbryinc'; import { doOpenModal, doAnalyticsView } from 'redux/actions/app'; import { doSetPlayingUri, doPlayUri } from 'redux/actions/content'; import FileDownloadLink from './view'; @@ -20,7 +20,7 @@ const select = (state, props) => { loading: makeSelectLoadingForUri(props.uri)(state), claimIsMine: selectClaimIsMine(state, claim), claim, - costInfo: makeSelectCostInfoForUri(props.uri)(state), + costInfo: selectCostInfoForUri(state, props.uri), claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state), streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state), }; diff --git a/ui/component/filePrice/index.js b/ui/component/filePrice/index.js index 560f38b96..3c816eb18 100644 --- a/ui/component/filePrice/index.js +++ b/ui/component/filePrice/index.js @@ -1,6 +1,6 @@ import { connect } from 'react-redux'; import { selectClaimForUri, makeSelectClaimWasPurchased, selectClaimIsMine } from 'redux/selectors/claims'; -import { makeSelectCostInfoForUri, doFetchCostInfoForUri, makeSelectFetchingCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri, doFetchCostInfoForUri, selectFetchingCostInfoForUri } from 'lbryinc'; import FilePrice from './view'; const select = (state, props) => { @@ -10,8 +10,8 @@ const select = (state, props) => { claim, claimIsMine: selectClaimIsMine(state, claim), claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state), - costInfo: makeSelectCostInfoForUri(props.uri)(state), - fetching: makeSelectFetchingCostInfoForUri(props.uri)(state), + costInfo: selectCostInfoForUri(state, props.uri), + fetching: selectFetchingCostInfoForUri(state, props.uri), }; }; diff --git a/ui/component/fileRenderFloating/index.js b/ui/component/fileRenderFloating/index.js index a05023544..aa8786b11 100644 --- a/ui/component/fileRenderFloating/index.js +++ b/ui/component/fileRenderFloating/index.js @@ -13,7 +13,7 @@ import { makeSelectFileRenderModeForUri, } from 'redux/selectors/content'; import { makeSelectClientSetting } from 'redux/selectors/settings'; -import { makeSelectCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri } from 'lbryinc'; import { doPlayUri, doSetPlayingUri } from 'redux/actions/content'; import { doFetchRecommendedContent } from 'redux/actions/search'; import { doAnaltyicsPurchaseEvent } from 'redux/actions/app'; @@ -38,7 +38,7 @@ const select = (state, props) => { floatingPlayerEnabled: makeSelectClientSetting(SETTINGS.FLOATING_PLAYER)(state), renderMode: makeSelectFileRenderModeForUri(uri)(state), videoTheaterMode: makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)(state), - costInfo: makeSelectCostInfoForUri(uri)(state), + costInfo: selectCostInfoForUri(state, uri), claimWasPurchased: makeSelectClaimWasPurchased(uri)(state), nextListUri: collectionId && makeSelectNextUrlForCollectionAndUrl(collectionId, uri)(state), previousListUri: collectionId && makeSelectPreviousUrlForCollectionAndUrl(collectionId, uri)(state), diff --git a/ui/component/fileRenderInitiator/index.js b/ui/component/fileRenderInitiator/index.js index 3cf1563c5..1215df924 100644 --- a/ui/component/fileRenderInitiator/index.js +++ b/ui/component/fileRenderInitiator/index.js @@ -4,14 +4,14 @@ import { selectThumbnailForUri, makeSelectClaimForUri, makeSelectClaimWasPurchas import { makeSelectFileInfoForUri } from 'redux/selectors/file_info'; import * as SETTINGS from 'constants/settings'; import * as COLLECTIONS_CONSTS from 'constants/collections'; -import { makeSelectCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri } from 'lbryinc'; import { selectUserVerifiedEmail } from 'redux/selectors/user'; import { makeSelectClientSetting } from 'redux/selectors/settings'; import { withRouter } from 'react-router'; import { makeSelectIsPlaying, selectShouldObscurePreviewForUri, - makeSelectInsufficientCreditsForUri, + selectInsufficientCreditsForUri, makeSelectFileRenderModeForUri, } from 'redux/selectors/content'; import FileRenderInitiator from './view'; @@ -27,9 +27,9 @@ const select = (state, props) => { fileInfo: makeSelectFileInfoForUri(props.uri)(state), obscurePreview: selectShouldObscurePreviewForUri(state, props.uri), isPlaying: makeSelectIsPlaying(props.uri)(state), - insufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state), + insufficientCredits: selectInsufficientCreditsForUri(state, props.uri), autoplay: makeSelectClientSetting(SETTINGS.AUTOPLAY_MEDIA)(state), - costInfo: makeSelectCostInfoForUri(props.uri)(state), + costInfo: selectCostInfoForUri(state, props.uri), renderMode: makeSelectFileRenderModeForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state), claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state), diff --git a/ui/component/fileRenderInline/index.js b/ui/component/fileRenderInline/index.js index f5e7a0db1..a858d3639 100644 --- a/ui/component/fileRenderInline/index.js +++ b/ui/component/fileRenderInline/index.js @@ -6,14 +6,14 @@ import { makeSelectFileRenderModeForUri, selectPrimaryUri } from 'redux/selector import { withRouter } from 'react-router'; import { doAnalyticsView } from 'redux/actions/app'; import FileRenderInline from './view'; -import { makeSelectCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri } from 'lbryinc'; const select = (state, props) => ({ fileInfo: makeSelectFileInfoForUri(props.uri)(state), isPlaying: selectPrimaryUri(state) === props.uri, streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state), renderMode: makeSelectFileRenderModeForUri(props.uri)(state), - costInfo: makeSelectCostInfoForUri(props.uri)(state), + costInfo: selectCostInfoForUri(state, props.uri), claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state), }); diff --git a/ui/component/fileTitleSection/index.js b/ui/component/fileTitleSection/index.js index 33abe6d1b..1fbbe0b08 100644 --- a/ui/component/fileTitleSection/index.js +++ b/ui/component/fileTitleSection/index.js @@ -1,7 +1,7 @@ import { connect } from 'react-redux'; import { doFetchSubCount, selectSubCountForUri } from 'lbryinc'; import { selectTitleForUri, selectClaimForUri } from 'redux/selectors/claims'; -import { makeSelectInsufficientCreditsForUri } from 'redux/selectors/content'; +import { selectInsufficientCreditsForUri } from 'redux/selectors/content'; import FileTitleSection from './view'; const select = (state, props) => { @@ -11,7 +11,7 @@ const select = (state, props) => { const subCount = channelUri && selectSubCountForUri(state, channelUri); return { - isInsufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state), + isInsufficientCredits: selectInsufficientCreditsForUri(state, props.uri), title: selectTitleForUri(state, props.uri), channelClaimId, subCount, diff --git a/ui/page/embedWrapper/index.js b/ui/page/embedWrapper/index.js index 7ce41b7ce..dc24e321c 100644 --- a/ui/page/embedWrapper/index.js +++ b/ui/page/embedWrapper/index.js @@ -5,7 +5,7 @@ import { makeSelectStreamingUrlForUri } from 'redux/selectors/file_info'; import { doResolveUri } from 'redux/actions/claims'; import { buildURI } from 'util/lbryURI'; import { doPlayUri } from 'redux/actions/content'; -import { makeSelectCostInfoForUri, doFetchCostInfoForUri, selectBlackListedOutpoints } from 'lbryinc'; +import { selectCostInfoForUri, doFetchCostInfoForUri, selectBlackListedOutpoints } from 'lbryinc'; const select = (state, props) => { const { match } = props; @@ -15,7 +15,7 @@ const select = (state, props) => { return { uri, claim: makeSelectClaimForUri(uri)(state), - costInfo: makeSelectCostInfoForUri(uri)(state), + costInfo: selectCostInfoForUri(state, uri), streamingUrl: makeSelectStreamingUrlForUri(uri)(state), isResolvingUri: selectIsUriResolving(state, uri), blackListedOutpoints: selectBlackListedOutpoints(state), diff --git a/ui/page/file/index.js b/ui/page/file/index.js index 27a59d8f4..53e17146d 100644 --- a/ui/page/file/index.js +++ b/ui/page/file/index.js @@ -11,7 +11,7 @@ import { doFetchFileInfo } from 'redux/actions/file_info'; import { makeSelectCollectionForId } from 'redux/selectors/collections'; import * as COLLECTIONS_CONSTS from 'constants/collections'; import * as SETTINGS from 'constants/settings'; -import { makeSelectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc'; import { selectShowMatureContent, makeSelectClientSetting } from 'redux/selectors/settings'; import { makeSelectFileRenderModeForUri, makeSelectContentPositionForUri } from 'redux/selectors/content'; import { DISABLE_COMMENTS_TAG } from 'constants/tags'; @@ -25,7 +25,7 @@ const select = (state, props) => { return { linkedCommentId: urlParams.get('lc'), - costInfo: makeSelectCostInfoForUri(props.uri)(state), + costInfo: selectCostInfoForUri(state, props.uri), obscureNsfw: !selectShowMatureContent(state), isMature: selectClaimIsNsfwForUri(state, props.uri), fileInfo: makeSelectFileInfoForUri(props.uri)(state), diff --git a/ui/redux/actions/content.js b/ui/redux/actions/content.js index 55220fabb..a54899cae 100644 --- a/ui/redux/actions/content.js +++ b/ui/redux/actions/content.js @@ -17,7 +17,7 @@ import { doToast } from 'redux/actions/notifications'; import { doPurchaseUri } from 'redux/actions/file'; import Lbry from 'lbry'; import * as SETTINGS from 'constants/settings'; -import { makeSelectCostInfoForUri, Lbryio } from 'lbryinc'; +import { selectCostInfoForUri, Lbryio } from 'lbryinc'; import { makeSelectClientSetting, selectosNotificationsEnabled, selectDaemonSettings } from 'redux/selectors/settings'; const DOWNLOAD_POLL_INTERVAL = 1000; @@ -164,7 +164,7 @@ export function doPlayUri( } const daemonSettings = selectDaemonSettings(state); - const costInfo = makeSelectCostInfoForUri(uri)(state); + const costInfo = selectCostInfoForUri(state, uri); const cost = (costInfo && Number(costInfo.cost)) || 0; const saveFile = !IS_WEB && (!uriIsStreamable ? true : daemonSettings.save_files || saveFileOverride || cost > 0); const instantPurchaseEnabled = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state); diff --git a/ui/redux/actions/file.js b/ui/redux/actions/file.js index e70bc666d..02411d739 100644 --- a/ui/redux/actions/file.js +++ b/ui/redux/actions/file.js @@ -22,7 +22,7 @@ import { } from 'redux/selectors/file_info'; type Dispatch = (action: any) => any; -type GetState = () => { file: FileState, content: any }; +type GetState = () => { claims: any, file: FileState, content: any }; export function doOpenFileInFolder(path: string) { return () => { shell.showItemInFolder(path); diff --git a/ui/redux/selectors/claims.js b/ui/redux/selectors/claims.js index 8c00eaf34..e9f62c2e9 100644 --- a/ui/redux/selectors/claims.js +++ b/ui/redux/selectors/claims.js @@ -247,26 +247,6 @@ export const selectClaimIsMineForUri = (state: State, rawUri: string) => { return selectClaimIsMine(state, claimsByUri && claimsByUri[uri]); }; -// DEPRECATED - use selectClaimIsMineForUri instead. -export const makeSelectClaimIsMine = (rawUri: string) => { - let uri; - try { - uri = normalizeURI(rawUri); - } catch (e) {} - - return createSelector(selectClaimsByUri, selectMyActiveClaims, (claims, myClaims) => { - if (!isURIValid(uri, false)) { - return false; - } - - return ( - claims && - claims[uri] && - (claims[uri].is_my_output || (claims[uri].claim_id && myClaims.has(claims[uri].claim_id))) - ); - }); -}; - export const selectMyPurchases = (state: State) => selectState(state).myPurchases; export const selectPurchaseUriSuccess = (state: State) => selectState(state).purchaseUriSuccess; export const selectMyPurchasesCount = (state: State) => selectState(state).myPurchasesPageTotalResults; diff --git a/ui/redux/selectors/content.js b/ui/redux/selectors/content.js index 5a6553134..418d171dd 100644 --- a/ui/redux/selectors/content.js +++ b/ui/redux/selectors/content.js @@ -4,12 +4,12 @@ import { makeSelectClaimForUri, selectClaimsByUri, selectClaimIsNsfwForUri, - makeSelectClaimIsMine, + selectClaimIsMineForUri, makeSelectContentTypeForUri, } from 'redux/selectors/claims'; import { makeSelectMediaTypeForUri, makeSelectFileNameForUri } from 'redux/selectors/file_info'; import { selectBalance } from 'redux/selectors/wallet'; -import { makeSelectCostInfoForUri } from 'lbryinc'; +import { selectCostInfoForUri } from 'lbryinc'; import { selectShowMatureContent } from 'redux/selectors/settings'; import * as RENDER_MODES from 'constants/file_render_modes'; import path from 'path'; @@ -18,7 +18,7 @@ import { FORCE_CONTENT_TYPE_PLAYER, FORCE_CONTENT_TYPE_COMIC } from 'constants/c const RECENT_HISTORY_AMOUNT = 10; const HISTORY_ITEMS_PER_PAGE = 50; -type State = { content: any }; +type State = { claims: any, content: any }; export const selectState = (state: State) => state.content || {}; @@ -157,12 +157,9 @@ export const makeSelectFileRenderModeForUri = (uri: string) => } ); -export const makeSelectInsufficientCreditsForUri = (uri: string) => - createSelector( - makeSelectClaimIsMine(uri), - makeSelectCostInfoForUri(uri), - selectBalance, - (isMine, costInfo, balance) => { - return !isMine && costInfo && costInfo.cost > 0 && costInfo.cost > balance; - } - ); +export const selectInsufficientCreditsForUri = (state: State, uri: string) => { + const isMine = selectClaimIsMineForUri(state, uri); + const costInfo = selectCostInfoForUri(state, uri); + const balance = selectBalance(state); + return !isMine && costInfo && costInfo.cost > 0 && costInfo.cost > balance; +};