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() {
|
$scope.usePincodeChange = function() {
|
||||||
pincodeService.lockChange({
|
pincodeService.lockChange({
|
||||||
enabled: $scope.usePincode.enabled,
|
from: 'settings',
|
||||||
from: 'settings'
|
locking: $scope.usePincode.enabled
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$rootScope.$on('updatePincodeOption', function(event) {
|
$rootScope.$on('updatePincodeOption', function(event) {
|
||||||
console.log('ON');
|
$timeout(function() {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
$scope.usePincode = {
|
$scope.usePincode = {
|
||||||
enabled: config.pincode ? config.pincode.enabled : false
|
enabled: config.pincode ? config.pincode.enabled : false
|
||||||
};
|
};
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('pincodeController', function($rootScope, $timeout, $scope, $log, $window, configService) {
|
angular.module('copayApp.controllers').controller('pincodeController', function($rootScope, $timeout, $scope, $log, $window, configService) {
|
||||||
var config = configService.getSync();
|
$scope.currentPincode = $scope.newPincode = '';
|
||||||
$scope.currentPincode = config.pincode ? config.pincode.value : null;
|
|
||||||
$scope.pincode = $scope.pc1 = $scope.pc2 = null;
|
|
||||||
|
|
||||||
angular.element($window).on('keydown', function(e) {
|
angular.element($window).on('keydown', function(e) {
|
||||||
if (e.which === 8) {
|
if (e.which === 8) {
|
||||||
|
@ -14,7 +12,7 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
|
||||||
if (e && e.key.match(/^[0-9]$/))
|
if (e && e.key.match(/^[0-9]$/))
|
||||||
$scope.add(e.key);
|
$scope.add(e.key);
|
||||||
else if (e && e.keyCode == 27)
|
else if (e && e.keyCode == 27)
|
||||||
$scope.cancel();
|
$scope.close();
|
||||||
else if (e && e.keyCode == 13)
|
else if (e && e.keyCode == 13)
|
||||||
$scope.save();
|
$scope.save();
|
||||||
});
|
});
|
||||||
|
@ -24,53 +22,63 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.delete = function() {
|
$scope.delete = function() {
|
||||||
if ($scope.pincode.length > 0) {
|
if ($scope.currentPincode.length > 0) {
|
||||||
$scope.pincode = $scope.pincode.substring(0, $scope.pincode.length - 1);
|
$scope.currentPincode = $scope.currentPincode.substring(0, $scope.currentPincode.length - 1);
|
||||||
updatePassCode();
|
updatePassCode();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function isComplete() {
|
function isComplete() {
|
||||||
if ($scope.pincode.length < 4) return false;
|
if ($scope.currentPincode.length < 4) return false;
|
||||||
else return true;
|
else return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
function updatePassCode(value) {
|
function updatePassCode(value) {
|
||||||
if (value && $scope.pincode.length < 4)
|
if (value && $scope.currentPincode.length < 4)
|
||||||
$scope.pincode = $scope.pincode + value;
|
$scope.currentPincode = $scope.currentPincode + value;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.save = function() {
|
$scope.save = function() {
|
||||||
if (!$scope.pc1) {
|
if (!isComplete()) return;
|
||||||
console.log('No pc 1');
|
var config = configService.getSync();
|
||||||
$scope.pc1 = $scope.pincode;
|
var match = config.pincode.value == $scope.currentPincode ? true : false;
|
||||||
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 ($scope.pc1 == $scope.pc2) {
|
if (!$scope.locking && !match) return;
|
||||||
$scope.close($scope.pc1);
|
checkCodes();
|
||||||
|
};
|
||||||
|
|
||||||
|
function checkCodes() {
|
||||||
|
if (!$scope.newPincode) {
|
||||||
|
$scope.newPincode = $scope.currentPincode;
|
||||||
|
$scope.currentPincode = '';
|
||||||
} else {
|
} 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() {
|
$scope.close = function() {
|
||||||
|
$rootScope.$emit('updatePincodeOption');
|
||||||
$scope.pincodeModal.hide();
|
$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: {
|
pincode: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
value: null,
|
value: '',
|
||||||
},
|
},
|
||||||
|
|
||||||
// External services
|
// External services
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
angular.module('copayApp.services').factory('pincodeService', function($log, $rootScope, $ionicModal, configService) {
|
angular.module('copayApp.services').factory('pincodeService', function($log, $rootScope, $ionicModal, configService) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
var openPincodeModal = function(opts) {
|
root.lockChange = function(opts) {
|
||||||
var scope = $rootScope.$new(true);
|
var scope = $rootScope.$new(true);
|
||||||
scope.from = opts.from;
|
scope.from = opts.from;
|
||||||
scope.enabled = opts.enabled;
|
scope.locking = opts.locking;
|
||||||
$ionicModal.fromTemplateUrl('views/modals/pincode.html', {
|
$ionicModal.fromTemplateUrl('views/modals/pincode.html', {
|
||||||
scope: scope,
|
scope: scope,
|
||||||
backdropClickToClose: false,
|
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() {
|
root.isLocked = function() {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
return config.pincode ? config.pincode.enabled : false;
|
return config.pincode ? config.pincode.enabled : false;
|
||||||
|
|
|
@ -4,16 +4,16 @@
|
||||||
<div class="block-code">
|
<div class="block-code">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{pincode.substring(0, 1)}}
|
{{currentPincode.substring(0, 1)}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{pincode.substring(1, 2)}}
|
{{currentPincode.substring(1, 2)}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{pincode.substring(2, 3)}}
|
{{currentPincode.substring(2, 3)}}
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{pincode.substring(3, 4)}}
|
{{currentPincode.substring(3, 4)}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue