From 74e6897d6632dd0a6398c4e3e299656ae5ade8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Tue, 30 Aug 2016 15:38:48 -0300 Subject: [PATCH] create profile separately from default wallet --- public/views/onboarding/collectEmail.html | 8 +-- public/views/onboarding/tour.html | 4 +- public/views/onboarding/welcome.html | 5 +- src/js/controllers/backController.js | 11 +++- .../controllers/onboarding/backupWarning.js | 6 +-- src/js/controllers/onboarding/collectEmail.js | 5 -- src/js/controllers/onboarding/tour.js | 23 +++------ .../onboarding/welcomeController.js | 11 +++- src/js/routes.js | 2 +- src/js/services/profileService.js | 50 +++++++------------ 10 files changed, 57 insertions(+), 68 deletions(-) diff --git a/public/views/onboarding/collectEmail.html b/public/views/onboarding/collectEmail.html index a539eaaa0..bceda1776 100644 --- a/public/views/onboarding/collectEmail.html +++ b/public/views/onboarding/collectEmail.html @@ -1,12 +1,12 @@ - - + + - - + Wallet Created Where would you like to receive email notifications about payments
diff --git a/public/views/onboarding/tour.html b/public/views/onboarding/tour.html index be57326b9..34e3c122c 100644 --- a/public/views/onboarding/tour.html +++ b/public/views/onboarding/tour.html @@ -7,7 +7,7 @@ - @@ -55,7 +55,7 @@

Not even BitPay can access it

- diff --git a/public/views/onboarding/welcome.html b/public/views/onboarding/welcome.html index 861e6ba87..21d9018cf 100644 --- a/public/views/onboarding/welcome.html +++ b/public/views/onboarding/welcome.html @@ -1,8 +1,7 @@ - +
-

bitpay

- +

bitpay

