Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
fix: rounding error
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Dec 27, 2018
1 parent d5a04b3 commit 7503867
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/components/swaptab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class SwapTab extends React.Component {
const rate = rates[pairId];

if (rate) {
return rate;
this.rate = rate;
return rate.rate.toFixed(5);
} else {
return 'Not found';
}
Expand All @@ -130,8 +131,6 @@ class SwapTab extends React.Component {
const { classes, rates, currencies } = this.props;
let { error, base, quote, baseAmount, quoteAmount } = this.state;

this.rate = this.getRate(rates, `${base}/${quote}`);

if (quoteAmount === 0) {
this.quoteAmount = this.calculateQuoteAmount(baseAmount);
quoteAmount = this.quoteAmount;
Expand All @@ -143,7 +142,10 @@ class SwapTab extends React.Component {
<InfoText title="Min amount:" text={`${MIN}`} />
<InfoText title="Max amount:" text={`${MAX}`} />
<InfoText title="Fee:" text={'0'} />
<InfoText title="Rate:" text={`${this.rate.rate}`} />
<InfoText
title="Rate:"
text={`${this.getRate(rates, `${base}/${quote}`)}`}
/>
</View>
<View className={classes.options}>
<View className={classes.select}>
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const getHexString = input => {
* @returns amount in satoshi
*/
export const toSatoshi = btc => {
return btc * 100000000;
return Math.ceil(btc * 100000000);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/views/landingpage/landingpageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getRates = pairs => {

// Set the rate for a buy order
rates[pair] = {
rate: rate.toFixed(5),
rate: rate,
pair: {
id: pair,
orderSide: 1,
Expand All @@ -30,7 +30,7 @@ const getRates = pairs => {
// And for a sell order
const { base, quote } = splitPairId(pair);
rates[`${quote}/${base}`] = {
rate: (1 / rate).toFixed(5),
rate: 1 / rate,
pair: {
id: pair,
orderSide: 0,
Expand Down

0 comments on commit 7503867

Please sign in to comment.