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 = { $scope.hideNextSteps = {
value: config.hideNextSteps.enabled value: config.hideNextSteps.enabled
}; };
$scope.usePincode = {
value: config.pincode ? config.pincode.enabled : false
};
}; };
$scope.spendUnconfirmedChange = function() { $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() { $scope.recentTransactionsChange = function() {
var opts = { var opts = {
recentTransactions: { recentTransactions: {

View file

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

View file

@ -1,6 +1,6 @@
'use strict'; '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.$on("$ionicView.beforeEnter", function(event) {
$scope.title = appConfigService.nameCase + ' ' + gettextCatalog.getString('is locked'); $scope.title = appConfigService.nameCase + ' ' + gettextCatalog.getString('is locked');
$scope.appName = appConfigService.name; $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', { .state('pin', {
url: '/pincode/', url: '/pin/',
controller: 'pincodeController', controller: 'pinController',
templateUrl: 'views/pincode.html', templateUrl: 'views/pin.html',
}) })
/* /*
* *
* Dead state - locked * Locked
* *
*/ */
.state('deadview', { .state('lockedView', {
url: '/deadview/', url: '/lockedView/',
controller: 'deadviewController', controller: 'lockedViewController',
templateUrl: 'views/deadview.html', templateUrl: 'views/lockedView.html',
}) })
/* /*
@ -463,21 +463,21 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
} }
} }
}) })
.state('tabs.lockapp', { .state('tabs.lock', {
url: '/lockapp', url: '/lock',
views: { views: {
'tab-settings@tabs': { 'tab-settings@tabs': {
controller: 'lockappController', controller: 'lockController',
templateUrl: 'views/lockapp.html', templateUrl: 'views/lock.html',
} }
} }
}) })
.state('tabs.lockapp.pincode', { .state('tabs.lock.pin', {
url: '/pincode/:fromSettings/:locking', url: '/pin/:fromSettings/:locking',
views: { views: {
'tab-settings@tabs': { 'tab-settings@tabs': {
controller: 'lockappController', controller: 'pinController',
templateUrl: 'views/pincode.html', templateUrl: 'views/pin.html',
cache: false cache: false
} }
} }
@ -1196,24 +1196,28 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
}); });
$ionicPlatform.on('resume', function() { $ionicPlatform.on('resume', function() {
configService.whenAvailable(function(config) { if (platformInfo.isCordova || platformInfo.isDevel) {
var nextView; configService.whenAvailable(function(config) {
var lockapp = config.lockapp; var nextView;
if (platformInfo.isCordova && fingerprintService.isAvailable() && lockapp.fingerprint && lockapp.fingerprint.enabled) { var lock = config.lock;
fingerprintService.check('unlockingApp', function(err) { if (lock && lock.method == 'fingerprint' && fingerprintService.isAvailable()) {
if (err) nextView = 'deadview'; fingerprintService.check('unlockingApp', function(err) {
else nextView = $ionicHistory.currentStateName(); if (err) nextView = 'lockedView';
goTo(nextView); else if ($ionicHistory.currentStateName() == 'lockedView') nextView = 'tabs.home';
}); else nextView = $ionicHistory.currentStateName();
} else if (platformInfo.isCordova && lockapp.pincode && lockapp.pincode.enabled) { goTo(nextView);
goTo('pincode'); });
} else } else if (lock && lock.method == 'pin') {
goTo('tabs.home'); goTo('pin');
}
function goTo(nextView) { function goTo(nextView) {
$state.go(nextView); $state.transitionTo(nextView).then(function() {
}; if (nextView == 'lockedView') $ionicHistory.clearHistory();
}); });
};
});
}
}); });
$ionicPlatform.on('menubutton', function() { $ionicPlatform.on('menubutton', function() {
@ -1256,25 +1260,27 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
disableAnimate: true, disableAnimate: true,
historyRoot: true historyRoot: true
}); });
configService.whenAvailable(function(config) { if (platformInfo.isCordova || platformInfo.isDevel) {
var lockapp = config.lockapp;
startupService.ready(); startupService.ready();
if ((platformInfo.isCordova || platformInfo.isDevel) && fingerprintService.isAvailable() && lockapp.fingerprint && lockapp.fingerprint.enabled) { configService.whenAvailable(function(config) {
fingerprintService.check('unlockingApp', function(err) { var lock = config.lock;
if (err) goTo('deadview'); if (fingerprintService.isAvailable() && lock && lock.method == 'fingerprint') {
else goTo('tabs.home'); fingerprintService.check('unlockingApp', function(err) {
}); if (err) goTo('lockedView');
} else if ((platformInfo.isCordova || platformInfo.isDevel) && lockapp.pincode && lockapp.pincode.enabled) { else goTo('tabs.home');
goTo('pincode'); });
} else } else if (lock && lock.method == 'pin') {
goTo('tabs.home'); goTo('pin');
} else
goTo('tabs.home');
function goTo(nextView) { function goTo(nextView) {
$state.transitionTo(nextView).then(function() { $state.transitionTo(nextView).then(function() {
$ionicHistory.clearHistory(); $ionicHistory.clearHistory();
}); });
}; };
}); });
}
}); });
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -32,7 +32,7 @@
<div ng-if="isCordova || isDevel"> <div ng-if="isCordova || isDevel">
<div class="item item-divider"></div> <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> <span translate>Lock App</span>
<i class="icon bp-arrow-right"></i> <i class="icon bp-arrow-right"></i>
</a> </a>

View file

@ -6,8 +6,8 @@
</ion-nav-bar> </ion-nav-bar>
<ion-content> <ion-content>
<ion-toggle ng-model="usePincode.enabled" toggle-class="toggle-balanced" ng-change="usePincodeChange()"> <ion-toggle ng-model="usePin.enabled" toggle-class="toggle-balanced" ng-change="usePinChange()">
<span class="toggle-label" translate>Enable Pin Code</span> <span class="toggle-label" translate>Enable Pin</span>
</ion-toggle> </ion-toggle>
<div ng-show="fingerprintAvailable"> <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-bar class="bar-royal">
<ion-nav-title>{{title}}</ion-nav-title> <ion-nav-title>{{title}}</ion-nav-title>
</ion-nav-bar> </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-bar class="bar-clear">
<ion-nav-back-button> <ion-nav-back-button>
</ion-nav-back-button> </ion-nav-back-button>
</ion-nav-bar> </ion-nav-bar>
<div class="content"> <div class="content">
<div class="block-text row"> <div class="block-text row">
<span translate ng-if="!newPincode && !isComplete()">Please enter your mobile unlock code</span> <span translate ng-if="!confirmPin && !error">Please enter your mobile unlock code</span>
<span translate ng-if="newPincode && !isComplete()">Confirm your mobile unlock code</span> <span translate ng-if="confirmPin && !error">Confirm your mobile unlock code</span>
<span translate ng-if="isComplete() && !locking && !match" class="error">Incorrect code, try again.</span> <span translate ng-if="error" class="error">Incorrect code, try again.</span>
</div> </div>
<div class="app-icon"> <div class="app-icon">
<i class="icon big-icon-svg"> <i class="icon big-icon-svg">
@ -24,43 +24,41 @@
</div> </div>
<div class="block-buttons"> <div class="block-buttons">
<div class="row"> <div class="row">
<div class="col" ng-click="updatePinCode('1')"> <div class="col" ng-click="updatePin('1')">
<div class="keyboard">1</div> <div class="keyboard">1</div>
</div> </div>
<div class="col" ng-click="updatePinCode('2')"> <div class="col" ng-click="updatePin('2')">
<div class="keyboard">2</div> <div class="keyboard">2</div>
</div> </div>
<div class="col" ng-click="updatePinCode('3')"> <div class="col" ng-click="updatePin('3')">
<div class="keyboard">3</div> <div class="keyboard">3</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col" ng-click="updatePinCode('4')"> <div class="col" ng-click="updatePin('4')">
<div class="keyboard">4</div> <div class="keyboard">4</div>
</div> </div>
<div class="col" ng-click="updatePinCode('5')"> <div class="col" ng-click="updatePin('5')">
<div class="keyboard">5</div> <div class="keyboard">5</div>
</div> </div>
<div class="col" ng-click="updatePinCode('6')"> <div class="col" ng-click="updatePin('6')">
<div class="keyboard">6</div> <div class="keyboard">6</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col" ng-click="updatePinCode('7')"> <div class="col" ng-click="updatePin('7')">
<div class="keyboard">7</div> <div class="keyboard">7</div>
</div> </div>
<div class="col" ng-click="updatePinCode('8')"> <div class="col" ng-click="updatePin('8')">
<div class="keyboard">8</div> <div class="keyboard">8</div>
</div> </div>
<div class="col" ng-click="updatePinCode('9')"> <div class="col" ng-click="updatePin('9')">
<div class="keyboard">9</div> <div class="keyboard">9</div>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col" ng-click="save()"> <div class="col"></div>
<div class="keyboard icon ion-checkmark" ng-disabled=""></div> <div class="col" ng-click="updatePin('0')">
</div>
<div class="col" ng-click="updatePinCode('0')">
<div class="">0</div> <div class="">0</div>
</div> </div>
<div class="col" ng-click="delete()"> <div class="col" ng-click="delete()">