Merge pull request #3 from matiu/gab1

Refactor profile creation
This commit is contained in:
Gabriel Edgardo Bazán 2015-11-17 15:39:46 -03:00
commit c10bcf0cdb
7 changed files with 74 additions and 97 deletions

View File

@ -1,7 +1,6 @@
<div class="splash content text-center"
ng-init="init()"
ng-controller="disclaimerController">
<div ng-if="!agreed">
<div>
<div class="row">
<div class="container-image large-2 medium-2 small-2 medium-centered small-centered large-centered columns">
<img src="img/icon-splash.png" alt="icon" width="100%">
@ -15,6 +14,7 @@
<div class="row">
<div class="scrollArea">
<p class="enable_text_select m0">
<div class="size-16 text-gray" translate>Terms of Use</div>
<ul>
<li translate>The software you are about to use functions as a free, open source, and multi-signature digital wallet.</li>
<li translate>The software does not constitute an account where BitPay or other third parties serve as financial intermediaries or custodians of your bitcoin.</li>
@ -33,21 +33,24 @@
</div>
</div>
</div>
<div class="text-center size-12 text-warning" ng-show="error">
{{(error)|translate}}. <span translate>Retrying...</span>
</div>
<div class="row">
<p ng-show="lang != 'en'">
<a class="center" ng-click="$root.openExternalLink('https://copay.io/disclaimer')" translate>Official English Disclaimer</a>
</p>
</div>
<div ng-show="!agreed">
<div>
<p class="text-gray columns" translate>I affirm that I have read, understood, and agree with these terms.</p>
</div>
<div class="row">
<div class="text-center size-12 text-warning" ng-show="error">
{{(error)|translate}}. <span translate>Retrying...</span>
</div>
<div class="start-button columns">
<button ng-disabled="noProfile" ng-click="create()" class="button black expand round size-12 text-spacing" translate>
GET STARTED
<button ng-disabled="creatingProfile" ng-click="goHome()" class="button black expand round size-12 text-spacing" translate>
I AGREE. GET STARTED
</button>
</div>
</div>

View File

@ -1107,7 +1107,13 @@ input.ng-invalid-match, input.ng-invalid-match:focus {
.scrollArea ul {
font-size: 0.8rem;
text-align: left;
text-align: justify;
margin-left: 0;
}
.scrollArea li {
list-style-type:none;
display: inline;
}
.tabbable {

View File

@ -1,38 +1,37 @@
'use strict';
angular.module('copayApp.controllers').controller('disclaimerController',
function($scope, $timeout, $log, profileService, isCordova, storageService, gettextCatalog, applicationService, uxLanguage, go) {
function($scope, $timeout, $log, profileService, isCordova, storageService, gettextCatalog, uxLanguage, go) {
self = this;
$scope.noProfile = true;
$scope.lang = uxLanguage.currentLanguage;
$scope.create = function() {
storageService.setCopayDisclaimerFlag(function(err) {
applicationService.restart();
$scope.goHome = function() {
go.walletHome();
};
var create = function () {
$scope.creatingProfile = true;
profileService.create({}, function(err) {
if (err) {
if (err == 'EEXISTS')
return go.walletHome();
$log.warn(err);
$scope.error = err;
$scope.$apply();
$timeout(function() {
$log.warn('Retrying to create profile......');
create();
}, 3000);
} else {
$scope.error = "";
$scope.creatingProfile = false;
}
});
};
$scope.init = function(noWallet) {
storageService.getCopayDisclaimerFlag(function(err, val) {
$scope.lang = uxLanguage.currentLanguage;
$scope.agreed = val;
profileService.create({
noWallet: noWallet
}, function(err) {
if (err && !'EEXIST') {
$log.warn(err);
$scope.error = err;
$scope.$apply();
$scope.noProfile = true;
$timeout(function() {
$scope.init();
}, 3000);
} else {
$scope.error = "";
$scope.noProfile = false;
}
});
});
};
// create();
});

View File

@ -1295,17 +1295,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/NewFocusedWallet', function() {
self.setFocusedWallet();
self.updateTxHistory();
storageService.getCopayDisclaimerFlag(function(err, val) {
if (val) 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() {});
}
});
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() {});
}
});
});

View File

@ -75,17 +75,6 @@ angular
// link: http://stackoverflow.com/questions/15606751/angular-changes-urls-to-unsafe-in-extension-page?lq=1
$compileProvider.imgSrcSanitizationWhitelist(/^\s*((https?|ftp|file|blob|chrome-extension):|data:image\/)/);
$stateProvider
.state('splash', {
url: '/splash',
needProfile: false,
views: {
'main': {
templateUrl: 'views/splash.html',
}
}
});
$stateProvider
.state('translators', {
url: '/translators',
@ -521,9 +510,6 @@ angular
if (err) {
if (err.message && err.message.match('NOPROFILE')) {
$log.debug('No profile... redirecting');
$state.transitionTo('splash');
} else if (err.message && err.message.match('NONAGREEDDISCLAIMER')) {
$log.debug('Display disclaimer... redirecting');
$state.transitionTo('disclaimer');
} else {
throw new Error(err); // TODO

View File

@ -134,32 +134,26 @@ angular.module('copayApp.services')
};
root.loadAndBindProfile = function(cb) {
storageService.getCopayDisclaimerFlag(function(err, val) {
if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
} else {
storageService.getProfile(function(err, profile) {
if (err) {
$rootScope.$emit('Local/DeviceError', err);
return cb(err);
}
if (!profile) {
// Migration??
storageService.tryToMigrate(function(err, migratedProfile) {
if (err) return cb(err);
if (!migratedProfile)
return cb(new Error('NOPROFILE: No profile'));
profile = migratedProfile;
return root.bindProfile(profile, cb);
})
} else {
$log.debug('Profile read');
return root.bindProfile(profile, cb);
}
});
storageService.getProfile(function(err, profile) {
if (err) {
$rootScope.$emit('Local/DeviceError', err);
return cb(err);
}
if (!profile) {
// Migration??
storageService.tryToMigrate(function(err, migratedProfile) {
if (err) return cb(err);
if (!migratedProfile)
return cb(new Error('NOPROFILE: No profile'));
profile = migratedProfile;
return root.bindProfile(profile, cb);
})
} else {
$log.debug('Profile read');
return root.bindProfile(profile, cb);
}
});
};
@ -276,8 +270,8 @@ angular.module('copayApp.services')
// check if exist
if (lodash.find(root.profile.credentials, {
'walletId': walletData.walletId
})) {
'walletId': walletData.walletId
})) {
return cb(gettext('Cannot join the same wallet more that once'));
}
} catch (ex) {

View File

@ -199,14 +199,6 @@ angular.module('copayApp.services')
storage.remove('config', cb);
};
root.setCopayDisclaimerFlag = function(cb) {
storage.set('agreeDisclaimer', true, cb);
};
root.getCopayDisclaimerFlag = function(cb) {
storage.get('agreeDisclaimer', cb);
};
root.setRemotePrefsStoredFlag = function(cb) {
storage.set('remotePrefStored', true, cb);
};