diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 2a9f916..d32a48b 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1934,63 +1934,6 @@ function doDismissError() { }; } -// JSON parser -const parseJson = (data, filters = []) => { - const list = data.map(item => { - const temp = {}; - // Apply filters - Object.entries(item).forEach(([key, value]) => { - if (!filters.includes(key)) temp[key] = value; - }); - return temp; - }); - // Beautify JSON - return JSON.stringify(list, null, '\t'); -}; - -// CSV Parser -// No need for an external module: -// https://gist.github.com/btzr-io/55c3450ea3d709fc57540e762899fb85 -const parseCsv = (data, filters = []) => { - // Get items for header - const getHeaders = item => { - const list = []; - // Apply filters - Object.entries(item).forEach(([key]) => { - if (!filters.includes(key)) list.push(key); - }); - // return headers - return list.join(','); - }; - - // Get rows content - const getData = list => list.map(item => { - const row = []; - // Apply filters - Object.entries(item).forEach(([key, value]) => { - if (!filters.includes(key)) row.push(value); - }); - // return rows - return row.join(','); - }).join('\n'); - - // Return CSV string - return `${getHeaders(data[0])} \n ${getData(data)}`; -}; - -const parseData = (data, format, filters = []) => { - // Check for validation - const valid = data && data[0] && format; - // Pick a format - const formats = { - csv: list => parseCsv(list, filters), - json: list => parseJson(list, filters) - }; - - // Return parsed data: JSON || CSV - return valid && formats[format] ? formats[format](data) : undefined; -}; - const selectState = state => state.wallet || {}; const selectWalletState = selectState; @@ -2142,24 +2085,6 @@ const selectHasTransactions = reselect.createSelector(selectTransactionItems, tr const selectIsFetchingTransactions = reselect.createSelector(selectState, state => state.fetchingTransactions); -/** - * CSV of 'selectTransactionItems'. - */ -const selectTransactionsFile = reselect.createSelector(selectTransactionItems, transactions => { - if (!transactions || transactions.length === 0) { - // No data. - return undefined; - } - - const parsed = parseData(transactions, 'csv'); - if (!parsed) { - // Invalid data, or failed to parse. - return null; - } - - return parsed; -}); - const selectIsSendingSupport = reselect.createSelector(selectState, state => state.sendingSupport); const selectReceiveAddress = reselect.createSelector(selectState, state => state.receiveAddress); @@ -3192,7 +3117,7 @@ function doSetDraftTransactionAddress(address) { }; } -function doSendTip(params, isSupport, successCallback, errorCallback) { +function doSendTip(params, isSupport, successCallback, errorCallback, shouldNotify = true) { return (dispatch, getState) => { const state = getState(); const balance = selectBalance(state); @@ -3208,19 +3133,21 @@ function doSendTip(params, isSupport, successCallback, errorCallback) { return; } - const success = () => { - dispatch(doToast({ - message: shouldSupport ? __('You deposited %amount% LBRY Credits as a support!', { amount: params.amount }) : __('You sent %amount% LBRY Credits as a tip, Mahalo!', { amount: params.amount }), - linkText: __('History'), - linkTarget: '/wallet' - })); + const success = response => { + if (shouldNotify) { + dispatch(doToast({ + message: shouldSupport ? __('You deposited %amount% LBRY Credits as a support!', { amount: params.amount }) : __('You sent %amount% LBRY Credits as a tip, Mahalo!', { amount: params.amount }), + linkText: __('History'), + linkTarget: '/wallet' + })); + } dispatch({ type: SUPPORT_TRANSACTION_COMPLETED }); if (successCallback) { - successCallback(); + successCallback(response); } }; @@ -4018,52 +3945,44 @@ function doClaimSearch(options = { page: 1 }) { const query = createNormalizedClaimSearchKey(options); - return (() => { - var _ref2 = _asyncToGenerator$1(function* (dispatch) { - dispatch({ - type: CLAIM_SEARCH_STARTED, - data: { query: query } - }); - - const success = function (data) { - const resolveInfo = {}; - const urls = []; - data.items.forEach(function (stream) { - resolveInfo[stream.canonical_url] = { stream }; - urls.push(stream.canonical_url); - }); - - dispatch({ - type: CLAIM_SEARCH_COMPLETED, - data: { - query, - resolveInfo, - urls, - append: options.page && options.page !== 1, - pageSize: options.page_size - } - }); - return true; - }; - - const failure = function (err) { - dispatch({ - type: CLAIM_SEARCH_FAILED, - data: { query }, - error: err - }); - return false; - }; - - return yield lbryProxy.claim_search(_extends$5({}, options, { - include_purchase_receipt: true - })).then(success, failure); + return dispatch => { + dispatch({ + type: CLAIM_SEARCH_STARTED, + data: { query: query } }); - return function (_x2) { - return _ref2.apply(this, arguments); + const success = data => { + const resolveInfo = {}; + const urls = []; + data.items.forEach(stream => { + resolveInfo[stream.canonical_url] = { stream }; + urls.push(stream.canonical_url); + }); + + dispatch({ + type: CLAIM_SEARCH_COMPLETED, + data: { + query, + resolveInfo, + urls, + append: options.page && options.page !== 1, + pageSize: options.page_size + } + }); }; - })(); + + const failure = err => { + dispatch({ + type: CLAIM_SEARCH_FAILED, + data: { query }, + error: err + }); + }; + + lbryProxy.claim_search(_extends$5({}, options, { + include_purchase_receipt: true + })).then(success, failure); + }; } function doRepost(options) { @@ -6876,7 +6795,6 @@ exports.selectTotalSupports = selectTotalSupports; exports.selectTransactionItems = selectTransactionItems; exports.selectTransactionListFilter = selectTransactionListFilter; exports.selectTransactionsById = selectTransactionsById; -exports.selectTransactionsFile = selectTransactionsFile; exports.selectTxoItemCount = selectTxoItemCount; exports.selectTxoPage = selectTxoPage; exports.selectTxoPageNumber = selectTxoPageNumber; diff --git a/dist/flow-typed/Lbry.js b/dist/flow-typed/Lbry.js index 326b3c6..0225fa2 100644 --- a/dist/flow-typed/Lbry.js +++ b/dist/flow-typed/Lbry.js @@ -124,14 +124,6 @@ declare type ChannelUpdateResponse = GenericTxResponse & { declare type CommentCreateResponse = Comment; declare type CommentUpdateResponse = Comment; -declare type CommentListResponse = { - items: Array, - page: number, - page_size: number, - total_items: number, - total_pages: number, -}; - declare type MyReactions = { // Keys are the commentId [string]: Array, @@ -308,8 +300,6 @@ declare type LbryTypes = { preference_set: (params: {}) => Promise, // Commenting - comment_list: (params: {}) => Promise, - comment_create: (params: {}) => Promise, comment_update: (params: {}) => Promise, comment_hide: (params: {}) => Promise, comment_abandon: (params: {}) => Promise, diff --git a/flow-typed/Lbry.js b/flow-typed/Lbry.js index 326b3c6..0225fa2 100644 --- a/flow-typed/Lbry.js +++ b/flow-typed/Lbry.js @@ -124,14 +124,6 @@ declare type ChannelUpdateResponse = GenericTxResponse & { declare type CommentCreateResponse = Comment; declare type CommentUpdateResponse = Comment; -declare type CommentListResponse = { - items: Array, - page: number, - page_size: number, - total_items: number, - total_pages: number, -}; - declare type MyReactions = { // Keys are the commentId [string]: Array, @@ -308,8 +300,6 @@ declare type LbryTypes = { preference_set: (params: {}) => Promise, // Commenting - comment_list: (params: {}) => Promise, - comment_create: (params: {}) => Promise, comment_update: (params: {}) => Promise, comment_hide: (params: {}) => Promise, comment_abandon: (params: {}) => Promise, diff --git a/src/index.js b/src/index.js index d412d83..24ec6fb 100644 --- a/src/index.js +++ b/src/index.js @@ -285,7 +285,6 @@ export { selectSupportsByOutpoint, selectTotalSupports, selectTransactionItems, - selectTransactionsFile, selectRecentTransactions, selectHasTransactions, selectIsFetchingTransactions, diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index cd0cb6d..a50c4f6 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -65,7 +65,7 @@ export function doResolveUris( } = {}; return Lbry.resolve({ urls: urisToResolve, ...options }).then( - async(result: ResolveResponse) => { + async (result: ResolveResponse) => { let repostedResults = {}; const repostsToResolve = []; const fallbackResolveInfo = { @@ -594,7 +594,7 @@ export function doClaimSearch( } ) { const query = createNormalizedClaimSearchKey(options); - return async(dispatch: Dispatch) => { + return (dispatch: Dispatch) => { dispatch({ type: ACTIONS.CLAIM_SEARCH_STARTED, data: { query: query }, @@ -618,7 +618,6 @@ export function doClaimSearch( pageSize: options.page_size, }, }); - return true; }; const failure = err => { @@ -627,10 +626,9 @@ export function doClaimSearch( data: { query }, error: err, }); - return false; }; - return await Lbry.claim_search({ + Lbry.claim_search({ ...options, include_purchase_receipt: true, }).then(success, failure); diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index 8d73e90..97254df 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -349,7 +349,7 @@ export function doSetDraftTransactionAddress(address) { }; } -export function doSendTip(params, isSupport, successCallback, errorCallback) { +export function doSendTip(params, isSupport, successCallback, errorCallback, shouldNotify = true) { return (dispatch, getState) => { const state = getState(); const balance = selectBalance(state); @@ -368,23 +368,25 @@ export function doSendTip(params, isSupport, successCallback, errorCallback) { return; } - const success = () => { - dispatch( - doToast({ - message: shouldSupport - ? __('You deposited %amount% LBRY Credits as a support!', { amount: params.amount }) - : __('You sent %amount% LBRY Credits as a tip, Mahalo!', { amount: params.amount }), - linkText: __('History'), - linkTarget: '/wallet', - }) - ); + const success = response => { + if (shouldNotify) { + dispatch( + doToast({ + message: shouldSupport + ? __('You deposited %amount% LBRY Credits as a support!', { amount: params.amount }) + : __('You sent %amount% LBRY Credits as a tip, Mahalo!', { amount: params.amount }), + linkText: __('History'), + linkTarget: '/wallet', + }) + ); + } dispatch({ type: ACTIONS.SUPPORT_TRANSACTION_COMPLETED, }); if (successCallback) { - successCallback(); + successCallback(response); } }; diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 0eb5316..89316d7 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -2,7 +2,6 @@ import { createSelector } from 'reselect'; import * as TRANSACTIONS from 'constants/transaction_types'; import { PAGE_SIZE, LATEST_PAGE_SIZE } from 'constants/transaction_list'; import { selectClaimIdsByUri } from 'redux/selectors/claims'; -import parseData from 'util/parse-data'; export const selectState = state => state.wallet || {}; export const selectWalletState = selectState; @@ -268,27 +267,6 @@ export const selectIsFetchingTransactions = createSelector( state => state.fetchingTransactions ); -/** - * CSV of 'selectTransactionItems'. - */ -export const selectTransactionsFile = createSelector( - selectTransactionItems, - transactions => { - if (!transactions || transactions.length === 0) { - // No data. - return undefined; - } - - const parsed = parseData(transactions, 'csv'); - if (!parsed) { - // Invalid data, or failed to parse. - return null; - } - - return parsed; - } -); - export const selectIsSendingSupport = createSelector( selectState, state => state.sendingSupport diff --git a/src/util/parse-data.js b/src/util/parse-data.js deleted file mode 100644 index 83f9a1c..0000000 --- a/src/util/parse-data.js +++ /dev/null @@ -1,61 +0,0 @@ -// JSON parser -const parseJson = (data, filters = []) => { - const list = data.map(item => { - const temp = {}; - // Apply filters - Object.entries(item).forEach(([key, value]) => { - if (!filters.includes(key)) temp[key] = value; - }); - return temp; - }); - // Beautify JSON - return JSON.stringify(list, null, '\t'); -}; - -// CSV Parser -// No need for an external module: -// https://gist.github.com/btzr-io/55c3450ea3d709fc57540e762899fb85 -const parseCsv = (data, filters = []) => { - // Get items for header - const getHeaders = item => { - const list = []; - // Apply filters - Object.entries(item).forEach(([key]) => { - if (!filters.includes(key)) list.push(key); - }); - // return headers - return list.join(','); - }; - - // Get rows content - const getData = list => - list - .map(item => { - const row = []; - // Apply filters - Object.entries(item).forEach(([key, value]) => { - if (!filters.includes(key)) row.push(value); - }); - // return rows - return row.join(','); - }) - .join('\n'); - - // Return CSV string - return `${getHeaders(data[0])} \n ${getData(data)}`; -}; - -const parseData = (data, format, filters = []) => { - // Check for validation - const valid = data && data[0] && format; - // Pick a format - const formats = { - csv: list => parseCsv(list, filters), - json: list => parseJson(list, filters), - }; - - // Return parsed data: JSON || CSV - return valid && formats[format] ? formats[format](data) : undefined; -}; - -export default parseData;