Removes block show and fixes download search selector #139

Merged
jessopb merged 1 commit from removeBlockShowForDates into master 2019-05-07 20:26:12 +02:00
3 changed files with 112 additions and 123 deletions

67
dist/bundle.es.js vendored
View file

@ -50,7 +50,6 @@ const CHECK_ADDRESS_IS_MINE_COMPLETED = 'CHECK_ADDRESS_IS_MINE_COMPLETED';
const SEND_TRANSACTION_STARTED = 'SEND_TRANSACTION_STARTED'; const SEND_TRANSACTION_STARTED = 'SEND_TRANSACTION_STARTED';
const SEND_TRANSACTION_COMPLETED = 'SEND_TRANSACTION_COMPLETED'; const SEND_TRANSACTION_COMPLETED = 'SEND_TRANSACTION_COMPLETED';
const SEND_TRANSACTION_FAILED = 'SEND_TRANSACTION_FAILED'; const SEND_TRANSACTION_FAILED = 'SEND_TRANSACTION_FAILED';
const FETCH_BLOCK_SUCCESS = 'FETCH_BLOCK_SUCCESS';
const SUPPORT_TRANSACTION_STARTED = 'SUPPORT_TRANSACTION_STARTED'; const SUPPORT_TRANSACTION_STARTED = 'SUPPORT_TRANSACTION_STARTED';
const SUPPORT_TRANSACTION_COMPLETED = 'SUPPORT_TRANSACTION_COMPLETED'; const SUPPORT_TRANSACTION_COMPLETED = 'SUPPORT_TRANSACTION_COMPLETED';
const SUPPORT_TRANSACTION_FAILED = 'SUPPORT_TRANSACTION_FAILED'; const SUPPORT_TRANSACTION_FAILED = 'SUPPORT_TRANSACTION_FAILED';
@ -262,7 +261,6 @@ var action_types = /*#__PURE__*/Object.freeze({
SEND_TRANSACTION_STARTED: SEND_TRANSACTION_STARTED, SEND_TRANSACTION_STARTED: SEND_TRANSACTION_STARTED,
SEND_TRANSACTION_COMPLETED: SEND_TRANSACTION_COMPLETED, SEND_TRANSACTION_COMPLETED: SEND_TRANSACTION_COMPLETED,
SEND_TRANSACTION_FAILED: SEND_TRANSACTION_FAILED, SEND_TRANSACTION_FAILED: SEND_TRANSACTION_FAILED,
FETCH_BLOCK_SUCCESS: FETCH_BLOCK_SUCCESS,
SUPPORT_TRANSACTION_STARTED: SUPPORT_TRANSACTION_STARTED, SUPPORT_TRANSACTION_STARTED: SUPPORT_TRANSACTION_STARTED,
SUPPORT_TRANSACTION_COMPLETED: SUPPORT_TRANSACTION_COMPLETED, SUPPORT_TRANSACTION_COMPLETED: SUPPORT_TRANSACTION_COMPLETED,
SUPPORT_TRANSACTION_FAILED: SUPPORT_TRANSACTION_FAILED, SUPPORT_TRANSACTION_FAILED: SUPPORT_TRANSACTION_FAILED,
@ -1233,6 +1231,15 @@ const makeSelectMetadataForUri = uri => reselect.createSelector(makeSelectClaimF
const makeSelectTitleForUri = uri => reselect.createSelector(makeSelectMetadataForUri(uri), metadata => metadata && metadata.title); const makeSelectTitleForUri = uri => reselect.createSelector(makeSelectMetadataForUri(uri), metadata => metadata && metadata.title);
const makeSelectDateForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
const timestamp = claim && claim.timestamp ? claim.timestamp * 1000 : undefined;
if (!timestamp) {
return undefined;
}
const dateObj = new Date(timestamp);
return dateObj;
});
const makeSelectContentTypeForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => { const makeSelectContentTypeForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => {
const source = claim && claim.value && claim.value.source; const source = claim && claim.value && claim.value.source;
return source ? source.media_type : undefined; return source ? source.media_type : undefined;
@ -1510,26 +1517,6 @@ const selectBlocks = reselect.createSelector(selectState$2, state => state.block
const selectCurrentHeight = reselect.createSelector(selectState$2, state => state.latestBlock); const selectCurrentHeight = reselect.createSelector(selectState$2, state => state.latestBlock);
const makeSelectBlockDate = block => reselect.createSelector(selectBlocks, selectCurrentHeight, (blocks, latestBlock) => {
// If we have the block data, look at the actual date,
// If not, try to simulate it based on 2.5 minute blocks
// Adding this on 11/7/2018 because caling block_show for every claim is causing
// performance issues.
if (blocks && blocks[block]) {
return new Date(blocks[block].time * 1000);
}
// Pending claim
if (block < 1) {
return null;
}
const difference = latestBlock - block;
const msSincePublish = difference * 2.5 * 60 * 1000; // Number of blocks * 2.5 minutes in ms
const publishDate = Date.now() - msSincePublish;
return new Date(publishDate);
});
const selectTransactionListFilter = reselect.createSelector(selectState$2, state => state.transactionListFilter || ''); const selectTransactionListFilter = reselect.createSelector(selectState$2, state => state.transactionListFilter || '');
function formatCredits(amount, precision) { function formatCredits(amount, precision) {
@ -1631,17 +1618,6 @@ function doFetchTransactions() {
}; };
} }
function doFetchBlock(height) {
return dispatch => {
lbryProxy.block_show({ height }).then(block => {
dispatch({
type: FETCH_BLOCK_SUCCESS,
data: { block }
});
});
};
}
function doGetNewAddress() { function doGetNewAddress() {
return dispatch => { return dispatch => {
dispatch({ dispatch({
@ -2235,14 +2211,18 @@ const selectSearchDownloadUris = query => reselect.createSelector(selectFileInfo
}); });
return downloadResultsFromQuery.length ? downloadResultsFromQuery.map(fileInfo => { return downloadResultsFromQuery.length ? downloadResultsFromQuery.map(fileInfo => {
const { channel_name: channelName, claim_id: claimId, claim_name: claimName } = fileInfo; const {
channel_name: channelName,
claim_id: claimId,
claim_name: claimName
} = fileInfo;
const uriParams = {}; const uriParams = {};
if (channelName) { if (channelName) {
const claim = claimsById[claimId]; const claim = claimsById[claimId];
if (claim && claim.value) { if (claim && claim.signing_channel) {
uriParams.claimId = claim.value.publisherSignature.certificateId; uriParams.claimId = claim.signing_channel.claim_id;
} else { } else {
uriParams.claimId = claimId; uriParams.claimId = claimId;
} }
@ -3256,18 +3236,6 @@ reducers$2[SUPPORT_TRANSACTION_FAILED] = (state, action) => Object.assign({}, st
sendingSupport: false sendingSupport: false
}); });
reducers$2[FETCH_BLOCK_SUCCESS] = (state, action) => {
const {
block,
block: { height }
} = action.data;
const blocks = Object.assign({}, state.blocks);
blocks[height] = block;
return Object.assign({}, state, { blocks });
};
reducers$2[WALLET_STATUS_COMPLETED] = (state, action) => Object.assign({}, state, { reducers$2[WALLET_STATUS_COMPLETED] = (state, action) => Object.assign({}, state, {
walletIsEncrypted: action.result walletIsEncrypted: action.result
}); });
@ -3442,7 +3410,6 @@ exports.doCreateChannel = doCreateChannel;
exports.doDismissError = doDismissError; exports.doDismissError = doDismissError;
exports.doDismissToast = doDismissToast; exports.doDismissToast = doDismissToast;
exports.doError = doError; exports.doError = doError;
exports.doFetchBlock = doFetchBlock;
exports.doFetchChannelListMine = doFetchChannelListMine; exports.doFetchChannelListMine = doFetchChannelListMine;
exports.doFetchClaimListMine = doFetchClaimListMine; exports.doFetchClaimListMine = doFetchClaimListMine;
exports.doFetchClaimsByChannel = doFetchClaimsByChannel; exports.doFetchClaimsByChannel = doFetchClaimsByChannel;
@ -3478,7 +3445,6 @@ exports.formatFullPrice = formatFullPrice;
exports.isNameValid = isNameValid; exports.isNameValid = isNameValid;
exports.isURIClaimable = isURIClaimable; exports.isURIClaimable = isURIClaimable;
exports.isURIValid = isURIValid; exports.isURIValid = isURIValid;
exports.makeSelectBlockDate = makeSelectBlockDate;
exports.makeSelectChannelForClaimUri = makeSelectChannelForClaimUri; exports.makeSelectChannelForClaimUri = makeSelectChannelForClaimUri;
exports.makeSelectClaimForUri = makeSelectClaimForUri; exports.makeSelectClaimForUri = makeSelectClaimForUri;
exports.makeSelectClaimIsMine = makeSelectClaimIsMine; exports.makeSelectClaimIsMine = makeSelectClaimIsMine;
@ -3489,6 +3455,7 @@ exports.makeSelectClaimsInChannelForPage = makeSelectClaimsInChannelForPage;
exports.makeSelectContentPositionForUri = makeSelectContentPositionForUri; exports.makeSelectContentPositionForUri = makeSelectContentPositionForUri;
exports.makeSelectContentTypeForUri = makeSelectContentTypeForUri; exports.makeSelectContentTypeForUri = makeSelectContentTypeForUri;
exports.makeSelectCoverForUri = makeSelectCoverForUri; exports.makeSelectCoverForUri = makeSelectCoverForUri;
exports.makeSelectDateForUri = makeSelectDateForUri;
exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri; exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri;
exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims; exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims;
exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri; exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri;

View file

@ -31,6 +31,7 @@ declare type GenericClaim = {
decoded_claim: boolean, // claim made in accordance with sdk protobuf types decoded_claim: boolean, // claim made in accordance with sdk protobuf types
depth: number, // confirmations since tx depth: number, // confirmations since tx
effective_amount: number, // bid amount + supports effective_amount: number, // bid amount + supports
timestamp?: number, // date of transaction
has_signature: boolean, has_signature: boolean,
height: number, // block height the tx was confirmed height: number, // block height the tx was confirmed
hex: string, // `value` hex encoded hex: string, // `value` hex encoded

View file

@ -26,11 +26,15 @@ export const selectIsFetchingFileListDownloadedOrPublished = createSelector(
); );
export const makeSelectFileInfoForUri = uri => export const makeSelectFileInfoForUri = uri =>
createSelector(selectClaimsByUri, selectFileInfosByOutpoint, (claims, byOutpoint) => { createSelector(
const claim = claims[uri]; selectClaimsByUri,
const outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined; selectFileInfosByOutpoint,
return outpoint ? byOutpoint[outpoint] : undefined; (claims, byOutpoint) => {
}); const claim = claims[uri];
const outpoint = claim ? `${claim.txid}:${claim.nout}` : undefined;
return outpoint ? byOutpoint[outpoint] : undefined;
}
);
export const selectDownloadingByOutpoint = createSelector( export const selectDownloadingByOutpoint = createSelector(
selectState, selectState,
@ -47,10 +51,16 @@ export const makeSelectDownloadingForUri = uri =>
} }
); );
export const selectUrisLoading = createSelector(selectState, state => state.urisLoading || {}); export const selectUrisLoading = createSelector(
selectState,
state => state.urisLoading || {}
);
export const makeSelectLoadingForUri = uri => export const makeSelectLoadingForUri = uri =>
createSelector(selectUrisLoading, byUri => byUri && byUri[uri]); createSelector(
selectUrisLoading,
byUri => byUri && byUri[uri]
);
export const selectFileInfosDownloaded = createSelector( export const selectFileInfosDownloaded = createSelector(
selectFileInfosByOutpoint, selectFileInfosByOutpoint,
@ -93,93 +103,103 @@ export const selectDownloadingFileInfos = createSelector(
} }
); );
export const selectTotalDownloadProgress = createSelector(selectDownloadingFileInfos, fileInfos => { export const selectTotalDownloadProgress = createSelector(
const progress = []; selectDownloadingFileInfos,
fileInfos => {
const progress = [];
fileInfos.forEach(fileInfo => { fileInfos.forEach(fileInfo => {
progress.push((fileInfo.written_bytes / fileInfo.total_bytes) * 100); progress.push((fileInfo.written_bytes / fileInfo.total_bytes) * 100);
}); });
const totalProgress = progress.reduce((a, b) => a + b, 0); const totalProgress = progress.reduce((a, b) => a + b, 0);
if (fileInfos.length > 0) return totalProgress / fileInfos.length / 100.0; if (fileInfos.length > 0) return totalProgress / fileInfos.length / 100.0;
return -1; return -1;
}); }
);
export const selectSearchDownloadUris = query => export const selectSearchDownloadUris = query =>
createSelector(selectFileInfosDownloaded, selectClaimsById, (fileInfos, claimsById) => { createSelector(
if (!query || !fileInfos.length) { selectFileInfosDownloaded,
return null; selectClaimsById,
} (fileInfos, claimsById) => {
if (!query || !fileInfos.length) {
const queryParts = query.toLowerCase().split(' '); return null;
const searchQueryDictionary = {};
queryParts.forEach(subQuery => {
searchQueryDictionary[subQuery] = subQuery;
});
const arrayContainsQueryPart = array => {
for (let i = 0; i < array.length; i += 1) {
const subQuery = array[i];
if (searchQueryDictionary[subQuery]) {
return true;
}
} }
return false;
};
const downloadResultsFromQuery = []; const queryParts = query.toLowerCase().split(' ');
fileInfos.forEach(fileInfo => { const searchQueryDictionary = {};
const { channel_name: channelName, claim_name: claimName, metadata } = fileInfo; queryParts.forEach(subQuery => {
const { author, description, title } = metadata; searchQueryDictionary[subQuery] = subQuery;
});
if (channelName) { const arrayContainsQueryPart = array => {
const lowerCaseChannel = channelName.toLowerCase(); for (let i = 0; i < array.length; i += 1) {
const strippedOutChannelName = lowerCaseChannel.slice(1); // trim off the @ const subQuery = array[i];
if (searchQueryDictionary[channelName] || searchQueryDictionary[strippedOutChannelName]) { if (searchQueryDictionary[subQuery]) {
return true;
}
}
return false;
};
const downloadResultsFromQuery = [];
fileInfos.forEach(fileInfo => {
const { channel_name: channelName, claim_name: claimName, metadata } = fileInfo;
const { author, description, title } = metadata;
if (channelName) {
const lowerCaseChannel = channelName.toLowerCase();
const strippedOutChannelName = lowerCaseChannel.slice(1); // trim off the @
if (searchQueryDictionary[channelName] || searchQueryDictionary[strippedOutChannelName]) {
downloadResultsFromQuery.push(fileInfo);
return;
}
}
const nameParts = claimName.toLowerCase().split('-');
if (arrayContainsQueryPart(nameParts)) {
downloadResultsFromQuery.push(fileInfo); downloadResultsFromQuery.push(fileInfo);
return; return;
} }
}
const nameParts = claimName.toLowerCase().split('-'); const titleParts = title.toLowerCase().split(' ');
if (arrayContainsQueryPart(nameParts)) { if (arrayContainsQueryPart(titleParts)) {
downloadResultsFromQuery.push(fileInfo);
return;
}
const titleParts = title.toLowerCase().split(' ');
if (arrayContainsQueryPart(titleParts)) {
downloadResultsFromQuery.push(fileInfo);
return;
}
if (author) {
const authorParts = author.toLowerCase().split(' ');
if (arrayContainsQueryPart(authorParts)) {
downloadResultsFromQuery.push(fileInfo); downloadResultsFromQuery.push(fileInfo);
return; return;
} }
}
if (description) { if (author) {
const descriptionParts = description.toLowerCase().split(' '); const authorParts = author.toLowerCase().split(' ');
if (arrayContainsQueryPart(descriptionParts)) { if (arrayContainsQueryPart(authorParts)) {
downloadResultsFromQuery.push(fileInfo); downloadResultsFromQuery.push(fileInfo);
return;
}
} }
}
});
return downloadResultsFromQuery.length if (description) {
? downloadResultsFromQuery.map(fileInfo => { const descriptionParts = description.toLowerCase().split(' ');
const { channel_name: channelName, claim_id: claimId, claim_name: claimName } = fileInfo; if (arrayContainsQueryPart(descriptionParts)) {
downloadResultsFromQuery.push(fileInfo);
}
}
});
return downloadResultsFromQuery.length
? downloadResultsFromQuery.map(fileInfo => {
const {
channel_name: channelName,
claim_id: claimId,
claim_name: claimName,
} = fileInfo;
const uriParams = {}; const uriParams = {};
if (channelName) { if (channelName) {
const claim = claimsById[claimId]; const claim = claimsById[claimId];
if (claim && claim.value) { if (claim && claim.signing_channel) {
uriParams.claimId = claim.value.publisherSignature.certificateId; uriParams.claimId = claim.signing_channel.claim_id;
} else { } else {
uriParams.claimId = claimId; uriParams.claimId = claimId;
} }
@ -193,8 +213,9 @@ export const selectSearchDownloadUris = query =>
const uri = buildURI(uriParams); const uri = buildURI(uriParams);
return uri; return uri;
}) })
: null; : null;
}); }
);
export const selectFileListPublishedSort = createSelector( export const selectFileListPublishedSort = createSelector(
selectState, selectState,