Skip to content

Commit

Permalink
Fix IOU value passed to Amount.from_json()
Browse files Browse the repository at this point in the history
  • Loading branch information
wltsmrz committed Feb 9, 2015
1 parent ff86d53 commit fd1b643
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/js/ripple/orderbook.js
Expand Up @@ -439,19 +439,22 @@ OrderBook.prototype.setFundedAmount = function(offer, fundedAmount) {
return offer;
}

var isOfferGetsExceeded = Amount.from_json(fundedAmount)
var isOfferGetsExceeded = Amount.from_json(
this._currencyGets.is_native()
? fundedAmount
: fundedAmount + OrderBook.IOU_SUFFIX
)
.compareTo(offer.TakerGets) > 0;

if (isOfferGetsExceeded) {
offer.taker_gets_funded = offer.TakerGets;
offer.taker_gets_funded = Amount.from_json(offer.TakerGets).to_text();
} else {
offer.taker_gets_funded = fundedAmount;
}

var takerPaysValue = (typeof offer.TakerPays === 'object')
? offer.TakerPays.value
: offer.TakerPays;

var takerPaysValue = this._currencyPays.is_native()
? offer.TakerPays
: offer.TakerPays.value;
var takerPays = Amount.from_json(takerPaysValue + OrderBook.IOU_SUFFIX);
var takerGets = Amount.from_json(offerSum);
var fundedPays = Amount.from_json(fundedAmount + OrderBook.IOU_SUFFIX);
Expand Down
6 changes: 4 additions & 2 deletions test/orderbook-test.js
Expand Up @@ -1594,6 +1594,7 @@ describe('OrderBook', function() {
taker_gets_funded: '0.2',
taker_pays_funded: '99.72233516476456'
},

{ Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y',
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414',
BookNode: '0000000000000000',
Expand All @@ -1614,8 +1615,9 @@ describe('OrderBook', function() {
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
owner_funds: '0.950363009783092',
is_fully_funded: false,
taker_gets_funded: '0.9484660776278363',
taker_gets_funded: '0.5',
taker_pays_funded: '94.58325208561269' },

{ Account: 'rwBG69mujDoD5yQfL3Sf7Yuh7rUNYdxe9Y',
BookDirectory: '6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC985711B6D8C62EF414',
BookNode: '0000000000000000',
Expand All @@ -1637,7 +1639,7 @@ describe('OrderBook', function() {
index: 'A437D85DF80D250F79308F2B613CF5391C7CF8EE9099BC4E553942651CD9FA86',
owner_funds: '0.950363009783092',
is_fully_funded: false,
taker_gets_funded: '0.9484660776278363',
taker_gets_funded: '0.5',
taker_pays_funded: '94.58325208561269'
}
]
Expand Down

0 comments on commit fd1b643

Please sign in to comment.