From 0ae6f043edf2a457a754b80eced5ba6500b7087c Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Wed, 15 Aug 2018 17:23:00 +0200 Subject: [PATCH 01/15] loading new txs using pagination --- src/js/controllers/walletDetails.js | 13 +++- src/js/services/walletService.js | 103 +++++++++++++++++++++++++--- www/views/walletDetails.html | 2 +- 3 files changed, 105 insertions(+), 13 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index ec787a5f4..68d26baf2 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -256,11 +256,18 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun return !tx.confirmations || tx.confirmations === 0; }; + var loadingTxs = false; $scope.showMore = function() { + if (loadingTxs) + return; + loadingTxs = true; $timeout(function() { - currentTxHistoryPage++; - $scope.showHistory(); - $scope.$broadcast('scroll.infiniteScrollComplete'); + walletService.getMoreTxs($scope.wallet, function() { + currentTxHistoryPage++; + $scope.showHistory(); + $scope.$broadcast('scroll.infiniteScrollComplete'); + loadingTxs = false; + }); }, 100); }; diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 647c69734..4d293a01f 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -396,6 +396,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim return ret; }; + var skipped = 0; + var updateLocalTxHistory = function(wallet, opts, cb) { var FIRST_LIMIT = 5; var LIMIT = 50; @@ -492,6 +494,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim } // + shouldContinue = false; + + skipped = skip; if (!shouldContinue) { $log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length); @@ -499,7 +504,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim } requestLimit = LIMIT; - getNewTxs(newTxs, skip, next); }); }; @@ -535,6 +539,87 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); } + + if (opts.getMoreTxs) { + var requestLimit = LIMIT; + getNewTxs([], skipped, function(err, txs) { + if (err) return cb(err); + + createReceivedEvents(txs); + + var newHistory = lodash.uniq(lodash.compact(txs.concat(confirmedTxs)), function(x) { + return x.txid; + }); + + + function updateNotes(cb2) { + if (!endingTs) return cb2(); + + $log.debug('Syncing notes from: ' + endingTs); + wallet.getTxNotes({ + minTs: endingTs + }, function(err, notes) { + if (err) { + $log.warn(err); + return cb2(); + }; + lodash.each(notes, function(note) { + $log.debug('Note for ' + note.txid); + lodash.each(newHistory, function(tx) { + if (tx.txid == note.txid) { + $log.debug('...updating note for ' + note.txid); + tx.note = note; + } + }); + }); + return cb2(); + }); + } + + function updateLowAmount(txs) { + if (!opts.lowAmount) return; + + lodash.each(txs, function(tx) { + tx.lowAmount = tx.amount < opts.lowAmount; + }); + }; + + updateLowAmount(txs); + + updateNotes(function() { + + // + if (foundLimitTx) { + $log.debug('Tx history read until limitTx: ' + opts.limitTx); + return cb(null, newHistory); + } + // + + var historyToSave = JSON.stringify(newHistory); + + lodash.each(txs, function(tx) { + tx.recent = true; + }) + + $log.debug('Tx History synced. Total Txs: ' + newHistory.length); + + // Final update + if (walletId == wallet.credentials.walletId) { + wallet.completeHistory = newHistory; + } + + return storageService.setTxHistory(historyToSave, walletId, function() { + $log.debug('Tx History saved.'); + + return cb(); + }); + }); + }); + return; + } + + skipped = 0; + getNewTxs([], 0, function(err, txs) { if (err) return cb(err); @@ -611,6 +696,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; + root.getMoreTxs = function(wallet, cb) { + var opts = {}; + opts.getMoreTxs = true; + updateLocalTxHistory(wallet, opts, cb); + }; + root.getTxNote = function(wallet, txid, cb) { wallet.getTxNote({ txid: txid @@ -675,16 +766,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim root.getTxHistory = function(wallet, opts, cb) { opts = opts || {}; - var walletId = wallet.credentials.walletId; - if (!wallet.isComplete()) return cb(); - function isHistoryCached() { - return wallet.completeHistory && wallet.completeHistory.isValid; - }; - - // disable caching - //if (isHistoryCached() && !opts.force) return cb(null, wallet.completeHistory); + // var historyIsCached = wallet.completeHistory && wallet.completeHistory.isValid; + // if (historyIsCached && !opts.force) return cb(null, wallet.completeHistory); $log.debug('Updating Transaction History'); diff --git a/www/views/walletDetails.html b/www/views/walletDetails.html index 6e05862aa..fc422ff1f 100644 --- a/www/views/walletDetails.html +++ b/www/views/walletDetails.html @@ -306,7 +306,7 @@ From 93b6c3f1be5fbf345c3628a0a9d64193e8154e57 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 16 Aug 2018 15:00:51 +1200 Subject: [PATCH 02/15] Spinner same size as refresh button. --- src/sass/views/walletDetails.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sass/views/walletDetails.scss b/src/sass/views/walletDetails.scss index 858229d85..39118320b 100644 --- a/src/sass/views/walletDetails.scss +++ b/src/sass/views/walletDetails.scss @@ -341,4 +341,6 @@ a.item { .loading-wallet svg { margin-top: 0; + width: 16px; + height: 16px; } \ No newline at end of file From 33d780f2e561f1681a9a1db7fd4377a2406814a3 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Thu, 16 Aug 2018 15:44:59 +1200 Subject: [PATCH 03/15] The spinner in wallet details now spins when the infinite scroll spinner spins. --- src/js/controllers/walletDetails.js | 46 +++++++++++++++++++++++------ www/views/includes/walletInfo.html | 4 +-- www/views/walletDetails.html | 10 +++---- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 68d26baf2..171c71847 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -5,12 +5,39 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun var HISTORY_SHOW_LIMIT = 10; var currentTxHistoryPage = 0; var listeners = []; - $scope.txps = []; + + // For gradual migration for doing it properly + $scope.vm = { + gettingInitialHistory: false, + updatingTxHistory: false + }; + + $scope.amountIsCollapsible = false; + $scope.color = '#888888'; $scope.completeTxHistory = []; - $scope.openTxpModal = txpModalService.open; + $scope.filteredTxHistory = []; $scope.isCordova = platformInfo.isCordova; $scope.isAndroid = platformInfo.isAndroid; $scope.isIOS = platformInfo.isIOS; + $scope.isSearching = false; + $scope.openTxpModal = txpModalService.open; + $scope.requiresMultipleSignatures = false; + $scope.showBalanceButton = false; + $scope.status = null; + $scope.txHistory = []; + $scope.txHistorySearchResults = []; + $scope.txHistoryShowMore = false; + $scope.txps = []; + $scope.updatingStatus = false; + $scope.updateStatusError = null; + $scope.updateTxHistoryError = null; + $scope.updatingTxHistoryProgress = 0; + $scope.wallet = null; + $scope.walletId = ''; + $scope.walletNotRegistered = false; + + + var channel = "ga"; if (platformInfo.isCordova) { @@ -172,7 +199,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun walletService.getTxHistory($scope.wallet, { feeLevels: levels }, function(err, txHistory) { - $scope.updatingTxHistory = false; + $scope.vm.gettingInitialHistory = false; if (err) { $scope.txHistory = null; $scope.updateTxHistoryError = true; @@ -256,17 +283,18 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun return !tx.confirmations || tx.confirmations === 0; }; - var loadingTxs = false; + $scope.showMore = function() { - if (loadingTxs) + if ($scope.vm.updatingTxHistory) { return; - loadingTxs = true; + } + $scope.vm.updatingTxHistory = true; $timeout(function() { - walletService.getMoreTxs($scope.wallet, function() { + walletService.getMoreTxs($scope.wallet, function onMoreTxs() { currentTxHistoryPage++; $scope.showHistory(); $scope.$broadcast('scroll.infiniteScrollComplete'); - loadingTxs = false; + $scope.vm.updatingTxHistory = false; }); }, 100); }; @@ -400,7 +428,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun if (!$scope.wallet) return; $scope.requiresMultipleSignatures = $scope.wallet.credentials.m > 1; - $scope.updatingTxHistory = true; + $scope.vm.gettingInitialHistory = true; addressbookService.list(function(err, ab) { if (err) $log.error(err); diff --git a/www/views/includes/walletInfo.html b/www/views/includes/walletInfo.html index 1680d2c2c..aff10fc09 100644 --- a/www/views/includes/walletInfo.html +++ b/www/views/includes/walletInfo.html @@ -3,8 +3,8 @@ Tap to recreate Tap to retry - -↻ +
diff --git a/www/views/walletDetails.html b/www/views/walletDetails.html index fc422ff1f..6021467ee 100644 --- a/www/views/walletDetails.html +++ b/www/views/walletDetails.html @@ -284,29 +284,29 @@
+ ng-show="!txHistory[0] && !vm.gettingInitialHistory && !updateTxHistoryError && !updateStatusError" translate> No transactions yet
+ ng-show="!txHistory[0] && !vm.gettingInitialHistory && updateTxHistoryError" translate> Could not update transaction history
-
+
Updating transaction history. Please stand by.
{{updatingTxHistoryProgress}} transactions downloaded
-
+
From 03fa87adbcac643b5b8a0547d42da7ad48f4b4e4 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Mon, 20 Aug 2018 17:21:30 +1200 Subject: [PATCH 04/15] Displaying transactions from cache when first entering wallet details. --- src/js/app.js | 4 +- src/js/controllers/walletDetails.js | 93 ++++++++++++++-- src/js/services/wallet-history.service.js | 129 ++++++++++++++++++++++ src/js/services/walletService.js | 41 +++---- www/views/includes/walletInfo.html | 2 +- www/views/walletDetails.html | 6 +- 6 files changed, 239 insertions(+), 36 deletions(-) create mode 100644 src/js/services/wallet-history.service.js diff --git a/src/js/app.js b/src/js/app.js index 745ceef50..503da9f52 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -19,7 +19,8 @@ var modules = [ 'copayApp.controllers', 'copayApp.directives', 'copayApp.addons', - 'bitcoincom.directives' + 'bitcoincom.directives', + 'bitcoincom.services' ]; var copayApp = window.copayApp = angular.module('copayApp', modules); @@ -30,3 +31,4 @@ angular.module('copayApp.controllers', []); angular.module('copayApp.directives', []); angular.module('copayApp.addons', []); angular.module('bitcoincom.directives', []); +angular.module('bitcoincom.services', []); diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 171c71847..6df56c943 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, sendFlowService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService) { +angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, sendFlowService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService, walletHistoryService) { var HISTORY_SHOW_LIMIT = 10; var currentTxHistoryPage = 0; @@ -8,8 +8,11 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun // For gradual migration for doing it properly $scope.vm = { - gettingInitialHistory: false, - updatingTxHistory: false + gettingCachedHistory: true, + gettingInitialHistory: true, + updatingTxHistory: false, + //updateTxHistoryError: false + updateTxHistoryFailed: false }; $scope.amountIsCollapsible = false; @@ -30,7 +33,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.txps = []; $scope.updatingStatus = false; $scope.updateStatusError = null; - $scope.updateTxHistoryError = null; $scope.updatingTxHistoryProgress = 0; $scope.wallet = null; $scope.walletId = ''; @@ -192,7 +194,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun var updateTxHistory = function(cb) { if (!cb) cb = function() {}; - $scope.updateTxHistoryError = false; + $scope.vm.updateTxHistoryFailed = false; $scope.updatingTxHistoryProgress = 0; feeService.getFeeLevels($scope.wallet.coin, function(err, levels) { @@ -202,10 +204,10 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.vm.gettingInitialHistory = false; if (err) { $scope.txHistory = null; - $scope.updateTxHistoryError = true; + $scope.vm.updateTxHistoryFailed = true; return; } - + applyCurrencyAliases(txHistory); var config = configService.getSync(); @@ -214,7 +216,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun var r = rateService.toFiat(t.amount, fiatCode, $scope.wallet.coin); t.alternativeAmountStr = r.toFixed(2) + ' ' + fiatCode; }); - + console.log('pagination Got tx history old way'); $scope.completeTxHistory = txHistory; $scope.showHistory(); @@ -230,12 +232,77 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun var defaults = configService.getDefaults(); var configCache = configService.getSync(); - lodash.each(txHistory, function(t) { - t.amountUnitStr = $scope.wallet.coin == 'btc' + lodash.each(txHistory, function onTx(tx) { + tx.amountUnitStr = $scope.wallet.coin == 'btc' ? (configCache.bitcoinAlias || defaults.bitcoinAlias) : (configCache.bitcoinCashAlias || defaults.bitcoinCashAlias); - t.amountUnitStr = t.amountUnitStr.toUpperCase(); + tx.amountUnitStr = tx.amountUnitStr.toUpperCase(); + }); + } + + function formatTxHistoryForDisplay(txHistory) { + applyCurrencyAliases(txHistory); + + var config = configService.getSync(); + var fiatCode = config.wallet.settings.alternativeIsoCode; + lodash.each(txHistory, function(t) { + var r = rateService.toFiat(t.amount, fiatCode, $scope.wallet.coin); + t.alternativeAmountStr = r.toFixed(2) + ' ' + fiatCode; + }); + } + + function updateTxHistoryUsingCachedData() { + walletHistoryService.getCachedTxHistory($scope.wallet.id, function onGetCachedTxHistory(err, txHistory){ + $scope.vm.gettingCachedHistory = false; + if (err) { + // Don't display an error because we are also requesting the histroy. + $log.error('Error getting cached tx history.', err); + return; + } + + if (!txHistory) { + $log.debug('No cached tx history.'); + return; + } + + console.log('pagination Got cached txs, count: ', txHistory.length); + + /* + var shortHistory = []; + if (txHistory.length > 0) { + shortHistory = [ + txHistory[0] + ]; + } + txHistory = shortHistory; + */ + + formatTxHistoryForDisplay(txHistory); + + $scope.completeTxHistory = txHistory; + $scope.showHistory(); + $scope.$apply(); + console.log('pagination displayed cached history.'); + }); + } + + function updateTxHistoryFromSmallCache(getLatest) { + walletHistoryService.updateTxHistoryByPage($scope.wallet, getLatest, true, function onUpdateTxHistoryByPage(err, txHistory) { + console.log('pagination returned'); + $scope.vm.gettingInitialHistory = false; + if (err) { + console.error('pagination Failed to get history.', err); + $scope.txHistory = null; + $scope.vm.updateTxHistoryFailed = true; + return; + } + console.log('pagination txs returned in history: ' + txHistory.length); + formatTxHistoryForDisplay(txHistory); + + $scope.completeTxHistory = txHistory; + $scope.showHistory(); + $scope.$apply(); }); } @@ -308,7 +375,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.updateAll = function(force, cb)  { updateStatus(force); - updateTxHistory(cb); + //updateTxHistory(cb); + updateTxHistoryFromSmallCache(); }; $scope.hideToggle = function() { @@ -450,6 +518,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun var refreshInterval; $scope.$on("$ionicView.afterEnter", function(event, data) { + updateTxHistoryUsingCachedData(); $scope.updateAll(); refreshAmountSection(); refreshInterval = $interval($scope.onRefresh, 10 * 1000); diff --git a/src/js/services/wallet-history.service.js b/src/js/services/wallet-history.service.js new file mode 100644 index 000000000..3679dd088 --- /dev/null +++ b/src/js/services/wallet-history.service.js @@ -0,0 +1,129 @@ +'use strict'; + +(function(){ + + angular + .module('bitcoincom.services') + .factory('walletHistoryService', walletHistoryService); + + function walletHistoryService(configService, storageService, lodash, $log, txFormatService) { + // 8 Transactions fit on an iPhone Plus screen when in Wallet Details. + // Make it a little bit bigger so it doesn't have to load more immediately + var PAGE_SIZE = 50 / 1.5; + // How much to overlap on each end of the page, for mitigating inconsistent sort order. + var PAGE_OVERLAP_FRACTION = 0.5; + + var SAFE_CONFIRMATIONS = 6; + + var service = { + getCachedTxHistory: getCachedTxHistory, + updateTxHistoryByPage: updateTxHistoryByPage + }; + return service; + + /** + * @param {string} walletId + * @param {function(error, txs)} cb + */ + function getCachedTxHistory(walletId, cb) { + storageService.getTxHistory(walletId, function onGetTxHistory(err, txHistoryString){ + if (err) { + return cb(err); + } + + if (!txHistoryString) { + return cb(null, txHistoryString); + } + + try { + var txHistory = JSON.parse(txHistoryString); + return cb(null, txHistory); + } catch (e) { + $log.error('Failed to parse tx history.', e); + return cb(e); + } + }); + } + + function processNewTxs(wallet, txs) { + var now = Math.floor(Date.now() / 1000); + var txHistoryUnique = {}; + var processedTxs = []; + wallet.hasUnsafeConfirmed = false; + + lodash.each(txs, function(tx) { + tx = txFormatService.processTx(wallet.coin, tx); + + // no future transactions... + if (tx.time > now) + tx.time = now; + + if (tx.confirmations >= SAFE_CONFIRMATIONS) { + tx.safeConfirmed = SAFE_CONFIRMATIONS + '+'; + } else { + tx.safeConfirmed = false; + wallet.hasUnsafeConfirmed = true; + } + + if (tx.note) { + delete tx.note.encryptedEditedByName; + delete tx.note.encryptedBody; + } + + if (!txHistoryUnique[tx.txid]) { + processedTxs.push(tx); + txHistoryUnique[tx.txid] = true; + } else { + $log.debug('Ignoring duplicate TX in history: ' + tx.txid) + } + }); + + // Update notes? + + return processedTxs; + }; + + /** + * A small cache of up to the 50 most recent transactions + */ + function saveTxHistory(processedTxs, walletId) { + storageService.setTxHistory(processedTxs, walletId, function onSetTxHistory(error){ + // Looks like callback only gets called on error + $log.error('pagination Failed to save tx history.', error); + }); + + } + + // Only clear the cache once we have received new transactions from the server. + function updateTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) { + var skip = 0; + var limit = Math.floor(PAGE_SIZE * (1 + PAGE_OVERLAP_FRACTION)); + + var opts = { + skip: skip, + limit: limit + }; + wallet.getTxHistory(opts, function onTxHistory(err, txsFromServer) { + if (err) { + return cb(err); + } + + if (!txsFromServer.length) { + return cb(null, []); + } + + var processedTxs = processNewTxs(wallet, txsFromServer); + + if (getLatest) { + console.log('pagination Saving retrieved txs.'); + saveTxHistory(wallet, processedTxs); + } + + return cb(null, processedTxs); + }); + } + + } + + +})(); \ No newline at end of file diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 4d293a01f..6f0c93697 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -398,6 +398,21 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim var skipped = 0; + function fixTxsUnit(txs) { + if (!txs || !txs[0] || !txs[0].amountStr) return; + + var cacheCoin = txs[0].amountStr.split(' ')[1]; + + if (cacheCoin == 'bits') { + + $log.debug('Fixing Tx Cache Unit to: ' + wallet.coin) + lodash.each(txs, function(tx) { + tx.amountStr = txFormatService.formatAmountStr(wallet.coin, tx.amount); + tx.feeStr = txFormatService.formatAmountStr(wallet.coin, tx.fees); + }); + } + }; + var updateLocalTxHistory = function(wallet, opts, cb) { var FIRST_LIMIT = 5; var LIMIT = 50; @@ -408,25 +423,10 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim var progressFn = opts.progressFn || function() {}; var foundLimitTx = false; - if (opts.feeLevels) { opts.lowAmount = root.getLowAmount(wallet, opts.feeLevels); } - var fixTxsUnit = function(txs) { - if (!txs || !txs[0] || !txs[0].amountStr) return; - - var cacheCoin = txs[0].amountStr.split(' ')[1]; - - if (cacheCoin == 'bits') { - - $log.debug('Fixing Tx Cache Unit to: ' + wallet.coin) - lodash.each(txs, function(tx) { - tx.amountStr = txFormatService.formatAmountStr(wallet.coin, tx.amount); - tx.feeStr = txFormatService.formatAmountStr(wallet.coin, tx.fees); - }); - } - }; getSavedTxs(walletId, function(err, txsFromLocal) { if (err) return cb(err); @@ -437,13 +437,14 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim var endingTxid = confirmedTxs[0] ? confirmedTxs[0].txid : null; var endingTs = confirmedTxs[0] ? confirmedTxs[0].time : null; - $log.debug('Confirmed TXs. Got:' + confirmedTxs.length + '/' + txsFromLocal.length); + console.log('pagination Hard confirmed TXs. Got:' + confirmedTxs.length + '/' + txsFromLocal.length); // First update progressFn(txsFromLocal, 0); wallet.completeHistory = txsFromLocal; function getNewTxs(newTxs, skip, next) { + console.log('pagination getNewTxs skip: ' + skip); getTxsFromServer(wallet, skip, endingTxid, requestLimit, function(err, res) { if (err) { $log.warn(bwcError.msg(err, 'Server Error')); //TODO @@ -456,6 +457,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim return next(err); } + console.log('pagination Result count: ' + res.length); // Check if new txs are founds, if yes, lets investigate in the 50 next // To be sure we are not missing txs by sorting (maybe a new tx is after the "endingTxid" var newDiscoveredTxs = res.filter(function (x) { @@ -464,7 +466,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }).length == 0; }); - $log.debug('Discovering TXs. Got:' + newDiscoveredTxs.length); + console.log('pagination Discovering new TXs. Got:' + newDiscoveredTxs.length); var shouldContinue = newDiscoveredTxs.length > 0; @@ -477,7 +479,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim skip = skip + requestLimit; - $log.debug('Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue); + console.log('pagination Syncing TXs. Got:' + newTxs.length + ' Skip:' + skip, ' EndingTxid:', endingTxid, ' Continue:', shouldContinue); // TODO Dirty // do not sync all history, just looking for a single TX. @@ -499,7 +501,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim skipped = skip; if (!shouldContinue) { - $log.debug('Finished Sync: New / soft confirmed Txs: ' + newTxs.length); + console.log('pagination Finished Sync: New / soft confirmed Txs: ' + newTxs.length); return next(null, newTxs); } @@ -545,6 +547,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim getNewTxs([], skipped, function(err, txs) { if (err) return cb(err); + console.log(); createReceivedEvents(txs); var newHistory = lodash.uniq(lodash.compact(txs.concat(confirmedTxs)), function(x) { diff --git a/www/views/includes/walletInfo.html b/www/views/includes/walletInfo.html index aff10fc09..f97ebf9ed 100644 --- a/www/views/includes/walletInfo.html +++ b/www/views/includes/walletInfo.html @@ -5,7 +5,7 @@
+ !walletNotRegistered && !updateStatusError && !vm.updateTxHistoryFailed">
Auditable diff --git a/www/views/walletDetails.html b/www/views/walletDetails.html index 6021467ee..2548aa4b9 100644 --- a/www/views/walletDetails.html +++ b/www/views/walletDetails.html @@ -284,13 +284,13 @@
+ ng-show="!txHistory[0] && !vm.gettingInitialHistory && !vm.updateTxHistoryFailed && !updateStatusError" translate> No transactions yet
+ ng-show="!txHistory[0] && !vm.gettingInitialHistory && vm.updateTxHistoryFailed" translate> Could not update transaction history
@@ -300,7 +300,7 @@ {{updatingTxHistoryProgress}} transactions downloaded
-
+
From 72cb94d2122b3b20d47873c8365679c22423045d Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Tue, 21 Aug 2018 08:58:19 +1200 Subject: [PATCH 05/15] Using infinite scroll on cached data. --- src/js/controllers/walletDetails.js | 83 +++++++++++++++++------------ www/views/walletDetails.html | 2 +- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 6df56c943..59c0ddb20 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -1,9 +1,10 @@ 'use strict'; angular.module('copayApp.controllers').controller('walletDetailsController', function($scope, $rootScope, $interval, $timeout, $filter, $log, $ionicModal, $ionicPopover, $state, $stateParams, $ionicHistory, profileService, lodash, configService, platformInfo, walletService, txpModalService, externalLinkService, popupService, addressbookService, sendFlowService, storageService, $ionicScrollDelegate, $window, bwcError, gettextCatalog, timeService, feeService, appConfigService, rateService, walletHistoryService) { - - var HISTORY_SHOW_LIMIT = 10; - var currentTxHistoryPage = 0; + // Desktop can display 13 rows of transactions, bump it up to a nice round 15. + var DISPLAY_PAGE_SIZE = 15; + var currentTxHistoryDisplayPage = 0; + var completeTxHistory = [] var listeners = []; // For gradual migration for doing it properly @@ -15,9 +16,12 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun updateTxHistoryFailed: false }; + // Need flag for when to allow infinite scroll at bottom + // - ie not when loading initial data and there is no more cached data + $scope.amountIsCollapsible = false; $scope.color = '#888888'; - $scope.completeTxHistory = []; + $scope.filteredTxHistory = []; $scope.isCordova = platformInfo.isCordova; $scope.isAndroid = platformInfo.isAndroid; @@ -27,9 +31,11 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.requiresMultipleSignatures = false; $scope.showBalanceButton = false; $scope.status = null; - $scope.txHistory = []; + // Displaying 50 transactions when entering the screen takes a while, so only display a subset + // of everything we have, not the complete history. + $scope.txHistory = []; // This is what is displayed $scope.txHistorySearchResults = []; - $scope.txHistoryShowMore = false; + //$scope.txHistoryShowMore = false; // Is this used anywhere? $scope.txps = []; $scope.updatingStatus = false; $scope.updateStatusError = null; @@ -217,9 +223,9 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun t.alternativeAmountStr = r.toFixed(2) + ' ' + fiatCode; }); console.log('pagination Got tx history old way'); - $scope.completeTxHistory = txHistory; + completeTxHistory = txHistory; - $scope.showHistory(); + //$scope.showHistory(); $timeout(function() { $scope.$apply(); }); @@ -256,7 +262,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun walletHistoryService.getCachedTxHistory($scope.wallet.id, function onGetCachedTxHistory(err, txHistory){ $scope.vm.gettingCachedHistory = false; if (err) { - // Don't display an error because we are also requesting the histroy. + // Don't display an error because we are also requesting the history. $log.error('Error getting cached tx history.', err); return; } @@ -267,27 +273,24 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } console.log('pagination Got cached txs, count: ', txHistory.length); - - /* - var shortHistory = []; - if (txHistory.length > 0) { - shortHistory = [ - txHistory[0] - ]; - } - txHistory = shortHistory; - */ - formatTxHistoryForDisplay(txHistory); - $scope.completeTxHistory = txHistory; - $scope.showHistory(); + completeTxHistory = txHistory; + showHistory(); + console.log('pagination Showing tx history items:', $scope.txHistory.length); $scope.$apply(); console.log('pagination displayed cached history.'); }); } function updateTxHistoryFromSmallCache(getLatest) { + if (completeTxHistory.length > $scope.txHistory.length) { + console.log('pagination Showing history we already have.'); + currentTxHistoryDisplayPage++; + showHistory(); + return + } + walletHistoryService.updateTxHistoryByPage($scope.wallet, getLatest, true, function onUpdateTxHistoryByPage(err, txHistory) { console.log('pagination returned'); $scope.vm.gettingInitialHistory = false; @@ -300,18 +303,20 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun console.log('pagination txs returned in history: ' + txHistory.length); formatTxHistoryForDisplay(txHistory); - $scope.completeTxHistory = txHistory; - $scope.showHistory(); + completeTxHistory = txHistory; + showHistory(); $scope.$apply(); }); } - $scope.showHistory = function() { - if ($scope.completeTxHistory) { - $scope.txHistory = $scope.completeTxHistory.slice(0, (currentTxHistoryPage + 1) * HISTORY_SHOW_LIMIT); - $scope.txHistoryShowMore = $scope.completeTxHistory.length > $scope.txHistory.length; + + function showHistory() { + if (completeTxHistory) { + $scope.txHistory = completeTxHistory.slice(0, (currentTxHistoryDisplayPage + 1) * DISPLAY_PAGE_SIZE); + $scope.txHistoryShowMore = completeTxHistory.length > $scope.txHistory.length; } - }; + } + $scope.getDate = function(txCreated) { var date = new Date(txCreated * 1000); @@ -350,22 +355,34 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun return !tx.confirmations || tx.confirmations === 0; }; - + // on-infinite="showMore()" $scope.showMore = function() { + console.log('pagination showMore()'); if ($scope.vm.updatingTxHistory) { return; } + + // Check if we have more than we are displaying + if (completeTxHistory.length > $scope.txHistory.length) { + currentTxHistoryDisplayPage++; + showHistory(); + $scope.$broadcast('scroll.infiniteScrollComplete'); + return; + } + /* $scope.vm.updatingTxHistory = true; $timeout(function() { walletService.getMoreTxs($scope.wallet, function onMoreTxs() { - currentTxHistoryPage++; - $scope.showHistory(); + currentTxHistoryDisplayPage++; + //$scope.showHistory(); $scope.$broadcast('scroll.infiniteScrollComplete'); $scope.vm.updatingTxHistory = false; }); }, 100); + */ }; + // on-refresh="onRefresh()" $scope.onRefresh = function() { $timeout(function() { $scope.$broadcast('scroll.refreshComplete'); @@ -376,7 +393,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.updateAll = function(force, cb)  { updateStatus(force); //updateTxHistory(cb); - updateTxHistoryFromSmallCache(); + //updateTxHistoryFromSmallCache(); }; $scope.hideToggle = function() { diff --git a/www/views/walletDetails.html b/www/views/walletDetails.html index 2548aa4b9..ea1afb197 100644 --- a/www/views/walletDetails.html +++ b/www/views/walletDetails.html @@ -306,7 +306,7 @@
From 0bd94601aed7e3714b41e69667d5c08e78b5f218 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Tue, 21 Aug 2018 09:17:56 +1200 Subject: [PATCH 06/15] Controlling when infinite scroll is available. --- src/js/controllers/walletDetails.js | 7 +++++-- www/views/walletDetails.html | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 59c0ddb20..173cb73d2 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -9,6 +9,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun // For gradual migration for doing it properly $scope.vm = { + allowInfiniteScroll: false, gettingCachedHistory: true, gettingInitialHistory: true, updatingTxHistory: false, @@ -35,7 +36,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun // of everything we have, not the complete history. $scope.txHistory = []; // This is what is displayed $scope.txHistorySearchResults = []; - //$scope.txHistoryShowMore = false; // Is this used anywhere? $scope.txps = []; $scope.updatingStatus = false; $scope.updateStatusError = null; @@ -258,6 +258,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun }); } + function updateTxHistoryUsingCachedData() { walletHistoryService.getCachedTxHistory($scope.wallet.id, function onGetCachedTxHistory(err, txHistory){ $scope.vm.gettingCachedHistory = false; @@ -313,7 +314,9 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun function showHistory() { if (completeTxHistory) { $scope.txHistory = completeTxHistory.slice(0, (currentTxHistoryDisplayPage + 1) * DISPLAY_PAGE_SIZE); - $scope.txHistoryShowMore = completeTxHistory.length > $scope.txHistory.length; + $scope.vm.allowInfiniteScroll = completeTxHistory.length > $scope.txHistory.length || !$scope.vm.gettingInitialHistory; + } else { + $scope.vm.allowInfiniteScroll = false; } } diff --git a/www/views/walletDetails.html b/www/views/walletDetails.html index ea1afb197..cb250a0ed 100644 --- a/www/views/walletDetails.html +++ b/www/views/walletDetails.html @@ -306,7 +306,7 @@
From 78f0ff28cdc319df55b778644a273cc313fdaebc Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Tue, 21 Aug 2018 12:43:03 +1200 Subject: [PATCH 07/15] Getting earlier transactions with pagination. --- src/js/controllers/walletDetails.js | 44 +++--- src/js/services/wallet-history.service.js | 183 ++++++++++++++++------ 2 files changed, 163 insertions(+), 64 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index 173cb73d2..d22ab388f 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -198,6 +198,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun }); }; + var updateTxHistory = function(cb) { if (!cb) cb = function() {}; $scope.vm.updateTxHistoryFailed = false; @@ -233,6 +234,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun }); }); }; + function applyCurrencyAliases(txHistory) { var defaults = configService.getDefaults(); @@ -259,7 +261,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } - function updateTxHistoryUsingCachedData() { + function updateTxHistoryFromCachedData() { walletHistoryService.getCachedTxHistory($scope.wallet.id, function onGetCachedTxHistory(err, txHistory){ $scope.vm.gettingCachedHistory = false; if (err) { @@ -277,27 +279,24 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun formatTxHistoryForDisplay(txHistory); completeTxHistory = txHistory; - showHistory(); + showHistory(false); console.log('pagination Showing tx history items:', $scope.txHistory.length); $scope.$apply(); console.log('pagination displayed cached history.'); }); } - function updateTxHistoryFromSmallCache(getLatest) { - if (completeTxHistory.length > $scope.txHistory.length) { - console.log('pagination Showing history we already have.'); - currentTxHistoryDisplayPage++; - showHistory(); - return - } + function fetchAndShowTxHistory(getLatest, flushCacheOnNew) { + $scope.vm.updatingTxHistory = true; - walletHistoryService.updateTxHistoryByPage($scope.wallet, getLatest, true, function onUpdateTxHistoryByPage(err, txHistory) { + walletHistoryService.updateLocalTxHistoryByPage($scope.wallet, getLatest, flushCacheOnNew, function onUpdateLocalTxHistoryByPage(err, txHistory) { console.log('pagination returned'); $scope.vm.gettingInitialHistory = false; + $scope.vm.updatingTxHistory = false; + $scope.$broadcast('scroll.infiniteScrollComplete'); + if (err) { console.error('pagination Failed to get history.', err); - $scope.txHistory = null; $scope.vm.updateTxHistoryFailed = true; return; } @@ -305,16 +304,17 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun formatTxHistoryForDisplay(txHistory); completeTxHistory = txHistory; - showHistory(); + showHistory(true); $scope.$apply(); }); } - function showHistory() { + function showHistory(showAll) { if (completeTxHistory) { - $scope.txHistory = completeTxHistory.slice(0, (currentTxHistoryDisplayPage + 1) * DISPLAY_PAGE_SIZE); + $scope.txHistory = showAll ? completeTxHistory : completeTxHistory.slice(0, (currentTxHistoryDisplayPage + 1) * DISPLAY_PAGE_SIZE); $scope.vm.allowInfiniteScroll = completeTxHistory.length > $scope.txHistory.length || !$scope.vm.gettingInitialHistory; + console.log('pagination Showing txs: ', $scope.txHistory.length); } else { $scope.vm.allowInfiniteScroll = false; } @@ -372,6 +372,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.$broadcast('scroll.infiniteScrollComplete'); return; } + + fetchAndShowTxHistory(false, false); /* $scope.vm.updatingTxHistory = true; $timeout(function() { @@ -393,10 +395,11 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.updateAll(true); }; - $scope.updateAll = function(force, cb)  { - updateStatus(force); + $scope.updateAll = function(forceStatusUpdate, getLatestTx, flushTxCacheOnNew)  { + console.log('pagination updateAll()'); + updateStatus(forceStatusUpdate); //updateTxHistory(cb); - //updateTxHistoryFromSmallCache(); + fetchAndShowTxHistory(getLatestTx, flushTxCacheOnNew); }; $scope.hideToggle = function() { @@ -538,10 +541,11 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun var refreshInterval; $scope.$on("$ionicView.afterEnter", function(event, data) { - updateTxHistoryUsingCachedData(); - $scope.updateAll(); + updateTxHistoryFromCachedData(); + $scope.updateAll(false, true, true); refreshAmountSection(); - refreshInterval = $interval($scope.onRefresh, 10 * 1000); + //refreshInterval = $interval($scope.onRefresh, 10 * 1000); + //refreshInterval = $interval($scope.onRefresh, 120 * 1000); // For testing }); $scope.$on("$ionicView.afterLeave", function(event, data) { diff --git a/src/js/services/wallet-history.service.js b/src/js/services/wallet-history.service.js index 3679dd088..00847cbbf 100644 --- a/src/js/services/wallet-history.service.js +++ b/src/js/services/wallet-history.service.js @@ -7,32 +7,109 @@ .factory('walletHistoryService', walletHistoryService); function walletHistoryService(configService, storageService, lodash, $log, txFormatService) { - // 8 Transactions fit on an iPhone Plus screen when in Wallet Details. - // Make it a little bit bigger so it doesn't have to load more immediately - var PAGE_SIZE = 50 / 1.5; + //var PAGE_SIZE = 50; + var PAGE_SIZE = 20; // For dev only // How much to overlap on each end of the page, for mitigating inconsistent sort order. - var PAGE_OVERLAP_FRACTION = 0.5; + var PAGE_OVERLAP_FRACTION = 0.2; + var PAGE_OVERLAP = Math.floor(PAGE_SIZE * PAGE_OVERLAP_FRACTION); + // The amount of transactions in the new overlapping resultset that we already know about. + // If we know about at least this many, then there are probably no gaps. + var MIN_KNOWN_TX_OVERLAP = Math.floor(PAGE_OVERLAP * 0.5); var SAFE_CONFIRMATIONS = 6; var service = { getCachedTxHistory: getCachedTxHistory, - updateTxHistoryByPage: updateTxHistoryByPage + updateLocalTxHistoryByPage: updateLocalTxHistoryByPage, }; return service; + function addEarlyTransactions(walletId, cachedTxs, newTxs) { + + var cachedTxIds = {}; + cachedTxs.forEach(function forCachedTx(tx){ + cachedTxIds[tx.txid] = true; + }); + + var someTransactionWereNew = false; + var overlappingTxsCount = 0; + + newTxs.forEach(function forNewTx(tx){ + if (cachedTxIds[tx.txid]) { + overlappingTxsCount++; + } else { + someTransactionWereNew = true; + cachedTxs.push(tx); + } + }); + + console.log('pagination Overlapping transactions:', overlappingTxsCount); + if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good + if (someTransactionWereNew) { + console.log('pagination someTransactionsWereNew'); + saveTxHistory(walletId, cachedTxs); + } + return cachedTxs; + } else { + // We might be missing some txs. + console.error('We might be missing some txs in the history.'); + // Our history is wrong, so remove it - we could instead, try to fetch data that was not so early. + storageService.removeTxHistory(walletId, function onRemoveTxHistory(){}); + return []; + } + + } + + function addLatestTransactions(cachedTxs, newTxs) { + } + + // Only clear the cache once we have received new transactions from the server. + /** + * @param {function(err, txs)} cb - transactions is always an array, may be empty + */ + function fetchTxHistoryByPage(wallet, start, cb) { + var skip = Math.max(0, start - PAGE_OVERLAP); + var limit = PAGE_SIZE; + + var opts = { + skip: skip, + limit: limit + }; + wallet.getTxHistory(opts, function onTxHistory(err, txsFromServer) { + if (err) { + return cb(err, []); + } + + if (txsFromServer.length === 0) { + return cb(null, []); + } + console.log('pagination Transactions fetched:', txsFromServer.length); + + var processedTxs = processNewTxs(wallet, txsFromServer); + + /* + if (getLatest) { + console.log('pagination Saving retrieved txs.'); + saveTxHistory(wallet, processedTxs); + } + */ + + return cb(null, processedTxs); + }); + } + /** * @param {string} walletId - * @param {function(error, txs)} cb + * @param {function(error, txs)} cb - txs is always an array, may be empty */ function getCachedTxHistory(walletId, cb) { storageService.getTxHistory(walletId, function onGetTxHistory(err, txHistoryString){ if (err) { - return cb(err); + return cb(err, []); } if (!txHistoryString) { - return cb(null, txHistoryString); + return cb(null, []); } try { @@ -40,7 +117,7 @@ return cb(null, txHistory); } catch (e) { $log.error('Failed to parse tx history.', e); - return cb(e); + return cb(e, []); } }); } @@ -83,46 +160,64 @@ return processedTxs; }; - /** - * A small cache of up to the 50 most recent transactions - */ - function saveTxHistory(processedTxs, walletId) { + function saveTxHistory(walletId, processedTxs) { + console.log('pagination Saving transactions:', processedTxs.length); storageService.setTxHistory(processedTxs, walletId, function onSetTxHistory(error){ - // Looks like callback only gets called on error - $log.error('pagination Failed to save tx history.', error); - }); - - } - - // Only clear the cache once we have received new transactions from the server. - function updateTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) { - var skip = 0; - var limit = Math.floor(PAGE_SIZE * (1 + PAGE_OVERLAP_FRACTION)); - - var opts = { - skip: skip, - limit: limit - }; - wallet.getTxHistory(opts, function onTxHistory(err, txsFromServer) { - if (err) { - return cb(err); + if (error) { + $log.error('pagination Failed to save tx history.', error); + } else { + console.log('pagination Save successful.'); } - - if (!txsFromServer.length) { - return cb(null, []); - } - - var processedTxs = processNewTxs(wallet, txsFromServer); - - if (getLatest) { - console.log('pagination Saving retrieved txs.'); - saveTxHistory(wallet, processedTxs); - } - - return cb(null, processedTxs); }); } + + function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) { + + if (flushCacheOnNew) { + console.log('pagination Getting latest txs.'); + fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){ + if (err) { + return cb(err, txs); + } + saveTxHistory(wallet.id, txs); + return cb(null, txs); + }); + } else { + console.log('pagination Getting early txs.'); + getCachedTxHistory(wallet.id, function onCachedHistory(err, cachedTxs){ + if (err) { + $log.error('Failed to get cached tx history.', err); + return cb(err, []); + } + + var start = getLatest ? 0 : cachedTxs.length; + console.log('pagination Transaction fetch start:', start); + fetchTxHistoryByPage(wallet, start, function onFetchHistory(err, fetchedTxs){ + if (err) { + return cb(err); + } + + if (fetchedTxs.length === 0) { + return cb(null, cachedTxs); + } + + var txs = []; + if (getLatest) { + txs = addLatestTransactions(wallet.id, cachedTxs, fetchedTxs); + } else { + txs = addEarlyTransactions(wallet.id, cachedTxs, fetchedTxs); + } + return cb(null, txs); + }); + + + }); + } + } + + + } From d5f01e9713b5c7338662900f8679e631e598880e Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Tue, 21 Aug 2018 21:36:55 +0200 Subject: [PATCH 08/15] stop fetching the wallet history when everything is fetched --- src/js/controllers/walletDetails.js | 54 +++++-------------- src/js/services/wallet-history.service.js | 63 +++++++++++++++++++++-- 2 files changed, 72 insertions(+), 45 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index d22ab388f..fece19906 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -13,6 +13,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun gettingCachedHistory: true, gettingInitialHistory: true, updatingTxHistory: false, + fetchedAllTxHistory: false, //updateTxHistoryError: false updateTxHistoryFailed: false }; @@ -108,6 +109,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.updatingStatus = true; $scope.updateStatusError = null; $scope.walletNotRegistered = false; + $scope.vm.fetchedAllTxHistory = false; walletService.getStatus($scope.wallet, { force: !!force, @@ -198,44 +200,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun }); }; - - var updateTxHistory = function(cb) { - if (!cb) cb = function() {}; - $scope.vm.updateTxHistoryFailed = false; - $scope.updatingTxHistoryProgress = 0; - - feeService.getFeeLevels($scope.wallet.coin, function(err, levels) { - walletService.getTxHistory($scope.wallet, { - feeLevels: levels - }, function(err, txHistory) { - $scope.vm.gettingInitialHistory = false; - if (err) { - $scope.txHistory = null; - $scope.vm.updateTxHistoryFailed = true; - return; - } - - applyCurrencyAliases(txHistory); - - var config = configService.getSync(); - var fiatCode = config.wallet.settings.alternativeIsoCode; - lodash.each(txHistory, function(t) { - var r = rateService.toFiat(t.amount, fiatCode, $scope.wallet.coin); - t.alternativeAmountStr = r.toFixed(2) + ' ' + fiatCode; - }); - console.log('pagination Got tx history old way'); - completeTxHistory = txHistory; - - //$scope.showHistory(); - $timeout(function() { - $scope.$apply(); - }); - return cb(); - }); - }); - }; - - function applyCurrencyAliases(txHistory) { var defaults = configService.getDefaults(); var configCache = configService.getSync(); @@ -289,7 +253,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun function fetchAndShowTxHistory(getLatest, flushCacheOnNew) { $scope.vm.updatingTxHistory = true; - walletHistoryService.updateLocalTxHistoryByPage($scope.wallet, getLatest, flushCacheOnNew, function onUpdateLocalTxHistoryByPage(err, txHistory) { + walletHistoryService.updateLocalTxHistoryByPage($scope.wallet, getLatest, flushCacheOnNew, function onUpdateLocalTxHistoryByPage(err, txHistory, fetchedAllTransactions) { console.log('pagination returned'); $scope.vm.gettingInitialHistory = false; $scope.vm.updatingTxHistory = false; @@ -300,6 +264,12 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.vm.updateTxHistoryFailed = true; return; } + + if (fetchedAllTransactions) { + console.log("All transactions seem to be fetched.."); + $scope.vm.fetchedAllTxHistory = true; + } + console.log('pagination txs returned in history: ' + txHistory.length); formatTxHistoryForDisplay(txHistory); @@ -313,7 +283,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun function showHistory(showAll) { if (completeTxHistory) { $scope.txHistory = showAll ? completeTxHistory : completeTxHistory.slice(0, (currentTxHistoryDisplayPage + 1) * DISPLAY_PAGE_SIZE); - $scope.vm.allowInfiniteScroll = completeTxHistory.length > $scope.txHistory.length || !$scope.vm.gettingInitialHistory; + $scope.vm.allowInfiniteScroll = !$scope.vm.fetchedAllTxHistory;//(completeTxHistory.length > $scope.txHistory.length || !$scope.vm.gettingInitialHistory) || (!$scope.vm.gettingInitialHistory && !$scope.vm.fetchedAllTxHistory); console.log('pagination Showing txs: ', $scope.txHistory.length); } else { $scope.vm.allowInfiniteScroll = false; @@ -392,7 +362,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $timeout(function() { $scope.$broadcast('scroll.refreshComplete'); }, 300); - $scope.updateAll(true); + $scope.updateAll(true, true, false); }; $scope.updateAll = function(forceStatusUpdate, getLatestTx, flushTxCacheOnNew)  { @@ -544,7 +514,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun updateTxHistoryFromCachedData(); $scope.updateAll(false, true, true); refreshAmountSection(); - //refreshInterval = $interval($scope.onRefresh, 10 * 1000); + refreshInterval = $interval($scope.onRefresh, 10 * 1000); //refreshInterval = $interval($scope.onRefresh, 120 * 1000); // For testing }); diff --git a/src/js/services/wallet-history.service.js b/src/js/services/wallet-history.service.js index 00847cbbf..e8ba8cf52 100644 --- a/src/js/services/wallet-history.service.js +++ b/src/js/services/wallet-history.service.js @@ -18,12 +18,46 @@ var SAFE_CONFIRMATIONS = 6; + var allTransactionsFetched = false; var service = { getCachedTxHistory: getCachedTxHistory, updateLocalTxHistoryByPage: updateLocalTxHistoryByPage, }; return service; +/* + function hasAllTransactionsFetched(walletId, cachedTxs, newTxs) { + var cachedTxIds = {}; + cachedTxs.forEach(function forCachedTx(tx){ + cachedTxIds[tx.txid] = true; + }); + + var someTransactionWereNew = false; + var overlappingTxsCount = 0; + + newTxs.forEach(function forNewTx(tx){ + if (cachedTxIds[tx.txid]) { + overlappingTxsCount++; + } else { + someTransactionWereNew = true; + } + }); + + console.log('pagination Overlapping transactions:', overlappingTxsCount); + if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good + if (!someTransactionWereNew && overlappingTxsCount === newTxs.length) { + console.log("We probably have all of the transactions fetched!!") + return true; + } + } else { + console.log("Something went wrong") + return true; // Something went wrong, so stop fetching.. + } + return false; + + } +*/ + function addEarlyTransactions(walletId, cachedTxs, newTxs) { var cachedTxIds = {}; @@ -48,6 +82,9 @@ if (someTransactionWereNew) { console.log('pagination someTransactionsWereNew'); saveTxHistory(walletId, cachedTxs); + } else if (overlappingTxsCount === newTxs.length) { + console.log('We probably have all transactions now'); + allTransactionsFetched = true; } return cachedTxs; } else { @@ -60,7 +97,26 @@ } - function addLatestTransactions(cachedTxs, newTxs) { + function addLatestTransactions(walletId, cachedTxs, newTxs) { + var cachedTxIds = {}; + var someTransactionWereNew = false; + cachedTxs.forEach(function forCachedTx(tx){ + cachedTxIds[tx.txid] = true; + }); + + newTxs.forEach(function forNewTx(tx){ + if (!cachedTxIds[tx.txid]) { + console.log("Brand new transactions pushed to top of the cache.") + someTransactionWereNew = true; + cachedTxs.unshift(tx); + } + }); + + if (someTransactionWereNew) { + saveTxHistory(walletId, cachedTxs); + } + + return cachedTxs; } // Only clear the cache once we have received new transactions from the server. @@ -199,7 +255,7 @@ } if (fetchedTxs.length === 0) { - return cb(null, cachedTxs); + return cb(null, cachedTxs, true /*fetchedAllTransactions*/); } var txs = []; @@ -207,11 +263,12 @@ txs = addLatestTransactions(wallet.id, cachedTxs, fetchedTxs); } else { txs = addEarlyTransactions(wallet.id, cachedTxs, fetchedTxs); + return cb(null, txs, allTransactionsFetched/*, hasAllTransactionsFetched(wallet.id, cachedTxs, fetchedTxs)*/); } return cb(null, txs); }); - + }); } } From ad6a1fbe8dbfcb4f07d68cff772bb06840043849 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Wed, 22 Aug 2018 19:28:24 +1200 Subject: [PATCH 09/15] Adding latest transactions. --- src/js/controllers/walletDetails.js | 26 ++++------ src/js/services/wallet-history.service.js | 58 ++++++++++++++++------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index d22ab388f..fc45d70f6 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -191,7 +191,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun if (err) return; $timeout(function() { walletService.startScan($scope.wallet, function() { - $scope.updateAll(); + $scope.updateAll(true, true); $scope.$apply(); }); }); @@ -287,6 +287,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } function fetchAndShowTxHistory(getLatest, flushCacheOnNew) { + console.log('pagination fetchAndShowTxHistory() getLatest:', getLatest, ', flushCacheOnNew:', flushCacheOnNew); $scope.vm.updatingTxHistory = true; walletHistoryService.updateLocalTxHistoryByPage($scope.wallet, getLatest, flushCacheOnNew, function onUpdateLocalTxHistoryByPage(err, txHistory) { @@ -374,17 +375,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } fetchAndShowTxHistory(false, false); - /* - $scope.vm.updatingTxHistory = true; - $timeout(function() { - walletService.getMoreTxs($scope.wallet, function onMoreTxs() { - currentTxHistoryDisplayPage++; - //$scope.showHistory(); - $scope.$broadcast('scroll.infiniteScrollComplete'); - $scope.vm.updatingTxHistory = false; - }); - }, 100); - */ }; // on-refresh="onRefresh()" @@ -392,14 +382,14 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $timeout(function() { $scope.$broadcast('scroll.refreshComplete'); }, 300); - $scope.updateAll(true); + $scope.updateAll(true, false); }; - $scope.updateAll = function(forceStatusUpdate, getLatestTx, flushTxCacheOnNew)  { + $scope.updateAll = function(forceStatusUpdate, flushTxCacheOnNew)  { console.log('pagination updateAll()'); updateStatus(forceStatusUpdate); //updateTxHistory(cb); - fetchAndShowTxHistory(getLatestTx, flushTxCacheOnNew); + fetchAndShowTxHistory(true, flushTxCacheOnNew); }; $scope.hideToggle = function() { @@ -529,11 +519,11 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun listeners = [ $rootScope.$on('bwsEvent', function(e, walletId) { if (walletId == $scope.wallet.id && e.type != 'NewAddress') - $scope.updateAll(); + $scope.updateAll(false, false); }), $rootScope.$on('Local/TxAction', function(e, walletId) { if (walletId == $scope.wallet.id) - $scope.updateAll(); + $scope.updateAll(false, false); }), ]; }); @@ -542,7 +532,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.$on("$ionicView.afterEnter", function(event, data) { updateTxHistoryFromCachedData(); - $scope.updateAll(false, true, true); + $scope.updateAll(false, true); refreshAmountSection(); //refreshInterval = $interval($scope.onRefresh, 10 * 1000); //refreshInterval = $interval($scope.onRefresh, 120 * 1000); // For testing diff --git a/src/js/services/wallet-history.service.js b/src/js/services/wallet-history.service.js index 00847cbbf..8d6345e1d 100644 --- a/src/js/services/wallet-history.service.js +++ b/src/js/services/wallet-history.service.js @@ -31,21 +31,21 @@ cachedTxIds[tx.txid] = true; }); - var someTransactionWereNew = false; + var someTransactionsWereNew = false; var overlappingTxsCount = 0; newTxs.forEach(function forNewTx(tx){ if (cachedTxIds[tx.txid]) { overlappingTxsCount++; } else { - someTransactionWereNew = true; + someTransactionsWereNew = true; cachedTxs.push(tx); } }); - console.log('pagination Overlapping transactions:', overlappingTxsCount); + console.log('pagination Early transactions overlapping:', overlappingTxsCount); if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good - if (someTransactionWereNew) { + if (someTransactionsWereNew) { console.log('pagination someTransactionsWereNew'); saveTxHistory(walletId, cachedTxs); } @@ -60,7 +60,42 @@ } - function addLatestTransactions(cachedTxs, newTxs) { + function addLatestTransactions(walletId, cachedTxs, newTxs) { + var cachedTxIds = {}; + cachedTxs.forEach(function forCachedTx(tx){ + cachedTxIds[tx.txid] = true; + }); + + var someTransactionsWereNew = false; + var overlappingTxsCount = 0; + var uniqueNewTxs = []; + + newTxs.forEach(function forNewTx(tx){ + if (cachedTxIds[tx.txid]) { + overlappingTxsCount++; + } else { + someTransactionWereNew = true; + uniqueNewTxs.push(tx); + } + }); + + console.log('pagination Latest transactions overlapping:', overlappingTxsCount); + if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good + if (someTransactionsWereNew) { + console.log('pagination someTransactionsWereNew'); + var allTxs = uniqueNewTxs.concat(cachedTxs); + saveTxHistory(walletId, allTxs); + return allTxs; + } else { + return cachedTxs; + } + } else { + // We might be missing some txs. + // Our history is wrong, so just include the latest ones + saveTxHistory(walletId, newTxs); + return newTxs; + } + } // Only clear the cache once we have received new transactions from the server. @@ -87,13 +122,6 @@ var processedTxs = processNewTxs(wallet, txsFromServer); - /* - if (getLatest) { - console.log('pagination Saving retrieved txs.'); - saveTxHistory(wallet, processedTxs); - } - */ - return cb(null, processedTxs); }); } @@ -154,8 +182,6 @@ $log.debug('Ignoring duplicate TX in history: ' + tx.txid) } }); - - // Update notes? return processedTxs; }; @@ -175,7 +201,7 @@ function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) { if (flushCacheOnNew) { - console.log('pagination Getting latest txs.'); + console.log('pagination Getting latest txs, will then flush cache.'); fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){ if (err) { return cb(err, txs); @@ -184,7 +210,7 @@ return cb(null, txs); }); } else { - console.log('pagination Getting early txs.'); + console.log('pagination Getting txs to add to cache.'); getCachedTxHistory(wallet.id, function onCachedHistory(err, cachedTxs){ if (err) { $log.error('Failed to get cached tx history.', err); From 745737ef73d5b38511062b0febe538fd081b67d9 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Wed, 22 Aug 2018 19:39:32 +1200 Subject: [PATCH 10/15] Adding missing parameter. --- src/js/controllers/walletDetails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index d0afee8ca..e5f85d21b 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -339,7 +339,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun // Check if we have more than we are displaying if (completeTxHistory.length > $scope.txHistory.length) { currentTxHistoryDisplayPage++; - showHistory(); + showHistory(false); $scope.$broadcast('scroll.infiniteScrollComplete'); return; } From e6beb6fed12822c0cd2998640ed30d25121f4a7a Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Wed, 22 Aug 2018 19:51:10 +1200 Subject: [PATCH 11/15] Displaying more cached data while waiting for first tx history fetch. --- src/js/controllers/walletDetails.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index e5f85d21b..c52982445 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -267,7 +267,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } if (fetchedAllTransactions) { - console.log("All transactions seem to be fetched.."); + console.log("pagination Fetched all transactions."); $scope.vm.fetchedAllTxHistory = true; } @@ -284,7 +284,7 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun function showHistory(showAll) { if (completeTxHistory) { $scope.txHistory = showAll ? completeTxHistory : completeTxHistory.slice(0, (currentTxHistoryDisplayPage + 1) * DISPLAY_PAGE_SIZE); - $scope.vm.allowInfiniteScroll = !$scope.vm.fetchedAllTxHistory;//(completeTxHistory.length > $scope.txHistory.length || !$scope.vm.gettingInitialHistory) || (!$scope.vm.gettingInitialHistory && !$scope.vm.fetchedAllTxHistory); + $scope.vm.allowInfiniteScroll = !$scope.vm.fetchedAllTxHistory && !(completeTxHistory.length === $scope.txHistory.length && $scope.vm.gettingInitialHistory); console.log('pagination Showing txs: ', $scope.txHistory.length); } else { $scope.vm.allowInfiniteScroll = false; @@ -332,18 +332,19 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun // on-infinite="showMore()" $scope.showMore = function() { console.log('pagination showMore()'); - if ($scope.vm.updatingTxHistory) { - return; - } - // Check if we have more than we are displaying if (completeTxHistory.length > $scope.txHistory.length) { + console.log('pagination We have more data than we are displaying.'); currentTxHistoryDisplayPage++; showHistory(false); $scope.$broadcast('scroll.infiniteScrollComplete'); return; } + if ($scope.vm.updatingTxHistory) { + return; + } + fetchAndShowTxHistory(false, false); }; From feca8b5807cc00f6a1b4da8aeeca03a4d1bc5947 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Wed, 22 Aug 2018 20:01:30 +1200 Subject: [PATCH 12/15] Checking every time we get earlier data, if all transactions have been fetched. --- src/js/services/wallet-history.service.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/services/wallet-history.service.js b/src/js/services/wallet-history.service.js index 1f9e03152..a607fc870 100644 --- a/src/js/services/wallet-history.service.js +++ b/src/js/services/wallet-history.service.js @@ -269,6 +269,7 @@ if (getLatest) { txs = addLatestTransactions(wallet.id, cachedTxs, fetchedTxs); } else { + allTransactionsFetched = false; txs = addEarlyTransactions(wallet.id, cachedTxs, fetchedTxs); return cb(null, txs, allTransactionsFetched/*, hasAllTransactionsFetched(wallet.id, cachedTxs, fetchedTxs)*/); } From 4cf268682bf0da47992a6f3a7a24cf2674271c65 Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Wed, 22 Aug 2018 16:21:57 +0200 Subject: [PATCH 13/15] removed comments --- src/js/controllers/walletDetails.js | 11 ----- src/js/services/wallet-history.service.js | 51 ++--------------------- 2 files changed, 3 insertions(+), 59 deletions(-) diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index c52982445..728238d50 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -239,23 +239,18 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun return; } - console.log('pagination Got cached txs, count: ', txHistory.length); formatTxHistoryForDisplay(txHistory); completeTxHistory = txHistory; showHistory(false); - console.log('pagination Showing tx history items:', $scope.txHistory.length); $scope.$apply(); - console.log('pagination displayed cached history.'); }); } function fetchAndShowTxHistory(getLatest, flushCacheOnNew) { - console.log('pagination fetchAndShowTxHistory() getLatest:', getLatest, ', flushCacheOnNew:', flushCacheOnNew); $scope.vm.updatingTxHistory = true; walletHistoryService.updateLocalTxHistoryByPage($scope.wallet, getLatest, flushCacheOnNew, function onUpdateLocalTxHistoryByPage(err, txHistory, fetchedAllTransactions) { - console.log('pagination returned'); $scope.vm.gettingInitialHistory = false; $scope.vm.updatingTxHistory = false; $scope.$broadcast('scroll.infiniteScrollComplete'); @@ -267,11 +262,9 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun } if (fetchedAllTransactions) { - console.log("pagination Fetched all transactions."); $scope.vm.fetchedAllTxHistory = true; } - console.log('pagination txs returned in history: ' + txHistory.length); formatTxHistoryForDisplay(txHistory); completeTxHistory = txHistory; @@ -285,7 +278,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun if (completeTxHistory) { $scope.txHistory = showAll ? completeTxHistory : completeTxHistory.slice(0, (currentTxHistoryDisplayPage + 1) * DISPLAY_PAGE_SIZE); $scope.vm.allowInfiniteScroll = !$scope.vm.fetchedAllTxHistory && !(completeTxHistory.length === $scope.txHistory.length && $scope.vm.gettingInitialHistory); - console.log('pagination Showing txs: ', $scope.txHistory.length); } else { $scope.vm.allowInfiniteScroll = false; } @@ -331,10 +323,8 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun // on-infinite="showMore()" $scope.showMore = function() { - console.log('pagination showMore()'); // Check if we have more than we are displaying if (completeTxHistory.length > $scope.txHistory.length) { - console.log('pagination We have more data than we are displaying.'); currentTxHistoryDisplayPage++; showHistory(false); $scope.$broadcast('scroll.infiniteScrollComplete'); @@ -357,7 +347,6 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun }; $scope.updateAll = function(forceStatusUpdate, flushTxCacheOnNew)  { - console.log('pagination updateAll()'); updateStatus(forceStatusUpdate); //updateTxHistory(cb); fetchAndShowTxHistory(true, flushTxCacheOnNew); diff --git a/src/js/services/wallet-history.service.js b/src/js/services/wallet-history.service.js index a607fc870..e10e763e9 100644 --- a/src/js/services/wallet-history.service.js +++ b/src/js/services/wallet-history.service.js @@ -25,39 +25,6 @@ }; return service; -/* - function hasAllTransactionsFetched(walletId, cachedTxs, newTxs) { - var cachedTxIds = {}; - cachedTxs.forEach(function forCachedTx(tx){ - cachedTxIds[tx.txid] = true; - }); - - var someTransactionWereNew = false; - var overlappingTxsCount = 0; - - newTxs.forEach(function forNewTx(tx){ - if (cachedTxIds[tx.txid]) { - overlappingTxsCount++; - } else { - someTransactionWereNew = true; - } - }); - - console.log('pagination Overlapping transactions:', overlappingTxsCount); - if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good - if (!someTransactionWereNew && overlappingTxsCount === newTxs.length) { - console.log("We probably have all of the transactions fetched!!") - return true; - } - } else { - console.log("Something went wrong") - return true; // Something went wrong, so stop fetching.. - } - return false; - - } -*/ - function addEarlyTransactions(walletId, cachedTxs, newTxs) { var cachedTxIds = {}; @@ -77,13 +44,10 @@ } }); - console.log('pagination Early transactions overlapping:', overlappingTxsCount); if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good if (someTransactionsWereNew) { - console.log('pagination someTransactionsWereNew'); saveTxHistory(walletId, cachedTxs); } else if (overlappingTxsCount === newTxs.length) { - console.log('We probably have all transactions now'); allTransactionsFetched = true; } return cachedTxs; @@ -111,15 +75,13 @@ if (cachedTxIds[tx.txid]) { overlappingTxsCount++; } else { - someTransactionWereNew = true; + someTransactionsWereNew = true; uniqueNewTxs.push(tx); } }); - console.log('pagination Latest transactions overlapping:', overlappingTxsCount); if (overlappingTxsCount >= MIN_KNOWN_TX_OVERLAP) { // We are good if (someTransactionsWereNew) { - console.log('pagination someTransactionsWereNew'); var allTxs = uniqueNewTxs.concat(cachedTxs); saveTxHistory(walletId, allTxs); return allTxs; @@ -155,8 +117,7 @@ if (txsFromServer.length === 0) { return cb(null, []); } - console.log('pagination Transactions fetched:', txsFromServer.length); - + var processedTxs = processNewTxs(wallet, txsFromServer); return cb(null, processedTxs); @@ -224,12 +185,9 @@ }; function saveTxHistory(walletId, processedTxs) { - console.log('pagination Saving transactions:', processedTxs.length); storageService.setTxHistory(processedTxs, walletId, function onSetTxHistory(error){ if (error) { $log.error('pagination Failed to save tx history.', error); - } else { - console.log('pagination Save successful.'); } }); } @@ -238,7 +196,6 @@ function updateLocalTxHistoryByPage(wallet, getLatest, flushCacheOnNew, cb) { if (flushCacheOnNew) { - console.log('pagination Getting latest txs, will then flush cache.'); fetchTxHistoryByPage(wallet, 0, function onFetchTxHistory(err, txs){ if (err) { return cb(err, txs); @@ -247,7 +204,6 @@ return cb(null, txs); }); } else { - console.log('pagination Getting txs to add to cache.'); getCachedTxHistory(wallet.id, function onCachedHistory(err, cachedTxs){ if (err) { $log.error('Failed to get cached tx history.', err); @@ -255,7 +211,6 @@ } var start = getLatest ? 0 : cachedTxs.length; - console.log('pagination Transaction fetch start:', start); fetchTxHistoryByPage(wallet, start, function onFetchHistory(err, fetchedTxs){ if (err) { return cb(err); @@ -271,7 +226,7 @@ } else { allTransactionsFetched = false; txs = addEarlyTransactions(wallet.id, cachedTxs, fetchedTxs); - return cb(null, txs, allTransactionsFetched/*, hasAllTransactionsFetched(wallet.id, cachedTxs, fetchedTxs)*/); + return cb(null, txs, allTransactionsFetched); } return cb(null, txs); }); From 43592a16897a5d967b24d89d5d5226ed3625fa28 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Mon, 27 Aug 2018 18:04:55 +1200 Subject: [PATCH 14/15] Fix package.json. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c1f37b2e6..e54e3d14d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "postinstall": "npm run apply:copay && echo && echo \"Repo configured for standard Copay distribution. To switch to the BitPay distribution, run 'npm run apply:bitpay'.\" && echo", "start": "echo && echo \"Choose a distribution by running 'npm run apply:copay' or 'npm run apply:bitpay'.\" && echo", "apply:copay": "npm i fs-extra@0.30 && cd app-template && node apply.js copay && cd .. && npm i", - "apply:bitcoincom": "npm i fs-extra && cd app-template && node apply.js bitcoincom && npm i && cordova prepare", + "apply:bitcoincom": "npm i fs-extra && cd app-template && node apply.js bitcoincom && npm i && cordova prepare && cd ../ && ./fix-asn1.sh", "apply:bitpay": "npm i fs-extra@0.30 && cd app-template && node apply.js bitpay && cd .. && npm i", "unstage-package": "git reset package.json", "clean-all": "git clean -dfx" From 81852836dd71f14cd6fd93c4fa59fd3d43a7b912 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Fri, 7 Sep 2018 01:18:54 +0900 Subject: [PATCH 15/15] Fix : callback the newHistory --- src/js/services/walletService.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 6f0c93697..d29f99272 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -613,8 +613,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim return storageService.setTxHistory(historyToSave, walletId, function() { $log.debug('Tx History saved.'); - - return cb(); + return cb(null, newHistory); }); }); }); @@ -691,8 +690,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim return storageService.setTxHistory(historyToSave, walletId, function() { $log.debug('Tx History saved.'); - - return cb(); + return cb(null, newHistory); }); }); }); @@ -728,7 +726,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }; root.getTx = function(wallet, txid, cb) { - function finish(list) { var tx = lodash.find(list, { txid: txid @@ -745,7 +742,6 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim limitTx: txid }, function(err, txHistory) { if (err) return cb(err); - finish(txHistory); }); }