Skip to content

Commit

Permalink
Merge pull request #244 from eoscostarica/fix/your-balance
Browse files Browse the repository at this point in the history
Show correct current supply value
  • Loading branch information
xavier506 authored Oct 31, 2020
2 parents 63f51cf + 0bea7b4 commit 83a81a2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/language/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"tableLabelCommunity": "Community Pools",
"inputLabel": "Add / Remove",
"available": "Current supply",
"balance": "Your balance",
"add": "Add",
"remove": "Remove",
"and": "and",
Expand Down
1 change: 1 addition & 0 deletions src/language/es/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"tableLabelCommunity": "Pooles comunitarios",
"inputLabel": "Aportar / Retirar",
"available": "Cantidad circulante",
"balance": "Tu Saldo",
"add": "Agregar",
"remove": "Retirar",
"and": "y",
Expand Down
1 change: 1 addition & 0 deletions src/language/ru/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"tableLabelCommunity": "Общественные пулы",
"inputLabel": "Добавить / Удалить",
"available": "Текущая поставка",
"balance": "баланс",
"add": "Добавить",
"remove": "Удалить",
"and": "и",
Expand Down
1 change: 1 addition & 0 deletions src/language/zh/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"tableLabelCommunity": "社区的流动性池",
"inputLabel": "添加 / 移除",
"available": "可用",
"balance": "平衡",
"add": "添加",
"remove": "移除",
"and": "",
Expand Down
39 changes: 27 additions & 12 deletions src/routes/Evodex/BackLayer/Liquidity/LiquidityBackLayer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'
import React, { useState, useEffect, useCallback } from 'react'
import PropTypes from 'prop-types'
import clsx from 'clsx'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -118,6 +118,7 @@ const useStyles = makeStyles((theme) => {
}
},
[theme.breakpoints.up('sm')]: {
paddingTop: theme.spacing(2),
flexDirection: 'row',
'& button': {
marginRight: theme.spacing(2),
Expand All @@ -128,11 +129,9 @@ const useStyles = makeStyles((theme) => {
inputBox: {
...inputBox,
[theme.breakpoints.up('md')]: {
width: 800
},
[theme.breakpoints.up('lg')]: {
marginTop: theme.spacing(0),
paddingBottom: theme.spacing(1)
width: 800,
paddingBottom: theme.spacing(0),
marginTop: theme.spacing(0)
}
},
contentWrapper: {
Expand Down Expand Up @@ -194,6 +193,7 @@ const LiquidityBackLayer = ({
const [isTourOpen, setIsTourOpen] = useState(false)
const [youGive, setYouGive] = useState({})
const [loading, setLoading] = useState(false)
const [currentSupplyValue, setCurrentSupplyValue] = useState('0')
const [error, setError] = useState('')
const validInput = RegExp('^([0-9]+([.][0-9]*)?|[.][0-9]+)$')

Expand Down Expand Up @@ -313,9 +313,19 @@ const LiquidityBackLayer = ({
setLoading(false)
}

const getCurrentSupply = useCallback(async () => {
const currentSupply = await evolutiondex.getCurrentSupply(
ual,
youGive.selectValue
)

setCurrentSupplyValue(currentSupply)
}, [ual, youGive.selectValue])

useEffect(() => {
getCurrentSupply()
setPair(pairs.find((pair) => pair.token === youGive.selectValue))
}, [pairs, youGive.selectValue])
}, [pairs, youGive.selectValue, getCurrentSupply])

useEffect(() => {
setError('')
Expand Down Expand Up @@ -371,11 +381,16 @@ const LiquidityBackLayer = ({
helperText={
<>
{pair && (
<Typography variant="body1" className={classes.textInfo}>
{`${t('available')} ${
pair.balance ? pair.balance.toString() : 0
}`}
</Typography>
<>
<Typography variant="body1" className={classes.textInfo}>
{`${t('balance')}: ${
pair.balance ? pair.balance.toString() : 0
}`}
</Typography>
<Typography variant="body1" className={classes.textInfo}>
{`${t('available')}: ${currentSupplyValue}`}
</Typography>
</>
)}
{error && (
<Typography variant="body1" className={classes.error}>
Expand Down
23 changes: 22 additions & 1 deletion src/utils/evolutiondex.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,26 @@ const voteFee = async (amount, pair, ual) => {
}
}

const getCurrentSupply = async (ual, pool) => {
if (!ual.activeUser || !pool) {
return
}

const rpc = getRpc(ual)

const { rows } = await rpc.get_table_rows({
json: true,
code: 'evolutiondex',
scope: pool,
table: 'stat',
limit: 1,
reverse: false,
show_payer: false
})

return rows.length ? rows[0].supply : `0 ${pool}`
}

export const evolutiondex = {
getInfo,
getTokensFor,
Expand All @@ -633,5 +653,6 @@ export const evolutiondex = {
addLiquidity,
getRemoveLiquidityAssets,
removeLiquidity,
voteFee
voteFee,
getCurrentSupply
}

0 comments on commit 83a81a2

Please sign in to comment.