lodash on loop

This commit is contained in:
Matias Alejo Garcia 2014-11-25 17:44:51 -03:00
commit 78933f8821
2 changed files with 25 additions and 25 deletions

View file

@ -598,7 +598,9 @@ Wallet.prototype._onReject = function(senderId, data) {
try { try {
var txp = this.txProposals.get(data.ntxid); var txp = this.txProposals.get(data.ntxid);
} catch (e) {}; } catch (e) {
log.info(e);
};
if (txp) { if (txp) {
if (txp.signedBy[senderId]) if (txp.signedBy[senderId])
@ -1401,22 +1403,20 @@ Wallet.prototype.generateAddress = function(isChange, cb) {
*/ */
Wallet.prototype.getTxProposals = function() { Wallet.prototype.getTxProposals = function() {
var ret = []; var ret = [];
var copayers = this.getRegisteredCopayerIds(); var self = this;
for (var ntxid in this.txProposals.txps) { var copayers = self.getRegisteredCopayerIds();
var txp = this.txProposals.getTxProposal(ntxid, copayers); var myId = self.getMyCopayerId();
txp.signedByUs = txp.signedBy[this.getMyCopayerId()] ? true : false; _.each(self.txProposals.txps, function(txp, ntxid){
txp.rejectedByUs = txp.rejectedBy[this.getMyCopayerId()] ? true : false; txp.signedByUs = txp.signedBy[myId] ? true : false;
txp.finallyRejected = this.totalCopayers - txp.rejectCount < this.requiredCopayers; txp.rejectedByUs = txp.rejectedBy[self.getMyCopayerId()] ? true : false;
txp.finallyRejected = self.totalCopayers - txp.rejectCount < self.requiredCopayers;
txp.isPending = !txp.finallyRejected && !txp.sentTxid; txp.isPending = !txp.finallyRejected && !txp.sentTxid;
// si no gastada
// y si no esta expirada;
if (!txp.readonly || txp.finallyRejected || txp.sentTs) { if (!txp.readonly || txp.finallyRejected || txp.sentTs) {
ret.push(txp); ret.push(txp);
} }
} });
return ret; return ret;
}; };

View file

@ -972,7 +972,7 @@ describe('Wallet model', function() {
done(); done();
}); });
}); });
it('should send Payment Messages on a PayPro payment', function(done) { it('should send Payment Messages on a PayPro payment', function(done) {
var w = createW2(null, 1); var w = createW2(null, 1);
@ -1895,13 +1895,13 @@ describe('Wallet model', function() {
describe('_onReject', function() { describe('_onReject', function() {
it('should fails if unknown tx', function() { it('should do nothing on unknown tx', function() {
var w = cachedCreateW(); var w = cachedCreateW();
(function() { var spy1 = sinon.spy(w, 'emitAndKeepAlive');
w._onReject(1, { w._onReject(1, {
ntxid: 1 ntxid: 1
}, 1); }, 1);
}).should.throw('Unknown TXP'); spy1.called.should.equal(false);
}); });
it('should fail to reject a signed tx', function() { it('should fail to reject a signed tx', function() {
var w = cachedCreateW(); var w = cachedCreateW();
@ -1949,13 +1949,13 @@ describe('Wallet model', function() {
describe('_onSeen', function() { describe('_onSeen', function() {
it('should fails if unknown tx', function() { it('should do nothing on unknown tx', function() {
var w = cachedCreateW(); var w = cachedCreateW();
(function() { var spy1 = sinon.spy(w, 'emitAndKeepAlive');
w._onReject(1, { w._onReject(1, {
ntxid: 1 ntxid: 1
}, 1); }, 1);
}).should.throw('Unknown TXP'); spy1.called.should.equal(false);
}); });
it('should set seen a tx', function() { it('should set seen a tx', function() {
var w = cachedCreateW(); var w = cachedCreateW();
@ -2458,7 +2458,7 @@ describe('Wallet model', function() {
describe.skip('#onPayProPaymentAck', function() { describe.skip('#onPayProPaymentAck', function() {
it('should emit', function() { it('should emit', function() {
var w = cachedCreateW2(); var w = cachedCreateW2();
sinon.stub(w,'emitAndKeepAlive'); sinon.stub(w, 'emitAndKeepAlive');
w.onPayProPaymentAck('id', 'data'); w.onPayProPaymentAck('id', 'data');
w.calledOnce.should.equal(true); w.calledOnce.should.equal(true);