From 9bb12e91f5190f4182d916eb06ec5551b4ac9d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 11:48:12 -0300 Subject: [PATCH 01/12] adding test modal for pin --- src/js/controllers/modals/pintest.js | 12 +++ src/js/controllers/pin.js | 9 ++- src/js/routes.js | 111 ++++++++++++++------------ src/js/services/applicationService.js | 38 ++++++++- www/views/modals/pintestview.html | 10 +++ 5 files changed, 127 insertions(+), 53 deletions(-) create mode 100644 src/js/controllers/modals/pintest.js create mode 100644 www/views/modals/pintestview.html diff --git a/src/js/controllers/modals/pintest.js b/src/js/controllers/modals/pintest.js new file mode 100644 index 000000000..2ab63e625 --- /dev/null +++ b/src/js/controllers/modals/pintest.js @@ -0,0 +1,12 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('pinTestController', function($scope, applicationService) { + + $scope.goodPin = function() { + applicationService.successfullUnlocked = true; + $scope.pintestview.hide(); + }; + + $scope.badPin = function() {}; + +}); diff --git a/src/js/controllers/pin.js b/src/js/controllers/pin.js index 20862c9d0..27fb48def 100644 --- a/src/js/controllers/pin.js +++ b/src/js/controllers/pin.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('pinController', function($state, $interval, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService) { +angular.module('copayApp.controllers').controller('pinController', function($state, $interval, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService, applicationService) { var ATTEMPT_LIMIT = 3; var ATTEMPT_LOCK_OUT_TIME = 5 * 60; var currentPin; @@ -126,7 +126,12 @@ angular.module('copayApp.controllers').controller('pinController', function($sta } break; case 'check': - if (isMatch(currentPin)) return $scope.close(); + if (isMatch(currentPin)) { + console.log("##################################### CHECKING"); + applicationService.successfullUnlocked = true; + $scope.close(); + return; + } showError(); checkAttempts(); break; diff --git a/src/js/routes.js b/src/js/routes.js index ac5889e1f..70c32b5bb 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1135,7 +1135,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }); }) - .run(function($rootScope, $state, $location, $log, $timeout, startupService, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService) { + .run(function($rootScope, $state, $location, $log, $timeout, startupService, fingerprintService, $ionicHistory, $ionicPlatform, $window, appConfigService, lodash, platformInfo, profileService, uxLanguage, gettextCatalog, openURLService, storageService, scannerService, configService, /* plugins START HERE => */ coinbaseService, glideraService, amazonService, bitpayCardService, applicationService) { uxLanguage.init(); @@ -1196,55 +1196,56 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr }); - function checkAndApplyLock(onResume) { - var defaultView = 'tabs.home'; - - if (!platformInfo.isCordova && !platformInfo.isDevel) { - goTo(defaultView); - } - - if (onResume) { - var now = Math.floor(Date.now() / 1000); - if (now < openURLService.unlockUntil) { - openURLService.unlockUntil = null; - $log.debug('Skip startup locking'); - return; - } - } - - function goTo(nextView) { - nextView = nextView || defaultView; - $state.transitionTo(nextView, { - action: 'check' - }).then(function() { - if (nextView == 'lockedView') - $ionicHistory.clearHistory(); - }); - }; - - startupService.ready(); - - configService.whenAvailable(function(config) { - var lockMethod = config.lock && config.lock.method; - $log.debug('App Lock:' + (lockMethod || 'no')); - - if (lockMethod == 'fingerprint' && fingerprintService.isAvailable()) { - fingerprintService.check('unlockingApp', function(err) { - if (err) - goTo('lockedView'); - else if ($ionicHistory.currentStateName() == 'lockedView' || !onResume) - goTo('tabs.home'); - }); - } else if (lockMethod == 'pin') { - goTo('pin'); - } else { - goTo(defaultView); - } - }); - } + // function checkAndApplyLock(onResume) { + // var defaultView = 'tabs.home'; + // + // if (!platformInfo.isCordova && !platformInfo.isDevel) { + // goTo(defaultView); + // } + // + // if (onResume) { + // var now = Math.floor(Date.now() / 1000); + // if (now < openURLService.unlockUntil) { + // openURLService.unlockUntil = null; + // $log.debug('Skip startup locking'); + // return; + // } + // } + // + // function goTo(nextView) { + // nextView = nextView || defaultView; + // $state.transitionTo(nextView, { + // action: 'check' + // }).then(function() { + // if (nextView == 'lockedView') + // $ionicHistory.clearHistory(); + // }); + // }; + // + // startupService.ready(); + // + // configService.whenAvailable(function(config) { + // var lockMethod = config.lock && config.lock.method; + // $log.debug('App Lock:' + (lockMethod || 'no')); + // + // if (lockMethod == 'fingerprint' && fingerprintService.isAvailable()) { + // fingerprintService.check('unlockingApp', function(err) { + // if (err) + // goTo('lockedView'); + // else if ($ionicHistory.currentStateName() == 'lockedView' || !onResume) + // goTo('tabs.home'); + // }); + // } else if (lockMethod == 'pin') { + // goTo('pin'); + // } else { + // goTo(defaultView); + // } + // }); + // } $ionicPlatform.on('resume', function() { - checkAndApplyLock(true); + applicationService.successfullUnlocked = false; + // checkAndApplyLock(true); }); $ionicPlatform.on('menubutton', function() { @@ -1287,8 +1288,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr disableAnimate: true, historyRoot: true }); - - checkAndApplyLock(); + $state.transitionTo('tabs.home'); }); }; // After everything have been loaded, initialize handler URL @@ -1316,5 +1316,16 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $log.debug('Route change from:', fromState.name || '-', ' to:', toState.name); $log.debug(' toParams:' + JSON.stringify(toParams || {})); $log.debug(' fromParams:' + JSON.stringify(fromParams || {})); + configService.whenAvailable(function(config) { + var lockMethod = config.lock && config.lock.method; + console.log(lockMethod); + console.log("########################"); + if (!lockMethod || lockMethod == 'none') return; + + if (!applicationService.successfullUnlocked && !applicationService.pinIsOpen) { + console.log("################################# OPEN PIN MODAL"); + applicationService.pinModal(); + } + }); }); }); diff --git a/src/js/services/applicationService.js b/src/js/services/applicationService.js index 7ec528f46..bcefb8f55 100644 --- a/src/js/services/applicationService.js +++ b/src/js/services/applicationService.js @@ -1,8 +1,11 @@ 'use strict'; angular.module('copayApp.services') - .factory('applicationService', function($rootScope, $timeout, $ionicHistory, platformInfo, $state) { + .factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, $state) { var root = {}; + root.successfullUnlocked = false; + root.pinIsOpen = false; + var isChromeApp = platformInfo.isChromeApp; var isNW = platformInfo.isNW; @@ -33,5 +36,38 @@ angular.module('copayApp.services') } }; + root.pinModal = function() { + + root.pinIsOpen = true; + root.successfullUnlocked = false; + var scope = $rootScope.$new(true); + $ionicModal.fromTemplateUrl('views/modals/pintestview.html', { + scope: scope, + animation: 'slide-in-up', + backdropClickToClose: false, + hardwareBackButtonClose: false + }).then(function(modal) { + scope.pintestview = modal; + scope.pintestview.show(); + }); + scope.openModal = function() { + scope.modal.show(); + }; + scope.closeModal = function() { + scope.modal.hide(); + }; + // Cleanup the modal when we're done with it! + scope.$on('$destroy', function() { + scope.modal.remove(); + }); + // Execute action on hide modal + scope.$on('modal.hidden', function() { + // Execute action + }); + // Execute action on remove modal + scope.$on('modal.removed', function() { + // Execute action + }); + } return root; }); diff --git a/www/views/modals/pintestview.html b/www/views/modals/pintestview.html new file mode 100644 index 000000000..0f1f6afe4 --- /dev/null +++ b/www/views/modals/pintestview.html @@ -0,0 +1,10 @@ + + + + + + From 282f549ed0c584ac6bae48f14ddc05f29a5a3b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 12:19:08 -0300 Subject: [PATCH 02/12] adding to pin modal to resume --- src/js/controllers/modals/pin.js | 224 ++++++++++++++++++++++++++++++ src/js/routes.js | 1 + src/js/services/glideraService.js | 28 ++-- www/views/modals/pin.html | 69 +++++++++ 4 files changed, 310 insertions(+), 12 deletions(-) create mode 100644 src/js/controllers/modals/pin.js create mode 100644 www/views/modals/pin.html diff --git a/src/js/controllers/modals/pin.js b/src/js/controllers/modals/pin.js new file mode 100644 index 000000000..5d3f23a27 --- /dev/null +++ b/src/js/controllers/modals/pin.js @@ -0,0 +1,224 @@ +'use strict'; + +angular.module('copayApp.controllers').controller('pinController', function($state, $interval, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService, applicationService) { + var ATTEMPT_LIMIT = 3; + var ATTEMPT_LOCK_OUT_TIME = 5 * 60; + var currentPin; + + $scope.$on("$ionicView.beforeEnter", function(event) { + currentPin = $scope.confirmPin = ''; + $scope.action = $stateParams.action; + $scope.match = $scope.error = $scope.disableButtons = false; + $scope.currentAttempts = 0; + $scope.appName = appConfigService.name; + }); + + $scope.$on("$ionicView.enter", function(event) { + configService.whenAvailable(function(config) { + if (!config.lock) return; + $scope.bannedUntil = config.lock.bannedUntil || null; + if ($scope.bannedUntil) { + var now = Math.floor(Date.now() / 1000); + if (now < $scope.bannedUntil) { + $scope.error = $scope.disableButtons = true; + lockTimeControl($scope.bannedUntil); + } + } + }); + }); + + function getSavedMethod() { + var config = configService.getSync(); + if (config.lock) return config.lock.method; + return 'none'; + }; + + function checkAttempts() { + $scope.currentAttempts += 1; + $log.debug('Attempts to unlock:', $scope.currentAttempts); + if ($scope.currentAttempts === ATTEMPT_LIMIT) { + $scope.currentAttempts = 0; + var bannedUntil = Math.floor(Date.now() / 1000) + ATTEMPT_LOCK_OUT_TIME; + saveFailedAttempt(bannedUntil); + } + }; + + function lockTimeControl(bannedUntil) { + setExpirationTime(); + + var countDown = $interval(function() { + setExpirationTime(); + }, 1000); + + function setExpirationTime() { + var now = Math.floor(Date.now() / 1000); + if (now > bannedUntil) { + if (countDown) reset(); + } else { + $scope.disableButtons = true; + var totalSecs = bannedUntil - now; + var m = Math.floor(totalSecs / 60); + var s = totalSecs % 60; + $scope.expires = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2); + } + }; + + function reset() { + $scope.expires = $scope.error = $scope.disableButtons = null; + currentPin = $scope.confirmPin = ''; + $interval.cancel(countDown); + $timeout(function() { + $scope.$apply(); + }); + return; + }; + }; + + $scope.getFilledClass = function(limit) { + return currentPin && currentPin.length >= limit ? 'filled-' + $scope.appName : null; + }; + + $scope.delete = function() { + if ($scope.disableButtons) return; + if (currentPin.length > 0) { + currentPin = currentPin.substring(0, currentPin.length - 1); + $scope.error = false; + $scope.updatePin(); + } + }; + + $scope.isComplete = function() { + if (currentPin.length < 4) return false; + else return true; + }; + + $scope.updatePin = function(value) { + if ($scope.disableButtons) return; + $scope.error = false; + if (value && !$scope.isComplete()) { + currentPin = currentPin + value; + $timeout(function() { + $scope.$apply(); + }); + } + $scope.save(); + }; + + function isMatch(pin) { + var config = configService.getSync(); + return config.lock.value == pin; + }; + + $scope.save = function() { + if (!$scope.isComplete()) return; + var savedMethod = getSavedMethod(); + + switch ($scope.action) { + case 'setup': + applyAndCheckPin(); + break; + case 'disable': + if (isMatch(currentPin)) { + deletePin(); + } else { + showError(); + checkAttempts(); + } + break; + case 'check': + if (isMatch(currentPin)) { + console.log("##################################### CHECKING"); + applicationService.successfullUnlocked = true; + $scope.pinModal.hide(); + return; + } + showError(); + checkAttempts(); + break; + } + }; + + function showError() { + $timeout(function() { + $scope.confirmPin = currentPin = ''; + $scope.error = true; + }, 200); + + $timeout(function() { + $scope.$apply(); + }); + }; + + function applyAndCheckPin() { + if (!$scope.confirmPin) { + $timeout(function() { + $scope.confirmPin = currentPin; + currentPin = ''; + }, 200); + } else { + if ($scope.confirmPin == currentPin) + savePin($scope.confirmPin); + else { + $scope.confirmPin = currentPin = ''; + $scope.error = true; + } + } + $timeout(function() { + $scope.$apply(); + }); + }; + + function deletePin() { + var opts = { + lock: { + method: 'none', + value: null, + bannedUntil: null, + } + }; + + configService.set(opts, function(err) { + if (err) $log.debug(err); + $scope.close(); + }); + }; + + function savePin(value) { + var opts = { + lock: { + method: 'pin', + value: value, + bannedUntil: null, + } + }; + + configService.set(opts, function(err) { + if (err) $log.debug(err); + $scope.close(); + }); + }; + + function saveFailedAttempt(bannedUntil) { + var opts = { + lock: { + bannedUntil: bannedUntil, + } + }; + + configService.set(opts, function(err) { + if (err) $log.debug(err); + lockTimeControl(bannedUntil); + }); + }; + + $scope.close = function(delay) { + $timeout(function() { + var shouldReturn = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName != 'starting'; + + if (shouldReturn) + $ionicHistory.goBack() + else + $state.go('tabs.home'); + }, delay || 1); + }; +}); diff --git a/src/js/routes.js b/src/js/routes.js index 70c32b5bb..437868ccb 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1245,6 +1245,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $ionicPlatform.on('resume', function() { applicationService.successfullUnlocked = false; + applicationService.pinModal(); // checkAndApplyLock(true); }); diff --git a/src/js/services/glideraService.js b/src/js/services/glideraService.js index f60230cdf..3c8f26dab 100644 --- a/src/js/services/glideraService.js +++ b/src/js/services/glideraService.js @@ -17,7 +17,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l * Development: 'testnet' * Production: 'livenet' */ - credentials.NETWORK = 'livenet'; + credentials.NETWORK = 'testnet'; //credentials.NETWORK = 'testnet'; if (credentials.NETWORK == 'testnet') { @@ -127,7 +127,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l }); }); }); - }); + }); }; var _get = function(endpoint, token) { @@ -365,7 +365,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l getPermissions(accessToken, credentials.NETWORK, true, function(err, permissions) { if (err) return cb(err); - + storageService.getGlideraStatus(credentials.NETWORK, function(err, status) { if (lodash.isString(status)) status = JSON.parse(status); storageService.getGlideraTxs(credentials.NETWORK, function(err, txs) { @@ -386,17 +386,21 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l root.updateStatus = function(data) { storageService.getGlideraToken(credentials.NETWORK, function(err, accessToken) { if (err) return; - + getPermissions(accessToken, credentials.NETWORK, false, function(err, permissions) { if (err) return; data.permissions = permissions; data.price = {}; - root.buyPrice(accessToken, {qty: 1}, function(err, buy) { + root.buyPrice(accessToken, { + qty: 1 + }, function(err, buy) { if (err) return; data.price['buy'] = buy.price; }); - root.sellPrice(accessToken, {qty: 1}, function(err, sell) { + root.sellPrice(accessToken, { + qty: 1 + }, function(err, sell) { if (err) return; data.price['sell'] = sell.price; }); @@ -405,12 +409,12 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l if (err) return; data.status = status; storageService.setGlideraStatus(credentials.NETWORK, JSON.stringify(status), function() {}); - }); - + }); + root.getLimits(accessToken, function(err, limits) { data.limits = limits; - }); - + }); + if (permissions.transaction_history) { root.getTransactions(accessToken, function(err, txs) { if (err) return; @@ -431,8 +435,8 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l data.personalInfo = info; }); } - }); - }); + }); + }); }; var register = function() { diff --git a/www/views/modals/pin.html b/www/views/modals/pin.html new file mode 100644 index 000000000..df0e82534 --- /dev/null +++ b/www/views/modals/pin.html @@ -0,0 +1,69 @@ + +
+
+
Please enter your PIN
+
Confirm your PIN
+
+
Incorrect PIN, try again.
+ +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
1
+
+
+
2
+
+
+
3
+
+
+
+
+
4
+
+
+
5
+
+
+
6
+
+
+
+
+
7
+
+
+
8
+
+
+
9
+
+
+
+
+
+
0
+
+
+
+
+
+
+
+
From 9b21292a682d2830d8d36cf33e0be823d309aa80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 12:36:32 -0300 Subject: [PATCH 03/12] apply pin logic to modal view --- src/js/controllers/lockSetup.js | 10 +- src/js/controllers/modals/pin.js | 64 ++++---- src/js/controllers/pin.js | 224 -------------------------- src/js/routes.js | 18 +-- src/js/services/applicationService.js | 17 +- www/views/pin.html | 73 --------- 6 files changed, 45 insertions(+), 361 deletions(-) delete mode 100644 src/js/controllers/pin.js delete mode 100644 www/views/pin.html diff --git a/src/js/controllers/lockSetup.js b/src/js/controllers/lockSetup.js index 0503a7aee..9613abaac 100644 --- a/src/js/controllers/lockSetup.js +++ b/src/js/controllers/lockSetup.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('lockSetupController', function($state, $scope, $timeout, $log, configService, gettextCatalog, fingerprintService, profileService, lodash) { +angular.module('copayApp.controllers').controller('lockSetupController', function($state, $scope, $timeout, $log, configService, gettextCatalog, fingerprintService, profileService, lodash, applicationService) { function init() { $scope.options = [ @@ -120,9 +120,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio function disableMethod(method) { switch (method) { case 'pin': - $state.transitionTo('tabs.pin', { - action: 'disable' - }); + applicationService.pinModal('disable'); break; case 'fingerprint': fingerprintService.check('unlockingApp', function(err) { @@ -136,9 +134,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio function enableMethod(method) { switch (method) { case 'pin': - $state.transitionTo('tabs.pin', { - action: 'setup' - }); + applicationService.pinModal('setup'); break; case 'fingerprint': saveConfig('fingerprint'); diff --git a/src/js/controllers/modals/pin.js b/src/js/controllers/modals/pin.js index 5d3f23a27..a580d0442 100644 --- a/src/js/controllers/modals/pin.js +++ b/src/js/controllers/modals/pin.js @@ -4,27 +4,21 @@ angular.module('copayApp.controllers').controller('pinController', function($sta var ATTEMPT_LIMIT = 3; var ATTEMPT_LOCK_OUT_TIME = 5 * 60; var currentPin; - - $scope.$on("$ionicView.beforeEnter", function(event) { - currentPin = $scope.confirmPin = ''; - $scope.action = $stateParams.action; - $scope.match = $scope.error = $scope.disableButtons = false; - $scope.currentAttempts = 0; - $scope.appName = appConfigService.name; - }); - - $scope.$on("$ionicView.enter", function(event) { - configService.whenAvailable(function(config) { - if (!config.lock) return; - $scope.bannedUntil = config.lock.bannedUntil || null; - if ($scope.bannedUntil) { - var now = Math.floor(Date.now() / 1000); - if (now < $scope.bannedUntil) { - $scope.error = $scope.disableButtons = true; - lockTimeControl($scope.bannedUntil); - } + currentPin = $scope.confirmPin = ''; + console.log("############################11111"); + $scope.match = $scope.error = $scope.disableButtons = false; + $scope.currentAttempts = 0; + $scope.appName = appConfigService.name; + configService.whenAvailable(function(config) { + if (!config.lock) return; + $scope.bannedUntil = config.lock.bannedUntil || null; + if ($scope.bannedUntil) { + var now = Math.floor(Date.now() / 1000); + if (now < $scope.bannedUntil) { + $scope.error = $scope.disableButtons = true; + lockTimeControl($scope.bannedUntil); } - }); + } }); function getSavedMethod() { @@ -75,7 +69,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta }; $scope.getFilledClass = function(limit) { - return currentPin && currentPin.length >= limit ? 'filled-' + $scope.appName : null; + return currentPin.length >= limit ? 'filled-' + $scope.appName : null; }; $scope.delete = function() { @@ -110,6 +104,8 @@ angular.module('copayApp.controllers').controller('pinController', function($sta }; $scope.save = function() { + console.log("##################################### CHECKING"); + console.log($scope.action); if (!$scope.isComplete()) return; var savedMethod = getSavedMethod(); @@ -129,7 +125,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta if (isMatch(currentPin)) { console.log("##################################### CHECKING"); applicationService.successfullUnlocked = true; - $scope.pinModal.hide(); + $scope.hideModal(); return; } showError(); @@ -179,7 +175,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta configService.set(opts, function(err) { if (err) $log.debug(err); - $scope.close(); + $scope.hideModal(); }); }; @@ -194,7 +190,7 @@ angular.module('copayApp.controllers').controller('pinController', function($sta configService.set(opts, function(err) { if (err) $log.debug(err); - $scope.close(); + $scope.hideModal(); }); }; @@ -211,14 +207,14 @@ angular.module('copayApp.controllers').controller('pinController', function($sta }); }; - $scope.close = function(delay) { - $timeout(function() { - var shouldReturn = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName != 'starting'; - - if (shouldReturn) - $ionicHistory.goBack() - else - $state.go('tabs.home'); - }, delay || 1); - }; + // $scope.close = function(delay) { + // $timeout(function() { + // var shouldReturn = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName != 'starting'; + // + // if (shouldReturn) + // $ionicHistory.goBack() + // else + // $state.go('tabs.home'); + // }, delay || 1); + // }; }); diff --git a/src/js/controllers/pin.js b/src/js/controllers/pin.js deleted file mode 100644 index 27fb48def..000000000 --- a/src/js/controllers/pin.js +++ /dev/null @@ -1,224 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('pinController', function($state, $interval, $stateParams, $ionicHistory, $timeout, $scope, $log, configService, appConfigService, applicationService) { - var ATTEMPT_LIMIT = 3; - var ATTEMPT_LOCK_OUT_TIME = 5 * 60; - var currentPin; - - $scope.$on("$ionicView.beforeEnter", function(event) { - currentPin = $scope.confirmPin = ''; - $scope.action = $stateParams.action; - $scope.match = $scope.error = $scope.disableButtons = false; - $scope.currentAttempts = 0; - $scope.appName = appConfigService.name; - }); - - $scope.$on("$ionicView.enter", function(event) { - configService.whenAvailable(function(config) { - if (!config.lock) return; - $scope.bannedUntil = config.lock.bannedUntil || null; - if ($scope.bannedUntil) { - var now = Math.floor(Date.now() / 1000); - if (now < $scope.bannedUntil) { - $scope.error = $scope.disableButtons = true; - lockTimeControl($scope.bannedUntil); - } - } - }); - }); - - function getSavedMethod() { - var config = configService.getSync(); - if (config.lock) return config.lock.method; - return 'none'; - }; - - function checkAttempts() { - $scope.currentAttempts += 1; - $log.debug('Attempts to unlock:', $scope.currentAttempts); - if ($scope.currentAttempts === ATTEMPT_LIMIT) { - $scope.currentAttempts = 0; - var bannedUntil = Math.floor(Date.now() / 1000) + ATTEMPT_LOCK_OUT_TIME; - saveFailedAttempt(bannedUntil); - } - }; - - function lockTimeControl(bannedUntil) { - setExpirationTime(); - - var countDown = $interval(function() { - setExpirationTime(); - }, 1000); - - function setExpirationTime() { - var now = Math.floor(Date.now() / 1000); - if (now > bannedUntil) { - if (countDown) reset(); - } else { - $scope.disableButtons = true; - var totalSecs = bannedUntil - now; - var m = Math.floor(totalSecs / 60); - var s = totalSecs % 60; - $scope.expires = ('0' + m).slice(-2) + ":" + ('0' + s).slice(-2); - } - }; - - function reset() { - $scope.expires = $scope.error = $scope.disableButtons = null; - currentPin = $scope.confirmPin = ''; - $interval.cancel(countDown); - $timeout(function() { - $scope.$apply(); - }); - return; - }; - }; - - $scope.getFilledClass = function(limit) { - return currentPin.length >= limit ? 'filled-' + $scope.appName : null; - }; - - $scope.delete = function() { - if ($scope.disableButtons) return; - if (currentPin.length > 0) { - currentPin = currentPin.substring(0, currentPin.length - 1); - $scope.error = false; - $scope.updatePin(); - } - }; - - $scope.isComplete = function() { - if (currentPin.length < 4) return false; - else return true; - }; - - $scope.updatePin = function(value) { - if ($scope.disableButtons) return; - $scope.error = false; - if (value && !$scope.isComplete()) { - currentPin = currentPin + value; - $timeout(function() { - $scope.$apply(); - }); - } - $scope.save(); - }; - - function isMatch(pin) { - var config = configService.getSync(); - return config.lock.value == pin; - }; - - $scope.save = function() { - if (!$scope.isComplete()) return; - var savedMethod = getSavedMethod(); - - switch ($scope.action) { - case 'setup': - applyAndCheckPin(); - break; - case 'disable': - if (isMatch(currentPin)) { - deletePin(); - } else { - showError(); - checkAttempts(); - } - break; - case 'check': - if (isMatch(currentPin)) { - console.log("##################################### CHECKING"); - applicationService.successfullUnlocked = true; - $scope.close(); - return; - } - showError(); - checkAttempts(); - break; - } - }; - - function showError() { - $timeout(function() { - $scope.confirmPin = currentPin = ''; - $scope.error = true; - }, 200); - - $timeout(function() { - $scope.$apply(); - }); - }; - - function applyAndCheckPin() { - if (!$scope.confirmPin) { - $timeout(function() { - $scope.confirmPin = currentPin; - currentPin = ''; - }, 200); - } else { - if ($scope.confirmPin == currentPin) - savePin($scope.confirmPin); - else { - $scope.confirmPin = currentPin = ''; - $scope.error = true; - } - } - $timeout(function() { - $scope.$apply(); - }); - }; - - function deletePin() { - var opts = { - lock: { - method: 'none', - value: null, - bannedUntil: null, - } - }; - - configService.set(opts, function(err) { - if (err) $log.debug(err); - $scope.close(); - }); - }; - - function savePin(value) { - var opts = { - lock: { - method: 'pin', - value: value, - bannedUntil: null, - } - }; - - configService.set(opts, function(err) { - if (err) $log.debug(err); - $scope.close(); - }); - }; - - function saveFailedAttempt(bannedUntil) { - var opts = { - lock: { - bannedUntil: bannedUntil, - } - }; - - configService.set(opts, function(err) { - if (err) $log.debug(err); - lockTimeControl(bannedUntil); - }); - }; - - $scope.close = function(delay) { - $timeout(function() { - var shouldReturn = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName != 'starting'; - - if (shouldReturn) - $ionicHistory.goBack() - else - $state.go('tabs.home'); - }, delay || 1); - }; -}); diff --git a/src/js/routes.js b/src/js/routes.js index 437868ccb..4b1cdf416 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -119,18 +119,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) - /* - * - * Pin - * - */ - - .state('pin', { - url: '/pin/:action', - controller: 'pinController', - templateUrl: 'views/pin.html', - }) - /* * * Locked @@ -1245,7 +1233,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $ionicPlatform.on('resume', function() { applicationService.successfullUnlocked = false; - applicationService.pinModal(); + applicationService.pinModal('check'); // checkAndApplyLock(true); }); @@ -1319,13 +1307,11 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $log.debug(' fromParams:' + JSON.stringify(fromParams || {})); configService.whenAvailable(function(config) { var lockMethod = config.lock && config.lock.method; - console.log(lockMethod); - console.log("########################"); if (!lockMethod || lockMethod == 'none') return; if (!applicationService.successfullUnlocked && !applicationService.pinIsOpen) { console.log("################################# OPEN PIN MODAL"); - applicationService.pinModal(); + applicationService.pinModal('check'); } }); }); diff --git a/src/js/services/applicationService.js b/src/js/services/applicationService.js index bcefb8f55..5c7bee379 100644 --- a/src/js/services/applicationService.js +++ b/src/js/services/applicationService.js @@ -36,25 +36,28 @@ angular.module('copayApp.services') } }; - root.pinModal = function() { + root.pinModal = function(action) { root.pinIsOpen = true; root.successfullUnlocked = false; var scope = $rootScope.$new(true); - $ionicModal.fromTemplateUrl('views/modals/pintestview.html', { + console.log(action); + console.log("###########################111"); + scope.action = action; + $ionicModal.fromTemplateUrl('views/modals/pin.html', { scope: scope, animation: 'slide-in-up', backdropClickToClose: false, hardwareBackButtonClose: false }).then(function(modal) { - scope.pintestview = modal; - scope.pintestview.show(); + scope.pinModal = modal; + scope.openModal(); }); scope.openModal = function() { - scope.modal.show(); + scope.pinModal.show(); }; - scope.closeModal = function() { - scope.modal.hide(); + scope.hideModal = function() { + scope.pinModal.hide(); }; // Cleanup the modal when we're done with it! scope.$on('$destroy', function() { diff --git a/www/views/pin.html b/www/views/pin.html deleted file mode 100644 index ab1b67dec..000000000 --- a/www/views/pin.html +++ /dev/null @@ -1,73 +0,0 @@ - - - - - -
-
-
Please enter your PIN
-
Confirm your PIN
-
-
Incorrect PIN, try again.
- -
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
1
-
-
-
2
-
-
-
3
-
-
-
-
-
4
-
-
-
5
-
-
-
6
-
-
-
-
-
7
-
-
-
8
-
-
-
9
-
-
-
-
-
-
0
-
-
-
-
-
-
-
-
From 8dfc2de01c81290e8b864bbceba8881a45a34cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 16:42:41 -0300 Subject: [PATCH 04/12] adding security popups for resume --- src/js/controllers/lockSetup.js | 11 ++++- src/js/controllers/modals/pin.js | 17 +------- src/js/routes.js | 61 +-------------------------- src/js/services/applicationService.js | 48 ++++++++++++--------- src/js/services/openURL.js | 5 --- src/sass/views/pin.scss | 8 +--- 6 files changed, 43 insertions(+), 107 deletions(-) diff --git a/src/js/controllers/lockSetup.js b/src/js/controllers/lockSetup.js index 9613abaac..fc4470bcc 100644 --- a/src/js/controllers/lockSetup.js +++ b/src/js/controllers/lockSetup.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('lockSetupController', function($state, $scope, $timeout, $log, configService, gettextCatalog, fingerprintService, profileService, lodash, applicationService) { +angular.module('copayApp.controllers').controller('lockSetupController', function($state, $rootScope, $scope, $timeout, $log, configService, gettextCatalog, fingerprintService, profileService, lodash, applicationService) { function init() { $scope.options = [ @@ -53,7 +53,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio o.disabled = false; }); - // HACK: Disable untill we allow to change between methods directly + // HACK: Disable until we allow to change between methods directly if (fingerprintService.isAvailable()) { switch (savedMethod) { case 'pin': @@ -121,6 +121,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio switch (method) { case 'pin': applicationService.pinModal('disable'); + initMethodSelector(); break; case 'fingerprint': fingerprintService.check('unlockingApp', function(err) { @@ -135,6 +136,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio switch (method) { case 'pin': applicationService.pinModal('setup'); + initMethodSelector(); break; case 'fingerprint': saveConfig('fingerprint'); @@ -155,4 +157,9 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio initMethodSelector(); }); }; + + $rootScope.$on('pinModalClosed', function() { + initMethodSelector(); + }); + }); diff --git a/src/js/controllers/modals/pin.js b/src/js/controllers/modals/pin.js index a580d0442..1e2acfb2b 100644 --- a/src/js/controllers/modals/pin.js +++ b/src/js/controllers/modals/pin.js @@ -5,10 +5,11 @@ angular.module('copayApp.controllers').controller('pinController', function($sta var ATTEMPT_LOCK_OUT_TIME = 5 * 60; var currentPin; currentPin = $scope.confirmPin = ''; - console.log("############################11111"); + $scope.match = $scope.error = $scope.disableButtons = false; $scope.currentAttempts = 0; $scope.appName = appConfigService.name; + configService.whenAvailable(function(config) { if (!config.lock) return; $scope.bannedUntil = config.lock.bannedUntil || null; @@ -104,8 +105,6 @@ angular.module('copayApp.controllers').controller('pinController', function($sta }; $scope.save = function() { - console.log("##################################### CHECKING"); - console.log($scope.action); if (!$scope.isComplete()) return; var savedMethod = getSavedMethod(); @@ -123,7 +122,6 @@ angular.module('copayApp.controllers').controller('pinController', function($sta break; case 'check': if (isMatch(currentPin)) { - console.log("##################################### CHECKING"); applicationService.successfullUnlocked = true; $scope.hideModal(); return; @@ -206,15 +204,4 @@ angular.module('copayApp.controllers').controller('pinController', function($sta lockTimeControl(bannedUntil); }); }; - - // $scope.close = function(delay) { - // $timeout(function() { - // var shouldReturn = $ionicHistory.viewHistory().backView && $ionicHistory.viewHistory().backView.stateName != 'starting'; - // - // if (shouldReturn) - // $ionicHistory.goBack() - // else - // $state.go('tabs.home'); - // }, delay || 1); - // }; }); diff --git a/src/js/routes.js b/src/js/routes.js index 4b1cdf416..5394d9ff3 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1183,58 +1183,8 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr // Nothing to do }); - - // function checkAndApplyLock(onResume) { - // var defaultView = 'tabs.home'; - // - // if (!platformInfo.isCordova && !platformInfo.isDevel) { - // goTo(defaultView); - // } - // - // if (onResume) { - // var now = Math.floor(Date.now() / 1000); - // if (now < openURLService.unlockUntil) { - // openURLService.unlockUntil = null; - // $log.debug('Skip startup locking'); - // return; - // } - // } - // - // function goTo(nextView) { - // nextView = nextView || defaultView; - // $state.transitionTo(nextView, { - // action: 'check' - // }).then(function() { - // if (nextView == 'lockedView') - // $ionicHistory.clearHistory(); - // }); - // }; - // - // startupService.ready(); - // - // configService.whenAvailable(function(config) { - // var lockMethod = config.lock && config.lock.method; - // $log.debug('App Lock:' + (lockMethod || 'no')); - // - // if (lockMethod == 'fingerprint' && fingerprintService.isAvailable()) { - // fingerprintService.check('unlockingApp', function(err) { - // if (err) - // goTo('lockedView'); - // else if ($ionicHistory.currentStateName() == 'lockedView' || !onResume) - // goTo('tabs.home'); - // }); - // } else if (lockMethod == 'pin') { - // goTo('pin'); - // } else { - // goTo(defaultView); - // } - // }); - // } - $ionicPlatform.on('resume', function() { - applicationService.successfullUnlocked = false; - applicationService.pinModal('check'); - // checkAndApplyLock(true); + applicationService.appLockModal('check'); }); $ionicPlatform.on('menubutton', function() { @@ -1305,14 +1255,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $log.debug('Route change from:', fromState.name || '-', ' to:', toState.name); $log.debug(' toParams:' + JSON.stringify(toParams || {})); $log.debug(' fromParams:' + JSON.stringify(fromParams || {})); - configService.whenAvailable(function(config) { - var lockMethod = config.lock && config.lock.method; - if (!lockMethod || lockMethod == 'none') return; - if (!applicationService.successfullUnlocked && !applicationService.pinIsOpen) { - console.log("################################# OPEN PIN MODAL"); - applicationService.pinModal('check'); - } - }); + if (!applicationService.successfullUnlocked) applicationService.appLockModal('check'); }); }); diff --git a/src/js/services/applicationService.js b/src/js/services/applicationService.js index 5c7bee379..c1c6584a3 100644 --- a/src/js/services/applicationService.js +++ b/src/js/services/applicationService.js @@ -1,10 +1,10 @@ 'use strict'; angular.module('copayApp.services') - .factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, $state) { + .factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, fingerprintService, openURLService, configService, $state) { var root = {}; root.successfullUnlocked = false; - root.pinIsOpen = false; + root.pinModalIsOpen = false; var isChromeApp = platformInfo.isChromeApp; var isNW = platformInfo.isNW; @@ -36,17 +36,24 @@ angular.module('copayApp.services') } }; - root.pinModal = function(action) { + root.fingerprintModal = function() { + fingerprintService.check('unlockingApp', function(err) { + if (err) { + root.fingerprintModal(); + return; + } + root.successfullUnlocked = true; + }); + }; + + root.pinModal = function(action) { + if (root.pinModalIsOpen) return; - root.pinIsOpen = true; - root.successfullUnlocked = false; var scope = $rootScope.$new(true); - console.log(action); - console.log("###########################111"); scope.action = action; $ionicModal.fromTemplateUrl('views/modals/pin.html', { scope: scope, - animation: 'slide-in-up', + animation: 'none', backdropClickToClose: false, hardwareBackButtonClose: false }).then(function(modal) { @@ -54,22 +61,25 @@ angular.module('copayApp.services') scope.openModal(); }); scope.openModal = function() { + root.pinModalIsOpen = true; scope.pinModal.show(); }; scope.hideModal = function() { + scope.$emit('pinModalClosed'); + root.pinModalIsOpen = false; scope.pinModal.hide(); }; - // Cleanup the modal when we're done with it! - scope.$on('$destroy', function() { - scope.modal.remove(); - }); - // Execute action on hide modal - scope.$on('modal.hidden', function() { - // Execute action - }); - // Execute action on remove modal - scope.$on('modal.removed', function() { - // Execute action + }; + + root.appLockModal = function(action) { + + configService.whenAvailable(function(config) { + var lockMethod = config.lock && config.lock.method; + if (!lockMethod || lockMethod == 'none') return; + + if (lockMethod == 'fingerprint' && fingerprintService.isAvailable()) root.fingerprintModal(); + if (lockMethod == 'pin') root.pinModal(action); + }); } return root; diff --git a/src/js/services/openURL.js b/src/js/services/openURL.js index 8e6a768cf..45e7748c7 100644 --- a/src/js/services/openURL.js +++ b/src/js/services/openURL.js @@ -1,14 +1,9 @@ 'use strict'; angular.module('copayApp.services').factory('openURLService', function($rootScope, $ionicHistory, $document, $log, $state, platformInfo, lodash, profileService, incomingData, appConfigService) { - var DELAY_UNLOCK_TIME = 2 * 60; var root = {}; - root.unlockUntil = null; - var handleOpenURL = function(args) { - root.unlockUntil = Math.floor(Date.now() / 1000) + DELAY_UNLOCK_TIME; - $log.debug('Set unlock time until: ' + root.unlockUntil); $log.info('Handling Open URL: ' + JSON.stringify(args)); // Stop it from caching the first view as one to return when the app opens diff --git a/src/sass/views/pin.scss b/src/sass/views/pin.scss index 3d695f185..8a3547de8 100644 --- a/src/sass/views/pin.scss +++ b/src/sass/views/pin.scss @@ -1,14 +1,8 @@ #pin { background-color: #FAFAFA; - .bar.bar-clear { - background-color: transparent; - border: none; - .back-button .icon:before { - color: #2d3f50; - } - } .content { text-align: center; + position: fixed; width: 100%; height: 100%; .app-icon { From ff5b662f3903bc03d975c5c09d234c5960671510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 17:29:33 -0300 Subject: [PATCH 05/12] fixes and remove unused views --- src/js/controllers/lockSetup.js | 4 +--- src/js/controllers/modals/pin.js | 1 + src/js/controllers/modals/pintest.js | 12 ------------ src/js/routes.js | 7 +++++-- src/js/services/glideraService.js | 2 +- www/views/modals/pin.html | 5 +++++ www/views/modals/pintestview.html | 10 ---------- www/views/tab-settings.html | 2 +- 8 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 src/js/controllers/modals/pintest.js delete mode 100644 www/views/modals/pintestview.html diff --git a/src/js/controllers/lockSetup.js b/src/js/controllers/lockSetup.js index fc4470bcc..cb6ff03cd 100644 --- a/src/js/controllers/lockSetup.js +++ b/src/js/controllers/lockSetup.js @@ -121,7 +121,6 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio switch (method) { case 'pin': applicationService.pinModal('disable'); - initMethodSelector(); break; case 'fingerprint': fingerprintService.check('unlockingApp', function(err) { @@ -136,7 +135,6 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio switch (method) { case 'pin': applicationService.pinModal('setup'); - initMethodSelector(); break; case 'fingerprint': saveConfig('fingerprint'); @@ -159,7 +157,7 @@ angular.module('copayApp.controllers').controller('lockSetupController', functio }; $rootScope.$on('pinModalClosed', function() { - initMethodSelector(); + init() }); }); diff --git a/src/js/controllers/modals/pin.js b/src/js/controllers/modals/pin.js index 1e2acfb2b..ec1623234 100644 --- a/src/js/controllers/modals/pin.js +++ b/src/js/controllers/modals/pin.js @@ -204,4 +204,5 @@ angular.module('copayApp.controllers').controller('pinController', function($sta lockTimeControl(bannedUntil); }); }; + }); diff --git a/src/js/controllers/modals/pintest.js b/src/js/controllers/modals/pintest.js deleted file mode 100644 index 2ab63e625..000000000 --- a/src/js/controllers/modals/pintest.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -angular.module('copayApp.controllers').controller('pinTestController', function($scope, applicationService) { - - $scope.goodPin = function() { - applicationService.successfullUnlocked = true; - $scope.pintestview.hide(); - }; - - $scope.badPin = function() {}; - -}); diff --git a/src/js/routes.js b/src/js/routes.js index 5394d9ff3..f0781c0a9 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1227,13 +1227,16 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr disableAnimate: true, historyRoot: true }); - $state.transitionTo('tabs.home'); + $state.transitionTo('tabs.home').then(function() { + // Clear history + $ionicHistory.clearHistory(); + }); }); }; // After everything have been loaded, initialize handler URL $timeout(function() { openURLService.init(); - }); + }, 1000); }); }); diff --git a/src/js/services/glideraService.js b/src/js/services/glideraService.js index 3c8f26dab..ad62d3ef4 100644 --- a/src/js/services/glideraService.js +++ b/src/js/services/glideraService.js @@ -17,7 +17,7 @@ angular.module('copayApp.services').factory('glideraService', function($http, $l * Development: 'testnet' * Production: 'livenet' */ - credentials.NETWORK = 'testnet'; + credentials.NETWORK = 'livenet'; //credentials.NETWORK = 'testnet'; if (credentials.NETWORK == 'testnet') { diff --git a/www/views/modals/pin.html b/www/views/modals/pin.html index df0e82534..7d852b1b9 100644 --- a/www/views/modals/pin.html +++ b/www/views/modals/pin.html @@ -1,4 +1,9 @@ + + +
Please enter your PIN
diff --git a/www/views/modals/pintestview.html b/www/views/modals/pintestview.html deleted file mode 100644 index 0f1f6afe4..000000000 --- a/www/views/modals/pintestview.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/www/views/tab-settings.html b/www/views/tab-settings.html index cfc054614..a26061508 100644 --- a/www/views/tab-settings.html +++ b/www/views/tab-settings.html @@ -89,7 +89,7 @@ - + {{'Lock App' | translate}} From 709b0369f1581e19f764e8b19167884d24b56e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 18:09:02 -0300 Subject: [PATCH 06/12] code refactor --- src/js/controllers/modals/pin.js | 1 - src/js/routes.js | 3 +-- src/js/services/applicationService.js | 7 ------- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/js/controllers/modals/pin.js b/src/js/controllers/modals/pin.js index ec1623234..bb7fa41a9 100644 --- a/src/js/controllers/modals/pin.js +++ b/src/js/controllers/modals/pin.js @@ -122,7 +122,6 @@ angular.module('copayApp.controllers').controller('pinController', function($sta break; case 'check': if (isMatch(currentPin)) { - applicationService.successfullUnlocked = true; $scope.hideModal(); return; } diff --git a/src/js/routes.js b/src/js/routes.js index f0781c0a9..8308559a4 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -1231,6 +1231,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr // Clear history $ionicHistory.clearHistory(); }); + applicationService.appLockModal('check'); }); }; // After everything have been loaded, initialize handler URL @@ -1258,7 +1259,5 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr $log.debug('Route change from:', fromState.name || '-', ' to:', toState.name); $log.debug(' toParams:' + JSON.stringify(toParams || {})); $log.debug(' fromParams:' + JSON.stringify(fromParams || {})); - - if (!applicationService.successfullUnlocked) applicationService.appLockModal('check'); }); }); diff --git a/src/js/services/applicationService.js b/src/js/services/applicationService.js index c1c6584a3..7a95d636e 100644 --- a/src/js/services/applicationService.js +++ b/src/js/services/applicationService.js @@ -3,9 +3,6 @@ angular.module('copayApp.services') .factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, fingerprintService, openURLService, configService, $state) { var root = {}; - root.successfullUnlocked = false; - root.pinModalIsOpen = false; - var isChromeApp = platformInfo.isChromeApp; var isNW = platformInfo.isNW; @@ -42,12 +39,10 @@ angular.module('copayApp.services') root.fingerprintModal(); return; } - root.successfullUnlocked = true; }); }; root.pinModal = function(action) { - if (root.pinModalIsOpen) return; var scope = $rootScope.$new(true); scope.action = action; @@ -61,12 +56,10 @@ angular.module('copayApp.services') scope.openModal(); }); scope.openModal = function() { - root.pinModalIsOpen = true; scope.pinModal.show(); }; scope.hideModal = function() { scope.$emit('pinModalClosed'); - root.pinModalIsOpen = false; scope.pinModal.hide(); }; }; From d67391dedf0040bdfa5a9db815bcbab774e03250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 18:33:31 -0300 Subject: [PATCH 07/12] adding modal to fingerprint check --- src/js/services/applicationService.js | 38 ++++++++++++++++++++++---- www/views/modals/fingerprintCheck.html | 12 ++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 www/views/modals/fingerprintCheck.html diff --git a/src/js/services/applicationService.js b/src/js/services/applicationService.js index 7a95d636e..c1d80b8a9 100644 --- a/src/js/services/applicationService.js +++ b/src/js/services/applicationService.js @@ -3,6 +3,8 @@ angular.module('copayApp.services') .factory('applicationService', function($rootScope, $timeout, $ionicHistory, $ionicModal, platformInfo, fingerprintService, openURLService, configService, $state) { var root = {}; + root.isPinModalOpen = false; + var isChromeApp = platformInfo.isChromeApp; var isNW = platformInfo.isNW; @@ -34,16 +36,40 @@ angular.module('copayApp.services') }; root.fingerprintModal = function() { - fingerprintService.check('unlockingApp', function(err) { - if (err) { - root.fingerprintModal(); - return; - } + + var scope = $rootScope.$new(true); + $ionicModal.fromTemplateUrl('views/modals/fingerprintCheck.html', { + scope: scope, + animation: 'none', + backdropClickToClose: false, + hardwareBackButtonClose: false + }).then(function(modal) { + scope.fingerprintCheckModal = modal; + scope.openModal(); }); + scope.openModal = function() { + scope.fingerprintCheckModal.show(); + checkFingerprint(); + }; + scope.hideModal = function() { + scope.fingerprintCheckModal.hide(); + }; + + function checkFingerprint() { + fingerprintService.check('unlockingApp', function(err) { + if (err) { + checkFingerprint(); + return; + } + scope.hideModal(); + }); + } }; root.pinModal = function(action) { + if (root.isPinModalOpen) return; + var scope = $rootScope.$new(true); scope.action = action; $ionicModal.fromTemplateUrl('views/modals/pin.html', { @@ -53,6 +79,7 @@ angular.module('copayApp.services') hardwareBackButtonClose: false }).then(function(modal) { scope.pinModal = modal; + root.isPinModalOpen = true; scope.openModal(); }); scope.openModal = function() { @@ -60,6 +87,7 @@ angular.module('copayApp.services') }; scope.hideModal = function() { scope.$emit('pinModalClosed'); + root.isPinModalOpen = false; scope.pinModal.hide(); }; }; diff --git a/www/views/modals/fingerprintCheck.html b/www/views/modals/fingerprintCheck.html new file mode 100644 index 000000000..67996a5f3 --- /dev/null +++ b/www/views/modals/fingerprintCheck.html @@ -0,0 +1,12 @@ + +
+
+
Please enter your FINGERPRINT
+
+
+ +
+
+
+
+
From c924e1116bcfd5990bfe724954aa63884591358b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 18:39:09 -0300 Subject: [PATCH 08/12] check if fingerprint modal is open --- src/js/services/applicationService.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/js/services/applicationService.js b/src/js/services/applicationService.js index c1d80b8a9..fe364a514 100644 --- a/src/js/services/applicationService.js +++ b/src/js/services/applicationService.js @@ -45,6 +45,7 @@ angular.module('copayApp.services') hardwareBackButtonClose: false }).then(function(modal) { scope.fingerprintCheckModal = modal; + root.isModalOpen = true; scope.openModal(); }); scope.openModal = function() { @@ -52,6 +53,7 @@ angular.module('copayApp.services') checkFingerprint(); }; scope.hideModal = function() { + root.isModalOpen = false; scope.fingerprintCheckModal.hide(); }; @@ -68,8 +70,6 @@ angular.module('copayApp.services') root.pinModal = function(action) { - if (root.isPinModalOpen) return; - var scope = $rootScope.$new(true); scope.action = action; $ionicModal.fromTemplateUrl('views/modals/pin.html', { @@ -79,7 +79,7 @@ angular.module('copayApp.services') hardwareBackButtonClose: false }).then(function(modal) { scope.pinModal = modal; - root.isPinModalOpen = true; + root.isModalOpen = true; scope.openModal(); }); scope.openModal = function() { @@ -87,13 +87,15 @@ angular.module('copayApp.services') }; scope.hideModal = function() { scope.$emit('pinModalClosed'); - root.isPinModalOpen = false; + root.isModalOpen = false; scope.pinModal.hide(); }; }; root.appLockModal = function(action) { + if (root.isModalOpen) return; + configService.whenAvailable(function(config) { var lockMethod = config.lock && config.lock.method; if (!lockMethod || lockMethod == 'none') return; From 155bf9c0d205df476ca036ce530abad2a27c71b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 18:42:50 -0300 Subject: [PATCH 09/12] remove label to fingerprint modal --- www/views/modals/fingerprintCheck.html | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/www/views/modals/fingerprintCheck.html b/www/views/modals/fingerprintCheck.html index 67996a5f3..b5e26937a 100644 --- a/www/views/modals/fingerprintCheck.html +++ b/www/views/modals/fingerprintCheck.html @@ -1,8 +1,6 @@
-
-
Please enter your FINGERPRINT
-
+
From 020dbcd9095bf08da455fdd4399c0b09e6882d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 18:51:12 -0300 Subject: [PATCH 10/12] remove unused view --- src/js/controllers/lockedView.js | 17 ------------- src/sass/views/lockedView.scss | 42 -------------------------------- www/views/lockedView.html | 21 ---------------- 3 files changed, 80 deletions(-) delete mode 100644 src/js/controllers/lockedView.js delete mode 100644 src/sass/views/lockedView.scss delete mode 100644 www/views/lockedView.html diff --git a/src/js/controllers/lockedView.js b/src/js/controllers/lockedView.js deleted file mode 100644 index 0842c5cf6..000000000 --- a/src/js/controllers/lockedView.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -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; - }); - - $scope.requestFingerprint = function() { - fingerprintService.check('unlockingApp', function(err) { - if (err) return; - $state.transitionTo('tabs.home').then(function() { - $ionicHistory.clearHistory(); - }); - }); - }; -}); diff --git a/src/sass/views/lockedView.scss b/src/sass/views/lockedView.scss deleted file mode 100644 index 23fed7a83..000000000 --- a/src/sass/views/lockedView.scss +++ /dev/null @@ -1,42 +0,0 @@ -#locked-view { - @mixin img-frame { - height: 60px; - width: 60px; - box-shadow: none; - margin: auto; - } - .img-container-copay { - padding: 20%; - @media(min-width: 480px) { - max-height: 150px; - } - .big-icon-svg { - > .bg { - @include img-frame; - background-image: url("../img/icon-fingerprint-copay.svg"); - } - } - } - .img-container-bitpay { - padding: 20%; - @media(min-width: 480px) { - max-height: 150px; - } - .big-icon-svg { - > .bg { - @include img-frame; - background-image: url("../img/icon-fingerprint-bitpay.svg"); - } - } - } - .comments { - text-align: center; - .header { - font-size: 20px; - } - .text-content { - width: 90%; - margin: 5% auto; - } - } -} diff --git a/www/views/lockedView.html b/www/views/lockedView.html deleted file mode 100644 index 0c86ea7f6..000000000 --- a/www/views/lockedView.html +++ /dev/null @@ -1,21 +0,0 @@ - - - {{title}} - - - -
-
-
-
-
-
-
-
One-touch Sign In
-
Please place your fingertip on the scanner to verify your identity
-
- -
-
From 83b8ee9a3cf7fb5dcfd5635dfe8b22beb0c72a06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 18:57:37 -0300 Subject: [PATCH 11/12] move pin scss to include folder --- src/sass/views/{ => includes}/pin.scss | 0 src/sass/views/views.scss | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) rename src/sass/views/{ => includes}/pin.scss (100%) diff --git a/src/sass/views/pin.scss b/src/sass/views/includes/pin.scss similarity index 100% rename from src/sass/views/pin.scss rename to src/sass/views/includes/pin.scss diff --git a/src/sass/views/views.scss b/src/sass/views/views.scss index bd8520c01..7a8058339 100644 --- a/src/sass/views/views.scss +++ b/src/sass/views/views.scss @@ -46,5 +46,4 @@ @import "includes/accountSelector"; @import "integrations/integrations"; @import "custom-amount"; -@import "pin"; -@import "lockedView"; +@import "includes/pin"; From 438c29a92443f2b77af84f6849ea08c0384bbb09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 9 May 2017 18:58:44 -0300 Subject: [PATCH 12/12] remove lockedView route --- src/js/routes.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/js/routes.js b/src/js/routes.js index 8308559a4..309ec01e3 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -119,18 +119,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } }) - /* - * - * Locked - * - */ - - .state('lockedView', { - url: '/lockedView/', - controller: 'lockedViewController', - templateUrl: 'views/lockedView.html', - }) - /* * * URI