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

refactor pool data flow

This commit is contained in:
Matthias Kretschmann 2020-10-26 18:13:12 +01:00
parent 8756a8e688
commit 99334f4d74
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 10 additions and 15 deletions

View File

@ -54,7 +54,6 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
const [showAdd, setShowAdd] = useState(false) const [showAdd, setShowAdd] = useState(false)
const [showRemove, setShowRemove] = useState(false) const [showRemove, setShowRemove] = useState(false)
const [isLoading, setIsLoading] = useState(true)
// TODO: put all these variables behind some useEffect // TODO: put all these variables behind some useEffect
// to prevent unneccessary updating on every render // to prevent unneccessary updating on every render
@ -76,8 +75,6 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
if (!ocean || !accountId || !price || !price.value) return if (!ocean || !accountId || !price || !price.value) return
async function init() { async function init() {
setIsLoading(true)
try { try {
// //
// Get everything which is in the pool // Get everything which is in the pool
@ -116,8 +113,6 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
setSwapFee(`${Number(swapFee) * 100}`) setSwapFee(`${Number(swapFee) * 100}`)
} catch (error) { } catch (error) {
Logger.error(error.message) Logger.error(error.message)
} finally {
setIsLoading(false)
} }
} }
init() init()
@ -125,9 +120,7 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
return ( return (
<> <>
{isLoading && !userLiquidity ? ( {showAdd ? (
<Loader message="Retrieving pools..." />
) : showAdd ? (
<Add <Add
setShowAdd={setShowAdd} setShowAdd={setShowAdd}
poolAddress={price.address} poolAddress={price.address}
@ -148,13 +141,13 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
<> <>
<div className={styles.dataToken}> <div className={styles.dataToken}>
<PriceUnit price="1" symbol={dtSymbol} /> ={' '} <PriceUnit price="1" symbol={dtSymbol} /> ={' '}
<PriceUnit price={`${price.value}`} /> <PriceUnit price={`${price?.value}`} />
<Conversion price={`${price.value}`} /> <Conversion price={`${price?.value}`} />
<Tooltip content={content.tooltips.price} /> <Tooltip content={content.tooltips.price} />
<div className={styles.dataTokenLinks}> <div className={styles.dataTokenLinks}>
<EtherscanLink <EtherscanLink
networkId={networkId} networkId={networkId}
path={`address/${price.address}`} path={`address/${price?.address}`}
> >
Pool Pool
</EtherscanLink> </EtherscanLink>
@ -174,8 +167,8 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
<Tooltip content={content.tooltips.liquidity} /> <Tooltip content={content.tooltips.liquidity} />
</> </>
} }
ocean={`${userLiquidity.ocean}`} ocean={`${userLiquidity?.ocean}` || '0'}
dt={`${userLiquidity.datatoken}`} dt={`${userLiquidity?.datatoken}` || '0'}
dtSymbol={dtSymbol} dtSymbol={dtSymbol}
poolShares={poolTokens} poolShares={poolTokens}
conversion={totalUserLiquidityInOcean} conversion={totalUserLiquidityInOcean}
@ -186,8 +179,8 @@ export default function Pool({ ddo }: { ddo: DDO }): ReactElement {
<TokenList <TokenList
title="Pool Statistics" title="Pool Statistics"
ocean={`${price.ocean}`} ocean={`${price?.ocean}`}
dt={`${price.datatoken}`} dt={`${price?.datatoken}`}
dtSymbol={dtSymbol} dtSymbol={dtSymbol}
poolShares={totalPoolTokens} poolShares={totalPoolTokens}
conversion={totalLiquidityInOcean} conversion={totalLiquidityInOcean}

View File

@ -6,6 +6,8 @@ export default async function checkPreviousOrder(
ddo: DDO, ddo: DDO,
serviceType: ServiceType serviceType: ServiceType
) { ) {
if (!ocean) return
const service = ddo.findServiceByType(serviceType) const service = ddo.findServiceByType(serviceType)
// apparenlty cost and timeout are not found, even though they are there... // apparenlty cost and timeout are not found, even though they are there...
const previousOrder = await ocean.datatokens.getPreviousValidOrders( const previousOrder = await ocean.datatokens.getPreviousValidOrders(