store pendingById

This commit is contained in:
zeppi 2021-06-24 14:26:51 -04:00 committed by jessopb
parent 0b505fb0f4
commit e66698eadc
8 changed files with 298 additions and 274 deletions

226
dist/bundle.es.js vendored
View file

@ -2370,7 +2370,13 @@ var _extends$3 = Object.assign || function (target) { for (var i = 1; i < argume
const selectState$1 = state => state.claims || {}; const selectState$1 = state => state.claims || {};
const selectClaimsById = reselect.createSelector(selectState$1, state => state.byId || {}); const selectById = reselect.createSelector(selectState$1, state => state.byId || {});
const selectPendingClaimsById = reselect.createSelector(selectState$1, state => state.pendingById || {});
const selectClaimsById = reselect.createSelector(selectById, selectPendingClaimsById, (byId, pendingById) => {
return Object.assign(byId, pendingById); // do I need merged?
});
const selectClaimIdsByUri = reselect.createSelector(selectState$1, state => state.claimsByUri || {}); const selectClaimIdsByUri = reselect.createSelector(selectState$1, state => state.claimsByUri || {});
@ -2405,29 +2411,31 @@ const selectClaimsByUri = reselect.createSelector(selectClaimIdsByUri, selectCla
const selectAllClaimsByChannel = reselect.createSelector(selectState$1, state => state.paginatedClaimsByChannel || {}); const selectAllClaimsByChannel = reselect.createSelector(selectState$1, state => state.paginatedClaimsByChannel || {});
const selectPendingIds = reselect.createSelector(selectState$1, state => state.pendingIds || []); const selectPendingIds = reselect.createSelector(selectState$1, state => Object.keys(state.pendingIds) || []);
const selectPendingClaims = reselect.createSelector(selectPendingIds, selectClaimsById, (pendingIds, byId) => pendingIds.map(id => byId[id])); const selectPendingClaims = reselect.createSelector(selectPendingClaimsById, pendingById => Object.values(pendingById));
const makeSelectClaimIsPending = uri => reselect.createSelector(selectClaimIdsByUri, selectPendingIds, (idsByUri, pendingIds) => { const makeSelectClaimIsPending = uri => reselect.createSelector(selectClaimIdsByUri, selectPendingClaimsById, (idsByUri, pendingById) => {
const claimId = idsByUri[normalizeURI(uri)]; const claimId = idsByUri[normalizeURI(uri)];
if (claimId) { if (claimId) {
return pendingIds.some(i => i === claimId); return Boolean(pendingById[claimId]);
} }
return false; return false;
}); });
const makeSelectClaimIdIsPending = claimId => reselect.createSelector(selectPendingIds, pendingIds => { const makeSelectClaimIdIsPending = claimId => reselect.createSelector(selectPendingClaimsById, pendingById => {
return pendingIds.some(i => i === claimId); return Boolean(pendingById[claimId]);
}); });
const makeSelectClaimIdForUri = uri => reselect.createSelector(selectClaimIdsByUri, claimIds => claimIds[uri]); const makeSelectClaimIdForUri = uri => reselect.createSelector(selectClaimIdsByUri, claimIds => claimIds[uri]);
const selectReflectingById = reselect.createSelector(selectState$1, state => state.reflectingById); const selectReflectingById = reselect.createSelector(selectState$1, state => state.reflectingById);
// use pendingFirst
const makeSelectClaimForClaimId = claimId => reselect.createSelector(selectClaimsById, byId => byId[claimId]); const makeSelectClaimForClaimId = claimId => reselect.createSelector(selectClaimsById, byId => byId[claimId]);
// use pendingFirst
const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => { const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => {
let validUri; let validUri;
let channelClaimId; let channelClaimId;
@ -2464,6 +2472,7 @@ const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelec
} }
}); });
// use pendingFirst
const selectMyClaimsRaw = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { const selectMyClaimsRaw = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => {
const ids = state.myClaims; const ids = state.myClaims;
if (!ids) { if (!ids) {
@ -2543,6 +2552,7 @@ const selectAllFetchingChannelClaims = reselect.createSelector(selectState$1, st
const makeSelectFetchingChannelClaims = uri => reselect.createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]); const makeSelectFetchingChannelClaims = uri => reselect.createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]);
// use pendingFirst
const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => {
const byChannel = allClaims[uri] || {}; const byChannel = allClaims[uri] || {};
const claimIds = byChannel[page || 1]; const claimIds = byChannel[page || 1];
@ -2552,24 +2562,32 @@ const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector(
return claimIds.map(claimId => byId[claimId]); return claimIds.map(claimId => byId[claimId]);
}); });
// THIS IS LEFT OVER FROM ONE TAB CHANNEL_CONTENT
const makeSelectTotalClaimsInChannelSearch = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { const makeSelectTotalClaimsInChannelSearch = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => {
const byChannel = allClaims[uri] || {}; const byChannel = allClaims[uri] || {};
return byChannel['itemCount']; return byChannel['itemCount'];
}); });
// THIS IS LEFT OVER FROM ONE_TAB CHANNEL CONTENT
const makeSelectTotalPagesInChannelSearch = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { const makeSelectTotalPagesInChannelSearch = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => {
const byChannel = allClaims[uri] || {}; const byChannel = allClaims[uri] || {};
return byChannel['pageCount']; return byChannel['pageCount'];
}); });
const makeSelectClaimsInChannelForCurrentPageState = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, selectCurrentChannelPage, (byId, allClaims, page) => { // export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) =>
const byChannel = allClaims[uri] || {}; // createSelector(
const claimIds = byChannel[page || 1]; // selectClaimsById,
// selectAllClaimsByChannel,
if (!claimIds) return claimIds; // selectCurrentChannelPage,
// (byId, allClaims, page) => {
return claimIds.map(claimId => byId[claimId]); // const byChannel = allClaims[uri] || {};
}); // const claimIds = byChannel[page || 1];
//
// if (!claimIds) return claimIds;
//
// return claimIds.map(claimId => byId[claimId]);
// }
// );
const makeSelectMetadataForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { const makeSelectMetadataForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
const metadata = claim && claim.value; const metadata = claim && claim.value;
@ -2624,6 +2642,7 @@ const selectMyClaimsPageItemCount = reselect.createSelector(selectState$1, state
const selectFetchingMyClaimsPageError = reselect.createSelector(selectState$1, state => state.fetchingClaimListMinePageError); const selectFetchingMyClaimsPageError = reselect.createSelector(selectState$1, state => state.fetchingClaimListMinePageError);
// use pendingFirst
const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, (myClaimIds, byId, abandoningIds) => { const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, (myClaimIds, byId, abandoningIds) => {
const claims = []; const claims = [];
@ -2666,6 +2685,7 @@ const selectFetchingMyChannels = reselect.createSelector(selectState$1, state =>
const selectFetchingMyCollections = reselect.createSelector(selectState$1, state => state.fetchingMyCollections); const selectFetchingMyCollections = reselect.createSelector(selectState$1, state => state.fetchingMyCollections);
// use pendingFirst
const selectMyChannelClaims = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { const selectMyChannelClaims = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => {
const ids = state.myChannelClaims; const ids = state.myChannelClaims;
if (!ids) { if (!ids) {
@ -2697,27 +2717,21 @@ const selectPlayingUri = reselect.createSelector(selectState$1, state => state.p
const selectChannelClaimCounts = reselect.createSelector(selectState$1, state => state.channelClaimCounts || {}); const selectChannelClaimCounts = reselect.createSelector(selectState$1, state => state.channelClaimCounts || {});
const makeSelectPendingClaimForUri = uri => reselect.createSelector(selectPendingIds, selectClaimsById, (pending, claims) => { // JUST PENDING - change this
let uriIsChannel; const makeSelectPendingClaimForUri = uri => reselect.createSelector(selectPendingClaimsById, pendingById => {
let uriStreamName; let uriStreamName;
let uriChannelName; let uriChannelName;
try { try {
({ ({
isChannel: uriIsChannel,
streamName: uriStreamName, streamName: uriStreamName,
channelName: uriChannelName channelName: uriChannelName
} = parseURI(uri)); } = parseURI(uri));
} catch (e) { } catch (e) {
return null; return null;
} }
const pendingClaims = pending.map(id => claims[id]); const pendingClaims = Object.values(pendingById);
const matchingClaim = pendingClaims.find(claim => { const matchingClaim = pendingClaims.find(claim => {
const { streamName, channelName, isChannel } = parseURI(claim.permanent_url); return claim.normalized_name === uriChannelName || claim.normalized_name === uriStreamName;
if (isChannel) {
return channelName === uriChannelName;
} else {
return streamName === uriStreamName;
}
}); });
return matchingClaim || null; return matchingClaim || null;
}); });
@ -2734,21 +2748,6 @@ const makeSelectNsfwCountFromUris = uris => reselect.createSelector(selectClaims
return acc; return acc;
}, 0)); }, 0));
const makeSelectNsfwCountForChannel = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, selectCurrentChannelPage, (byId, allClaims, page) => {
const byChannel = allClaims[uri] || {};
const claimIds = byChannel[page || 1];
if (!claimIds) return 0;
return claimIds.reduce((acc, claimId) => {
const claim = byId[claimId];
if (isClaimNsfw(claim)) {
return acc + 1;
}
return acc;
}, 0);
});
const makeSelectOmittedCountForChannel = uri => reselect.createSelector(makeSelectTotalItemsForChannel(uri), makeSelectTotalClaimsInChannelSearch(uri), (claimsInChannel, claimsInSearch) => { const makeSelectOmittedCountForChannel = uri => reselect.createSelector(makeSelectTotalItemsForChannel(uri), makeSelectTotalClaimsInChannelSearch(uri), (claimsInChannel, claimsInSearch) => {
if (claimsInChannel && typeof claimsInSearch === 'number' && claimsInSearch >= 0) { if (claimsInChannel && typeof claimsInSearch === 'number' && claimsInSearch >= 0) {
return claimsInChannel - claimsInSearch; return claimsInChannel - claimsInSearch;
@ -3748,6 +3747,9 @@ var _extends$5 = Object.assign || function (target) { for (var i = 1; i < argume
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"); }); }; } 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"); }); }; }
let checkPendingCallbacks = [];
let checkPendingInterval;
function doResolveUris(uris, returnCachedClaims = false, resolveReposts = true) { function doResolveUris(uris, returnCachedClaims = false, resolveReposts = true) {
return (dispatch, getState) => { return (dispatch, getState) => {
const normalizedUris = uris.map(normalizeURI); const normalizedUris = uris.map(normalizeURI);
@ -4571,47 +4573,49 @@ function doPurchaseList(page = 1, pageSize = PAGE_SIZE) {
} }
const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { const doCheckPendingClaims = onConfirmed => (dispatch, getState) => {
let claimCheckInterval; clearInterval(checkPendingInterval);
const checkTxoList = checkPendingCallbacks => {
const checkClaimList = () => {
const state = getState(); const state = getState();
const pendingIdSet = new Set(selectPendingIds(state)); const pendingById = Object.assign({}, selectPendingClaimsById(state));
const pendingTxos = Object.values(pendingById).map(p => p.txid);
// use collections
const pendingCollections = selectPendingCollections(state); const pendingCollections = selectPendingCollections(state);
lbryProxy.claim_list({ page: 1, page_size: 10 }).then(result => { if (pendingTxos.length) {
const claims = result.items; lbryProxy.txo_list({ txid: pendingTxos }).then(result => {
const claimsToConfirm = []; const txos = result.items;
claims.forEach(claim => { const idsToConfirm = [];
const { claim_id: claimId } = claim; txos.forEach(txo => {
if (claim.confirmations > 0 && pendingIdSet.has(claimId)) { if (txo.claim_id && txo.confirmations > 0) {
pendingIdSet.delete(claimId); idsToConfirm.push(txo.claim_id);
if (Object.keys(pendingCollections).includes(claim.claim_id)) { delete pendingById[txo.claim_id];
dispatch(doFetchItemsInCollection({ collectionId: claim.claim_id }));
dispatch(doCollectionDelete(claim.claim_id, 'pending'));
}
claimsToConfirm.push(claim);
if (onConfirmed) {
onConfirmed(claim);
}
} }
}); });
if (claimsToConfirm.length) { return { idsToConfirm, pendingById };
}).then(results => {
const { idsToConfirm, pendingById } = results;
if (idsToConfirm.length) {
return lbryProxy.claim_list({ claim_id: idsToConfirm, resolve: true }).then(results => {
const claims = results.items;
// what if results.items includes a collection?
dispatch({ dispatch({
type: UPDATE_CONFIRMED_CLAIMS, type: UPDATE_CONFIRMED_CLAIMS,
data: { data: {
claims: claimsToConfirm claims: claims,
pending: pendingById
} }
}); });
} checkPendingCallbacks.forEach(cb => cb());
return pendingIdSet.size; clearInterval(checkPendingInterval);
}).then(len => { });
if (!len) {
clearInterval(claimCheckInterval);
} }
}); });
} else {
clearInterval(checkPendingInterval);
}
}; };
// do something with onConfirmed (typically get blocklist for channel)
claimCheckInterval = setInterval(() => { checkPendingInterval = setInterval(() => {
checkClaimList(); checkTxoList(checkPendingCallbacks);
}, 30000); }, 30000);
}; };
@ -6001,7 +6005,7 @@ const defaultState = {
fetchingMyChannels: false, fetchingMyChannels: false,
fetchingMyCollections: false, fetchingMyCollections: false,
abandoningById: {}, abandoningById: {},
pendingIds: [], pendingById: {},
reflectingById: {}, reflectingById: {},
claimSearchError: false, claimSearchError: false,
claimSearchByQuery: {}, claimSearchByQuery: {},
@ -6035,7 +6039,7 @@ function handleClaimAction(state, action) {
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const channelClaimCounts = Object.assign({}, state.channelClaimCounts); const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
const pendingIds = state.pendingIds; const pendingById = state.pendingById;
let newResolvingUrls = new Set(state.resolvingUris); let newResolvingUrls = new Set(state.resolvingUris);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
@ -6045,7 +6049,7 @@ function handleClaimAction(state, action) {
const channel = channelFromResolve || stream && stream.signing_channel; const channel = channelFromResolve || stream && stream.signing_channel;
if (stream) { if (stream) {
if (pendingIds.includes(stream.claim_id)) { if (pendingById[stream.claim_id]) {
byId[stream.claim_id] = mergeClaims(stream, byId[stream.claim_id]); byId[stream.claim_id] = mergeClaims(stream, byId[stream.claim_id]);
} else { } else {
byId[stream.claim_id] = stream; byId[stream.claim_id] = stream;
@ -6075,7 +6079,7 @@ function handleClaimAction(state, action) {
channelClaimCounts[channel.canonical_url] = claimsInChannel; channelClaimCounts[channel.canonical_url] = claimsInChannel;
} }
if (pendingIds.includes(channel.claim_id)) { if (pendingById[channel.claim_id]) {
byId[channel.claim_id] = mergeClaims(channel, byId[channel.claim_id]); byId[channel.claim_id] = mergeClaims(channel, byId[channel.claim_id]);
} else { } else {
byId[channel.claim_id] = channel; byId[channel.claim_id] = channel;
@ -6088,7 +6092,7 @@ function handleClaimAction(state, action) {
} }
if (collection) { if (collection) {
if (pendingIds.includes(collection.claim_id)) { if (pendingById[collection.claim_id]) {
byId[collection.claim_id] = mergeClaims(collection, byId[collection.claim_id]); byId[collection.claim_id] = mergeClaims(collection, byId[collection.claim_id]);
} else { } else {
byId[collection.claim_id] = collection; byId[collection.claim_id] = collection;
@ -6105,7 +6109,7 @@ function handleClaimAction(state, action) {
} }
newResolvingUrls.delete(url); newResolvingUrls.delete(url);
if (!stream && !channel && !collection && !pendingIds.includes(byUri[url])) { if (!stream && !channel && !collection && !pendingById[byUri[url]]) {
byUri[url] = null; byUri[url] = null;
} }
}); });
@ -6145,34 +6149,33 @@ reducers[FETCH_CLAIM_LIST_MINE_STARTED] = state => Object.assign({}, state, {
}); });
reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => { reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => {
const { result, resolve } = action.data; const { result } = action.data;
const claims = result.items; const claims = result.items;
const page = result.page; const page = result.page;
const totalItems = result.total_items; const totalItems = result.total_items;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const pendingIds = state.pendingIds || []; const pendingById = Object.assign({}, state.pendingById);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
let urlsForCurrentPage = []; let urlsForCurrentPage = [];
const pendingIdSet = new Set(pendingIds);
claims.forEach(claim => { claims.forEach(claim => {
const { permanent_url: permanentUri, claim_id: claimId } = claim; const { permanent_url: permanentUri, claim_id: claimId, canonical_url: canonicalUri } = claim;
if (claim.type && claim.type.match(/claim|update/)) { if (claim.type && claim.type.match(/claim|update/)) {
urlsForCurrentPage.push(permanentUri); urlsForCurrentPage.push(permanentUri);
if (claim.confirmations < 1) { if (claim.confirmations < 1) {
pendingIdSet.add(claimId); pendingById[claimId] = claim;
} else if (!resolve && pendingIdSet.has(claimId) && claim.confirmations > 0) { if (byId[claimId]) {
pendingIdSet.delete(claimId);
}
if (pendingIds.includes(claimId)) {
byId[claimId] = mergeClaims(claim, byId[claimId]); byId[claimId] = mergeClaims(claim, byId[claimId]);
} else { } else {
byId[claimId] = claim; byId[claimId] = claim;
} }
} else {
byId[claimId] = claim;
}
byUri[permanentUri] = claimId; byUri[permanentUri] = claimId;
byUri[canonicalUri] = claimId;
myClaimIds.add(claimId); myClaimIds.add(claimId);
} }
}); });
@ -6181,7 +6184,7 @@ reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => {
isFetchingClaimListMine: false, isFetchingClaimListMine: false,
myClaims: Array.from(myClaimIds), myClaims: Array.from(myClaimIds),
byId, byId,
pendingIds: Array.from(pendingIdSet), pendingById,
claimsByUri: byUri, claimsByUri: byUri,
myClaimsPageResults: urlsForCurrentPage, myClaimsPageResults: urlsForCurrentPage,
myClaimsPageNumber: page, myClaimsPageNumber: page,
@ -6193,9 +6196,8 @@ reducers[FETCH_CHANNEL_LIST_STARTED] = state => Object.assign({}, state, { fetch
reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
const { claims } = action.data; const { claims } = action.data;
const myClaims = state.myClaims || [];
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
const pendingIds = state.pendingIds || []; const pendingById = Object.assign({}, state.pendingById);
let myChannelClaims; let myChannelClaims;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
@ -6208,7 +6210,7 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
myChannelClaims = new Set(state.myChannelClaims); myChannelClaims = new Set(state.myChannelClaims);
claims.forEach(claim => { claims.forEach(claim => {
const { claims_in_channel: claimsInChannel } = claim.meta; const { claims_in_channel: claimsInChannel } = claim.meta;
const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId } = claim; const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId, confirmations } = claim;
byUri[canonicalUrl] = claimId; byUri[canonicalUrl] = claimId;
byUri[permanentUrl] = claimId; byUri[permanentUrl] = claimId;
@ -6217,7 +6219,14 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
// $FlowFixMe // $FlowFixMe
myChannelClaims.add(claimId); myChannelClaims.add(claimId);
if (!pendingIds.some(c => c === claimId)) { if (confirmations < 1) {
pendingById[claimId] = claim;
if (byId[claimId]) {
byId[claimId] = mergeClaims(claim, byId[claimId]);
} else {
byId[claimId] = claim;
}
} else {
byId[claimId] = claim; byId[claimId] = claim;
} }
myClaimIds.add(claimId); myClaimIds.add(claimId);
@ -6226,6 +6235,7 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => {
return Object.assign({}, state, { return Object.assign({}, state, {
byId, byId,
pendingById,
claimsByUri: byUri, claimsByUri: byUri,
channelClaimCounts, channelClaimCounts,
fetchingMyChannels: false, fetchingMyChannels: false,
@ -6248,7 +6258,7 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => {
const { claims } = action.data; const { claims } = action.data;
const myClaims = state.myClaims || []; const myClaims = state.myClaims || [];
let myClaimIds = new Set(myClaims); let myClaimIds = new Set(myClaims);
const pendingIds = state.pendingIds || []; const pendingById = Object.assign({}, state.pendingById);
let myCollectionClaimsSet = new Set([]); let myCollectionClaimsSet = new Set([]);
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
@ -6256,7 +6266,7 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => {
if (claims.length) { if (claims.length) {
myCollectionClaimsSet = new Set(state.myCollectionClaims); myCollectionClaimsSet = new Set(state.myCollectionClaims);
claims.forEach(claim => { claims.forEach(claim => {
const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId } = claim; const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId, confirmations } = claim;
byUri[canonicalUrl] = claimId; byUri[canonicalUrl] = claimId;
byUri[permanentUrl] = claimId; byUri[permanentUrl] = claimId;
@ -6264,7 +6274,14 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => {
// $FlowFixMe // $FlowFixMe
myCollectionClaimsSet.add(claimId); myCollectionClaimsSet.add(claimId);
// we don't want to overwrite a pending result with a resolve // we don't want to overwrite a pending result with a resolve
if (!pendingIds.some(c => c === claimId)) { if (confirmations < 1) {
pendingById[claimId] = claim;
if (byId[claimId]) {
byId[claimId] = mergeClaims(claim, byId[claimId]);
} else {
byId[claimId] = claim;
}
} else {
byId[claimId] = claim; byId[claimId] = claim;
} }
myClaimIds.add(claimId); myClaimIds.add(claimId);
@ -6273,6 +6290,7 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => {
return _extends$9({}, state, { return _extends$9({}, state, {
byId, byId,
pendingById,
claimsByUri: byUri, claimsByUri: byUri,
fetchingMyCollections: false, fetchingMyCollections: false,
myCollectionClaims: Array.from(myCollectionClaimsSet), myCollectionClaims: Array.from(myCollectionClaimsSet),
@ -6358,9 +6376,8 @@ reducers[ABANDON_CLAIM_STARTED] = (state, action) => {
reducers[UPDATE_PENDING_CLAIMS] = (state, action) => { reducers[UPDATE_PENDING_CLAIMS] = (state, action) => {
const { claims: pendingClaims } = action.data; const { claims: pendingClaims } = action.data;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const pendingById = Object.assign({}, state.pendingById);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const pendingIds = state.pendingIds;
const pendingIdSet = new Set(pendingIds);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
const myChannelClaims = new Set(state.myChannelClaims); const myChannelClaims = new Set(state.myChannelClaims);
@ -6368,7 +6385,7 @@ reducers[UPDATE_PENDING_CLAIMS] = (state, action) => {
pendingClaims.forEach(claim => { pendingClaims.forEach(claim => {
let newClaim; let newClaim;
const { permanent_url: uri, claim_id: claimId, type, value_type: valueType } = claim; const { permanent_url: uri, claim_id: claimId, type, value_type: valueType } = claim;
pendingIdSet.add(claimId); pendingById[claimId] = claim; // make sure we don't need to merge?
const oldClaim = byId[claimId]; const oldClaim = byId[claimId];
if (oldClaim && oldClaim.canonical_url) { if (oldClaim && oldClaim.canonical_url) {
newClaim = mergeClaims(oldClaim, claim); newClaim = mergeClaims(oldClaim, claim);
@ -6388,21 +6405,19 @@ reducers[UPDATE_PENDING_CLAIMS] = (state, action) => {
return Object.assign({}, state, { return Object.assign({}, state, {
myClaims: Array.from(myClaimIds), myClaims: Array.from(myClaimIds),
byId, byId,
pendingById,
myChannelClaims: Array.from(myChannelClaims), myChannelClaims: Array.from(myChannelClaims),
claimsByUri: byUri, claimsByUri: byUri
pendingIds: Array.from(pendingIdSet)
}); });
}; };
reducers[UPDATE_CONFIRMED_CLAIMS] = (state, action) => { reducers[UPDATE_CONFIRMED_CLAIMS] = (state, action) => {
const { claims: confirmedClaims } = action.data; const { claims: confirmedClaims, pending: pendingClaims } = action.data;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const pendingIds = state.pendingIds; //
const pendingIdSet = new Set(pendingIds);
confirmedClaims.forEach(claim => { confirmedClaims.forEach(claim => {
const { permanent_url: permanentUri, claim_id: claimId, type } = claim; const { claim_id: claimId, type } = claim;
let newClaim = claim; let newClaim = claim;
const oldClaim = byId[claimId]; const oldClaim = byId[claimId];
if (oldClaim && oldClaim.canonical_url) { if (oldClaim && oldClaim.canonical_url) {
@ -6410,11 +6425,10 @@ reducers[UPDATE_CONFIRMED_CLAIMS] = (state, action) => {
} }
if (type && type.match(/claim|update|channel/)) { if (type && type.match(/claim|update|channel/)) {
byId[claimId] = newClaim; byId[claimId] = newClaim;
pendingIdSet.delete(claimId);
} }
}); });
return Object.assign({}, state, { return Object.assign({}, state, {
pendingIds: Array.from(pendingIdSet), pendingById: pendingClaims,
byId, byId,
claimsByUri: byUri claimsByUri: byUri
}); });
@ -7938,7 +7952,6 @@ exports.makeSelectClaimIsNsfw = makeSelectClaimIsNsfw;
exports.makeSelectClaimIsPending = makeSelectClaimIsPending; exports.makeSelectClaimIsPending = makeSelectClaimIsPending;
exports.makeSelectClaimIsStreamPlaceholder = makeSelectClaimIsStreamPlaceholder; exports.makeSelectClaimIsStreamPlaceholder = makeSelectClaimIsStreamPlaceholder;
exports.makeSelectClaimWasPurchased = makeSelectClaimWasPurchased; exports.makeSelectClaimWasPurchased = makeSelectClaimWasPurchased;
exports.makeSelectClaimsInChannelForCurrentPageState = makeSelectClaimsInChannelForCurrentPageState;
exports.makeSelectClaimsInChannelForPage = makeSelectClaimsInChannelForPage; exports.makeSelectClaimsInChannelForPage = makeSelectClaimsInChannelForPage;
exports.makeSelectCollectionForId = makeSelectCollectionForId; exports.makeSelectCollectionForId = makeSelectCollectionForId;
exports.makeSelectCollectionForIdHasClaimUrl = makeSelectCollectionForIdHasClaimUrl; exports.makeSelectCollectionForIdHasClaimUrl = makeSelectCollectionForIdHasClaimUrl;
@ -7972,7 +7985,6 @@ exports.makeSelectMyPurchasesForPage = makeSelectMyPurchasesForPage;
exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage; exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage;
exports.makeSelectNameForCollectionId = makeSelectNameForCollectionId; exports.makeSelectNameForCollectionId = makeSelectNameForCollectionId;
exports.makeSelectNextUrlForCollectionAndUrl = makeSelectNextUrlForCollectionAndUrl; exports.makeSelectNextUrlForCollectionAndUrl = makeSelectNextUrlForCollectionAndUrl;
exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel;
exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris; exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris;
exports.makeSelectOmittedCountForChannel = makeSelectOmittedCountForChannel; exports.makeSelectOmittedCountForChannel = makeSelectOmittedCountForChannel;
exports.makeSelectPendingAmountByUri = makeSelectPendingAmountByUri; exports.makeSelectPendingAmountByUri = makeSelectPendingAmountByUri;

View file

@ -75,7 +75,7 @@ declare type BalanceResponse = {
declare type ResolveResponse = { declare type ResolveResponse = {
// Keys are the url(s) passed to resolve // Keys are the url(s) passed to resolve
[string]: { error?: {}, stream?: StreamClaim, channel?: ChannelClaim, claimsInChannel?: number }, [string]: { error?: {}, stream?: StreamClaim, channel?: ChannelClaim, collection?: CollectionClaim, claimsInChannel?: number },
}; };
declare type GetResponse = FileListItem & { error?: string }; declare type GetResponse = FileListItem & { error?: string };
@ -351,6 +351,7 @@ declare type LbryTypes = {
address_unused: (params: {}) => Promise<string>, // New address address_unused: (params: {}) => Promise<string>, // New address
address_list: (params: {}) => Promise<string>, address_list: (params: {}) => Promise<string>,
transaction_list: (params: {}) => Promise<TxListResponse>, transaction_list: (params: {}) => Promise<TxListResponse>,
txo_list: (params: {}) => Promise<any>,
// Sync // Sync
sync_hash: (params: {}) => Promise<string>, sync_hash: (params: {}) => Promise<string>,

3
flow-typed/Lbry.js vendored
View file

@ -75,7 +75,7 @@ declare type BalanceResponse = {
declare type ResolveResponse = { declare type ResolveResponse = {
// Keys are the url(s) passed to resolve // Keys are the url(s) passed to resolve
[string]: { error?: {}, stream?: StreamClaim, channel?: ChannelClaim, claimsInChannel?: number }, [string]: { error?: {}, stream?: StreamClaim, channel?: ChannelClaim, collection?: CollectionClaim, claimsInChannel?: number },
}; };
declare type GetResponse = FileListItem & { error?: string }; declare type GetResponse = FileListItem & { error?: string };
@ -351,6 +351,7 @@ declare type LbryTypes = {
address_unused: (params: {}) => Promise<string>, // New address address_unused: (params: {}) => Promise<string>, // New address
address_list: (params: {}) => Promise<string>, address_list: (params: {}) => Promise<string>,
transaction_list: (params: {}) => Promise<TxListResponse>, transaction_list: (params: {}) => Promise<TxListResponse>,
txo_list: (params: {}) => Promise<any>,
// Sync // Sync
sync_hash: (params: {}) => Promise<string>, sync_hash: (params: {}) => Promise<string>,

View file

@ -209,7 +209,7 @@ export {
makeSelectTotalItemsForChannel, makeSelectTotalItemsForChannel,
makeSelectTotalPagesForChannel, makeSelectTotalPagesForChannel,
makeSelectNsfwCountFromUris, makeSelectNsfwCountFromUris,
makeSelectNsfwCountForChannel, // makeSelectNsfwCountForChannel,
makeSelectOmittedCountForChannel, makeSelectOmittedCountForChannel,
makeSelectClaimIsNsfw, makeSelectClaimIsNsfw,
makeSelectChannelForClaimUri, makeSelectChannelForClaimUri,
@ -217,7 +217,7 @@ export {
makeSelectMyChannelPermUrlForName, makeSelectMyChannelPermUrlForName,
makeSelectClaimIsPending, makeSelectClaimIsPending,
makeSelectReflectingClaimForUri, makeSelectReflectingClaimForUri,
makeSelectClaimsInChannelForCurrentPageState, // makeSelectClaimsInChannelForCurrentPageState,
makeSelectShortUrlForUri, makeSelectShortUrlForUri,
makeSelectCanonicalUrlForUri, makeSelectCanonicalUrlForUri,
makeSelectPermanentUrlForUri, makeSelectPermanentUrlForUri,

View file

@ -117,6 +117,7 @@ const Lbry: LbryTypes = {
utxo_release: (params = {}) => daemonCallWithResult('utxo_release', params), utxo_release: (params = {}) => daemonCallWithResult('utxo_release', params),
support_abandon: (params = {}) => daemonCallWithResult('support_abandon', params), support_abandon: (params = {}) => daemonCallWithResult('support_abandon', params),
purchase_list: (params = {}) => daemonCallWithResult('purchase_list', params), purchase_list: (params = {}) => daemonCallWithResult('purchase_list', params),
txo_list: (params = {}) => daemonCallWithResult('txo_list', params),
sync_hash: (params = {}) => daemonCallWithResult('sync_hash', params), sync_hash: (params = {}) => daemonCallWithResult('sync_hash', params),
sync_apply: (params = {}) => daemonCallWithResult('sync_apply', params), sync_apply: (params = {}) => daemonCallWithResult('sync_apply', params),

View file

@ -18,14 +18,16 @@ import { creditsToString } from 'util/format-credits';
import { batchActions } from 'util/batch-actions'; import { batchActions } from 'util/batch-actions';
import { createNormalizedClaimSearchKey } from 'util/claim'; import { createNormalizedClaimSearchKey } from 'util/claim';
import { PAGE_SIZE } from 'constants/claim'; import { PAGE_SIZE } from 'constants/claim';
import { import { selectPendingCollections } from 'redux/selectors/collections';
selectPendingCollections,
} from 'redux/selectors/collections';
import { import {
doFetchItemsInCollection, doFetchItemsInCollection,
doFetchItemsInCollections, doFetchItemsInCollections,
doCollectionDelete, doCollectionDelete,
} from 'redux/actions/collections'; } from 'redux/actions/collections';
import { selectPendingClaimsById } from '../selectors/claims';
let checkPendingCallbacks = [];
let checkPendingInterval;
export function doResolveUris( export function doResolveUris(
uris: Array<string>, uris: Array<string>,
@ -979,48 +981,50 @@ export const doCheckPendingClaims = (onConfirmed: Function) => (
dispatch: Dispatch, dispatch: Dispatch,
getState: GetState getState: GetState
) => { ) => {
let claimCheckInterval; clearInterval(checkPendingInterval);
const checkTxoList = checkPendingCallbacks => {
const checkClaimList = () => {
const state = getState(); const state = getState();
const pendingIdSet = new Set(selectPendingIds(state)); const pendingById = Object.assign({}, selectPendingClaimsById(state));
const pendingTxos = (Object.values(pendingById): any).map(p => p.txid);
// use collections
const pendingCollections = selectPendingCollections(state); const pendingCollections = selectPendingCollections(state);
Lbry.claim_list({ page: 1, page_size: 10 }) if (pendingTxos.length) {
Lbry.txo_list({ txid: pendingTxos })
.then(result => { .then(result => {
const claims = result.items; const txos = result.items;
const claimsToConfirm = []; const idsToConfirm = [];
claims.forEach(claim => { txos.forEach(txo => {
const { claim_id: claimId } = claim; if (txo.claim_id && txo.confirmations > 0) {
if (claim.confirmations > 0 && pendingIdSet.has(claimId)) { idsToConfirm.push(txo.claim_id);
pendingIdSet.delete(claimId); delete pendingById[txo.claim_id];
if (Object.keys(pendingCollections).includes(claim.claim_id)) {
dispatch(doFetchItemsInCollection({ collectionId: claim.claim_id }));
dispatch(doCollectionDelete(claim.claim_id, 'pending'));
}
claimsToConfirm.push(claim);
if (onConfirmed) {
onConfirmed(claim);
}
} }
}); });
if (claimsToConfirm.length) { return { idsToConfirm, pendingById };
})
.then(results => {
const { idsToConfirm, pendingById } = results;
if (idsToConfirm.length) {
return Lbry.claim_list({ claim_id: idsToConfirm, resolve: true }).then(results => {
const claims = results.items;
// what if results.items includes a collection?
dispatch({ dispatch({
type: ACTIONS.UPDATE_CONFIRMED_CLAIMS, type: ACTIONS.UPDATE_CONFIRMED_CLAIMS,
data: { data: {
claims: claimsToConfirm, claims: claims,
pending: pendingById,
}, },
}); });
} checkPendingCallbacks.forEach(cb => cb());
return pendingIdSet.size; clearInterval(checkPendingInterval);
}) });
.then(len => {
if (!len) {
clearInterval(claimCheckInterval);
} }
}); });
} else {
clearInterval(checkPendingInterval);
}
}; };
// do something with onConfirmed (typically get blocklist for channel)
claimCheckInterval = setInterval(() => { checkPendingInterval = setInterval(() => {
checkClaimList(); checkTxoList(checkPendingCallbacks);
}, 30000); }, 30000);
}; };

View file

@ -17,8 +17,8 @@ type State = {
channelClaimCounts: { [string]: number }, channelClaimCounts: { [string]: number },
claimsByUri: { [string]: string }, claimsByUri: { [string]: string },
byId: { [string]: Claim }, byId: { [string]: Claim },
pendingById: { [string]: Claim }, // keep pending claims
resolvingUris: Array<string>, resolvingUris: Array<string>,
pendingIds: Array<string>,
reflectingById: { [string]: ReflectingUpdate }, reflectingById: { [string]: ReflectingUpdate },
myClaims: ?Array<string>, myClaims: ?Array<string>,
myChannelClaims: ?Array<string>, myChannelClaims: ?Array<string>,
@ -83,7 +83,7 @@ const defaultState = {
fetchingMyChannels: false, fetchingMyChannels: false,
fetchingMyCollections: false, fetchingMyCollections: false,
abandoningById: {}, abandoningById: {},
pendingIds: [], pendingById: {},
reflectingById: {}, reflectingById: {},
claimSearchError: false, claimSearchError: false,
claimSearchByQuery: {}, claimSearchByQuery: {},
@ -117,7 +117,7 @@ function handleClaimAction(state: State, action: any): State {
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const channelClaimCounts = Object.assign({}, state.channelClaimCounts); const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
const pendingIds = state.pendingIds; const pendingById = state.pendingById;
let newResolvingUrls = new Set(state.resolvingUris); let newResolvingUrls = new Set(state.resolvingUris);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
@ -127,7 +127,7 @@ function handleClaimAction(state: State, action: any): State {
const channel = channelFromResolve || (stream && stream.signing_channel); const channel = channelFromResolve || (stream && stream.signing_channel);
if (stream) { if (stream) {
if (pendingIds.includes(stream.claim_id)) { if (pendingById[stream.claim_id]) {
byId[stream.claim_id] = mergeClaim(stream, byId[stream.claim_id]); byId[stream.claim_id] = mergeClaim(stream, byId[stream.claim_id]);
} else { } else {
byId[stream.claim_id] = stream; byId[stream.claim_id] = stream;
@ -157,7 +157,7 @@ function handleClaimAction(state: State, action: any): State {
channelClaimCounts[channel.canonical_url] = claimsInChannel; channelClaimCounts[channel.canonical_url] = claimsInChannel;
} }
if (pendingIds.includes(channel.claim_id)) { if (pendingById[channel.claim_id]) {
byId[channel.claim_id] = mergeClaim(channel, byId[channel.claim_id]); byId[channel.claim_id] = mergeClaim(channel, byId[channel.claim_id]);
} else { } else {
byId[channel.claim_id] = channel; byId[channel.claim_id] = channel;
@ -170,7 +170,7 @@ function handleClaimAction(state: State, action: any): State {
} }
if (collection) { if (collection) {
if (pendingIds.includes(collection.claim_id)) { if (pendingById[collection.claim_id]) {
byId[collection.claim_id] = mergeClaim(collection, byId[collection.claim_id]); byId[collection.claim_id] = mergeClaim(collection, byId[collection.claim_id]);
} else { } else {
byId[collection.claim_id] = collection; byId[collection.claim_id] = collection;
@ -187,7 +187,7 @@ function handleClaimAction(state: State, action: any): State {
} }
newResolvingUrls.delete(url); newResolvingUrls.delete(url);
if (!stream && !channel && !collection && !pendingIds.includes(byUri[url])) { if (!stream && !channel && !collection && !pendingById[byUri[url]]) {
byUri[url] = null; byUri[url] = null;
} }
}); });
@ -230,34 +230,33 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_STARTED] = (state: State): State =>
}); });
reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any): State => { reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any): State => {
const { result, resolve }: { result: ClaimListResponse, resolve: boolean } = action.data; const { result }: { result: ClaimListResponse } = action.data;
const claims = result.items; const claims = result.items;
const page = result.page; const page = result.page;
const totalItems = result.total_items; const totalItems = result.total_items;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const pendingIds = state.pendingIds || []; const pendingById = Object.assign({}, state.pendingById);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
let urlsForCurrentPage = []; let urlsForCurrentPage = [];
const pendingIdSet = new Set(pendingIds);
claims.forEach((claim: Claim) => { claims.forEach((claim: Claim) => {
const { permanent_url: permanentUri, claim_id: claimId } = claim; const { permanent_url: permanentUri, claim_id: claimId, canonical_url: canonicalUri } = claim;
if (claim.type && claim.type.match(/claim|update/)) { if (claim.type && claim.type.match(/claim|update/)) {
urlsForCurrentPage.push(permanentUri); urlsForCurrentPage.push(permanentUri);
if (claim.confirmations < 1) { if (claim.confirmations < 1) {
pendingIdSet.add(claimId); pendingById[claimId] = claim;
} else if (!resolve && pendingIdSet.has(claimId) && claim.confirmations > 0) { if (byId[claimId]) {
pendingIdSet.delete(claimId);
}
if (pendingIds.includes(claimId)) {
byId[claimId] = mergeClaim(claim, byId[claimId]); byId[claimId] = mergeClaim(claim, byId[claimId]);
} else { } else {
byId[claimId] = claim; byId[claimId] = claim;
} }
} else {
byId[claimId] = claim;
}
byUri[permanentUri] = claimId; byUri[permanentUri] = claimId;
byUri[canonicalUri] = claimId;
myClaimIds.add(claimId); myClaimIds.add(claimId);
} }
}); });
@ -266,7 +265,7 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any):
isFetchingClaimListMine: false, isFetchingClaimListMine: false,
myClaims: Array.from(myClaimIds), myClaims: Array.from(myClaimIds),
byId, byId,
pendingIds: Array.from(pendingIdSet), pendingById,
claimsByUri: byUri, claimsByUri: byUri,
myClaimsPageResults: urlsForCurrentPage, myClaimsPageResults: urlsForCurrentPage,
myClaimsPageNumber: page, myClaimsPageNumber: page,
@ -279,9 +278,8 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_STARTED] = (state: State): State =>
reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): State => { reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): State => {
const { claims }: { claims: Array<ChannelClaim> } = action.data; const { claims }: { claims: Array<ChannelClaim> } = action.data;
const myClaims = state.myClaims || [];
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
const pendingIds = state.pendingIds || []; const pendingById = Object.assign({}, state.pendingById);
let myChannelClaims; let myChannelClaims;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
@ -295,7 +293,12 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
claims.forEach(claim => { claims.forEach(claim => {
const { meta } = claim; const { meta } = claim;
const { claims_in_channel: claimsInChannel } = claim.meta; const { claims_in_channel: claimsInChannel } = claim.meta;
const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId } = claim; const {
canonical_url: canonicalUrl,
permanent_url: permanentUrl,
claim_id: claimId,
confirmations,
} = claim;
byUri[canonicalUrl] = claimId; byUri[canonicalUrl] = claimId;
byUri[permanentUrl] = claimId; byUri[permanentUrl] = claimId;
@ -304,7 +307,14 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
// $FlowFixMe // $FlowFixMe
myChannelClaims.add(claimId); myChannelClaims.add(claimId);
if (!pendingIds.some(c => c === claimId)) { if (confirmations < 1) {
pendingById[claimId] = claim;
if (byId[claimId]) {
byId[claimId] = mergeClaim(claim, byId[claimId]);
} else {
byId[claimId] = claim;
}
} else {
byId[claimId] = claim; byId[claimId] = claim;
} }
myClaimIds.add(claimId); myClaimIds.add(claimId);
@ -313,6 +323,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St
return Object.assign({}, state, { return Object.assign({}, state, {
byId, byId,
pendingById,
claimsByUri: byUri, claimsByUri: byUri,
channelClaimCounts, channelClaimCounts,
fetchingMyChannels: false, fetchingMyChannels: false,
@ -336,7 +347,7 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
const { claims }: { claims: Array<CollectionClaim> } = action.data; const { claims }: { claims: Array<CollectionClaim> } = action.data;
const myClaims = state.myClaims || []; const myClaims = state.myClaims || [];
let myClaimIds = new Set(myClaims); let myClaimIds = new Set(myClaims);
const pendingIds = state.pendingIds || []; const pendingById = Object.assign({}, state.pendingById);
let myCollectionClaimsSet = new Set([]); let myCollectionClaimsSet = new Set([]);
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
@ -345,7 +356,12 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
myCollectionClaimsSet = new Set(state.myCollectionClaims); myCollectionClaimsSet = new Set(state.myCollectionClaims);
claims.forEach(claim => { claims.forEach(claim => {
const { meta } = claim; const { meta } = claim;
const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId } = claim; const {
canonical_url: canonicalUrl,
permanent_url: permanentUrl,
claim_id: claimId,
confirmations,
} = claim;
byUri[canonicalUrl] = claimId; byUri[canonicalUrl] = claimId;
byUri[permanentUrl] = claimId; byUri[permanentUrl] = claimId;
@ -353,7 +369,14 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
// $FlowFixMe // $FlowFixMe
myCollectionClaimsSet.add(claimId); myCollectionClaimsSet.add(claimId);
// we don't want to overwrite a pending result with a resolve // we don't want to overwrite a pending result with a resolve
if (!pendingIds.some(c => c === claimId)) { if (confirmations < 1) {
pendingById[claimId] = claim;
if (byId[claimId]) {
byId[claimId] = mergeClaim(claim, byId[claimId]);
} else {
byId[claimId] = claim;
}
} else {
byId[claimId] = claim; byId[claimId] = claim;
} }
myClaimIds.add(claimId); myClaimIds.add(claimId);
@ -363,6 +386,7 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any):
return { return {
...state, ...state,
byId, byId,
pendingById,
claimsByUri: byUri, claimsByUri: byUri,
fetchingMyCollections: false, fetchingMyCollections: false,
myCollectionClaims: Array.from(myCollectionClaimsSet), myCollectionClaims: Array.from(myCollectionClaimsSet),
@ -455,9 +479,8 @@ reducers[ACTIONS.ABANDON_CLAIM_STARTED] = (state: State, action: any): State =>
reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => { reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => {
const { claims: pendingClaims }: { claims: Array<Claim> } = action.data; const { claims: pendingClaims }: { claims: Array<Claim> } = action.data;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const pendingById = Object.assign({}, state.pendingById);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const pendingIds = state.pendingIds;
const pendingIdSet = new Set(pendingIds);
let myClaimIds = new Set(state.myClaims); let myClaimIds = new Set(state.myClaims);
const myChannelClaims = new Set(state.myChannelClaims); const myChannelClaims = new Set(state.myChannelClaims);
@ -465,7 +488,7 @@ reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State =>
pendingClaims.forEach((claim: Claim) => { pendingClaims.forEach((claim: Claim) => {
let newClaim; let newClaim;
const { permanent_url: uri, claim_id: claimId, type, value_type: valueType } = claim; const { permanent_url: uri, claim_id: claimId, type, value_type: valueType } = claim;
pendingIdSet.add(claimId); pendingById[claimId] = claim; // make sure we don't need to merge?
const oldClaim = byId[claimId]; const oldClaim = byId[claimId];
if (oldClaim && oldClaim.canonical_url) { if (oldClaim && oldClaim.canonical_url) {
newClaim = mergeClaim(oldClaim, claim); newClaim = mergeClaim(oldClaim, claim);
@ -485,21 +508,22 @@ reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State =>
return Object.assign({}, state, { return Object.assign({}, state, {
myClaims: Array.from(myClaimIds), myClaims: Array.from(myClaimIds),
byId, byId,
pendingById,
myChannelClaims: Array.from(myChannelClaims), myChannelClaims: Array.from(myChannelClaims),
claimsByUri: byUri, claimsByUri: byUri,
pendingIds: Array.from(pendingIdSet),
}); });
}; };
reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => { reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => {
const { claims: confirmedClaims }: { claims: Array<Claim> } = action.data; const {
claims: confirmedClaims,
pending: pendingClaims,
}: { claims: Array<Claim>, pending: { [string]: Claim } } = action.data;
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const pendingIds = state.pendingIds; //
const pendingIdSet = new Set(pendingIds);
confirmedClaims.forEach((claim: GenericClaim) => { confirmedClaims.forEach((claim: GenericClaim) => {
const { permanent_url: permanentUri, claim_id: claimId, type } = claim; const { claim_id: claimId, type } = claim;
let newClaim = claim; let newClaim = claim;
const oldClaim = byId[claimId]; const oldClaim = byId[claimId];
if (oldClaim && oldClaim.canonical_url) { if (oldClaim && oldClaim.canonical_url) {
@ -507,11 +531,10 @@ reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State =
} }
if (type && type.match(/claim|update|channel/)) { if (type && type.match(/claim|update|channel/)) {
byId[claimId] = newClaim; byId[claimId] = newClaim;
pendingIdSet.delete(claimId);
} }
}); });
return Object.assign({}, state, { return Object.assign({}, state, {
pendingIds: Array.from(pendingIdSet), pendingById: pendingClaims,
byId, byId,
claimsByUri: byUri, claimsByUri: byUri,
}); });

View file

@ -1,5 +1,5 @@
// @flow // @flow
import { normalizeURI, buildURI, parseURI } from 'lbryURI'; import { normalizeURI, parseURI } from 'lbryURI';
import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { isClaimNsfw, filterClaims } from 'util/claim'; import { isClaimNsfw, filterClaims } from 'util/claim';
@ -7,11 +7,24 @@ import * as CLAIM from 'constants/claim';
const selectState = state => state.claims || {}; const selectState = state => state.claims || {};
export const selectClaimsById = createSelector( export const selectById = createSelector(
selectState, selectState,
state => state.byId || {} state => state.byId || {}
); );
export const selectPendingClaimsById = createSelector(
selectState,
state => state.pendingById || {}
);
export const selectClaimsById = createSelector(
selectById,
selectPendingClaimsById,
(byId, pendingById) => {
return Object.assign(byId, pendingById); // do I need merged?
}
);
export const selectClaimIdsByUri = createSelector( export const selectClaimIdsByUri = createSelector(
selectState, selectState,
state => state.claimsByUri || {} state => state.claimsByUri || {}
@ -72,33 +85,33 @@ export const selectAllClaimsByChannel = createSelector(
export const selectPendingIds = createSelector( export const selectPendingIds = createSelector(
selectState, selectState,
state => state.pendingIds || [] state => Object.keys(state.pendingIds) || []
); );
export const selectPendingClaims = createSelector( export const selectPendingClaims = createSelector(
selectPendingIds, selectPendingClaimsById,
selectClaimsById, pendingById => Object.values(pendingById)
(pendingIds, byId) => pendingIds.map(id => byId[id])
); );
export const makeSelectClaimIsPending = (uri: string) => export const makeSelectClaimIsPending = (uri: string) =>
createSelector( createSelector(
selectClaimIdsByUri, selectClaimIdsByUri,
selectPendingIds, selectPendingClaimsById,
(idsByUri, pendingIds) => { (idsByUri, pendingById) => {
const claimId = idsByUri[normalizeURI(uri)]; const claimId = idsByUri[normalizeURI(uri)];
if (claimId) { if (claimId) {
return pendingIds.some(i => i === claimId); return Boolean(pendingById[claimId]);
} }
return false; return false;
} }
); );
export const makeSelectClaimIdIsPending = (claimId: string) => createSelector( export const makeSelectClaimIdIsPending = (claimId: string) =>
selectPendingIds, createSelector(
(pendingIds) => { selectPendingClaimsById,
return pendingIds.some(i => i === claimId); pendingById => {
return Boolean(pendingById[claimId]);
} }
); );
@ -113,12 +126,14 @@ export const selectReflectingById = createSelector(
state => state.reflectingById state => state.reflectingById
); );
// use pendingFirst
export const makeSelectClaimForClaimId = (claimId: string) => export const makeSelectClaimForClaimId = (claimId: string) =>
createSelector( createSelector(
selectClaimsById, selectClaimsById,
byId => byId[claimId] byId => byId[claimId]
); );
// use pendingFirst
export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) => export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) =>
createSelector( createSelector(
selectClaimIdsByUri, selectClaimIdsByUri,
@ -163,6 +178,7 @@ export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true)
} }
); );
// use pendingFirst
export const selectMyClaimsRaw = createSelector( export const selectMyClaimsRaw = createSelector(
selectState, selectState,
selectClaimsById, selectClaimsById,
@ -311,6 +327,7 @@ export const makeSelectFetchingChannelClaims = (uri: string) =>
fetching => fetching && fetching[uri] fetching => fetching && fetching[uri]
); );
// use pendingFirst
export const makeSelectClaimsInChannelForPage = (uri: string, page?: number) => export const makeSelectClaimsInChannelForPage = (uri: string, page?: number) =>
createSelector( createSelector(
selectClaimsById, selectClaimsById,
@ -325,6 +342,7 @@ export const makeSelectClaimsInChannelForPage = (uri: string, page?: number) =>
} }
); );
// THIS IS LEFT OVER FROM ONE TAB CHANNEL_CONTENT
export const makeSelectTotalClaimsInChannelSearch = (uri: string) => export const makeSelectTotalClaimsInChannelSearch = (uri: string) =>
createSelector( createSelector(
selectClaimsById, selectClaimsById,
@ -335,6 +353,7 @@ export const makeSelectTotalClaimsInChannelSearch = (uri: string) =>
} }
); );
// THIS IS LEFT OVER FROM ONE_TAB CHANNEL CONTENT
export const makeSelectTotalPagesInChannelSearch = (uri: string) => export const makeSelectTotalPagesInChannelSearch = (uri: string) =>
createSelector( createSelector(
selectClaimsById, selectClaimsById,
@ -345,20 +364,20 @@ export const makeSelectTotalPagesInChannelSearch = (uri: string) =>
} }
); );
export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) => // export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) =>
createSelector( // createSelector(
selectClaimsById, // selectClaimsById,
selectAllClaimsByChannel, // selectAllClaimsByChannel,
selectCurrentChannelPage, // selectCurrentChannelPage,
(byId, allClaims, page) => { // (byId, allClaims, page) => {
const byChannel = allClaims[uri] || {}; // const byChannel = allClaims[uri] || {};
const claimIds = byChannel[page || 1]; // const claimIds = byChannel[page || 1];
//
if (!claimIds) return claimIds; // if (!claimIds) return claimIds;
//
return claimIds.map(claimId => byId[claimId]); // return claimIds.map(claimId => byId[claimId]);
} // }
); // );
export const makeSelectMetadataForUri = (uri: string) => export const makeSelectMetadataForUri = (uri: string) =>
createSelector( createSelector(
@ -480,6 +499,7 @@ export const selectFetchingMyClaimsPageError = createSelector(
state => state.fetchingClaimListMinePageError state => state.fetchingClaimListMinePageError
); );
// use pendingFirst
export const selectMyClaims = createSelector( export const selectMyClaims = createSelector(
selectMyActiveClaims, selectMyActiveClaims,
selectClaimsById, selectClaimsById,
@ -500,7 +520,9 @@ export const selectMyClaims = createSelector(
export const selectMyClaimsWithoutChannels = createSelector( export const selectMyClaimsWithoutChannels = createSelector(
selectMyClaims, selectMyClaims,
myClaims => myClaims =>
myClaims.filter(claim => claim && !claim.name.match(/^@/)).sort((a, b) => a.timestamp - b.timestamp) myClaims
.filter(claim => claim && !claim.name.match(/^@/))
.sort((a, b) => a.timestamp - b.timestamp)
); );
export const selectMyClaimUrisWithoutChannels = createSelector( export const selectMyClaimUrisWithoutChannels = createSelector(
@ -549,6 +571,7 @@ export const selectFetchingMyCollections = createSelector(
state => state.fetchingMyCollections state => state.fetchingMyCollections
); );
// use pendingFirst
export const selectMyChannelClaims = createSelector( export const selectMyChannelClaims = createSelector(
selectState, selectState,
selectClaimsById, selectClaimsById,
@ -606,33 +629,21 @@ export const selectChannelClaimCounts = createSelector(
state => state.channelClaimCounts || {} state => state.channelClaimCounts || {}
); );
// JUST PENDING - change this
export const makeSelectPendingClaimForUri = (uri: string) => export const makeSelectPendingClaimForUri = (uri: string) =>
createSelector( createSelector(
selectPendingIds, selectPendingClaimsById,
selectClaimsById, pendingById => {
(pending, claims) => {
let validUri;
let uriIsChannel;
let uriStreamName; let uriStreamName;
let uriChannelName; let uriChannelName;
try { try {
({ ({ streamName: uriStreamName, channelName: uriChannelName } = parseURI(uri));
isChannel: uriIsChannel,
streamName: uriStreamName,
channelName: uriChannelName,
} = parseURI(uri));
validUri = true;
} catch (e) { } catch (e) {
return null; return null;
} }
const pendingClaims = pending.map(id => claims[id]); const pendingClaims = (Object.values(pendingById): any);
const matchingClaim = pendingClaims.find(claim => { const matchingClaim = pendingClaims.find((claim: GenericClaim) => {
const { streamName, channelName, isChannel } = parseURI(claim.permanent_url); return claim.normalized_name === uriChannelName || claim.normalized_name === uriStreamName;
if (isChannel) {
return channelName === uriChannelName;
} else {
return streamName === uriStreamName;
}
}); });
return matchingClaim || null; return matchingClaim || null;
} }
@ -663,27 +674,6 @@ export const makeSelectNsfwCountFromUris = (uris: Array<string>) =>
}, 0) }, 0)
); );
export const makeSelectNsfwCountForChannel = (uri: string) =>
createSelector(
selectClaimsById,
selectAllClaimsByChannel,
selectCurrentChannelPage,
(byId, allClaims, page) => {
const byChannel = allClaims[uri] || {};
const claimIds = byChannel[page || 1];
if (!claimIds) return 0;
return claimIds.reduce((acc, claimId) => {
const claim = byId[claimId];
if (isClaimNsfw(claim)) {
return acc + 1;
}
return acc;
}, 0);
}
);
export const makeSelectOmittedCountForChannel = (uri: string) => export const makeSelectOmittedCountForChannel = (uri: string) =>
createSelector( createSelector(
makeSelectTotalItemsForChannel(uri), makeSelectTotalItemsForChannel(uri),
@ -763,14 +753,6 @@ export const makeSelectTagsForUri = (uri: string) =>
} }
); );
export const makeSelectChannelTagsForUri = (uri: string) =>
createSelector(
makeSelectMetadataForUri(uri),
(metadata: ?GenericMetadata) => {
return (metadata && metadata.tags) || [];
}
);
export const selectFetchingClaimSearchByQuery = createSelector( export const selectFetchingClaimSearchByQuery = createSelector(
selectState, selectState,
state => state.fetchingClaimSearchByQuery || {} state => state.fetchingClaimSearchByQuery || {}