Take control of your money - get started with bitcoin diff --git a/src/js/controllers/backController.js b/src/js/controllers/backController.js index c54ba0599..285f8f630 100644 --- a/src/js/controllers/backController.js +++ b/src/js/controllers/backController.js @@ -1,10 +1,19 @@ 'use strict'; -angular.module('copayApp.controllers').controller('backController', function($scope, $state, $stateParams) { +angular.module('copayApp.controllers').controller('backController', function($scope, $state, $stateParams, platformInfo) { + + var isCordova = platformInfo.isCordova; + var isWP = platformInfo.isWP; + var usePushNotifications = isCordova && !isWP; $scope.importGoBack = function() { if ($stateParams.fromOnboarding) $state.go('onboarding.welcome'); else $state.go('add.main'); }; + $scope.onboardingMailSkip = function() { + if (!usePushNotifications) $state.go('onboarding.backupRequest'); + else $state.go('onboarding.notifications'); + } + }); diff --git a/src/js/controllers/onboarding/backupWarning.js b/src/js/controllers/onboarding/backupWarning.js index f0b7c4978..9067b1bf6 100644 --- a/src/js/controllers/onboarding/backupWarning.js +++ b/src/js/controllers/onboarding/backupWarning.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.controllers').controller('backupWarningController', function($scope, $state, $ionicPopup, profileService) { +angular.module('copayApp.controllers').controller('backupWarningController', function($scope, $state, $ionicPopup, $stateParams, profileService) { $scope.openPopup = function() { var backupWarningPopup = $ionicPopup.show({ @@ -10,12 +10,10 @@ angular.module('copayApp.controllers').controller('backupWarningController', fun $scope.close = function() { backupWarningPopup.close(); - var wallet = profileService.getWallets()[0]; $state.go('wallet.backup', { - walletId: wallet.credentials.walletId, + walletId: $stateParams.walletId, fromOnboarding: true }) }; } - }); diff --git a/src/js/controllers/onboarding/collectEmail.js b/src/js/controllers/onboarding/collectEmail.js index 8fda2d4df..220c349e5 100644 --- a/src/js/controllers/onboarding/collectEmail.js +++ b/src/js/controllers/onboarding/collectEmail.js @@ -6,11 +6,6 @@ angular.module('copayApp.controllers').controller('collectEmailController', func var isWP = platformInfo.isWP; var usePushNotifications = isCordova && !isWP; - $scope.skip = function() { - if (!usePushNotifications) $state.go('onboarding.backupRequest'); - else $state.go('onboarding.notifications'); - } - $scope.save = function(form) { var wallet = profileService.getWallet($stateParams.walletId); var email = $scope.email || ''; diff --git a/src/js/controllers/onboarding/tour.js b/src/js/controllers/onboarding/tour.js index 662b0431d..c5b69bde3 100644 --- a/src/js/controllers/onboarding/tour.js +++ b/src/js/controllers/onboarding/tour.js @@ -2,8 +2,9 @@ angular.module('copayApp.controllers').controller('tourController', function($scope, $state, $log, $timeout, ongoingProcess, profileService) { - $scope.init = function() { + var tries = 0; + $scope.init = function() { $scope.data = { index: 0 }; @@ -16,33 +17,25 @@ angular.module('copayApp.controllers').controller('tourController', } }; - $scope.createProfile = function(opts) { - var tries = 0; - opts = opts || {}; - $log.debug('Creating profile'); + $scope.createDefaultWallet = function() { ongoingProcess.set('creatingWallet', true); - profileService.create(opts, function(err) { + profileService.createDefaultWallet(function(err, walletClient) { if (err) { $log.warn(err); - $scope.error = err; - $scope.$apply(); return $timeout(function() { - $log.warn('Retrying to create profile......'); + $log.warn('Retrying to create default wallet......'); if (tries == 3) { tries == 0; - return $scope.createProfile({ - noWallet: true - }); + return $scope.createDefaultWallet(); } else { tries += 1; - return $scope.createProfile(); + return $scope.createDefaultWallet(); } }, 3000); }; - $scope.error = ""; ongoingProcess.set('creatingWallet', false); - var wallet = profileService.getWallets()[0]; + var wallet = walletClient; $state.go('onboarding.collectEmail', { walletId: wallet.credentials.walletId }); diff --git a/src/js/controllers/onboarding/welcomeController.js b/src/js/controllers/onboarding/welcomeController.js index cda0a930c..b6e529a11 100644 --- a/src/js/controllers/onboarding/welcomeController.js +++ b/src/js/controllers/onboarding/welcomeController.js @@ -1,11 +1,18 @@ 'use strict'; -angular.module('copayApp.controllers').controller('welcomeController', function($scope, $state, $ionicPopup, profileService) { +angular.module('copayApp.controllers').controller('welcomeController', function($scope, $state, $timeout, $log, $ionicPopup, profileService) { $scope.goImport = function() { $state.go('add.import.phrase', { fromOnboarding: true }); - } + }; + + $scope.createProfile = function() { + $log.debug('Creating profile'); + profileService.createProfile(function(err) { + if (err) $log.warn(err); + }); + }; }); diff --git a/src/js/routes.js b/src/js/routes.js index 98b24680e..c12c61be6 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -554,7 +554,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr */ .state('onboarding', { - url: '/onboarding', + url: '/onboarding/:walletId', abstract: true, template: '' }) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 44c38b697..37161dd00 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -367,26 +367,6 @@ angular.module('copayApp.services') }, 50); }; - // Creates the default Copay profile and its wallet - root.createDefaultProfile = function(opts, cb) { - var p = Profile.create(); - - if (opts.noWallet) { - return cb(null, p); - } - - opts.m = 1; - opts.n = 1; - opts.network = 'livenet'; - - doCreateWallet(opts, function(err, walletClient) { - if (err) return cb(err); - - p.addWallet(JSON.parse(walletClient.export())); - return cb(null, p); - }); - }; - // create and store a wallet root.createWallet = function(opts, cb) { doCreateWallet(opts, function(err, walletClient, secret) { @@ -482,6 +462,7 @@ angular.module('copayApp.services') if (!client || !client.credentials) return cb(gettext('Could not access wallet')); + if (root.profile) root.profile = Profile.create(); var walletId = client.credentials.walletId if (!root.profile.addWallet(JSON.parse(client.export()))) @@ -633,26 +614,33 @@ angular.module('copayApp.services') }); }; - root.create = function(opts, cb) { - $log.info('Creating profile', opts); + root.createProfile = function(cb) { + $log.info('Creating profile'); var defaults = configService.getDefaults(); configService.get(function(err) { - root.createDefaultProfile(opts, function(err, p) { - if (err) return cb(err); + if (err) $log.debug(err); - storageService.storeNewProfile(p, function(err) { - if (err) return cb(err); - root.bindProfile(p, function(err) { - // ignore NONAGREEDDISCLAIMER - if (err && err.toString().match('NONAGREEDDISCLAIMER')) return cb(); - return cb(err); - }); + var p = Profile.create(); + storageService.storeNewProfile(p, function(err) { + if (err) return cb(err); + root.bindProfile(p, function(err) { + // ignore NONAGREEDDISCLAIMER + if (err && err.toString().match('NONAGREEDDISCLAIMER')) return cb(); + return cb(err); }); }); }); }; + root.createDefaultWallet = function(cb) { + var opts = {}; + opts.m = 1; + opts.n = 1; + opts.network = 'livenet'; + root.createWallet(opts, cb); + }; + root.setDisclaimerAccepted = function(cb) { root.profile.disclaimerAccepted = true; storageService.storeProfile(root.profile, function(err) {