From d6ca449bd97499f93de39445837802e39ca9524c Mon Sep 17 00:00:00 2001 From: zxawry Date: Sun, 11 Aug 2019 17:29:21 +0100 Subject: [PATCH 1/9] add selector for total supports --- src/redux/selectors/wallet.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 654836d..274287d 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -90,6 +90,21 @@ export const selectSupportsByOutpoint = createSelector( state => state.supports || {} ); +export const selectTotalSupports = createSelector( + selectSupportsByOutpoint, + byOutpoint => { + let total = parseFloat("0.0"); + //let total = 0.0; + + Object.values(byOutpoint).forEach(support => { + const { amount } = support; + total = amount ? total + parseFloat(amount) : total; + }); + + return total; + } +); + export const selectTransactionItems = createSelector( selectTransactionsById, byId => { -- 2.45.3 From 79e41150b95efc4a19d4ef05a0a8d8ecefdd5bd1 Mon Sep 17 00:00:00 2001 From: zxawry Date: Sun, 11 Aug 2019 17:29:56 +0100 Subject: [PATCH 2/9] add selector for claim supports --- src/redux/selectors/claims.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index eac3390..082aa31 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -1,6 +1,7 @@ // @flow import { normalizeURI, buildURI, parseURI } from 'lbryURI'; import { selectSearchUrisByQuery } from 'redux/selectors/search'; +import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { createSelector } from 'reselect'; import { isClaimNsfw, createNormalizedClaimSearchKey } from 'util/claim'; import { getSearchQueryString } from 'util/query-params'; @@ -531,3 +532,24 @@ export const makeSelectShortUrlForUri = (uri: string) => makeSelectClaimForUri(uri), claim => claim && claim.short_url ); + +export const makeSelectSupportsForUri = (uri: string) => + createSelector( + selectSupportsByOutpoint, + makeSelectClaimForUri(uri), + (byOutpoint, claim: ?StreamClaim) => { + if (!claim || !claim.is_mine) { + return null; + } + + const { claim_id: claimId } = claim; + let total = parseFloat("0.0"); + + Object.values(byOutpoint).forEach(support => { + const { claim_id, amount } = support + total = (claim_id === claimId && amount) ? total + parseFloat(amount) : total; + }); + + return total; + } + ); -- 2.45.3 From f0edb11ac1ba164d3f3f301fd2746df9fe900959 Mon Sep 17 00:00:00 2001 From: zxawry Date: Sun, 11 Aug 2019 17:30:29 +0100 Subject: [PATCH 3/9] export added selectors --- src/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.js b/src/index.js index 2f93891..a138016 100644 --- a/src/index.js +++ b/src/index.js @@ -173,6 +173,7 @@ export { makeSelectPendingByUri, makeSelectClaimsInChannelForCurrentPageState, makeSelectShortUrlForUri, + makeSelectSupportsForUri, selectPendingById, selectClaimsById, selectClaimsByUri, @@ -245,6 +246,7 @@ export { selectTotalBalance, selectTransactionsById, selectSupportsByOutpoint, + selectTotalSupports, selectTransactionItems, selectRecentTransactions, selectHasTransactions, -- 2.45.3 From 836531d8a24ded1cd6149bfdc2dc40ba8d7f4145 Mon Sep 17 00:00:00 2001 From: zxawry Date: Sun, 11 Aug 2019 17:33:49 +0100 Subject: [PATCH 4/9] cleanup --- src/redux/selectors/wallet.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 274287d..6ca8b77 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -94,7 +94,6 @@ export const selectTotalSupports = createSelector( selectSupportsByOutpoint, byOutpoint => { let total = parseFloat("0.0"); - //let total = 0.0; Object.values(byOutpoint).forEach(support => { const { amount } = support; -- 2.45.3 From 1a3615cddba989703da1fae3925fdac30f1a801c Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Wed, 14 Aug 2019 14:47:57 -0400 Subject: [PATCH 5/9] fix: publish bugs Fixes files being passed on edit + tags not repopulating. --- dist/bundle.es.js | 15 ++++----------- src/redux/actions/publish.js | 11 ++--------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index aeb5956..8cd3dd8 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -3044,7 +3044,8 @@ const doPrepareEdit = (claim, uri, fileInfo, fs) => dispatch => { license, license_url: licenseUrl, thumbnail, - title + title, + tags } = value; const publishData = { @@ -3060,7 +3061,8 @@ const doPrepareEdit = (claim, uri, fileInfo, fs) => dispatch => { uri, uploadThumbnailStatus: thumbnail ? MANUAL : undefined, licenseUrl, - nsfw: isClaimNsfw(claim) + nsfw: isClaimNsfw(claim), + tags: tags ? tags.map(tag => ({ name: tag })) : [] }; // Make sure custom licenses are mapped properly @@ -3082,15 +3084,6 @@ const doPrepareEdit = (claim, uri, fileInfo, fs) => dispatch => { publishData['channel'] = channelName; } - if (fs && fileInfo && fileInfo.download_path) { - try { - fs.accessSync(fileInfo.download_path, fs.constants.R_OK); - publishData.filePath = fileInfo.download_path; - } catch (e) { - console.error(e.name, e.message); - } - } - dispatch({ type: DO_PREPARE_EDIT, data: publishData }); }; diff --git a/src/redux/actions/publish.js b/src/redux/actions/publish.js index 6c23373..5db20c9 100644 --- a/src/redux/actions/publish.js +++ b/src/redux/actions/publish.js @@ -189,6 +189,7 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis license_url: licenseUrl, thumbnail, title, + tags, } = value; const publishData: UpdatePublishFormData = { @@ -205,6 +206,7 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis uploadThumbnailStatus: thumbnail ? THUMBNAIL_STATUSES.MANUAL : undefined, licenseUrl, nsfw: isClaimNsfw(claim), + tags: tags ? tags.map(tag => ({ name: tag })) : [], }; // Make sure custom licenses are mapped properly @@ -226,15 +228,6 @@ export const doPrepareEdit = (claim: StreamClaim, uri: string, fileInfo: FileLis publishData['channel'] = channelName; } - if (fs && fileInfo && fileInfo.download_path) { - try { - fs.accessSync(fileInfo.download_path, fs.constants.R_OK); - publishData.filePath = fileInfo.download_path; - } catch (e) { - console.error(e.name, e.message); - } - } - dispatch({ type: ACTIONS.DO_PREPARE_EDIT, data: publishData }); }; -- 2.45.3 From 6005fa245a888e2de045d7e42411847de7943f52 Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Wed, 14 Aug 2019 18:22:50 -0400 Subject: [PATCH 6/9] fix: streaming + downloads Allows you to download while streaming + re-download already streamed content if it was deleted or settings changed. --- dist/bundle.es.js | 2 +- src/redux/actions/file.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index baa40ce..79ea5d8 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2730,7 +2730,7 @@ function doPurchaseUri(uri, costInfo, saveFile = true, onSuccess) { const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint]; const alreadyStreaming = makeSelectStreamingUrlForUri(uri)(state); - if (alreadyDownloading || alreadyStreaming) { + if (!saveFile && (alreadyDownloading || alreadyStreaming)) { dispatch({ type: PURCHASE_URI_FAILED, data: { uri, error: `Already fetching uri: ${uri}` } diff --git a/src/redux/actions/file.js b/src/redux/actions/file.js index 79d9b99..f6befff 100644 --- a/src/redux/actions/file.js +++ b/src/redux/actions/file.js @@ -95,7 +95,7 @@ export function doPurchaseUri( const alreadyDownloading = fileInfo && !!downloadingByOutpoint[fileInfo.outpoint]; const alreadyStreaming = makeSelectStreamingUrlForUri(uri)(state); - if (alreadyDownloading || alreadyStreaming) { + if (!saveFile && (alreadyDownloading || alreadyStreaming)) { dispatch({ type: ACTIONS.PURCHASE_URI_FAILED, data: { uri, error: `Already fetching uri: ${uri}` }, -- 2.45.3 From 027c517ec653f328eeed2cf509b1062b0f787f22 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 14 Aug 2019 23:47:04 -0400 Subject: [PATCH 7/9] update for 0.38.7 account_balance api changes --- dist/bundle.es.js | 4 ++-- src/redux/actions/wallet.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index baa40ce..049f588 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1750,8 +1750,8 @@ function doUpdateBalance() { const { wallet: { balance: balanceInStore } } = getState(); - lbryProxy.account_balance().then(balanceAsString => { - const balance = parseFloat(balanceAsString); + lbryProxy.account_balance().then(({ available }) => { + const balance = parseFloat(available); if (balanceInStore !== balance) { dispatch({ type: UPDATE_BALANCE, diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index 475436f..8757422 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -10,8 +10,8 @@ export function doUpdateBalance() { const { wallet: { balance: balanceInStore }, } = getState(); - Lbry.account_balance().then(balanceAsString => { - const balance = parseFloat(balanceAsString); + Lbry.account_balance().then(({ available }) => { + const balance = parseFloat(available); if (balanceInStore !== balance) { dispatch({ type: ACTIONS.UPDATE_BALANCE, -- 2.45.3 From 197e55b6390025ad779ea219afe457a902bd6073 Mon Sep 17 00:00:00 2001 From: zxawry Date: Thu, 15 Aug 2019 07:13:50 +0100 Subject: [PATCH 8/9] yarn build --- dist/bundle.es.js | 331 +++++++++++++++++++++++++--------------------- 1 file changed, 180 insertions(+), 151 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 14e4c16..eb98dbd 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1229,6 +1229,156 @@ function doDismissError() { }; } +const selectState$1 = state => state.wallet || {}; + +const selectWalletState = selectState$1; + +const selectWalletIsEncrypted = reselect.createSelector(selectState$1, state => state.walletIsEncrypted); + +const selectWalletEncryptPending = reselect.createSelector(selectState$1, state => state.walletEncryptPending); + +const selectWalletEncryptSucceeded = reselect.createSelector(selectState$1, state => state.walletEncryptSucceded); + +const selectWalletEncryptResult = reselect.createSelector(selectState$1, state => state.walletEncryptResult); + +const selectWalletDecryptPending = reselect.createSelector(selectState$1, state => state.walletDecryptPending); + +const selectWalletDecryptSucceeded = reselect.createSelector(selectState$1, state => state.walletDecryptSucceded); + +const selectWalletDecryptResult = reselect.createSelector(selectState$1, state => state.walletDecryptResult); + +const selectWalletUnlockPending = reselect.createSelector(selectState$1, state => state.walletUnlockPending); + +const selectWalletUnlockSucceeded = reselect.createSelector(selectState$1, state => state.walletUnlockSucceded); + +const selectWalletUnlockResult = reselect.createSelector(selectState$1, state => state.walletUnlockResult); + +const selectWalletLockPending = reselect.createSelector(selectState$1, state => state.walletLockPending); + +const selectWalletLockSucceeded = reselect.createSelector(selectState$1, state => state.walletLockSucceded); + +const selectWalletLockResult = reselect.createSelector(selectState$1, state => state.walletLockResult); + +const selectBalance = reselect.createSelector(selectState$1, state => state.balance); + +const selectTotalBalance = reselect.createSelector(selectState$1, state => state.totalBalance); + +const selectTransactionsById = reselect.createSelector(selectState$1, state => state.transactions || {}); + +const selectSupportsByOutpoint = reselect.createSelector(selectState$1, state => state.supports || {}); + +const selectTotalSupports = reselect.createSelector(selectSupportsByOutpoint, byOutpoint => { + let total = parseFloat("0.0"); + + Object.values(byOutpoint).forEach(support => { + const { amount } = support; + total = amount ? total + parseFloat(amount) : total; + }); + + return total; +}); + +const selectTransactionItems = reselect.createSelector(selectTransactionsById, byId => { + const items = []; + + Object.keys(byId).forEach(txid => { + const tx = byId[txid]; + + // ignore dust/fees + // it is fee only txn if all infos are also empty + if (Math.abs(tx.value) === Math.abs(tx.fee) && tx.claim_info.length === 0 && tx.support_info.length === 0 && tx.update_info.length === 0 && tx.abandon_info.length === 0) { + return; + } + + const append = []; + + append.push(...tx.claim_info.map(item => Object.assign({}, tx, item, { + type: item.claim_name[0] === '@' ? CHANNEL$1 : PUBLISH$1 + }))); + append.push(...tx.support_info.map(item => Object.assign({}, tx, item, { + type: !item.is_tip ? SUPPORT : TIP + }))); + append.push(...tx.update_info.map(item => Object.assign({}, tx, item, { type: UPDATE }))); + append.push(...tx.abandon_info.map(item => Object.assign({}, tx, item, { type: ABANDON }))); + + if (!append.length) { + append.push(Object.assign({}, tx, { + type: tx.value < 0 ? SPEND : RECEIVE + })); + } + + items.push(...append.map(item => { + // value on transaction, amount on outpoint + // amount is always positive, but should match sign of value + const balanceDelta = parseFloat(item.balance_delta); + const value = parseFloat(item.value); + const amount = balanceDelta || value; + const fee = parseFloat(tx.fee); + + return { + txid, + timestamp: tx.timestamp, + date: tx.timestamp ? new Date(Number(tx.timestamp) * 1000) : null, + amount, + fee, + claim_id: item.claim_id, + claim_name: item.claim_name, + type: item.type || SPEND, + nout: item.nout, + confirmations: tx.confirmations + }; + })); + }); + + return items.sort((tx1, tx2) => { + if (!tx1.timestamp && !tx2.timestamp) { + return 0; + } else if (!tx1.timestamp && tx2.timestamp) { + return -1; + } else if (tx1.timestamp && !tx2.timestamp) { + return 1; + } + + return tx2.timestamp - tx1.timestamp; + }); +}); + +const selectRecentTransactions = reselect.createSelector(selectTransactionItems, transactions => { + const threshold = new Date(); + threshold.setDate(threshold.getDate() - 7); + return transactions.filter(transaction => { + if (!transaction.date) { + return true; // pending transaction + } + + return transaction.date > threshold; + }); +}); + +const selectHasTransactions = reselect.createSelector(selectTransactionItems, transactions => transactions && transactions.length > 0); + +const selectIsFetchingTransactions = reselect.createSelector(selectState$1, state => state.fetchingTransactions); + +const selectIsSendingSupport = reselect.createSelector(selectState$1, state => state.sendingSupport); + +const selectReceiveAddress = reselect.createSelector(selectState$1, state => state.receiveAddress); + +const selectGettingNewAddress = reselect.createSelector(selectState$1, state => state.gettingNewAddress); + +const selectDraftTransaction = reselect.createSelector(selectState$1, state => state.draftTransaction || {}); + +const selectDraftTransactionAmount = reselect.createSelector(selectDraftTransaction, draft => draft.amount); + +const selectDraftTransactionAddress = reselect.createSelector(selectDraftTransaction, draft => draft.address); + +const selectDraftTransactionError = reselect.createSelector(selectDraftTransaction, draft => draft.error); + +const selectBlocks = reselect.createSelector(selectState$1, state => state.blocks); + +const selectCurrentHeight = reselect.createSelector(selectState$1, state => state.latestBlock); + +const selectTransactionListFilter = reselect.createSelector(selectState$1, state => state.transactionListFilter || ''); + var _extends$2 = 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(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; } @@ -1265,13 +1415,13 @@ function createNormalizedClaimSearchKey(options) { // -const selectState$1 = state => state.claims || {}; +const selectState$2 = state => state.claims || {}; -const selectClaimsById = reselect.createSelector(selectState$1, state => state.byId || {}); +const selectClaimsById = reselect.createSelector(selectState$2, state => state.byId || {}); -const selectCurrentChannelPage = reselect.createSelector(selectState$1, state => state.currentChannelPage || 1); +const selectCurrentChannelPage = reselect.createSelector(selectState$2, state => state.currentChannelPage || 1); -const selectClaimsByUri = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { +const selectClaimsByUri = reselect.createSelector(selectState$2, selectClaimsById, (state, byId) => { const byUri = state.claimsByUri || {}; const claims = {}; @@ -1291,11 +1441,11 @@ const selectClaimsByUri = reselect.createSelector(selectState$1, selectClaimsByI return claims; }); -const selectAllClaimsByChannel = reselect.createSelector(selectState$1, state => state.claimsByChannel || {}); +const selectAllClaimsByChannel = reselect.createSelector(selectState$2, state => state.claimsByChannel || {}); -const selectPendingById = reselect.createSelector(selectState$1, state => state.pendingById || {}); +const selectPendingById = reselect.createSelector(selectState$2, state => state.pendingById || {}); -const selectPendingClaims = reselect.createSelector(selectState$1, state => Object.values(state.pendingById || [])); +const selectPendingClaims = reselect.createSelector(selectState$2, state => Object.values(state.pendingById || [])); const makeSelectClaimIsPending = uri => reselect.createSelector(selectPendingById, pendingById => { let claimId; @@ -1335,9 +1485,9 @@ const makeSelectClaimForUri = uri => reselect.createSelector(selectClaimsByUri, } }); -const selectMyClaimsRaw = reselect.createSelector(selectState$1, state => state.myClaims); +const selectMyClaimsRaw = reselect.createSelector(selectState$2, state => state.myClaims); -const selectAbandoningIds = reselect.createSelector(selectState$1, state => Object.keys(state.abandoningById || {})); +const selectAbandoningIds = reselect.createSelector(selectState$2, state => Object.keys(state.abandoningById || {})); const selectMyActiveClaims = reselect.createSelector(selectMyClaimsRaw, selectAbandoningIds, (claims, abandoningIds) => new Set(claims && claims.map(claim => claim.claim_id).filter(claimId => Object.keys(abandoningIds).indexOf(claimId) === -1))); @@ -1358,7 +1508,7 @@ const makeSelectClaimIsMine = rawUri => { }); }; -const selectAllFetchingChannelClaims = reselect.createSelector(selectState$1, state => state.fetchingChannelClaims || {}); +const selectAllFetchingChannelClaims = reselect.createSelector(selectState$2, state => state.fetchingChannelClaims || {}); const makeSelectFetchingChannelClaims = uri => reselect.createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]); @@ -1423,7 +1573,7 @@ const makeSelectCoverForUri = uri => reselect.createSelector(makeSelectClaimForU return cover ? cover.url : undefined; }); -const selectIsFetchingClaimListMine = reselect.createSelector(selectState$1, state => state.isFetchingClaimListMine); +const selectIsFetchingClaimListMine = reselect.createSelector(selectState$2, state => state.isFetchingClaimListMine); const selectMyClaims = reselect.createSelector(selectMyActiveClaims, selectClaimsById, selectAbandoningIds, selectPendingClaims, (myClaimIds, byId, abandoningIds, pendingClaims) => { const claims = []; @@ -1459,9 +1609,9 @@ const selectMyClaimsOutpoints = reselect.createSelector(selectMyClaims, myClaims return outpoints; }); -const selectFetchingMyChannels = reselect.createSelector(selectState$1, state => state.fetchingMyChannels); +const selectFetchingMyChannels = reselect.createSelector(selectState$2, state => state.fetchingMyChannels); -const selectMyChannelClaims = reselect.createSelector(selectState$1, selectClaimsById, (state, byId) => { +const selectMyChannelClaims = reselect.createSelector(selectState$2, selectClaimsById, (state, byId) => { const ids = state.myChannelClaims || []; const claims = []; @@ -1475,13 +1625,13 @@ const selectMyChannelClaims = reselect.createSelector(selectState$1, selectClaim return claims; }); -const selectResolvingUris = reselect.createSelector(selectState$1, state => state.resolvingUris || []); +const selectResolvingUris = reselect.createSelector(selectState$2, state => state.resolvingUris || []); const makeSelectIsUriResolving = uri => reselect.createSelector(selectResolvingUris, resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1); -const selectPlayingUri = reselect.createSelector(selectState$1, state => state.playingUri); +const selectPlayingUri = reselect.createSelector(selectState$2, state => state.playingUri); -const selectChannelClaimCounts = reselect.createSelector(selectState$1, state => state.channelClaimCounts || {}); +const selectChannelClaimCounts = reselect.createSelector(selectState$2, state => state.channelClaimCounts || {}); const makeSelectTotalItemsForChannel = uri => reselect.createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]); @@ -1564,153 +1714,30 @@ const makeSelectTagsForUri = uri => reselect.createSelector(makeSelectMetadataFo return metadata && metadata.tags || []; }); -const selectFetchingClaimSearchByQuery = reselect.createSelector(selectState$1, state => state.fetchingClaimSearchByQuery || {}); +const selectFetchingClaimSearchByQuery = reselect.createSelector(selectState$2, state => state.fetchingClaimSearchByQuery || {}); const selectFetchingClaimSearch = reselect.createSelector(selectFetchingClaimSearchByQuery, fetchingClaimSearchByQuery => Boolean(Object.keys(fetchingClaimSearchByQuery).length)); -const selectClaimSearchByQuery = reselect.createSelector(selectState$1, state => state.claimSearchByQuery || {}); +const selectClaimSearchByQuery = reselect.createSelector(selectState$2, state => state.claimSearchByQuery || {}); const makeSelectShortUrlForUri = uri => reselect.createSelector(makeSelectClaimForUri(uri), claim => claim && claim.short_url); -const selectState$2 = state => state.wallet || {}; +const makeSelectSupportsForUri = uri => reselect.createSelector(selectSupportsByOutpoint, makeSelectClaimForUri(uri), (byOutpoint, claim) => { + if (!claim || !claim.is_mine) { + return null; + } -const selectWalletState = selectState$2; + const { claim_id: claimId } = claim; + let total = parseFloat("0.0"); -const selectWalletIsEncrypted = reselect.createSelector(selectState$2, state => state.walletIsEncrypted); - -const selectWalletEncryptPending = reselect.createSelector(selectState$2, state => state.walletEncryptPending); - -const selectWalletEncryptSucceeded = reselect.createSelector(selectState$2, state => state.walletEncryptSucceded); - -const selectWalletEncryptResult = reselect.createSelector(selectState$2, state => state.walletEncryptResult); - -const selectWalletDecryptPending = reselect.createSelector(selectState$2, state => state.walletDecryptPending); - -const selectWalletDecryptSucceeded = reselect.createSelector(selectState$2, state => state.walletDecryptSucceded); - -const selectWalletDecryptResult = reselect.createSelector(selectState$2, state => state.walletDecryptResult); - -const selectWalletUnlockPending = reselect.createSelector(selectState$2, state => state.walletUnlockPending); - -const selectWalletUnlockSucceeded = reselect.createSelector(selectState$2, state => state.walletUnlockSucceded); - -const selectWalletUnlockResult = reselect.createSelector(selectState$2, state => state.walletUnlockResult); - -const selectWalletLockPending = reselect.createSelector(selectState$2, state => state.walletLockPending); - -const selectWalletLockSucceeded = reselect.createSelector(selectState$2, state => state.walletLockSucceded); - -const selectWalletLockResult = reselect.createSelector(selectState$2, state => state.walletLockResult); - -const selectBalance = reselect.createSelector(selectState$2, state => state.balance); - -const selectTotalBalance = reselect.createSelector(selectState$2, state => state.totalBalance); - -const selectTransactionsById = reselect.createSelector(selectState$2, state => state.transactions || {}); - -const selectSupportsByOutpoint = reselect.createSelector(selectState$2, state => state.supports || {}); - -const selectTransactionItems = reselect.createSelector(selectTransactionsById, byId => { - const items = []; - - Object.keys(byId).forEach(txid => { - const tx = byId[txid]; - - // ignore dust/fees - // it is fee only txn if all infos are also empty - if (Math.abs(tx.value) === Math.abs(tx.fee) && tx.claim_info.length === 0 && tx.support_info.length === 0 && tx.update_info.length === 0 && tx.abandon_info.length === 0) { - return; - } - - const append = []; - - append.push(...tx.claim_info.map(item => Object.assign({}, tx, item, { - type: item.claim_name[0] === '@' ? CHANNEL$1 : PUBLISH$1 - }))); - append.push(...tx.support_info.map(item => Object.assign({}, tx, item, { - type: !item.is_tip ? SUPPORT : TIP - }))); - append.push(...tx.update_info.map(item => Object.assign({}, tx, item, { type: UPDATE }))); - append.push(...tx.abandon_info.map(item => Object.assign({}, tx, item, { type: ABANDON }))); - - if (!append.length) { - append.push(Object.assign({}, tx, { - type: tx.value < 0 ? SPEND : RECEIVE - })); - } - - items.push(...append.map(item => { - // value on transaction, amount on outpoint - // amount is always positive, but should match sign of value - const balanceDelta = parseFloat(item.balance_delta); - const value = parseFloat(item.value); - const amount = balanceDelta || value; - const fee = parseFloat(tx.fee); - - return { - txid, - timestamp: tx.timestamp, - date: tx.timestamp ? new Date(Number(tx.timestamp) * 1000) : null, - amount, - fee, - claim_id: item.claim_id, - claim_name: item.claim_name, - type: item.type || SPEND, - nout: item.nout, - confirmations: tx.confirmations - }; - })); + Object.values(byOutpoint).forEach(support => { + const { claim_id, amount } = support; + total = claim_id === claimId && amount ? total + parseFloat(amount) : total; }); - return items.sort((tx1, tx2) => { - if (!tx1.timestamp && !tx2.timestamp) { - return 0; - } else if (!tx1.timestamp && tx2.timestamp) { - return -1; - } else if (tx1.timestamp && !tx2.timestamp) { - return 1; - } - - return tx2.timestamp - tx1.timestamp; - }); + return total; }); -const selectRecentTransactions = reselect.createSelector(selectTransactionItems, transactions => { - const threshold = new Date(); - threshold.setDate(threshold.getDate() - 7); - return transactions.filter(transaction => { - if (!transaction.date) { - return true; // pending transaction - } - - return transaction.date > threshold; - }); -}); - -const selectHasTransactions = reselect.createSelector(selectTransactionItems, transactions => transactions && transactions.length > 0); - -const selectIsFetchingTransactions = reselect.createSelector(selectState$2, state => state.fetchingTransactions); - -const selectIsSendingSupport = reselect.createSelector(selectState$2, state => state.sendingSupport); - -const selectReceiveAddress = reselect.createSelector(selectState$2, state => state.receiveAddress); - -const selectGettingNewAddress = reselect.createSelector(selectState$2, state => state.gettingNewAddress); - -const selectDraftTransaction = reselect.createSelector(selectState$2, state => state.draftTransaction || {}); - -const selectDraftTransactionAmount = reselect.createSelector(selectDraftTransaction, draft => draft.amount); - -const selectDraftTransactionAddress = reselect.createSelector(selectDraftTransaction, draft => draft.address); - -const selectDraftTransactionError = reselect.createSelector(selectDraftTransaction, draft => draft.error); - -const selectBlocks = reselect.createSelector(selectState$2, state => state.blocks); - -const selectCurrentHeight = reselect.createSelector(selectState$2, state => state.latestBlock); - -const selectTransactionListFilter = reselect.createSelector(selectState$2, state => state.transactionListFilter || ''); - function formatCredits(amount, precision) { if (Number.isNaN(parseFloat(amount))) return '0'; return parseFloat(amount).toFixed(precision || 1).replace(/\.?0+$/, ''); @@ -4859,6 +4886,7 @@ exports.makeSelectRecommendedContentForUri = makeSelectRecommendedContentForUri; exports.makeSelectSearchUris = makeSelectSearchUris; exports.makeSelectShortUrlForUri = makeSelectShortUrlForUri; exports.makeSelectStreamingUrlForUri = makeSelectStreamingUrlForUri; +exports.makeSelectSupportsForUri = makeSelectSupportsForUri; exports.makeSelectTagsForUri = makeSelectTagsForUri; exports.makeSelectThumbnailForUri = makeSelectThumbnailForUri; exports.makeSelectTitleForUri = makeSelectTitleForUri; @@ -4945,6 +4973,7 @@ exports.selectTakeOverAmount = selectTakeOverAmount; exports.selectToast = selectToast; exports.selectTotalBalance = selectTotalBalance; exports.selectTotalDownloadProgress = selectTotalDownloadProgress; +exports.selectTotalSupports = selectTotalSupports; exports.selectTransactionItems = selectTransactionItems; exports.selectTransactionListFilter = selectTransactionListFilter; exports.selectTransactionsById = selectTransactionsById; -- 2.45.3 From 22dc431ee0230e9b7455f6f7a1eaebdf93dab439 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Fri, 16 Aug 2019 01:16:04 -0400 Subject: [PATCH 9/9] remove mime --- dist/bundle.es.js | 36 +++++++++++++------------------- flow-typed/mime.js | 4 ---- package.json | 1 - src/lbry.js | 51 +++++++++++++++++++--------------------------- yarn.lock | 5 ----- 5 files changed, 35 insertions(+), 62 deletions(-) delete mode 100644 flow-typed/mime.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index baa40ce..fbd32c8 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true }); function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } require('proxy-polyfill'); -var mime = _interopDefault(require('mime')); var reselect = require('reselect'); var uuid = _interopDefault(require('uuid/v4')); @@ -692,29 +691,22 @@ const Lbry = { // Returns a human readable media type based on the content type or extension of a file that is returned by the sdk getMediaType: (contentType, fileName) => { - const formats = [[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/\.(cbr|cbt|cbz)$/i, 'comic-book']]; + if (fileName) { + const formats = [[/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], [/\.(cbr|cbt|cbz)$/i, 'comic-book']]; - const extName = mime.getExtension(contentType); - const fileExt = extName ? `.${extName}` : null; - const testString = fileName || fileExt; - - // Get mediaType from file extension - if (testString) { const res = formats.reduce((ret, testpair) => { - const [regex, mediaType] = testpair; - - return regex.test(ret) ? mediaType : ret; - }, testString); - - if (res !== testString) return res; - } - - // Get mediaType from contentType - if (contentType) { - const matches = /^[^/]+/.exec(contentType); - if (matches) { - return matches[0]; - } + switch (testpair[0].test(ret)) { + case true: + return testpair[1]; + default: + return ret; + } + }, fileName); + return res === fileName ? 'unknown' : res; + } else if (contentType) { + // $FlowFixMe + return (/^[^/]+/.exec(contentType)[0] + ); } return 'unknown'; diff --git a/flow-typed/mime.js b/flow-typed/mime.js deleted file mode 100644 index 476b179..0000000 --- a/flow-typed/mime.js +++ /dev/null @@ -1,4 +0,0 @@ -// @flow -declare module 'mime' { - declare module.exports: any; -} diff --git a/package.json b/package.json index 8cba56d..21b595f 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "format": "prettier 'src/**/*.{js,json}' --write" }, "dependencies": { - "mime": "^2.4.4", "proxy-polyfill": "0.1.6", "reselect": "^3.0.0", "uuid": "^3.3.2" diff --git a/src/lbry.js b/src/lbry.js index b87a8a2..6313063 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -1,6 +1,5 @@ // @flow import 'proxy-polyfill'; -import mime from 'mime'; const CHECK_DAEMON_STARTED_TRY_NUMBER = 200; // @@ -34,37 +33,29 @@ const Lbry: LbryTypes = { // Returns a human readable media type based on the content type or extension of a file that is returned by the sdk getMediaType: (contentType?: string, fileName: ?string) => { - const formats = [ - [/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], - [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], - [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], - [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], - [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], - [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], - [/\.(cbr|cbt|cbz)$/i, 'comic-book'], - ]; + if (fileName) { + const formats = [ + [/\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'], + [/\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'], + [/\.(h|go|ja|java|js|jsx|c|cpp|cs|css|rb|scss|sh|php|py)$/i, 'script'], + [/\.(json|csv|txt|log|md|markdown|docx|pdf|xml|yml|yaml)$/i, 'document'], + [/\.(pdf|odf|doc|docx|epub|org|rtf)$/i, 'e-book'], + [/\.(stl|obj|fbx|gcode)$/i, '3D-file'], + [/\.(cbr|cbt|cbz)$/i, 'comic-book'], + ]; - const extName = mime.getExtension(contentType); - const fileExt = extName ? `.${extName}` : null; - const testString = fileName || fileExt; - - // Get mediaType from file extension - if (testString) { const res = formats.reduce((ret, testpair) => { - const [regex, mediaType] = testpair; - - return regex.test(ret) ? mediaType : ret; - }, testString); - - if (res !== testString) return res; - } - - // Get mediaType from contentType - if (contentType) { - const matches = /^[^/]+/.exec(contentType); - if (matches) { - return matches[0]; - } + switch (testpair[0].test(ret)) { + case true: + return testpair[1]; + default: + return ret; + } + }, fileName); + return res === fileName ? 'unknown' : res; + } else if (contentType) { + // $FlowFixMe + return /^[^/]+/.exec(contentType)[0]; } return 'unknown'; diff --git a/yarn.lock b/yarn.lock index 182afdc..49dc513 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3523,11 +3523,6 @@ mime-types@^2.1.12, mime-types@~2.1.17: dependencies: mime-db "~1.33.0" -mime@^2.4.4: - version "2.4.4" - resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.4.tgz#bd7b91135fc6b01cde3e9bae33d659b63d8857e5" - integrity sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA== - mimic-fn@^1.0.0: version "1.2.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" -- 2.45.3