From 21b3cb8f5dd10b8a775ec6fc120f7f64ad0e4cd3 Mon Sep 17 00:00:00 2001
From: Benoit Lavenier <benoit.lavenier@e-is.pro>
Date: Thu, 5 Mar 2020 18:24:38 +0100
Subject: [PATCH] [enh] Rename web extension artifact to ZIP (need by chrome
 store)

---
 gulpfile.js                               | 19 +++++-----
 scripts/github.sh                         | 43 +++++++++++++++--------
 scripts/release.sh                        |  5 +--
 www/js/controllers/wallets-controllers.js |  7 ++--
 www/js/filters.js                         |  2 +-
 www/js/platform.js                        |  4 +--
 www/js/services/wallet-services.js        | 10 +++---
 7 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/gulpfile.js b/gulpfile.js
index ea06f03a..65c1381c 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -617,7 +617,9 @@ function webZip() {
 }
 
 
-function webExtCopyFiles() {
+function webExtensionCopyFiles() {
+  const wwwPath = './dist/web/www';
+  const resourcesPath = './resources/web-ext';
   log(colors.green('Copy web extension files...'));
 
   const version = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
@@ -625,8 +627,6 @@ function webExtCopyFiles() {
   const txtFilter = filter(["**/*.txt"], { restore: true });
 
   // Copy files
-  const wwwPath = './dist/web/www';
-  const resourcesPath = './resources/web-ext';
   return gulp.src([
     wwwPath + '/**/*',
 
@@ -668,20 +668,19 @@ function webExtCopyFiles() {
     .pipe(gulp.dest('./dist/web/ext'));
 }
 
-function webExtXpi() {
+function webExtensionZip() {
   const srcPath = './dist/web/ext';
   const distPath = './dist/web/build';
   const version = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
 
   return gulp.src(srcPath + '/**/*.*')
-    .pipe(zip('cesium-v'+version+'-extension.xpi'))
+    .pipe(zip('cesium-v'+version+'-extension.zip'))
     .pipe(gulp.dest(distPath));
 }
 
 function webBuildSuccess(done) {
   var version = JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
-  log(colors.green("Build for web created at: 'dist/web/build/cesium-v" + version + "-web.zip'"));
-  log(colors.green("Build for web extension created at: 'dist/webExtension/cesium-v" + version + "-extension.xpi'"));
+  log(colors.green("Web artifacts created at: 'dist/web/build/cesium-v" + version + "-web.zip' and 'dist/web/build/cesium-v" + version + "-extension.zip'"));
   done();
 }
 
@@ -738,9 +737,9 @@ gulp.task('webCleanUnusedFiles', ['webApiUglify'], webCleanUnusedFiles);
 gulp.task('webCleanUnusedDirectories', ['webCleanUnusedFiles'], webCleanUnusedDirectories);
 gulp.task('webZip', ['webCleanUnusedDirectories'], webZip);
 
-gulp.task('webExtCopyFiles', ['webCleanUnusedDirectories'], webExtCopyFiles);
-gulp.task('webExtXpi', ['webExtCopyFiles'], webExtXpi);
+gulp.task('webExtensionCopyFiles', ['webCleanUnusedDirectories'], webExtensionCopyFiles);
+gulp.task('webExtensionZip', ['webExtensionCopyFiles'], webExtensionZip);
 
-gulp.task('webBuild', ['webZip', 'webExtXpi'], webBuildSuccess);
+gulp.task('webBuild', ['webZip', 'webExtensionZip'], webBuildSuccess);
 gulp.task('build:web', ['webBuild']); // = webBuild
 
diff --git a/scripts/github.sh b/scripts/github.sh
index 657eb81a..1e04c224 100755
--- a/scripts/github.sh
+++ b/scripts/github.sh
@@ -91,36 +91,51 @@ case "$1" in
       fi
 
       ###  Sending files
-      echo "Uploading files to ${upload_url} ..."
+      echo "Uploading artifacts to ${upload_url} ..."
       dirname=$(pwd)
 
-      ZIP_BASENAME="${PROJECT_NAME}-v$current-web.zip"
-      ZIP_FILE="${DIST_WEB}/${ZIP_BASENAME}"
-      if [[ -f "${ZIP_FILE}" ]]; then
-        result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${ZIP_FILE}" "${upload_url}?name=${ZIP_BASENAME}")
+      # Upload web file
+      WEB_BASENAME="${PROJECT_NAME}-v$current-web.zip"
+      WEB_FILE="${DIST_WEB}/${WEB_BASENAME}"
+      if [[ -f "${WEB_FILE}" ]]; then
+        result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WEB_FILE}" "${upload_url}?name=${WEB_BASENAME}")
         browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+"  | grep -oP "https://[A-Za-z0-9/.-]+")
-        ZIP_SHA256=$(cd ${DIST_WEB} && sha256sum "${ZIP_BASENAME}")
-        echo " - ${browser_download_url}  | Checksum: ${ZIP_SHA256}"
+        WEB_FILE_SHA256=$(cd ${DIST_WEB} && sha256sum "${WEB_BASENAME}")
+        echo " - ${browser_download_url}  | Checksum: ${WEB_FILE_SHA256}"
       else
-        echo " - ERROR: Web release (ZIP) not found! Skipping."
+        echo " - ERROR: Web artifact (ZIP) not found! Skipping."
       fi
 
+      # Upload web extension file
+      WEB_EXT_BASENAME="${PROJECT_NAME}-v$current-extension.zip"
+      WEB_EXT_FILE="${DIST_WEB}/${WEB_EXT_BASENAME}"
+      if [[ -f "${WEB_EXT_FILE}" ]]; then
+        result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/zip' -T "${WEB_EXT_FILE}" "${upload_url}?name=${WEB_EXT_BASENAME}")
+        browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+"  | grep -oP "https://[A-Za-z0-9/.-]+")
+        WEB_EXT_FILE_SHA256=$(cd ${DIST_WEB} && sha256sum "${WEB_EXT_BASENAME}")
+        echo " - ${browser_download_url}  | Checksum: ${WEB_EXT_FILE_SHA256}"
+      else
+        echo " - ERROR: Web extension artifact (ZIP) not found! Skipping."
+      fi
+
+      # Upload Android APK file
       APK_BASENAME="${PROJECT_NAME}-v${current}-android.apk"
       APK_FILE="${DIST_ANDROID}/${APK_BASENAME}"
       if [[ -f "${APK_FILE}" ]]; then
         result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: application/vnd.android.package-archive' -T "${APK_FILE}" "${upload_url}?name=${APK_BASENAME}")
         browser_download_url=$(echo "$result" | grep -P "\"browser_download_url\":[ ]?\"[^\"]+" | grep -oP "\"browser_download_url\":[ ]?\"[^\"]+"  | grep -oP "https://[A-Za-z0-9/.-]+")
-        APK_SHA256=$(cd ${DIST_ANDROID} && sha256sum "${APK_BASENAME}")
-        echo " - ${browser_download_url}  | Checksum: ${APK_SHA256}"
+        APK_FILE_SHA256=$(cd ${DIST_ANDROID} && sha256sum "${APK_BASENAME}")
+        echo " - ${browser_download_url}  | Checksum: ${APK_FILE_SHA256}"
       else
-        echo "- ERROR: Android release (APK) not found! Skipping."
+        echo "- ERROR: Android artifact (APK) not found! Skipping."
       fi
 
-      # Send Checksum file
+      # Upload sha256 file (checksum)
       SHA_BASENAME=${PROJECT_NAME}-v$current.sha256
       SHA_FILE=${PROJECT_DIR}/dist/${SHA_BASENAME}
-      echo "${ZIP_SHA256}" > ${SHA_FILE}
-      echo "${APK_SHA256}" >> ${SHA_FILE}
+      echo "${WEB_FILE_SHA256}" > ${SHA_FILE}
+      echo "${WEB_EXT_FILE_SHA256}" >> ${SHA_FILE}
+      echo "${APK_FILE_SHA256}" >> ${SHA_FILE}
       result=$(curl -s -H ''"$GITHUT_AUTH"'' -H 'Content-Type: text/plain' -T "${SHA_FILE}" "${upload_url}?name=${SHA_BASENAME}")
 
       echo "-----------------------------------------"
diff --git a/scripts/release.sh b/scripts/release.sh
index c60ef0c7..a2308484 100755
--- a/scripts/release.sh
+++ b/scripts/release.sh
@@ -120,7 +120,7 @@ if [[ ! -f "${DIST_WEB_FILE}" ]]; then
   echo "ERROR: Missing web artifact at ${DIST_WEB_FILE}"
   exit 1
 fi;
-DIST_WEB_EXT_FILE="${DIST_WEB}/${PROJECT_NAME}-v$2-extension.xpi"
+DIST_WEB_EXT_FILE="${DIST_WEB}/${PROJECT_NAME}-v$2-extension.zip"
 if [[ ! -f "${DIST_WEB_EXT_FILE}" ]]; then
   echo "ERROR: Missing web-ext artifact at ${DIST_WEB_EXT_FILE}"
   exit 1
@@ -177,9 +177,6 @@ else
   fi
 fi
 
-
-exit 1
-
 echo "**********************************"
 echo "* Uploading artifacts to Github..."
 echo "**********************************"
diff --git a/www/js/controllers/wallets-controllers.js b/www/js/controllers/wallets-controllers.js
index 5e9a7cfc..8825522a 100644
--- a/www/js/controllers/wallets-controllers.js
+++ b/www/js/controllers/wallets-controllers.js
@@ -318,7 +318,7 @@ function WalletListAbstractController($scope, $q, $timeout, UIUtils, filterTrans
       method: 'PUBKEY' // Default method - fix #767
     })
       .then(function(walletData) {
-        if (!walletData) { // User cancelled
+        if (!walletData || !walletData.pubkey) { // User cancelled
           UIUtils.loading.hide(100);
           return;
         }
@@ -337,7 +337,7 @@ function WalletListAbstractController($scope, $q, $timeout, UIUtils, filterTrans
           return;
         }
 
-        console.debug("[wallet] Adding secondary wallet {"+walletData.pubkey.substring(0,8)+"}");
+        console.debug("[wallet] Adding secondary wallet {{0}}".format(walletData.pubkey.substring(0,8)));
 
         // Add the child wallet
         return $scope.addNewWallet(wallet)
@@ -530,6 +530,7 @@ function WalletListViewController($scope, $controller, $state, $timeout, $q, $tr
     $scope.hideActionsPopover();
 
     var loginAndAddWallet = function(authData) {
+      if (!authData || !authData.pubkey) return $q.reject('Invalid authentication data');
       console.debug("[wallet] Adding secondary wallet {"+authData.pubkey.substring(0,8)+"}");
       var wallet = csWallet.children.instance();
       return wallet.login({
@@ -588,7 +589,7 @@ function WalletListViewController($scope, $controller, $state, $timeout, $q, $tr
     return $q(function(resolve, reject) {
       $translate(['ACCOUNT.WALLET_LIST.EDIT_POPOVER.TITLE', 'ACCOUNT.WALLET_LIST.EDIT_POPOVER.HELP', 'COMMON.BTN_OK', 'COMMON.BTN_CANCEL'])
         .then(function (translations) {
-          $scope.formData.name = wallet.data.localName || wallet.data.name || wallet.data.uid || wallet.data.pubkey.substring(0, 8);
+          $scope.formData.name = wallet.data.localName || wallet.data.name || wallet.data.uid || (wallet.data.pubkey && wallet.data.pubkey.substring(0, 8)) || '';
 
           // Choose UID popup
           $ionicPopup.show({
diff --git a/www/js/filters.js b/www/js/filters.js
index 3cf9060a..b38b0cc2 100644
--- a/www/js/filters.js
+++ b/www/js/filters.js
@@ -349,7 +349,7 @@ angular.module('cesium.filters', ['cesium.config', 'cesium.platform', 'pascalpre
     return function(input) {
       if (!input) return '';
       input = input.toLowerCase();
-      return input.substring(0,1).toUpperCase()+input.substring(1);
+      return input.length > 1 ? (input.substring(0,1).toUpperCase()+input.substring(1)) : input;
     };
   })
 
diff --git a/www/js/platform.js b/www/js/platform.js
index 57c60f75..02c2de56 100644
--- a/www/js/platform.js
+++ b/www/js/platform.js
@@ -33,11 +33,9 @@ angular.module('cesium.platform', ['ngIdle', 'cesium.config', 'cesium.services']
     // endRemoveIf(no-device)
   })
 
-
   .config(function($compileProvider, csConfig) {
     'ngInject';
-
-    $compileProvider.debugInfoEnabled(!!csConfig.debug);
+     $compileProvider.debugInfoEnabled(csConfig.debug === true);
   })
 
   .config(function($animateProvider) {
diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js
index e182342a..51cf9cc9 100644
--- a/www/js/services/wallet-services.js
+++ b/www/js/services/wallet-services.js
@@ -1760,11 +1760,8 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
           var saveIdFile = new Blob([saveId], {type: 'text/plain; charset=utf-8'});
           FileSaver.saveAs(saveIdFile, '{0}-recover_ID.txt'.format(data.pubkey.substring(0,8)));
         });
-
     },
 
-
-
     downloadKeyFile = function(format){
       if (!isAuth()) return $q.reject('user not authenticated');
 
@@ -2121,7 +2118,12 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se
     fromJson = function(json, failIfInvalid) {
       failIfInvalid = angular.isUndefined(failIfInvalid) ? true : failIfInvalid;
       return $q(function(resolve, reject) {
-        var obj = JSON.parse(json || '{}');
+        var obj;
+        try {
+          obj = JSON.parse(json || '{}');
+        }
+        catch(err) { /* invalid JSON : continue*/}
+
         // FIXME #379
         /*if (obj && obj.pubkey) {
           resolve({
-- 
GitLab