From 3678b27bf53fa079ad3779c8e91ec58931d1cebb Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Tue, 14 Apr 2015 15:41:27 -0300 Subject: [PATCH] set scan status --- lib/server.js | 36 ++++++++++++++++++++++-------------- test/integration/server.js | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/server.js b/lib/server.js index 5a8d636..2b0ea1a 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1224,27 +1224,35 @@ WalletService.prototype.scan = function(opts, cb) { WalletService.prototype.startScan = function(opts, cb) { var self = this; - function scanFinished(err) { - var data = {}; - if (err) { - data.result = 'error'; - data.error = err; - } else { - data.result = 'success'; - } - self._notify('ScanFinished', data, true); + function scanFinished(wallet, err) { + var result = err ? 'error' : 'success'; + var data = { + result: result, + }; + if (err) data.error = err; + + self.getWallet({}, function(err, wallet) { + wallet.scanStatus = result; + self.storage.storeWallet(wallet, function() { + self._notify('ScanFinished', data, true); + }); + }); }; self.getWallet({}, function(err, wallet) { if (err) return cb(err); if (!wallet.isComplete()) return cb(new ClientError('Wallet is not complete')); + wallet.scanStatus = 'running'; + self.storage.storeWallet(wallet, function(err) { + if (err) return cb(err); - setTimeout(function() { - self.scan(opts, scanFinished); - }, 100); + setTimeout(function() { + self.scan(opts, _.bind(scanFinished, self, wallet)); + }, 100); - return cb(null, { - started: true + return cb(null, { + started: true + }); }); }); }; diff --git a/test/integration/server.js b/test/integration/server.js index fdb588b..8acd6e4 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2657,7 +2657,7 @@ describe('Wallet service', function() { NotificationBroadcaster.removeAllListeners(); }); - it.only('should start an asynchronous scan', function(done) { + it('should start an asynchronous scan', function(done) { helpers.stubAddressActivity(['3K2VWMXheGZ4qG35DyGjA2dLeKfaSr534A']); var expectedPaths = [ 'm/2147483647/0/0',