From 18ddf8e29858e3de5f81ef084eff5fdb7d2f793d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 18 Nov 2015 10:24:15 -0300 Subject: [PATCH] fix Units in history after change --- src/js/controllers/index.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 46d7c2e42..0d5902b0c 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -142,7 +142,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r var defaults = configService.getDefaults(); var config = configService.getSync(); - self.usingCustomBWS = config.bwsFor && config.bwsFor[self.walletId] && (config.bwsFor[self.walletId] != defaults.bws.url); + self.usingCustomBWS = config.bwsFor && config.bwsFor[self.walletId] && (config.bwsFor[self.walletId] != defaults.bws.url); }; self.setTab = function(tab, reset, tries, switchState) { @@ -786,11 +786,33 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.updateLocalTxHistory = function(client, cb) { var requestLimit = 6; var walletId = client.credentials.walletId; + var config = configService.getSync().wallet.settings; + + var fixTxsUnit = function(txs) { + if (!txs || !txs[0]) return; + + var cacheUnit = txs[0].amountStr.split(' ')[1]; + console.log('[index.js.794:cacheUnit:]', cacheUnit, config.unitName); //TODO + + if (cacheUnit == config.unitName) + return; + + var name = ' ' + config.unitName; + + $log.debug('Fixing Tx Cache Unit to:' + name) + lodash.each(txs, function(tx) { + + tx.amountStr = profileService.formatAmount(tx.amount, config.unitName) + name; + tx.feeStr = profileService.formatAmount(tx.fees, config.unitName) + name; + }); + }; self.getConfirmedTxs(walletId, function(err, txsFromLocal) { if (err) return cb(err); var endingTxid = txsFromLocal[0] ? txsFromLocal[0].txid : null; + fixTxsUnit(txsFromLocal); + function getNewTxs(newTxs, skip, i_cb) { self.getTxsFromServer(client, skip, endingTxid, requestLimit, function(err, res, shouldContinue) { @@ -807,7 +829,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r return i_cb(null, newTxs); } - if (walletId == profileService.focusedClient.credentials.walletId) + if (walletId == profileService.focusedClient.credentials.walletId) self.txProgress = newTxs.length; $timeout(function() { @@ -822,7 +844,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r var newHistory = lodash.compact(txs.concat(txsFromLocal)); $log.debug('Tx History synced. Total Txs: ' + newHistory.length); - if (walletId == profileService.focusedClient.credentials.walletId) { + if (walletId == profileService.focusedClient.credentials.walletId) { self.completeHistory = newHistory; self.txHistory = newHistory.slice(0, self.historyShowLimit); self.historyShowShowAll = newHistory.length >= self.historyShowLimit; @@ -1137,8 +1159,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/UnitSettingUpdated', function(event) { - self.updateAll(); - self.updateTxHistory(); + self.updateAll({ + triggerTxUpdate: true, + }); self.updateRemotePreferences({ saveAll: true }, function() {