diff --git a/js/models/TxProposal.js b/js/models/TxProposal.js index 1c50459c9..7131bbe05 100644 --- a/js/models/TxProposal.js +++ b/js/models/TxProposal.js @@ -255,7 +255,9 @@ TxProposal.prototype.setSent = function(sentTxid) { this.sentTs = Date.now(); }; - +TxProposal.prototype.getSent = function(sentTxid) { + return !!this.sentTxid; +} TxProposal.prototype._allSignatures = function() { var ret = {}; diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 0f26b9e4f..54b87dde9 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -405,9 +405,11 @@ Wallet.prototype._onTxProposal = function(senderId, data) { if (tx.isComplete()) { this._checkSentTx(m.ntxid, function(ret) { if (ret) { - m.txp.setSent(m.ntxid); - self.emit('txProposalsUpdated'); - self.store(); + if (!m.txp.getSent()) { + m.txp.setSent(m.ntxid); + self.emit('txProposalsUpdated'); + self.store(); + } } }); } else { diff --git a/test/Wallet.js b/test/Wallet.js index 2155eca83..8fd2fa218 100644 --- a/test/Wallet.js +++ b/test/Wallet.js @@ -1564,6 +1564,7 @@ describe('Wallet model', function() { var txp = { getSeen: sinon.stub().returns(true), setCopayers: sinon.stub().returns(['new copayer']), + getSent: sinon.stub().returns(false), setSent: sinon.spy(), builder: { build: sinon.stub().returns({ @@ -1595,6 +1596,7 @@ describe('Wallet model', function() { var txp = { getSeen: sinon.stub().returns(true), setCopayers: sinon.stub().returns(['new copayer']), + getSent: sinon.stub().returns(false), setSent: sinon.spy(), builder: { build: sinon.stub().returns({ @@ -1618,6 +1620,38 @@ describe('Wallet model', function() { done(); }); + it('should not overwrite sent info', function(done) { + var data = { + txProposal: { + dummy: 1, + }, + }; + var txp = { + getSeen: sinon.stub().returns(true), + setCopayers: sinon.stub().returns(['new copayer']), + getSent: sinon.stub().returns(true), + setSent: sinon.spy(), + builder: { + build: sinon.stub().returns({ + isComplete: sinon.stub().returns(true), + }), + }, + }; + + w.txProposals.merge = sinon.stub().returns({ + ntxid: 1, + txp: txp, + new: false, + hasChanged: false, + }); + w._checkSentTx = sinon.stub().yields(true); + + w._onTxProposal('senderID', data); + txp.setSent.called.should.be.false; + w.sendTxProposal.called.should.be.false; + done(); + }); + it('should resend when not complete only if changed', function(done) { var data = { txProposal: {