request PIN to disable it - add disabled options

This commit is contained in:
JDonadio 2017-04-20 12:59:15 -03:00
parent 01343d120d
commit 328ec337e1
2 changed files with 34 additions and 11 deletions

View File

@ -12,6 +12,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
method: 'pin', method: 'pin',
label: gettextCatalog.getString('Lock by PIN'), label: gettextCatalog.getString('Lock by PIN'),
needsBackup: null, needsBackup: null,
disabled: null,
}, },
]; ];
@ -20,15 +21,11 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
method: 'fingerprint', method: 'fingerprint',
label: gettextCatalog.getString('Lock by Fingerprint'), label: gettextCatalog.getString('Lock by Fingerprint'),
needsBackup: null, needsBackup: null,
disabled: null,
}); });
} }
var config = configService.getSync(); checkAndSelectOption();
var method = config.lock && config.lock.method;
if (!method) $scope.currentOption = $scope.options[0];
else $scope.currentOption = lodash.find($scope.options, {
'method': method
});
processWallets(); processWallets();
}; };
@ -36,6 +33,26 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
init(); init();
}); });
function checkAndSelectOption() {
var config = configService.getSync();
var method = config.lock && config.lock.method;
if (!method) {
$scope.currentOption = $scope.options[0];
$scope.options[1].disabled = false;
$scope.options[2].disabled = false;
} else {
if (method == 'fingerprint') $scope.options[1].disabled = true;
if (method == 'pin') $scope.options[2].disabled = true;
$scope.currentOption = lodash.find($scope.options, {
'method': method
});
}
$timeout(function() {
$scope.$apply();
});
};
function processWallets() { function processWallets() {
var wallets = profileService.getWallets(); var wallets = profileService.getWallets();
var singleLivenetWallet = wallets.length == 1 && wallets[0].network == 'livenet' && wallets[0].needsBackup; var singleLivenetWallet = wallets.length == 1 && wallets[0].network == 'livenet' && wallets[0].needsBackup;
@ -73,9 +90,14 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
var config = configService.getSync(); var config = configService.getSync();
var savedMethod = config.lock && config.lock.method; var savedMethod = config.lock && config.lock.method;
if (!selectedMethod) if (!selectedMethod) {
saveConfig(); if (!savedMethod) return;
else if (selectedMethod == 'fingerprint') { if (savedMethod == 'pin') $state.transitionTo('tabs.pin', {
fromSettings: true,
locking: false,
});
else saveConfig();
} else if (selectedMethod == 'fingerprint') {
if (savedMethod == 'pin') { if (savedMethod == 'pin') {
askForDisablePin(function(disablePin) { askForDisablePin(function(disablePin) {
if (disablePin) saveConfig('fingerprint'); if (disablePin) saveConfig('fingerprint');
@ -116,6 +138,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio
configService.set(opts, function(err) { configService.set(opts, function(err) {
if (err) $log.debug(err); if (err) $log.debug(err);
checkAndSelectOption();
}); });
}; };
}); });

View File

@ -6,8 +6,8 @@
</ion-nav-bar> </ion-nav-bar>
<ion-content> <ion-content>
<ion-radio ng-repeat="opt in options" ng-value="opt" ng-model="currentOption" ng-click="select(opt.method)" ng-disabled="opt.needsBackup"> <ion-radio ng-repeat="opt in options" ng-value="opt" ng-model="currentOption" ng-click="select(opt.method)" ng-disabled="opt.needsBackup || opt.disabled">
<span ng-class="{'disabled': opt.needsBackup}">{{opt.label}}</span> <span ng-class="{'disabled': opt.needsBackup || opt.disabled}">{{opt.label}}</span>
</ion-radio> </ion-radio>
<div class="assertive" style="text-align: center; margin: 4rem" ng-if="errorMsg"> <div class="assertive" style="text-align: center; margin: 4rem" ng-if="errorMsg">