From b5dd653d9769214b4b731982c99990888109631d Mon Sep 17 00:00:00 2001
From: Benoit Lavenier <benoit.lavenier@e-is.pro>
Date: Mon, 14 Aug 2023 08:35:43 +0200
Subject: [PATCH] fix(tx): TX view: add a delay between many call of
 showMoreTx()

---
 www/js/controllers/wallet-controllers.js | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js
index 20c2f3c8..fd5f693c 100644
--- a/www/js/controllers/wallet-controllers.js
+++ b/www/js/controllers/wallet-controllers.js
@@ -687,6 +687,8 @@ function WalletTxController($scope, $ionicPopover, $state, $timeout, $location,
   'ngInject';
 
   $scope.loading = true;
+  $scope.loadingMore = false;
+  $scope.lastMoreTxTime = null;
   $scope.settings = csSettings.data;
   $scope.listeners = [];
   $scope.qrcodeId = 'qrcode-wallet-tx-' + $scope.$id;
@@ -913,12 +915,19 @@ function WalletTxController($scope, $ionicPopover, $state, $timeout, $location,
     return $scope.goState('app.view_wallet_tx_errors_by_id', {id: wallet.id});
   };
 
-
-
   $scope.showMoreTx = function(fromTime) {
     if ($scope.loadingMore) return; // Skip
 
+    // Add a delay if previous load has been done recently
+    var waitDelayMs = $scope.lastMoreTxTime ? Date.now() - $scope.lastMoreTxTime : BMA.constants.LIMIT_REQUEST_DELAY;
+    if (waitDelayMs > 0 && waitDelayMs < BMA.constants.LIMIT_REQUEST_DELAY) {
+      return $timeout(function() {
+        return $scope.showMoreTx(fromTime);
+      }, waitDelayMs);
+    }
+
     $scope.loadingMore = true;
+    $scope.loadingMoreTime = Date.now();
 
     fromTime = fromTime ||
       ($scope.formData.tx.fromTime - csSettings.data.walletHistoryTimeSecond) ||
-- 
GitLab