refactor profileService
This commit is contained in:
parent
7781b93a88
commit
4865ea8ad8
9 changed files with 241 additions and 204 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue