This commit is contained in:
JDonadio 2017-03-29 11:30:16 -03:00
commit 5c2b067c87
14 changed files with 196 additions and 218 deletions

View file

@ -14,9 +14,6 @@ angular.module('copayApp.controllers').controller('advancedSettingsController',
$scope.hideNextSteps = {
value: config.hideNextSteps.enabled
};
$scope.usePincode = {
value: config.pincode ? config.pincode.enabled : false
};
};
$scope.spendUnconfirmedChange = function() {
@ -41,23 +38,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() {
var opts = {
recentTransactions: {

View file

@ -1,28 +1,28 @@
'use strict';
angular.module('copayApp.controllers').controller('lockappController', function($state, $scope, $timeout, $log, configService, popupService, gettextCatalog, appConfigService) {
angular.module('copayApp.controllers').controller('lockController', function($state, $scope, $timeout, $log, configService, popupService, gettextCatalog, appConfigService, fingerprintService) {
$scope.$on("$ionicView.beforeEnter", function(event) {
var config = configService.getSync();
$scope.fingerprintAvailable = fingerprintService.isAvailable();
$scope.usePincode = {
enabled: config.lockapp ? config.lockapp.pincode.enabled : false
$scope.usePin = {
enabled: config.lock && config.lock.method == 'pin' ? true : false
};
$scope.useFingerprint = {
enabled: config.lockapp ? config.lockapp.fingerprint.enabled : false
enabled: config.lock && config.lock.method == 'fingerprint' ? true : false
};
});
$scope.usePincodeChange = function() {
$state.go('tabs.lockapp.pincode', {
$scope.usePinChange = function() {
$state.go('tabs.lock.pin', {
fromSettings: true,
locking: $scope.usePincode.enabled
locking: $scope.usePin.enabled
});
};
$scope.useFingerprintChange = function() {
if ($scope.usePincode.enabled) {
if ($scope.usePin.enabled) {
var message = gettextCatalog.getString('{{appName}} is protected by Pin Code. Are you sure you want to disable it?', {
appName: appConfigService.nameCase
});
@ -44,21 +44,16 @@ angular.module('copayApp.controllers').controller('lockappController', function(
saveConfig();
function saveConfig() {
$scope.usePincode = {
$scope.usePin = {
enabled: false
};
$timeout(function() {
$scope.$apply();
});
var opts = {
lockapp: {
pincode: {
enabled: false,
value: ''
},
fingerprint: {
enabled: $scope.useFingerprint.enabled
}
lock: {
method: $scope.useFingerprint.enabled ? 'fingerprint' : '',
value: '',
}
};

View file

@ -1,6 +1,6 @@
'use strict';
angular.module('copayApp.controllers').controller('deadviewController', function($state, $scope, $ionicHistory, fingerprintService, appConfigService, gettextCatalog) {
angular.module('copayApp.controllers').controller('lockedViewController', function($state, $scope, $ionicHistory, fingerprintService, appConfigService, gettextCatalog) {
$scope.$on("$ionicView.beforeEnter", function(event) {
$scope.title = appConfigService.nameCase + ' ' + gettextCatalog.getString('is locked');
$scope.appName = appConfigService.name;

98
src/js/controllers/pin.js Normal file
View file

@ -0,0 +1,98 @@
'use strict';
angular.module('copayApp.controllers').controller('pinController', function($state, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService) {
var PIN = 'pin';
$scope.$on("$ionicView.beforeEnter", function(event) {
$scope.currentPin = $scope.confirmPin = '';
$scope.fromSettings = $stateParams.fromSettings == 'true' ? true : false;
$scope.locking = $stateParams.locking == 'true' ? true : false;
$scope.match = false;
$scope.error = false;
$scope.appName = appConfigService.name;
});
$scope.getFilledClass = function(limit) {
return $scope.currentPin.length >= limit ? 'filled-' + $scope.appName : null;
};
$scope.delete = function() {
if ($scope.currentPin.length > 0) {
$scope.currentPin = $scope.currentPin.substring(0, $scope.currentPin.length - 1);
$scope.error = false;
$scope.updatePin();
}
};
$scope.isComplete = function() {
if ($scope.currentPin.length < 4) return false;
else return true;
};
$scope.updatePin = function(value) {
$scope.error = false;
if (value && !$scope.isComplete()) {
$scope.currentPin = $scope.currentPin + value;
$timeout(function() {
$scope.$apply();
});
}
$scope.save();
};
$scope.save = function() {
if (!$scope.isComplete()) return;
var config = configService.getSync();
$scope.match = config.lock && config.lock.method == PIN && config.lock.value == $scope.currentPin ? true : false;
if (!$scope.locking) {
if ($scope.match) {
$scope.fromSettings ? saveSettings() : $scope.close(150);
$scope.error = false;
} else {
$scope.confirmPin = $scope.currentPin = '';
$scope.error = true;
}
} else {
processCodes();
}
};
function processCodes() {
if (!$scope.confirmPin) {
$scope.confirmPin = $scope.currentPin;
$timeout(function() {
$scope.currentPin = '';
}, 200);
} else {
if ($scope.confirmPin == $scope.currentPin)
saveSettings(PIN, $scope.confirmPin);
else {
$scope.confirmPin = $scope.currentPin = '';
$scope.error = true;
}
}
$timeout(function() {
$scope.$apply();
});
};
function saveSettings(method, value) {
var opts = {
lock: {
method: method || '',
value: value || '',
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
$scope.close();
});
};
$scope.close = function(delay) {
$timeout(function() {
$ionicHistory.viewHistory().backView ? $ionicHistory.goBack() : $state.go('tabs.home');
}, delay || 1);
};
});

View file

@ -1,94 +0,0 @@
'use strict';
angular.module('copayApp.controllers').controller('pincodeController', function($state, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService) {
$scope.$on("$ionicView.beforeEnter", function(event) {
$scope.currentPincode = $scope.newPincode = '';
$scope.fromSettings = $stateParams.fromSettings == 'true' ? true : false;
$scope.locking = $stateParams.locking == 'true' ? true : false;
$scope.match = false;
$scope.appName = appConfigService.name;
});
$scope.getFilledClass = function(limit) {
return $scope.currentPincode.length >= limit ? 'filled-' + $scope.appName : null;
};
$scope.delete = function() {
if ($scope.currentPincode.length > 0) {
$scope.currentPincode = $scope.currentPincode.substring(0, $scope.currentPincode.length - 1);
$scope.updatePinCode();
}
};
$scope.isComplete = function() {
if ($scope.currentPincode.length < 4) return false;
else return true;
};
$scope.updatePinCode = function(value) {
if (value && !$scope.isComplete()) {
$scope.currentPincode = $scope.currentPincode + value;
}
$timeout(function() {
$scope.$apply();
});
if (!$scope.locking && $scope.isComplete()) {
$scope.save();
}
};
$scope.save = function() {
if (!$scope.isComplete()) return;
var config = configService.getSync();
$scope.match = config.lockapp.pincode.value == $scope.currentPincode ? true : false;
$timeout(function() {
$scope.$apply();
});
if (!$scope.locking) {
if ($scope.match) {
$scope.fromSettings ? saveSettings($scope.locking, '') : $scope.close(150);
}
} else {
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);
}
};
function saveSettings(enabled, value) {
var opts = {
lockapp: {
pincode: {
enabled: enabled,
value: value
},
fingerprint: {
enabled: false
}
}
};
configService.set(opts, function(err) {
if (err) $log.debug(err);
$scope.close();
});
};
$scope.close = function(delay) {
$timeout(function() {
$ionicHistory.viewHistory().backView ? $ionicHistory.goBack() : $state.go('tabs.home');
}, delay || 1);
};
});