diff --git a/www/js/controllers/login-controllers.js b/www/js/controllers/login-controllers.js index 42a00b976dde5847a78a341249c5eef5ac6d28b7..3b3e3a6fd9a6bdc0f9d3128f96be7c51effa80bc 100644 --- a/www/js/controllers/login-controllers.js +++ b/www/js/controllers/login-controllers.js @@ -24,12 +24,10 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.scryptParamsValues = _.keys(CryptoUtils.constants.SCRYPT_PARAMS) .reduce(function(res, key) { return res.concat({id: key, label: 'LOGIN.SCRYPT.' + key, params: CryptoUtils.constants.SCRYPT_PARAMS[key]}); - }, [{id: 'user', label: 'LOGIN.SCRYPT.USER', params: {}}]); - - // modal enter - $scope.enter = function() { - UIUtils.loading.hide(); + }, [{id: 'USER', label: 'LOGIN.SCRYPT.USER', params: {}}]); + // modal init + $scope.init = function() { // Should auto-compute pubkey ? $scope.autoComputePubkey = ionic.Platform.grade.toLowerCase()==='a' && !UIUtils.screen.isSmall(); @@ -42,15 +40,17 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.formData.keepAuth = ($scope.formData.keepAuthIdle == csSettings.constants.KEEP_AUTH_IDLE_SESSION); // Init method - $scope.formData.method = csSettings.data.login && csSettings.data.login.method || 'SCRYPT_DEFAULT'; + var method = csSettings.data.login && csSettings.data.login.method || 'SCRYPT_DEFAULT'; var params = csSettings.data.login && csSettings.data.login.params; - if ($scope.isAuth && $scope.formData.method == 'PUBKEY') { + if ($scope.isAuth && method == 'PUBKEY') { $scope.formData.method = 'SCRYPT_DEFAULT'; - params = undefined; // will use default - } - $scope.changeMethod($scope.formData.method, params); + $scope.changeMethod(method, params); + }; + // modal enter + $scope.enter = function() { + UIUtils.loading.hide(); // Ink effect UIUtils.ink({selector: '.modal-login .ink'}); }; @@ -176,7 +176,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, }); }; - $scope.scryptFormDataChanged = function() { + $scope.onScryptFormChanged = function() { if ($scope.computing) return; // avoid multiple call $scope.pubkey = null; $scope.pubkeyError = false; @@ -189,7 +189,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.showComputePubkeyButton = !$scope.autoComputePubkey && $scope.showPubkey; } }; - $scope.$watch('formData.username + formData.password', $scope.scryptFormDataChanged, true); + $scope.$watch('formData.username + formData.password', $scope.onScryptFormChanged, true); $scope.computePubkey = function() { $scope.showComputePubkeyButton = false; @@ -218,7 +218,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, .catch(function (err) { UIUtils.onError('ERROR.CRYPTO_UNKNOWN_ERROR')(err); $scope.computing = false; - $scope.scryptFormDataChanged(); + $scope.onScryptFormChanged(); }); }, 100); }; @@ -245,14 +245,32 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.hideMethodsPopover(); if (method == $scope.formData.method) return; // same method - console.debug("[login] method changed: ", method); + console.debug("[login] method is: " + method); $scope.formData.method = method; - delete $scope.form.$submitted; // hide form's fields errors on the form + + if ($scope.form) { + // hide form's fields errors on the form + delete $scope.form.$submitted; + } // Scrypt (advanced or not) if (method == 'SCRYPT_DEFAULT' || method == 'SCRYPT_ADVANCED') { - var scrypt = params || _.findWhere($scope.scryptParamsValues, {id: 'DEFAULT'}); + // Search scrypt object + var scrypt; + if (params) { + scrypt = _.find($scope.scryptParamsValues, function(item){ + return item.params && angular.equals(item.params, params); + }); + if (!scrypt) { + scrypt = _.findWhere($scope.scryptParamsValues, {id: 'USER'}) || {}; + scrypt.params = params; + } + } + else { + scrypt = _.findWhere($scope.scryptParamsValues, {id: 'DEFAULT'}); + } $scope.changeScrypt(scrypt); + $scope.autoComputePubkey = $scope.autoComputePubkey && (method == 'SCRYPT_DEFAULT'); } else { @@ -266,6 +284,7 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, $scope.changeScrypt = function(scrypt) { // Protect params against changes $scope.formData.scrypt = angular.copy(scrypt||{}); + $scope.onScryptFormChanged(); }; $scope.fileChanged = function(event) { @@ -380,6 +399,9 @@ function LoginModalController($scope, $timeout, $q, $ionicPopover, CryptoUtils, } }; + // Default action + $scope.init(); + // TODO : for DEV only /*$timeout(function() { diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index e5355b01da557a4d05cb3996cddb886060f1a61b..9ebcde2e5532d01c7032b620af06cb5866d40fa1 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -3,7 +3,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se 'cesium.settings.services']) -.factory('csWallet', function($q, $rootScope, $timeout, $translate, $filter, $ionicHistory, +.factory('csWallet', function($q, $rootScope, $timeout, $translate, $filter, $ionicHistory, UIUtils, Api, Idle, localStorage, sessionStorage, Modals, CryptoUtils, BMA, csConfig, csSettings, FileSaver, Blob, csWot, csTx, csCurrency) { 'ngInject'; diff --git a/www/templates/login/form_file_import.html b/www/templates/login/form_file_import.html index f4fd7ce486cbe7aa2d25e2c229d7f793633ead58..574cf66097978b0dc645ef7ff72e534c85c2c6f7 100644 --- a/www/templates/login/form_file_import.html +++ b/www/templates/login/form_file_import.html @@ -3,7 +3,7 @@ </div> -<div class="item item-icon-left "> +<div class="item item-icon-left item-text-wrap"> <i class="icon ion-ios-information-outline positive"></i> <span class="positive" translate>LOGIN.FILE.HELP</span> </div> diff --git a/www/templates/login/form_scrypt_advanced.html b/www/templates/login/form_scrypt_advanced.html index d87edfeb44b2f4f66c948641cd75e8a51755a99b..93b21b85bc6aaa8c6b0e16d70e983e2c670bc11e 100644 --- a/www/templates/login/form_scrypt_advanced.html +++ b/www/templates/login/form_scrypt_advanced.html @@ -12,19 +12,31 @@ <div class="col no-padding"> <label class="item item-input"> <span class="input-label" translate>LOGIN.SCRYPT.N</span> - <input class="no-padding-right" type="number" placeholder="N" ng-model="formData.scrypt.params.N" required> + <input class="no-padding-right" type="number" placeholder="N" + ng-model="formData.scrypt.params.N" + ng-model-options="{ debounce: 650 }" + ng-change="onScryptFormChanged()" + required> </label> </div> <div class="col no-padding"> <label class="item item-input"> <span class="input-label" translate>LOGIN.SCRYPT.r</span> - <input class="no-padding-right" type="number" placeholder="r" ng-model="formData.scrypt.params.r" required> + <input class="no-padding-right" type="number" placeholder="r" + ng-model="formData.scrypt.params.r" + ng-model-options="{ debounce: 650 }" + ng-change="onScryptFormChanged()" + required> </label> </div> <div class="col no-padding"> <label class="item item-input"> <span class="input-label" translate>LOGIN.SCRYPT.p</span> - <input class="no-padding-right" type="number" placeholder="p" ng-model="formData.scrypt.params.p" required> + <input class="no-padding-right" type="number" placeholder="p" + ng-model="formData.scrypt.params.p" + ng-model-options="{ debounce: 650 }" + ng-change="onScryptFormChanged()" + required> </label> </div> </div>