Skip to content

Commit

Permalink
Merge pull request #236 from eoscostarica/fix/you-give-calculation
Browse files Browse the repository at this point in the history
fix: wrong value for asset input
  • Loading branch information
xavier506 authored Oct 16, 2020
2 parents 3713ad6 + f481b42 commit 6bd74b2
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 89 deletions.
3 changes: 3 additions & 0 deletions src/components/InputTextAndSelect/InputTextAndSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ const useStyles = makeStyles((theme) => ({
lineHeight: 1.48,
letterSpacing: '0.15px',
color: '#ffffff',
'& ::before, & ::after': {
display: 'none'
},
'& input': {
color: '#ffffff',
'&::placeholder': {
Expand Down
6 changes: 4 additions & 2 deletions src/language/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/language/es/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions src/language/ru/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"noAmountAdd": "Пожалуйста, введите сумму, которую нужно добавить",
"noAmountRemove": "Введите сумму, которую нужно удалить",
"successTransaction": "Транзакция успешна",
"help": "Помощь"
"help": "Помощь",
"errorNumberIsTooBig": "Номер слишком большой"
},
"fee": {
"title": "Проголосуйте за комиссию",
Expand Down Expand Up @@ -118,7 +119,8 @@
"pool": "Пул",
"help": "Помощь",
"valueOverWalletBalance": "Ценность над балансом вашего кошелька",
"valueOverPoolBalance": "Ценность над балансом пула"
"valueOverPoolBalance": "Ценность над балансом пула",
"errorNumberIsTooBig": "Номер слишком большой"
},
"about": {
"title": "О evodex"
Expand Down
3 changes: 2 additions & 1 deletion src/language/zh/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
"noAmountAdd": "请填写一个数量 添加",
"noAmountRemove": "请填写一个数量 移除",
"successTransaction": "交易成功",
"help": "帮帮我"
"help": "帮帮我",
"errorNumberIsTooBig": "这个数字太大"
},
"fee": {
"title": "费率投票",
Expand Down
84 changes: 51 additions & 33 deletions src/routes/Evodex/BackLayer/Exchange/ExchangeBackLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions src/routes/Evodex/BackLayer/Fee/FeeBackLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6bd74b2

Please sign in to comment.