store pendingById #418
9 changed files with 307 additions and 290 deletions
263
dist/bundle.es.js
vendored
263
dist/bundle.es.js
vendored
|
@ -1190,6 +1190,7 @@ const Lbry = {
|
||||||
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),
|
||||||
|
@ -2370,7 +2371,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 to keep metadata?
|
||||||
|
});
|
||||||
|
|
||||||
const selectClaimIdsByUri = reselect.createSelector(selectState$1, state => state.claimsByUri || {});
|
const selectClaimIdsByUri = reselect.createSelector(selectState$1, state => state.claimsByUri || {});
|
||||||
|
|
||||||
|
@ -2405,21 +2412,21 @@ 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]);
|
||||||
|
@ -2552,25 +2559,18 @@ 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) => {
|
|
||||||
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;
|
||||||
return metadata || (claim === undefined ? undefined : null);
|
return metadata || (claim === undefined ? undefined : null);
|
||||||
|
@ -2697,27 +2697,17 @@ 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) => {
|
const makeSelectPendingClaimForUri = uri => reselect.createSelector(selectPendingClaimsById, pendingById => {
|
||||||
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));
|
|
||||||
} 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 +2724,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;
|
||||||
|
@ -3690,7 +3665,7 @@ const makeSelectIsResolvingCollectionForId = id => reselect.createSelector(selec
|
||||||
});
|
});
|
||||||
|
|
||||||
const makeSelectCollectionForId = id => reselect.createSelector(selectBuiltinCollections, selectResolvedCollections, selectMyUnpublishedCollections, selectMyEditedCollections, selectPendingCollections, (bLists, rLists, uLists, eLists, pLists) => {
|
const makeSelectCollectionForId = id => reselect.createSelector(selectBuiltinCollections, selectResolvedCollections, selectMyUnpublishedCollections, selectMyEditedCollections, selectPendingCollections, (bLists, rLists, uLists, eLists, pLists) => {
|
||||||
const collection = bLists[id] || uLists[id] || eLists[id] || rLists[id] || pLists[id];
|
const collection = bLists[id] || uLists[id] || eLists[id] || pLists[id] || rLists[id];
|
||||||
return collection;
|
return collection;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3748,6 +3723,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 onChannelConfirmCallback;
|
||||||
|
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);
|
||||||
|
@ -4086,7 +4064,7 @@ function doClearChannelErrors() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function doCreateChannel(name, amount, optionalParams, cb) {
|
function doCreateChannel(name, amount, optionalParams, onConfirm) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: CREATE_CHANNEL_STARTED
|
type: CREATE_CHANNEL_STARTED
|
||||||
|
@ -4140,7 +4118,7 @@ function doCreateChannel(name, amount, optionalParams, cb) {
|
||||||
claims: [channelClaim]
|
claims: [channelClaim]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dispatch(doCheckPendingClaims(cb));
|
dispatch(doCheckPendingClaims(onConfirm));
|
||||||
return channelClaim;
|
return channelClaim;
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({
|
dispatch({
|
||||||
|
@ -4490,7 +4468,6 @@ function doCollectionPublishUpdate(options) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dispatch(doCheckPendingClaims());
|
dispatch(doCheckPendingClaims());
|
||||||
dispatch(doFetchCollectionListMine(1, 10));
|
|
||||||
return resolve(collectionClaim);
|
return resolve(collectionClaim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4570,48 +4547,63 @@ function doPurchaseList(page = 1, pageSize = PAGE_SIZE) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const doCheckPendingClaims = onConfirmed => (dispatch, getState) => {
|
const doCheckPendingClaims = onChannelConfirmed => (dispatch, getState) => {
|
||||||
let claimCheckInterval;
|
if (onChannelConfirmed) {
|
||||||
|
onChannelConfirmCallback = onChannelConfirmed;
|
||||||
const checkClaimList = () => {
|
}
|
||||||
|
clearInterval(checkPendingInterval);
|
||||||
|
const checkTxoList = () => {
|
||||||
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) {
|
|
||||||
dispatch({
|
|
||||||
type: UPDATE_CONFIRMED_CLAIMS,
|
|
||||||
data: {
|
|
||||||
claims: claimsToConfirm
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
return { idsToConfirm, pendingById };
|
||||||
return pendingIdSet.size;
|
}).then(results => {
|
||||||
}).then(len => {
|
const { idsToConfirm, pendingById } = results;
|
||||||
if (!len) {
|
if (idsToConfirm.length) {
|
||||||
clearInterval(claimCheckInterval);
|
return lbryProxy.claim_list({ claim_id: idsToConfirm, resolve: true }).then(results => {
|
||||||
}
|
const claims = results.items;
|
||||||
});
|
const collectionIds = claims.filter(c => c.value_type === 'collection').map(c => c.claim_id);
|
||||||
|
dispatch({
|
||||||
|
type: UPDATE_CONFIRMED_CLAIMS,
|
||||||
|
data: {
|
||||||
|
claims: claims,
|
||||||
|
pending: pendingById
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (collectionIds.length) {
|
||||||
|
dispatch(doFetchItemsInCollections({
|
||||||
|
collectionIds
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
const channelClaims = claims.filter(claim => claim.value_type === 'channel');
|
||||||
|
if (channelClaims.length && onChannelConfirmCallback) {
|
||||||
|
channelClaims.forEach(claim => onChannelConfirmCallback(claim));
|
||||||
|
}
|
||||||
|
if (Object.keys(pendingById).length === 0) {
|
||||||
|
clearInterval(checkPendingInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
clearInterval(checkPendingInterval);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
// do something with onConfirmed (typically get blocklist for channel)
|
||||||
claimCheckInterval = setInterval(() => {
|
checkPendingInterval = setInterval(() => {
|
||||||
checkClaimList();
|
checkTxoList();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6001,7 +5993,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 +6027,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 +6037,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 +6067,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 +6080,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 +6097,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 +6137,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);
|
byId[claimId] = mergeClaims(claim, byId[claimId]);
|
||||||
}
|
} else {
|
||||||
if (pendingIds.includes(claimId)) {
|
byId[claimId] = claim;
|
||||||
byId[claimId] = mergeClaims(claim, byId[claimId]);
|
}
|
||||||
} else {
|
} else {
|
||||||
byId[claimId] = claim;
|
byId[claimId] = claim;
|
||||||
}
|
}
|
||||||
byUri[permanentUri] = claimId;
|
byUri[permanentUri] = claimId;
|
||||||
|
byUri[canonicalUri] = claimId;
|
||||||
myClaimIds.add(claimId);
|
myClaimIds.add(claimId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6181,7 +6172,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 +6184,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 +6198,12 @@ 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 +6212,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 +6228,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 +6251,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 +6259,12 @@ 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 +6272,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 +6288,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 +6374,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 +6383,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 +6403,22 @@ 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 +6426,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 +7953,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 +7986,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;
|
||||||
|
|
3
dist/flow-typed/Lbry.js
vendored
3
dist/flow-typed/Lbry.js
vendored
|
@ -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
3
flow-typed/Lbry.js
vendored
|
@ -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>,
|
||||||
|
|
|
@ -209,7 +209,6 @@ export {
|
||||||
makeSelectTotalItemsForChannel,
|
makeSelectTotalItemsForChannel,
|
||||||
makeSelectTotalPagesForChannel,
|
makeSelectTotalPagesForChannel,
|
||||||
makeSelectNsfwCountFromUris,
|
makeSelectNsfwCountFromUris,
|
||||||
makeSelectNsfwCountForChannel,
|
|
||||||
makeSelectOmittedCountForChannel,
|
makeSelectOmittedCountForChannel,
|
||||||
makeSelectClaimIsNsfw,
|
makeSelectClaimIsNsfw,
|
||||||
makeSelectChannelForClaimUri,
|
makeSelectChannelForClaimUri,
|
||||||
|
@ -217,7 +216,6 @@ export {
|
||||||
makeSelectMyChannelPermUrlForName,
|
makeSelectMyChannelPermUrlForName,
|
||||||
makeSelectClaimIsPending,
|
makeSelectClaimIsPending,
|
||||||
makeSelectReflectingClaimForUri,
|
makeSelectReflectingClaimForUri,
|
||||||
makeSelectClaimsInChannelForCurrentPageState,
|
|
||||||
makeSelectShortUrlForUri,
|
makeSelectShortUrlForUri,
|
||||||
makeSelectCanonicalUrlForUri,
|
makeSelectCanonicalUrlForUri,
|
||||||
makeSelectPermanentUrlForUri,
|
makeSelectPermanentUrlForUri,
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -10,6 +10,7 @@ import {
|
||||||
selectClaimsByUri,
|
selectClaimsByUri,
|
||||||
selectMyChannelClaims,
|
selectMyChannelClaims,
|
||||||
selectPendingIds,
|
selectPendingIds,
|
||||||
|
selectPendingClaimsById,
|
||||||
} from 'redux/selectors/claims';
|
} from 'redux/selectors/claims';
|
||||||
|
|
||||||
import { doFetchTxoPage } from 'redux/actions/wallet';
|
import { doFetchTxoPage } from 'redux/actions/wallet';
|
||||||
|
@ -18,15 +19,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';
|
||||||
|
|
||||||
|
let onChannelConfirmCallback;
|
||||||
|
let checkPendingInterval;
|
||||||
|
|
||||||
export function doResolveUris(
|
export function doResolveUris(
|
||||||
uris: Array<string>,
|
uris: Array<string>,
|
||||||
returnCachedClaims: boolean = false,
|
returnCachedClaims: boolean = false,
|
||||||
|
@ -402,7 +404,7 @@ export function doClearChannelErrors() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doCreateChannel(name: string, amount: number, optionalParams: any, cb: any) {
|
export function doCreateChannel(name: string, amount: number, optionalParams: any, onConfirm: any) {
|
||||||
return (dispatch: Dispatch) => {
|
return (dispatch: Dispatch) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACTIONS.CREATE_CHANNEL_STARTED,
|
type: ACTIONS.CREATE_CHANNEL_STARTED,
|
||||||
|
@ -469,7 +471,7 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an
|
||||||
claims: [channelClaim],
|
claims: [channelClaim],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch(doCheckPendingClaims(cb));
|
dispatch(doCheckPendingClaims(onConfirm));
|
||||||
return channelClaim;
|
return channelClaim;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -895,7 +897,6 @@ export function doCollectionPublishUpdate(options: {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch(doCheckPendingClaims());
|
dispatch(doCheckPendingClaims());
|
||||||
dispatch(doFetchCollectionListMine(1, 10));
|
|
||||||
return resolve(collectionClaim);
|
return resolve(collectionClaim);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -975,52 +976,71 @@ export function doPurchaseList(page: number = 1, pageSize: number = PAGE_SIZE) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const doCheckPendingClaims = (onConfirmed: Function) => (
|
export const doCheckPendingClaims = (onChannelConfirmed: Function) => (
|
||||||
dispatch: Dispatch,
|
dispatch: Dispatch,
|
||||||
getState: GetState
|
getState: GetState
|
||||||
) => {
|
) => {
|
||||||
let claimCheckInterval;
|
if (onChannelConfirmed) {
|
||||||
|
onChannelConfirmCallback = onChannelConfirmed;
|
||||||
const checkClaimList = () => {
|
}
|
||||||
|
clearInterval(checkPendingInterval);
|
||||||
|
const checkTxoList = () => {
|
||||||
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) {
|
||||||
.then(result => {
|
Lbry.txo_list({ txid: pendingTxos })
|
||||||
const claims = result.items;
|
.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);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
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;
|
||||||
|
const collectionIds = claims
|
||||||
|
.filter(c => c.value_type === 'collection')
|
||||||
|
.map(c => c.claim_id);
|
||||||
|
dispatch({
|
||||||
|
type: ACTIONS.UPDATE_CONFIRMED_CLAIMS,
|
||||||
|
data: {
|
||||||
|
claims: claims,
|
||||||
|
pending: pendingById,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (collectionIds.length) {
|
||||||
|
dispatch(
|
||||||
|
doFetchItemsInCollections({
|
||||||
|
collectionIds,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const channelClaims = claims.filter(claim => claim.value_type === 'channel');
|
||||||
|
if (channelClaims.length && onChannelConfirmCallback) {
|
||||||
|
channelClaims.forEach(claim => onChannelConfirmCallback(claim));
|
||||||
|
}
|
||||||
|
if (Object.keys(pendingById).length === 0) {
|
||||||
|
clearInterval(checkPendingInterval);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (claimsToConfirm.length) {
|
} else {
|
||||||
dispatch({
|
clearInterval(checkPendingInterval);
|
||||||
type: ACTIONS.UPDATE_CONFIRMED_CLAIMS,
|
}
|
||||||
data: {
|
|
||||||
claims: claimsToConfirm,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return pendingIdSet.size;
|
|
||||||
})
|
|
||||||
.then(len => {
|
|
||||||
if (!len) {
|
|
||||||
clearInterval(claimCheckInterval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
// do something with onConfirmed (typically get blocklist for channel)
|
||||||
claimCheckInterval = setInterval(() => {
|
checkPendingInterval = setInterval(() => {
|
||||||
checkClaimList();
|
checkTxoList();
|
||||||
}, 30000);
|
}, 30000);
|
||||||
};
|
};
|
||||||
|
|
|
@ -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);
|
byId[claimId] = mergeClaim(claim, byId[claimId]);
|
||||||
}
|
} else {
|
||||||
if (pendingIds.includes(claimId)) {
|
byId[claimId] = claim;
|
||||||
byId[claimId] = mergeClaim(claim, byId[claimId]);
|
}
|
||||||
} else {
|
} else {
|
||||||
byId[claimId] = claim;
|
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,
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 to keep metadata?
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const selectClaimIdsByUri = createSelector(
|
export const selectClaimIdsByUri = createSelector(
|
||||||
selectState,
|
selectState,
|
||||||
state => state.claimsByUri || {}
|
state => state.claimsByUri || {}
|
||||||
|
@ -72,35 +85,35 @@ 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]);
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export const makeSelectClaimIdForUri = (uri: string) =>
|
export const makeSelectClaimIdForUri = (uri: string) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
|
@ -325,6 +338,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 +349,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,21 +360,6 @@ export const makeSelectTotalPagesInChannelSearch = (uri: string) =>
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) =>
|
|
||||||
createSelector(
|
|
||||||
selectClaimsById,
|
|
||||||
selectAllClaimsByChannel,
|
|
||||||
selectCurrentChannelPage,
|
|
||||||
(byId, allClaims, page) => {
|
|
||||||
const byChannel = allClaims[uri] || {};
|
|
||||||
const claimIds = byChannel[page || 1];
|
|
||||||
|
|
||||||
if (!claimIds) return claimIds;
|
|
||||||
|
|
||||||
return claimIds.map(claimId => byId[claimId]);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export const makeSelectMetadataForUri = (uri: string) =>
|
export const makeSelectMetadataForUri = (uri: string) =>
|
||||||
createSelector(
|
createSelector(
|
||||||
makeSelectClaimForUri(uri),
|
makeSelectClaimForUri(uri),
|
||||||
|
@ -500,7 +500,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(
|
||||||
|
@ -608,31 +610,18 @@ export const selectChannelClaimCounts = createSelector(
|
||||||
|
|
||||||
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 +652,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 +731,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 || {}
|
||||||
|
|
|
@ -158,7 +158,7 @@ export const makeSelectCollectionForId = (id: string) =>
|
||||||
selectMyEditedCollections,
|
selectMyEditedCollections,
|
||||||
selectPendingCollections,
|
selectPendingCollections,
|
||||||
(bLists, rLists, uLists, eLists, pLists) => {
|
(bLists, rLists, uLists, eLists, pLists) => {
|
||||||
const collection = bLists[id] || uLists[id] || eLists[id] || rLists[id] || pLists[id];
|
const collection = bLists[id] || uLists[id] || eLists[id] || pLists[id] || rLists[id];
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue