Normalize token decimals before calculating exchange rate (#129)

This commit is contained in:
Chi Kei Chan 2018-11-12 11:29:26 +08:00 committed by GitHub
parent 02341f647b
commit f87aa671a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1809 additions and 3 deletions

@ -258,10 +258,10 @@ class AddLiquidity extends Component {
return;
}
const { value: tokenValue } = selectors().getBalance(fromToken[token], token);
const { value: tokenValue, decimals } = selectors().getBalance(fromToken[token], token);
const { value: ethValue } = selectors().getBalance(fromToken[token], eth);
return tokenValue.dividedBy(ethValue);
return tokenValue.multipliedBy(10 ** (18 - decimals)).dividedBy(ethValue);
}
validate() {
@ -368,7 +368,7 @@ class AddLiquidity extends Component {
<div className="pool__summary-panel">
<div className="pool__exchange-rate-wrapper">
<span className="pool__exchange-rate">Exchange Rate</span>
<span>{`1 ETH = ${tokenValue.dividedBy(ethValue).toFixed(4)} ${label}`}</span>
<span>{`1 ETH = ${tokenValue.multipliedBy(10 ** (18 - decimals)).dividedBy(ethValue).toFixed(4)} ${label}`}</span>
</div>
<div className="pool__exchange-rate-wrapper">
<span className="swap__exchange-rate">Current Pool Size</span>

1806
yarn.lock

File diff suppressed because it is too large Load Diff