Merge pull request #10 from gabrielbazan7/feat/restoreOnboarding

onboarding restore feature
This commit is contained in:
Matias Alejo Garcia 2016-08-31 09:38:43 -03:00 committed by GitHub
commit e638442fc8
21 changed files with 138 additions and 165 deletions

View File

@ -1,10 +1,10 @@
<div>
<h1 translate>Without a backup, you could lose money</h1>
<span translate>If something happens to this device, this app is deleted, or your password forgotten, neither you nor Bitpay can revoer your funds.</span>
<button ng-click="goBack()" class="button button-block button-light">
<button ng-click="goBack()" class="button button-block button-light" translate>
Go back
</button>
<button ng-click="continue()" class="button button-block button-light">
<button ng-click="continue()" class="button button-block button-light" translate>
I understand
</button>
</div>

View File

@ -1,7 +1,7 @@
<div>
<h1 translate>Screenshots are not secure</h1>
<span translate>if you take a screenshot, your backup may be viewed by others apps. You can make a safe backup with paper and a pen.</span>
<button ng-click="close()" class="button button-block button-light">
<button ng-click="close()" class="button button-block button-light" translate>
Got it
</button>
</div>

View File

@ -2,7 +2,7 @@
<ion-nav-bar class="bar-stable">
<ion-nav-buttons side="primary">
<button class="button no-border" href ui-sref="onboarding.backupRequest">
<i class="icon ion-chevron-left"></i> Back
<i class="icon ion-chevron-left"></i> {{'Back' | translate}}
</button>
</ion-nav-buttons>
</ion-nav-bar>

View File

@ -1,14 +1,14 @@
<ion-view ng-controller="collectEmailController">
<ion-nav-bar class="bar-stable">
<ion-view>
<ion-nav-bar class="bar-stable" ng-controller="backController">
<ion-nav-buttons side="secondary">
<button class="button no-border" ng-click="skip()">
Skip
<button class="button no-border" ng-click="onboardingMailSkip()">
{{'Skip' | translate}}
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-content >
Wallet Created
Where would you like to receive email notifications about payments
<ion-content ng-controller="collectEmailController">
<span translate>Wallet Created </span>
<span translate>Where would you like to receive email notifications about payments </span>
<form name="emailForm" ng-submit="save(emailForm)" novalidate>
<input type="email" id="email" name="email" ng-model="email" required></input>
<input type="submit" class="button button-block button-positive" value="{{'Save'|translate}}" ng-disabled="emailForm.$invalid">

View File

@ -1,9 +1,9 @@
<ion-view>
<ion-nav-bar class="bar-stable">
<ion-nav-title>Terms of Use</ion-nav-title>
<ion-nav-title>{{'Terms of Use' | translate}}</ion-nav-title>
<ion-nav-buttons side="primary">
<button class="button no-border" href ui-sref="onboarding.disclaimer">
<i class="icon ion-chevron-left"></i> Back
<i class="icon ion-chevron-left"></i> {{'Back' | translate}}
</button>
</ion-nav-buttons>
</ion-nav-bar>

View File

@ -1,14 +1,14 @@
<ion-view ng-controller="tourController" ng-init="init()">
<ion-nav-bar class="bar-stable">
<ion-nav-title>Get Started</ion-nav-title>
<ion-nav-title>{{'Get Started' | translate}}</ion-nav-title>
<ion-nav-buttons side="primary">
<button class="button no-border" ng-click="goBack()">
<i class="icon ion-chevron-left"></i> Back
<i class="icon ion-chevron-left"></i> {{'Back' | translate}}
</button>
</ion-nav-buttons>
<ion-nav-buttons side="secondary">
<button class="button no-border" ng-show="data.index == 0" ng-click="createProfile()">
Skip
<button class="button no-border" ng-show="data.index == 0" ng-click="createDefaultWallet()">
{{'Skip' | translate}}
</button>
</ion-nav-buttons>
</ion-nav-bar>
@ -23,7 +23,7 @@
<p translate>
Just scan the code to pay
</p>
<button class="button icon-right ion-chevron-right button-positive" ng-click="slideNext()">
<button class="button icon-right ion-chevron-right button-positive" ng-click="slideNext()" translate>
Got it
</button>
</div>
@ -39,7 +39,7 @@
<p translate>
The exchange rate changes with the market
</p>
<button class="button icon-right ion-chevron-right button-positive" ng-click="slideNext()">
<button class="button icon-right ion-chevron-right button-positive" ng-click="slideNext()" translate>
Makes sense
</button>
</div>
@ -55,7 +55,7 @@
<p translate>
Not even BitPay can access it
</p>
<button class="button icon-right button-positive" ng-click="createProfile()">
<button class="button icon-right button-positive" ng-click="createDefaultWallet()" translate>
Create bitcoin wallet
</button>
</div>

