From fb8a8041331cae92f2d5d73afe251e7336178930 Mon Sep 17 00:00:00 2001 From: zeppi Date: Thu, 24 Jun 2021 14:26:51 -0400 Subject: [PATCH 1/7] store pendingById --- dist/bundle.es.js | 242 ++++++++++++++++++---------------- dist/flow-typed/Lbry.js | 3 +- flow-typed/Lbry.js | 3 +- src/index.js | 4 +- src/lbry.js | 1 + src/redux/actions/claims.js | 84 ++++++------ src/redux/reducers/claims.js | 97 ++++++++------ src/redux/selectors/claims.js | 138 +++++++++---------- 8 files changed, 298 insertions(+), 274 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index cfade36..717831e 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2370,7 +2370,13 @@ var _extends$3 = Object.assign || function (target) { for (var i = 1; i < argume 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 || {}); @@ -2405,29 +2411,31 @@ const selectClaimsByUri = reselect.createSelector(selectClaimIdsByUri, selectCla 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)]; if (claimId) { - return pendingIds.some(i => i === claimId); + return Boolean(pendingById[claimId]); } return false; }); -const makeSelectClaimIdIsPending = claimId => reselect.createSelector(selectPendingIds, pendingIds => { - return pendingIds.some(i => i === claimId); +const makeSelectClaimIdIsPending = claimId => reselect.createSelector(selectPendingClaimsById, pendingById => { + return Boolean(pendingById[claimId]); }); const makeSelectClaimIdForUri = uri => reselect.createSelector(selectClaimIdsByUri, claimIds => claimIds[uri]); const selectReflectingById = reselect.createSelector(selectState$1, state => state.reflectingById); +// use pendingFirst const makeSelectClaimForClaimId = claimId => reselect.createSelector(selectClaimsById, byId => byId[claimId]); +// use pendingFirst const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => { let validUri; 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 ids = state.myClaims; if (!ids) { @@ -2543,6 +2552,7 @@ const selectAllFetchingChannelClaims = reselect.createSelector(selectState$1, st const makeSelectFetchingChannelClaims = uri => reselect.createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]); +// use pendingFirst const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { const byChannel = allClaims[uri] || {}; const claimIds = byChannel[page || 1]; @@ -2552,24 +2562,32 @@ const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector( 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 byChannel = allClaims[uri] || {}; return byChannel['itemCount']; }); +// THIS IS LEFT OVER FROM ONE_TAB CHANNEL CONTENT const makeSelectTotalPagesInChannelSearch = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { const byChannel = allClaims[uri] || {}; 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]); -}); +// 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]); +// } +// ); const makeSelectMetadataForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { 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); +// use pendingFirst const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, (myClaimIds, byId, abandoningIds) => { const claims = []; @@ -2666,6 +2685,7 @@ const selectFetchingMyChannels = reselect.createSelector(selectState$1, state => const selectFetchingMyCollections = reselect.createSelector(selectState$1, state => state.fetchingMyCollections); +// use pendingFirst const selectMyChannelClaims = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { const ids = state.myChannelClaims; 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 makeSelectPendingClaimForUri = uri => reselect.createSelector(selectPendingIds, selectClaimsById, (pending, claims) => { - let uriIsChannel; +// JUST PENDING - change this +const makeSelectPendingClaimForUri = uri => reselect.createSelector(selectPendingClaimsById, pendingById => { let uriStreamName; let uriChannelName; try { ({ - isChannel: uriIsChannel, streamName: uriStreamName, channelName: uriChannelName } = parseURI(uri)); } catch (e) { return null; } - const pendingClaims = pending.map(id => claims[id]); + const pendingClaims = Object.values(pendingById); const matchingClaim = pendingClaims.find(claim => { - const { streamName, channelName, isChannel } = parseURI(claim.permanent_url); - if (isChannel) { - return channelName === uriChannelName; - } else { - return streamName === uriStreamName; - } + return claim.normalized_name === uriChannelName || claim.normalized_name === uriStreamName; }); return matchingClaim || null; }); @@ -2734,21 +2748,6 @@ const makeSelectNsfwCountFromUris = uris => reselect.createSelector(selectClaims return acc; }, 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) => { if (claimsInChannel && typeof claimsInSearch === 'number' && claimsInSearch >= 0) { 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"); }); }; } +let checkPendingCallbacks = []; +let checkPendingInterval; + function doResolveUris(uris, returnCachedClaims = false, resolveReposts = true) { return (dispatch, getState) => { const normalizedUris = uris.map(normalizeURI); @@ -4571,47 +4573,49 @@ function doPurchaseList(page = 1, pageSize = PAGE_SIZE) { } const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { - let claimCheckInterval; - - const checkClaimList = () => { + clearInterval(checkPendingInterval); + const checkTxoList = checkPendingCallbacks => { 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); - lbryProxy.claim_list({ page: 1, page_size: 10 }).then(result => { - const claims = result.items; - const claimsToConfirm = []; - claims.forEach(claim => { - const { claim_id: claimId } = claim; - if (claim.confirmations > 0 && pendingIdSet.has(claimId)) { - pendingIdSet.delete(claimId); - 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) { - dispatch({ - type: UPDATE_CONFIRMED_CLAIMS, - data: { - claims: claimsToConfirm + if (pendingTxos.length) { + lbryProxy.txo_list({ txid: pendingTxos }).then(result => { + const txos = result.items; + const idsToConfirm = []; + txos.forEach(txo => { + if (txo.claim_id && txo.confirmations > 0) { + idsToConfirm.push(txo.claim_id); + delete pendingById[txo.claim_id]; } }); - } - return pendingIdSet.size; - }).then(len => { - if (!len) { - clearInterval(claimCheckInterval); - } - }); + 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({ + type: UPDATE_CONFIRMED_CLAIMS, + data: { + claims: claims, + pending: pendingById + } + }); + checkPendingCallbacks.forEach(cb => cb()); + clearInterval(checkPendingInterval); + }); + } + }); + } else { + clearInterval(checkPendingInterval); + } }; - - claimCheckInterval = setInterval(() => { - checkClaimList(); + // do something with onConfirmed (typically get blocklist for channel) + checkPendingInterval = setInterval(() => { + checkTxoList(checkPendingCallbacks); }, 30000); }; @@ -6001,7 +6005,7 @@ const defaultState = { fetchingMyChannels: false, fetchingMyCollections: false, abandoningById: {}, - pendingIds: [], + pendingById: {}, reflectingById: {}, claimSearchError: false, claimSearchByQuery: {}, @@ -6035,7 +6039,7 @@ function handleClaimAction(state, action) { const byUri = Object.assign({}, state.claimsByUri); const byId = Object.assign({}, state.byId); const channelClaimCounts = Object.assign({}, state.channelClaimCounts); - const pendingIds = state.pendingIds; + const pendingById = state.pendingById; let newResolvingUrls = new Set(state.resolvingUris); let myClaimIds = new Set(state.myClaims); @@ -6045,7 +6049,7 @@ function handleClaimAction(state, action) { const channel = channelFromResolve || stream && stream.signing_channel; if (stream) { - if (pendingIds.includes(stream.claim_id)) { + if (pendingById[stream.claim_id]) { byId[stream.claim_id] = mergeClaims(stream, byId[stream.claim_id]); } else { byId[stream.claim_id] = stream; @@ -6075,7 +6079,7 @@ function handleClaimAction(state, action) { 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]); } else { byId[channel.claim_id] = channel; @@ -6088,7 +6092,7 @@ function handleClaimAction(state, action) { } if (collection) { - if (pendingIds.includes(collection.claim_id)) { + if (pendingById[collection.claim_id]) { byId[collection.claim_id] = mergeClaims(collection, byId[collection.claim_id]); } else { byId[collection.claim_id] = collection; @@ -6105,7 +6109,7 @@ function handleClaimAction(state, action) { } newResolvingUrls.delete(url); - if (!stream && !channel && !collection && !pendingIds.includes(byUri[url])) { + if (!stream && !channel && !collection && !pendingById[byUri[url]]) { 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) => { - const { result, resolve } = action.data; + const { result } = action.data; const claims = result.items; const page = result.page; const totalItems = result.total_items; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingIds = state.pendingIds || []; + const pendingById = Object.assign({}, state.pendingById); let myClaimIds = new Set(state.myClaims); let urlsForCurrentPage = []; - const pendingIdSet = new Set(pendingIds); - 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/)) { urlsForCurrentPage.push(permanentUri); if (claim.confirmations < 1) { - pendingIdSet.add(claimId); - } else if (!resolve && pendingIdSet.has(claimId) && claim.confirmations > 0) { - pendingIdSet.delete(claimId); - } - if (pendingIds.includes(claimId)) { - byId[claimId] = mergeClaims(claim, byId[claimId]); + pendingById[claimId] = claim; + if (byId[claimId]) { + byId[claimId] = mergeClaims(claim, byId[claimId]); + } else { + byId[claimId] = claim; + } } else { byId[claimId] = claim; } byUri[permanentUri] = claimId; + byUri[canonicalUri] = claimId; myClaimIds.add(claimId); } }); @@ -6181,7 +6184,7 @@ reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => { isFetchingClaimListMine: false, myClaims: Array.from(myClaimIds), byId, - pendingIds: Array.from(pendingIdSet), + pendingById, claimsByUri: byUri, myClaimsPageResults: urlsForCurrentPage, myClaimsPageNumber: page, @@ -6193,9 +6196,8 @@ reducers[FETCH_CHANNEL_LIST_STARTED] = state => Object.assign({}, state, { fetch reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { const { claims } = action.data; - const myClaims = state.myClaims || []; let myClaimIds = new Set(state.myClaims); - const pendingIds = state.pendingIds || []; + const pendingById = Object.assign({}, state.pendingById); let myChannelClaims; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); @@ -6208,7 +6210,7 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { myChannelClaims = new Set(state.myChannelClaims); claims.forEach(claim => { 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[permanentUrl] = claimId; @@ -6217,7 +6219,14 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { // $FlowFixMe 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; } myClaimIds.add(claimId); @@ -6226,6 +6235,7 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { return Object.assign({}, state, { byId, + pendingById, claimsByUri: byUri, channelClaimCounts, fetchingMyChannels: false, @@ -6248,7 +6258,7 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => { const { claims } = action.data; const myClaims = state.myClaims || []; let myClaimIds = new Set(myClaims); - const pendingIds = state.pendingIds || []; + const pendingById = Object.assign({}, state.pendingById); let myCollectionClaimsSet = new Set([]); const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); @@ -6256,7 +6266,7 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => { if (claims.length) { myCollectionClaimsSet = new Set(state.myCollectionClaims); 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[permanentUrl] = claimId; @@ -6264,7 +6274,14 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => { // $FlowFixMe myCollectionClaimsSet.add(claimId); // 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; } myClaimIds.add(claimId); @@ -6273,6 +6290,7 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => { return _extends$9({}, state, { byId, + pendingById, claimsByUri: byUri, fetchingMyCollections: false, myCollectionClaims: Array.from(myCollectionClaimsSet), @@ -6358,9 +6376,8 @@ reducers[ABANDON_CLAIM_STARTED] = (state, action) => { reducers[UPDATE_PENDING_CLAIMS] = (state, action) => { const { claims: pendingClaims } = action.data; const byId = Object.assign({}, state.byId); + const pendingById = Object.assign({}, state.pendingById); const byUri = Object.assign({}, state.claimsByUri); - const pendingIds = state.pendingIds; - const pendingIdSet = new Set(pendingIds); let myClaimIds = new Set(state.myClaims); const myChannelClaims = new Set(state.myChannelClaims); @@ -6368,7 +6385,7 @@ reducers[UPDATE_PENDING_CLAIMS] = (state, action) => { pendingClaims.forEach(claim => { let newClaim; 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]; if (oldClaim && oldClaim.canonical_url) { newClaim = mergeClaims(oldClaim, claim); @@ -6388,21 +6405,19 @@ reducers[UPDATE_PENDING_CLAIMS] = (state, action) => { return Object.assign({}, state, { myClaims: Array.from(myClaimIds), byId, + pendingById, myChannelClaims: Array.from(myChannelClaims), - claimsByUri: byUri, - pendingIds: Array.from(pendingIdSet) + claimsByUri: byUri }); }; 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 byUri = Object.assign({}, state.claimsByUri); - const pendingIds = state.pendingIds; - const pendingIdSet = new Set(pendingIds); - + // confirmedClaims.forEach(claim => { - const { permanent_url: permanentUri, claim_id: claimId, type } = claim; + const { claim_id: claimId, type } = claim; let newClaim = claim; const oldClaim = byId[claimId]; if (oldClaim && oldClaim.canonical_url) { @@ -6410,11 +6425,10 @@ reducers[UPDATE_CONFIRMED_CLAIMS] = (state, action) => { } if (type && type.match(/claim|update|channel/)) { byId[claimId] = newClaim; - pendingIdSet.delete(claimId); } }); return Object.assign({}, state, { - pendingIds: Array.from(pendingIdSet), + pendingById: pendingClaims, byId, claimsByUri: byUri }); @@ -7938,7 +7952,6 @@ exports.makeSelectClaimIsNsfw = makeSelectClaimIsNsfw; exports.makeSelectClaimIsPending = makeSelectClaimIsPending; exports.makeSelectClaimIsStreamPlaceholder = makeSelectClaimIsStreamPlaceholder; exports.makeSelectClaimWasPurchased = makeSelectClaimWasPurchased; -exports.makeSelectClaimsInChannelForCurrentPageState = makeSelectClaimsInChannelForCurrentPageState; exports.makeSelectClaimsInChannelForPage = makeSelectClaimsInChannelForPage; exports.makeSelectCollectionForId = makeSelectCollectionForId; exports.makeSelectCollectionForIdHasClaimUrl = makeSelectCollectionForIdHasClaimUrl; @@ -7972,7 +7985,6 @@ exports.makeSelectMyPurchasesForPage = makeSelectMyPurchasesForPage; exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage; exports.makeSelectNameForCollectionId = makeSelectNameForCollectionId; exports.makeSelectNextUrlForCollectionAndUrl = makeSelectNextUrlForCollectionAndUrl; -exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel; exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris; exports.makeSelectOmittedCountForChannel = makeSelectOmittedCountForChannel; exports.makeSelectPendingAmountByUri = makeSelectPendingAmountByUri; diff --git a/dist/flow-typed/Lbry.js b/dist/flow-typed/Lbry.js index 7284455..2fd2ac6 100644 --- a/dist/flow-typed/Lbry.js +++ b/dist/flow-typed/Lbry.js @@ -75,7 +75,7 @@ declare type BalanceResponse = { declare type ResolveResponse = { // 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 }; @@ -351,6 +351,7 @@ declare type LbryTypes = { address_unused: (params: {}) => Promise, // New address address_list: (params: {}) => Promise, transaction_list: (params: {}) => Promise, + txo_list: (params: {}) => Promise, // Sync sync_hash: (params: {}) => Promise, diff --git a/flow-typed/Lbry.js b/flow-typed/Lbry.js index 7284455..2fd2ac6 100644 --- a/flow-typed/Lbry.js +++ b/flow-typed/Lbry.js @@ -75,7 +75,7 @@ declare type BalanceResponse = { declare type ResolveResponse = { // 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 }; @@ -351,6 +351,7 @@ declare type LbryTypes = { address_unused: (params: {}) => Promise, // New address address_list: (params: {}) => Promise, transaction_list: (params: {}) => Promise, + txo_list: (params: {}) => Promise, // Sync sync_hash: (params: {}) => Promise, diff --git a/src/index.js b/src/index.js index aba6c58..220ff62 100644 --- a/src/index.js +++ b/src/index.js @@ -209,7 +209,7 @@ export { makeSelectTotalItemsForChannel, makeSelectTotalPagesForChannel, makeSelectNsfwCountFromUris, - makeSelectNsfwCountForChannel, + // makeSelectNsfwCountForChannel, makeSelectOmittedCountForChannel, makeSelectClaimIsNsfw, makeSelectChannelForClaimUri, @@ -217,7 +217,7 @@ export { makeSelectMyChannelPermUrlForName, makeSelectClaimIsPending, makeSelectReflectingClaimForUri, - makeSelectClaimsInChannelForCurrentPageState, + // makeSelectClaimsInChannelForCurrentPageState, makeSelectShortUrlForUri, makeSelectCanonicalUrlForUri, makeSelectPermanentUrlForUri, diff --git a/src/lbry.js b/src/lbry.js index 9a73384..a7828d9 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -117,6 +117,7 @@ const Lbry: LbryTypes = { utxo_release: (params = {}) => daemonCallWithResult('utxo_release', params), support_abandon: (params = {}) => daemonCallWithResult('support_abandon', params), purchase_list: (params = {}) => daemonCallWithResult('purchase_list', params), + txo_list: (params = {}) => daemonCallWithResult('txo_list', params), sync_hash: (params = {}) => daemonCallWithResult('sync_hash', params), sync_apply: (params = {}) => daemonCallWithResult('sync_apply', params), diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index cee7c13..078f41b 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -18,14 +18,16 @@ import { creditsToString } from 'util/format-credits'; import { batchActions } from 'util/batch-actions'; import { createNormalizedClaimSearchKey } from 'util/claim'; import { PAGE_SIZE } from 'constants/claim'; -import { - selectPendingCollections, -} from 'redux/selectors/collections'; +import { selectPendingCollections } from 'redux/selectors/collections'; import { doFetchItemsInCollection, doFetchItemsInCollections, doCollectionDelete, } from 'redux/actions/collections'; +import { selectPendingClaimsById } from '../selectors/claims'; + +let checkPendingCallbacks = []; +let checkPendingInterval; export function doResolveUris( uris: Array, @@ -979,48 +981,50 @@ export const doCheckPendingClaims = (onConfirmed: Function) => ( dispatch: Dispatch, getState: GetState ) => { - let claimCheckInterval; - - const checkClaimList = () => { + clearInterval(checkPendingInterval); + const checkTxoList = checkPendingCallbacks => { 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); - Lbry.claim_list({ page: 1, page_size: 10 }) - .then(result => { - const claims = result.items; - const claimsToConfirm = []; - claims.forEach(claim => { - const { claim_id: claimId } = claim; - if (claim.confirmations > 0 && pendingIdSet.has(claimId)) { - pendingIdSet.delete(claimId); - 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 (pendingTxos.length) { + Lbry.txo_list({ txid: pendingTxos }) + .then(result => { + const txos = result.items; + const idsToConfirm = []; + txos.forEach(txo => { + if (txo.claim_id && txo.confirmations > 0) { + idsToConfirm.push(txo.claim_id); + delete pendingById[txo.claim_id]; } + }); + 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({ + type: ACTIONS.UPDATE_CONFIRMED_CLAIMS, + data: { + claims: claims, + pending: pendingById, + }, + }); + checkPendingCallbacks.forEach(cb => cb()); + clearInterval(checkPendingInterval); + }); } }); - if (claimsToConfirm.length) { - dispatch({ - type: ACTIONS.UPDATE_CONFIRMED_CLAIMS, - data: { - claims: claimsToConfirm, - }, - }); - } - return pendingIdSet.size; - }) - .then(len => { - if (!len) { - clearInterval(claimCheckInterval); - } - }); + } else { + clearInterval(checkPendingInterval); + } }; - - claimCheckInterval = setInterval(() => { - checkClaimList(); + // do something with onConfirmed (typically get blocklist for channel) + checkPendingInterval = setInterval(() => { + checkTxoList(checkPendingCallbacks); }, 30000); }; diff --git a/src/redux/reducers/claims.js b/src/redux/reducers/claims.js index e167aac..410e032 100644 --- a/src/redux/reducers/claims.js +++ b/src/redux/reducers/claims.js @@ -17,8 +17,8 @@ type State = { channelClaimCounts: { [string]: number }, claimsByUri: { [string]: string }, byId: { [string]: Claim }, + pendingById: { [string]: Claim }, // keep pending claims resolvingUris: Array, - pendingIds: Array, reflectingById: { [string]: ReflectingUpdate }, myClaims: ?Array, myChannelClaims: ?Array, @@ -83,7 +83,7 @@ const defaultState = { fetchingMyChannels: false, fetchingMyCollections: false, abandoningById: {}, - pendingIds: [], + pendingById: {}, reflectingById: {}, claimSearchError: false, claimSearchByQuery: {}, @@ -117,7 +117,7 @@ function handleClaimAction(state: State, action: any): State { const byUri = Object.assign({}, state.claimsByUri); const byId = Object.assign({}, state.byId); const channelClaimCounts = Object.assign({}, state.channelClaimCounts); - const pendingIds = state.pendingIds; + const pendingById = state.pendingById; let newResolvingUrls = new Set(state.resolvingUris); let myClaimIds = new Set(state.myClaims); @@ -127,7 +127,7 @@ function handleClaimAction(state: State, action: any): State { const channel = channelFromResolve || (stream && stream.signing_channel); if (stream) { - if (pendingIds.includes(stream.claim_id)) { + if (pendingById[stream.claim_id]) { byId[stream.claim_id] = mergeClaim(stream, byId[stream.claim_id]); } else { byId[stream.claim_id] = stream; @@ -157,7 +157,7 @@ function handleClaimAction(state: State, action: any): State { 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]); } else { byId[channel.claim_id] = channel; @@ -170,7 +170,7 @@ function handleClaimAction(state: State, action: any): State { } if (collection) { - if (pendingIds.includes(collection.claim_id)) { + if (pendingById[collection.claim_id]) { byId[collection.claim_id] = mergeClaim(collection, byId[collection.claim_id]); } else { byId[collection.claim_id] = collection; @@ -187,7 +187,7 @@ function handleClaimAction(state: State, action: any): State { } newResolvingUrls.delete(url); - if (!stream && !channel && !collection && !pendingIds.includes(byUri[url])) { + if (!stream && !channel && !collection && !pendingById[byUri[url]]) { 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 => { - const { result, resolve }: { result: ClaimListResponse, resolve: boolean } = action.data; + const { result }: { result: ClaimListResponse } = action.data; const claims = result.items; const page = result.page; const totalItems = result.total_items; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingIds = state.pendingIds || []; + const pendingById = Object.assign({}, state.pendingById); let myClaimIds = new Set(state.myClaims); let urlsForCurrentPage = []; - const pendingIdSet = new Set(pendingIds); - 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/)) { urlsForCurrentPage.push(permanentUri); if (claim.confirmations < 1) { - pendingIdSet.add(claimId); - } else if (!resolve && pendingIdSet.has(claimId) && claim.confirmations > 0) { - pendingIdSet.delete(claimId); - } - if (pendingIds.includes(claimId)) { - byId[claimId] = mergeClaim(claim, byId[claimId]); + pendingById[claimId] = claim; + if (byId[claimId]) { + byId[claimId] = mergeClaim(claim, byId[claimId]); + } else { + byId[claimId] = claim; + } } else { byId[claimId] = claim; } byUri[permanentUri] = claimId; + byUri[canonicalUri] = claimId; myClaimIds.add(claimId); } }); @@ -266,7 +265,7 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any): isFetchingClaimListMine: false, myClaims: Array.from(myClaimIds), byId, - pendingIds: Array.from(pendingIdSet), + pendingById, claimsByUri: byUri, myClaimsPageResults: urlsForCurrentPage, 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 => { const { claims }: { claims: Array } = action.data; - const myClaims = state.myClaims || []; let myClaimIds = new Set(state.myClaims); - const pendingIds = state.pendingIds || []; + const pendingById = Object.assign({}, state.pendingById); let myChannelClaims; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); @@ -295,7 +293,12 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St claims.forEach(claim => { const { meta } = claim; 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[permanentUrl] = claimId; @@ -304,7 +307,14 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St // $FlowFixMe 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; } myClaimIds.add(claimId); @@ -313,6 +323,7 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St return Object.assign({}, state, { byId, + pendingById, claimsByUri: byUri, channelClaimCounts, fetchingMyChannels: false, @@ -336,7 +347,7 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any): const { claims }: { claims: Array } = action.data; const myClaims = state.myClaims || []; let myClaimIds = new Set(myClaims); - const pendingIds = state.pendingIds || []; + const pendingById = Object.assign({}, state.pendingById); let myCollectionClaimsSet = new Set([]); const byId = Object.assign({}, state.byId); 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); claims.forEach(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[permanentUrl] = claimId; @@ -353,7 +369,14 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any): // $FlowFixMe myCollectionClaimsSet.add(claimId); // 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; } myClaimIds.add(claimId); @@ -363,6 +386,7 @@ reducers[ACTIONS.FETCH_COLLECTION_LIST_COMPLETED] = (state: State, action: any): return { ...state, byId, + pendingById, claimsByUri: byUri, fetchingMyCollections: false, 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 => { const { claims: pendingClaims }: { claims: Array } = action.data; const byId = Object.assign({}, state.byId); + const pendingById = Object.assign({}, state.pendingById); const byUri = Object.assign({}, state.claimsByUri); - const pendingIds = state.pendingIds; - const pendingIdSet = new Set(pendingIds); let myClaimIds = new Set(state.myClaims); const myChannelClaims = new Set(state.myChannelClaims); @@ -465,7 +488,7 @@ reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => pendingClaims.forEach((claim: Claim) => { let newClaim; 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]; if (oldClaim && oldClaim.canonical_url) { newClaim = mergeClaim(oldClaim, claim); @@ -485,21 +508,22 @@ reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => return Object.assign({}, state, { myClaims: Array.from(myClaimIds), byId, + pendingById, myChannelClaims: Array.from(myChannelClaims), claimsByUri: byUri, - pendingIds: Array.from(pendingIdSet), }); }; reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => { - const { claims: confirmedClaims }: { claims: Array } = action.data; + const { + claims: confirmedClaims, + pending: pendingClaims, + }: { claims: Array, pending: { [string]: Claim } } = action.data; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingIds = state.pendingIds; - const pendingIdSet = new Set(pendingIds); - + // confirmedClaims.forEach((claim: GenericClaim) => { - const { permanent_url: permanentUri, claim_id: claimId, type } = claim; + const { claim_id: claimId, type } = claim; let newClaim = claim; const oldClaim = byId[claimId]; 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/)) { byId[claimId] = newClaim; - pendingIdSet.delete(claimId); } }); return Object.assign({}, state, { - pendingIds: Array.from(pendingIdSet), + pendingById: pendingClaims, byId, claimsByUri: byUri, }); diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 683077d..583d4b1 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -1,5 +1,5 @@ // @flow -import { normalizeURI, buildURI, parseURI } from 'lbryURI'; +import { normalizeURI, parseURI } from 'lbryURI'; import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { createSelector } from 'reselect'; import { isClaimNsfw, filterClaims } from 'util/claim'; @@ -7,11 +7,24 @@ import * as CLAIM from 'constants/claim'; const selectState = state => state.claims || {}; -export const selectClaimsById = createSelector( +export const selectById = createSelector( selectState, 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( selectState, state => state.claimsByUri || {} @@ -72,35 +85,35 @@ export const selectAllClaimsByChannel = createSelector( export const selectPendingIds = createSelector( selectState, - state => state.pendingIds || [] + state => Object.keys(state.pendingIds) || [] ); export const selectPendingClaims = createSelector( - selectPendingIds, - selectClaimsById, - (pendingIds, byId) => pendingIds.map(id => byId[id]) + selectPendingClaimsById, + pendingById => Object.values(pendingById) ); export const makeSelectClaimIsPending = (uri: string) => createSelector( selectClaimIdsByUri, - selectPendingIds, - (idsByUri, pendingIds) => { + selectPendingClaimsById, + (idsByUri, pendingById) => { const claimId = idsByUri[normalizeURI(uri)]; if (claimId) { - return pendingIds.some(i => i === claimId); + return Boolean(pendingById[claimId]); } return false; } ); -export const makeSelectClaimIdIsPending = (claimId: string) => createSelector( - selectPendingIds, - (pendingIds) => { - return pendingIds.some(i => i === claimId); - } -); +export const makeSelectClaimIdIsPending = (claimId: string) => + createSelector( + selectPendingClaimsById, + pendingById => { + return Boolean(pendingById[claimId]); + } + ); export const makeSelectClaimIdForUri = (uri: string) => createSelector( @@ -113,12 +126,14 @@ export const selectReflectingById = createSelector( state => state.reflectingById ); +// use pendingFirst export const makeSelectClaimForClaimId = (claimId: string) => createSelector( selectClaimsById, byId => byId[claimId] ); +// use pendingFirst export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) => createSelector( selectClaimIdsByUri, @@ -163,6 +178,7 @@ export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) } ); +// use pendingFirst export const selectMyClaimsRaw = createSelector( selectState, selectClaimsById, @@ -311,6 +327,7 @@ export const makeSelectFetchingChannelClaims = (uri: string) => fetching => fetching && fetching[uri] ); +// use pendingFirst export const makeSelectClaimsInChannelForPage = (uri: string, page?: number) => createSelector( 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) => createSelector( selectClaimsById, @@ -335,6 +353,7 @@ export const makeSelectTotalClaimsInChannelSearch = (uri: string) => } ); +// THIS IS LEFT OVER FROM ONE_TAB CHANNEL CONTENT export const makeSelectTotalPagesInChannelSearch = (uri: string) => createSelector( selectClaimsById, @@ -345,20 +364,20 @@ 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 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) => createSelector( @@ -480,6 +499,7 @@ export const selectFetchingMyClaimsPageError = createSelector( state => state.fetchingClaimListMinePageError ); +// use pendingFirst export const selectMyClaims = createSelector( selectMyActiveClaims, selectClaimsById, @@ -500,7 +520,9 @@ export const selectMyClaims = createSelector( export const selectMyClaimsWithoutChannels = createSelector( selectMyClaims, 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( @@ -549,6 +571,7 @@ export const selectFetchingMyCollections = createSelector( state => state.fetchingMyCollections ); +// use pendingFirst export const selectMyChannelClaims = createSelector( selectState, selectClaimsById, @@ -606,33 +629,21 @@ export const selectChannelClaimCounts = createSelector( state => state.channelClaimCounts || {} ); +// JUST PENDING - change this export const makeSelectPendingClaimForUri = (uri: string) => createSelector( - selectPendingIds, - selectClaimsById, - (pending, claims) => { - let validUri; - let uriIsChannel; + selectPendingClaimsById, + pendingById => { let uriStreamName; let uriChannelName; try { - ({ - isChannel: uriIsChannel, - streamName: uriStreamName, - channelName: uriChannelName, - } = parseURI(uri)); - validUri = true; + ({ streamName: uriStreamName, channelName: uriChannelName } = parseURI(uri)); } catch (e) { return null; } - const pendingClaims = pending.map(id => claims[id]); - const matchingClaim = pendingClaims.find(claim => { - const { streamName, channelName, isChannel } = parseURI(claim.permanent_url); - if (isChannel) { - return channelName === uriChannelName; - } else { - return streamName === uriStreamName; - } + const pendingClaims = (Object.values(pendingById): any); + const matchingClaim = pendingClaims.find((claim: GenericClaim) => { + return claim.normalized_name === uriChannelName || claim.normalized_name === uriStreamName; }); return matchingClaim || null; } @@ -663,27 +674,6 @@ export const makeSelectNsfwCountFromUris = (uris: Array) => }, 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) => createSelector( 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( selectState, state => state.fetchingClaimSearchByQuery || {} -- 2.45.2 From aa832ac02465e27285cf660a0171b7ee0c714697 Mon Sep 17 00:00:00 2001 From: zeppi Date: Thu, 24 Jun 2021 14:51:33 -0400 Subject: [PATCH 2/7] cleanup --- src/index.js | 2 -- src/redux/selectors/claims.js | 24 +----------------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/src/index.js b/src/index.js index 220ff62..5d04fc4 100644 --- a/src/index.js +++ b/src/index.js @@ -209,7 +209,6 @@ export { makeSelectTotalItemsForChannel, makeSelectTotalPagesForChannel, makeSelectNsfwCountFromUris, - // makeSelectNsfwCountForChannel, makeSelectOmittedCountForChannel, makeSelectClaimIsNsfw, makeSelectChannelForClaimUri, @@ -217,7 +216,6 @@ export { makeSelectMyChannelPermUrlForName, makeSelectClaimIsPending, makeSelectReflectingClaimForUri, - // makeSelectClaimsInChannelForCurrentPageState, makeSelectShortUrlForUri, makeSelectCanonicalUrlForUri, makeSelectPermanentUrlForUri, diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 583d4b1..0fab1c1 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -21,7 +21,7 @@ export const selectClaimsById = createSelector( selectById, selectPendingClaimsById, (byId, pendingById) => { - return Object.assign(byId, pendingById); // do I need merged? + return Object.assign(byId, pendingById); // do I need merged to keep metadata? } ); @@ -126,14 +126,12 @@ export const selectReflectingById = createSelector( state => state.reflectingById ); -// use pendingFirst export const makeSelectClaimForClaimId = (claimId: string) => createSelector( selectClaimsById, byId => byId[claimId] ); -// use pendingFirst export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) => createSelector( selectClaimIdsByUri, @@ -178,7 +176,6 @@ export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) } ); -// use pendingFirst export const selectMyClaimsRaw = createSelector( selectState, selectClaimsById, @@ -327,7 +324,6 @@ export const makeSelectFetchingChannelClaims = (uri: string) => fetching => fetching && fetching[uri] ); -// use pendingFirst export const makeSelectClaimsInChannelForPage = (uri: string, page?: number) => createSelector( selectClaimsById, @@ -364,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) => createSelector( makeSelectClaimForUri(uri), @@ -499,7 +480,6 @@ export const selectFetchingMyClaimsPageError = createSelector( state => state.fetchingClaimListMinePageError ); -// use pendingFirst export const selectMyClaims = createSelector( selectMyActiveClaims, selectClaimsById, @@ -571,7 +551,6 @@ export const selectFetchingMyCollections = createSelector( state => state.fetchingMyCollections ); -// use pendingFirst export const selectMyChannelClaims = createSelector( selectState, selectClaimsById, @@ -629,7 +608,6 @@ export const selectChannelClaimCounts = createSelector( state => state.channelClaimCounts || {} ); -// JUST PENDING - change this export const makeSelectPendingClaimForUri = (uri: string) => createSelector( selectPendingClaimsById, -- 2.45.2 From 1948f633781256049674cb34e31ca2bc0b50b661 Mon Sep 17 00:00:00 2001 From: zeppi Date: Thu, 24 Jun 2021 17:53:09 -0400 Subject: [PATCH 3/7] collection check pending --- dist/bundle.es.js | 57 ++++++++++++++++--------------------- src/redux/actions/claims.js | 16 ++++++++--- 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 717831e..0e5d6a1 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1190,6 +1190,7 @@ const Lbry = { utxo_release: (params = {}) => daemonCallWithResult('utxo_release', params), support_abandon: (params = {}) => daemonCallWithResult('support_abandon', params), purchase_list: (params = {}) => daemonCallWithResult('purchase_list', params), + txo_list: (params = {}) => daemonCallWithResult('txo_list', params), sync_hash: (params = {}) => daemonCallWithResult('sync_hash', params), sync_apply: (params = {}) => daemonCallWithResult('sync_apply', params), @@ -2375,7 +2376,7 @@ 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? + return Object.assign(byId, pendingById); // do I need merged to keep metadata? }); const selectClaimIdsByUri = reselect.createSelector(selectState$1, state => state.claimsByUri || {}); @@ -2432,10 +2433,8 @@ const makeSelectClaimIdForUri = uri => reselect.createSelector(selectClaimIdsByU const selectReflectingById = reselect.createSelector(selectState$1, state => state.reflectingById); -// use pendingFirst const makeSelectClaimForClaimId = claimId => reselect.createSelector(selectClaimsById, byId => byId[claimId]); -// use pendingFirst const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => { let validUri; let channelClaimId; @@ -2472,7 +2471,6 @@ const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelec } }); -// use pendingFirst const selectMyClaimsRaw = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { const ids = state.myClaims; if (!ids) { @@ -2552,7 +2550,6 @@ const selectAllFetchingChannelClaims = reselect.createSelector(selectState$1, st const makeSelectFetchingChannelClaims = uri => reselect.createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]); -// use pendingFirst const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { const byChannel = allClaims[uri] || {}; const claimIds = byChannel[page || 1]; @@ -2574,21 +2571,6 @@ const makeSelectTotalPagesInChannelSearch = uri => reselect.createSelector(selec return byChannel['pageCount']; }); -// 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]); -// } -// ); - const makeSelectMetadataForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { const metadata = claim && claim.value; return metadata || (claim === undefined ? undefined : null); @@ -2642,7 +2624,6 @@ const selectMyClaimsPageItemCount = reselect.createSelector(selectState$1, state const selectFetchingMyClaimsPageError = reselect.createSelector(selectState$1, state => state.fetchingClaimListMinePageError); -// use pendingFirst const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, (myClaimIds, byId, abandoningIds) => { const claims = []; @@ -2685,7 +2666,6 @@ const selectFetchingMyChannels = reselect.createSelector(selectState$1, state => const selectFetchingMyCollections = reselect.createSelector(selectState$1, state => state.fetchingMyCollections); -// use pendingFirst const selectMyChannelClaims = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { const ids = state.myChannelClaims; if (!ids) { @@ -2717,15 +2697,11 @@ const selectPlayingUri = reselect.createSelector(selectState$1, state => state.p const selectChannelClaimCounts = reselect.createSelector(selectState$1, state => state.channelClaimCounts || {}); -// JUST PENDING - change this const makeSelectPendingClaimForUri = uri => reselect.createSelector(selectPendingClaimsById, pendingById => { let uriStreamName; let uriChannelName; try { - ({ - streamName: uriStreamName, - channelName: uriChannelName - } = parseURI(uri)); + ({ streamName: uriStreamName, channelName: uriChannelName } = parseURI(uri)); } catch (e) { return null; } @@ -4492,7 +4468,6 @@ function doCollectionPublishUpdate(options) { } }); dispatch(doCheckPendingClaims()); - dispatch(doFetchCollectionListMine(1, 10)); return resolve(collectionClaim); } @@ -4596,7 +4571,7 @@ const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { 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? + const collectionIds = claims.filter(c => c.value_type === 'collection').map(c => c.claim_id); dispatch({ type: UPDATE_CONFIRMED_CLAIMS, data: { @@ -4604,6 +4579,11 @@ const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { pending: pendingById } }); + if (collectionIds.length) { + dispatch(doFetchItemsInCollections({ + collectionIds + })); + } checkPendingCallbacks.forEach(cb => cb()); clearInterval(checkPendingInterval); }); @@ -6210,7 +6190,12 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { myChannelClaims = new Set(state.myChannelClaims); claims.forEach(claim => { const { claims_in_channel: claimsInChannel } = claim.meta; - const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId, confirmations } = claim; + const { + canonical_url: canonicalUrl, + permanent_url: permanentUrl, + claim_id: claimId, + confirmations + } = claim; byUri[canonicalUrl] = claimId; byUri[permanentUrl] = claimId; @@ -6266,7 +6251,12 @@ reducers[FETCH_COLLECTION_LIST_COMPLETED] = (state, action) => { if (claims.length) { myCollectionClaimsSet = new Set(state.myCollectionClaims); claims.forEach(claim => { - const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId, confirmations } = claim; + const { + canonical_url: canonicalUrl, + permanent_url: permanentUrl, + claim_id: claimId, + confirmations + } = claim; byUri[canonicalUrl] = claimId; byUri[permanentUrl] = claimId; @@ -6412,7 +6402,10 @@ reducers[UPDATE_PENDING_CLAIMS] = (state, action) => { }; reducers[UPDATE_CONFIRMED_CLAIMS] = (state, action) => { - const { claims: confirmedClaims, pending: pendingClaims } = action.data; + const { + claims: confirmedClaims, + pending: pendingClaims + } = action.data; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); // diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index 078f41b..03e1b78 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -76,7 +76,7 @@ export function doResolveUris( const collectionIds: Array = []; return Lbry.resolve({ urls: urisToResolve, ...options }).then( - async(result: ResolveResponse) => { + async (result: ResolveResponse) => { let repostedResults = {}; const repostsToResolve = []; const fallbackResolveInfo = { @@ -648,7 +648,7 @@ export function doClaimSearch( } ) { const query = createNormalizedClaimSearchKey(options); - return async(dispatch: Dispatch) => { + return async (dispatch: Dispatch) => { dispatch({ type: ACTIONS.CLAIM_SEARCH_STARTED, data: { query: query }, @@ -897,7 +897,6 @@ export function doCollectionPublishUpdate(options: { }, }); dispatch(doCheckPendingClaims()); - dispatch(doFetchCollectionListMine(1, 10)); return resolve(collectionClaim); } @@ -1006,7 +1005,9 @@ export const doCheckPendingClaims = (onConfirmed: Function) => ( 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? + const collectionIds = claims + .filter(c => c.value_type === 'collection') + .map(c => c.claim_id); dispatch({ type: ACTIONS.UPDATE_CONFIRMED_CLAIMS, data: { @@ -1014,6 +1015,13 @@ export const doCheckPendingClaims = (onConfirmed: Function) => ( pending: pendingById, }, }); + if (collectionIds.length) { + dispatch( + doFetchItemsInCollections({ + collectionIds, + }) + ); + } checkPendingCallbacks.forEach(cb => cb()); clearInterval(checkPendingInterval); }); -- 2.45.2 From 7b1cec5d52c1ce563e4fec73ae8430957545f1bf Mon Sep 17 00:00:00 2001 From: zeppi Date: Fri, 25 Jun 2021 16:53:26 -0400 Subject: [PATCH 4/7] prefer pending and edited collections in selector --- dist/bundle.es.js | 2 +- src/redux/selectors/collections.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 0e5d6a1..6eb1d1d 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -3665,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 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; }); diff --git a/src/redux/selectors/collections.js b/src/redux/selectors/collections.js index 3218e2f..24a8038 100644 --- a/src/redux/selectors/collections.js +++ b/src/redux/selectors/collections.js @@ -158,7 +158,7 @@ export const makeSelectCollectionForId = (id: string) => 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; } ); -- 2.45.2 From f1496084bb8d8d495b56d425ef4d58b133fb390e Mon Sep 17 00:00:00 2001 From: zeppi Date: Thu, 1 Jul 2021 17:16:34 -0400 Subject: [PATCH 5/7] fix bug canceling pending check early --- dist/bundle.es.js | 4 +++- src/redux/actions/claims.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 6eb1d1d..8f10413 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -4585,7 +4585,9 @@ const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { })); } checkPendingCallbacks.forEach(cb => cb()); - clearInterval(checkPendingInterval); + if (Object.keys(pendingById).length === 0) { + clearInterval(checkPendingInterval); + } }); } }); diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index 03e1b78..0af072c 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -1023,7 +1023,9 @@ export const doCheckPendingClaims = (onConfirmed: Function) => ( ); } checkPendingCallbacks.forEach(cb => cb()); - clearInterval(checkPendingInterval); + if (Object.keys(pendingById).length === 0) { + clearInterval(checkPendingInterval); + } }); } }); -- 2.45.2 From d4d927ce7b49cd5132337c84c42fdc9736701912 Mon Sep 17 00:00:00 2001 From: zeppi Date: Thu, 1 Jul 2021 18:04:56 -0400 Subject: [PATCH 6/7] cleanup --- src/redux/actions/claims.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index 0af072c..330480f 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -10,6 +10,7 @@ import { selectClaimsByUri, selectMyChannelClaims, selectPendingIds, + selectPendingClaimsById, } from 'redux/selectors/claims'; import { doFetchTxoPage } from 'redux/actions/wallet'; @@ -24,7 +25,6 @@ import { doFetchItemsInCollections, doCollectionDelete, } from 'redux/actions/collections'; -import { selectPendingClaimsById } from '../selectors/claims'; let checkPendingCallbacks = []; let checkPendingInterval; -- 2.45.2 From aae16889215ab18fca94681b9853fbaea4e517a2 Mon Sep 17 00:00:00 2001 From: zeppi Date: Fri, 2 Jul 2021 16:44:44 -0400 Subject: [PATCH 7/7] channel modlist on confirm --- dist/bundle.es.js | 20 +++++++++++++------- src/redux/actions/claims.js | 24 +++++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 8f10413..e2f4853 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -3723,7 +3723,7 @@ 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"); }); }; } -let checkPendingCallbacks = []; +let onChannelConfirmCallback; let checkPendingInterval; function doResolveUris(uris, returnCachedClaims = false, resolveReposts = true) { @@ -4064,7 +4064,7 @@ function doClearChannelErrors() { }; } -function doCreateChannel(name, amount, optionalParams, cb) { +function doCreateChannel(name, amount, optionalParams, onConfirm) { return dispatch => { dispatch({ type: CREATE_CHANNEL_STARTED @@ -4118,7 +4118,7 @@ function doCreateChannel(name, amount, optionalParams, cb) { claims: [channelClaim] } }); - dispatch(doCheckPendingClaims(cb)); + dispatch(doCheckPendingClaims(onConfirm)); return channelClaim; }).catch(error => { dispatch({ @@ -4547,9 +4547,12 @@ function doPurchaseList(page = 1, pageSize = PAGE_SIZE) { }; } -const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { +const doCheckPendingClaims = onChannelConfirmed => (dispatch, getState) => { + if (onChannelConfirmed) { + onChannelConfirmCallback = onChannelConfirmed; + } clearInterval(checkPendingInterval); - const checkTxoList = checkPendingCallbacks => { + const checkTxoList = () => { const state = getState(); const pendingById = Object.assign({}, selectPendingClaimsById(state)); const pendingTxos = Object.values(pendingById).map(p => p.txid); @@ -4584,7 +4587,10 @@ const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { collectionIds })); } - checkPendingCallbacks.forEach(cb => cb()); + 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); } @@ -4597,7 +4603,7 @@ const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { }; // do something with onConfirmed (typically get blocklist for channel) checkPendingInterval = setInterval(() => { - checkTxoList(checkPendingCallbacks); + checkTxoList(); }, 30000); }; diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index 330480f..37212a1 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -26,7 +26,7 @@ import { doCollectionDelete, } from 'redux/actions/collections'; -let checkPendingCallbacks = []; +let onChannelConfirmCallback; let checkPendingInterval; export function doResolveUris( @@ -76,7 +76,7 @@ export function doResolveUris( const collectionIds: Array = []; return Lbry.resolve({ urls: urisToResolve, ...options }).then( - async (result: ResolveResponse) => { + async(result: ResolveResponse) => { let repostedResults = {}; const repostsToResolve = []; const fallbackResolveInfo = { @@ -404,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) => { dispatch({ type: ACTIONS.CREATE_CHANNEL_STARTED, @@ -471,7 +471,7 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an claims: [channelClaim], }, }); - dispatch(doCheckPendingClaims(cb)); + dispatch(doCheckPendingClaims(onConfirm)); return channelClaim; }) .catch(error => { @@ -648,7 +648,7 @@ export function doClaimSearch( } ) { const query = createNormalizedClaimSearchKey(options); - return async (dispatch: Dispatch) => { + return async(dispatch: Dispatch) => { dispatch({ type: ACTIONS.CLAIM_SEARCH_STARTED, data: { query: query }, @@ -976,12 +976,15 @@ export function doPurchaseList(page: number = 1, pageSize: number = PAGE_SIZE) { }; } -export const doCheckPendingClaims = (onConfirmed: Function) => ( +export const doCheckPendingClaims = (onChannelConfirmed: Function) => ( dispatch: Dispatch, getState: GetState ) => { + if (onChannelConfirmed) { + onChannelConfirmCallback = onChannelConfirmed; + } clearInterval(checkPendingInterval); - const checkTxoList = checkPendingCallbacks => { + const checkTxoList = () => { const state = getState(); const pendingById = Object.assign({}, selectPendingClaimsById(state)); const pendingTxos = (Object.values(pendingById): any).map(p => p.txid); @@ -1022,7 +1025,10 @@ export const doCheckPendingClaims = (onConfirmed: Function) => ( }) ); } - checkPendingCallbacks.forEach(cb => cb()); + 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); } @@ -1035,6 +1041,6 @@ export const doCheckPendingClaims = (onConfirmed: Function) => ( }; // do something with onConfirmed (typically get blocklist for channel) checkPendingInterval = setInterval(() => { - checkTxoList(checkPendingCallbacks); + checkTxoList(); }, 30000); }; -- 2.45.2