From ce9f720bbd978d7574ab072771aa85ff5a83e2fc Mon Sep 17 00:00:00 2001 From: zeppi Date: Wed, 16 Dec 2020 22:35:12 -0500 Subject: [PATCH] support repost amount bugfix resolve reposted claims inline refactor resolve reposts further refactor bugfix --- dist/bundle.es.js | 92 ++++++++++++++++++++++------------ dist/flow-typed/Claim.js | 1 + flow-typed/Claim.js | 1 + src/redux/actions/claims.js | 94 +++++++++++++++++++++++------------ src/redux/selectors/claims.js | 2 +- 5 files changed, 126 insertions(+), 64 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 7267d86..44c7b96 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2364,7 +2364,7 @@ const makeSelectAmountForUri = uri => reselect.createSelector(makeSelectClaimFor return claim && claim.amount; }); -const makeSelectEffectiveAmountForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { +const makeSelectEffectiveAmountForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri, false), claim => { return claim && claim.meta && typeof claim.meta.effective_amount === 'string' && Number(claim.meta.effective_amount); }); @@ -3193,7 +3193,9 @@ function batchActions(...actions) { var _extends$5 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; -function doResolveUris(uris, returnCachedClaims = false) { +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } + +function doResolveUris(uris, returnCachedClaims = false, resolveReposts = true) { return (dispatch, getState) => { const normalizedUris = uris.map(normalizeURI); const state = getState(); @@ -3226,44 +3228,72 @@ function doResolveUris(uris, returnCachedClaims = false) { const resolveInfo = {}; - return lbryProxy.resolve(_extends$5({ urls: urisToResolve }, options)).then(result => { - Object.entries(result).forEach(([uri, uriResolveInfo]) => { + return lbryProxy.resolve(_extends$5({ urls: urisToResolve }, options)).then((() => { + var _ref = _asyncToGenerator(function* (result) { + let repostedResults = {}; + const repostsToResolve = []; const fallbackResolveInfo = { stream: null, claimsInChannel: null, channel: null }; - // Flow has terrible Object.entries support - // https://github.com/facebook/flow/issues/2221 - if (uriResolveInfo) { - if (uriResolveInfo.error) { - resolveInfo[uri] = _extends$5({}, fallbackResolveInfo); - } else { - let result = {}; - if (uriResolveInfo.value_type === 'channel') { - result.channel = uriResolveInfo; - // $FlowFixMe - result.claimsInChannel = uriResolveInfo.meta.claims_in_channel; - } else { - result.stream = uriResolveInfo; - if (uriResolveInfo.signing_channel) { - result.channel = uriResolveInfo.signing_channel; - result.claimsInChannel = uriResolveInfo.signing_channel.meta && uriResolveInfo.signing_channel.meta.claims_in_channel || 0; + function processResult(result, resolveInfo = {}, checkReposts = false) { + Object.entries(result).forEach(([uri, uriResolveInfo]) => { + // Flow has terrible Object.entries support + // https://github.com/facebook/flow/issues/2221 + if (uriResolveInfo) { + if (uriResolveInfo.error) { + resolveInfo[uri] = _extends$5({}, fallbackResolveInfo); + } else { + if (checkReposts) { + if (uriResolveInfo.reposted_claim) { + const repostUrl = uriResolveInfo.reposted_claim.permanent_url; + if (!resolvingUris.includes(repostUrl)) { + repostsToResolve.push(repostUrl); + } + } + } + let result = {}; + if (uriResolveInfo.value_type === 'channel') { + result.channel = uriResolveInfo; + // $FlowFixMe + result.claimsInChannel = uriResolveInfo.meta.claims_in_channel; + } else { + result.stream = uriResolveInfo; + if (uriResolveInfo.signing_channel) { + result.channel = uriResolveInfo.signing_channel; + result.claimsInChannel = uriResolveInfo.signing_channel.meta && uriResolveInfo.signing_channel.meta.claims_in_channel || 0; + } + } + // $FlowFixMe + resolveInfo[uri] = result; } } - // $FlowFixMe - resolveInfo[uri] = result; - } + }); } + processResult(result, resolveInfo, resolveReposts); + + if (repostsToResolve.length) { + dispatch({ + type: RESOLVE_URIS_STARTED, + data: { uris: repostsToResolve, debug: 'reposts' } + }); + repostedResults = yield lbryProxy.resolve(_extends$5({ urls: repostsToResolve }, options)); + } + processResult(repostedResults, resolveInfo); + + dispatch({ + type: RESOLVE_URIS_COMPLETED, + data: { resolveInfo } + }); + return result; }); - dispatch({ - type: RESOLVE_URIS_COMPLETED, - data: { resolveInfo } - }); - return result; - }); + return function (_x) { + return _ref.apply(this, arguments); + }; + })()); }; } @@ -4269,7 +4299,7 @@ const selectTakeOverAmount = reselect.createSelector(selectState$3, selectMyClai var _extends$7 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; -function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } +function _asyncToGenerator$1(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } const doResetThumbnailStatus = () => dispatch => { dispatch({ @@ -4603,7 +4633,7 @@ const doCheckReflectingFiles = () => (dispatch, getState) => { let reflectorCheckInterval; const checkFileList = (() => { - var _ref = _asyncToGenerator(function* () { + var _ref = _asyncToGenerator$1(function* () { const state = getState(); const reflectingById = selectReflectingById(state); const ids = Object.keys(reflectingById); diff --git a/dist/flow-typed/Claim.js b/dist/flow-typed/Claim.js index d8af692..655a4bc 100644 --- a/dist/flow-typed/Claim.js +++ b/dist/flow-typed/Claim.js @@ -32,6 +32,7 @@ declare type GenericClaim = { type: 'claim' | 'update' | 'support', value_type: 'stream' | 'channel', signing_channel?: ChannelClaim, + reposted_claim?: GenericClaim, repost_channel_url?: string, repost_url?: string, repost_bid_amount?: string, diff --git a/flow-typed/Claim.js b/flow-typed/Claim.js index d8af692..655a4bc 100644 --- a/flow-typed/Claim.js +++ b/flow-typed/Claim.js @@ -32,6 +32,7 @@ declare type GenericClaim = { type: 'claim' | 'update' | 'support', value_type: 'stream' | 'channel', signing_channel?: ChannelClaim, + reposted_claim?: GenericClaim, repost_channel_url?: string, repost_url?: string, repost_bid_amount?: string, diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index 8fe9551..4e25d92 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -18,7 +18,13 @@ import { batchActions } from 'util/batch-actions'; import { createNormalizedClaimSearchKey } from 'util/claim'; import { PAGE_SIZE } from 'constants/claim'; -export function doResolveUris(uris: Array, returnCachedClaims: boolean = false) { +type ResolveEntries = Array<[string, GenericClaim]>; + +export function doResolveUris( + uris: Array, + returnCachedClaims: boolean = false, + resolveReposts: boolean = true +) { return (dispatch: Dispatch, getState: GetState) => { const normalizedUris = uris.map(normalizeURI); const state = getState(); @@ -57,47 +63,71 @@ export function doResolveUris(uris: Array, returnCachedClaims: boolean = }, } = {}; - return Lbry.resolve({ urls: urisToResolve, ...options }).then((result: ResolveResponse) => { - Object.entries(result).forEach(([uri, uriResolveInfo]) => { + return Lbry.resolve({ urls: urisToResolve, ...options }).then( + async (result: ResolveResponse) => { + let repostedResults = {}; + const repostsToResolve = []; const fallbackResolveInfo = { stream: null, claimsInChannel: null, channel: null, }; - // Flow has terrible Object.entries support - // https://github.com/facebook/flow/issues/2221 - if (uriResolveInfo) { - if (uriResolveInfo.error) { - resolveInfo[uri] = { ...fallbackResolveInfo }; - } else { - let result = {}; - if (uriResolveInfo.value_type === 'channel') { - result.channel = uriResolveInfo; - // $FlowFixMe - result.claimsInChannel = uriResolveInfo.meta.claims_in_channel; - } else { - result.stream = uriResolveInfo; - if (uriResolveInfo.signing_channel) { - result.channel = uriResolveInfo.signing_channel; - result.claimsInChannel = - (uriResolveInfo.signing_channel.meta && - uriResolveInfo.signing_channel.meta.claims_in_channel) || - 0; + function processResult(result, resolveInfo = {}, checkReposts = false) { + Object.entries(result).forEach(([uri, uriResolveInfo]) => { + // Flow has terrible Object.entries support + // https://github.com/facebook/flow/issues/2221 + if (uriResolveInfo) { + if (uriResolveInfo.error) { + resolveInfo[uri] = { ...fallbackResolveInfo }; + } else { + if (checkReposts) { + if (uriResolveInfo.reposted_claim) { + const repostUrl = uriResolveInfo.reposted_claim.permanent_url; + if (!resolvingUris.includes(repostUrl)) { + repostsToResolve.push(repostUrl); + } + } + } + let result = {}; + if (uriResolveInfo.value_type === 'channel') { + result.channel = uriResolveInfo; + // $FlowFixMe + result.claimsInChannel = uriResolveInfo.meta.claims_in_channel; + } else { + result.stream = uriResolveInfo; + if (uriResolveInfo.signing_channel) { + result.channel = uriResolveInfo.signing_channel; + result.claimsInChannel = + (uriResolveInfo.signing_channel.meta && + uriResolveInfo.signing_channel.meta.claims_in_channel) || + 0; + } + } + // $FlowFixMe + resolveInfo[uri] = result; } } - // $FlowFixMe - resolveInfo[uri] = result; - } + }); } - }); + processResult(result, resolveInfo, resolveReposts); - dispatch({ - type: ACTIONS.RESOLVE_URIS_COMPLETED, - data: { resolveInfo }, - }); - return result; - }); + if (repostsToResolve.length) { + dispatch({ + type: ACTIONS.RESOLVE_URIS_STARTED, + data: { uris: repostsToResolve, debug: 'reposts' }, + }); + repostedResults = await Lbry.resolve({ urls: repostsToResolve, ...options }); + } + processResult(repostedResults, resolveInfo); + + dispatch({ + type: ACTIONS.RESOLVE_URIS_COMPLETED, + data: { resolveInfo }, + }); + return result; + } + ); }; } diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 4f497a3..21d335b 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -386,7 +386,7 @@ export const makeSelectAmountForUri = (uri: string) => export const makeSelectEffectiveAmountForUri = (uri: string) => createSelector( - makeSelectClaimForUri(uri), + makeSelectClaimForUri(uri, false), claim => { return ( claim &&