create profile separately from default wallet

This commit is contained in:
Gabriel Bazán 2016-08-30 15:38:48 -03:00
commit 74e6897d66
10 changed files with 57 additions and 68 deletions

View file

@ -1,12 +1,12 @@
<ion-view ng-controller="collectEmailController"> <ion-view>
<ion-nav-bar class="bar-stable"> <ion-nav-bar class="bar-stable" ng-controller="backController">
<ion-nav-buttons side="secondary"> <ion-nav-buttons side="secondary">
<button class="button no-border" ng-click="skip()"> <button class="button no-border" ng-click="onboardingMailSkip()">
Skip Skip
</button> </button>
</ion-nav-buttons> </ion-nav-buttons>
</ion-nav-bar> </ion-nav-bar>
<ion-content > <ion-content ng-controller="collectEmailController">
Wallet Created Wallet Created
Where would you like to receive email notifications about payments Where would you like to receive email notifications about payments
<form name="emailForm" ng-submit="save(emailForm)" novalidate> <form name="emailForm" ng-submit="save(emailForm)" novalidate>

View file

@ -7,7 +7,7 @@
</button> </button>
</ion-nav-buttons> </ion-nav-buttons>
<ion-nav-buttons side="secondary"> <ion-nav-buttons side="secondary">
<button class="button no-border" ng-show="data.index == 0" ng-click="createProfile()"> <button class="button no-border" ng-show="data.index == 0" ng-click="createDefaultWallet()">
Skip Skip
</button> </button>
</ion-nav-buttons> </ion-nav-buttons>
@ -55,7 +55,7 @@
<p translate> <p translate>
Not even BitPay can access it Not even BitPay can access it
</p> </p>
<button class="button icon-right button-positive" ng-click="createProfile()"> <button class="button icon-right button-positive" ng-click="createDefaultWallet()">
Create bitcoin wallet Create bitcoin wallet
</button> </button>
</div> </div>

View file

@ -1,8 +1,7 @@
<ion-view> <ion-view>
<ion-content ng-controller="welcomeController"> <ion-content ng-controller="welcomeController" ng-init="createProfile()">
<div class="text-center"> <div class="text-center">
<h2>bitpay</h2> <h2>bitpay</h2>
<span translate> <span translate>
Take control of your money - get started with bitcoin Take control of your money - get started with bitcoin
</span> </span>

View file

@ -1,10 +1,19 @@
'use strict'; '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() { $scope.importGoBack = function() {
if ($stateParams.fromOnboarding) $state.go('onboarding.welcome'); if ($stateParams.fromOnboarding) $state.go('onboarding.welcome');
else $state.go('add.main'); else $state.go('add.main');
}; };
$scope.onboardingMailSkip = function() {
if (!usePushNotifications) $state.go('onboarding.backupRequest');
else $state.go('onboarding.notifications');
}
}); });

View file

@ -1,6 +1,6 @@
'use strict'; '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() { $scope.openPopup = function() {
var backupWarningPopup = $ionicPopup.show({ var backupWarningPopup = $ionicPopup.show({
@ -10,12 +10,10 @@ angular.module('copayApp.controllers').controller('backupWarningController', fun
$scope.close = function() { $scope.close = function() {
backupWarningPopup.close(); backupWarningPopup.close();
var wallet = profileService.getWallets()[0];
$state.go('wallet.backup', { $state.go('wallet.backup', {
walletId: wallet.credentials.walletId, walletId: $stateParams.walletId,
fromOnboarding: true fromOnboarding: true
}) })
}; };
} }
}); });

View file

