From a28f9c0e7f7ae21d2ce86ecb370ed08735cb33f0 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 4 Dec 2015 18:45:35 -0300 Subject: [PATCH 1/3] Ref bootstrapping (disclaimer) --- public/index.html | 2 +- public/views/disclaimer.html | 90 +++++++++++++++---------------- src/js/controllers/disclaimer.js | 19 +++---- src/js/controllers/index.js | 49 +++++++---------- src/js/services/profileService.js | 44 +++++++++++---- 5 files changed, 108 insertions(+), 96 deletions(-) diff --git a/public/index.html b/public/index.html index 3e763dc79..a9c4def93 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.agreeDisclaimer() ? index.openMenu() : null"> + ng-swipe-right="index.disclaimerAccepted ? index.openMenu() : null">
diff --git a/public/views/disclaimer.html b/public/views/disclaimer.html index b8bc3efb4..19b9e40f9 100644 --- a/public/views/disclaimer.html +++ b/public/views/disclaimer.html @@ -1,56 +1,54 @@
-
-
-
- icon + ng-controller="disclaimerController as disclaimer" ng-init="disclaimer.init()"> +
+
+ icon +
+
+
+ WELCOME TO COPAY +

A multisignature bitcoin wallet

-
-
- WELCOME TO COPAY -

A multisignature bitcoin wallet

-
-
-
-
-

-

Terms of Use
-
-

-
-
-
- - +
+
+

+

Terms of Use
+

-
-

I affirm that I have read, understood, and agree with these terms.

-
-
+
+
-
- {{(error)|translate}}. Retrying... -
-
-
-
-
-
-
-
-
-
- Creating Profile... -
+ +
+

I affirm that I have read, understood, and agree with these terms.

