fix disclaimer

This commit is contained in:
Gabriel Bazán 2015-11-23 12:17:04 -03:00
commit f23df02d0b
4 changed files with 89 additions and 74 deletions

View file

@ -6,7 +6,9 @@ angular.module('copayApp.controllers').controller('disclaimerController',
$scope.lang = uxLanguage.currentLanguage;
$scope.goHome = function() {
go.walletHome();
storageService.setCopayDisclaimerFlag(function(err) {
go.walletHome();
});
};
var create = function() {
@ -15,16 +17,20 @@ angular.module('copayApp.controllers').controller('disclaimerController',
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);
if (err == 'EEXISTS') {
storageService.getCopayDisclaimerFlag(function(val) {
if (val) return go.walletHome();
$scope.creatingProfile = false;
});
} else {
$log.warn(err);
$scope.error = err;
$scope.$apply();
$timeout(function() {
$log.warn('Retrying to create profile......');
create();
}, 3000);
}
} else {
$scope.error = "";
$scope.creatingProfile = false;

View file

@ -263,43 +263,39 @@ angular
},
}
})
.state('preferencesGlidera', {
url: '/preferencesGlidera',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesGlidera.html'
},
}
})
.state('preferencesAdvanced', {
url: '/preferencesAdvanced',
templateUrl: 'views/preferencesAdvanced.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesAdvanced.html'
},
}
})
.state('preferencesColor', {
url: '/preferencesColor',
templateUrl: 'views/preferencesColor.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesColor.html'
},
}
})
.state('preferencesAltCurrency', {
.state('preferencesGlidera', {
url: '/preferencesGlidera',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesGlidera.html'
},
}
})
.state('preferencesAdvanced', {
url: '/preferencesAdvanced',
templateUrl: 'views/preferencesAdvanced.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesAdvanced.html'
},
}
})
.state('preferencesColor', {
url: '/preferencesColor',
templateUrl: 'views/preferencesColor.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/preferencesColor.html'
},
}
})
.state('preferencesAltCurrency', {
url: '/preferencesAltCurrency',
templateUrl: 'views/preferencesAltCurrency.html',
walletShouldBeComplete: true,
@ -378,8 +374,7 @@ angular
},
}
})
.state('about', {
.state('about', {
url: '/about',
templateUrl: 'views/preferencesAbout.html',
walletShouldBeComplete: true,
@ -449,8 +444,7 @@ angular
templateUrl: 'views/warning.html',
needProfile: false
})
.state('add', {
.state('add', {
url: '/add',
needProfile: true,
views: {
@ -516,13 +510,15 @@ angular
// Give us time to open / create the profile
event.preventDefault();
// Try to open local profile
profileService.loadAndBindProfile(function(err) {
if (err) {
if (err.message && err.message.match('NOPROFILE')) {
$log.debug('No profile... redirecting');
$state.transitionTo('disclaimer');
} 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,26 +134,31 @@ angular.module('copayApp.services')
};
root.loadAndBindProfile = function(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);
})
storageService.getCopayDisclaimerFlag(function(err, val) {
if (!val) {
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
} 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);
}
});
}
});
};
@ -270,8 +275,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

@ -65,7 +65,7 @@ angular.module('copayApp.services')
return storage.set('profile', text, function(err) {
return cb(err, text);
});
} catch(e) {
} catch (e) {
$log.warn('Decrypt error: ', e);
return cb('Could not decrypt storage: device ID mismatch');
};
@ -199,6 +199,14 @@ 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);
};