Skip to content

Commit 0d7fc0a

Browse files
committedNov 26, 2014
Fix fractional drops in funded taker_pays setter
1 parent 74cacd5 commit 0d7fc0a

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed
 

‎src/js/ripple/orderbook.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ OrderBook.prototype.setFundedAmount = function(offer, fundedAmount) {
380380
return offer;
381381
}
382382

383-
var iouSuffix = '/' + this._currencyGets.to_json()
384-
+ '/' + this._issuerGets;
383+
var iouSuffix = '/' + this._currencyGets.to_json() + '/' + this._issuerGets;
385384

386385
offer.is_fully_funded = Amount.from_json(
387386
this._currencyGets.is_native() ? fundedAmount : fundedAmount + iouSuffix
@@ -420,11 +419,17 @@ OrderBook.prototype.setFundedAmount = function(offer, fundedAmount) {
420419
fundedPays = fundedPays.multiply(rate);
421420

422421
if (fundedPays.compareTo(takerPays) < 0) {
423-
offer.taker_pays_funded = fundedPays.to_json().value;
422+
if (this._currencyPays.is_native()) {
423+
fundedPays = String(parseInt(fundedPays.to_json().value, 10));
424+
} else {
425+
fundedPays = fundedPays.to_json().value;
426+
}
424427
} else {
425-
offer.taker_pays_funded = takerPays.to_json().value;
428+
fundedPays = takerPays.to_json().value;
426429
}
427430

431+
offer.taker_pays_funded = fundedPays;
432+
428433
return offer;
429434
};
430435

‎test/orderbook-test.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,12 @@ describe('OrderBook', function() {
329329
});
330330
});
331331

332-
it('Set funded amount - funded', function() {
332+
it('Set funded amount - iou/xrp - funded', function() {
333333
var remote = new Remote();
334334
var book = remote.createOrderBook({
335+
currency_gets: 'BTC',
335336
currency_pays: 'XRP',
336-
issuer_gets: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
337-
currency_gets: 'BTC'
337+
issuer_gets: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
338338
});
339339

340340
var offer = {
@@ -359,21 +359,21 @@ describe('OrderBook', function() {
359359
assert.deepEqual(offer, expected);
360360
});
361361

362-
it('Set funded amount - unfunded', function() {
362+
it('Set funded amount - iou/xrp - unfunded', function() {
363363
var remote = new Remote();
364364
var book = remote.createOrderBook({
365-
currency_gets: 'XRP',
366-
issuer_pays: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
367-
currency_pays: 'BTC'
365+
currency_gets: 'BTC',
366+
currency_pays: 'XRP',
367+
issuer_gets: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
368368
});
369369

370370
var offer = {
371-
TakerGets: '100',
372-
TakerPays: {
373-
value: '123456',
371+
TakerGets: {
372+
value: '100',
374373
currency: 'BTC',
375374
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
376-
}
375+
},
376+
TakerPays: '123456'
377377
};
378378

379379
book.setFundedAmount(offer, '99');
@@ -383,13 +383,13 @@ describe('OrderBook', function() {
383383
TakerPays: offer.TakerPays,
384384
is_fully_funded: false,
385385
taker_gets_funded: '99',
386-
taker_pays_funded: '122221.44'
386+
taker_pays_funded: '122221'
387387
};
388388

389389
assert.deepEqual(offer, expected);
390390
});
391391

392-
it('Set funded amount - native currency - funded', function() {
392+
it('Set funded amount - xrp/iou - funded', function() {
393393
var remote = new Remote();
394394
var book = remote.createOrderBook({
395395
currency_gets: 'XRP',
@@ -400,50 +400,50 @@ describe('OrderBook', function() {
400400
var offer = {
401401
TakerGets: '100',
402402
TakerPays: {
403-
value: '100.1234',
404-
currency: 'USD',
403+
value: '123.456',
404+
currency: 'BTC',
405405
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
406406
}
407407
};
408408

409-
book.setFundedAmount(offer, '100');
409+
book.setFundedAmount(offer, '100.1');
410410

411411
var expected = {
412412
TakerGets: offer.TakerGets,
413413
TakerPays: offer.TakerPays,
414414
is_fully_funded: true,
415415
taker_gets_funded: '100',
416-
taker_pays_funded: '100.1234'
416+
taker_pays_funded: '123.456'
417417
};
418418

419419
assert.deepEqual(offer, expected);
420420
});
421421

422-
it('Set funded amount - native currency - unfunded', function() {
422+
it('Set funded amount - xrp/iou - unfunded', function() {
423423
var remote = new Remote();
424424
var book = remote.createOrderBook({
425425
currency_gets: 'XRP',
426426
issuer_pays: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
427-
currency_pays: 'USD'
427+
currency_pays: 'BTC'
428428
});
429429

430430
var offer = {
431-
TakerGets: {
432-
value: '100.1234',
433-
currency: 'USD',
431+
TakerGets: '100',
432+
TakerPays: {
433+
value: '123.456',
434+
currency: 'BTC',
434435
issuer: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
435-
},
436-
TakerPays: '123'
436+
}
437437
};
438438

439-
book.setFundedAmount(offer, '100');
439+
book.setFundedAmount(offer, '99');
440440

441441
var expected = {
442442
TakerGets: offer.TakerGets,
443443
TakerPays: offer.TakerPays,
444444
is_fully_funded: false,
445-
taker_gets_funded: '100',
446-
taker_pays_funded: '122.8484050681459'
445+
taker_gets_funded: '99',
446+
taker_pays_funded: '122.22144'
447447
};
448448

449449
assert.deepEqual(offer, expected);

0 commit comments

Comments
 (0)
Please sign in to comment.