+
+
+ +
+ {{(error)|translate}}. Retrying...
-
- +
+
+
+
+
+
+
+
+ Creating Profile... +
+
+
+
diff --git a/src/js/controllers/disclaimer.js b/src/js/controllers/disclaimer.js index c26ddcb30..cce17f5f9 100644 --- a/src/js/controllers/disclaimer.js +++ b/src/js/controllers/disclaimer.js @@ -3,14 +3,12 @@ angular.module('copayApp.controllers').controller('disclaimerController', function($scope, $timeout, $log, profileService, isCordova, storageService, applicationService, gettextCatalog, uxLanguage, go) { self = this; - $scope.lang = uxLanguage.currentLanguage; $scope.goHome = function() { $scope.error = ""; profileService.storeDisclaimer(function(err) { if (err) { $scope.error = err; - $log.warn(err); $scope.$apply(); } else go.walletHome(); }); @@ -35,13 +33,16 @@ angular.module('copayApp.controllers').controller('disclaimerController', }); }; - storageService.getProfile(function(err, profile) { - if (!profile) create(); - else $scope.creatingProfile = false; + this.init = function() { + self.lang = uxLanguage.currentLanguage; + storageService.getProfile(function(err, profile) { + if (!profile) create(); + else $scope.creatingProfile = false; - //compatible - storageService.getCopayDisclaimerFlag(function(err, val) { - if (val) go.walletHome(); + //compatible + profileService.checkDisclaimer(function(val) { + if (val) go.walletHome(); + }); }); - }); + }; }); diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index f90539b99..780dcd5d6 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -126,26 +126,21 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.initGlidera(); 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; + profileService.checkDisclaimer(function(v) { + if (v) self.disclaimerAccepted = true; + if (fc.isPrivKeyExternal()) { + self.needsBackup = false; self.openWallet(); - }); - } - }); - }; - - self.agreeDisclaimer = function() { - storageService.getProfile(function(err, profile) { - if (profile && profile.agreeDisclaimer) - return profile.agreeDisclaimer; - return null; + } 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(); + }); + } + }); }); }; @@ -1168,10 +1163,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }); - $rootScope.$on('Local/NewFocusedWallet', function() { - self.setUxLanguage(); - }); - $rootScope.$on('Local/LanguageSettingUpdated', function() { self.setUxLanguage(); self.updateRemotePreferences({ @@ -1229,6 +1220,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.debouncedUpdate(); }); @@ -1348,14 +1340,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/NewFocusedWallet', function() { + self.setUxLanguage(); self.setFocusedWallet(); self.updateTxHistory(); - storageService.getProfile(function(err, profile) { - if (profile && profile.agreeDisclaimer) go.walletHome(); - - //compatible - storageService.getCopayDisclaimerFlag(function(err, val) { - if (val) go.walletHome(); + if (self.disclaimerAccepted) go.walletHome(); + storageService.getCleanAndScanAddresses(function(err, walletId) { if (walletId && profileService.walletClients[walletId]) { $log.debug('Clear last address cache and Scan ', walletId); @@ -1365,8 +1354,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r 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 317d48aa5..9c1bcbb23 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -134,6 +134,11 @@ angular.module('copayApp.services') }; root.loadAndBindProfile = function(cb) { + root.checkDisclaimer(function(val) { + if (!val) { + return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); + } + else { storageService.getProfile(function(err, profile) { if (err) { $rootScope.$emit('Local/DeviceError', err); @@ -150,13 +155,10 @@ angular.module('copayApp.services') return root.bindProfile(profile, cb); }) } else { - storageService.getCopayDisclaimerFlag(function(err, val) { - if (!profile.agreeDisclaimer) { - if (!val) return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); - } - $log.debug('Profile read'); - return root.bindProfile(profile, cb); - }); + $log.debug('Profile read'); + return root.bindProfile(profile, cb); + } + }); } }); }; @@ -521,11 +523,35 @@ angular.module('copayApp.services') root.storeDisclaimer = function(cb) { storageService.getProfile(function(err, profile) { profile.agreeDisclaimer = true; - storageService.storeProfile(profile, function() { + storageService.storeProfile(profile, function(err) { return cb(err); }); }); - } + }; + + 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) { + if (err) $log.error(err); + return cb(true); + }); + } + else { + return cb(); + } + }); + } + else { + return cb(); + } + }); + }; root.importLegacyWallet = function(username, password, blob, cb) { var walletClient = bwcService.getClient(); From bdfa89115d568d77a10284ec1600b039434f6052 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Sat, 5 Dec 2015 20:50:31 -0300 Subject: [PATCH 2/3] 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); }); From 8e69c0aa7ef0ea2e13bd613064a65f77fc7cc75b Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Mon, 7 Dec 2015 12:52:42 -0300 Subject: [PATCH 3/3] Rename variables --- public/views/disclaimer.html | 2 +- src/js/controllers/disclaimer.js | 2 +- src/js/controllers/index.js | 16 ++++++++-------- src/js/models/profile.js | 4 ++-- src/js/services/profileService.js | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/public/views/disclaimer.html b/public/views/disclaimer.html index 1dd70e071..639b73ad8 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 d783e55f9..853b496be 100644 --- a/src/js/controllers/disclaimer.js +++ b/src/js/controllers/disclaimer.js @@ -30,7 +30,7 @@ angular.module('copayApp.controllers').controller('disclaimerController', else $scope.creatingProfile = false; //compatible - profileService.checkDisclaimer(function(val) { + profileService.isDisclaimerAccepted(function(val) { if (val) go.walletHome(); }); }); diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 242f7be82..d6d88c512 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -148,24 +148,24 @@ 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() { + self.acceptDisclaimer = function() { var profile = profileService.profile; - if (profile) profile.agreeDisclaimer = true; + if (profile) profile.disclaimerAccepted = true; self.disclaimerAccepted = true; - profileService.storeDisclaimer(function(err) { + profileService.setDisclaimerAccepted(function(err) { if (err) $log.error(err); go.walletHome(); }); }; - self.checkDisclaimer = function() { + self.isDisclaimerAccepted = function() { if (self.disclaimerAccepted == true) { go.walletHome(); return; } - profileService.checkDisclaimer(function(v) { + profileService.isDisclaimerAccepted(function(v) { if (v) { - self.agreeDisclaimer(); + self.acceptDisclaimer(); } else go.path('disclaimer'); }); }; @@ -1240,7 +1240,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r $rootScope.$on('Local/Resume', function(event) { $log.debug('### Resume event'); - self.checkDisclaimer(); + self.isDisclaimerAccepted(); self.debouncedUpdate(); }); @@ -1363,7 +1363,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.setUxLanguage(); self.setFocusedWallet(); self.updateTxHistory(); - self.checkDisclaimer(); + self.isDisclaimerAccepted(); storageService.getCleanAndScanAddresses(function(err, walletId) { if (walletId && profileService.walletClients[walletId]) { $log.debug('Clear last address cache and Scan ', walletId); diff --git a/src/js/models/profile.js b/src/js/models/profile.js index 46d78bb3b..4b57a0f66 100644 --- a/src/js/models/profile.js +++ b/src/js/models/profile.js @@ -15,7 +15,7 @@ Profile.create = function(opts) { var x = new Profile(); x.createdOn = Date.now(); x.credentials = opts.credentials || []; - x.agreeDisclaimer = false; + x.disclaimerAccepted = false; return x; }; @@ -24,7 +24,7 @@ Profile.fromObj = function(obj) { x.createdOn = obj.createdOn; x.credentials = obj.credentials; - x.agreeDisclaimer = obj.agreeDisclaimer; + x.disclaimerAccepted = obj.disclaimerAccepted; if (x.credentials[0] && typeof x.credentials[0] != 'object') throw ("credentials should be an object"); diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index ea59c9673..40bb3260f 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -127,7 +127,7 @@ angular.module('copayApp.services') if (err) return cb(err); root._setFocus(focusedWalletId, function() { $rootScope.$emit('Local/ProfileBound'); - root.checkDisclaimer(function(val) { + root.isDisclaimerAccepted(function(val) { if (!val) { return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); } @@ -521,23 +521,23 @@ angular.module('copayApp.services') }); }; - root.storeDisclaimer = function(cb) { + root.setDisclaimerAccepted = function(cb) { storageService.getProfile(function(err, profile) { - profile.agreeDisclaimer = true; + profile.disclaimerAccepted = true; storageService.storeProfile(profile, function(err) { return cb(err); }); }); }; - root.checkDisclaimer = function(cb) { + root.isDisclaimerAccepted = function(cb) { storageService.getProfile(function(err, profile) { - if (profile && profile.agreeDisclaimer) + if (profile && profile.disclaimerAccepted) return cb(true); - else if (profile && !profile.agreeDisclaimer) { + else if (profile && !profile.disclaimerAccepted) { storageService.getCopayDisclaimerFlag(function(err, val) { if (val) { - profile.agreeDisclaimer = true; + profile.disclaimerAccepted = true; storageService.storeProfile(profile, function(err) { if (err) $log.error(err); return cb(true);