From f23df02d0bae10407ad45d13b275f172435cc45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Mon, 23 Nov 2015 12:17:04 -0300 Subject: [PATCH] fix disclaimer --- src/js/controllers/disclaimer.js | 28 ++++++----- src/js/routes.js | 80 +++++++++++++++---------------- src/js/services/profileService.js | 45 +++++++++-------- src/js/services/storageService.js | 10 +++- 4 files changed, 89 insertions(+), 74 deletions(-) diff --git a/src/js/controllers/disclaimer.js b/src/js/controllers/disclaimer.js index 4d55984cc..725247970 100644 --- a/src/js/controllers/disclaimer.js +++ b/src/js/controllers/disclaimer.js @@ -6,7 +6,9 @@ angular.module('copayApp.controllers').controller('disclaimerController', $scope.lang = uxLanguage.currentLanguage; $scope.goHome = function() { - go.walletHome(); + storageService.setCopayDisclaimerFlag(function(err) { + go.walletHome(); + }); }; var create = function() { @@ -15,16 +17,20 @@ angular.module('copayApp.controllers').controller('disclaimerController', if (err) { - if (err == 'EEXISTS') - return go.walletHome(); - - $log.warn(err); - $scope.error = err; - $scope.$apply(); - $timeout(function() { - $log.warn('Retrying to create profile......'); - create(); - }, 3000); + if (err == 'EEXISTS') { + storageService.getCopayDisclaimerFlag(function(val) { + if (val) return go.walletHome(); + $scope.creatingProfile = false; + }); + } else { + $log.warn(err); + $scope.error = err; + $scope.$apply(); + $timeout(function() { + $log.warn('Retrying to create profile......'); + create(); + }, 3000); + } } else { $scope.error = ""; $scope.creatingProfile = false; diff --git a/src/js/routes.js b/src/js/routes.js index 90d408c3d..6e8c7d527 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -263,43 +263,39 @@ angular }, } }) - - .state('preferencesGlidera', { - url: '/preferencesGlidera', - walletShouldBeComplete: true, - needProfile: true, - views: { - 'main': { - templateUrl: 'views/preferencesGlidera.html' - }, - } - }) - - .state('preferencesAdvanced', { - url: '/preferencesAdvanced', - templateUrl: 'views/preferencesAdvanced.html', - walletShouldBeComplete: true, - needProfile: true, - views: { - 'main': { - templateUrl: 'views/preferencesAdvanced.html' - }, - } - }) - - .state('preferencesColor', { - url: '/preferencesColor', - templateUrl: 'views/preferencesColor.html', - walletShouldBeComplete: true, - needProfile: true, - views: { - 'main': { - templateUrl: 'views/preferencesColor.html' - }, - } - }) - - .state('preferencesAltCurrency', { + .state('preferencesGlidera', { + url: '/preferencesGlidera', + walletShouldBeComplete: true, + needProfile: true, + views: { + 'main': { + templateUrl: 'views/preferencesGlidera.html' + }, + } + }) + .state('preferencesAdvanced', { + url: '/preferencesAdvanced', + templateUrl: 'views/preferencesAdvanced.html', + walletShouldBeComplete: true, + needProfile: true, + views: { + 'main': { + templateUrl: 'views/preferencesAdvanced.html' + }, + } + }) + .state('preferencesColor', { + url: '/preferencesColor', + templateUrl: 'views/preferencesColor.html', + walletShouldBeComplete: true, + needProfile: true, + views: { + 'main': { + templateUrl: 'views/preferencesColor.html' + }, + } + }) + .state('preferencesAltCurrency', { url: '/preferencesAltCurrency', templateUrl: 'views/preferencesAltCurrency.html', walletShouldBeComplete: true, @@ -378,8 +374,7 @@ angular }, } }) - - .state('about', { + .state('about', { url: '/about', templateUrl: 'views/preferencesAbout.html', walletShouldBeComplete: true, @@ -449,8 +444,7 @@ angular templateUrl: 'views/warning.html', needProfile: false }) - - .state('add', { + .state('add', { url: '/add', needProfile: true, views: { @@ -516,13 +510,15 @@ angular // Give us time to open / create the profile event.preventDefault(); - // Try to open local profile profileService.loadAndBindProfile(function(err) { if (err) { if (err.message && err.message.match('NOPROFILE')) { $log.debug('No profile... redirecting'); $state.transitionTo('disclaimer'); + } else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) { + $log.debug('Display disclaimer... redirecting'); + $state.transitionTo('disclaimer'); } else { throw new Error(err); // TODO } diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 12cd57065..a1b54c4f5 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -134,26 +134,31 @@ angular.module('copayApp.services') }; root.loadAndBindProfile = function(cb) { - storageService.getProfile(function(err, profile) { - if (err) { - $rootScope.$emit('Local/DeviceError', err); - return cb(err); - } - if (!profile) { - // Migration?? - storageService.tryToMigrate(function(err, migratedProfile) { - if (err) return cb(err); - if (!migratedProfile) - return cb(new Error('NOPROFILE: No profile')); - - profile = migratedProfile; - return root.bindProfile(profile, cb); - }) + storageService.getCopayDisclaimerFlag(function(err, val) { + if (!val) { + return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); } else { - $log.debug('Profile read'); - return root.bindProfile(profile, cb); - } + storageService.getProfile(function(err, profile) { + if (err) { + $rootScope.$emit('Local/DeviceError', err); + return cb(err); + } + if (!profile) { + // Migration?? + storageService.tryToMigrate(function(err, migratedProfile) { + if (err) return cb(err); + if (!migratedProfile) + return cb(new Error('NOPROFILE: No profile')); + profile = migratedProfile; + return root.bindProfile(profile, cb); + }) + } else { + $log.debug('Profile read'); + return root.bindProfile(profile, cb); + } + }); + } }); }; @@ -270,8 +275,8 @@ angular.module('copayApp.services') // check if exist if (lodash.find(root.profile.credentials, { - 'walletId': walletData.walletId - })) { + 'walletId': walletData.walletId + })) { return cb(gettext('Cannot join the same wallet more that once')); } } catch (ex) { diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index 9178cb69c..e688b578e 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -65,7 +65,7 @@ angular.module('copayApp.services') return storage.set('profile', text, function(err) { return cb(err, text); }); - } catch(e) { + } catch (e) { $log.warn('Decrypt error: ', e); return cb('Could not decrypt storage: device ID mismatch'); }; @@ -199,6 +199,14 @@ angular.module('copayApp.services') storage.remove('config', cb); }; + root.setCopayDisclaimerFlag = function(cb) { + storage.set('agreeDisclaimer', true, cb); + }; + + root.getCopayDisclaimerFlag = function(cb) { + storage.get('agreeDisclaimer', cb); + }; + root.setRemotePrefsStoredFlag = function(cb) { storage.set('remotePrefStored', true, cb); };