From 3aee3683ef3d20aeb06a2db8c8240f89c2b00765 Mon Sep 17 00:00:00 2001 From: zeppi Date: Wed, 27 Jan 2021 10:01:55 -0500 Subject: [PATCH] support mass claiming tips --- dist/bundle.es.js | 65 +++++++++++++++++++++++++++++++---- src/constants/action_types.js | 3 ++ src/index.js | 2 ++ src/redux/actions/wallet.js | 28 ++++++++++++--- src/redux/reducers/wallet.js | 22 ++++++++++++ src/redux/selectors/wallet.js | 5 +++ 6 files changed, 115 insertions(+), 10 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 09c7c98..bd73933 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -103,6 +103,9 @@ const SET_DRAFT_TRANSACTION_ADDRESS = 'SET_DRAFT_TRANSACTION_ADDRESS'; const FETCH_UTXO_COUNT_STARTED = 'FETCH_UTXO_COUNT_STARTED'; const FETCH_UTXO_COUNT_COMPLETED = 'FETCH_UTXO_COUNT_COMPLETED'; const FETCH_UTXO_COUNT_FAILED = 'FETCH_UTXO_COUNT_FAILED'; +const TIP_CLAIM_MASS_STARTED = 'TIP_CLAIM_MASS_STARTED'; +const TIP_CLAIM_MASS_COMPLETED = 'TIP_CLAIM_MASS_COMPLETED'; +const TIP_CLAIM_MASS_FAILED = 'TIP_CLAIM_MASS_FAILED'; const DO_UTXO_CONSOLIDATE_STARTED = 'DO_UTXO_CONSOLIDATE_STARTED'; const DO_UTXO_CONSOLIDATE_COMPLETED = 'DO_UTXO_CONSOLIDATE_COMPLETED'; const DO_UTXO_CONSOLIDATE_FAILED = 'DO_UTXO_CONSOLIDATE_FAILED'; @@ -377,6 +380,9 @@ var action_types = /*#__PURE__*/Object.freeze({ FETCH_UTXO_COUNT_STARTED: FETCH_UTXO_COUNT_STARTED, FETCH_UTXO_COUNT_COMPLETED: FETCH_UTXO_COUNT_COMPLETED, FETCH_UTXO_COUNT_FAILED: FETCH_UTXO_COUNT_FAILED, + TIP_CLAIM_MASS_STARTED: TIP_CLAIM_MASS_STARTED, + TIP_CLAIM_MASS_COMPLETED: TIP_CLAIM_MASS_COMPLETED, + TIP_CLAIM_MASS_FAILED: TIP_CLAIM_MASS_FAILED, DO_UTXO_CONSOLIDATE_STARTED: DO_UTXO_CONSOLIDATE_STARTED, DO_UTXO_CONSOLIDATE_COMPLETED: DO_UTXO_CONSOLIDATE_COMPLETED, DO_UTXO_CONSOLIDATE_FAILED: DO_UTXO_CONSOLIDATE_FAILED, @@ -2120,6 +2126,8 @@ const selectIsFetchingUtxoCounts = reselect.createSelector(selectState, state => const selectIsConsolidatingUtxos = reselect.createSelector(selectState, state => state.consolidatingUtxos); +const selectIsMassClaimingTips = reselect.createSelector(selectState, state => state.massClaimingTips); + const selectUtxoCounts = reselect.createSelector(selectState, state => state.utxoCounts); 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; }; @@ -2832,15 +2840,12 @@ function doFetchUtxoCounts() { type: FETCH_UTXO_COUNT_STARTED }); - let resultSets = yield Promise.all([lbryProxy.txo_list({ type: 'other', is_not_spent: true, page: 1, page_size: 1 })] - // removing until we figure out sdk load / need it - // Lbry.txo_list({ type: 'support', is_not_spent: true }), - ); + let resultSets = yield Promise.all([lbryProxy.txo_list({ type: 'other', is_not_spent: true, page: 1, page_size: 1 }), lbryProxy.txo_list({ type: 'support', is_not_spent: true, page: 1, page_size: 1 })]); const counts = {}; const paymentCount = resultSets[0]['total_items']; - // const supportCount = resultSets[1]['total_items']; + const supportCount = resultSets[1]['total_items']; counts['other'] = typeof paymentCount === 'number' ? paymentCount : 0; - counts['support'] = 0; + counts['support'] = typeof supportCount === 'number' ? supportCount : 0; dispatch({ type: FETCH_UTXO_COUNT_COMPLETED, @@ -2882,6 +2887,33 @@ function doUtxoConsolidate() { })(); } +function doTipClaimMass() { + return (() => { + var _ref3 = _asyncToGenerator(function* (dispatch) { + dispatch({ + type: TIP_CLAIM_MASS_STARTED + }); + + const results = yield lbryProxy.txo_spend({ type: 'support', is_not_my_input: true }); + const result = results[0]; + + dispatch({ + type: PENDING_CONSOLIDATED_TXOS_UPDATED, + data: { txids: [result.txid] } + }); + + dispatch({ + type: TIP_CLAIM_MASS_COMPLETED + }); + dispatch(doCheckPendingTxs()); + }); + + return function (_x3) { + return _ref3.apply(this, arguments); + }; + })(); +} + function doGetNewAddress() { return dispatch => { dispatch({ @@ -5957,6 +5989,7 @@ const defaultState$5 = { fetchingUtxoCounts: false, fetchingUtxoError: undefined, consolidatingUtxos: false, + massClaimingTips: false, txoPage: {}, fetchingTxos: false, fetchingTxosError: undefined, @@ -6044,6 +6077,24 @@ const walletReducer = handleActions({ }); }, + [TIP_CLAIM_MASS_STARTED]: state => { + return _extends$d({}, state, { + massClaimingTips: true + }); + }, + + [TIP_CLAIM_MASS_COMPLETED]: (state, action) => { + return _extends$d({}, state, { + massClaimingTips: false + }); + }, + + [TIP_CLAIM_MASS_FAILED]: (state, action) => { + return _extends$d({}, state, { + massClaimingTips: false + }); + }, + [PENDING_CONSOLIDATED_TXOS_UPDATED]: (state, action) => { const pendingTxos = state.pendingConsolidateTxos; @@ -6429,6 +6480,7 @@ exports.doSetDraftTransactionAmount = doSetDraftTransactionAmount; exports.doSetFileListSort = doSetFileListSort; exports.doSetTransactionListFilter = doSetTransactionListFilter; exports.doSupportAbandonForClaim = doSupportAbandonForClaim; +exports.doTipClaimMass = doTipClaimMass; exports.doToast = doToast; exports.doUpdateBalance = doUpdateBalance; exports.doUpdateBlockHeight = doUpdateBlockHeight; @@ -6562,6 +6614,7 @@ exports.selectIsFetchingMyPurchases = selectIsFetchingMyPurchases; exports.selectIsFetchingTransactions = selectIsFetchingTransactions; exports.selectIsFetchingTxos = selectIsFetchingTxos; exports.selectIsFetchingUtxoCounts = selectIsFetchingUtxoCounts; +exports.selectIsMassClaimingTips = selectIsMassClaimingTips; exports.selectIsResolvingPublishUris = selectIsResolvingPublishUris; exports.selectIsSendingSupport = selectIsSendingSupport; exports.selectIsStillEditing = selectIsStillEditing; diff --git a/src/constants/action_types.js b/src/constants/action_types.js index bdd4273..5e3f672 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -82,6 +82,9 @@ export const SET_DRAFT_TRANSACTION_ADDRESS = 'SET_DRAFT_TRANSACTION_ADDRESS'; export const FETCH_UTXO_COUNT_STARTED = 'FETCH_UTXO_COUNT_STARTED'; export const FETCH_UTXO_COUNT_COMPLETED = 'FETCH_UTXO_COUNT_COMPLETED'; export const FETCH_UTXO_COUNT_FAILED = 'FETCH_UTXO_COUNT_FAILED'; +export const TIP_CLAIM_MASS_STARTED = 'TIP_CLAIM_MASS_STARTED'; +export const TIP_CLAIM_MASS_COMPLETED = 'TIP_CLAIM_MASS_COMPLETED'; +export const TIP_CLAIM_MASS_FAILED = 'TIP_CLAIM_MASS_FAILED'; export const DO_UTXO_CONSOLIDATE_STARTED = 'DO_UTXO_CONSOLIDATE_STARTED'; export const DO_UTXO_CONSOLIDATE_COMPLETED = 'DO_UTXO_CONSOLIDATE_COMPLETED'; export const DO_UTXO_CONSOLIDATE_FAILED = 'DO_UTXO_CONSOLIDATE_FAILED'; diff --git a/src/index.js b/src/index.js index 14c14b6..9117d29 100644 --- a/src/index.js +++ b/src/index.js @@ -122,6 +122,7 @@ export { doSupportAbandonForClaim, doFetchUtxoCounts, doUtxoConsolidate, + doTipClaimMass, } from 'redux/actions/wallet'; export { doPopulateSharedUserState, doPreferenceGet, doPreferenceSet } from 'redux/actions/sync'; @@ -317,6 +318,7 @@ export { makeSelectPendingAmountByUri, selectIsFetchingUtxoCounts, selectIsConsolidatingUtxos, + selectIsMassClaimingTips, selectUtxoCounts, selectPendingOtherTransactions, } from 'redux/selectors/wallet'; diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index 354c813..02b9227 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -137,14 +137,13 @@ export function doFetchUtxoCounts() { let resultSets = await Promise.all([ Lbry.txo_list({ type: 'other', is_not_spent: true, page: 1, page_size: 1 }), - // removing until we figure out sdk load / need it - // Lbry.txo_list({ type: 'support', is_not_spent: true }), + Lbry.txo_list({ type: 'support', is_not_spent: true, page: 1, page_size: 1 }), ]); const counts = {}; const paymentCount = resultSets[0]['total_items']; - // const supportCount = resultSets[1]['total_items']; + const supportCount = resultSets[1]['total_items']; counts['other'] = typeof paymentCount === 'number' ? paymentCount : 0; - counts['support'] = 0; + counts['support'] = typeof supportCount === 'number' ? supportCount : 0; dispatch({ type: ACTIONS.FETCH_UTXO_COUNT_COMPLETED, @@ -175,6 +174,27 @@ export function doUtxoConsolidate() { }; } +export function doTipClaimMass() { + return async dispatch => { + dispatch({ + type: ACTIONS.TIP_CLAIM_MASS_STARTED, + }); + + const results = await Lbry.txo_spend({ type: 'support', is_not_my_input: true }); + const result = results[0]; + + dispatch({ + type: ACTIONS.PENDING_CONSOLIDATED_TXOS_UPDATED, + data: { txids: [result.txid] }, + }); + + dispatch({ + type: ACTIONS.TIP_CLAIM_MASS_COMPLETED, + }); + dispatch(doCheckPendingTxs()); + }; +} + export function doGetNewAddress() { return dispatch => { dispatch({ diff --git a/src/redux/reducers/wallet.js b/src/redux/reducers/wallet.js index 174cd16..e6b56ef 100644 --- a/src/redux/reducers/wallet.js +++ b/src/redux/reducers/wallet.js @@ -91,6 +91,7 @@ const defaultState = { fetchingUtxoCounts: false, fetchingUtxoError: undefined, consolidatingUtxos: false, + massClaimingTips: false, txoPage: {}, fetchingTxos: false, fetchingTxosError: undefined, @@ -190,6 +191,27 @@ export const walletReducer = handleActions( }; }, + [ACTIONS.TIP_CLAIM_MASS_STARTED]: (state: WalletState) => { + return { + ...state, + massClaimingTips: true, + }; + }, + + [ACTIONS.TIP_CLAIM_MASS_COMPLETED]: (state: WalletState, action) => { + return { + ...state, + massClaimingTips: false, + }; + }, + + [ACTIONS.TIP_CLAIM_MASS_FAILED]: (state: WalletState, action) => { + return { + ...state, + massClaimingTips: false, + }; + }, + [ACTIONS.PENDING_CONSOLIDATED_TXOS_UPDATED]: (state: WalletState, action) => { const pendingTxos = state.pendingConsolidateTxos; diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index d7b27d9..5e2c61b 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -396,6 +396,11 @@ export const selectIsConsolidatingUtxos = createSelector( state => state.consolidatingUtxos ); +export const selectIsMassClaimingTips = createSelector( + selectState, + state => state.massClaimingTips +); + export const selectUtxoCounts = createSelector( selectState, state => state.utxoCounts