Skip to content

Commit

Permalink
fix various 0 decimal bugs (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahZinsmeister committed Jun 21, 2019
1 parent 0a92400 commit 668a1c8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
26 changes: 19 additions & 7 deletions src/pages/Pool/AddLiquidity.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export default function AddLiquidity() {
<>
<div>
{t('youAreAdding')} {b(`${amountFormatter(inputValueParsed, 18, 4)} ETH`)} {t('and')} {'at most'}{' '}
{b(`${amountFormatter(outputValueMax, decimals, 4)} ${symbol}`)} {t('intoPool')}
{b(`${amountFormatter(outputValueMax, decimals, Math.min(decimals, 4))} ${symbol}`)} {t('intoPool')}
</div>
<LastSummaryText>
{t('youWillMint')} {b(amountFormatter(liquidityMinted, 18, 4))} {t('liquidityTokens')}
Expand Down Expand Up @@ -355,9 +355,6 @@ export default function AddLiquidity() {

const addTransaction = useTransactionAdder()

const isActive = active && account
const isValid = inputError === null || outputError === null

async function onAddLiquidity() {
ReactGA.event({
category: 'Pool',
Expand Down Expand Up @@ -409,7 +406,13 @@ export default function AddLiquidity() {

// parse input value
useEffect(() => {
if (isNewExchange === false && inputValue && marketRate && lastEditedField === INPUT && decimals) {
if (
isNewExchange === false &&
inputValue &&
marketRate &&
lastEditedField === INPUT &&
(decimals || decimals === 0)
) {
try {
const parsedValue = ethers.utils.parseUnits(inputValue, 18)

Expand All @@ -427,7 +430,7 @@ export default function AddLiquidity() {
setOutputValueParsed(currencyAmount)
dispatchAddLiquidityState({
type: 'UPDATE_DEPENDENT_VALUE',
payload: { field: OUTPUT, value: amountFormatter(currencyAmount, decimals, 4, false) }
payload: { field: OUTPUT, value: amountFormatter(currencyAmount, decimals, Math.min(decimals, 4), false) }
})

return () => {
Expand All @@ -447,7 +450,13 @@ export default function AddLiquidity() {

// parse output value
useEffect(() => {
if (isNewExchange === false && outputValue && marketRateInverted && lastEditedField === OUTPUT && decimals) {
if (
isNewExchange === false &&
outputValue &&
marketRateInverted &&
lastEditedField === OUTPUT &&
(decimals || decimals === 0)
) {
try {
const parsedValue = ethers.utils.parseUnits(outputValue, decimals)

Expand Down Expand Up @@ -516,6 +525,9 @@ export default function AddLiquidity() {
}
}, [outputValueParsed, allowance, t])

const isActive = active && account
const isValid = (inputError === null || outputError === null) && !showUnlock

return (
<>
{isNewExchange ? (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Pool/RemoveLiquidity.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ export default function RemoveLiquidity() {
</ExchangeRateWrapper>
<ExchangeRateWrapper>
<ExchangeRate>{t('currentPoolSize')}</ExchangeRate>
{exchangeETHBalance && exchangeTokenBalance && decimals ? (
{exchangeETHBalance && exchangeTokenBalance && (decimals || decimals === 0) ? (
<span>{`${amountFormatter(exchangeETHBalance, 18, 4)} ETH + ${amountFormatter(
exchangeTokenBalance,
decimals,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default function Swap({ initialCurrency }) {

// declare/get parsed and formatted versions of input/output values
const [independentValueParsed, setIndependentValueParsed] = useState()
const dependentValueFormatted = !!(dependentValue && dependentDecimals)
const dependentValueFormatted = !!(dependentValue && (dependentDecimals || dependentDecimals === 0))
? amountFormatter(dependentValue, dependentDecimals, Math.min(4, dependentDecimals), false)
: ''
const inputValueParsed = independentField === INPUT ? independentValueParsed : dependentValue
Expand All @@ -305,7 +305,7 @@ export default function Swap({ initialCurrency }) {
// validate + parse independent value
const [independentError, setIndependentError] = useState()
useEffect(() => {
if (independentValue && independentDecimals) {
if (independentValue && (independentDecimals || independentDecimals === 0)) {
try {
const parsedValue = ethers.utils.parseUnits(independentValue, independentDecimals)

Expand Down

0 comments on commit 668a1c8

Please sign in to comment.