From adf7115c9cc337dd48d0358e8634ad7731ea7ce3 Mon Sep 17 00:00:00 2001 From: Brendon Duncan Date: Mon, 4 Jun 2018 14:38:15 +1200 Subject: [PATCH] Merging profiles. --- src/js/models/profile.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/js/models/profile.js b/src/js/models/profile.js index d80087e7f..ac4b4828c 100644 --- a/src/js/models/profile.js +++ b/src/js/models/profile.js @@ -67,7 +67,22 @@ Profile.prototype.isDeviceChecked = function(ua) { * @param {Profile} other */ Profile.prototype.merge = function(other) { - throw 'Profile merge not implemented.'; + + var newCredentials = []; + + other.credentials.forEach(function(otherCredential) { + var credentialExists = false; + this.credentials.forEach(function(thisCredential) { + if (otherCredential.walletId === thisCredential.walletId) { + credentialExists = true; + } + }); + if (!credentialExists) { + newCredentials.push(otherCredential); + } + }); + + Array.prototype.push.apply(this.credentials, newCredentials); }; Profile.prototype.setChecked = function(ua, walletId) {