Skip to content

Commit

Permalink
Merge pull request #3494 from xiangxn/fix-3487
Browse files Browse the repository at this point in the history
Fix inaccurate floating point numbers used in credit offers #3487
  • Loading branch information
sschiessl-bcp authored Apr 16, 2022
2 parents 2a311c4 + 2a4504c commit 5ae711e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions app/components/Account/CreditOffer/CreditOfferPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,6 @@ class CreditOfferPage extends React.Component {
}
let {info, selectAsset} = this.state;
if (asset && info && selectAsset) {
let mortgageAsset = new Asset({
asset_id: selectAsset.get("id"),
real: amount,
precision: selectAsset.get("precision")
});
let index = info.acceptable_collateral.findIndex(
v => v[0] == selectAsset.get("id")
);
Expand All @@ -385,13 +380,17 @@ class CreditOfferPage extends React.Component {

let price = new Price({base: baseAsset, quote: quoteAsset});
// let currentAmount = price.toReal() * mortgageAsset.getAmount();
let mortgageAmount =
(1.0 / price.toReal()) * mortgageAsset.getAmount(); // Keeping it consistent with the App, this may violate Graphene's price representation convention.
let mortgageAmount = (1.0 / price.toReal()) * amount; // Keeping it consistent with the App, this may violate Graphene's price representation convention.
if (Number.isNaN(mortgageAmount)) {
mortgageAmount = 0;
} else {
mortgageAmount = Math.ceil(mortgageAmount);
}
let mortgageAsset = new Asset({
asset_id: selectAsset.get("id"),
real: mortgageAmount,
precision: selectAsset.get("precision")
});
let rateAsset = new Asset({
asset_id: asset.get("id"),
real: amount,
Expand All @@ -407,7 +406,7 @@ class CreditOfferPage extends React.Component {
amount,
error: null,
maxAmount: false,
mortgageAmount,
mortgageAmount: mortgageAsset.getAmount(),
rateAmount
},
this._checkBalance
Expand Down

0 comments on commit 5ae711e

Please sign in to comment.