diff --git a/lib/plugins.js b/lib/plugins.js index bab22d6c..501ea212 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -184,10 +184,32 @@ exports.trade = function trade(rawTrade, deviceFingerprint) { }; } - tradesQueue.push({ - currency: rawTrade.currency, - satoshis: rawTrade.satoshis - }); + // record (vel log) inserted bill + db.recordBill(deviceFingerprint, rawTrade); + + // cache partial Transaction (if supported by machine) + if (rawTrade.partialTx) { + var tx = { + txId: rawTrade.txId, + status: 'partial', + toAddress: rawTrade.toAddress, + currencyCode: rawTrade.currency, + satoshis: rawTrade.partialTx.satoshis, + fiat: rawTrade.partialTx.fiat + }; + db.summonTransaction(deviceFingerprint, tx, function(err, txInfo) { + logger.debug('plugins|cache|err', err); + logger.debug('plugins|cache|info', txInfo); + }); + } + + // add bill to trader queue (if trader is enabled) + if (traderPlugin) { + tradesQueue.push({ + currency: rawTrade.currency, + satoshis: rawTrade.satoshis + }); + } }; exports.fiatBalance = function fiatBalance() { @@ -222,7 +244,7 @@ exports.sendBitcoins = function sendBitcoins(deviceFingerprint, tx, callback) { db.summonTransaction(deviceFingerprint, tx, function(err, txInfo) { if (err) return callback(err); - if (!txInfo) { + if (!txInfo || txInfo.status === 'partial') { clearSession(deviceFingerprint); return walletPlugin.sendBitcoins(