Skip to content
Snippets Groups Projects
Commit 5d96cf4b authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

enh(tx): Revert load UD using BMA (use Cesium+ pod).

fix(tx): Fix UD history, when cache has been enabled
parent f021b984
No related branches found
No related tags found
No related merge requests found
Pipeline #33019 failed
...@@ -226,7 +226,8 @@ function TransferModalController($scope, $q, $translate, $timeout, $filter, $foc ...@@ -226,7 +226,8 @@ function TransferModalController($scope, $q, $translate, $timeout, $filter, $foc
}; };
$scope.onAmountChanged = function() { $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; var amount = $scope.formData.amount;
if (amount && typeof amount === "string") { if (amount && typeof amount === "string") {
......
...@@ -189,7 +189,8 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services', ...@@ -189,7 +189,8 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
// get UD history // get UD history
if (csSettings.data.showUDHistory) { 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; if (!res || !res.history || !res.history.history) return;
_.forEach(res.history.history, function(ud){ _.forEach(res.history.history, function(ud){
if (ud.time < fromTime) return res; // skip to old UD if (ud.time < fromTime) return res; // skip to old UD
...@@ -213,7 +214,26 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services', ...@@ -213,7 +214,26 @@ angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services',
// get all UD // get all UD
else { else {
jobs.push(BMA.ud.history.all({pubkey: pubkey}).then(reduceUdFn)); 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);
})
);
} }
} }
......
...@@ -32,6 +32,8 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu ...@@ -32,6 +32,8 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu
options = options || {}; options = options || {};
if (!options.pubkey) deferred.reject('Missing [pubkey] when calling [loadUDs] extension point'); 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([ $q.all([
// Get currency // Get currency
csCurrency.get(), csCurrency.get(),
...@@ -47,9 +49,13 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu ...@@ -47,9 +49,13 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu
// Filter memberships using options.fromTime // Filter memberships using options.fromTime
if (options.fromTime !== -1) { if (options.fromTime !== -1) {
memberships = memberships.reduce(function(res, membership) { memberships = memberships.reduce(function(res, membership) {
// Exclude membership periods when BEFORE formTime
if (membership.leaveTime < options.fromTime) return res; if (membership.leaveTime < options.fromTime) return res;
membership.joinTime = Math.max(membership.joinTime, options.fromTime); // Do a copy, to avoid to change cached data
return res.concat(membership); 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 ...@@ -89,19 +95,21 @@ angular.module('cesium.es.tx.services', ['ngResource', 'cesium.services', 'cesiu
}) })
.then(function(res){ .then(function(res){
if (!res || !res.length) return; 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; 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 block = hit._source;
var amount = _powBase(block.dividend, block.unitbase);
return res.concat({ return res.concat({
id: [amount, 'ud', block.medianTime].join(':'),
time: block.medianTime, time: block.medianTime,
amount: _powBase(block.dividend, block.unitbase), amount: amount,
isUD: true, isUD: true,
block_number: block.number block_number: block.number
}); });
}, [])); }, uds);
}, []); }, []);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment