mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Merge pull request #137 from oceanprotocol/feature/pool-data
refactor pool data flow
This commit is contained in:
commit
08276a284d
@ -2,6 +2,7 @@ import React, { ReactElement, ReactNode } from 'react'
|
|||||||
import { getNetworkName } from '../../utils/wallet'
|
import { getNetworkName } from '../../utils/wallet'
|
||||||
import { ReactComponent as External } from '../../images/external.svg'
|
import { ReactComponent as External } from '../../images/external.svg'
|
||||||
import styles from './EtherscanLink.module.css'
|
import styles from './EtherscanLink.module.css'
|
||||||
|
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||||
|
|
||||||
export default function EtherscanLink({
|
export default function EtherscanLink({
|
||||||
networkId,
|
networkId,
|
||||||
@ -12,10 +13,15 @@ export default function EtherscanLink({
|
|||||||
path: string
|
path: string
|
||||||
children: ReactNode
|
children: ReactNode
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
|
const { appConfig } = useSiteMetadata()
|
||||||
const url =
|
const url =
|
||||||
networkId === 1
|
networkId === 1
|
||||||
? `https://etherscan.io`
|
? `https://etherscan.io`
|
||||||
: `https://${getNetworkName(networkId).toLowerCase()}.etherscan.io`
|
: `https://${
|
||||||
|
networkId
|
||||||
|
? getNetworkName(networkId).toLowerCase()
|
||||||
|
: appConfig.network
|
||||||
|
}.etherscan.io`
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
|
@ -19,7 +19,7 @@ export default function Actions({
|
|||||||
actionName: string
|
actionName: string
|
||||||
action: () => void
|
action: () => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { networkId } = useOcean()
|
const { networkId, ocean } = useOcean()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -27,7 +27,12 @@ export default function Actions({
|
|||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<Loader message={loaderMessage} />
|
<Loader message={loaderMessage} />
|
||||||
) : (
|
) : (
|
||||||
<Button style="primary" size="small" onClick={() => action()}>
|
<Button
|
||||||
|
style="primary"
|
||||||
|
size="small"
|
||||||
|
onClick={() => action()}
|
||||||
|
disabled={!ocean}
|
||||||
|
>
|
||||||
{actionName}
|
{actionName}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
@ -207,6 +207,7 @@ export default function Add({
|
|||||||
!touched?.amount && setTouched({ amount: true })
|
!touched?.amount && setTouched({ amount: true })
|
||||||
handleChange(e)
|
handleChange(e)
|
||||||
}}
|
}}
|
||||||
|
disabled={!ocean}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
|
@ -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}`}
|
||||||
dt={`${userLiquidity.datatoken}`}
|
dt={`${userLiquidity?.datatoken}`}
|
||||||
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}
|
||||||
|
@ -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(
|
||||||
|
Loading…
Reference in New Issue
Block a user