|
|
@ -1060,26 +1060,33 @@ WalletService.prototype._getActiveAddresses = function(cb) { |
|
|
|
WalletService.prototype.getBalance2Steps = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
self._getActiveAddresses(function(err, activeAddresses) { |
|
|
|
self.storage.countAddresses(self.walletId, function(err, nbAddresses) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (_.isEmpty(activeAddresses)) { |
|
|
|
if (nbAddresses < Defaults.TWO_STEP_BALANCE_THRESHOLD) { |
|
|
|
return self.getBalance(opts, cb); |
|
|
|
} else { |
|
|
|
self._getBalanceFromAddresses(activeAddresses, function(err, partialBalance) { |
|
|
|
if (err) return cb(err); |
|
|
|
cb(null, partialBalance); |
|
|
|
setTimeout(function() { |
|
|
|
self.getBalance(opts, function(err, fullBalance) { |
|
|
|
if (err) return; |
|
|
|
if (!_.isEqual(partialBalance, fullBalance)) { |
|
|
|
log.debug('Cache miss: balance in active addresses differs from final balance'); |
|
|
|
self._notify('BalanceUpdated', fullBalance); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, 1); |
|
|
|
return; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
self._getActiveAddresses(function(err, activeAddresses) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (_.isEmpty(activeAddresses)) { |
|
|
|
return self.getBalance(opts, cb); |
|
|
|
} else { |
|
|
|
self._getBalanceFromAddresses(activeAddresses, function(err, partialBalance) { |
|
|
|
if (err) return cb(err); |
|
|
|
cb(null, partialBalance); |
|
|
|
setTimeout(function() { |
|
|
|
self.getBalance(opts, function(err, fullBalance) { |
|
|
|
if (err) return; |
|
|
|
if (!_.isEqual(partialBalance, fullBalance)) { |
|
|
|
log.debug('Cache miss: balance in active addresses differs from final balance'); |
|
|
|
self._notify('BalanceUpdated', fullBalance); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, 1); |
|
|
|
return; |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|