support repost amount

bugfix

resolve reposted claims inline

refactor resolve reposts

further refactor

bugfix
This commit is contained in:
zeppi 2020-12-16 22:35:12 -05:00 committed by Sean Yesmunt
parent e3c05268e5
commit ce9f720bbd
5 changed files with 126 additions and 64 deletions

42
dist/bundle.es.js vendored
View file

@ -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,20 +3228,32 @@ 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
};
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;
@ -3257,6 +3271,17 @@ function doResolveUris(uris, returnCachedClaims = false) {
}
}
});
}
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,
@ -3264,6 +3289,11 @@ function doResolveUris(uris, returnCachedClaims = false) {
});
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);

View file

@ -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,

1
flow-typed/Claim.js vendored
View file

@ -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,

View file

@ -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<string>, returnCachedClaims: boolean = false) {
type ResolveEntries = Array<[string, GenericClaim]>;
export function doResolveUris(
uris: Array<string>,
returnCachedClaims: boolean = false,
resolveReposts: boolean = true
) {
return (dispatch: Dispatch, getState: GetState) => {
const normalizedUris = uris.map(normalizeURI);
const state = getState();
@ -57,20 +63,32 @@ export function doResolveUris(uris: Array<string>, 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,
};
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;
@ -91,13 +109,25 @@ export function doResolveUris(uris: Array<string>, returnCachedClaims: boolean =
}
}
});
}
processResult(result, resolveInfo, resolveReposts);
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;
});
}
);
};
}

View file

@ -386,7 +386,7 @@ export const makeSelectAmountForUri = (uri: string) =>
export const makeSelectEffectiveAmountForUri = (uri: string) =>
createSelector(
makeSelectClaimForUri(uri),
makeSelectClaimForUri(uri, false),
claim => {
return (
claim &&