Commit 4b4df7ed authored by Kenny Tran's avatar Kenny Tran Committed by Chi Kei Chan

Don’t render numbers if decimals is 0 (#135)

parent 7608485f
...@@ -118,6 +118,10 @@ class AddLiquidity extends Component { ...@@ -118,6 +118,10 @@ class AddLiquidity extends Component {
} }
const { value, decimals } = selectors().getBalance(account, currency); const { value, decimals } = selectors().getBalance(account, currency);
if (!decimals) {
return '';
}
return `Balance: ${value.dividedBy(10 ** decimals).toFixed(4)}`; return `Balance: ${value.dividedBy(10 ** decimals).toFixed(4)}`;
} }
...@@ -339,7 +343,7 @@ class AddLiquidity extends Component { ...@@ -339,7 +343,7 @@ class AddLiquidity extends Component {
const ownedEth = ethPer.multipliedBy(liquidityBalance).dividedBy(10 ** 18); const ownedEth = ethPer.multipliedBy(liquidityBalance).dividedBy(10 ** 18);
const ownedToken = tokenPer.multipliedBy(liquidityBalance).dividedBy(10 ** decimals); const ownedToken = tokenPer.multipliedBy(liquidityBalance).dividedBy(10 ** decimals);
if (!label) { if (!label || !decimals) {
return blank; return blank;
} }
......
...@@ -151,6 +151,10 @@ class RemoveLiquidity extends Component { ...@@ -151,6 +151,10 @@ class RemoveLiquidity extends Component {
return ''; return '';
} }
const { value, decimals } = selectors().getBalance(account, exchangeAddress); const { value, decimals } = selectors().getBalance(account, exchangeAddress);
if (!decimals) {
return '';
}
return `Balance: ${value.dividedBy(10 ** decimals).toFixed(7)}`; return `Balance: ${value.dividedBy(10 ** decimals).toFixed(7)}`;
}; };
...@@ -244,42 +248,48 @@ class RemoveLiquidity extends Component { ...@@ -244,42 +248,48 @@ class RemoveLiquidity extends Component {
const { tokenAddress, totalSupply, value: input } = this.state; const { tokenAddress, totalSupply, value: input } = this.state;
const blank = [
<CurrencyInputPanel
key="remove-liquidity-input"
title="Output"
description="(estimated)"
renderInput={() => (
<div className="remove-liquidity__output"></div>
)}
disableTokenSelect
disableUnlock
/>,
<OversizedPanel key="remove-liquidity-input-under" hideBottom>
<div className="pool__summary-panel">
<div className="pool__exchange-rate-wrapper">
<span className="pool__exchange-rate">Exchange Rate</span>
<span> - </span>
</div>
<div className="pool__exchange-rate-wrapper">
<span className="swap__exchange-rate">Current Pool Size</span>
<span> - </span>
</div>
<div className="pool__exchange-rate-wrapper">
<span className="swap__exchange-rate">Your Pool Share</span>
<span> - </span>
</div>
</div>
</OversizedPanel>
];
const exchangeAddress = fromToken[tokenAddress]; const exchangeAddress = fromToken[tokenAddress];
if (!exchangeAddress || !web3) { if (!exchangeAddress || !web3) {
return [ return blank;
<CurrencyInputPanel
key="remove-liquidity-input"
title="Output"
description="(estimated)"
renderInput={() => (
<div className="remove-liquidity__output"></div>
)}
disableTokenSelect
disableUnlock
/>,
<OversizedPanel key="remove-liquidity-input-under" hideBottom>
<div className="pool__summary-panel">
<div className="pool__exchange-rate-wrapper">
<span className="pool__exchange-rate">Exchange Rate</span>
<span> - </span>
</div>
<div className="pool__exchange-rate-wrapper">
<span className="swap__exchange-rate">Current Pool Size</span>
<span> - </span>
</div>
<div className="pool__exchange-rate-wrapper">
<span className="swap__exchange-rate">Your Pool Share</span>
<span> - </span>
</div>
</div>
</OversizedPanel>
];
} }
const { value: liquidityBalance } = getBalance(account, exchangeAddress); const { value: liquidityBalance } = getBalance(account, exchangeAddress);
const { value: ethReserve } = getBalance(exchangeAddress); const { value: ethReserve } = getBalance(exchangeAddress);
const { value: tokenReserve, decimals: tokenDecimals, label } = getBalance(exchangeAddress, tokenAddress); const { value: tokenReserve, decimals: tokenDecimals, label } = getBalance(exchangeAddress, tokenAddress);
if (!tokenDecimals) {
return blank;
}
const ownership = liquidityBalance.dividedBy(totalSupply); const ownership = liquidityBalance.dividedBy(totalSupply);
const ethPer = ethReserve.dividedBy(totalSupply); const ethPer = ethReserve.dividedBy(totalSupply);
const tokenPer = tokenReserve.multipliedBy(10 ** (18 - tokenDecimals)).dividedBy(totalSupply); const tokenPer = tokenReserve.multipliedBy(10 ** (18 - tokenDecimals)).dividedBy(totalSupply);
......
...@@ -682,6 +682,14 @@ class Send extends Component { ...@@ -682,6 +682,14 @@ class Send extends Component {
); );
} }
renderBalance(currency, balance, decimals) {
if (!currency || decimals === 0) {
return '';
}
return `Balance: ${balance.dividedBy(BN(10 ** decimals)).toFixed(4)}`
}
render() { render() {
const { selectors, account } = this.props; const { selectors, account } = this.props;
const { const {
...@@ -716,10 +724,7 @@ class Send extends Component { ...@@ -716,10 +724,7 @@ class Send extends Component {
<CurrencyInputPanel <CurrencyInputPanel
title="Input" title="Input"
description={lastEditedField === OUTPUT ? estimatedText : ''} description={lastEditedField === OUTPUT ? estimatedText : ''}
extraText={inputCurrency extraText={this.renderBalance(inputCurrency, inputBalance, inputDecimals)}
? `Balance: ${inputBalance.dividedBy(BN(10 ** inputDecimals)).toFixed(4)}`
: ''
}
onCurrencySelected={inputCurrency => this.setState({ inputCurrency }, this.recalcForm)} onCurrencySelected={inputCurrency => this.setState({ inputCurrency }, this.recalcForm)}
onValueChange={this.updateInput} onValueChange={this.updateInput}
selectedTokens={[inputCurrency, outputCurrency]} selectedTokens={[inputCurrency, outputCurrency]}
...@@ -735,10 +740,7 @@ class Send extends Component { ...@@ -735,10 +740,7 @@ class Send extends Component {
<CurrencyInputPanel <CurrencyInputPanel
title="Output" title="Output"
description={lastEditedField === INPUT ? estimatedText : ''} description={lastEditedField === INPUT ? estimatedText : ''}
extraText={outputCurrency extraText={this.renderBalance(outputCurrency, outputBalance, outputDecimals)}
? `Balance: ${outputBalance.dividedBy(BN(10 ** outputDecimals)).toFixed(4)}`
: ''
}
onCurrencySelected={outputCurrency => this.setState({ outputCurrency }, this.recalcForm)} onCurrencySelected={outputCurrency => this.setState({ outputCurrency }, this.recalcForm)}
onValueChange={this.updateOutput} onValueChange={this.updateOutput}
selectedTokens={[inputCurrency, outputCurrency]} selectedTokens={[inputCurrency, outputCurrency]}
......
...@@ -662,6 +662,14 @@ class Swap extends Component { ...@@ -662,6 +662,14 @@ class Swap extends Component {
); );
} }
renderBalance(currency, balance, decimals) {
if (!currency || decimals === 0) {
return '';
}
return `Balance: ${balance.dividedBy(BN(10 ** decimals)).toFixed(4)}`
}
render() { render() {
const { selectors, account } = this.props; const { selectors, account } = this.props;
const { const {
...@@ -678,6 +686,8 @@ class Swap extends Component { ...@@ -678,6 +686,8 @@ class Swap extends Component {
const { inputError, outputError, isValid } = this.validate(); const { inputError, outputError, isValid } = this.validate();
return ( return (
<div className="swap"> <div className="swap">
<MediaQuery query="(max-device-width: 767px)"> <MediaQuery query="(max-device-width: 767px)">
...@@ -696,10 +706,7 @@ class Swap extends Component { ...@@ -696,10 +706,7 @@ class Swap extends Component {
<CurrencyInputPanel <CurrencyInputPanel
title="Input" title="Input"
description={lastEditedField === OUTPUT ? estimatedText : ''} description={lastEditedField === OUTPUT ? estimatedText : ''}
extraText={inputCurrency extraText={this.renderBalance(inputCurrency, inputBalance, inputDecimals)}
? `Balance: ${inputBalance.dividedBy(BN(10 ** inputDecimals)).toFixed(4)}`
: ''
}
onCurrencySelected={inputCurrency => this.setState({ inputCurrency }, this.recalcForm)} onCurrencySelected={inputCurrency => this.setState({ inputCurrency }, this.recalcForm)}
onValueChange={this.updateInput} onValueChange={this.updateInput}
selectedTokens={[inputCurrency, outputCurrency]} selectedTokens={[inputCurrency, outputCurrency]}
...@@ -715,10 +722,7 @@ class Swap extends Component { ...@@ -715,10 +722,7 @@ class Swap extends Component {
<CurrencyInputPanel <CurrencyInputPanel
title="Output" title="Output"
description={lastEditedField === INPUT ? estimatedText : ''} description={lastEditedField === INPUT ? estimatedText : ''}
extraText={outputCurrency extraText={this.renderBalance(outputCurrency, outputBalance, outputDecimals)}
? `Balance: ${outputBalance.dividedBy(BN(10 ** outputDecimals)).toFixed(4)}`
: ''
}
onCurrencySelected={outputCurrency => this.setState({ outputCurrency }, this.recalcForm)} onCurrencySelected={outputCurrency => this.setState({ outputCurrency }, this.recalcForm)}
onValueChange={this.updateOutput} onValueChange={this.updateOutput}
selectedTokens={[inputCurrency, outputCurrency]} selectedTokens={[inputCurrency, outputCurrency]}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment