From 0d81cf8e9cc15ce0eb22bbccbbacd0916a9c8545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Baz=C3=A1n?= Date: Fri, 6 Nov 2015 17:45:23 -0300 Subject: [PATCH] fix --- src/js/services/backupService.js | 12 +++++++++++- src/js/services/profileService.js | 8 ++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/js/services/backupService.js b/src/js/services/backupService.js index de47cf5a2..041015053 100644 --- a/src/js/services/backupService.js +++ b/src/js/services/backupService.js @@ -53,6 +53,14 @@ angular.module('copayApp.services') return cb(); }; + root.addMetadata = function(b, opts) { + + b = JSON.parse(b); + if (opts.historyCache) b.historyCache = opts.historyCache; + if (opts.addressBook) b.addressBook = opts.addressBook; + return JSON.stringify(b); + } + root.walletExport = function(password, opts) { if (!password) { return null; @@ -61,6 +69,8 @@ angular.module('copayApp.services') try { opts = opts || {}; var b = fc.export(opts); + if (opts.historyCache || opts.addressBook) b = root.addMetadata(b, opts); + var e = sjcl.encrypt(password, b, { iter: 10000 }); @@ -82,4 +92,4 @@ angular.module('copayApp.services') _download(ew, filename, cb) }; return root; - }); + }); \ No newline at end of file diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index a99fe69ef..d54d045b3 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -338,9 +338,10 @@ angular.module('copayApp.services') }; root.setMetaData = function(walletClient, addressBook, historyCache, cb) { - storageService.setAddressbook(walletClient.credentials.network, addressBook, function(err) { + + storageService.setAddressbook(walletClient.credentials.network, JSON.stringify(addressBook), function(err) { if (err) return cb(err); - storageService.setTxHistory(historyCache, walletClient.credentials.walletId, function(err) { + storageService.setTxHistory(JSON.stringify(historyCache), walletClient.credentials.walletId, function(err) { if (err) return cb(err); return cb(null); }); @@ -393,6 +394,9 @@ angular.module('copayApp.services') } catch (err) { return cb(gettext('Could not import. Check input file and password')); } + + str = JSON.parse(str); + var addressBook = str.addressBook || []; var historyCache = str.historyCache ||  [];