Merge pull request #3905 from matiu/ref/disclaimer

refactor disclaimer handling
This commit is contained in:
Gustavo Maximiliano Cortez 2016-02-23 09:23:08 -03:00
commit f870ee410e
10 changed files with 57 additions and 55 deletions

View File

@ -38,7 +38,7 @@
</div>
</div>
<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
</button>
</div>

View File

@ -9,7 +9,7 @@
ng-repeat="item in sidebar.wallets track by $index"
ng-class="{'selected': item.id == index.walletId}"
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"
ng-style="{'background-color':item.color}">
<i class="icon-wallet size-21"></i>
@ -19,7 +19,7 @@
</a>
</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="fi-plus size-24 icon vm"></i>
<div class="tu text-bold">
@ -29,7 +29,7 @@
</a>
</li>
<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-bank size-24 icon vm"></i>
<div class="tu text-bold">
@ -39,7 +39,7 @@
</a>
</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="fi-widget size-24 icon vm"></i>
<div class="tu text-bold">

View File

@ -170,6 +170,7 @@ angular.module('copayApp.controllers').controller('createController',
});
return;
}
go.walletHome();
});
}, 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 {
$rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
}
});
}, 100);
@ -309,6 +310,7 @@ angular.module('copayApp.controllers').controller('importController',
}
$rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
});
}, 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.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;
@ -1068,8 +1047,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
};
self.openMenu = function() {
if (!self.disclaimerAccepted) return;
go.swipe(true);
profileService.isDisclaimerAccepted(function(val){
if (val) go.swipe(true);
else
$log.debug('Disclaimer not accepted, cannot open menu');
});
};
self.closeMenu = function() {
@ -1334,7 +1316,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/Resume', function(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();
});
@ -1476,7 +1463,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.setUxLanguage();
self.setFocusedWallet();
self.debounceUpdateHistory();
self.isDisclaimerAccepted();
storageService.getCleanAndScanAddresses(function(err, walletId) {
if (walletId && profileService.walletClients[walletId]) {
$log.debug('Clear last address cache and Scan ', walletId);

View File

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

View File

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

View File

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

View File

@ -28,12 +28,19 @@ angular.module('copayApp.services')
if (!config.pushNotifications.enabled) return;
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) {
var opts = {};
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
opts.token = token;
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));
});
});