View File

@ -1,13 +1,12 @@
<ion-view>
<ion-content>
<ion-content ng-controller="welcomeController" ng-init="createProfile()">
<div class="text-center">
<h2>bitpay</h2>
<h2>bitpay</h2>
<span translate>
Take control of your money - get started with bitcoin
</span>
<button class="button button-block button-positive" href ui-sref="onboarding.tour" translate>Get started</button>
<button class="button button-block button-light" translate>Restore</button>
<button class="button button-block button-light" ng-click="goImport()" translate>Restore</button>
</div>
</ion-content>
</ion-view>

View File

@ -1,6 +1,6 @@
<ion-nav-bar class="bar-stable">
<ion-nav-bar class="bar-stable" ng-controller="backController">
<ion-nav-buttons side="primary">
<button class="button no-border" ui-sref="add.main">
<button class="button no-border" ng-click="importGoBack()">
<i class="icon ion-chevron-left"></i> Back
</button>
</ion-nav-buttons>

View File

@ -1,6 +1,6 @@
<ion-nav-bar class="bar-stable">
<ion-nav-bar class="bar-stable" ng-controller="backController">
<ion-nav-buttons side="primary">
<button class="button no-border" ui-sref="add.main">
<button class="button no-border" ng-click="importGoBack()">
<i class="icon ion-chevron-left"></i> Back
</button>
</ion-nav-buttons>

View File

@ -1,6 +1,6 @@
<ion-nav-bar class="bar-stable">
<ion-nav-bar class="bar-stable" ng-controller="backController">
<ion-nav-buttons side="primary">
<button class="button no-border" ui-sref="add.main">
<button class="button no-border" ng-click="importGoBack()">
<i class="icon ion-chevron-left"></i> Back
</button>
</ion-nav-buttons>

View File

@ -0,0 +1,19 @@
'use strict';
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');
}
});

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('backupController',
function($rootScope, $scope, $timeout, $log, $state, $stateParams, $ionicPopup, $ionicNavBarDelegate, uxLanguage, lodash, fingerprintService, platformInfo, configService, profileService, bwcService, walletService, ongoingProcess) {
function($rootScope, $scope, $timeout, $log, $state, $stateParams, $ionicPopup, $ionicNavBarDelegate, uxLanguage, lodash, fingerprintService, platformInfo, configService, profileService, bwcService, walletService, ongoingProcess, storageService) {
var wallet = profileService.getWallet($stateParams.walletId);
$ionicNavBarDelegate.title(wallet.credentials.walletName);
$scope.n = wallet.n;
@ -136,8 +136,11 @@ angular.module('copayApp.controllers').controller('backupController',
}
}
$rootScope.$emit('Local/BackupDone');
return cb();
$log.debug('Backup done');
storageService.setBackupFlag(wallet.credentials.walletId, function(err) {
$log.debug('Backup stored');
return cb();
});
}, 1);
};

