From 4a6836108a803fd1dea8620c91db44fb5b820214 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Fri, 29 Mar 2019 06:05:37 +0100 Subject: [PATCH 1/6] add sync methods --- dist/bundle.js | 10 ++++++++++ src/lbry.js | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/dist/bundle.js b/dist/bundle.js index 297ffc4..3b60adc 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -2347,6 +2347,16 @@ Lbry.utxo_release = function () { return daemonCallWithResult('utxo_release', params); }; +// sync +Lbry.sync_hash = function () { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return daemonCallWithResult('sync_hash', params); +}; +Lbry.sync_apply = function () { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + return daemonCallWithResult('sync_apply', params); +}; + Lbry.connectPromise = null; Lbry.connect = function () { if (Lbry.connectPromise === null) { diff --git a/src/lbry.js b/src/lbry.js index 765ac27..3554362 100644 --- a/src/lbry.js +++ b/src/lbry.js @@ -93,6 +93,10 @@ Lbry.claim_tip = (params = {}) => daemonCallWithResult('claim_tip', params); Lbry.transaction_list = (params = {}) => daemonCallWithResult('transaction_list', params); Lbry.utxo_release = (params = {}) => daemonCallWithResult('utxo_release', params); +// sync +Lbry.sync_hash = (params = {}) => daemonCallWithResult('sync_hash', params); +Lbry.sync_apply = (params = {}) => daemonCallWithResult('sync_apply', params); + Lbry.connectPromise = null; Lbry.connect = () => { if (Lbry.connectPromise === null) { -- 2.45.2 From 3a59ccfcead49baf41126db9be282acbdd5d8af0 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sat, 30 Mar 2019 04:50:01 +0100 Subject: [PATCH 2/6] add total balance for all wallet accounts --- dist/bundle.js | 71 ++++++++++++++++++++++++++++-- src/constants/action_types.js | 1 + src/index.js | 3 ++ src/redux/actions/wallet.js | 31 ++++++++++++++ src/redux/reducers/wallet.js | 6 +++ src/redux/selectors/wallet.js | 81 +++++++++++++++++------------------ 6 files changed, 149 insertions(+), 44 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 3b60adc..141c89c 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -89,8 +89,8 @@ return /******/ (function(modules) { // webpackBootstrap Object.defineProperty(exports, "__esModule", { value: true }); -exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.makeSelectQueryWithOptions = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchOptions = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectCurrentChannelPage = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = undefined; -exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectClaimsInChannelForCurrentPageState = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectFirstRecommendedFileForUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.makeSelectContentPositionForUri = exports.contentReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.savePosition = exports.doUpdateSearchOptions = exports.setSearchApi = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_OPTIONS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined; +exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectTotalBalance = exports.selectBalance = exports.makeSelectBlockDate = exports.makeSelectQueryWithOptions = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchOptions = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectCurrentChannelPage = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = undefined; +exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectClaimsInChannelForCurrentPageState = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectFirstRecommendedFileForUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.makeSelectContentPositionForUri = exports.contentReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doTotalBalanceSubscribe = exports.doUpdateTotalBalance = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.savePosition = exports.doUpdateSearchOptions = exports.setSearchApi = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_OPTIONS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined; var _Notification = __webpack_require__(1); @@ -313,6 +313,18 @@ Object.defineProperty(exports, 'doBalanceSubscribe', { return _wallet.doBalanceSubscribe; } }); +Object.defineProperty(exports, 'doUpdateTotalBalance', { + enumerable: true, + get: function get() { + return _wallet.doUpdateTotalBalance; + } +}); +Object.defineProperty(exports, 'doTotalBalanceSubscribe', { + enumerable: true, + get: function get() { + return _wallet.doTotalBalanceSubscribe; + } +}); Object.defineProperty(exports, 'doFetchTransactions', { enumerable: true, get: function get() { @@ -1027,6 +1039,12 @@ Object.defineProperty(exports, 'selectBalance', { return _wallet3.selectBalance; } }); +Object.defineProperty(exports, 'selectTotalBalance', { + enumerable: true, + get: function get() { + return _wallet3.selectTotalBalance; + } +}); Object.defineProperty(exports, 'selectTransactionsById', { enumerable: true, get: function get() { @@ -1378,6 +1396,7 @@ var GET_NEW_ADDRESS_COMPLETED = exports.GET_NEW_ADDRESS_COMPLETED = 'GET_NEW_ADD var FETCH_TRANSACTIONS_STARTED = exports.FETCH_TRANSACTIONS_STARTED = 'FETCH_TRANSACTIONS_STARTED'; var FETCH_TRANSACTIONS_COMPLETED = exports.FETCH_TRANSACTIONS_COMPLETED = 'FETCH_TRANSACTIONS_COMPLETED'; var UPDATE_BALANCE = exports.UPDATE_BALANCE = 'UPDATE_BALANCE'; +var UPDATE_TOTAL_BALANCE = exports.UPDATE_TOTAL_BALANCE = 'UPDATE_TOTAL_BALANCE'; var CHECK_ADDRESS_IS_MINE_STARTED = exports.CHECK_ADDRESS_IS_MINE_STARTED = 'CHECK_ADDRESS_IS_MINE_STARTED'; var CHECK_ADDRESS_IS_MINE_COMPLETED = exports.CHECK_ADDRESS_IS_MINE_COMPLETED = 'CHECK_ADDRESS_IS_MINE_COMPLETED'; var SEND_TRANSACTION_STARTED = exports.SEND_TRANSACTION_STARTED = 'SEND_TRANSACTION_STARTED'; @@ -3566,7 +3585,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.doUpdateBalance = doUpdateBalance; +exports.doUpdateTotalBalance = doUpdateTotalBalance; exports.doBalanceSubscribe = doBalanceSubscribe; +exports.doTotalBalanceSubscribe = doTotalBalanceSubscribe; exports.doFetchTransactions = doFetchTransactions; exports.doFetchBlock = doFetchBlock; exports.doGetNewAddress = doGetNewAddress; @@ -3621,6 +3642,30 @@ function doUpdateBalance() { }; } +function doUpdateTotalBalance() { + return function (dispatch, getState) { + var _getState2 = getState(), + totalBalanceInStore = _getState2.wallet.totalBalance; + + _lbry2.default.account_list().then(function (accounts) { + var totalSatoshis = accounts.lbc_mainnet.reduce(function (a, b) { + if (!a.satoshis) return b.satoshis; + if (!b.satoshis) return a.satoshis; + return a.satoshis + b.satoshis; + }); + var totalBalance = totalSatoshis / Math.pow(10, 8); + if (totalBalanceInStore !== totalBalance) { + dispatch({ + type: ACTIONS.UPDATE_TOTAL_BALANCE, + data: { + totalBalance: totalBalance + } + }); + } + }); + }; +} + function doBalanceSubscribe() { return function (dispatch) { dispatch(doUpdateBalance()); @@ -3630,6 +3675,15 @@ function doBalanceSubscribe() { }; } +function doTotalBalanceSubscribe() { + return function (dispatch) { + dispatch(doUpdateTotalBalance()); + setInterval(function () { + return dispatch(doUpdateTotalBalance()); + }, 5000); + }; +} + function doFetchTransactions() { return function (dispatch) { dispatch({ @@ -3956,7 +4010,7 @@ function doUpdateBlockHeight() { Object.defineProperty(exports, "__esModule", { value: true }); -exports.selectTransactionListFilter = exports.makeSelectBlockDate = exports.selectCurrentHeight = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.selectWalletLockResult = exports.selectWalletLockSucceeded = exports.selectWalletLockPending = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletIsEncrypted = exports.selectWalletState = exports.selectState = undefined; +exports.selectTransactionListFilter = exports.makeSelectBlockDate = exports.selectCurrentHeight = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectTotalBalance = exports.selectBalance = exports.selectWalletLockResult = exports.selectWalletLockSucceeded = exports.selectWalletLockPending = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletIsEncrypted = exports.selectWalletState = exports.selectState = undefined; var _reselect = __webpack_require__(14); @@ -4030,6 +4084,10 @@ var selectBalance = exports.selectBalance = (0, _reselect.createSelector)(select return state.balance; }); +var selectTotalBalance = exports.selectTotalBalance = (0, _reselect.createSelector)(selectState, function (state) { + return state.totalBalance; +}); + var selectTransactionsById = exports.selectTransactionsById = (0, _reselect.createSelector)(selectState, function (state) { return state.transactions; }); @@ -5753,6 +5811,7 @@ var buildDraftTransaction = function buildDraftTransaction() { var defaultState = { balance: undefined, + totalBalance: undefined, blocks: {}, latestBlock: undefined, transactions: {}, @@ -5821,6 +5880,12 @@ reducers[ACTIONS.UPDATE_BALANCE] = function (state /*: WalletState*/, action) { }); }; +reducers[ACTIONS.UPDATE_TOTAL_BALANCE] = function (state /*: WalletState*/, action) { + return Object.assign({}, state, { + totalBalance: action.data.totalBalance + }); +}; + reducers[ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED] = function (state /*: WalletState*/) { return Object.assign({}, state, { checkingAddressOwnership: true diff --git a/src/constants/action_types.js b/src/constants/action_types.js index 8a5132d..4043671 100644 --- a/src/constants/action_types.js +++ b/src/constants/action_types.js @@ -34,6 +34,7 @@ export const GET_NEW_ADDRESS_COMPLETED = 'GET_NEW_ADDRESS_COMPLETED'; export const FETCH_TRANSACTIONS_STARTED = 'FETCH_TRANSACTIONS_STARTED'; export const FETCH_TRANSACTIONS_COMPLETED = 'FETCH_TRANSACTIONS_COMPLETED'; export const UPDATE_BALANCE = 'UPDATE_BALANCE'; +export const UPDATE_TOTAL_BALANCE = 'UPDATE_TOTAL_BALANCE'; export const CHECK_ADDRESS_IS_MINE_STARTED = 'CHECK_ADDRESS_IS_MINE_STARTED'; export const CHECK_ADDRESS_IS_MINE_COMPLETED = 'CHECK_ADDRESS_IS_MINE_COMPLETED'; export const SEND_TRANSACTION_STARTED = 'SEND_TRANSACTION_STARTED'; diff --git a/src/index.js b/src/index.js index 18d7237..04ece8a 100644 --- a/src/index.js +++ b/src/index.js @@ -71,6 +71,8 @@ export { savePosition } from 'redux/actions/content'; export { doUpdateBalance, doBalanceSubscribe, + doUpdateTotalBalance, + doTotalBalanceSubscribe, doFetchTransactions, doFetchBlock, doGetNewAddress, @@ -201,6 +203,7 @@ export { export { makeSelectBlockDate, selectBalance, + selectTotalBalance, selectTransactionsById, selectTransactionItems, selectRecentTransactions, diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index 43a1c0d..fb35e6e 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -24,6 +24,30 @@ export function doUpdateBalance() { }; } +export function doUpdateTotalBalance() { + return (dispatch, getState) => { + const { + wallet: { totalBalance: totalBalanceInStore }, + } = getState(); + Lbry.account_list().then(accounts => { + const totalSatoshis = accounts.lbc_mainnet.reduce((a, b) => { + if (!a.satoshis) return b.satoshis; + if (!b.satoshis) return a.satoshis; + return a.satoshis + b.satoshis; + }); + const totalBalance = totalSatoshis / 10 ** 8; + if (totalBalanceInStore !== totalBalance) { + dispatch({ + type: ACTIONS.UPDATE_TOTAL_BALANCE, + data: { + totalBalance, + }, + }); + } + }); + }; +} + export function doBalanceSubscribe() { return dispatch => { dispatch(doUpdateBalance()); @@ -31,6 +55,13 @@ export function doBalanceSubscribe() { }; } +export function doTotalBalanceSubscribe() { + return dispatch => { + dispatch(doUpdateTotalBalance()); + setInterval(() => dispatch(doUpdateTotalBalance()), 5000); + }; +} + export function doFetchTransactions() { return dispatch => { dispatch({ diff --git a/src/redux/reducers/wallet.js b/src/redux/reducers/wallet.js index 0df481e..f32d801 100644 --- a/src/redux/reducers/wallet.js +++ b/src/redux/reducers/wallet.js @@ -40,6 +40,7 @@ type WalletState = { const defaultState = { balance: undefined, + totalBalance: undefined, blocks: {}, latestBlock: undefined, transactions: {}, @@ -103,6 +104,11 @@ reducers[ACTIONS.UPDATE_BALANCE] = (state: WalletState, action) => balance: action.data.balance, }); +reducers[ACTIONS.UPDATE_TOTAL_BALANCE] = (state: WalletState, action) => + Object.assign({}, state, { + totalBalance: action.data.totalBalance, + }); + reducers[ACTIONS.CHECK_ADDRESS_IS_MINE_STARTED] = (state: WalletState) => Object.assign({}, state, { checkingAddressOwnership: true, diff --git a/src/redux/selectors/wallet.js b/src/redux/selectors/wallet.js index 6b0fe6a..af5d340 100644 --- a/src/redux/selectors/wallet.js +++ b/src/redux/selectors/wallet.js @@ -1,83 +1,82 @@ import { createSelector } from 'reselect'; import * as TRANSACTIONS from 'constants/transaction_types'; -export const selectState = (state) => state.wallet || {}; +export const selectState = state => state.wallet || {}; export const selectWalletState = selectState; export const selectWalletIsEncrypted = createSelector( selectState, - (state) => state.walletIsEncrypted + state => state.walletIsEncrypted ); export const selectWalletEncryptPending = createSelector( selectState, - (state) => state.walletEncryptPending + state => state.walletEncryptPending ); export const selectWalletEncryptSucceeded = createSelector( selectState, - (state) => state.walletEncryptSucceded + state => state.walletEncryptSucceded ); export const selectWalletEncryptResult = createSelector( selectState, - (state) => state.walletEncryptResult + state => state.walletEncryptResult ); export const selectWalletDecryptPending = createSelector( selectState, - (state) => state.walletDecryptPending + state => state.walletDecryptPending ); export const selectWalletDecryptSucceeded = createSelector( selectState, - (state) => state.walletDecryptSucceded + state => state.walletDecryptSucceded ); export const selectWalletDecryptResult = createSelector( selectState, - (state) => state.walletDecryptResult + state => state.walletDecryptResult ); export const selectWalletUnlockPending = createSelector( selectState, - (state) => state.walletUnlockPending + state => state.walletUnlockPending ); export const selectWalletUnlockSucceeded = createSelector( selectState, - (state) => state.walletUnlockSucceded + state => state.walletUnlockSucceded ); export const selectWalletUnlockResult = createSelector( selectState, - (state) => state.walletUnlockResult + state => state.walletUnlockResult ); export const selectWalletLockPending = createSelector( selectState, - (state) => state.walletLockPending + state => state.walletLockPending ); export const selectWalletLockSucceeded = createSelector( selectState, - (state) => state.walletLockSucceded + state => state.walletLockSucceded ); -export const selectWalletLockResult = createSelector( - selectState, - (state) => state.walletLockResult -); +export const selectWalletLockResult = createSelector(selectState, state => state.walletLockResult); -export const selectBalance = createSelector(selectState, (state) => state.balance); +export const selectBalance = createSelector(selectState, state => state.balance); -export const selectTransactionsById = createSelector(selectState, (state) => state.transactions); +export const selectTotalBalance = createSelector(selectState, state => state.totalBalance); -export const selectTransactionItems = createSelector(selectTransactionsById, (byId) => { +export const selectTransactionsById = createSelector(selectState, state => state.transactions); + +export const selectTransactionItems = createSelector(selectTransactionsById, byId => { const items = []; - Object.keys(byId).forEach((txid) => { + Object.keys(byId).forEach(txid => { const tx = byId[txid]; // ignore dust/fees @@ -95,24 +94,24 @@ export const selectTransactionItems = createSelector(selectTransactionsById, (by const append = []; append.push( - ...tx.claim_info.map((item) => + ...tx.claim_info.map(item => Object.assign({}, tx, item, { type: item.claim_name[0] === '@' ? TRANSACTIONS.CHANNEL : TRANSACTIONS.PUBLISH, }) ) ); append.push( - ...tx.support_info.map((item) => + ...tx.support_info.map(item => Object.assign({}, tx, item, { type: !item.is_tip ? TRANSACTIONS.SUPPORT : TRANSACTIONS.TIP, }) ) ); append.push( - ...tx.update_info.map((item) => Object.assign({}, tx, item, { type: TRANSACTIONS.UPDATE })) + ...tx.update_info.map(item => Object.assign({}, tx, item, { type: TRANSACTIONS.UPDATE })) ); append.push( - ...tx.abandon_info.map((item) => Object.assign({}, tx, item, { type: TRANSACTIONS.ABANDON })) + ...tx.abandon_info.map(item => Object.assign({}, tx, item, { type: TRANSACTIONS.ABANDON })) ); if (!append.length) { @@ -124,7 +123,7 @@ export const selectTransactionItems = createSelector(selectTransactionsById, (by } items.push( - ...append.map((item) => { + ...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); @@ -161,10 +160,10 @@ export const selectTransactionItems = createSelector(selectTransactionsById, (by }); }); -export const selectRecentTransactions = createSelector(selectTransactionItems, (transactions) => { +export const selectRecentTransactions = createSelector(selectTransactionItems, transactions => { const threshold = new Date(); threshold.setDate(threshold.getDate() - 7); - return transactions.filter((transaction) => { + return transactions.filter(transaction => { if (!transaction.date) { return true; // pending transaction } @@ -175,48 +174,48 @@ export const selectRecentTransactions = createSelector(selectTransactionItems, ( export const selectHasTransactions = createSelector( selectTransactionItems, - (transactions) => transactions && transactions.length > 0 + transactions => transactions && transactions.length > 0 ); export const selectIsFetchingTransactions = createSelector( selectState, - (state) => state.fetchingTransactions + state => state.fetchingTransactions ); -export const selectIsSendingSupport = createSelector(selectState, (state) => state.sendingSupport); +export const selectIsSendingSupport = createSelector(selectState, state => state.sendingSupport); -export const selectReceiveAddress = createSelector(selectState, (state) => state.receiveAddress); +export const selectReceiveAddress = createSelector(selectState, state => state.receiveAddress); export const selectGettingNewAddress = createSelector( selectState, - (state) => state.gettingNewAddress + state => state.gettingNewAddress ); export const selectDraftTransaction = createSelector( selectState, - (state) => state.draftTransaction || {} + state => state.draftTransaction || {} ); export const selectDraftTransactionAmount = createSelector( selectDraftTransaction, - (draft) => draft.amount + draft => draft.amount ); export const selectDraftTransactionAddress = createSelector( selectDraftTransaction, - (draft) => draft.address + draft => draft.address ); export const selectDraftTransactionError = createSelector( selectDraftTransaction, - (draft) => draft.error + draft => draft.error ); -export const selectBlocks = createSelector(selectState, (state) => state.blocks); +export const selectBlocks = createSelector(selectState, state => state.blocks); -export const selectCurrentHeight = createSelector(selectState, (state) => state.latestBlock); +export const selectCurrentHeight = createSelector(selectState, state => state.latestBlock); -export const makeSelectBlockDate = (block) => +export const makeSelectBlockDate = block => 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 @@ -239,5 +238,5 @@ export const makeSelectBlockDate = (block) => export const selectTransactionListFilter = createSelector( selectState, - (state) => state.transactionListFilter || '' + state => state.transactionListFilter || '' ); -- 2.45.2 From b1d8dade0dfa277140eac03f7a448724cc6bd52c Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sat, 30 Mar 2019 04:51:52 +0100 Subject: [PATCH 3/6] add parentheses -- 2.45.2 From 1d9218669bc8f18eb91cd053bbb29f347267f091 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Sat, 30 Mar 2019 11:01:25 +0100 Subject: [PATCH 4/6] fix total balance calculation --- dist/bundle.js | 10 +++++----- src/redux/actions/wallet.js | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 141c89c..8d37246 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -3647,13 +3647,13 @@ function doUpdateTotalBalance() { var _getState2 = getState(), totalBalanceInStore = _getState2.wallet.totalBalance; - _lbry2.default.account_list().then(function (accounts) { - var totalSatoshis = accounts.lbc_mainnet.reduce(function (a, b) { - if (!a.satoshis) return b.satoshis; - if (!b.satoshis) return a.satoshis; + _lbry2.default.account_list().then(function (accountList) { + var accounts = accountList.lbc_mainnet; + + var totalSatoshis = accounts.length === 1 ? accounts[0].satoshis : accounts.reduce(function (a, b) { return a.satoshis + b.satoshis; }); - var totalBalance = totalSatoshis / Math.pow(10, 8); + var totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / Math.pow(10, 8); if (totalBalanceInStore !== totalBalance) { dispatch({ type: ACTIONS.UPDATE_TOTAL_BALANCE, diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index fb35e6e..7500e44 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -29,13 +29,13 @@ export function doUpdateTotalBalance() { const { wallet: { totalBalance: totalBalanceInStore }, } = getState(); - Lbry.account_list().then(accounts => { - const totalSatoshis = accounts.lbc_mainnet.reduce((a, b) => { - if (!a.satoshis) return b.satoshis; - if (!b.satoshis) return a.satoshis; - return a.satoshis + b.satoshis; - }); - const totalBalance = totalSatoshis / 10 ** 8; + Lbry.account_list().then(accountList => { + const { lbc_mainnet: accounts } = accountList; + const totalSatoshis = + accounts.length === 1 + ? accounts[0].satoshis + : accounts.reduce((a, b) => a.satoshis + b.satoshis); + const totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / 10 ** 8; if (totalBalanceInStore !== totalBalance) { dispatch({ type: ACTIONS.UPDATE_TOTAL_BALANCE, -- 2.45.2 From 8448766e48b533f8be7f3ecd0b94be495799614f Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 11 Apr 2019 08:53:04 -0400 Subject: [PATCH 5/6] testing --- dist/bundle.js | 3 +++ src/redux/actions/wallet.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dist/bundle.js b/dist/bundle.js index 8d37246..0ba15c9 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -3629,6 +3629,7 @@ function doUpdateBalance() { _lbry2.default.account_balance().then(function (balanceAsString) { var balance = parseFloat(balanceAsString); + console.log('balance=' + balance); if (balanceInStore !== balance) { dispatch({ @@ -3650,10 +3651,12 @@ function doUpdateTotalBalance() { _lbry2.default.account_list().then(function (accountList) { var accounts = accountList.lbc_mainnet; + console.log(accountList); var totalSatoshis = accounts.length === 1 ? accounts[0].satoshis : accounts.reduce(function (a, b) { return a.satoshis + b.satoshis; }); var totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / Math.pow(10, 8); + console.log(totalBalance); if (totalBalanceInStore !== totalBalance) { dispatch({ type: ACTIONS.UPDATE_TOTAL_BALANCE, diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index 7500e44..144ea26 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -11,6 +11,7 @@ export function doUpdateBalance() { } = getState(); Lbry.account_balance().then(balanceAsString => { const balance = parseFloat(balanceAsString); + console.log(`balance=${balance}`); if (balanceInStore !== balance) { dispatch({ @@ -31,11 +32,13 @@ export function doUpdateTotalBalance() { } = getState(); Lbry.account_list().then(accountList => { const { lbc_mainnet: accounts } = accountList; + console.log(accountList); const totalSatoshis = accounts.length === 1 ? accounts[0].satoshis : accounts.reduce((a, b) => a.satoshis + b.satoshis); const totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / 10 ** 8; + console.log(totalBalance); if (totalBalanceInStore !== totalBalance) { dispatch({ type: ACTIONS.UPDATE_TOTAL_BALANCE, -- 2.45.2 From 8c17d91b549215e924a43f5f80220286e888d575 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 17 Apr 2019 15:37:33 +0100 Subject: [PATCH 6/6] remove console.log calls --- dist/bundle.es.js | 4 ---- dist/bundle.js | 4 ---- src/redux/actions/wallet.js | 4 ---- 3 files changed, 12 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 8531903..3f149e2 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1542,8 +1542,6 @@ function doUpdateBalance() { } = getState(); lbryProxy.account_balance().then(balanceAsString => { const balance = parseFloat(balanceAsString); - console.log(`balance=${balance}`); - if (balanceInStore !== balance) { dispatch({ type: UPDATE_BALANCE, @@ -1563,10 +1561,8 @@ function doUpdateTotalBalance() { } = getState(); lbryProxy.account_list().then(accountList => { const { lbc_mainnet: accounts } = accountList; - console.log(accountList); const totalSatoshis = accounts.length === 1 ? accounts[0].satoshis : accounts.reduce((a, b) => a.satoshis + b.satoshis); const totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / Math.pow(10, 8); - console.log(totalBalance); if (totalBalanceInStore !== totalBalance) { dispatch({ type: UPDATE_TOTAL_BALANCE, diff --git a/dist/bundle.js b/dist/bundle.js index d20a386..f2d5996 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -3285,8 +3285,6 @@ function doUpdateBalance() { _lbry2.default.account_balance().then(function (balanceAsString) { var balance = parseFloat(balanceAsString); - console.log('balance=' + balance); - if (balanceInStore !== balance) { dispatch({ type: ACTIONS.UPDATE_BALANCE, @@ -3307,12 +3305,10 @@ function doUpdateTotalBalance() { _lbry2.default.account_list().then(function (accountList) { var accounts = accountList.lbc_mainnet; - console.log(accountList); var totalSatoshis = accounts.length === 1 ? accounts[0].satoshis : accounts.reduce(function (a, b) { return a.satoshis + b.satoshis; }); var totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / Math.pow(10, 8); - console.log(totalBalance); if (totalBalanceInStore !== totalBalance) { dispatch({ type: ACTIONS.UPDATE_TOTAL_BALANCE, diff --git a/src/redux/actions/wallet.js b/src/redux/actions/wallet.js index 144ea26..6724ed3 100644 --- a/src/redux/actions/wallet.js +++ b/src/redux/actions/wallet.js @@ -11,8 +11,6 @@ export function doUpdateBalance() { } = getState(); Lbry.account_balance().then(balanceAsString => { const balance = parseFloat(balanceAsString); - console.log(`balance=${balance}`); - if (balanceInStore !== balance) { dispatch({ type: ACTIONS.UPDATE_BALANCE, @@ -32,13 +30,11 @@ export function doUpdateTotalBalance() { } = getState(); Lbry.account_list().then(accountList => { const { lbc_mainnet: accounts } = accountList; - console.log(accountList); const totalSatoshis = accounts.length === 1 ? accounts[0].satoshis : accounts.reduce((a, b) => a.satoshis + b.satoshis); const totalBalance = (Number.isNaN(totalSatoshis) ? 0 : totalSatoshis) / 10 ** 8; - console.log(totalBalance); if (totalBalanceInStore !== totalBalance) { dispatch({ type: ACTIONS.UPDATE_TOTAL_BALANCE, -- 2.45.2