1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 01:34:57 +01:00

tweak all pool calculations, display on Add screen

This commit is contained in:
Matthias Kretschmann 2020-08-26 09:37:28 +02:00
parent 5e61123669
commit 2a8f045efa
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 30 additions and 5 deletions

View File

@ -2,25 +2,43 @@ import React, { ReactElement, useState, ChangeEvent } from 'react'
import styles from './Add.module.css' import styles from './Add.module.css'
import stylesIndex from './index.module.css' import stylesIndex from './index.module.css'
import Button from '../../../atoms/Button' import Button from '../../../atoms/Button'
import Input from '../../../atoms/Input'
import { useOcean } from '@oceanprotocol/react' import { useOcean } from '@oceanprotocol/react'
import Header from './Header' import Header from './Header'
import Loader from '../../../atoms/Loader' import Loader from '../../../atoms/Loader'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import InputElement from '../../../atoms/Input/InputElement' import InputElement from '../../../atoms/Input/InputElement'
import Token from './Token'
import { Balance } from './'
function calculatePercent(percent: number, num: number) {
return (percent / 100) * num
}
export default function Add({ export default function Add({
setShowAdd, setShowAdd,
dtSymbol, dtSymbol,
poolAddress poolAddress,
totalPoolTokens,
totalBalance
}: { }: {
setShowAdd: (show: boolean) => void setShowAdd: (show: boolean) => void
dtSymbol: string dtSymbol: string
poolAddress: string poolAddress: string
totalPoolTokens: string
totalBalance: Balance
}): ReactElement { }): ReactElement {
const { ocean, accountId } = useOcean() const { ocean, accountId } = useOcean()
const [amount, setAmount] = useState<string>() const [amount, setAmount] = useState<string>()
const [isLoading, setIsLoading] = useState<boolean>() const [isLoading, setIsLoading] = useState<boolean>()
const [newDtAmount, setNewDtAmount] = useState<string>()
const newPoolTokens =
totalBalance &&
((Number(amount) / Number(totalBalance.ocean)) * 100).toFixed(2)
const newPoolShare =
totalBalance &&
((Number(newPoolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
async function handleAddLiquidity() { async function handleAddLiquidity() {
setIsLoading(true) setIsLoading(true)
@ -59,7 +77,12 @@ export default function Add({
/> />
</div> </div>
<p>You will receive:</p> <div>
<p>You will receive:</p>
<Token symbol={dtSymbol} balance={newDtAmount} />
<Token symbol="BPT" balance={newPoolTokens} />
<Token symbol="% of pool" balance={newPoolShare} />
</div>
<div className={stylesIndex.actions}> <div className={stylesIndex.actions}>
{isLoading ? ( {isLoading ? (

View File

@ -12,7 +12,7 @@ import Tooltip from '../../../atoms/Tooltip'
import Conversion from '../../../atoms/Price/Conversion' import Conversion from '../../../atoms/Price/Conversion'
import EtherscanLink from '../../../atoms/EtherscanLink' import EtherscanLink from '../../../atoms/EtherscanLink'
interface Balance { export interface Balance {
ocean: string ocean: string
dt: string dt: string
} }
@ -37,7 +37,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
const poolShare = const poolShare =
totalBalance && totalBalance &&
userBalance && userBalance &&
((Number(totalPoolTokens) * Number(poolTokens)) / 100).toFixed(2) ((Number(poolTokens) / Number(totalPoolTokens)) * 100).toFixed(2)
useEffect(() => { useEffect(() => {
if (!ocean || !accountId || !poolAddress || !price) return if (!ocean || !accountId || !poolAddress || !price) return
@ -98,6 +98,8 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
setShowAdd={setShowAdd} setShowAdd={setShowAdd}
dtSymbol={dtSymbol} dtSymbol={dtSymbol}
poolAddress={poolAddress} poolAddress={poolAddress}
totalPoolTokens={totalPoolTokens}
totalBalance={totalBalance}
/> />
) : showRemove ? ( ) : showRemove ? (
<Remove setShowRemove={setShowRemove} poolAddress={poolAddress} /> <Remove setShowRemove={setShowRemove} poolAddress={poolAddress} />