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);
};
});

View file

@ -121,26 +121,26 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
/*
*
* Pin code
* Pin
*
*/
.state('pincode', {
url: '/pincode/',
controller: 'pincodeController',
templateUrl: 'views/pincode.html',
.state('pin', {
url: '/pin/',
controller: 'pinController',
templateUrl: 'views/pin.html',
})
/*
*
* Dead state - locked
* Locked
*
*/
.state('deadview', {
url: '/deadview/',
controller: 'deadviewController',
templateUrl: 'views/deadview.html',
.state('lockedView', {
url: '/lockedView/',
controller: 'lockedViewController',
templateUrl: 'views/lockedView.html',
})
/*
@ -463,21 +463,21 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}
}
})
.state('tabs.lockapp', {
url: '/lockapp',
.state('tabs.lock', {
url: '/lock',
views: {
'tab-settings@tabs': {
controller: 'lockappController',
templateUrl: 'views/lockapp.html',
controller: 'lockController',
templateUrl: 'views/lock.html',
}
}
})
.state('tabs.lockapp.pincode', {
url: '/pincode/:fromSettings/:locking',
.state('tabs.lock.pin', {
url: '/pin/:fromSettings/:locking',
views: {
'tab-settings@tabs': {
controller: 'lockappController',
templateUrl: 'views/pincode.html',
controller: 'pinController',
templateUrl: 'views/pin.html',
cache: false
}
}
@ -1196,24 +1196,28 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
});
$ionicPlatform.on('resume', function() {
configService.whenAvailable(function(config) {
var nextView;
var lockapp = config.lockapp;
if (platformInfo.isCordova && fingerprintService.isAvailable() && lockapp.fingerprint && lockapp.fingerprint.enabled) {
fingerprintService.check('unlockingApp', function(err) {
if (err) nextView = 'deadview';
else nextView = $ionicHistory.currentStateName();
goTo(nextView);
});
} else if (platformInfo.isCordova && lockapp.pincode && lockapp.pincode.enabled) {
goTo('pincode');
} else
goTo('tabs.home');
if (platformInfo.isCordova || platformInfo.isDevel) {
configService.whenAvailable(function(config) {
var nextView;
var lock = config.lock;
if (lock && lock.method == 'fingerprint' && fingerprintService.isAvailable()) {
fingerprintService.check('unlockingApp', function(err) {
if (err) nextView = 'lockedView';
else if ($ionicHistory.currentStateName() == 'lockedView') nextView = 'tabs.home';
else nextView = $ionicHistory.currentStateName();
goTo(nextView);
});
} else if (lock && lock.method == 'pin') {
goTo('pin');
}
function goTo(nextView) {
$state.go(nextView);
};
});
function goTo(nextView) {
$state.transitionTo(nextView).then(function() {
if (nextView == 'lockedView') $ionicHistory.clearHistory();
});
};
});
}
});
$ionicPlatform.on('menubutton', function() {
@ -1256,25 +1260,27 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
disableAnimate: true,
historyRoot: true
});
configService.whenAvailable(function(config) {
var lockapp = config.lockapp;
if (platformInfo.isCordova || platformInfo.isDevel) {
startupService.ready();
if ((platformInfo.isCordova || platformInfo.isDevel) && fingerprintService.isAvailable() && lockapp.fingerprint && lockapp.fingerprint.enabled) {
fingerprintService.check('unlockingApp', function(err) {
if (err) goTo('deadview');
else goTo('tabs.home');
});
} else if ((platformInfo.isCordova || platformInfo.isDevel) && lockapp.pincode && lockapp.pincode.enabled) {
goTo('pincode');
} else
goTo('tabs.home');
configService.whenAvailable(function(config) {
var lock = config.lock;
if (fingerprintService.isAvailable() && lock && lock.method == 'fingerprint') {
fingerprintService.check('unlockingApp', function(err) {
if (err) goTo('lockedView');
else goTo('tabs.home');
});
} else if (lock && lock.method == 'pin') {
goTo('pin');
} else
goTo('tabs.home');
function goTo(nextView) {
$state.transitionTo(nextView).then(function() {
$ionicHistory.clearHistory();
});
};
});
function goTo(nextView) {
$state.transitionTo(nextView).then(function() {
$ionicHistory.clearHistory();
});
};
});
}
});
}

View file

@ -53,14 +53,9 @@ angular.module('copayApp.services').factory('configService', function(storageSer
}
},
lockapp: {
pincode: {
enabled: false,
value: '',
},
fingerprint: {
enabled: false
}
lock: {
method: '',
value: '',
},
// External services

View file

@ -1,4 +1,4 @@
#dead-view {
#locked-view {
@mixin img-frame {
height: 60px;
width: 60px;

View file

@ -1,4 +1,4 @@
#pin-code {
#pin {
background-color: #FAFAFA;
.bar.bar-clear {
background-color: transparent;

View file

@ -46,5 +46,5 @@
@import "includes/accountSelector";
@import "integrations/integrations";
@import "custom-amount";
@import "pincode";
@import "deadview";
@import "pin";
@import "lockedView";

View file

@ -32,7 +32,7 @@
<div ng-if="isCordova || isDevel">
<div class="item item-divider"></div>
<a class="item item-icon-right" ui-sref="tabs.lockapp">
<a class="item item-icon-right" ui-sref="tabs.lock">
<span translate>Lock App</span>
<i class="icon bp-arrow-right"></i>
</a>

View file

@ -6,8 +6,8 @@
</ion-nav-bar>
<ion-content>
<ion-toggle ng-model="usePincode.enabled" toggle-class="toggle-balanced" ng-change="usePincodeChange()">
<span class="toggle-label" translate>Enable Pin Code</span>
<ion-toggle ng-model="usePin.enabled" toggle-class="toggle-balanced" ng-change="usePinChange()">
<span class="toggle-label" translate>Enable Pin</span>
</ion-toggle>
<div ng-show="fingerprintAvailable">

View file

@ -1,4 +1,4 @@
<ion-view id="dead-view">
<ion-view id="locked-view">
<ion-nav-bar class="bar-royal">
<ion-nav-title>{{title}}</ion-nav-title>
</ion-nav-bar>

View file

@ -1,13 +1,13 @@
<ion-view id="pin-code" ng-controller="pincodeController" hide-tabs hide-back-button="!fromSettings">
<ion-view id="pin" hide-tabs hide-back-button="!fromSettings">
<ion-nav-bar class="bar-clear">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<div class="content">
<div class="block-text row">
<span translate ng-if="!newPincode && !isComplete()">Please enter your mobile unlock code</span>
<span translate ng-if="newPincode && !isComplete()">Confirm your mobile unlock code</span>
<span translate ng-if="isComplete() && !locking && !match" class="error">Incorrect code, try again.</span>
<span translate ng-if="!confirmPin && !error">Please enter your mobile unlock code</span>
<span translate ng-if="confirmPin && !error">Confirm your mobile unlock code</span>
<span translate ng-if="error" class="error">Incorrect code, try again.</span>
</div>
<div class="app-icon">
<i class="icon big-icon-svg">
@ -24,43 +24,41 @@
</div>
<div class="block-buttons">
<div class="row">
<div class="col" ng-click="updatePinCode('1')">
<div class="col" ng-click="updatePin('1')">
<div class="keyboard">1</div>
</div>
<div class="col" ng-click="updatePinCode('2')">
<div class="col" ng-click="updatePin('2')">
<div class="keyboard">2</div>
</div>
<div class="col" ng-click="updatePinCode('3')">
<div class="col" ng-click="updatePin('3')">
<div class="keyboard">3</div>
</div>
</div>
<div class="row">
<div class="col" ng-click="updatePinCode('4')">
<div class="col" ng-click="updatePin('4')">
<div class="keyboard">4</div>
</div>
<div class="col" ng-click="updatePinCode('5')">
<div class="col" ng-click="updatePin('5')">
<div class="keyboard">5</div>
</div>
<div class="col" ng-click="updatePinCode('6')">
<div class="col" ng-click="updatePin('6')">
<div class="keyboard">6</div>
</div>
</div>
<div class="row">
<div class="col" ng-click="updatePinCode('7')">
<div class="col" ng-click="updatePin('7')">
<div class="keyboard">7</div>
</div>
<div class="col" ng-click="updatePinCode('8')">
<div class="col" ng-click="updatePin('8')">
<div class="keyboard">8</div>
</div>
<div class="col" ng-click="updatePinCode('9')">
<div class="col" ng-click="updatePin('9')">
<div class="keyboard">9</div>
</div>
</div>
<div class="row">
<div class="col" ng-click="save()">
<div class="keyboard icon ion-checkmark" ng-disabled=""></div>
</div>
<div class="col" ng-click="updatePinCode('0')">
<div class="col"></div>
<div class="col" ng-click="updatePin('0')">
<div class="">0</div>
</div>
<div class="col" ng-click="delete()">