From f24c718fb181b249bcdf922b41f2eb1ce07d9d1e Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Thu, 10 Aug 2017 18:20:40 +0200
Subject: [PATCH] [fix] hide qrcode on logout, and reuse it if already created
 -  fix #503

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

diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js
index d1cb02f32..2058dd921 100644
--- a/www/js/controllers/wallet-controllers.js
+++ b/www/js/controllers/wallet-controllers.js
@@ -81,7 +81,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
         $scope.formData = walletData;
         $scope.loading=false; // very important, to avoid TX to be display before wallet.currentUd is loaded
         $scope.updateView();
-        $scope.showQRCode('qrcode', $scope.formData.pubkey, 1100);
+        $scope.showQRCode('qrcode', $scope.formData.pubkey);
         $scope.showHelpTip();
         UIUtils.loading.hide(); // loading could have be open (e.g. new account)
       })
@@ -108,7 +108,8 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
 
   // Clean controller data when logout
   $scope.onWalletLogout = function() {
-    delete $scope.qrcode; // clean QRcode
+    // clean QRcode
+    $scope.hideQRCode('qrcode');
     delete $scope.formData;
     $scope.loading = true;
   };
@@ -444,16 +445,27 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
   };
 
   $scope.showQRCode = function(id, text, timeout) {
-    if (!!$scope.qrcode) {
-      return;
+    if (!$scope.qrcode) {
+      $scope.qrcode = new QRCode(id, {
+        text: text,
+        width: 200,
+        height: 200,
+        correctLevel: QRCode.CorrectLevel.L
+      });
+      UIUtils.motion.toggleOn({selector: '#wallet #'+id+'.qrcode'}, timeout || 1100);
+    }
+    else {
+      $scope.qrcode.clear();
+      $scope.qrcode.makeCode(text);
+      UIUtils.motion.toggleOn({selector: '#wallet #'+id+'.qrcode'}, timeout || 1100);
+    }
+  };
+
+  $scope.hideQRCode = function(id) {
+    if ($scope.qrcode) {
+      $scope.qrcode.clear();
+      UIUtils.motion.toggleOff({selector: '#wallet #'+id+'.qrcode'});
     }
-    $scope.qrcode = new QRCode(id, {
-      text: text,
-      width: 200,
-      height: 200,
-      correctLevel: QRCode.CorrectLevel.L
-    });
-    UIUtils.motion.toggleOn({selector: '#wallet #'+id+'.qrcode'}, timeout || 1100);
   };
 
   $scope.showCertifications = function() {
-- 
GitLab