@ -6,11 +6,6 @@ angular.module('copayApp.controllers').controller('collectEmailController', func
var isWP = platformInfo.isWP; var isWP = platformInfo.isWP;
var usePushNotifications = isCordova && !isWP; var usePushNotifications = isCordova && !isWP;
$scope.skip = function() {
if (!usePushNotifications) $state.go('onboarding.backupRequest');
else $state.go('onboarding.notifications');
}
$scope.save = function(form) { $scope.save = function(form) {
var wallet = profileService.getWallet($stateParams.walletId); var wallet = profileService.getWallet($stateParams.walletId);
var email = $scope.email || ''; var email = $scope.email || '';

View file

@ -2,8 +2,9 @@
angular.module('copayApp.controllers').controller('tourController', angular.module('copayApp.controllers').controller('tourController',
function($scope, $state, $log, $timeout, ongoingProcess, profileService) { function($scope, $state, $log, $timeout, ongoingProcess, profileService) {
$scope.init = function() { var tries = 0;
$scope.init = function() {
$scope.data = { $scope.data = {
index: 0 index: 0
}; };
@ -16,33 +17,25 @@ angular.module('copayApp.controllers').controller('tourController',
} }
}; };
$scope.createProfile = function(opts) { $scope.createDefaultWallet = function() {
var tries = 0;
opts = opts || {};
$log.debug('Creating profile');
ongoingProcess.set('creatingWallet', true); ongoingProcess.set('creatingWallet', true);
profileService.create(opts, function(err) { profileService.createDefaultWallet(function(err, walletClient) {
if (err) { if (err) {
$log.warn(err); $log.warn(err);
$scope.error = err;
$scope.$apply();
return $timeout(function() { return $timeout(function() {
$log.warn('Retrying to create profile......'); $log.warn('Retrying to create default wallet......');
if (tries == 3) { if (tries == 3) {
tries == 0; tries == 0;
return $scope.createProfile({ return $scope.createDefaultWallet();
noWallet: true
});
} else { } else {
tries += 1; tries += 1;
return $scope.createProfile(); return $scope.createDefaultWallet();
} }
}, 3000); }, 3000);
}; };
$scope.error = "";
ongoingProcess.set('creatingWallet', false); ongoingProcess.set('creatingWallet', false);
var wallet = profileService.getWallets()[0]; var wallet = walletClient;
$state.go('onboarding.collectEmail', { $state.go('onboarding.collectEmail', {
walletId: wallet.credentials.walletId walletId: wallet.credentials.walletId
}); });

View file

@ -1,11 +1,18 @@
'use strict'; '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() { $scope.goImport = function() {
$state.go('add.import.phrase', { $state.go('add.import.phrase', {
fromOnboarding: true fromOnboarding: true
}); });
} };
$scope.createProfile = function() {
$log.debug('Creating profile');
profileService.createProfile(function(err) {
if (err) $log.warn(err);
});
};
}); });

View file

@ -554,7 +554,7 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr
*/ */
.state('onboarding', { .state('onboarding', {
url: '/onboarding', url: '/onboarding/:walletId',
abstract: true, abstract: true,
template: '<ion-nav-view name="onboarding"></ion-nav-view>' template: '<ion-nav-view name="onboarding"></ion-nav-view>'
}) })

View file

@ -367,26 +367,6 @@ angular.module('copayApp.services')
}, 50); }, 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 // create and store a wallet
root.createWallet = function(opts, cb) { root.createWallet = function(opts, cb) {
doCreateWallet(opts, function(err, walletClient, secret) { doCreateWallet(opts, function(err, walletClient, secret) {
@ -482,6 +462,7 @@ angular.module('copayApp.services')
if (!client || !client.credentials) if (!client || !client.credentials)
return cb(gettext('Could not access wallet')); return cb(gettext('Could not access wallet'));
if (root.profile) root.profile = Profile.create();
var walletId = client.credentials.walletId var walletId = client.credentials.walletId
if (!root.profile.addWallet(JSON.parse(client.export()))) if (!root.profile.addWallet(JSON.parse(client.export())))
@ -633,26 +614,33 @@ angular.module('copayApp.services')
}); });
}; };
root.create = function(opts, cb) { root.createProfile = function(cb) {
$log.info('Creating profile', opts); $log.info('Creating profile');
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
configService.get(function(err) { configService.get(function(err) {
root.createDefaultProfile(opts, function(err, p) { if (err) $log.debug(err);
if (err) return cb(err);
storageService.storeNewProfile(p, function(err) { var p = Profile.create();
if (err) return cb(err); storageService.storeNewProfile(p, function(err) {
root.bindProfile(p, function(err) { if (err) return cb(err);
// ignore NONAGREEDDISCLAIMER root.bindProfile(p, function(err) {
if (err && err.toString().match('NONAGREEDDISCLAIMER')) return cb(); // ignore NONAGREEDDISCLAIMER
return cb(err); 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.setDisclaimerAccepted = function(cb) {
root.profile.disclaimerAccepted = true; root.profile.disclaimerAccepted = true;
storageService.storeProfile(root.profile, function(err) { storageService.storeProfile(root.profile, function(err) {