From 5d96cf4bfa9035fa019b2ceb056f0aabd97d133d Mon Sep 17 00:00:00 2001 From: Benoit Lavenier <benoit.lavenier@e-is.pro> Date: Mon, 14 Aug 2023 17:31:12 +0200 Subject: [PATCH] enh(tx): Revert load UD using BMA (use Cesium+ pod). fix(tx): Fix UD history, when cache has been enabled --- www/js/controllers/transfer-controllers.js | 3 ++- www/js/services/tx-services.js | 24 ++++++++++++++++++++-- www/plugins/es/js/services/tx-services.js | 20 ++++++++++++------ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/www/js/controllers/transfer-controllers.js b/www/js/controllers/transfer-controllers.js index 32386d350..fb5f53b5b 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 e68cd0853..0c753ba3d 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 1a1f41e18..660e72749 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); }, []); -- GitLab