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

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