Merge pull request #3602 from cmgustavo/ref/disclaimer-flag

Ref bootstrapping (disclaimer)
This commit is contained in:
Matias Alejo Garcia 2015-12-07 12:58:31 -03:00
commit 74d7b24d02
6 changed files with 132 additions and 110 deletions

View file

@ -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.openMenu()">
<div class="off-canvas-wrap" id="off-canvas-wrap">
<div class="inner-wrap">

View file

@ -1,6 +1,5 @@
<div class="splash content text-center"
ng-controller="disclaimerController">
<div>
ng-controller="disclaimerController as disclaimer" ng-init="disclaimer.init()">
<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%">
@ -22,7 +21,7 @@
</div>
<div class="row">
<p ng-show="lang != 'en'">
<p ng-show="disclaimer.lang != 'en'">
<a class="center" ng-click="$root.openExternalLink('https://copay.io/disclaimer')" translate>Official English Disclaimer</a>
</p>
</div>
@ -47,10 +46,9 @@
</div>
</div>
<div class="start-button columns">
<button ng-disabled="creatingProfile" ng-click="goHome()" class="button black expand round size-12 text-spacing" translate>
<button ng-disabled="creatingProfile" ng-click="index.acceptDisclaimer()" class="button black expand round size-12 text-spacing" translate>
I AGREE. GET STARTED
</button>
</div>
</div>
</div>
</div>

View file

@ -3,18 +3,6 @@
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();
});
};
var create = function() {
$scope.creatingProfile = true;
@ -35,13 +23,16 @@ angular.module('copayApp.controllers').controller('disclaimerController',
});
};
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) {
profileService.isDisclaimerAccepted(function(val) {
if (val) go.walletHome();
});
});
};
});

View file

@ -141,14 +141,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
};
self.agreeDisclaimer = function() {
storageService.getProfile(function(err, profile) {
if (profile && profile.agreeDisclaimer)
return profile.agreeDisclaimer;
return null;
});
};
self.setCustomBWSFlag = function() {
var defaults = configService.getDefaults();
var config = configService.getSync();
@ -156,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.acceptDisclaimer = function() {
var profile = profileService.profile;
if (profile) profile.disclaimerAccepted = true;
self.disclaimerAccepted = true;
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
go.walletHome();
});
};
self.isDisclaimerAccepted = function() {
if (self.disclaimerAccepted == true) {
go.walletHome();
return;
}
profileService.isDisclaimerAccepted(function(v) {
if (v) {
self.acceptDisclaimer();
} else go.path('disclaimer');
});
};
self.setTab = function(tab, reset, tries, switchState) {
tries = tries || 0;
@ -980,6 +994,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
};
self.openMenu = function() {
if (!self.disclaimerAccepted) return;
go.swipe(true);
};
@ -1168,10 +1183,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 +1240,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/Resume', function(event) {
$log.debug('### Resume event');
self.isDisclaimerAccepted();
self.debouncedUpdate();
});
@ -1348,14 +1360,10 @@ 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();
self.isDisclaimerAccepted();
storageService.getCleanAndScanAddresses(function(err, walletId) {
if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan ', walletId);
@ -1366,8 +1374,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}
});
});
});
});
$rootScope.$on('Local/SetTab', function(event, tab, reset) {
self.setTab(tab, reset);

View file

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

View file

@ -127,10 +127,18 @@ angular.module('copayApp.services')
if (err) return cb(err);
root._setFocus(focusedWalletId, function() {
$rootScope.$emit('Local/ProfileBound');
root.isDisclaimerAccepted(function(val) {
if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
}
else {
return cb();
}
});
});
});
});
};
root.loadAndBindProfile = function(cb) {
@ -150,13 +158,8 @@ 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);
});
}
});
};
@ -518,14 +521,38 @@ angular.module('copayApp.services')
});
};
root.storeDisclaimer = function(cb) {
root.setDisclaimerAccepted = function(cb) {
storageService.getProfile(function(err, profile) {
profile.agreeDisclaimer = true;
storageService.storeProfile(profile, function() {
profile.disclaimerAccepted = true;
storageService.storeProfile(profile, function(err) {
return cb(err);
});
});
};
root.isDisclaimerAccepted = function(cb) {
storageService.getProfile(function(err, profile) {
if (profile && profile.disclaimerAccepted)
return cb(true);
else if (profile && !profile.disclaimerAccepted) {
storageService.getCopayDisclaimerFlag(function(err, val) {
if (val) {
profile.disclaimerAccepted = true;
storageService.storeProfile(profile, 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();