diff --git a/src/js/controllers/advancedSettings.js b/src/js/controllers/advancedSettings.js
index 7b9a201dd..934adddfe 100644
--- a/src/js/controllers/advancedSettings.js
+++ b/src/js/controllers/advancedSettings.js
@@ -1,6 +1,6 @@
'use strict';
-angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $rootScope, $timeout, $state, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $ionicScrollDelegate, pincodeService) {
+angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $timeout, $state, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $ionicScrollDelegate, pincodeService) {
var updateConfig = function() {
var config = configService.getSync();
@@ -53,27 +53,22 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
};
$scope.usePincodeChange = function() {
- // pincodeService.lockChange({
- // fromSettings: true,
- // locking: $scope.usePincode.enabled
- // });
$state.go('tabs.pincode', {
fromSettings: true,
locking: $scope.usePincode.enabled
});
};
- $rootScope.$on('updatePincodeOption', function(event) {
- $timeout(function() {
- var config = configService.getSync();
- $scope.usePincode = {
- enabled: config.pincode ? config.pincode.enabled : false
- };
- $scope.$apply();
- });
+ $scope.$on('updatePincodeOption', function(event) {
+ var config = configService.getSync();
+ $scope.usePincode = {
+ enabled: config.pincode ? config.pincode.enabled : false
+ };
+ $scope.$apply();
});
$scope.$on("$ionicView.beforeEnter", function(event, data) {
+ $scope.isCordova = platformInfo.isCordova;
updateConfig();
});
diff --git a/src/js/controllers/pincode.js b/src/js/controllers/pincode.js
index f9d4831b7..35c888ed6 100644
--- a/src/js/controllers/pincode.js
+++ b/src/js/controllers/pincode.js
@@ -1,36 +1,17 @@
'use strict';
-angular.module('copayApp.controllers').controller('pincodeController', function($rootScope, $state, $timeout, $scope, $log, $window, configService) {
+angular.module('copayApp.controllers').controller('pincodeController', function($state, $stateParams, $timeout, $scope, $log, $window, configService) {
- $scope.$on("$ionicView.beforeEnter", function(event, data) {
+ $scope.$on("$ionicView.beforeEnter", function(event) {
$scope.currentPincode = $scope.newPincode = '';
- $scope.fromSettings = data.stateParams.fromSettings == 'true' ? true : false;
- $scope.locking = data.stateParams.locking == 'true' ? true : false;
- console.log('### From Settings:', $scope.fromSettings, 'Locking:', $scope.locking);
+ $scope.fromSettings = $stateParams.fromSettings == 'true' ? true : false;
+ $scope.locking = $stateParams.locking == 'true' ? true : false;
});
- angular.element($window).on('keydown', function(e) {
- if (e.which === 8) {
- e.preventDefault();
- $scope.delete();
- }
-
- if (e && e.key.match(/^[0-9]$/))
- $scope.add(e.key);
- else if (e && e.keyCode == 27)
- $scope.close();
- else if (e && e.keyCode == 13)
- $scope.save();
- });
-
- $scope.add = function(value) {
- updatePassCode(value);
- };
-
$scope.delete = function() {
if ($scope.currentPincode.length > 0) {
$scope.currentPincode = $scope.currentPincode.substring(0, $scope.currentPincode.length - 1);
- updatePassCode();
+ $scope.updatePinCode();
}
};
@@ -39,12 +20,18 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
else return true;
};
- function updatePassCode(value) {
- if (value && $scope.currentPincode.length < 4)
+ $scope.updatePinCode = function(value) {
+ if (value && !isComplete()) {
$scope.currentPincode = $scope.currentPincode + value;
+ }
$timeout(function() {
$scope.$apply();
});
+ if (!$scope.locking && isComplete()) {
+ $timeout(function() {
+ $scope.save();
+ });
+ }
};
$scope.save = function() {
@@ -52,29 +39,27 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
var config = configService.getSync();
var match = config.pincode.value == $scope.currentPincode ? true : false;
- if (!$scope.fromSettings && match) {
- $scope.currentPincode = '';
- $scope.close();
- return;
- }
if (!$scope.locking) {
- if (!match) return;
- saveSettings($scope.locking, '');
+ if (match) {
+ $scope.fromSettings ? saveSettings($scope.locking, '') : $scope.close();
+ return;
+ }
+ } else {
+ checkCodes();
}
- checkCodes();
};
function checkCodes() {
if (!$scope.newPincode) {
$scope.newPincode = $scope.currentPincode;
$scope.currentPincode = '';
+ $timeout(function() {
+ $scope.$apply();
+ });
} else {
if ($scope.newPincode == $scope.currentPincode)
saveSettings($scope.locking, $scope.newPincode);
}
- $timeout(function() {
- $scope.$apply();
- });
};
function saveSettings(enabled, value) {
@@ -92,7 +77,7 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
};
$scope.close = function() {
- $rootScope.$emit('updatePincodeOption');
+ $scope.$emit('updatePincodeOption');
if ($scope.fromSettings) $state.go('tabs.advanced');
else $state.go('tabs.home');
};
diff --git a/src/js/routes.js b/src/js/routes.js
index 249d7bd85..31dafd194 100644
--- a/src/js/routes.js
+++ b/src/js/routes.js
@@ -126,9 +126,9 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
*/
.state('pincode', {
- url: '/pincode/:fromSettings/:locking',
+ url: '/pincode/',
controller: 'pincodeController',
- templateUrl: 'views/pincode.html'
+ templateUrl: 'views/pincode.html',
})
/*
@@ -457,6 +457,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
'tab-settings@tabs': {
controller: 'pincodeController',
templateUrl: 'views/pincode.html',
+ cache: false
}
}
})
@@ -1112,7 +1113,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
});
})
- .run(function($rootScope, $state, $location, $log, $timeout, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService) {
+ .run(function($rootScope, $state, $location, $log, $timeout, startupService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService) {
uxLanguage.init();
@@ -1218,11 +1219,11 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
historyRoot: true
});
configService.whenAvailable(function(config) {
- console.log('### CONFIG', config.pincode);
- if (config.pincode && config.pincode.enabled) {
- $state.go('pincode', {
- fromSettings: false,
- locking: false
+ startupService.ready();
+ if (platformInfo.isCordova && config.pincode && config.pincode.enabled) {
+ $state.transitionTo('pincode').then(function() {
+ // Clear history
+ $ionicHistory.clearHistory();
});
} else {
$state.transitionTo('tabs.home').then(function() {
diff --git a/www/views/advancedSettings.html b/www/views/advancedSettings.html
index 8a8208587..861e325a0 100644
--- a/www/views/advancedSettings.html
+++ b/www/views/advancedSettings.html
@@ -31,7 +31,7 @@
-
+
Use pin to lock/unlock the app
diff --git a/www/views/pincode.html b/www/views/pincode.html
index 5f8f75a4d..cd8138eaf 100644
--- a/www/views/pincode.html
+++ b/www/views/pincode.html
@@ -1,4 +1,9 @@
-
+
+
+ {{'Pin Code' | translate}}
+
+
+
Close