Wallet/src/js/controllers/pincode.js

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-02-23 16:56:46 -05:00
'use strict';
2017-02-24 14:46:54 -05:00
angular.module('copayApp.controllers').controller('pincodeController', function($timeout, $scope, $log, $window, configService) {
$scope.pincode = '';
2017-02-23 16:56:46 -05:00
angular.element($window).on('keydown', function(e) {
if (e.which === 8) { // you can add others here inside brackets.
e.preventDefault();
$scope.delete();
}
if (e.key && e.key.match(/^[0-9]$/))
$scope.add(e.key);
else if (e.key && e.key == 'Enter')
2017-02-24 14:46:54 -05:00
checkPasscode();
2017-02-23 16:56:46 -05:00
});
$scope.add = function(value) {
2017-02-24 14:46:54 -05:00
if (isComplete()) checkPasscode();
2017-02-23 16:56:46 -05:00
else updatePassCode(value);
};
$scope.delete = function() {
2017-02-24 14:46:54 -05:00
if ($scope.pincode.length > 0) {
$scope.pincode = $scope.pincode.substring(0, $scope.pincode.length - 1);
2017-02-23 16:56:46 -05:00
updatePassCode();
}
};
function isComplete() {
2017-02-24 14:46:54 -05:00
if ($scope.pincode.length < 4) return false;
2017-02-23 16:56:46 -05:00
else return true;
};
function updatePassCode(value) {
2017-02-24 14:46:54 -05:00
if (value) $scope.pincode = $scope.pincode + value;
2017-02-23 16:56:46 -05:00
$timeout(function() {
2017-02-24 14:46:54 -05:00
checkPasscode();
2017-02-23 16:56:46 -05:00
$scope.$apply();
});
};
2017-02-24 14:46:54 -05:00
function checkPasscode() {
configService.whenAvailable(function(config) {
var value = '1234';
if (value != $scope.pincode) return;
console.log('MATCH');
});
};
2017-02-23 16:56:46 -05:00
});