Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inaccurate floating point numbers used in credit offers #3487 #3494

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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