diff --git a/js/models/Wallet.js b/js/models/Wallet.js index d5bc8f149..075372c44 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -378,7 +378,7 @@ Wallet.prototype._onTxProposal = function(senderId, data) { if (tx.isComplete()) { this._checkSentTx(m.ntxid, function(ret) { if (ret) { - m.txp.setSent(m.mtxid); + m.txp.setSent(m.ntxid); self.emit('txProposalsUpdated'); self.store(); } @@ -2107,27 +2107,30 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) { cb = cb || function() {}; - var txps = _.where(this.getTxProposals(), { + if (!_.some(self.getTxProposals(), { isPending: true - }); - var inputs = _.flatten(_.map(txps, function(txp) { - return _.map(txp.builder.utxos, function(utxo) { - return { - ntxid: txp.ntxid, - txid: utxo.txid, - vout: utxo.vout, - }; - }); - })); - - if (inputs.length === 0) + })) return cb(); - var proposalsChanged = false; this.blockchain.getUnspent(this.getAddressesStr(), function(err, unspentList) { if (err) return cb(err); + var txps = _.where(self.getTxProposals(), { + isPending: true + }); + if (txps.length === 0) return cb(); + + var inputs = _.flatten(_.map(txps, function(txp) { + return _.map(txp.builder.utxos, function(utxo) { + return { + ntxid: txp.ntxid, + txid: utxo.txid, + vout: utxo.vout, + }; + }); + })); + _.each(unspentList, function(unspent) { _.each(inputs, function(input) { input.unspent = input.unspent || (input.txid === unspent.txid && input.vout === unspent.vout); diff --git a/test/models/Wallet.js b/test/models/Wallet.js index a3bd201c5..5c60dda16 100644 --- a/test/models/Wallet.js +++ b/test/models/Wallet.js @@ -1592,6 +1592,7 @@ describe('Wallet model', function() { w._onTxProposal('senderID', data); txp.setSent.called.should.be.false; + txp.setSent.calledWith(1).should.be.false; w.sendTxProposal.called.should.be.false; done(); });