merged in latest from master

This commit is contained in:
Josh Harvey 2014-08-07 18:50:01 -04:00
commit 142dbe7f8b
6 changed files with 85 additions and 72 deletions

View file

@ -21,7 +21,12 @@ var Trader = module.exports = function (db) {
};
Trader.prototype._findExchange = function (name) {
return require('lamassu-' + name);
try {
return require('lamassu-' + name);
} catch(_) {
throw new Error(name + ' module is not installed. Try running `npm install --save lamassu-' + name + '` first');
}
};
Trader.prototype._findTicker = function (name) {
@ -98,7 +103,7 @@ Trader.prototype.configure = function (config) {
};
// IMPORTANT: This function returns the estimated minimum available balance
// in fiat as of the start of the current user session on the device. User
// in fiat as of the start of the current user session on the device. User
// session starts when a user presses then Start button and ends when we
// send the bitcoins.
Trader.prototype.fiatBalance = function (deviceFingerprint) {
@ -120,7 +125,7 @@ Trader.prototype.fiatBalance = function (deviceFingerprint) {
// `balance.transferBalance` is the balance of our transfer account (the one
// we use to send Bitcoins to clients) in satoshis.
var transferBalance = balance.transferBalance;
// Since `transferBalance` is in satoshis, we need to turn it into
// bitcoins and then fiat to learn how much fiat currency we can exchange.
//
@ -188,7 +193,7 @@ Trader.prototype.sendBitcoins = function (deviceFingerprint, tx, cb) {
if (txRec.status === 'insufficientFunds') txErr.name = 'InsufficientFunds';
}
// transaction exists, but txHash might be null,
// transaction exists, but txHash might be null,
// in which case ATM should continue polling
self.pollBalance();
cb(txErr, txRec.txHash);
@ -218,7 +223,7 @@ Trader.prototype.trade = function (rec, deviceFingerprint) {
delete self._sessionInfo[deviceFingerprint];
}, SESSION_TIMEOUT)
};
}
}
this._tradeQueue.push({fiat: rec.fiat, satoshis: rec.satoshis, currency: rec.currency});
};
@ -296,7 +301,7 @@ Trader.prototype._tradeForexMultiplier = function _tradeForexMultiplier() {
Trader.prototype._tradeBalanceFunc = function _tradeBalanceFunc(callback) {
if (!this.tradeExchange) return callback(null, null);
var forexMultiplier = this._tradeForexMultiplier();
if (!forexMultiplier) return callback(new Error('Can\'t compute balance, no tickers yet.'));
if (!forexMultiplier) return callback(new Error('Can\'t compute balance, no tickers yet.'));
this.tradeExchange.balance(function (err, localBalance) {
if (err) return callback(err);
callback(null, localBalance * forexMultiplier);