1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

correct pool shares

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2020-10-26 21:04:49 +02:00
parent 2b6759c3a2
commit 93d141f91f
No known key found for this signature in database
GPG Key ID: 4FB0C2329B4C6E29

View File

@ -158,13 +158,28 @@ export default function Add({
submitForm,
handleChange
}) => {
const newPoolTokens =
totalBalance &&
((values.amount / Number(totalBalance.ocean)) * 100).toFixed(2)
const newPoolShare =
totalBalance &&
((Number(newPoolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
const [newPoolTokens, setNewPoolTokens] = useState('0')
const [newPoolShare, setNewPoolShare] = useState('0')
useEffect(() => {
async function calculatePoolShares() {
if (!values.amount) return
if (Number(values.amount) > Number(amountMax)) return
const poolTokens = await ocean.pool.calcPoolOutGivenSingleIn(
poolAddress,
ocean.pool.oceanAddress,
values.amount.toString()
)
setNewPoolTokens(poolTokens)
setNewPoolShare(
totalBalance &&
(
(Number(poolTokens) / Number(totalPoolTokens)) *
100
).toFixed(2)
)
}
calculatePoolShares()
}, [values.amount])
return (
<>