diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 171bd30..3da1f70 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2180,8 +2180,7 @@ const selectRepostLoading = reselect.createSelector(selectState$2, state => stat const selectRepostError = reselect.createSelector(selectState$2, state => state.repostError); -const selectClaimsByUri = reselect.createSelector(selectState$2, selectClaimsById, (state, byId) => { - const byUri = state.claimsByUri || {}; +const selectClaimsByUri = reselect.createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => { const claims = {}; Object.keys(byUri).forEach(uri => { @@ -2202,52 +2201,32 @@ const selectClaimsByUri = reselect.createSelector(selectState$2, selectClaimsByI const selectAllClaimsByChannel = reselect.createSelector(selectState$2, state => state.paginatedClaimsByChannel || {}); -const selectPendingById = reselect.createSelector(selectState$2, state => state.pendingById || {}); +const selectPendingIds = reselect.createSelector(selectState$2, state => state.pendingIds || []); -const selectPendingClaims = reselect.createSelector(selectState$2, state => Object.values(state.pendingById || [])); - -const makeSelectClaimIsPending = uri => reselect.createSelector(selectPendingById, pendingById => { - let claimId; - - try { - const { isChannel, channelClaimId, streamClaimId } = parseURI(uri); - claimId = isChannel ? channelClaimId : streamClaimId; - } catch (e) {} +const makeSelectClaimIsPending = uri => reselect.createSelector(selectClaimIdsByUri, selectPendingIds, (idsByUri, pendingIds) => { + const claimId = idsByUri(normalizeURI(uri)); if (claimId) { - return Boolean(pendingById[claimId]); + return pendingIds.some(i => i === claimId); } + return false; }); -const makeSelectPendingByUri = uri => reselect.createSelector(selectPendingById, pendingById => { - const { isChannel, channelClaimId, streamClaimId } = parseURI(uri); - const claimId = isChannel ? channelClaimId : streamClaimId; - return pendingById[claimId]; -}); const selectReflectingById = reselect.createSelector(selectState$2, state => state.reflectingById); -const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimsByUri, selectPendingById, (byUri, pendingById) => { - // Check if a claim is pending first - // It won't be in claimsByUri because resolving it will return nothing - - let valid; +const makeSelectClaimForUri = (uri, returnRepost = true) => reselect.createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => { + let validUri; let channelClaimId; let streamClaimId; let isChannel; try { ({ isChannel, channelClaimId, streamClaimId } = parseURI(uri)); - valid = true; + validUri = true; } catch (e) {} - if (valid && byUri) { - const claimId = isChannel ? channelClaimId : streamClaimId; - const pendingClaim = pendingById[claimId]; - - if (pendingClaim) { - return pendingClaim; - } - - const claim = byUri[normalizeURI(uri)]; + if (validUri && byUri) { + const claimId = uri && byUri[normalizeURI(uri)]; + const claim = byId[claimId]; if (claim === undefined || claim === null) { // Make sure to return the claim as is so apps can check if it's been resolved before (null) or still needs to be resolved (undefined) return claim; @@ -2416,7 +2395,7 @@ const selectMyClaimsPageItemCount = reselect.createSelector(selectState$2, state const selectFetchingMyClaimsPageError = reselect.createSelector(selectState$2, state => state.fetchingClaimListMinePageError); -const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, selectPendingClaims, (myClaimIds, byId, abandoningIds, pendingClaims) => { +const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, (myClaimIds, byId, abandoningIds) => { const claims = []; myClaimIds.forEach(id => { @@ -2425,7 +2404,7 @@ const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaim if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim); }); - return [...claims, ...pendingClaims]; + return [...claims]; }); const selectMyClaimsWithoutChannels = reselect.createSelector(selectMyClaims, myClaims => myClaims.filter(claim => !claim.name.match(/^@/)).sort((a, b) => a.timestamp - b.timestamp)); @@ -2444,6 +2423,8 @@ const selectMyClaimUrisWithoutChannels = reselect.createSelector(selectMyClaimsW }); }); +const selectMyChannelUrls = reselect.createSelector(selectState$2, state => state.myChannelUrls); + const selectAllMyClaimsByOutpoint = reselect.createSelector(selectMyClaimsRaw, claims => new Set(claims && claims.length ? claims.map(claim => `${claim.txid}:${claim.nout}`) : null)); const selectMyClaimsOutpoints = reselect.createSelector(selectMyClaims, myClaims => { @@ -3506,7 +3487,7 @@ function doFetchClaimsByChannel(uri, page = 1) { }; } -function doCreateChannel(name, amount, optionalParams) { +function doCreateChannel(name, amount, optionalParams, cb) { return dispatch => { dispatch({ type: CREATE_CHANNEL_STARTED @@ -3551,6 +3532,11 @@ function doCreateChannel(name, amount, optionalParams) { type: CREATE_CHANNEL_COMPLETED, data: { channelClaim } }); + dispatch({ + type: UPDATE_PENDING_CLAIMS, + data: [channelClaim] + }); + dispatch(doCheckPendingClaims(cb)); return channelClaim; }).catch(error => { dispatch({ @@ -3562,7 +3548,7 @@ function doCreateChannel(name, amount, optionalParams) { }; } -function doUpdateChannel(params) { +function doUpdateChannel(params, cb) { return (dispatch, getState) => { dispatch({ type: UPDATE_CHANNEL_STARTED @@ -3607,7 +3593,14 @@ function doUpdateChannel(params) { type: UPDATE_CHANNEL_COMPLETED, data: { channelClaim } }); - }).catch(error => { + dispatch({ + type: UPDATE_PENDING_CLAIMS, + data: { + claims: [channelClaim] + } + }); + dispatch(doCheckPendingClaims(cb)); + }).then().catch(error => { dispatch({ type: UPDATE_CHANNEL_FAILED, data: error @@ -3803,6 +3796,46 @@ function doPurchaseList(page = 1, pageSize = PAGE_SIZE) { }; } +const doCheckPendingClaims = onConfirmed => (dispatch, getState) => { + let claimCheckInterval; + + const checkClaimList = () => { + const state = getState(); + const pendingIdSet = new Set(selectPendingIds(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); + claimsToConfirm.push(claim); + if (onConfirmed) { + onConfirmed(claim); + } + } + }); + if (claimsToConfirm.length) { + dispatch({ + type: UPDATE_CONFIRMED_CLAIMS, + data: { + claims: claimsToConfirm + } + }); + } + return pendingIdSet.size; + }).then(len => { + if (!len) { + clearInterval(claimCheckInterval); + } + }); + }; + + claimCheckInterval = setInterval(() => { + checkClaimList(); + }, 30000); +}; + const selectState$3 = state => state.fileInfo || {}; const selectFileInfosByOutpoint = reselect.createSelector(selectState$3, state => state.byOutpoint || {}); @@ -4588,44 +4621,6 @@ const doCheckReflectingFiles = () => (dispatch, getState) => { }, 5000); } }; -const doCheckPendingPublishes = onConfirmed => (dispatch, getState) => { - let publishCheckInterval; - - const checkFileList = () => { - const state = getState(); - const pendingById = selectPendingById(state); - lbryProxy.claim_list({ page: 1, page_size: 10 }).then(result => { - const claims = result.items; - const claimsToConfirm = []; - claims.forEach(claim => { - if (claim.confirmations > 0 && pendingById[claim.claim_id]) { - delete pendingById[claim.claim_id]; - claimsToConfirm.push(claim); - if (onConfirmed) { - onConfirmed(claim); - } - } - }); - if (claimsToConfirm.length) { - dispatch({ - type: UPDATE_CONFIRMED_CLAIMS, - data: { - claims: claimsToConfirm - } - }); - } - return Object.keys(pendingById).length; - }).then(len => { - if (!len) { - clearInterval(publishCheckInterval); - } - }); - }; - - publishCheckInterval = setInterval(() => { - checkFileList(); - }, 30000); -}; // Returns a function, that, as long as it continues to be invoked, will not // be triggered. The function will be called after it stops being called for @@ -5112,6 +5107,16 @@ const doToggleBlockChannel = uri => ({ var _extends$a = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +/* +new claim = { ...maybeResolvedClaim, ...pendingClaim, meta: maybeResolvedClaim['meta'] } + */ + +function mergeClaims(maybeResolved, pending) { + return _extends$a({}, maybeResolved, pending, { meta: maybeResolved.meta }); +} + +var _extends$b = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + function _objectWithoutProperties$3(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } const reducers = {}; @@ -5123,6 +5128,7 @@ const defaultState = { fetchingChannelClaims: {}, resolvingUris: [], myChannelClaims: undefined, + myChannelUrls: undefined, myClaims: undefined, myPurchases: undefined, myPurchasesPageNumber: undefined, @@ -5132,7 +5138,7 @@ const defaultState = { fetchingMyPurchasesError: undefined, fetchingMyChannels: false, abandoningById: {}, - pendingById: {}, + pendingIds: [], reflectingById: {}, claimSearchError: false, claimSearchByQuery: {}, @@ -5163,18 +5169,19 @@ 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; let newResolvingUrls = new Set(state.resolvingUris); Object.entries(resolveInfo).forEach(([url, resolveResponse]) => { // $FlowFixMe const { claimsInChannel, stream, channel } = resolveResponse; - if (claimsInChannel) { - channelClaimCounts[url] = claimsInChannel; - channelClaimCounts[channel.canonical_url] = claimsInChannel; - } if (stream) { - byId[stream.claim_id] = stream; + if (pendingIds.includes(stream.claim_id)) { + byId[stream.claim_id] = mergeClaims(stream, byId[stream.claim_id]); // merge them + } else { + byId[stream.claim_id] = stream; + } byUri[url] = stream.claim_id; // If url isn't a canonical_url, make sure that is added too @@ -5186,12 +5193,18 @@ function handleClaimAction(state, action) { newResolvingUrls.delete(stream.permanent_url); } - if (channel) { - if (!stream) { - byUri[url] = channel.claim_id; + if (channel && channel.claim_id) { + if (claimsInChannel) { + channelClaimCounts[url] = claimsInChannel; + channelClaimCounts[channel.canonical_url] = claimsInChannel; } + byUri[url] = channel.claim_id; - byId[channel.claim_id] = channel; + if (pendingIds.includes(channel.claim_id)) { + byId[channel.claim_id] = mergeClaims(channel, byId[channel.claim_id]); + } else { + byId[channel.claim_id] = channel; + } // Also add the permanent_url here until lighthouse returns canonical_url for search results byUri[channel.permanent_url] = channel.claim_id; byUri[channel.canonical_url] = channel.claim_id; @@ -5231,7 +5244,7 @@ reducers[RESOLVE_URIS_STARTED] = (state, action) => { }; reducers[RESOLVE_URIS_COMPLETED] = (state, action) => { - return _extends$a({}, handleClaimAction(state, action)); + return _extends$b({}, handleClaimAction(state, action)); }; reducers[FETCH_CLAIM_LIST_MINE_STARTED] = state => Object.assign({}, state, { @@ -5246,46 +5259,37 @@ reducers[FETCH_CLAIM_LIST_MINE_COMPLETED] = (state, action) => { const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingById = Object.assign({}, state.pendingById); + const pendingIds = state.pendingIds || []; let myClaimIds = new Set(state.myClaims); let urlsForCurrentPage = []; + const pendingIdSet = new Set(pendingIds); + claims.forEach(claim => { - const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id }); - const { claim_id: claimId } = claim; + const { permanent_url: permanentUri, claim_id: claimId } = claim; if (claim.type && claim.type.match(/claim|update/)) { - urlsForCurrentPage.push(uri); + urlsForCurrentPage.push(permanentUri); if (claim.confirmations < 1) { - pendingById[claimId] = claim; - delete byId[claimId]; - delete byUri[claimId]; + 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]); } else { - byId[claimId] = claim; - byUri[uri] = claimId; + byId[claimId] = claim; // just add } + byUri[permanentUri] = claimId; myClaimIds.add(claimId); - if (!resolve && pendingById[claimId] && claim.confirmations > 0) { - delete pendingById[claimId]; - } } }); - // Remove old pending publishes if resolve if false (resolve=true means confirmations on updates are not 0) - if (!resolve) { - Object.values(pendingById) - // $FlowFixMe - .filter(pendingClaim => byId[pendingClaim.claim_id]).forEach(pendingClaim => { - // $FlowFixMe - delete pendingById[pendingClaim.claim_id]; - }); - } - return Object.assign({}, state, { isFetchingClaimListMine: false, myClaims: Array.from(myClaimIds), byId, + pendingIds: Array.from(pendingIdSet), claimsByUri: byUri, - pendingById, myClaimsPageResults: urlsForCurrentPage, myClaimsPageNumber: page, myClaimsPageTotalResults: totalItems @@ -5298,8 +5302,9 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { const { claims } = action.data; const myClaims = state.myClaims || []; let myClaimIds = new Set(state.myClaims); - const pendingById = Object.assign(state.pendingById); + const pendingIds = state.pendingIds || []; let myChannelClaims; + let myChannelUrls = []; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); const channelClaimCounts = Object.assign({}, state.channelClaimCounts); @@ -5307,8 +5312,10 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { if (!claims.length) { // $FlowFixMe myChannelClaims = null; + myChannelUrls = null; } else { myChannelClaims = new Set(state.myChannelClaims); + myChannelUrls = []; claims.forEach(claim => { const { claims_in_channel: claimsInChannel } = claim.meta; const { canonical_url: canonicalUrl, permanent_url: permanentUrl, claim_id: claimId } = claim; @@ -5320,18 +5327,11 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { // $FlowFixMe myChannelClaims.add(claimId); - if (!byId[claimId]) { + if (!pendingIds.some(c => c === claimId)) { byId[claimId] = claim; } - + myChannelUrls.push(permanentUrl); myClaimIds.add(claimId); - if (pendingById[claimId] && claim.confirmations > 0) { - delete pendingById[claimId]; - } - - if (pendingById[claimId] && claim.confirmations > 0) { - delete pendingById[claimId]; - } }); } @@ -5341,7 +5341,8 @@ reducers[FETCH_CHANNEL_LIST_COMPLETED] = (state, action) => { channelClaimCounts, fetchingMyChannels: false, myChannelClaims: myChannelClaims ? Array.from(myChannelClaims) : null, - myClaims: Array.from(myClaimIds) + myClaims: myClaimIds ? Array.from(myClaimIds) : null, + myChannelUrls }); }; @@ -5423,19 +5424,31 @@ reducers[ABANDON_CLAIM_STARTED] = (state, action) => { }; reducers[UPDATE_PENDING_CLAIMS] = (state, action) => { - const { claims } = action.data; + const { claims: pendingClaims } = action.data; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingById = Object.assign({}, state.pendingById); + const pendingIds = state.pendingIds; + const pendingIdSet = new Set(pendingIds); let myClaimIds = new Set(state.myClaims); + const myChannelClaims = new Set(state.myChannelClaims); // $FlowFixMe - claims.forEach(claim => { - const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id }); - const { claim_id: claimId } = claim; - if (claim.type && claim.type.match(/claim|update/)) { - pendingById[claimId] = claim; - delete byId[claimId]; + pendingClaims.forEach(claim => { + let newClaim; + const { permanent_url: uri, claim_id: claimId, type, value_type: valueType } = claim; + pendingIdSet.add(claimId); + const oldClaim = byId[claimId]; + if (oldClaim && oldClaim.canonical_url) { + newClaim = mergeClaims(oldClaim, claim); + } else { + newClaim = claim; + } + if (valueType === 'channel') { + myChannelClaims.add(claimId); + } + + if (type && type.match(/claim|update/)) { + byId[claimId] = newClaim; byUri[uri] = claimId; } myClaimIds.add(claimId); @@ -5443,32 +5456,35 @@ reducers[UPDATE_PENDING_CLAIMS] = (state, action) => { return Object.assign({}, state, { myClaims: Array.from(myClaimIds), byId, + myChannelClaims: Array.from(myChannelClaims), claimsByUri: byUri, - pendingById + pendingIds: Array.from(pendingIdSet) }); }; reducers[UPDATE_CONFIRMED_CLAIMS] = (state, action) => { - const { claims } = action.data; + const { claims: confirmedClaims } = action.data; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingById = Object.assign({}, state.pendingById); - let myClaimIds = new Set(state.myClaims); + const pendingIds = state.pendingIds; + const pendingIdSet = new Set(pendingIds); - claims.forEach(claim => { - const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id }); - const { claim_id: claimId } = claim; - if (claim.type && claim.type.match(/claim|update/)) { - delete pendingById[claimId]; - byId[claimId] = claim; + confirmedClaims.forEach(claim => { + const { permanent_url: permanentUri, claim_id: claimId, type } = claim; + let newClaim = claim; + const oldClaim = byId[claimId]; + if (oldClaim && oldClaim.canonical_url) { + newClaim = mergeClaims(oldClaim, claim); + } + if (type && type.match(/claim|update|channel/)) { + byId[claimId] = newClaim; + pendingIdSet.delete(claimId); } - myClaimIds.add(claimId); }); return Object.assign({}, state, { - myClaims: Array.from(myClaimIds), + pendingIds: Array.from(pendingIdSet), byId, - claimsByUri: byUri, - pendingById + claimsByUri: byUri }); }; @@ -5497,25 +5513,13 @@ reducers[ABANDON_CLAIM_SUCCEEDED] = (state, action) => { }); }; -reducers[CREATE_CHANNEL_STARTED] = state => _extends$a({}, state, { +reducers[CREATE_CHANNEL_STARTED] = state => _extends$b({}, state, { creatingChannel: true, createChannelError: null }); reducers[CREATE_CHANNEL_COMPLETED] = (state, action) => { - const channelClaim = action.data.channelClaim; - const byId = Object.assign({}, state.byId); - const pendingById = Object.assign({}, state.pendingById); - const myChannelClaims = new Set(state.myChannelClaims); - - byId[channelClaim.claim_id] = channelClaim; - pendingById[channelClaim.claim_id] = channelClaim; - myChannelClaims.add(channelClaim.claim_id); - return Object.assign({}, state, { - byId, - pendingById, - myChannelClaims: Array.from(myChannelClaims), creatingChannel: false }); }; @@ -5535,13 +5539,7 @@ reducers[UPDATE_CHANNEL_STARTED] = (state, action) => { }; reducers[UPDATE_CHANNEL_COMPLETED] = (state, action) => { - const channelClaim = action.data.channelClaim; - const byId = Object.assign({}, state.byId); - - byId[channelClaim.claim_id] = channelClaim; - return Object.assign({}, state, { - byId, updateChannelError: '', updatingChannel: false }); @@ -5585,7 +5583,7 @@ reducers[CLAIM_SEARCH_COMPLETED] = (state, action) => { delete fetchingClaimSearchByQuery[query]; - return Object.assign({}, state, _extends$a({}, handleClaimAction(state, action), { + return Object.assign({}, state, _extends$b({}, handleClaimAction(state, action), { claimSearchByQuery, claimSearchByQueryLastPageReached, fetchingClaimSearchByQuery @@ -5607,22 +5605,22 @@ reducers[CLAIM_SEARCH_FAILED] = (state, action) => { }; reducers[CLAIM_REPOST_STARTED] = state => { - return _extends$a({}, state, { + return _extends$b({}, state, { repostLoading: true, repostError: null }); }; reducers[CLAIM_REPOST_COMPLETED] = (state, action) => { const { originalClaimId, repostClaim } = action.data; - const byId = _extends$a({}, state.byId); - const claimsByUri = _extends$a({}, state.claimsByUri); + const byId = _extends$b({}, state.byId); + const claimsByUri = _extends$b({}, state.claimsByUri); const claimThatWasReposted = byId[originalClaimId]; - const repostStub = _extends$a({}, repostClaim, { reposted_claim: claimThatWasReposted }); + const repostStub = _extends$b({}, repostClaim, { reposted_claim: claimThatWasReposted }); byId[repostStub.claim_id] = repostStub; claimsByUri[repostStub.permanent_url] = repostStub.claim_id; - return _extends$a({}, state, { + return _extends$b({}, state, { byId, claimsByUri, repostLoading: false, @@ -5632,13 +5630,13 @@ reducers[CLAIM_REPOST_COMPLETED] = (state, action) => { reducers[CLAIM_REPOST_FAILED] = (state, action) => { const { error } = action.data; - return _extends$a({}, state, { + return _extends$b({}, state, { repostLoading: false, repostError: error }); }; reducers[CLEAR_REPOST_ERROR] = state => { - return _extends$a({}, state, { + return _extends$b({}, state, { repostError: null }); }; @@ -5649,34 +5647,34 @@ reducers[ADD_FILES_REFLECTING] = (state, action) => { reflectingById[claimId] = { fileListItem: pendingClaim, progress: 0, stalled: false }; - return Object.assign({}, state, _extends$a({}, state, { + return Object.assign({}, state, _extends$b({}, state, { reflectingById: reflectingById })); }; reducers[UPDATE_FILES_REFLECTING] = (state, action) => { const newReflectingById = action.data; - return Object.assign({}, state, _extends$a({}, state, { + return Object.assign({}, state, _extends$b({}, state, { reflectingById: newReflectingById })); }; reducers[TOGGLE_CHECKING_REFLECTING] = (state, action) => { const checkingReflecting = action.data; - return Object.assign({}, state, _extends$a({}, state, { + return Object.assign({}, state, _extends$b({}, state, { checkingReflecting })); }; reducers[TOGGLE_CHECKING_PENDING] = (state, action) => { const checking = action.data; - return Object.assign({}, state, _extends$a({}, state, { + return Object.assign({}, state, _extends$b({}, state, { checkingPending: checking })); }; reducers[PURCHASE_LIST_STARTED] = state => { - return _extends$a({}, state, { + return _extends$b({}, state, { fetchingMyPurchases: true, fetchingMyPurchasesError: null }); @@ -5721,7 +5719,7 @@ reducers[PURCHASE_LIST_COMPLETED] = (state, action) => { reducers[PURCHASE_LIST_FAILED] = (state, action) => { const { error } = action.data; - return _extends$a({}, state, { + return _extends$b({}, state, { fetchingMyPurchases: false, fetchingMyPurchasesError: error }); @@ -5742,7 +5740,7 @@ reducers[PURCHASE_URI_COMPLETED] = (state, action) => { myPurchases.push(uri); - return _extends$a({}, state, { + return _extends$b({}, state, { byId, myPurchases, purchaseUriSuccess: true @@ -5750,13 +5748,13 @@ reducers[PURCHASE_URI_COMPLETED] = (state, action) => { }; reducers[PURCHASE_URI_FAILED] = state => { - return _extends$a({}, state, { + return _extends$b({}, state, { purchaseUriSuccess: false }); }; reducers[CLEAR_PURCHASED_URI_SUCCESS] = state => { - return _extends$a({}, state, { + return _extends$b({}, state, { purchaseUriSuccess: false }); }; @@ -5785,7 +5783,7 @@ const handleActions = (actionMap, defaultState) => (state = defaultState, action return state; }; -var _extends$b = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$c = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; const defaultState$1 = { commentById: {}, // commentId -> Comment @@ -5796,11 +5794,11 @@ const defaultState$1 = { }; const commentReducer = handleActions({ - [COMMENT_CREATE_STARTED]: (state, action) => _extends$b({}, state, { + [COMMENT_CREATE_STARTED]: (state, action) => _extends$c({}, state, { isLoading: true }), - [COMMENT_CREATE_FAILED]: (state, action) => _extends$b({}, state, { + [COMMENT_CREATE_FAILED]: (state, action) => _extends$c({}, state, { isLoading: false }), @@ -5818,14 +5816,14 @@ const commentReducer = handleActions({ newCommentIds.unshift(comment.comment_id); byId[claimId] = newCommentIds; - return _extends$b({}, state, { + return _extends$c({}, state, { commentById, byId, isLoading: false }); }, - [COMMENT_LIST_STARTED]: state => _extends$b({}, state, { isLoading: true }), + [COMMENT_LIST_STARTED]: state => _extends$c({}, state, { isLoading: true }), [COMMENT_LIST_COMPLETED]: (state, action) => { const { comments, claimId, uri } = action.data; @@ -5849,7 +5847,7 @@ const commentReducer = handleActions({ byId[claimId] = commentIds; commentsByUri[uri] = claimId; } - return _extends$b({}, state, { + return _extends$c({}, state, { byId, commentById, commentsByUri, @@ -5857,10 +5855,10 @@ const commentReducer = handleActions({ }); }, - [COMMENT_LIST_FAILED]: (state, action) => _extends$b({}, state, { + [COMMENT_LIST_FAILED]: (state, action) => _extends$c({}, state, { isLoading: false }), - [COMMENT_ABANDON_STARTED]: (state, action) => _extends$b({}, state, { + [COMMENT_ABANDON_STARTED]: (state, action) => _extends$c({}, state, { isLoading: true }), [COMMENT_ABANDON_COMPLETED]: (state, action) => { @@ -5878,18 +5876,18 @@ const commentReducer = handleActions({ } delete commentById[comment_id]; - return _extends$b({}, state, { + return _extends$c({}, state, { commentById, byId, isLoading: false }); }, // do nothing - [COMMENT_ABANDON_FAILED]: (state, action) => _extends$b({}, state, { + [COMMENT_ABANDON_FAILED]: (state, action) => _extends$c({}, state, { isLoading: false }), // do nothing - [COMMENT_UPDATE_STARTED]: (state, action) => _extends$b({}, state, { + [COMMENT_UPDATE_STARTED]: (state, action) => _extends$c({}, state, { isLoading: true }), // replace existing comment with comment returned here under its comment_id @@ -5898,29 +5896,29 @@ const commentReducer = handleActions({ const commentById = Object.assign({}, state.commentById); commentById[comment.comment_id] = comment; - return _extends$b({}, state, { + return _extends$c({}, state, { commentById, isLoading: false }); }, // nothing can be done here - [COMMENT_UPDATE_FAILED]: (state, action) => _extends$b({}, state, { + [COMMENT_UPDATE_FAILED]: (state, action) => _extends$c({}, state, { isLoading: false }), // nothing can really be done here - [COMMENT_HIDE_STARTED]: (state, action) => _extends$b({}, state, { + [COMMENT_HIDE_STARTED]: (state, action) => _extends$c({}, state, { isLoading: true }), - [COMMENT_HIDE_COMPLETED]: (state, action) => _extends$b({}, state, { // todo: add HiddenComments state & create selectors + [COMMENT_HIDE_COMPLETED]: (state, action) => _extends$c({}, state, { // todo: add HiddenComments state & create selectors isLoading: false }), // nothing can be done here - [COMMENT_HIDE_FAILED]: (state, action) => _extends$b({}, state, { + [COMMENT_HIDE_FAILED]: (state, action) => _extends$c({}, state, { isLoading: false }) }, defaultState$1); -var _extends$c = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$d = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; const reducers$1 = {}; const defaultState$2 = { @@ -5929,9 +5927,9 @@ const defaultState$2 = { reducers$1[SET_CONTENT_POSITION] = (state, action) => { const { claimId, outpoint, position } = action.data; - return _extends$c({}, state, { - positions: _extends$c({}, state.positions, { - [claimId]: _extends$c({}, state.positions[claimId], { + return _extends$d({}, state, { + positions: _extends$d({}, state.positions, { + [claimId]: _extends$d({}, state.positions[claimId], { [outpoint]: position }) }) @@ -6098,7 +6096,7 @@ function fileInfoReducer(state = defaultState$3, action) { return state; } -var _extends$d = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$e = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; const defaultState$4 = { notifications: [], @@ -6113,7 +6111,7 @@ const notificationsReducer = handleActions({ const newToasts = state.toasts.slice(); newToasts.push(toast); - return _extends$d({}, state, { + return _extends$e({}, state, { toasts: newToasts }); }, @@ -6121,7 +6119,7 @@ const notificationsReducer = handleActions({ const newToasts = state.toasts.slice(); newToasts.shift(); - return _extends$d({}, state, { + return _extends$e({}, state, { toasts: newToasts }); }, @@ -6132,7 +6130,7 @@ const notificationsReducer = handleActions({ const newNotifications = state.notifications.slice(); newNotifications.push(notification); - return _extends$d({}, state, { + return _extends$e({}, state, { notifications: newNotifications }); }, @@ -6143,7 +6141,7 @@ const notificationsReducer = handleActions({ notifications = notifications.map(pastNotification => pastNotification.id === notification.id ? notification : pastNotification); - return _extends$d({}, state, { + return _extends$e({}, state, { notifications }); }, @@ -6152,7 +6150,7 @@ const notificationsReducer = handleActions({ let newNotifications = state.notifications.slice(); newNotifications = newNotifications.filter(notification => notification.id !== id); - return _extends$d({}, state, { + return _extends$e({}, state, { notifications: newNotifications }); }, @@ -6163,7 +6161,7 @@ const notificationsReducer = handleActions({ const newErrors = state.errors.slice(); newErrors.push(error); - return _extends$d({}, state, { + return _extends$e({}, state, { errors: newErrors }); }, @@ -6171,13 +6169,13 @@ const notificationsReducer = handleActions({ const newErrors = state.errors.slice(); newErrors.shift(); - return _extends$d({}, state, { + return _extends$e({}, state, { errors: newErrors }); } }, defaultState$4); -var _extends$e = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$f = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _objectWithoutProperties$4(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } @@ -6218,20 +6216,20 @@ const defaultState$5 = { const publishReducer = handleActions({ [UPDATE_PUBLISH_FORM]: (state, action) => { const { data } = action; - return _extends$e({}, state, data); + return _extends$f({}, state, data); }, - [CLEAR_PUBLISH]: state => _extends$e({}, defaultState$5, { + [CLEAR_PUBLISH]: state => _extends$f({}, defaultState$5, { bid: state.bid, optimize: state.optimize }), - [PUBLISH_START]: state => _extends$e({}, state, { + [PUBLISH_START]: state => _extends$f({}, state, { publishing: true, publishSuccess: false }), - [PUBLISH_FAIL]: state => _extends$e({}, state, { + [PUBLISH_FAIL]: state => _extends$f({}, state, { publishing: false }), - [PUBLISH_SUCCESS]: state => _extends$e({}, state, { + [PUBLISH_SUCCESS]: state => _extends$f({}, state, { publishing: false, publishSuccess: true }), @@ -6246,14 +6244,14 @@ const publishReducer = handleActions({ streamName: name }); - return _extends$e({}, defaultState$5, publishData, { + return _extends$f({}, defaultState$5, publishData, { editingURI: uri, uri: shortUri }); } }, defaultState$5); -var _extends$f = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$g = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; const defaultState$6 = { isActive: false, // does the user have any typed text in the search input @@ -6275,23 +6273,23 @@ const defaultState$6 = { }; const searchReducer = handleActions({ - [SEARCH_START]: state => _extends$f({}, state, { + [SEARCH_START]: state => _extends$g({}, state, { searching: true }), [SEARCH_SUCCESS]: (state, action) => { const { query, uris } = action.data; - return _extends$f({}, state, { + return _extends$g({}, state, { searching: false, urisByQuery: Object.assign({}, state.urisByQuery, { [query]: uris }) }); }, - [SEARCH_FAIL]: state => _extends$f({}, state, { + [SEARCH_FAIL]: state => _extends$g({}, state, { searching: false }), - [RESOLVED_SEARCH_START]: state => _extends$f({}, state, { + [RESOLVED_SEARCH_START]: state => _extends$g({}, state, { searching: true }), [RESOLVED_SEARCH_SUCCESS]: (state, action) => { @@ -6309,24 +6307,24 @@ const searchReducer = handleActions({ // the returned number of urls is less than the page size, so we're on the last page resolvedResultsByQueryLastPageReached[query] = results.length < pageSize; - return _extends$f({}, state, { + return _extends$g({}, state, { searching: false, resolvedResultsByQuery, resolvedResultsByQueryLastPageReached }); }, - [RESOLVED_SEARCH_FAIL]: state => _extends$f({}, state, { + [RESOLVED_SEARCH_FAIL]: state => _extends$g({}, state, { searching: false }), - [UPDATE_SEARCH_QUERY]: (state, action) => _extends$f({}, state, { + [UPDATE_SEARCH_QUERY]: (state, action) => _extends$g({}, state, { searchQuery: action.data.query, isActive: true }), - [UPDATE_SEARCH_SUGGESTIONS]: (state, action) => _extends$f({}, state, { - suggestions: _extends$f({}, state.suggestions, { + [UPDATE_SEARCH_SUGGESTIONS]: (state, action) => _extends$g({}, state, { + suggestions: _extends$g({}, state.suggestions, { [action.data.query]: action.data.suggestions }) }), @@ -6334,30 +6332,30 @@ const searchReducer = handleActions({ // sets isActive to false so the uri will be populated correctly if the // user is on a file page. The search query will still be present on any // other page - [DISMISS_NOTIFICATION]: state => _extends$f({}, state, { + [DISMISS_NOTIFICATION]: state => _extends$g({}, state, { isActive: false }), - [SEARCH_FOCUS]: state => _extends$f({}, state, { + [SEARCH_FOCUS]: state => _extends$g({}, state, { focused: true }), - [SEARCH_BLUR]: state => _extends$f({}, state, { + [SEARCH_BLUR]: state => _extends$g({}, state, { focused: false }), [UPDATE_SEARCH_OPTIONS]: (state, action) => { const { options: oldOptions } = state; const newOptions = action.data; - const options = _extends$f({}, oldOptions, newOptions); - return _extends$f({}, state, { + const options = _extends$g({}, oldOptions, newOptions); + return _extends$g({}, state, { options }); } }, defaultState$6); -var _extends$g = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$h = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function getDefaultKnownTags() { - return DEFAULT_FOLLOWED_TAGS.concat(DEFAULT_KNOWN_TAGS).reduce((tagsMap, tag) => _extends$g({}, tagsMap, { + return DEFAULT_FOLLOWED_TAGS.concat(DEFAULT_KNOWN_TAGS).reduce((tagsMap, tag) => _extends$h({}, tagsMap, { [tag]: { name: tag } }), {}); } @@ -6380,7 +6378,7 @@ const tagsReducer = handleActions({ newFollowedTags.push(name); } - return _extends$g({}, state, { + return _extends$h({}, state, { followedTags: newFollowedTags }); }, @@ -6389,10 +6387,10 @@ const tagsReducer = handleActions({ const { knownTags } = state; const { name } = action.data; - let newKnownTags = _extends$g({}, knownTags); + let newKnownTags = _extends$h({}, knownTags); newKnownTags[name] = { name }; - return _extends$g({}, state, { + return _extends$h({}, state, { knownTags: newKnownTags }); }, @@ -6401,11 +6399,11 @@ const tagsReducer = handleActions({ const { knownTags, followedTags } = state; const { name } = action.data; - let newKnownTags = _extends$g({}, knownTags); + let newKnownTags = _extends$h({}, knownTags); delete newKnownTags[name]; const newFollowedTags = followedTags.filter(tag => tag !== name); - return _extends$g({}, state, { + return _extends$h({}, state, { knownTags: newKnownTags, followedTags: newFollowedTags }); @@ -6413,15 +6411,15 @@ const tagsReducer = handleActions({ [USER_STATE_POPULATE]: (state, action) => { const { tags } = action.data; if (Array.isArray(tags)) { - return _extends$g({}, state, { + return _extends$h({}, state, { followedTags: tags }); } - return _extends$g({}, state); + return _extends$h({}, state); } }, defaultState$7); -var _extends$h = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$i = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; const defaultState$8 = { blockedChannels: [] @@ -6445,13 +6443,13 @@ const blockedReducer = handleActions({ }, [USER_STATE_POPULATE]: (state, action) => { const { blocked } = action.data; - return _extends$h({}, state, { + return _extends$i({}, state, { blockedChannels: blocked && blocked.length ? blocked : state.blockedChannels }); } }, defaultState$8); -var _extends$i = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$j = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; const buildDraftTransaction = () => ({ amount: undefined, @@ -6503,40 +6501,40 @@ const defaultState$9 = { }; const walletReducer = handleActions({ - [FETCH_TRANSACTIONS_STARTED]: state => _extends$i({}, state, { + [FETCH_TRANSACTIONS_STARTED]: state => _extends$j({}, state, { fetchingTransactions: true }), [FETCH_TRANSACTIONS_COMPLETED]: (state, action) => { - const byId = _extends$i({}, state.transactions); + const byId = _extends$j({}, state.transactions); const { transactions } = action.data; transactions.forEach(transaction => { byId[transaction.txid] = transaction; }); - return _extends$i({}, state, { + return _extends$j({}, state, { transactions: byId, fetchingTransactions: false }); }, [FETCH_TXO_PAGE_STARTED]: state => { - return _extends$i({}, state, { + return _extends$j({}, state, { fetchingTxos: true, fetchingTxosError: undefined }); }, [FETCH_TXO_PAGE_COMPLETED]: (state, action) => { - return _extends$i({}, state, { + return _extends$j({}, state, { txoPage: action.data, fetchingTxos: false }); }, [FETCH_TXO_PAGE_FAILED]: (state, action) => { - return _extends$i({}, state, { + return _extends$j({}, state, { txoPage: {}, fetchingTxos: false, fetchingTxosError: action.data @@ -6544,12 +6542,12 @@ const walletReducer = handleActions({ }, [UPDATE_TXO_FETCH_PARAMS]: (state, action) => { - return _extends$i({}, state, { + return _extends$j({}, state, { txoFetchParams: action.data }); }, - [FETCH_SUPPORTS_STARTED]: state => _extends$i({}, state, { + [FETCH_SUPPORTS_STARTED]: state => _extends$j({}, state, { fetchingSupports: true }), @@ -6562,7 +6560,7 @@ const walletReducer = handleActions({ byOutpoint[`${txid}:${nout}`] = transaction; }); - return _extends$i({}, state, { supports: byOutpoint, fetchingSupports: false }); + return _extends$j({}, state, { supports: byOutpoint, fetchingSupports: false }); }, [ABANDON_SUPPORT_STARTED]: (state, action) => { @@ -6571,7 +6569,7 @@ const walletReducer = handleActions({ currentlyAbandoning[outpoint] = true; - return _extends$i({}, state, { + return _extends$j({}, state, { abandoningSupportsByOutpoint: currentlyAbandoning }); }, @@ -6584,20 +6582,20 @@ const walletReducer = handleActions({ delete currentlyAbandoning[outpoint]; delete byOutpoint[outpoint]; - return _extends$i({}, state, { + return _extends$j({}, state, { supports: byOutpoint, abandoningSupportsById: currentlyAbandoning }); }, [ABANDON_CLAIM_SUPPORT_STARTED]: (state, action) => { - return _extends$i({}, state, { + return _extends$j({}, state, { abandonClaimSupportError: undefined }); }, [ABANDON_CLAIM_SUPPORT_PREVIEW]: (state, action) => { - return _extends$i({}, state, { + return _extends$j({}, state, { abandonClaimSupportError: undefined }); }, @@ -6608,36 +6606,36 @@ const walletReducer = handleActions({ pendingtxs[claimId] = { txid, type, effective }; - return _extends$i({}, state, { + return _extends$j({}, state, { pendingSupportTransactions: pendingtxs, abandonClaimSupportError: undefined }); }, [ABANDON_CLAIM_SUPPORT_FAILED]: (state, action) => { - return _extends$i({}, state, { + return _extends$j({}, state, { abandonClaimSupportError: action.data }); }, [PENDING_SUPPORTS_UPDATED]: (state, action) => { - return _extends$i({}, state, { + return _extends$j({}, state, { pendingSupportTransactions: action.data }); }, - [GET_NEW_ADDRESS_STARTED]: state => _extends$i({}, state, { + [GET_NEW_ADDRESS_STARTED]: state => _extends$j({}, state, { gettingNewAddress: true }), [GET_NEW_ADDRESS_COMPLETED]: (state, action) => { const { address } = action.data; - return _extends$i({}, state, { gettingNewAddress: false, receiveAddress: address }); + return _extends$j({}, state, { gettingNewAddress: false, receiveAddress: address }); }, - [UPDATE_BALANCE]: (state, action) => _extends$i({}, state, { + [UPDATE_BALANCE]: (state, action) => _extends$j({}, state, { totalBalance: action.data.totalBalance, balance: action.data.balance, reservedBalance: action.data.reservedBalance, @@ -6646,32 +6644,32 @@ const walletReducer = handleActions({ tipsBalance: action.data.tipsBalance }), - [CHECK_ADDRESS_IS_MINE_STARTED]: state => _extends$i({}, state, { + [CHECK_ADDRESS_IS_MINE_STARTED]: state => _extends$j({}, state, { checkingAddressOwnership: true }), - [CHECK_ADDRESS_IS_MINE_COMPLETED]: state => _extends$i({}, state, { + [CHECK_ADDRESS_IS_MINE_COMPLETED]: state => _extends$j({}, state, { checkingAddressOwnership: false }), [SET_DRAFT_TRANSACTION_AMOUNT]: (state, action) => { const oldDraft = state.draftTransaction; - const newDraft = _extends$i({}, oldDraft, { amount: parseFloat(action.data.amount) }); + const newDraft = _extends$j({}, oldDraft, { amount: parseFloat(action.data.amount) }); - return _extends$i({}, state, { draftTransaction: newDraft }); + return _extends$j({}, state, { draftTransaction: newDraft }); }, [SET_DRAFT_TRANSACTION_ADDRESS]: (state, action) => { const oldDraft = state.draftTransaction; - const newDraft = _extends$i({}, oldDraft, { address: action.data.address }); + const newDraft = _extends$j({}, oldDraft, { address: action.data.address }); - return _extends$i({}, state, { draftTransaction: newDraft }); + return _extends$j({}, state, { draftTransaction: newDraft }); }, [SEND_TRANSACTION_STARTED]: state => { - const newDraftTransaction = _extends$i({}, state.draftTransaction, { sending: true }); + const newDraftTransaction = _extends$j({}, state.draftTransaction, { sending: true }); - return _extends$i({}, state, { draftTransaction: newDraftTransaction }); + return _extends$j({}, state, { draftTransaction: newDraftTransaction }); }, [SEND_TRANSACTION_COMPLETED]: state => Object.assign({}, state, { @@ -6684,114 +6682,114 @@ const walletReducer = handleActions({ error: action.data.error }); - return _extends$i({}, state, { draftTransaction: newDraftTransaction }); + return _extends$j({}, state, { draftTransaction: newDraftTransaction }); }, - [SUPPORT_TRANSACTION_STARTED]: state => _extends$i({}, state, { + [SUPPORT_TRANSACTION_STARTED]: state => _extends$j({}, state, { sendingSupport: true }), - [SUPPORT_TRANSACTION_COMPLETED]: state => _extends$i({}, state, { + [SUPPORT_TRANSACTION_COMPLETED]: state => _extends$j({}, state, { sendingSupport: false }), - [SUPPORT_TRANSACTION_FAILED]: (state, action) => _extends$i({}, state, { + [SUPPORT_TRANSACTION_FAILED]: (state, action) => _extends$j({}, state, { error: action.data.error, sendingSupport: false }), - [CLEAR_SUPPORT_TRANSACTION]: state => _extends$i({}, state, { + [CLEAR_SUPPORT_TRANSACTION]: state => _extends$j({}, state, { sendingSupport: false }), - [WALLET_STATUS_COMPLETED]: (state, action) => _extends$i({}, state, { + [WALLET_STATUS_COMPLETED]: (state, action) => _extends$j({}, state, { walletIsEncrypted: action.result }), - [WALLET_ENCRYPT_START]: state => _extends$i({}, state, { + [WALLET_ENCRYPT_START]: state => _extends$j({}, state, { walletEncryptPending: true, walletEncryptSucceded: null, walletEncryptResult: null }), - [WALLET_ENCRYPT_COMPLETED]: (state, action) => _extends$i({}, state, { + [WALLET_ENCRYPT_COMPLETED]: (state, action) => _extends$j({}, state, { walletEncryptPending: false, walletEncryptSucceded: true, walletEncryptResult: action.result }), - [WALLET_ENCRYPT_FAILED]: (state, action) => _extends$i({}, state, { + [WALLET_ENCRYPT_FAILED]: (state, action) => _extends$j({}, state, { walletEncryptPending: false, walletEncryptSucceded: false, walletEncryptResult: action.result }), - [WALLET_DECRYPT_START]: state => _extends$i({}, state, { + [WALLET_DECRYPT_START]: state => _extends$j({}, state, { walletDecryptPending: true, walletDecryptSucceded: null, walletDecryptResult: null }), - [WALLET_DECRYPT_COMPLETED]: (state, action) => _extends$i({}, state, { + [WALLET_DECRYPT_COMPLETED]: (state, action) => _extends$j({}, state, { walletDecryptPending: false, walletDecryptSucceded: true, walletDecryptResult: action.result }), - [WALLET_DECRYPT_FAILED]: (state, action) => _extends$i({}, state, { + [WALLET_DECRYPT_FAILED]: (state, action) => _extends$j({}, state, { walletDecryptPending: false, walletDecryptSucceded: false, walletDecryptResult: action.result }), - [WALLET_UNLOCK_START]: state => _extends$i({}, state, { + [WALLET_UNLOCK_START]: state => _extends$j({}, state, { walletUnlockPending: true, walletUnlockSucceded: null, walletUnlockResult: null }), - [WALLET_UNLOCK_COMPLETED]: (state, action) => _extends$i({}, state, { + [WALLET_UNLOCK_COMPLETED]: (state, action) => _extends$j({}, state, { walletUnlockPending: false, walletUnlockSucceded: true, walletUnlockResult: action.result }), - [WALLET_UNLOCK_FAILED]: (state, action) => _extends$i({}, state, { + [WALLET_UNLOCK_FAILED]: (state, action) => _extends$j({}, state, { walletUnlockPending: false, walletUnlockSucceded: false, walletUnlockResult: action.result }), - [WALLET_LOCK_START]: state => _extends$i({}, state, { + [WALLET_LOCK_START]: state => _extends$j({}, state, { walletLockPending: false, walletLockSucceded: null, walletLockResult: null }), - [WALLET_LOCK_COMPLETED]: (state, action) => _extends$i({}, state, { + [WALLET_LOCK_COMPLETED]: (state, action) => _extends$j({}, state, { walletLockPending: false, walletLockSucceded: true, walletLockResult: action.result }), - [WALLET_LOCK_FAILED]: (state, action) => _extends$i({}, state, { + [WALLET_LOCK_FAILED]: (state, action) => _extends$j({}, state, { walletLockPending: false, walletLockSucceded: false, walletLockResult: action.result }), - [SET_TRANSACTION_LIST_FILTER]: (state, action) => _extends$i({}, state, { + [SET_TRANSACTION_LIST_FILTER]: (state, action) => _extends$j({}, state, { transactionListFilter: action.data }), - [UPDATE_CURRENT_HEIGHT]: (state, action) => _extends$i({}, state, { + [UPDATE_CURRENT_HEIGHT]: (state, action) => _extends$j({}, state, { latestBlock: action.data }), - [WALLET_RESTART]: state => _extends$i({}, state, { + [WALLET_RESTART]: state => _extends$j({}, state, { walletReconnecting: true }), - [WALLET_RESTART_COMPLETED]: state => _extends$i({}, state, { + [WALLET_RESTART_COMPLETED]: state => _extends$j({}, state, { walletReconnecting: false }) }, defaultState$9); @@ -6809,14 +6807,14 @@ const makeSelectContentPositionForUri = uri => reselect.createSelector(selectSta return state.positions[id] ? state.positions[id][outpoint] : null; }); -var _extends$j = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; +var _extends$k = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; const selectState$6 = state => state.notifications || {}; const selectToast = reselect.createSelector(selectState$6, state => { if (state.toasts.length) { const { id, params } = state.toasts[0]; - return _extends$j({ + return _extends$k({ id }, params); } @@ -6964,7 +6962,7 @@ exports.doAddTag = doAddTag; exports.doBalanceSubscribe = doBalanceSubscribe; exports.doBlurSearchInput = doBlurSearchInput; exports.doCheckAddressIsMine = doCheckAddressIsMine; -exports.doCheckPendingPublishes = doCheckPendingPublishes; +exports.doCheckPendingClaims = doCheckPendingClaims; exports.doCheckPublishNameAvailability = doCheckPublishNameAvailability; exports.doCheckReflectingFiles = doCheckReflectingFiles; exports.doClaimSearch = doClaimSearch; @@ -7073,7 +7071,6 @@ exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel; exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris; exports.makeSelectOmittedCountForChannel = makeSelectOmittedCountForChannel; exports.makeSelectPendingAmountByUri = makeSelectPendingAmountByUri; -exports.makeSelectPendingByUri = makeSelectPendingByUri; exports.makeSelectPermanentUrlForUri = makeSelectPermanentUrlForUri; exports.makeSelectPublishFormValue = makeSelectPublishFormValue; exports.makeSelectQueryWithOptions = makeSelectQueryWithOptions; @@ -7165,6 +7162,7 @@ exports.selectIsStillEditing = selectIsStillEditing; exports.selectIsWalletReconnecting = selectIsWalletReconnecting; exports.selectMyActiveClaims = selectMyActiveClaims; exports.selectMyChannelClaims = selectMyChannelClaims; +exports.selectMyChannelUrls = selectMyChannelUrls; exports.selectMyClaimForUri = selectMyClaimForUri; exports.selectMyClaimUrisWithoutChannels = selectMyClaimUrisWithoutChannels; exports.selectMyClaims = selectMyClaims; @@ -7177,8 +7175,6 @@ exports.selectMyClaimsWithoutChannels = selectMyClaimsWithoutChannels; exports.selectMyPurchases = selectMyPurchases; exports.selectMyPurchasesCount = selectMyPurchasesCount; exports.selectMyStreamUrlsCount = selectMyStreamUrlsCount; -exports.selectPendingById = selectPendingById; -exports.selectPendingClaims = selectPendingClaims; exports.selectPendingSupportTransactions = selectPendingSupportTransactions; exports.selectPlayingUri = selectPlayingUri; exports.selectPublishFormValues = selectPublishFormValues; diff --git a/dist/flow-typed/Claim.js b/dist/flow-typed/Claim.js index c9732bd..0b97c0e 100644 --- a/dist/flow-typed/Claim.js +++ b/dist/flow-typed/Claim.js @@ -22,7 +22,7 @@ declare type GenericClaim = { timestamp?: number, // date of last transaction height: number, // block height the tx was confirmed is_channel_signature_valid?: boolean, - is_my_output: true, + is_my_output: boolean, name: string, normalized_name: string, // `name` normalized via unicode NFD spec, nout: number, // index number for an output of a tx diff --git a/flow-typed/Claim.js b/flow-typed/Claim.js index c9732bd..0b97c0e 100644 --- a/flow-typed/Claim.js +++ b/flow-typed/Claim.js @@ -22,7 +22,7 @@ declare type GenericClaim = { timestamp?: number, // date of last transaction height: number, // block height the tx was confirmed is_channel_signature_valid?: boolean, - is_my_output: true, + is_my_output: boolean, name: string, normalized_name: string, // `name` normalized via unicode NFD spec, nout: number, // index number for an output of a tx diff --git a/src/index.js b/src/index.js index 76f5ed6..dcec873 100644 --- a/src/index.js +++ b/src/index.js @@ -76,6 +76,7 @@ export { doClearRepostError, doCheckPublishNameAvailability, doPurchaseList, + doCheckPendingClaims, } from 'redux/actions/claims'; export { doClearPurchasedUriSuccess, doPurchaseUri, doFileGet } from 'redux/actions/file'; @@ -94,7 +95,6 @@ export { doUploadThumbnail, doPrepareEdit, doPublish, - doCheckPendingPublishes, doCheckReflectingFiles, } from 'redux/actions/publish'; @@ -198,7 +198,6 @@ export { makeSelectFirstRecommendedFileForUri, makeSelectChannelForClaimUri, makeSelectClaimIsPending, - makeSelectPendingByUri, makeSelectReflectingClaimForUri, makeSelectClaimsInChannelForCurrentPageState, makeSelectShortUrlForUri, @@ -207,7 +206,6 @@ export { makeSelectSupportsForUri, makeSelectMyPurchasesForPage, makeSelectClaimWasPurchased, - selectPendingById, selectReflectingById, selectClaimsById, selectClaimsByUri, @@ -217,9 +215,9 @@ export { selectMyActiveClaims, selectAllFetchingChannelClaims, selectIsFetchingClaimListMine, - selectPendingClaims, selectMyClaims, selectMyClaimsWithoutChannels, + selectMyChannelUrls, selectMyClaimUrisWithoutChannels, selectAllMyClaimsByOutpoint, selectMyClaimsOutpoints, diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index 56a4baf..91039ea 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -9,6 +9,7 @@ import { selectResolvingUris, selectClaimsByUri, selectMyChannelClaims, + selectPendingIds, } from 'redux/selectors/claims'; import { doFetchTxoPage } from 'redux/actions/wallet'; import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; @@ -338,7 +339,7 @@ export function doFetchClaimsByChannel(uri: string, page: number = 1) { }; } -export function doCreateChannel(name: string, amount: number, optionalParams: any) { +export function doCreateChannel(name: string, amount: number, optionalParams: any, cb: any) { return (dispatch: Dispatch) => { dispatch({ type: ACTIONS.CREATE_CHANNEL_STARTED, @@ -395,6 +396,11 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an type: ACTIONS.CREATE_CHANNEL_COMPLETED, data: { channelClaim }, }); + dispatch({ + type: ACTIONS.UPDATE_PENDING_CLAIMS, + data: [channelClaim], + }); + dispatch(doCheckPendingClaims(cb)); return channelClaim; }) .catch(error => { @@ -408,7 +414,7 @@ export function doCreateChannel(name: string, amount: number, optionalParams: an }; } -export function doUpdateChannel(params: any) { +export function doUpdateChannel(params: any, cb: any) { return (dispatch: Dispatch, getState: GetState) => { dispatch({ type: ACTIONS.UPDATE_CHANNEL_STARTED, @@ -454,7 +460,15 @@ export function doUpdateChannel(params: any) { type: ACTIONS.UPDATE_CHANNEL_COMPLETED, data: { channelClaim }, }); + dispatch({ + type: ACTIONS.UPDATE_PENDING_CLAIMS, + data: { + claims: [channelClaim], + }, + }); + dispatch(doCheckPendingClaims(cb)); }) + .then() .catch(error => { dispatch({ type: ACTIONS.UPDATE_CHANNEL_FAILED, @@ -669,3 +683,48 @@ export function doPurchaseList(page: number = 1, pageSize: number = PAGE_SIZE) { }).then(success, failure); }; } + +export const doCheckPendingClaims = (onConfirmed: Function) => ( + dispatch: Dispatch, + getState: GetState +) => { + let claimCheckInterval; + + const checkClaimList = () => { + const state = getState(); + const pendingIdSet = new Set(selectPendingIds(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); + claimsToConfirm.push(claim); + if (onConfirmed) { + onConfirmed(claim); + } + } + }); + if (claimsToConfirm.length) { + dispatch({ + type: ACTIONS.UPDATE_CONFIRMED_CLAIMS, + data: { + claims: claimsToConfirm, + }, + }); + } + return pendingIdSet.size; + }) + .then(len => { + if (!len) { + clearInterval(claimCheckInterval); + } + }); + }; + + claimCheckInterval = setInterval(() => { + checkClaimList(); + }, 30000); +}; diff --git a/src/redux/actions/publish.js b/src/redux/actions/publish.js index 23d6d74..c977640 100644 --- a/src/redux/actions/publish.js +++ b/src/redux/actions/publish.js @@ -10,7 +10,6 @@ import { doError } from 'redux/actions/notifications'; import { isClaimNsfw } from 'util/claim'; import { selectMyChannelClaims, - selectPendingById, selectMyClaimsWithoutChannels, selectReflectingById, } from 'redux/selectors/claims'; @@ -427,46 +426,3 @@ export const doCheckReflectingFiles = () => (dispatch: Dispatch, getState: GetSt }, 5000); } }; -export const doCheckPendingPublishes = (onConfirmed: Function) => ( - dispatch: Dispatch, - getState: GetState -) => { - let publishCheckInterval; - - const checkFileList = () => { - const state = getState(); - const pendingById = selectPendingById(state); - Lbry.claim_list({ page: 1, page_size: 10 }) - .then(result => { - const claims = result.items; - const claimsToConfirm = []; - claims.forEach(claim => { - if (claim.confirmations > 0 && pendingById[claim.claim_id]) { - delete pendingById[claim.claim_id]; - claimsToConfirm.push(claim); - if (onConfirmed) { - onConfirmed(claim); - } - } - }); - if (claimsToConfirm.length) { - dispatch({ - type: ACTIONS.UPDATE_CONFIRMED_CLAIMS, - data: { - claims: claimsToConfirm, - }, - }); - } - return Object.keys(pendingById).length; - }) - .then(len => { - if (!len) { - clearInterval(publishCheckInterval); - } - }); - }; - - publishCheckInterval = setInterval(() => { - checkFileList(); - }, 30000); -}; diff --git a/src/redux/reducers/claims.js b/src/redux/reducers/claims.js index d74ffd1..99a4e4a 100644 --- a/src/redux/reducers/claims.js +++ b/src/redux/reducers/claims.js @@ -9,7 +9,7 @@ // - Sean import * as ACTIONS from 'constants/action_types'; -import { buildURI, parseURI } from 'lbryURI'; +import mergeClaim from 'util/merge-claim'; type State = { createChannelError: ?string, @@ -17,10 +17,11 @@ type State = { claimsByUri: { [string]: string }, byId: { [string]: Claim }, resolvingUris: Array, - pendingById: { [string]: Claim }, + pendingIds: Array, reflectingById: { [string]: ReflectingUpdate }, myClaims: ?Array, myChannelClaims: ?Array, + myChannelUrls: ?Array, abandoningById: { [string]: boolean }, fetchingChannelClaims: { [string]: number }, fetchingMyChannels: boolean, @@ -66,6 +67,7 @@ const defaultState = { fetchingChannelClaims: {}, resolvingUris: [], myChannelClaims: undefined, + myChannelUrls: undefined, myClaims: undefined, myPurchases: undefined, myPurchasesPageNumber: undefined, @@ -75,7 +77,7 @@ const defaultState = { fetchingMyPurchasesError: undefined, fetchingMyChannels: false, abandoningById: {}, - pendingById: {}, + pendingIds: [], reflectingById: {}, claimSearchError: false, claimSearchByQuery: {}, @@ -112,18 +114,19 @@ 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; let newResolvingUrls = new Set(state.resolvingUris); Object.entries(resolveInfo).forEach(([url: string, resolveResponse: ResolveResponse]) => { // $FlowFixMe const { claimsInChannel, stream, channel } = resolveResponse; - if (claimsInChannel) { - channelClaimCounts[url] = claimsInChannel; - channelClaimCounts[channel.canonical_url] = claimsInChannel; - } if (stream) { - byId[stream.claim_id] = stream; + if (pendingIds.includes(stream.claim_id)) { + byId[stream.claim_id] = mergeClaim(stream, byId[stream.claim_id]);// merge them + } else { + byId[stream.claim_id] = stream; + } byUri[url] = stream.claim_id; // If url isn't a canonical_url, make sure that is added too @@ -135,12 +138,18 @@ function handleClaimAction(state: State, action: any): State { newResolvingUrls.delete(stream.permanent_url); } - if (channel) { - if (!stream) { - byUri[url] = channel.claim_id; + if (channel && channel.claim_id) { + if (claimsInChannel) { + channelClaimCounts[url] = claimsInChannel; + channelClaimCounts[channel.canonical_url] = claimsInChannel; } + byUri[url] = channel.claim_id; - byId[channel.claim_id] = channel; + if (pendingIds.includes(channel.claim_id)) { + byId[channel.claim_id] = mergeClaim(channel, byId[channel.claim_id]); + } else { + byId[channel.claim_id] = channel; + } // Also add the permanent_url here until lighthouse returns canonical_url for search results byUri[channel.permanent_url] = channel.claim_id; byUri[channel.canonical_url] = channel.claim_id; @@ -198,47 +207,37 @@ reducers[ACTIONS.FETCH_CLAIM_LIST_MINE_COMPLETED] = (state: State, action: any): const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById); + const pendingIds = state.pendingIds || []; let myClaimIds = new Set(state.myClaims); let urlsForCurrentPage = []; + const pendingIdSet = new Set(pendingIds); + claims.forEach((claim: Claim) => { - const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id }); - const { claim_id: claimId } = claim; + const { permanent_url: permanentUri, claim_id: claimId } = claim; if (claim.type && claim.type.match(/claim|update/)) { - urlsForCurrentPage.push(uri); + urlsForCurrentPage.push(permanentUri); if (claim.confirmations < 1) { - pendingById[claimId] = claim; - delete byId[claimId]; - delete byUri[claimId]; + 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]); } else { - byId[claimId] = claim; - byUri[uri] = claimId; + byId[claimId] = claim;// just add } + byUri[permanentUri] = claimId; myClaimIds.add(claimId); - if (!resolve && pendingById[claimId] && claim.confirmations > 0) { - delete pendingById[claimId]; - } } }); - // Remove old pending publishes if resolve if false (resolve=true means confirmations on updates are not 0) - if (!resolve) { - Object.values(pendingById) - // $FlowFixMe - .filter(pendingClaim => byId[pendingClaim.claim_id]) - .forEach(pendingClaim => { - // $FlowFixMe - delete pendingById[pendingClaim.claim_id]; - }); - } - return Object.assign({}, state, { isFetchingClaimListMine: false, myClaims: Array.from(myClaimIds), byId, + pendingIds: Array.from(pendingIdSet), claimsByUri: byUri, - pendingById, myClaimsPageResults: urlsForCurrentPage, myClaimsPageNumber: page, myClaimsPageTotalResults: totalItems, @@ -252,8 +251,9 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St const { claims }: { claims: Array } = action.data; const myClaims = state.myClaims || []; let myClaimIds = new Set(state.myClaims); - const pendingById = Object.assign(state.pendingById); + const pendingIds = state.pendingIds || []; let myChannelClaims; + let myChannelUrls = []; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); const channelClaimCounts = Object.assign({}, state.channelClaimCounts); @@ -261,8 +261,10 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St if (!claims.length) { // $FlowFixMe myChannelClaims = null; + myChannelUrls = null; } else { myChannelClaims = new Set(state.myChannelClaims); + myChannelUrls = []; claims.forEach(claim => { const { meta } = claim; const { claims_in_channel: claimsInChannel } = claim.meta; @@ -275,18 +277,11 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St // $FlowFixMe myChannelClaims.add(claimId); - if (!byId[claimId]) { + if (!pendingIds.some(c => c === claimId)) { byId[claimId] = claim; } - + myChannelUrls.push(permanentUrl); myClaimIds.add(claimId); - if (pendingById[claimId] && claim.confirmations > 0) { - delete pendingById[claimId]; - } - - if (pendingById[claimId] && claim.confirmations > 0) { - delete pendingById[claimId]; - } }); } @@ -296,7 +291,8 @@ reducers[ACTIONS.FETCH_CHANNEL_LIST_COMPLETED] = (state: State, action: any): St channelClaimCounts, fetchingMyChannels: false, myChannelClaims: myChannelClaims ? Array.from(myChannelClaims) : null, - myClaims: Array.from(myClaimIds), + myClaims: myClaimIds ? Array.from(myClaimIds) : null, + myChannelUrls, }); }; @@ -385,19 +381,31 @@ reducers[ACTIONS.ABANDON_CLAIM_STARTED] = (state: State, action: any): State => }; reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => { - const { claims }: { claims: Array } = action.data; + const { claims: pendingClaims }: { claims: Array } = action.data; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById); + const pendingIds = state.pendingIds; + const pendingIdSet = new Set(pendingIds); let myClaimIds = new Set(state.myClaims); + const myChannelClaims = new Set(state.myChannelClaims); // $FlowFixMe - claims.forEach((claim: Claim) => { - const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id }); - const { claim_id: claimId } = claim; - if (claim.type && claim.type.match(/claim|update/)) { - pendingById[claimId] = claim; - delete byId[claimId]; + pendingClaims.forEach((claim: Claim) => { + let newClaim; + const { permanent_url: uri, claim_id: claimId, type, value_type: valueType } = claim; + pendingIdSet.add(claimId); + const oldClaim = byId[claimId]; + if (oldClaim && oldClaim.canonical_url) { + newClaim = mergeClaim(oldClaim, claim); + } else { + newClaim = claim; + } + if (valueType === 'channel') { + myChannelClaims.add(claimId); + } + + if (type && type.match(/claim|update/)) { + byId[claimId] = newClaim; byUri[uri] = claimId; } myClaimIds.add(claimId); @@ -405,32 +413,35 @@ reducers[ACTIONS.UPDATE_PENDING_CLAIMS] = (state: State, action: any): State => return Object.assign({}, state, { myClaims: Array.from(myClaimIds), byId, + myChannelClaims: Array.from(myChannelClaims), claimsByUri: byUri, - pendingById, + pendingIds: Array.from(pendingIdSet), }); }; reducers[ACTIONS.UPDATE_CONFIRMED_CLAIMS] = (state: State, action: any): State => { - const { claims }: { claims: Array } = action.data; + const { claims: confirmedClaims }: { claims: Array } = action.data; const byId = Object.assign({}, state.byId); const byUri = Object.assign({}, state.claimsByUri); - const pendingById: { [string]: Claim } = Object.assign({}, state.pendingById); - let myClaimIds = new Set(state.myClaims); + const pendingIds = state.pendingIds; + const pendingIdSet = new Set(pendingIds); - claims.forEach((claim: GenericClaim) => { - const uri = buildURI({ streamName: claim.name, streamClaimId: claim.claim_id }); - const { claim_id: claimId } = claim; - if (claim.type && claim.type.match(/claim|update/)) { - delete pendingById[claimId]; - byId[claimId] = claim; + confirmedClaims.forEach((claim: GenericClaim) => { + const { permanent_url: permanentUri, claim_id: claimId, type } = claim; + let newClaim = claim; + const oldClaim = byId[claimId]; + if (oldClaim && oldClaim.canonical_url) { + newClaim = mergeClaim(oldClaim, claim); + } + if (type && type.match(/claim|update|channel/)) { + byId[claimId] = newClaim; + pendingIdSet.delete(claimId); } - myClaimIds.add(claimId); }); return Object.assign({}, state, { - myClaims: Array.from(myClaimIds), + pendingIds: Array.from(pendingIdSet), byId, claimsByUri: byUri, - pendingById, }); }; @@ -466,19 +477,7 @@ reducers[ACTIONS.CREATE_CHANNEL_STARTED] = (state: State): State => ({ }); reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state: State, action: any): State => { - const channelClaim: ChannelClaim = action.data.channelClaim; - const byId = Object.assign({}, state.byId); - const pendingById = Object.assign({}, state.pendingById); - const myChannelClaims = new Set(state.myChannelClaims); - - byId[channelClaim.claim_id] = channelClaim; - pendingById[channelClaim.claim_id] = channelClaim; - myChannelClaims.add(channelClaim.claim_id); - return Object.assign({}, state, { - byId, - pendingById, - myChannelClaims: Array.from(myChannelClaims), creatingChannel: false, }); }; @@ -498,13 +497,7 @@ reducers[ACTIONS.UPDATE_CHANNEL_STARTED] = (state: State, action: any): State => }; reducers[ACTIONS.UPDATE_CHANNEL_COMPLETED] = (state: State, action: any): State => { - const channelClaim: ChannelClaim = action.data.channelClaim; - const byId = Object.assign({}, state.byId); - - byId[channelClaim.claim_id] = channelClaim; - return Object.assign({}, state, { - byId, updateChannelError: '', updatingChannel: false, }); diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index e2ced6c..33a1bf3 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -6,7 +6,7 @@ import { } from 'redux/selectors/search'; import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { createSelector } from 'reselect'; -import { isClaimNsfw, createNormalizedClaimSearchKey, filterClaims } from 'util/claim'; +import { isClaimNsfw, filterClaims } from 'util/claim'; import { getSearchQueryString } from 'util/query-params'; import { PAGE_SIZE } from 'constants/claim'; @@ -48,10 +48,9 @@ export const selectRepostError = createSelector( ); export const selectClaimsByUri = createSelector( - selectState, + selectClaimIdsByUri, selectClaimsById, - (state, byId) => { - const byUri = state.claimsByUri || {}; + (byUri, byId) => { const claims = {}; Object.keys(byUri).forEach(uri => { @@ -76,42 +75,25 @@ export const selectAllClaimsByChannel = createSelector( state => state.paginatedClaimsByChannel || {} ); -export const selectPendingById = createSelector( +export const selectPendingIds = createSelector( selectState, - state => state.pendingById || {} -); - -export const selectPendingClaims = createSelector( - selectState, - state => Object.values(state.pendingById || []) + state => state.pendingIds || [] ); export const makeSelectClaimIsPending = (uri: string) => createSelector( - selectPendingById, - pendingById => { - let claimId; - - try { - const { isChannel, channelClaimId, streamClaimId } = parseURI(uri); - claimId = isChannel ? channelClaimId : streamClaimId; - } catch (e) {} + selectClaimIdsByUri, + selectPendingIds, + (idsByUri, pendingIds) => { + const claimId = idsByUri(normalizeURI(uri)); if (claimId) { - return Boolean(pendingById[claimId]); + return pendingIds.some(i => i === claimId); } + return false; } ); -export const makeSelectPendingByUri = (uri: string) => - createSelector( - selectPendingById, - pendingById => { - const { isChannel, channelClaimId, streamClaimId } = parseURI(uri); - const claimId = isChannel ? channelClaimId : streamClaimId; - return pendingById[claimId]; - } - ); export const selectReflectingById = createSelector( selectState, state => state.reflectingById @@ -119,30 +101,21 @@ export const selectReflectingById = createSelector( export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) => createSelector( - selectClaimsByUri, - selectPendingById, - (byUri, pendingById) => { - // Check if a claim is pending first - // It won't be in claimsByUri because resolving it will return nothing - - let valid; + selectClaimIdsByUri, + selectClaimsById, + (byUri, byId) => { + let validUri; let channelClaimId; let streamClaimId; let isChannel; try { ({ isChannel, channelClaimId, streamClaimId } = parseURI(uri)); - valid = true; + validUri = true; } catch (e) {} - if (valid && byUri) { - const claimId = isChannel ? channelClaimId : streamClaimId; - const pendingClaim = pendingById[claimId]; - - if (pendingClaim) { - return pendingClaim; - } - - const claim = byUri[normalizeURI(uri)]; + if (validUri && byUri) { + const claimId = uri && byUri[normalizeURI(uri)]; + const claim = byId[claimId]; if (claim === undefined || claim === null) { // Make sure to return the claim as is so apps can check if it's been resolved before (null) or still needs to be resolved (undefined) return claim; @@ -456,8 +429,7 @@ export const selectMyClaims = createSelector( selectMyActiveClaims, selectClaimsById, selectAbandoningIds, - selectPendingClaims, - (myClaimIds, byId, abandoningIds, pendingClaims) => { + (myClaimIds, byId, abandoningIds) => { const claims = []; myClaimIds.forEach(id => { @@ -466,7 +438,7 @@ export const selectMyClaims = createSelector( if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim); }); - return [...claims, ...pendingClaims]; + return [...claims]; } ); @@ -495,6 +467,11 @@ export const selectMyClaimUrisWithoutChannels = createSelector( } ); +export const selectMyChannelUrls = createSelector( + selectState, + state => state.myChannelUrls +); + export const selectAllMyClaimsByOutpoint = createSelector( selectMyClaimsRaw, claims => diff --git a/src/util/merge-claim.js b/src/util/merge-claim.js new file mode 100644 index 0000000..3ab2976 --- /dev/null +++ b/src/util/merge-claim.js @@ -0,0 +1,7 @@ +/* +new claim = { ...maybeResolvedClaim, ...pendingClaim, meta: maybeResolvedClaim['meta'] } + */ + +export default function mergeClaims(maybeResolved, pending){ + return { ...maybeResolved, ...pending, meta: maybeResolved.meta }; +}