refactor disclaimer handling

This commit is contained in:
Matias Alejo Garcia 2016-02-22 19:32:24 -03:00
commit bffaf9ad9d
10 changed files with 57 additions and 55 deletions

View file

@ -38,7 +38,7 @@
</div> </div>
</div> </div>
<div class="start-button columns button-box"> <div class="start-button columns button-box">
<button ng-disabled="creatingProfile" ng-click="index.acceptDisclaimer()" class="button black expand round size-12 text-spacing m0" translate> <button ng-disabled="creatingProfile" ng-click="disclaimer.accept()" class="button black expand round size-12 text-spacing m0" translate>
I AGREE. GET STARTED I AGREE. GET STARTED
</button> </button>
</div> </div>

View file

@ -9,7 +9,7 @@
ng-repeat="item in sidebar.wallets track by $index" ng-repeat="item in sidebar.wallets track by $index"
ng-class="{'selected': item.id == index.walletId}" ng-class="{'selected': item.id == index.walletId}"
class="nav-item"> class="nav-item">
<a fast-click callback-fn="sidebar.switchWallet(item.id, index.walletId)" class="oh"> <a fast-click callback-fn="sidebar.closeMenu(); sidebar.switchWallet(item.id, index.walletId)" class="oh">
<div class="avatar-wallet" <div class="avatar-wallet"
ng-style="{'background-color':item.color}"> ng-style="{'background-color':item.color}">
<i class="icon-wallet size-21"></i> <i class="icon-wallet size-21"></i>
@ -19,7 +19,7 @@
</a> </a>
</li> </li>
<li> <li>
<a ng-click="$root.go('add')" class="oh"> <a ng-click="sidebar.closeMenu(); $root.go('add')" class="oh">
<i class="icon-arrow-right3 size-18 right m10t vm"></i> <i class="icon-arrow-right3 size-18 right m10t vm"></i>
<i class="fi-plus size-24 icon vm"></i> <i class="fi-plus size-24 icon vm"></i>
<div class="tu text-bold"> <div class="tu text-bold">
@ -29,7 +29,7 @@
</a> </a>
</li> </li>
<li ng-show="index.glideraEnabled"> <li ng-show="index.glideraEnabled">
<a ng-click="$root.go('glidera')" class="oh"> <a ng-click="sidebar.closeMenu(); $root.go('glidera')" class="oh">
<i class="icon-arrow-right3 size-18 right m10t vm"></i> <i class="icon-arrow-right3 size-18 right m10t vm"></i>
<i class="icon-bank size-24 icon vm"></i> <i class="icon-bank size-24 icon vm"></i>
<div class="tu text-bold"> <div class="tu text-bold">
@ -39,7 +39,7 @@
</a> </a>
</li> </li>
<li> <li>
<a ng-click="$root.go('preferencesGlobal')" class="oh"> <a ng-click="sidebar.closeMenu(); $root.go('preferencesGlobal')" class="oh">
<i class="icon-arrow-right3 size-18 right m10t vm"></i> <i class="icon-arrow-right3 size-18 right m10t vm"></i>
<i class="fi-widget size-24 icon vm"></i> <i class="fi-widget size-24 icon vm"></i>
<div class="tu text-bold"> <div class="tu text-bold">

View file

@ -170,6 +170,7 @@ angular.module('copayApp.controllers').controller('createController',
}); });
return; return;
} }
go.walletHome();
}); });
}, 100); }, 100);

View file

@ -44,4 +44,11 @@ angular.module('copayApp.controllers').controller('disclaimerController',
}); });
}); });
}; };
});
this.accept = function() {
profileService.setDisclaimerAccepted(function(err) {
if (err) $log.error(err);
else go.walletHome();
});
};
});

View file

@ -75,6 +75,7 @@ angular.module('copayApp.controllers').controller('importController',
} else { } else {
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
} }
}); });
}, 100); }, 100);
@ -309,6 +310,7 @@ angular.module('copayApp.controllers').controller('importController',
} }
$rootScope.$emit('Local/WalletImported', walletId); $rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly')); notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}); });
}, 100); }, 100);
}; };

View file

