From 1d3d0ff5ed13f6b54750326e130628f20d9e9445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Mon, 9 Nov 2015 10:58:10 -0300 Subject: [PATCH] fix set global address book --- src/js/services/profileService.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index d54d045b3..9e85e5c6f 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -338,12 +338,16 @@ angular.module('copayApp.services') }; root.setMetaData = function(walletClient, addressBook, historyCache, cb) { - - storageService.setAddressbook(walletClient.credentials.network, JSON.stringify(addressBook), function(err) { - if (err) return cb(err); - storageService.setTxHistory(JSON.stringify(historyCache), walletClient.credentials.walletId, function(err) { + storageService.getAddressbook(walletClient.credentials.network, function(err, localAddressBook) { + localAddressBook = JSON.parse(localAddressBook); + if (!localAddressBook) localAddressBook = {}; + addressBook = lodash.merge(addressBook, localAddressBook); + storageService.setAddressbook(walletClient.credentials.network, JSON.stringify(addressBook), function(err) { if (err) return cb(err); - return cb(null); + storageService.setTxHistory(JSON.stringify(historyCache), walletClient.credentials.walletId, function(err) { + if (err) return cb(err); + return cb(null); + }); }); }); } @@ -397,12 +401,11 @@ angular.module('copayApp.services') str = JSON.parse(str); - var addressBook = str.addressBook || []; + var addressBook = str.addressBook || {}; var historyCache = str.historyCache ||  []; root.setMetaData(walletClient, addressBook, historyCache, function(err) { if (err) console.log(err); - root._addWalletClient(walletClient, opts, cb); }); };