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

get pool reserve data

This commit is contained in:
Matthias Kretschmann 2020-08-18 14:25:27 +02:00
parent f82e98863e
commit e01b1c4fee
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -2,12 +2,17 @@ import React, { ReactElement, useEffect, useState } from 'react'
import { useOcean, useMetadata } from '@oceanprotocol/react'
import { DDO } from '@oceanprotocol/lib'
interface Balance {
ocean: string
dt: string
}
export default function Trade({ ddo }: { ddo: DDO }): ReactElement {
const { ocean, accountId } = useOcean()
const { getBestPool } = useMetadata()
const [finalTokens, setFinalTokens] = useState()
const [currentTokens, setCurrentTokens] = useState<string[]>()
const [numTokens, setNumTokens] = useState()
const [balance, setBalance] = useState<Balance>()
const [sharesBalance, setSharesBalance] = useState()
useEffect(() => {
async function init() {
@ -17,17 +22,21 @@ export default function Trade({ ddo }: { ddo: DDO }): ReactElement {
const numTokens = await ocean.pool.getNumTokens(accountId, poolAddress)
setNumTokens(numTokens)
const currentTokens = await ocean.pool.getCurrentTokens(
const oceanReserve = await ocean.pool.getOceanReserve(
accountId,
poolAddress
)
setCurrentTokens(currentTokens)
const dtReserve = await ocean.pool.getDTReserve(accountId, poolAddress)
setBalance({
ocean: oceanReserve,
dt: dtReserve
})
const finalTokens = await ocean.pool.getFinalTokens(
const sharesBalance = await ocean.pool.sharesBalance(
accountId,
poolAddress
)
setFinalTokens(finalTokens)
setSharesBalance(sharesBalance)
} catch (error) {
console.error(error.message)
}
@ -37,9 +46,24 @@ export default function Trade({ ddo }: { ddo: DDO }): ReactElement {
return (
<>
<div>Num Tokens: {numTokens}</div>
<div>Current Tokens: {currentTokens}</div>
<div>Final Tokens: {finalTokens}</div>
<div>
Num Tokens: <br />
{numTokens}
</div>
<div>
Reserve: <br />
{balance && (
<>
OCEAN {balance.ocean}
<br />
DT {balance.dt}
</>
)}
</div>
<div>
Shares Balance: <br />
{sharesBalance}
</div>
</>
)
}