From a0bfbee9585bb847060fc016f70286d289677335 Mon Sep 17 00:00:00 2001 From: infiinte-persistence Date: Sat, 17 Apr 2021 20:50:03 +0800 Subject: [PATCH 1/4] Transaction export: move file-creation to background. --- dist/bundle.es.js | 76 +++++++++++++++++++++++++++++++++++ src/index.js | 1 + src/redux/selectors/wallet.js | 22 ++++++++++ src/util/parse-data.js | 61 ++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 src/util/parse-data.js diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 9474043..c445cdc 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1934,6 +1934,63 @@ 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; @@ -2085,6 +2142,24 @@ 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); @@ -6793,6 +6868,7 @@ 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/src/index.js b/src/index.js index 24ec6fb..d412d83 100644 --- a/src/index.js +++ b/src/index.js @@ -285,6 +285,7 @@ export { selectSupportsByOutpoint, selectTotalSupports, selectTransactionItems, + selectTransactionsFile, selectRecentTransactions, selectHasTransactions, selectIsFetchingTransactions, diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 89316d7..0eb5316 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -2,6 +2,7 @@ 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; @@ -267,6 +268,27 @@ 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 new file mode 100644 index 0000000..83f9a1c --- /dev/null +++ b/src/util/parse-data.js @@ -0,0 +1,61 @@ +// 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; -- 2.45.2 From 864d40bea760158f678ad678bafad28c2ee555c0 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 22 Apr 2021 01:54:54 -0400 Subject: [PATCH 2/4] superchat support --- dist/bundle.es.js | 18 ++++++++++-------- src/redux/actions/wallet.js | 26 ++++++++++++++------------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 9474043..d32a48b 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -3117,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); @@ -3133,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); } }; 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); } }; -- 2.45.2 From b11687e2952771c8d5ec91ff87235d20359027a8 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 22 Apr 2021 14:13:10 -0400 Subject: [PATCH 3/4] remove unused comment types --- dist/flow-typed/Lbry.js | 10 ---------- flow-typed/Lbry.js | 10 ---------- 2 files changed, 20 deletions(-) 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, -- 2.45.2 From c2e03fa71d6f6e09cf551093357df94cd930ae8f Mon Sep 17 00:00:00 2001 From: zeppi Date: Thu, 22 Apr 2021 22:31:08 -0400 Subject: [PATCH 4/4] support claim search async dispatch --- dist/bundle.es.js | 78 ++++++++++++++++++++----------------- src/redux/actions/claims.js | 8 ++-- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index c445cdc..2a9f916 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -4018,44 +4018,52 @@ function doClaimSearch(options = { page: 1 }) { const query = createNormalizedClaimSearchKey(options); - return dispatch => { - dispatch({ - type: CLAIM_SEARCH_STARTED, - data: { query: query } + 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); }); - 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 - } - }); + return function (_x2) { + return _ref2.apply(this, arguments); }; - - 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) { diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index a50c4f6..cd0cb6d 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 (dispatch: Dispatch) => { + return async(dispatch: Dispatch) => { dispatch({ type: ACTIONS.CLAIM_SEARCH_STARTED, data: { query: query }, @@ -618,6 +618,7 @@ export function doClaimSearch( pageSize: options.page_size, }, }); + return true; }; const failure = err => { @@ -626,9 +627,10 @@ export function doClaimSearch( data: { query }, error: err, }); + return false; }; - Lbry.claim_search({ + return await Lbry.claim_search({ ...options, include_purchase_receipt: true, }).then(success, failure); -- 2.45.2