View File

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('createController',
function($scope, $rootScope, $timeout, $log, lodash, $state, profileService, configService, gettext, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess, walletService) {
function($scope, $rootScope, $timeout, $log, lodash, $state, profileService, configService, gettext, ledger, trezor, platformInfo, derivationPathHelper, ongoingProcess, walletService, storageService) {
var isChromeApp = platformInfo.isChromeApp;
var isCordova = platformInfo.isCordova;
@ -184,7 +184,10 @@ angular.module('copayApp.controllers').controller('createController',
if (self.seedSourceId == 'set') {
$timeout(function() {
$rootScope.$emit('Local/BackupDone');
$log.debug('Backup done');
storageService.setBackupFlag(wallet.credentials.walletId, function(err) {
$log.debug('Backup stored');
});
}, 1);
}
$state.go('tabs.home')

View File

@ -1,69 +0,0 @@
'use strict';
angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $rootScope, $timeout, $log, $ionicSideMenuDelegate, profileService, applicationService, gettextCatalog, uxLanguage, $state, storageService, gettext, platformInfo, ongoingProcess) {
var tries = 0;
var isCordova = platformInfo.isCordova;
ongoingProcess.set('creatingWallet', true);
var create = function(opts) {
opts = opts || {};
$log.debug('Creating profile');
profileService.create(opts, function(err) {
if (err) {
$log.warn(err);
$scope.error = err;
$scope.$apply();
return $timeout(function() {
$log.warn('Retrying to create profile......');
if (tries == 3) {
tries == 0;
return create({
noWallet: true
});
} else {
tries += 1;
return create();
}
}, 3000);
};
$scope.error = "";
ongoingProcess.set('creatingWallet', false);
});
};
$scope.init = function(opts) {
$ionicSideMenuDelegate.canDragContent(false);
$scope.lang = uxLanguage.currentLanguage;
storageService.getProfile(function(err, profile) {
if (!profile) {
create(opts);
} else {
$log.info('There is already a profile');
ongoingProcess.set('creatingWallet', false);
profileService.bindProfile(profile, function(err) {
if (!err || !err.message || !err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Disclaimer already accepted at #disclaimer. Redirect to Wallet Home.');
$ionicSideMenuDelegate.canDragContent(true);
$state.go('tabs.home');
}
});
}
});
};
$scope.accept = function() {
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
else {
$ionicSideMenuDelegate.canDragContent(true);
$rootScope.$emit('disclaimerAccepted');
$state.go('tabs.home');
}
});
};
});

View File

@ -15,10 +15,6 @@ angular.module('copayApp.controllers').controller('importController',
$scope.account = 1;
$scope.importErr = false;
$scope.goBack = function() {
$ionicHistory.goBack();
};
var updateSeedSourceSelect = function() {
$scope.seedOptions = [];
@ -114,6 +110,11 @@ angular.module('copayApp.controllers').controller('importController',
});
$rootScope.$emit('Local/WalletImported', client.credentials.walletId);
if ($stateParams.fromOnboarding)
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
});
$state.go('tabs.home');
});
}, 100);
@ -141,6 +142,11 @@ angular.module('copayApp.controllers').controller('importController',
});
$rootScope.$emit('Local/WalletImported', client.credentials.walletId);
if ($stateParams.fromOnboarding)
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
});
$state.go('tabs.home');
});
}, 100);
@ -161,6 +167,11 @@ angular.module('copayApp.controllers').controller('importController',
});
}
$rootScope.$emit('Local/WalletImported', walletId);
if ($stateParams.fromOnboarding)
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
});
$state.go('tabs.home');
});
}, 100);
@ -190,6 +201,11 @@ angular.module('copayApp.controllers').controller('importController',
});
$rootScope.$emit('Local/WalletImported', client.credentials.walletId);
if ($stateParams.fromOnboarding)
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
});
$state.go('tabs.home');
});
}, 100);
@ -324,6 +340,11 @@ angular.module('copayApp.controllers').controller('importController',
$log.debug('Remote preferences saved for:' + wallet.walletId)
});
$rootScope.$emit('Local/WalletImported', wallet.walletId);
if ($stateParams.fromOnboarding)
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
});
$state.go('tabs.home');
});
}, 100);
@ -401,6 +422,12 @@ angular.module('copayApp.controllers').controller('importController',
$log.debug('Remote preferences saved for:' + wallet.walletId)
});
$rootScope.$emit('Local/WalletImported', wallet.walletId);
if ($stateParams.fromOnboarding)
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
});
$state.go('tabs.home');
});
}, 100);

View File

@ -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
})
};
}
});

View File

@ -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 || '';

View File

@ -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
});

View File

@ -0,0 +1,18 @@
'use strict';
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);
});
};
});

View File

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

View File

@ -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) {
@ -633,26 +613,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) {