Skip to content

Commit fd1b643

Browse files
committed
Fix IOU value passed to Amount.from_json()
1 parent ff86d53 commit fd1b643

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/js/ripple/orderbook.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -439,19 +439,22 @@ OrderBook.prototype.setFundedAmount = function(offer, fundedAmount) {
439439
return offer;
440440
}
441441

442-
var isOfferGetsExceeded = Amount.from_json(fundedAmount)
442+
var isOfferGetsExceeded = Amount.from_json(
443+
this._currencyGets.is_native()
444+
? fundedAmount
445+
: fundedAmount + OrderBook.IOU_SUFFIX
446+
)
443447
.compareTo(offer.TakerGets) > 0;
444448

445449
if (isOfferGetsExceeded) {
446-
offer.taker_gets_funded = offer.TakerGets;
450+
offer.taker_gets_funded = Amount.from_json(offer.TakerGets).to_text();
447451
} else {
448452
offer.taker_gets_funded = fundedAmount;
449453
}
450454

451-
var takerPaysValue = (typeof offer.TakerPays === 'object')
452-
? offer.TakerPays.value
453-
: offer.TakerPays;
454-
455+
var takerPaysValue = this._currencyPays.is_native()
456+
? offer.TakerPays
457+
: offer.TakerPays.value;
455458
var takerPays = Amount.from_json(takerPaysValue + OrderBook.IOU_SUFFIX);
456459
var takerGets = Amount.from_json(offerSum);
457460
var fundedPays = Amount.from_json(fundedAmount + OrderBook.IOU_SUFFIX);

test/orderbook-test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ describe('OrderBook', function() {
15941594
taker_gets_funded: '0.2',
15951595
taker_pays_funded: '99.72233516476456'
15961596
},
1597+
15971598
{ Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y',
15981599
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414',
15991600
BookNode: '0000000000000000',
@@ -1614,8 +1615,9 @@ describe('OrderBook', function() {
16141615
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
16151616
owner_funds: '0.950363009783092',
16161617
is_fully_funded: false,
1617-
taker_gets_funded: '0.9484660776278363',
1618+
taker_gets_funded: '0.5',
16181619
taker_pays_funded: '94.58325208561269' },
1620+
16191621
{ Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y',
16201622
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414',
16211623
BookNode: '0000000000000000',
@@ -1637,7 +1639,7 @@ describe('OrderBook', function() {
16371639
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
16381640
owner_funds: '0.950363009783092',
16391641
is_fully_funded: false,
1640-
taker_gets_funded: '0.9484660776278363',
1642+
taker_gets_funded: '0.5',
16411643
taker_pays_funded: '94.58325208561269'
16421644
}
16431645
]

0 commit comments

Comments
 (0)