@ -161,27 +161,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.usingCustomBWS = config.bwsFor && config.bwsFor[self.walletId] && (config.bwsFor[self.walletId] != defaults.bws.url); 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) { self.setTab = function(tab, reset, tries, switchState) {
tries = tries || 0; tries = tries || 0;
@ -1068,8 +1047,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}; };
self.openMenu = function() { self.openMenu = function() {
if (!self.disclaimerAccepted) return; profileService.isDisclaimerAccepted(function(val){
go.swipe(true); if (val) go.swipe(true);
else
$log.debug('Disclaimer not accepted, cannot open menu');
});
}; };
self.closeMenu = function() { self.closeMenu = function() {
@ -1334,7 +1316,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/Resume', function(event) { $rootScope.$on('Local/Resume', function(event) {
$log.debug('### Resume event'); $log.debug('### Resume event');
self.isDisclaimerAccepted(); profileService.isDisclaimerAccepted(function(v) {
if (!v) {
$log.debug('Disclaimer not accepted, resume to home');
go.path('disclaimer');
}
});
self.debouncedUpdate(); self.debouncedUpdate();
}); });
@ -1476,7 +1463,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setUxLanguage(); self.setUxLanguage();
self.setFocusedWallet(); self.setFocusedWallet();
self.debounceUpdateHistory(); self.debounceUpdateHistory();
self.isDisclaimerAccepted();
storageService.getCleanAndScanAddresses(function(err, walletId) { storageService.getCleanAndScanAddresses(function(err, walletId) {
if (walletId && profileService.walletClients[walletId]) { if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan ', walletId); $log.debug('Clear last address cache and Scan ', walletId);

View file

@ -128,7 +128,7 @@ angular.module('copayApp.controllers').controller('joinController',
$rootScope.$apply(); $rootScope.$apply();
return; return;
} }
go.walletHome();
}); });
}, 100); }, 100);
}; };

View file

@ -21,6 +21,10 @@ angular.module('copayApp.controllers').controller('sidebarController',
}); });
self.closeMenu = function() {
go.swipe();
};
self.signout = function() { self.signout = function() {
profileService.signout(); profileService.signout();
}; };
@ -60,5 +64,4 @@ angular.module('copayApp.controllers').controller('sidebarController',
}; };
self.setWallets(); self.setWallets();
}); });

View file

@ -134,7 +134,9 @@ angular.module('copayApp.services')
root._setFocus(focusedWalletId, function() { root._setFocus(focusedWalletId, function() {
$rootScope.$emit('Local/ProfileBound'); $rootScope.$emit('Local/ProfileBound');
storageService.getDeviceToken(function(err, token) { storageService.getDeviceToken(function(err, token) {
if (!token) pushNotificationsService.pushNotificationsInit(); if (!token)
pushNotificationsService.pushNotificationsInit();
root.isDisclaimerAccepted(function(val) { root.isDisclaimerAccepted(function(val) {
if (!val) { if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
@ -413,6 +415,7 @@ angular.module('copayApp.services')
handleImport(function() { handleImport(function() {
root.setAndStoreFocus(walletId, function() { root.setAndStoreFocus(walletId, function() {
storageService.storeProfile(root.profile, function(err) { storageService.storeProfile(root.profile, function(err) {
$rootScope.$emit('Local/ProfileCreated'); $rootScope.$emit('Local/ProfileCreated');
if (config.pushNotifications.enabled) if (config.pushNotifications.enabled)
pushNotificationsService.enableNotifications(root.walletClients); pushNotificationsService.enableNotifications(root.walletClients);
@ -447,7 +450,7 @@ angular.module('copayApp.services')
root._addWalletClient(walletClient, opts, function(err, walletId) { root._addWalletClient(walletClient, opts, function(err, walletId) {
if (err) return cb(err); if (err) return cb(err);
root.setMetaData(walletClient, addressBook, historyCache, function(error) { root.setMetaData(walletClient, addressBook, historyCache, function(error) {
if (error) console.log(error); if (error) $log.warn(error);
return cb(err, walletId); return cb(err, walletId);
}); });
}); });
@ -540,30 +543,23 @@ angular.module('copayApp.services')
}; };
root.setDisclaimerAccepted = function(cb) { root.setDisclaimerAccepted = function(cb) {
storageService.getProfile(function(err, profile) { root.profile.disclaimerAccepted = true;
profile.disclaimerAccepted = true; storageService.storeProfile(root.profile, function(err) {
storageService.storeProfile(profile, function(err) { return cb(err);
return cb(err);
});
}); });
}; };
root.isDisclaimerAccepted = function(cb) { root.isDisclaimerAccepted = function(cb) {
storageService.getProfile(function(err, profile) { var disclaimerAccepted = root.profile && root.profile.disclaimerAccepted;
if (profile && profile.disclaimerAccepted)
if (disclaimerAccepted)
return cb(true);
// OLD flag
storageService.getCopayDisclaimerFlag(function(err, val) {
if (val) {
root.profile.disclaimerAccepted = true;
return cb(true); 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 { } else {
return cb(); return cb();
} }

View file

@ -28,12 +28,19 @@ angular.module('copayApp.services')
if (!config.pushNotifications.enabled) return; if (!config.pushNotifications.enabled) return;
storageService.getDeviceToken(function(err, token) { storageService.getDeviceToken(function(err, token) {
if (err || !token) {
$log.warn('No token available for this device. Cannot set push notifications');
return;
}
lodash.forEach(walletsClients, function(walletClient) { lodash.forEach(walletsClients, function(walletClient) {
var opts = {}; var opts = {};
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null; opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
opts.token = token; opts.token = token;
root.subscribe(opts, walletClient, function(err, response) { root.subscribe(opts, walletClient, function(err, response) {
if (err) $log.warn('Subscription error: ' + err.message); if (err) $log.warn('Subscription error: ' + err.message + ': ' + JSON.stringify(opts));
else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response)); else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
}); });
}); });