Commit 668a1c80 authored by Noah Zinsmeister's avatar Noah Zinsmeister Committed by GitHub

fix various 0 decimal bugs (#342)

parent 0a924003
......@@ -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')}
......@@ -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',
......@@ -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)
......@@ -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 () => {
......@@ -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)
......@@ -516,6 +525,9 @@ export default function AddLiquidity() {
}
}, [outputValueParsed, allowance, t])
const isActive = active && account
const isValid = (inputError === null || outputError === null) && !showUnlock
return (
<>
{isNewExchange ? (
......
......@@ -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,
......
......@@ -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
......@@ -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)
......
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