add pincode service - refactor
This commit is contained in:
parent
82e556b026
commit
313269a45c
5 changed files with 85 additions and 48 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $rootScope, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $timeout, $ionicScrollDelegate) {
|
angular.module('copayApp.controllers').controller('advancedSettingsController', function($scope, $rootScope, $log, $window, $ionicModal, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService, storageService, $ionicHistory, $ionicScrollDelegate, pincodeService) {
|
||||||
|
|
||||||
var updateConfig = function() {
|
var updateConfig = function() {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
|
|
@ -15,7 +15,7 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
|
||||||
value: config.hideNextSteps.enabled
|
value: config.hideNextSteps.enabled
|
||||||
};
|
};
|
||||||
$scope.usePincode = {
|
$scope.usePincode = {
|
||||||
value: config.pincode ? config.pincode.enabled : false
|
enabled: config.pincode ? config.pincode.enabled : false
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -41,23 +41,6 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.savePincodeChanges = function(val) {
|
|
||||||
if (!val || val.length < 4) {
|
|
||||||
$scope.usePincode = {
|
|
||||||
value: false
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var opts = {
|
|
||||||
usePincode: {
|
|
||||||
enabled: $scope.usePincode.enabled
|
|
||||||
},
|
|
||||||
};
|
|
||||||
configService.set(opts, function(err) {
|
|
||||||
if (err) $log.debug(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
$scope.recentTransactionsChange = function() {
|
$scope.recentTransactionsChange = function() {
|
||||||
var opts = {
|
var opts = {
|
||||||
recentTransactions: {
|
recentTransactions: {
|
||||||
|
|
@ -69,15 +52,20 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.showPincodeModal = function() {
|
$scope.usePincodeChange = function() {
|
||||||
$scope.fromSettings = true;
|
var opts = {};
|
||||||
$ionicModal.fromTemplateUrl('views/modals/pincode.html', {
|
opts.enabled = $scope.usePincode.enabled;
|
||||||
scope: $scope,
|
opts.from = 'settings';
|
||||||
backdropClickToClose: false,
|
|
||||||
hardwareBackButtonClose: false
|
pincodeService.lockChange(opts, function(err) {
|
||||||
}).then(function(modal) {
|
if (err) {
|
||||||
$scope.pincodeModal = modal;
|
$log.warn(err);
|
||||||
$scope.pincodeModal.show();
|
|
||||||
|
// ToDo show error?
|
||||||
|
$scope.usePincode.enabled = false;
|
||||||
|
$scope.$apply();
|
||||||
|
return;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('pincodeController', function($timeout, $scope, $log, $window, configService) {
|
angular.module('copayApp.controllers').controller('pincodeController', function($timeout, $scope, $log, $window, configService) {
|
||||||
$scope.pincode = '';
|
var config = configService.getSync();
|
||||||
|
$scope.currentPincode = config.pincode ? config.pincode.value : null;
|
||||||
|
$scope.pincode = $scope.pc1 = $scope.pc2 = '';
|
||||||
|
|
||||||
|
console.log('#######', $scope.from, $scope.enabled);
|
||||||
|
|
||||||
angular.element($window).on('keydown', function(e) {
|
angular.element($window).on('keydown', function(e) {
|
||||||
if (e.which === 8) { // you can add others here inside brackets.
|
if (e.which === 8) { // you can add others here inside brackets.
|
||||||
|
|
@ -9,15 +13,16 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
|
||||||
$scope.delete();
|
$scope.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.key && e.key.match(/^[0-9]$/))
|
if (e && e.key.match(/^[0-9]$/))
|
||||||
$scope.add(e.key);
|
$scope.add(e.key);
|
||||||
else if (e.key && e.key == 'Enter')
|
else if (e && e.keyCode == 27)
|
||||||
checkPasscode();
|
$scope.close(false);
|
||||||
|
else if (e && e.keyCode == 13)
|
||||||
|
$scope.save();
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.add = function(value) {
|
$scope.add = function(value) {
|
||||||
if (isComplete()) checkPasscode();
|
updatePassCode(value);
|
||||||
else updatePassCode(value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.delete = function() {
|
$scope.delete = function() {
|
||||||
|
|
@ -33,24 +38,36 @@ angular.module('copayApp.controllers').controller('pincodeController', function(
|
||||||
};
|
};
|
||||||
|
|
||||||
function updatePassCode(value) {
|
function updatePassCode(value) {
|
||||||
if (value) $scope.pincode = $scope.pincode + value;
|
if (value && $scope.pincode.length < 4)
|
||||||
|
$scope.pincode = $scope.pincode + value;
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
checkPasscode();
|
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkPasscode() {
|
$scope.save = function() {
|
||||||
console.log('Checking');
|
if (!$scope.pc1) {
|
||||||
configService.whenAvailable(function(config) {
|
console.log('No pc 1');
|
||||||
var value = '1234';
|
$scope.pc1 = $scope.pincode;
|
||||||
if (value != $scope.pincode) return;
|
console.log('$scope.pc1', $scope.pc1);
|
||||||
console.log('MATCH');
|
$scope.pincode = '';
|
||||||
});
|
$timeout(function() {
|
||||||
|
$scope.$apply();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
$scope.pc2 = $scope.pincode;
|
||||||
|
console.log('$scope.pc2', $scope.pc2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($scope.pc1 == $scope.pc2) {
|
||||||
|
$scope.close($scope.pc1);
|
||||||
|
} else {
|
||||||
|
$scope.enabled ? pincodeService.lockApp() : pincodeService.unlockApp();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.cancel = function() {
|
$scope.close = function() {
|
||||||
$scope.savePincodeChanges(false);
|
|
||||||
$scope.pincodeModal.hide();
|
$scope.pincodeModal.hide();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
32
src/js/services/pincodeService.js
Normal file
32
src/js/services/pincodeService.js
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('copayApp.services').factory('pincodeService', function($log, $rootScope, $ionicModal, configService) {
|
||||||
|
var root = {};
|
||||||
|
|
||||||
|
var openPincodeModal = function(opts) {
|
||||||
|
var scope = $rootScope.$new(true);
|
||||||
|
scope.from = opts.from;
|
||||||
|
scope.enabled = opts.enabled;
|
||||||
|
$ionicModal.fromTemplateUrl('views/modals/pincode.html', {
|
||||||
|
scope: scope,
|
||||||
|
backdropClickToClose: false,
|
||||||
|
hardwareBackButtonClose: false
|
||||||
|
}).then(function(modal) {
|
||||||
|
scope.pincodeModal = modal;
|
||||||
|
scope.pincodeModal.show();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
root.lockChange = function(opts, cb) {
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
<div class="item item-divider"></div>
|
<div class="item item-divider"></div>
|
||||||
|
|
||||||
<ion-toggle ng-model="usePincode.value" toggle-class="toggle-balanced" ng-change="showPincodeModal()">
|
<ion-toggle ng-model="usePincode.enabled" toggle-class="toggle-balanced" ng-change="usePincodeChange()">
|
||||||
<span class="toggle-label" translate>Use pin to lock/unlock the app</span>
|
<span class="toggle-label" translate>Use pin to lock/unlock the app</span>
|
||||||
</ion-toggle>
|
</ion-toggle>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<ion-modal-view id="pin-code" ng-controller="pincodeController">
|
<ion-modal-view id="pin-code" ng-controller="pincodeController">
|
||||||
<div ng-if="fromSettings" ng-click="cancel()" class="close" translate>Close</div>
|
<div ng-if="from == 'settings'" ng-click="close()" class="close" translate>Close</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="block-code">
|
<div class="block-code">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button class="button button-light button-stretch icon ion-checkmark" ng-click="save()"></button>
|
<button class="button button-light button-stretch icon ion-checkmark" ng-click="save()" ng-disabled=""></button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button class="button button-light button-stretch" ng-click="add('0')">0</button>
|
<button class="button button-light button-stretch" ng-click="add('0')">0</button>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue