From 5db2b12c1213a0da6c4f68d666f67767a9025894 Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Wed, 29 Aug 2018 10:29:36 +0200
Subject: [PATCH] [fix] When identity has bas self block, add a button to
 resend the membership - fix #722

---
 www/i18n/locale-en-GB.json                |  1 +
 www/i18n/locale-en.json                   |  1 +
 www/i18n/locale-es-ES.json                |  1 +
 www/i18n/locale-fr-FR.json                |  1 +
 www/i18n/locale-it-IT.json                |  5 ++--
 www/js/controllers/wallet-controllers.js  |  4 ++-
 www/js/services/wallet-services.js        | 30 ++++++++++++++---------
 www/js/services/wot-services.js           |  2 +-
 www/templates/wallet/popover_actions.html |  8 +++++-
 9 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/www/i18n/locale-en-GB.json b/www/i18n/locale-en-GB.json
index 163e74215..8612f6de8 100644
--- a/www/i18n/locale-en-GB.json
+++ b/www/i18n/locale-en-GB.json
@@ -470,6 +470,7 @@
     "SIG_STOCK": "Stock of certifications to give",
     "BTN_RECEIVE_MONEY": "Receive",
     "BTN_SELECT_ALTERNATIVES_IDENTITIES": "Switch to another identity...",
+    "BTN_FIX_MEMBERSHIP": "Resubmit membership request...",
     "BTN_MEMBERSHIP_RENEW": "Renew membership",
     "BTN_MEMBERSHIP_RENEW_DOTS": "Renew membership...",
     "BTN_MEMBERSHIP_OUT_DOTS": "Revoke membership...",
diff --git a/www/i18n/locale-en.json b/www/i18n/locale-en.json
index 8d455d5fc..d0ab4d98d 100644
--- a/www/i18n/locale-en.json
+++ b/www/i18n/locale-en.json
@@ -470,6 +470,7 @@
     "SIG_STOCK": "Stock of certifications to give",
     "BTN_RECEIVE_MONEY": "Receive",
     "BTN_SELECT_ALTERNATIVES_IDENTITIES": "Switch to another identity...",
+    "BTN_FIX_MEMBERSHIP": "Resubmit membership request...",
     "BTN_MEMBERSHIP_RENEW": "Renew membership",
     "BTN_MEMBERSHIP_RENEW_DOTS": "Renew membership...",
     "BTN_MEMBERSHIP_OUT_DOTS": "Revoke membership...",
diff --git a/www/i18n/locale-es-ES.json b/www/i18n/locale-es-ES.json
index eb09ca109..7418e41e3 100644
--- a/www/i18n/locale-es-ES.json
+++ b/www/i18n/locale-es-ES.json
@@ -454,6 +454,7 @@
     "SIG_STOCK": "Certificaciones emitidas",
     "BTN_RECEIVE_MONEY": "Recibir",
     "BTN_SELECT_ALTERNATIVES_IDENTITIES": "Cambiar a otra identidad...",
+    "BTN_FIX_MEMBERSHIP": "Volver a enviar la adhesión...",
     "BTN_MEMBERSHIP_RENEW": "Renovar la adhesión",
     "BTN_MEMBERSHIP_RENEW_DOTS": "Renovar la adhesión...",
     "BTN_MEMBERSHIP_OUT_DOTS": "Cancelar la adhesión...",
diff --git a/www/i18n/locale-fr-FR.json b/www/i18n/locale-fr-FR.json
index 7ba68b4e1..efdc56170 100644
--- a/www/i18n/locale-fr-FR.json
+++ b/www/i18n/locale-fr-FR.json
@@ -470,6 +470,7 @@
     "SIG_STOCK": "Certifications envoyées",
     "BTN_RECEIVE_MONEY": "Encaisser",
     "BTN_SELECT_ALTERNATIVES_IDENTITIES": "Basculer vers une autre identité...",
+    "BTN_FIX_MEMBERSHIP": "Renvoyer la demande d'adhésion...",
     "BTN_MEMBERSHIP_RENEW": "Renouveler l'adhésion",
     "BTN_MEMBERSHIP_RENEW_DOTS": "Renouveler l'adhésion...",
     "BTN_MEMBERSHIP_OUT_DOTS": "Arrêter l'adhésion...",
diff --git a/www/i18n/locale-it-IT.json b/www/i18n/locale-it-IT.json
index fd900c28b..b33352b40 100644
--- a/www/i18n/locale-it-IT.json
+++ b/www/i18n/locale-it-IT.json
@@ -458,8 +458,9 @@
      "BTN_RECEIVE_MONEY": "Ricevere",
      "BTN_SELECT_ALTERNATIVES_IDENTITIES": "Usare un'altra identità..",
      "BTN_MEMBERSHIP_IN_DOTS": "Registrati come membro..",
-     "BTN_MEMBERSHIP_RENEW": "Rinnovare certificazione",
-     "BTN_MEMBERSHIP_RENEW_DOTS": "Rinnovare certificazione ...",
+     "BTN_FIX_MEMBERSHIP": "Invia nuovamente di adesione...",
+     "BTN_MEMBERSHIP_RENEW": "Rinnovare adesione",
+     "BTN_MEMBERSHIP_RENEW_DOTS": "Rinnovare adesione ...",
      "BTN_MEMBERSHIP_OUT_DOTS": "Revocare adesione...",
      "BTN_SEND_IDENTITY_DOTS": "Pubblicare identità...",
      "BTN_SECURITY_DOTS": "Login e securità...",
diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js
index 0b844f132..ab394fad5 100644
--- a/www/js/controllers/wallet-controllers.js
+++ b/www/js/controllers/wallet-controllers.js
@@ -409,7 +409,9 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state,
       return UIUtils.alert.info("INFO.NOT_NEED_MEMBERSHIP");
     }
 
-    return wallet.auth()
+    $scope.hideActionsPopover();
+
+    return wallet.auth({silent: true})
       .then(function() {
         UIUtils.alert.confirm("CONFIRM.FIX_MEMBERSHIP");
       })
diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js
index 1d402fab1..3e9050eca 100644
--- a/www/js/services/wallet-services.js
+++ b/www/js/services/wallet-services.js
@@ -671,13 +671,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
 
               // Check if self has been done on a valid block
               if (!data.isMember && blockNumber !== 0 && blockHash !== block.hash) {
-                addEvent({type: 'error', message: 'ERROR.WALLET_INVALID_BLOCK_HASH', context: 'requirements'});
-                console.debug("Invalid membership for uid={0}: block hash changed".format(data.uid));
-              }
-              // Check if self expired
-              else if (!data.isMember && data.requirements.expired) {
-                addEvent({type: 'error', message: 'ERROR.WALLET_IDENTITY_EXPIRED', context: 'requirements'});
-                console.debug("Identity expired for uid={0}.".format(data.uid));
+                data.requirements.hasBadSelfBlock = true;
               }
             })
             .catch(function(err){
@@ -720,13 +714,24 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
     addEvents = function() {
       // Add user events
       if (data.requirements.revoked) {
+        delete data.requirements.hasBadSelfBlock;
         addEvent({type:'info', message: 'ERROR.WALLET_REVOKED', context: 'requirements'});
       }
       else if (data.requirements.pendingRevocation) {
+        delete data.requirements.hasBadSelfBlock;
         addEvent({type:'pending', message: 'INFO.REVOCATION_SENT_WAITING_PROCESS', context: 'requirements'});
       }
       else {
-        if (data.requirements.pendingMembership) {
+        if (!data.isMember && data.requirements.hasBadSelfBlock) {
+          addEvent({type: 'error', message: 'ERROR.WALLET_INVALID_BLOCK_HASH', context: 'requirements'});
+          console.debug("Invalid membership for uid={0}: block hash changed".format(data.uid));
+        }
+        // Check if self expired
+        else if (!data.isMember && data.requirements.expired) {
+          addEvent({type: 'error', message: 'ERROR.WALLET_IDENTITY_EXPIRED', context: 'requirements'});
+          console.debug("Identity expired for uid={0}.".format(data.uid));
+        }
+        else if (data.requirements.pendingMembership) {
           addEvent({type:'pending', message: 'ACCOUNT.WAITING_MEMBERSHIP', context: 'requirements'});
         }
         // If user has send a SELF, ask for membership - fix #625
@@ -1455,7 +1460,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
         return $q.all([
           getKeypair(),
           csCurrency.get(),
-          csCurrency.blockchain.current()
+          csCurrency.blockchain.lastValid()
         ])
         // Create identity document
         .then(function(res) {
@@ -1473,7 +1478,10 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
         .then(function () {
           if (!!needToLoadRequirements) {
             // Refresh membership data (if need)
-            return loadRequirements();
+            return loadRequirements()
+
+              // Add wallet events
+              .then(addEvents)
           }
           else {
             data.uid = uid;
@@ -1497,7 +1505,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
 
         return $q.all([
             getKeypair(),
-            csCurrency.blockchain.current()
+            csCurrency.blockchain.lastValid()
           ])
           .then(function(res) {
             var keypair = res[0];
diff --git a/www/js/services/wot-services.js b/www/js/services/wot-services.js
index c36387724..5852a5360 100644
--- a/www/js/services/wot-services.js
+++ b/www/js/services/wot-services.js
@@ -541,7 +541,7 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c
           delete data.hasBadSelfBlock;
           if (!data.isMember) {
             addEvent(data, {type: 'error', message: 'ERROR.IDENTITY_INVALID_BLOCK_HASH'});
-            console.debug("[wot] Invalid membership for {0}: block hash changed".format(data.uid));
+            console.debug("[wot] Invalid membership for uid {0}: block hash changed".format(data.uid));
           }
         }
         else if (data.requirements.expired) {
diff --git a/www/templates/wallet/popover_actions.html b/www/templates/wallet/popover_actions.html
index 00f24afea..fa7084450 100644
--- a/www/templates/wallet/popover_actions.html
+++ b/www/templates/wallet/popover_actions.html
@@ -29,12 +29,18 @@
         {{'ACCOUNT.BTN_MEMBERSHIP_RENEW_DOTS' | translate}}
       </a>
       <a class="item item-icon-left ink hidden-xs hidden-sm"
-         ng-if="!walletData.requirements.needSelf && !walletData.requirements.revoked"
+         ng-if="!walletData.requirements.needSelf && !walletData.requirements.hasBadSelfBlock && !walletData.requirements.revoked"
          ng-class="{'gray':!walletData.requirements.needRenew}"
          ng-click="renewMembership()">
         <i class="icon ion-loop"></i>
         {{'ACCOUNT.BTN_MEMBERSHIP_RENEW_DOTS' | translate}}
       </a>
+      <a class="item item-icon-left ink hidden-xs hidden-sm"
+         ng-if="walletData.requirements.hasBadSelfBlock"
+         ng-click="fixMembership()">
+        <i class="icon ion-loop"></i>
+        {{'ACCOUNT.BTN_FIX_MEMBERSHIP' | translate}}
+      </a>
 
       <a class="item item-icon-left assertive ink"
               ng-if="walletData.requirements.canMembershipOut"
-- 
GitLab