refactor profileService

This commit is contained in:
Matias Alejo Garcia 2016-06-06 12:21:15 -03:00
commit 4865ea8ad8
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
9 changed files with 241 additions and 204 deletions

View file

@ -27,6 +27,7 @@ Profile.fromObj = function(obj) {
x.credentials = obj.credentials;
x.disclaimerAccepted = obj.disclaimerAccepted;
x.checked = obj.checked || {};
x.checkedUA = null;
if (x.credentials[0] && typeof x.credentials[0] != 'object')
throw ("credentials should be an object");
@ -41,3 +42,44 @@ Profile.fromString = function(str) {
Profile.prototype.toObj = function() {
return JSON.stringify(this);
};
Profile.prototype.hasWallet = function(walletId) {
for (var i in this.credentials) {
var c = this.credentials[i];
if (c.walletId == walletId) return true;
};
return false;
};
Profile.prototype.isChecked = function(ua, walletId) {
return this.checkedUA == ua && this.checked[walletId];
};
Profile.prototype.setChecked = function(ua, walletId) {
if (this.checkedUA != ua) {
this.checkedUA = ua;
this.checked = {};
}
this.checked[walletId] = true;
};
Profile.prototype.addWallet = function(credentials) {
if (this.hasWallet(credentials.walletId))
return false;
this.credentials.push(credentials);
return true;
};
Profile.prototype.deleteWallet = function(walletId) {
if (!this.hasWallet(walletId))
return false;
this.credentials = this.credentials.filter(function(c) {
return c.walletId != walletId;
});
return true;
};