diff --git a/www/js/controllers/transfer-controllers.js b/www/js/controllers/transfer-controllers.js index 32386d350c6edd75e4a889377eb62bc7a7448889..fb5f53b5bb3c11400462485fb30709eefa54c1f2 100644 --- a/www/js/controllers/transfer-controllers.js +++ b/www/js/controllers/transfer-controllers.js @@ -226,7 +226,8 @@ function TransferModalController($scope, $q, $translate, $timeout, $filter, $foc }; $scope.onAmountChanged = function() { - if ($scope.sending) return; // skip if sending TX + if (!$scope.form || !$scope.form.amount) return; // skip if modal has been destroyed + if ($scope.sending || !$scope.form.amount) return; // skip if sending TX var amount = $scope.formData.amount; if (amount && typeof amount === "string") { diff --git a/www/js/services/tx-services.js b/www/js/services/tx-services.js index e68cd08538ff72bcfb96fc5e91c6abb12de69ad3..0c753ba3d207c2914697877507a980305c3fcf9f 100644 --- a/www/js/services/tx-services.js +++ b/www/js/services/tx-services.js @@ -189,7 +189,8 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services', // get UD history if (csSettings.data.showUDHistory) { - var reduceUdFn = function(res) { + // FIXME: cannot use BMA here, because it return only NOT consumed UD ! + /*var reduceUdFn = function(res) { if (!res || !res.history || !res.history.history) return; _.forEach(res.history.history, function(ud){ if (ud.time < fromTime) return res; // skip to old UD @@ -213,7 +214,26 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services', // get all UD else { jobs.push(BMA.ud.history.all({pubkey: pubkey}).then(reduceUdFn)); - } + }*/ + + // API extension + jobs.push( + api.data.raisePromise.loadUDs({ + pubkey: pubkey, + fromTime: fromTime + }) + .then(function(res) { + if (!res || !res.length) return; + _.forEach(res, function(hits) { + tx.history.push(hits); + }); + }) + + .catch(function(err) { + console.debug('Error while loading UDs history, on extension point.'); + console.error(err); + }) + ); } } diff --git a/www/plugins/es/js/services/tx-services.js b/www/plugins/es/js/services/tx-services.js index 1a1f41e1869a046dad1e159740c14d578d6a7cdd..660e7274925d1597da731e053539791b47c8a5e3 100644 --- a/www/plugins/es/js/services/tx-services.js +++ b/www/plugins/es/js/services/tx-services.js @@ -32,6 +32,8 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu options = options || {}; if (!options.pubkey) deferred.reject('Missing [pubkey] when calling [loadUDs] extension point'); + console.debug('[ES] [tx] Loading UD from time: ' + (options.fromTime || -1)); + $q.all([ // Get currency csCurrency.get(), @@ -47,9 +49,13 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu // Filter memberships using options.fromTime if (options.fromTime !== -1) { memberships = memberships.reduce(function(res, membership) { + // Exclude membership periods when BEFORE formTime if (membership.leaveTime < options.fromTime) return res; - membership.joinTime = Math.max(membership.joinTime, options.fromTime); - return res.concat(membership); + // Do a copy, to avoid to change cached data + return res.concat({ + joinTime: Math.max(membership.joinTime, options.fromTime), + leaveTime: membership.leaveTime + }); }, []); } @@ -89,19 +95,21 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu }) .then(function(res){ if (!res || !res.length) return; - return res.reduce(function(uds, res){ + return res.reduce(function(uds, res) { if (!res.hits.total || !res.hits.hits.length) return res; - return uds.concat(res.hits.hits.reduce(function(res, hit){ + return res.hits.hits.reduce(function(res, hit){ var block = hit._source; + var amount = _powBase(block.dividend, block.unitbase); return res.concat({ + id: [amount, 'ud', block.medianTime].join(':'), time: block.medianTime, - amount: _powBase(block.dividend, block.unitbase), + amount: amount, isUD: true, block_number: block.number }); - }, [])); + }, uds); }, []);