From 75a99d95821a87dc4827a757fc4f1d9ef44a4171 Mon Sep 17 00:00:00 2001 From: Adriel Diaz Date: Thu, 15 Oct 2020 12:13:20 -0600 Subject: [PATCH 1/6] fix: wrong value for asset input --- src/utils/evolutiondex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/evolutiondex.js b/src/utils/evolutiondex.js index fb7f679..c69943a 100644 --- a/src/utils/evolutiondex.js +++ b/src/utils/evolutiondex.js @@ -29,7 +29,7 @@ const amountToAsset = (amount = '0', currentAsset) => { } const chunks = amount.split('.') - const integer = chunks[0].substring(0, 10) + const integer = chunks[0] const decimal = chunks[1] || '0' const validAmount = parseFloat(`${integer}.${decimal}`).toFixed( currentAsset.symbol.precision() From 7cda7a6d5de556a07a043fde46f843c9a925155f Mon Sep 17 00:00:00 2001 From: Adriel Diaz Date: Thu, 15 Oct 2020 13:13:46 -0600 Subject: [PATCH 2/6] fix: error with magnitude of asset amount must be less than 2^62 --- src/language/en/en.json | 6 +- src/language/es/es.json | 6 +- src/language/ru/ru.json | 6 +- src/language/zh/zh.json | 3 +- .../BackLayer/Exchange/ExchangeBackLayer.js | 84 +++++++++++-------- .../BackLayer/Liquidity/LiquidityBackLayer.js | 63 +++++++++++--- 6 files changed, 118 insertions(+), 50 deletions(-) diff --git a/src/language/en/en.json b/src/language/en/en.json index a3e3229..a9c3865 100644 --- a/src/language/en/en.json +++ b/src/language/en/en.json @@ -76,7 +76,8 @@ "noAmountAdd": "Please enter the amount to add", "noAmountRemove": "Please enter the amount to remove", "successTransaction": "Transaction successful", - "help": "Help" + "help": "Help", + "errorNumberIsTooBig": "The number is too big" }, "fee": { "title": "Vote Your Fee", @@ -120,7 +121,8 @@ "pool": "Pool", "help": "Help", "valueOverWalletBalance": "Value is over your wallet balance", - "valueOverPoolBalance": "Value is over pool balance" + "valueOverPoolBalance": "Value is over pool balance", + "errorNumberIsTooBig": "The number is too big" }, "about": { "title": "About evodex" diff --git a/src/language/es/es.json b/src/language/es/es.json index 2aabdef..ff07819 100644 --- a/src/language/es/es.json +++ b/src/language/es/es.json @@ -77,7 +77,8 @@ "noAmountAdd": "Por favor ingrese el monto a enviar", "noAmountRemove": "Por favor ingrese el monto a retirar", "successTransaction": "Transacción realizada", - "help": "Ayuda" + "help": "Ayuda", + "errorNumberIsTooBig": "El numero ingresado es muy grande" }, "fee": { "title": "Votar Valor de la Comisión", @@ -121,7 +122,8 @@ "pool": "Pool", "help": "Ayuda", "valueOverWalletBalance": "El valor supera el balance de su billetera", - "valueOverPoolBalance": "El valor supera el balance del pool" + "valueOverPoolBalance": "El valor supera el balance del pool", + "errorNumberIsTooBig": "El numero ingresado es muy grande" }, "about": { "title": "Acerca de evodex" diff --git a/src/language/ru/ru.json b/src/language/ru/ru.json index dc1edf7..da541c4 100644 --- a/src/language/ru/ru.json +++ b/src/language/ru/ru.json @@ -76,7 +76,8 @@ "noAmountAdd": "Пожалуйста, введите сумму, которую нужно добавить", "noAmountRemove": "Введите сумму, которую нужно удалить", "successTransaction": "Транзакция успешна", - "help": "Помощь" + "help": "Помощь", + "errorNumberIsTooBig": "Номер слишком большой" }, "fee": { "title": "Проголосуйте за комиссию", @@ -118,7 +119,8 @@ "pool": "Пул", "help": "Помощь", "valueOverWalletBalance": "Ценность над балансом вашего кошелька", - "valueOverPoolBalance": "Ценность над балансом пула" + "valueOverPoolBalance": "Ценность над балансом пула", + "errorNumberIsTooBig": "Номер слишком большой" }, "about": { "title": "О evodex" diff --git a/src/language/zh/zh.json b/src/language/zh/zh.json index fcf3ff4..80490c1 100644 --- a/src/language/zh/zh.json +++ b/src/language/zh/zh.json @@ -76,7 +76,8 @@ "noAmountAdd": "请填写一个数量 添加", "noAmountRemove": "请填写一个数量 移除", "successTransaction": "交易成功", - "help": "帮帮我" + "help": "帮帮我", + "errorNumberIsTooBig": "这个数字太大" }, "fee": { "title": "费率投票", diff --git a/src/routes/Evodex/BackLayer/Exchange/ExchangeBackLayer.js b/src/routes/Evodex/BackLayer/Exchange/ExchangeBackLayer.js index 64ef18c..fd3145d 100644 --- a/src/routes/Evodex/BackLayer/Exchange/ExchangeBackLayer.js +++ b/src/routes/Evodex/BackLayer/Exchange/ExchangeBackLayer.js @@ -239,23 +239,37 @@ const ExchangeBackLayer = ({ onReload, ual, isLightMode, showMessage }) => { return } - const assets = getExchangeAssets(value.inputValue, pair) - setAssets(assets) - setInputsData((prevState) => { - const data = { - ...prevState[secondField], - inputValue: assets[assetTo].toString().split(' ')[0] - } - validate(data) - - return { - [mainField]: { - ...prevState[mainField], - ...value - }, - [secondField]: data - } - }) + try { + const assets = getExchangeAssets(value.inputValue, pair) + setAssets(assets) + setInputsData((prevState) => { + const data = { + ...prevState[secondField], + inputValue: assets[assetTo].toString().split(' ')[0] + } + validate(data) + + return { + [mainField]: { + ...prevState[mainField], + ...value + }, + [secondField]: data + } + }) + } catch (error) { + // TODO: improve error handler + console.log(error.message) + setInputsData((prevState) => ({ + ...prevState, + [mainField]: value, + [secondField]: { + ...prevState[secondField], + inputValue: '' + } + })) + setInputError((prev) => ({ ...prev, [mainField]: 'errorNumberIsTooBig' })) + } } const validateYouGive = (value) => { @@ -491,23 +505,27 @@ const ExchangeBackLayer = ({ onReload, ual, isLightMode, showMessage }) => { return } - const pool1 = - (await evolutiondex.getUserTokenBalance(ual, pair.pool1)) || - `0 ${pair.pool1.asset.symbol.code().toString()}` - const pool2 = - (await evolutiondex.getUserTokenBalance(ual, pair.pool2)) || - `0 ${pair.pool2.asset.symbol.code().toString()}` - balance = { - [pair.pool1.asset.symbol.code().toString()]: { - ...balance[pair.pool1.asset.symbol.code().toString()], - userAsset: pool1, - userAmount: parseFloat(pool1.split(' ')[0] || 0) - }, - [pair.pool2.asset.symbol.code().toString()]: { - ...balance[pair.pool2.asset.symbol.code().toString()], - userAsset: pool2, - userAmount: parseFloat(pool2.split(' ')[0] || 0) + try { + const pool1 = + (await evolutiondex.getUserTokenBalance(ual, pair.pool1)) || + `0 ${pair.pool1.asset.symbol.code().toString()}` + const pool2 = + (await evolutiondex.getUserTokenBalance(ual, pair.pool2)) || + `0 ${pair.pool2.asset.symbol.code().toString()}` + balance = { + [pair.pool1.asset.symbol.code().toString()]: { + ...balance[pair.pool1.asset.symbol.code().toString()], + userAsset: pool1, + userAmount: parseFloat(pool1.split(' ')[0] || 0) + }, + [pair.pool2.asset.symbol.code().toString()]: { + ...balance[pair.pool2.asset.symbol.code().toString()], + userAsset: pool2, + userAmount: parseFloat(pool2.split(' ')[0] || 0) + } } + } catch (error) { + console.log(error.message) } setBalance(balance) } diff --git a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js index 55568a3..d1cb66b 100644 --- a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js +++ b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js @@ -155,6 +155,23 @@ const useStyles = makeStyles((theme) => { noPadding: { padding: 0 }, + error: { + fontWeight: 500, + letterSpacing: '0.5px', + marginLeft: theme.spacing(1), + lineHeight: 1.73, + fontSize: 12, + minHeight: 20, + color: theme.palette.error.main + }, + textInfo: { + fontSize: 12, + fontWeight: 500, + letterSpacing: '0.5px', + marginLeft: theme.spacing(1), + lineHeight: 1.73, + color: '#fff' + }, helpText, message, rocketSvg @@ -177,6 +194,8 @@ const LiquidityBackLayer = ({ const [isTourOpen, setIsTourOpen] = useState(false) const [youGive, setYouGive] = useState({}) const [loading, setLoading] = useState(false) + const [error, setError] = useState('') + const validInput = RegExp('^([0-9]+([.][0-9]*)?|[.][0-9]+)$') const handleOnChange = (value) => { showMessage(null) @@ -306,8 +325,16 @@ const LiquidityBackLayer = ({ return } - setToBuy(evolutiondex.getAddLiquidityAssets(youGive.inputValue, pair)) - setToSell(evolutiondex.getRemoveLiquidityAssets(youGive.inputValue, pair)) + try { + setToBuy(evolutiondex.getAddLiquidityAssets(youGive.inputValue, pair)) + setToSell(evolutiondex.getRemoveLiquidityAssets(youGive.inputValue, pair)) + } catch (error) { + // TODO: improve error handler + console.log(error.message) + setToBuy(null) + setToSell(null) + setError('errorNumberIsTooBig') + } }, [pair, youGive.inputValue]) useEffect(() => { @@ -338,19 +365,35 @@ const LiquidityBackLayer = ({ id="liquidityYouGive" containerId="youGive" label={t('inputLabel')} + useHelperTextAsNode helperText={ - pair - ? `${t('available')}: ${ - pair.balance ? pair.balance.toString() : 0 - }` - : '' + <> + {pair && ( + + {`${t('available')} ${ + pair.balance ? pair.balance.toString() : 0 + }`} + + )} + {error && ( + + {t(error)} + + )} + } onChange={handleOnChange} value={youGive} - isValueAllowed={({ floatValue, value }) => { - if (value === '-' || floatValue < 0) return false + isValueAllowed={(value) => { + if (!value) { + return true + } + + if (!validInput.test(value)) { + return false + } - if (!floatValue) return true + const floatValue = parseFloat(value) return floatValue < LIQUIDITY_MAX_VALUE }} From 93cea3c7b522ebc8cdb229402504269b906c9a04 Mon Sep 17 00:00:00 2001 From: Adriel Diaz Date: Thu, 15 Oct 2020 13:24:56 -0600 Subject: [PATCH 3/6] fix: clear error on value change --- src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js index d1cb66b..065e084 100644 --- a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js +++ b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js @@ -325,6 +325,7 @@ const LiquidityBackLayer = ({ return } + setError('') try { setToBuy(evolutiondex.getAddLiquidityAssets(youGive.inputValue, pair)) setToSell(evolutiondex.getRemoveLiquidityAssets(youGive.inputValue, pair)) From 3462e8256f4b217b4efb0d0b7d64fb6620e33ceb Mon Sep 17 00:00:00 2001 From: Adriel Diaz Date: Thu, 15 Oct 2020 13:28:18 -0600 Subject: [PATCH 4/6] fix: clear error on value change --- src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js index 065e084..211beeb 100644 --- a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js +++ b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js @@ -318,6 +318,8 @@ const LiquidityBackLayer = ({ }, [pairs, youGive.selectValue]) useEffect(() => { + setError('') + if (!pair || !youGive.inputValue) { setToBuy(null) setToSell(null) @@ -325,7 +327,6 @@ const LiquidityBackLayer = ({ return } - setError('') try { setToBuy(evolutiondex.getAddLiquidityAssets(youGive.inputValue, pair)) setToSell(evolutiondex.getRemoveLiquidityAssets(youGive.inputValue, pair)) From 987bda739b472d56504cd7fd17d1c3d6068eb448 Mon Sep 17 00:00:00 2001 From: Adriel Diaz Date: Thu, 15 Oct 2020 13:46:43 -0600 Subject: [PATCH 5/6] chore: validate max decimal for liquidity form --- .../BackLayer/Liquidity/LiquidityBackLayer.js | 87 +++++++++++-------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js index 211beeb..6651140 100644 --- a/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js +++ b/src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js @@ -89,16 +89,13 @@ const useStyles = makeStyles((theme) => { rateFeeBox: { display: 'flex', justifyContent: 'space-between', - alignItems: 'center', + alignItems: 'start', '& p': { fontSize: 16.2, fontWeight: 500, letterSpacing: '0.5px', lineHeight: 1.73, color: '#fff' - }, - [theme.breakpoints.up('md')]: { - width: 500 } }, btnExchange: { @@ -172,6 +169,9 @@ const useStyles = makeStyles((theme) => { lineHeight: 1.73, color: '#fff' }, + rateFeeBoxFee: { + marginLeft: theme.spacing(2) + }, helpText, message, rocketSvg @@ -391,6 +391,15 @@ const LiquidityBackLayer = ({ return true } + const [, floatSection = ''] = value.split('.') + + if ( + pair && + floatSection.length > pair.supply.symbol.precision() + ) { + return false + } + if (!validInput.test(value)) { return false } @@ -401,40 +410,42 @@ const LiquidityBackLayer = ({ }} /> - {pair && ( - - - {`${t('add')}: `} - {toBuy && ( - - {`${toBuy.asset1.toString()} ${t( - 'and' - )} ${toBuy.asset2.toString()}`} - - )} - - - {`${t('fee')}:`} {Number(pair.fee) / 100}% - - - )} - {pair && ( - - - {`${t('remove')}: `} - {toSell && ( - - {`${toSell.asset1.toString()} ${t( - 'and' - )} ${toSell.asset2.toString()}`} - - )} - - - {`${t('fee')}:`} 0% - - - )} + + {pair && ( + + + {`${t('add')}: `} + {toBuy && ( + + {`${toBuy.asset1.toString()} ${t( + 'and' + )} ${toBuy.asset2.toString()}`} + + )} + + + {`${t('fee')}:`} {Number(pair.fee) / 100}% + + + )} + {pair && ( + + + {`${t('remove')}: `} + {toSell && ( + + {`${toSell.asset1.toString()} ${t( + 'and' + )} ${toSell.asset2.toString()}`} + + )} + + + {`${t('fee')}:`} 0% + + + )} + {loading && ( )} From f481b424d3ff95ef046609a070da2e1d01a0c75c Mon Sep 17 00:00:00 2001 From: Adriel Diaz Date: Thu, 15 Oct 2020 19:11:47 -0600 Subject: [PATCH 6/6] chore: validate max decimals for vote the fee --- src/components/InputTextAndSelect/InputTextAndSelect.js | 3 +++ src/routes/Evodex/BackLayer/Fee/FeeBackLayer.js | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/components/InputTextAndSelect/InputTextAndSelect.js b/src/components/InputTextAndSelect/InputTextAndSelect.js index ccfb4c1..f94e0f0 100644 --- a/src/components/InputTextAndSelect/InputTextAndSelect.js +++ b/src/components/InputTextAndSelect/InputTextAndSelect.js @@ -89,6 +89,9 @@ const useStyles = makeStyles((theme) => ({ lineHeight: 1.48, letterSpacing: '0.15px', color: '#ffffff', + '& ::before, & ::after': { + display: 'none' + }, '& input': { color: '#ffffff', '&::placeholder': { diff --git a/src/routes/Evodex/BackLayer/Fee/FeeBackLayer.js b/src/routes/Evodex/BackLayer/Fee/FeeBackLayer.js index d1a6180..897bd5c 100644 --- a/src/routes/Evodex/BackLayer/Fee/FeeBackLayer.js +++ b/src/routes/Evodex/BackLayer/Fee/FeeBackLayer.js @@ -261,6 +261,12 @@ const FeeBackLayer = ({ return false } + const [, floatSection = ''] = value.split('.') + + if (floatSection.length > 2) { + return false + } + const floatValue = parseFloat(value) if (floatValue < 0 || value === '00') return false