mirror of https://github.com/BTCPrivate/copay.git
set lock/unlock properly
This commit is contained in:
parent
34413278ec
commit
e5ecc111f3
|
@ -54,18 +54,19 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
|
|||
|
||||
$scope.usePincodeChange = function() {
|
||||
pincodeService.lockChange({
|
||||
enabled: $scope.usePincode.enabled,
|
||||
from: 'settings'
|
||||
from: 'settings',
|
||||
locking: $scope.usePincode.enabled
|
||||
});
|
||||
};
|
||||
|
||||
$rootScope.$on('updatePincodeOption', function(event) {
|
||||
console.log('ON');
|
||||
var config = configService.getSync();
|
||||
$scope.usePincode = {
|
||||
enabled: config.pincode ? config.pincode.enabled : false
|
||||
};
|
||||
$scope.$apply();
|
||||
$timeout(function() {
|
||||
var config = configService.getSync();
|
||||
$scope.usePincode = {
|
||||
enabled: config.pincode ? config.pincode.enabled : false
|
||||
};
|
||||
$scope.$apply();
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('pincodeController', function($rootScope, $timeout, $scope, $log, $window, configService) {
|
||||
var config = configService.getSync();
|
||||
$scope.currentPincode = config.pincode ? config.pincode.value : null;
|
||||
$scope.pincode = $scope.pc1 = $scope.pc2 = null;
|
||||
$scope.currentPincode = $scope.newPincode = '';
|
||||
|
||||
angular.element($window).on('keydown', function(e) {
|
||||
if (e.which === 8) {
|
||||
|
@ -14,7 +12,7 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
|
|||
if (e && e.key.match(/^[0-9]$/))
|
||||
$scope.add(e.key);
|
||||
else if (e && e.keyCode == 27)
|
||||
$scope.cancel();
|
||||
$scope.close();
|
||||
else if (e && e.keyCode == 13)
|
||||
$scope.save();
|
||||
});
|
||||
|
@ -24,53 +22,63 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
|
|||
};
|
||||
|
||||
$scope.delete = function() {
|
||||
if ($scope.pincode.length > 0) {
|
||||
$scope.pincode = $scope.pincode.substring(0, $scope.pincode.length - 1);
|
||||
if ($scope.currentPincode.length > 0) {
|
||||
$scope.currentPincode = $scope.currentPincode.substring(0, $scope.currentPincode.length - 1);
|
||||
updatePassCode();
|
||||
}
|
||||
};
|
||||
|
||||
function isComplete() {
|
||||
if ($scope.pincode.length < 4) return false;
|
||||
if ($scope.currentPincode.length < 4) return false;
|
||||
else return true;
|
||||
};
|
||||
|
||||
function updatePassCode(value) {
|
||||
if (value && $scope.pincode.length < 4)
|
||||
$scope.pincode = $scope.pincode + value;
|
||||
if (value && $scope.currentPincode.length < 4)
|
||||
$scope.currentPincode = $scope.currentPincode + value;
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.save = function() {
|
||||
if (!$scope.pc1) {
|
||||
console.log('No pc 1');
|
||||
$scope.pc1 = $scope.pincode;
|
||||
console.log('$scope.pc1', $scope.pc1);
|
||||
$scope.pincode = '';
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
$scope.pc2 = $scope.pincode;
|
||||
console.log('$scope.pc2', $scope.pc2);
|
||||
}
|
||||
if (!isComplete()) return;
|
||||
var config = configService.getSync();
|
||||
var match = config.pincode.value == $scope.currentPincode ? true : false;
|
||||
|
||||
if ($scope.pc1 == $scope.pc2) {
|
||||
$scope.close($scope.pc1);
|
||||
if (!$scope.locking && !match) return;
|
||||
checkCodes();
|
||||
};
|
||||
|
||||
function checkCodes() {
|
||||
if (!$scope.newPincode) {
|
||||
$scope.newPincode = $scope.currentPincode;
|
||||
$scope.currentPincode = '';
|
||||
} else {
|
||||
$scope.enabled ? pincodeService.lockApp() : pincodeService.unlockApp();
|
||||
if ($scope.newPincode == $scope.currentPincode)
|
||||
saveSettings($scope.locking, $scope.newPincode);
|
||||
}
|
||||
$timeout(function() {
|
||||
$scope.$apply();
|
||||
});
|
||||
};
|
||||
|
||||
function saveSettings(enabled, value) {
|
||||
var opts = {
|
||||
pincode: {
|
||||
enabled: enabled,
|
||||
value: value
|
||||
}
|
||||
};
|
||||
|
||||
configService.set(opts, function(err) {
|
||||
if (err) $log.debug(err);
|
||||
$scope.close();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.close = function() {
|
||||
$rootScope.$emit('updatePincodeOption');
|
||||
$scope.pincodeModal.hide();
|
||||
};
|
||||
|
||||
$scope.cancel = function() {
|
||||
$rootScope.$emit('updatePincodeOption', false);
|
||||
$scope.close();
|
||||
};
|
||||
});
|
||||
|
|
|
@ -55,7 +55,7 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
|||
|
||||
pincode: {
|
||||
enabled: false,
|
||||
value: null,
|
||||
value: '',
|
||||
},
|
||||
|
||||
// External services
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
angular.module('copayApp.services').factory('pincodeService', function($log, $rootScope, $ionicModal, configService) {
|
||||
var root = {};
|
||||
|
||||
var openPincodeModal = function(opts) {
|
||||
root.lockChange = function(opts) {
|
||||
var scope = $rootScope.$new(true);
|
||||
scope.from = opts.from;
|
||||
scope.enabled = opts.enabled;
|
||||
scope.locking = opts.locking;
|
||||
$ionicModal.fromTemplateUrl('views/modals/pincode.html', {
|
||||
scope: scope,
|
||||
backdropClickToClose: false,
|
||||
|
@ -17,12 +17,6 @@ angular.module('copayApp.services').factory('pincodeService', function($log, $ro
|
|||
});
|
||||
};
|
||||
|
||||
root.lockChange = function(opts) {
|
||||
if (opts.enabled) console.log('Locking app from service');
|
||||
else console.log('Unlocking app from service');
|
||||
openPincodeModal(opts);
|
||||
};
|
||||
|
||||
root.isLocked = function() {
|
||||
var config = configService.getSync();
|
||||
return config.pincode ? config.pincode.enabled : false;
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
<div class="block-code">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{{pincode.substring(0, 1)}}
|
||||
{{currentPincode.substring(0, 1)}}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{pincode.substring(1, 2)}}
|
||||
{{currentPincode.substring(1, 2)}}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{pincode.substring(2, 3)}}
|
||||
{{currentPincode.substring(2, 3)}}
|
||||
</div>
|
||||
<div class="col">
|
||||
{{pincode.substring(3, 4)}}
|
||||
{{currentPincode.substring(3, 4)}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue