From bdfa89115d568d77a10284ec1600b039434f6052 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Sat, 5 Dec 2015 20:50:31 -0300 Subject: [PATCH] Fix disclaimer --- public/index.html | 2 +- public/views/disclaimer.html | 2 +- src/js/controllers/disclaimer.js | 10 ----- src/js/controllers/index.js | 71 ++++++++++++++++++++----------- src/js/services/profileService.js | 25 +++++------ 5 files changed, 60 insertions(+), 50 deletions(-) diff --git a/public/index.html b/public/index.html index a9c4def93..56a114dec 100644 --- a/public/index.html +++ b/public/index.html @@ -18,7 +18,7 @@ ng-controller="indexController as index" ng-swipe-disable-mouse ng-swipe-left="index.closeMenu()" - ng-swipe-right="index.disclaimerAccepted ? index.openMenu() : null"> + ng-swipe-right="index.openMenu()">
diff --git a/public/views/disclaimer.html b/public/views/disclaimer.html index 19b9e40f9..1dd70e071 100644 --- a/public/views/disclaimer.html +++ b/public/views/disclaimer.html @@ -46,7 +46,7 @@
-
diff --git a/src/js/controllers/disclaimer.js b/src/js/controllers/disclaimer.js index cce17f5f9..d783e55f9 100644 --- a/src/js/controllers/disclaimer.js +++ b/src/js/controllers/disclaimer.js @@ -4,16 +4,6 @@ angular.module('copayApp.controllers').controller('disclaimerController', function($scope, $timeout, $log, profileService, isCordova, storageService, applicationService, gettextCatalog, uxLanguage, go) { self = this; - $scope.goHome = function() { - $scope.error = ""; - profileService.storeDisclaimer(function(err) { - if (err) { - $scope.error = err; - $scope.$apply(); - } else go.walletHome(); - }); - }; - var create = function() { $scope.creatingProfile = true; profileService.create({}, function(err) { diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 780dcd5d6..242f7be82 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -125,22 +125,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.initGlidera(); - self.setCustomBWSFlag(); - profileService.checkDisclaimer(function(v) { - if (v) self.disclaimerAccepted = true; - if (fc.isPrivKeyExternal()) { - self.needsBackup = false; + self.setCustomBWSFlag(); + if (fc.isPrivKeyExternal()) { + self.needsBackup = false; + self.openWallet(); + } else { + storageService.getBackupFlag(self.walletId, function(err, val) { + if (!fc.credentials.mnemonic) + self.needsBackup = false; + else + self.needsBackup = self.network == 'testnet' ? false : !val; self.openWallet(); - } else { - storageService.getBackupFlag(self.walletId, function(err, val) { - if (!fc.credentials.mnemonic) - self.needsBackup = false; - else - self.needsBackup = self.network == 'testnet' ? false : !val; - self.openWallet(); - }); - } - }); + }); + } }); }; @@ -151,6 +148,28 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.usingCustomBWS = config.bwsFor && config.bwsFor[self.walletId] && (config.bwsFor[self.walletId] != defaults.bws.url); }; + self.agreeDisclaimer = function() { + var profile = profileService.profile; + if (profile) profile.agreeDisclaimer = true; + self.disclaimerAccepted = true; + profileService.storeDisclaimer(function(err) { + if (err) $log.error(err); + go.walletHome(); + }); + }; + + self.checkDisclaimer = function() { + if (self.disclaimerAccepted == true) { + go.walletHome(); + return; + } + profileService.checkDisclaimer(function(v) { + if (v) { + self.agreeDisclaimer(); + } else go.path('disclaimer'); + }); + }; + self.setTab = function(tab, reset, tries, switchState) { tries = tries || 0; @@ -975,6 +994,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r }; self.openMenu = function() { + if (!self.disclaimerAccepted) return; go.swipe(true); }; @@ -1220,7 +1240,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r $rootScope.$on('Local/Resume', function(event) { $log.debug('### Resume event'); - if (!self.disclaimerAccepted) go.path('disclaimer'); + self.checkDisclaimer(); self.debouncedUpdate(); }); @@ -1343,17 +1363,16 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.setUxLanguage(); self.setFocusedWallet(); self.updateTxHistory(); - if (self.disclaimerAccepted) go.walletHome(); - - storageService.getCleanAndScanAddresses(function(err, walletId) { - if (walletId && profileService.walletClients[walletId]) { - $log.debug('Clear last address cache and Scan ', walletId); - addressService.expireAddress(walletId, function(err) { - self.startScan(walletId); - }); - storageService.removeCleanAndScanAddresses(function() {}); - } + self.checkDisclaimer(); + storageService.getCleanAndScanAddresses(function(err, walletId) { + if (walletId && profileService.walletClients[walletId]) { + $log.debug('Clear last address cache and Scan ', walletId); + addressService.expireAddress(walletId, function(err) { + self.startScan(walletId); }); + storageService.removeCleanAndScanAddresses(function() {}); + } + }); }); $rootScope.$on('Local/SetTab', function(event, tab, reset) { diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 9c1bcbb23..ea59c9673 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -118,7 +118,7 @@ angular.module('copayApp.services') root.bindProfile = function(profile, cb) { root.profile = profile; - + configService.get(function(err) { $log.debug('Preferences read'); if (err) return cb(err); @@ -127,18 +127,21 @@ angular.module('copayApp.services') if (err) return cb(err); root._setFocus(focusedWalletId, function() { $rootScope.$emit('Local/ProfileBound'); - return cb(); + root.checkDisclaimer(function(val) { + if (!val) { + return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); + } + else { + return cb(); + } + }); }); }); }); + }; - root.loadAndBindProfile = function(cb) { - root.checkDisclaimer(function(val) { - if (!val) { - return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); - } - else { + root.loadAndBindProfile = function(cb) { storageService.getProfile(function(err, profile) { if (err) { $rootScope.$emit('Local/DeviceError', err); @@ -159,8 +162,6 @@ angular.module('copayApp.services') return root.bindProfile(profile, cb); } }); - } - }); }; root._seedWallet = function(opts, cb) { @@ -530,14 +531,14 @@ angular.module('copayApp.services') }; root.checkDisclaimer = function(cb) { - if (root.profile && root.profile.agreeDisclaimer) return cb(true); storageService.getProfile(function(err, profile) { if (profile && profile.agreeDisclaimer) return cb(true); else if (profile && !profile.agreeDisclaimer) { storageService.getCopayDisclaimerFlag(function(err, val) { if (val) { - root.storeDisclaimer(function(err) { + profile.agreeDisclaimer = true; + storageService.storeProfile(profile, function(err) { if (err) $log.error(err); return cb(true); });