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

Merge branch 'v4' into feature/publish

This commit is contained in:
Matthias Kretschmann 2022-01-11 19:06:16 +00:00
commit d9b52e6da5
Signed by: m
GPG Key ID: 606EEEF3C479A91F
31 changed files with 398 additions and 449 deletions

12
package-lock.json generated
View File

@ -107,7 +107,7 @@
},
"../ocean.js": {
"name": "@oceanprotocol/lib",
"version": "1.0.0-next.0",
"version": "1.0.0-next.2",
"extraneous": true,
"license": "Apache-2.0",
"dependencies": {
@ -17096,6 +17096,11 @@
"node": ">=12"
}
},
"node_modules/js-sha256": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
"integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA=="
},
"node_modules/js-sha3": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
@ -43616,6 +43621,11 @@
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.1.tgz",
"integrity": "sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw=="
},
"js-sha256": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz",
"integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA=="
},
"js-sha3": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",

View File

@ -7,7 +7,7 @@ import React, {
useCallback,
ReactNode
} from 'react'
import { LoggerInstance } from '@oceanprotocol/lib'
import { LoggerInstance, Purgatory } from '@oceanprotocol/lib'
import getAssetPurgatoryData from '@utils/purgatory'
import { CancelToken } from 'axios'
import { retrieveDDO } from '@utils/aquarius'
@ -18,7 +18,7 @@ import { useCancelToken } from '@hooks/useCancelToken'
interface AssetProviderValue {
isInPurgatory: boolean
purgatoryData: PurgatoryData
purgatoryData: Purgatory
ddo: Asset
title: string
owner: string
@ -30,12 +30,6 @@ interface AssetProviderValue {
refreshDdo: (token?: CancelToken) => Promise<void>
}
// temp, just to get rid of the error
export interface PurgatoryData {
did: string
reason: string
}
const AssetContext = createContext({} as AssetProviderValue)
const refreshInterval = 10000 // 10 sec.
@ -51,7 +45,7 @@ function AssetProvider({
const { networkId } = useWeb3()
const [isInPurgatory, setIsInPurgatory] = useState(false)
const [purgatoryData, setPurgatoryData] = useState<PurgatoryData>()
const [purgatoryData, setPurgatoryData] = useState<Purgatory>()
const [ddo, setDDO] = useState<Asset>()
const [did, setDID] = useState<string>()
const [title, setTitle] = useState<string>()
@ -92,7 +86,7 @@ function AssetProvider({
try {
const result = await getAssetPurgatoryData(did)
const isInPurgatory = result?.did !== undefined
const isInPurgatory = result?.state === true
setIsInPurgatory(isInPurgatory)
isInPurgatory && setPurgatoryData(result)
} catch (error) {

View File

@ -261,9 +261,9 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement {
setNetworkDisplayName(networkDisplayName)
// Figure out if we're on a chain's testnet, or not
setIsTestnet(
networkData?.network !== 'mainnet' && networkData?.network !== 'moonriver'
)
// setIsTestnet(
// networkData?.network !== 'mainnet' && networkData.network !== 'moonriver'
// )
LoggerInstance.log(
`[web3] Network display name set to: ${networkDisplayName}`

View File

@ -7,7 +7,6 @@ export const networkDataGaiaX: EthereumListsChain = {
chainId: 2021000,
shortName: 'GAIA-X',
chain: 'GAIA-X',
network: 'testnet',
networkId: 2021000,
nativeCurrency: { name: 'Gaia-X', symbol: 'GX', decimals: 18 },
rpc: [configGaiaX.nodeUri],

View File

@ -1,4 +1,4 @@
import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute'
import { ComputeJob } from '@oceanprotocol/lib'
import { OrdersData_tokenOrders_datatokenId as OrdersDatatoken } from './apollo/OrdersData'
// declaring into global scope to be able to use this as

View File

@ -1,4 +1,4 @@
import { PurgatoryData as PurgatoryDataAsset } from '@oceanprotocol/lib'
import { Purgatory } from '@oceanprotocol/lib'
import { fetchData } from './fetch'
const purgatoryUrl = 'https://market-purgatory.oceanprotocol.com/api/'
@ -10,12 +10,12 @@ export interface PurgatoryDataAccount {
export default async function getAssetPurgatoryData(
did: string
): Promise<PurgatoryDataAsset> {
): Promise<Purgatory> {
const data = (await fetchData(
`${purgatoryUrl}asset?did=${did}`
)) as PurgatoryDataAsset[]
)) as Purgatory[]
return { did: data[0]?.did, reason: data[0]?.reason }
return { state: data[0]?.state, reason: data[0]?.reason }
}
export async function getAccountPurgatoryData(

View File

@ -1,7 +1,7 @@
import React, { ReactElement, ReactNode, useEffect, useState } from 'react'
import External from '@images/external.svg'
import classNames from 'classnames/bind'
import { ConfigHelperConfig } from '@oceanprotocol/lib'
import { Config } from '@oceanprotocol/lib'
import { useOcean } from '@context/Ocean'
import styles from './index.module.css'
import { getOceanConfig } from '@utils/ocean'
@ -19,9 +19,9 @@ export default function ExplorerLink({
children: ReactNode
className?: string
}): ReactElement {
const { config, ocean } = useOcean()
const { config } = useOcean()
const [url, setUrl] = useState<string>()
const [oceanConfig, setOceanConfig] = useState<ConfigHelperConfig>()
const [oceanConfig, setOceanConfig] = useState<Config>()
const styleClasses = cx({
link: true,
[className]: className
@ -38,7 +38,7 @@ export default function ExplorerLink({
if (oceanConfig === undefined) {
initOcean()
}
}, [config, oceanConfig, networkId, ocean])
}, [config, oceanConfig, networkId])
return (
<a

View File

@ -1,5 +1,4 @@
import React, { ReactElement, useCallback, useEffect, useState } from 'react'
import { useOcean } from '@context/Ocean'
import { useAsset } from '@context/Asset'
import { useWeb3 } from '@context/Web3'
import Decimal from 'decimal.js'
@ -20,7 +19,6 @@ export default function TokenApproval({
const { ddo, price, isAssetNetwork } = useAsset()
const [tokenApproved, setTokenApproved] = useState(false)
const [loading, setLoading] = useState(false)
const { ocean } = useOcean()
const { accountId } = useWeb3()
const config = getOceanConfig(ddo.chainId)
@ -32,21 +30,18 @@ export default function TokenApproval({
const spender = price.address
const checkTokenApproval = useCallback(async () => {
if (!ocean || !tokenAddress || !spender || !isAssetNetwork || !amount)
return
const allowance = await ocean.datatokens.allowance(
tokenAddress,
accountId,
spender
)
amount &&
new Decimal(amount).greaterThan(new Decimal('0')) &&
setTokenApproved(
new Decimal(allowance).greaterThanOrEqualTo(new Decimal(amount))
)
}, [ocean, tokenAddress, spender, accountId, amount, isAssetNetwork])
// if (!tokenAddress || !spender || !isAssetNetwork || !amount) return
// const allowance = await ocean.datatokens.allowance(
// tokenAddress,
// accountId,
// spender
// )
// amount &&
// new Decimal(amount).greaterThan(new Decimal('0')) &&
// setTokenApproved(
// new Decimal(allowance).greaterThanOrEqualTo(new Decimal(amount))
// )
}, [tokenAddress, spender, accountId, amount, isAssetNetwork])
useEffect(() => {
checkTokenApproval()
@ -56,7 +51,7 @@ export default function TokenApproval({
setLoading(true)
try {
await ocean.datatokens.approve(tokenAddress, spender, amount, accountId)
// await ocean.datatokens.approve(tokenAddress, spender, amount, accountId)
} catch (error) {
setLoading(false)
}

View File

@ -66,7 +66,6 @@ export default function FormStartCompute({
const [totalPrice, setTotalPrice] = useState(price?.value)
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false)
const { accountId, balance } = useWeb3()
const { ocean } = useOcean()
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
useState<number>()
@ -85,11 +84,11 @@ export default function FormStartCompute({
if (!accountId || !isConsumable) return
async function checkIsConsumable() {
const consumable = await ocean.assets.isConsumable(
algorithmDDO as any,
accountId.toLowerCase()
)
if (consumable) setAlgorithmConsumableStatus(consumable.status)
// const consumable = await ocean.assets.isConsumable(
// algorithmDDO as any,
// accountId.toLowerCase()
// )
// if (consumable) setAlgorithmConsumableStatus(consumable.status)
}
checkIsConsumable()
}, [values.algorithm, accountId, isConsumable])

View File

@ -1,5 +1,9 @@
import React, { useState, ReactElement, useEffect, useCallback } from 'react'
import { LoggerInstance } from '@oceanprotocol/lib'
import {
LoggerInstance,
ComputeAlgorithm,
ComputeOutput
} from '@oceanprotocol/lib'
import { toast } from 'react-toastify'
import Price from '@shared/Price'
import FileIcon from '@shared/FileIcon'
@ -17,10 +21,6 @@ import {
} from '@utils/aquarius'
import { Formik } from 'formik'
import { getInitialValues, validationSchema } from './_constants'
import {
ComputeAlgorithm,
ComputeOutput
} from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute'
import axios from 'axios'
import FormStartComputeDataset from './FormComputeDataset'
import styles from './index.module.css'
@ -55,7 +55,6 @@ export default function Compute({
}): ReactElement {
const { appConfig } = useSiteMetadata()
const { accountId } = useWeb3()
const { ocean } = useOcean()
const { buyDT, pricingError, pricingStepText } = usePricing()
const [isJobStarting, setIsJobStarting] = useState(false)
const [error, setError] = useState<string>()
@ -83,7 +82,6 @@ export default function Compute({
const isComputeButtonDisabled =
isJobStarting === true ||
file === null ||
!ocean ||
(!hasPreviousDatasetOrder && !hasDatatoken && !isConsumablePrice) ||
(!hasPreviousAlgorithmOrder &&
!hasAlgoAssetDatatoken &&
@ -111,12 +109,12 @@ export default function Compute({
}
async function checkAssetDTBalance(asset: DDO) {
const AssetDtBalance = await ocean.datatokens.balance(
asset.services[0].datatokenAddress,
accountId
)
setalgorithmDTBalance(AssetDtBalance)
setHasAlgoAssetDatatoken(Number(AssetDtBalance) >= 1)
// const AssetDtBalance = await ocean.datatokens.balance(
// asset.services[0].datatokenAddress,
// accountId
// )
// setalgorithmDTBalance(AssetDtBalance)
// setHasAlgoAssetDatatoken(Number(AssetDtBalance) >= 1)
}
function getQuerryString(
@ -204,9 +202,9 @@ export default function Compute({
}, [ddo])
useEffect(() => {
if (!ocean || !accountId) return
if (!accountId) return
checkPreviousOrders(ddo)
}, [ocean, ddo, accountId])
}, [ddo, accountId])
useEffect(() => {
if (!selectedAlgorithmAsset) return
@ -231,8 +229,8 @@ export default function Compute({
checkPreviousOrders(selectedAlgorithmAsset)
}
}
ocean && checkAssetDTBalance(selectedAlgorithmAsset)
}, [ddo, selectedAlgorithmAsset, ocean, accountId, hasPreviousAlgorithmOrder])
// ocean && checkAssetDTBalance(selectedAlgorithmAsset)
}, [ddo, selectedAlgorithmAsset, accountId, hasPreviousAlgorithmOrder])
// Output errors in toast UI
useEffect(() => {

View File

@ -4,7 +4,6 @@ import Button from '@shared/atoms/Button'
import styles from './Actions.module.css'
import ExplorerLink from '@shared/ExplorerLink'
import SuccessConfetti from '@shared/SuccessConfetti'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import TokenApproval from '@shared/TokenApproval'
@ -30,14 +29,13 @@ export default function Actions({
isDisabled?: boolean
}): ReactElement {
const { networkId } = useWeb3()
const { ocean } = useOcean()
const actionButton = (
<Button
style="primary"
size="small"
onClick={() => action()}
disabled={!ocean || isDisabled}
disabled={isDisabled}
>
{actionName}
</Button>
@ -53,7 +51,7 @@ export default function Actions({
actionButton={actionButton}
amount={amount}
coin={coin}
disabled={!ocean || isDisabled}
disabled={isDisabled}
/>
) : (
actionButton

View File

@ -11,7 +11,6 @@ import Button from '@shared/atoms/Button'
import CoinSelect from '../CoinSelect'
import { FormAddLiquidity } from '.'
import UserLiquidity from '../../UserLiquidity'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import { isValidNumber } from '@utils/numbers'
@ -43,8 +42,7 @@ export default function FormAdd({
setNewPoolTokens: (value: string) => void
setNewPoolShare: (value: string) => void
}): ReactElement {
const { balance } = useWeb3()
const { ocean } = useOcean()
const { balance, web3 } = useWeb3()
const { isAssetNetwork } = useAsset()
// Connect with form
@ -69,36 +67,31 @@ export default function FormAdd({
useEffect(() => {
async function calculatePoolShares() {
if (!ocean) return
const tokenInAddress =
coin === 'OCEAN' ? ocean.pool.oceanAddress : ocean.pool.dtAddress
if (!values.amount || !tokenInAddress) {
setNewPoolTokens('0')
setNewPoolShare('0')
return
}
if (Number(values.amount) > Number(amountMax)) return
const poolTokens = await ocean.pool.calcPoolOutGivenSingleIn(
poolAddress,
tokenInAddress,
`${values.amount}`
)
setNewPoolTokens(poolTokens)
const newPoolShareDecimal =
isValidNumber(poolTokens) && isValidNumber(totalPoolTokens)
? new Decimal(poolTokens)
.dividedBy(
new Decimal(totalPoolTokens).plus(new Decimal(poolTokens))
)
.mul(100)
.toString()
: '0'
totalBalance && setNewPoolShare(newPoolShareDecimal)
// if (!web3) return
// const tokenInAddress =
// coin === 'OCEAN' ? ocean.pool.oceanAddress : ocean.pool.dtAddress
// if (!values.amount || !tokenInAddress) {
// setNewPoolTokens('0')
// setNewPoolShare('0')
// return
// }
// if (Number(values.amount) > Number(amountMax)) return
// const poolTokens = await ocean.pool.calcPoolOutGivenSingleIn(
// poolAddress,
// tokenInAddress,
// `${values.amount}`
// )
// setNewPoolTokens(poolTokens)
// const newPoolShareDecimal =
// isValidNumber(poolTokens) && isValidNumber(totalPoolTokens)
// ? new Decimal(poolTokens)
// .dividedBy(
// new Decimal(totalPoolTokens).plus(new Decimal(poolTokens))
// )
// .mul(100)
// .toString()
// : '0'
// totalBalance && setNewPoolShare(newPoolShareDecimal)
}
calculatePoolShares()
}, [
@ -108,7 +101,6 @@ export default function FormAdd({
amountMax,
coin,
poolAddress,
ocean?.pool,
setNewPoolTokens,
setNewPoolShare
])
@ -144,14 +136,14 @@ export default function FormAdd({
<CoinSelect
dtSymbol={dtSymbol}
setCoin={setCoin}
disabled={!ocean || !isAssetNetwork}
disabled={!web3 || !isAssetNetwork}
/>
}
placeholder="0"
field={field}
form={form}
onChange={handleFieldChange}
disabled={!ocean || !isAssetNetwork}
disabled={!isAssetNetwork}
/>
)}
</Field>
@ -161,7 +153,7 @@ export default function FormAdd({
className={styles.buttonMax}
style="text"
size="small"
disabled={!ocean}
disabled={!web3}
onClick={() => {
setAmount(amountMax)
setFieldValue('amount', amountMax)

View File

@ -10,7 +10,6 @@ import Alert from '@shared/atoms/Alert'
import { useUserPreferences } from '@context/UserPreferences'
import Output from './Output'
import DebugOutput from '@shared/DebugOutput'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import { useAsset } from '@context/Asset'
import content from '../../../../../../content/price.json'
@ -43,7 +42,6 @@ export default function Add({
dtAddress: string
}): ReactElement {
const { accountId, balance } = useWeb3()
const { ocean } = useOcean()
const { isAssetNetwork } = useAsset()
const { debug } = useUserPreferences()
const [txId, setTxId] = useState<string>()
@ -69,53 +67,50 @@ export default function Add({
// Get datatoken balance when datatoken selected
useEffect(() => {
if (!ocean || !isAssetNetwork || coin === 'OCEAN') return
async function getDtBalance() {
const dtBalance = await ocean.datatokens.balance(dtAddress, accountId)
setDtBalance(dtBalance)
}
getDtBalance()
}, [ocean, accountId, dtAddress, coin])
// if (!accountId || !isAssetNetwork || coin === 'OCEAN') return
// async function getDtBalance() {
// const dtBalance = await ocean.datatokens.balance(dtAddress, accountId)
// setDtBalance(dtBalance)
// }
// getDtBalance()
}, [accountId, dtAddress, coin])
// Get maximum amount for either OCEAN or datatoken
useEffect(() => {
if (!ocean || !isAssetNetwork || !poolAddress) return
if (!accountId || !isAssetNetwork || !poolAddress) return
async function getMaximum() {
const amountMaxPool =
coin === 'OCEAN'
? await ocean.pool.getOceanMaxAddLiquidity(poolAddress)
: await ocean.pool.getDTMaxAddLiquidity(poolAddress)
const amountMax =
coin === 'OCEAN'
? Number(balance.ocean) > Number(amountMaxPool)
? amountMaxPool
: balance.ocean
: Number(dtBalance) > Number(amountMaxPool)
? amountMaxPool
: dtBalance
setAmountMax(Number(amountMax).toFixed(3))
// const amountMaxPool =
// coin === 'OCEAN'
// ? await ocean.pool.getOceanMaxAddLiquidity(poolAddress)
// : await ocean.pool.getDTMaxAddLiquidity(poolAddress)
// const amountMax =
// coin === 'OCEAN'
// ? Number(balance.ocean) > Number(amountMaxPool)
// ? amountMaxPool
// : balance.ocean
// : Number(dtBalance) > Number(amountMaxPool)
// ? amountMaxPool
// : dtBalance
// setAmountMax(Number(amountMax).toFixed(3))
}
getMaximum()
}, [ocean, poolAddress, coin, dtBalance, balance.ocean])
}, [accountId, isAssetNetwork, poolAddress, coin, dtBalance, balance.ocean])
// Submit
async function handleAddLiquidity(amount: number, resetForm: () => void) {
try {
const result =
coin === 'OCEAN'
? await ocean.pool.addOceanLiquidity(
accountId,
poolAddress,
`${amount}`
)
: await ocean.pool.addDTLiquidity(accountId, poolAddress, `${amount}`)
setTxId(result?.transactionHash)
resetForm()
refreshInfo()
// const result =
// coin === 'OCEAN'
// ? await ocean.pool.addOceanLiquidity(
// accountId,
// poolAddress,
// `${amount}`
// )
// : await ocean.pool.addDTLiquidity(accountId, poolAddress, `${amount}`)
// setTxId(result?.transactionHash)
// resetForm()
// refreshInfo()
} catch (error) {
console.error(error.message)
toast.error(error.message)

View File

@ -41,7 +41,6 @@ export default function Remove({
}): ReactElement {
const slippagePresets = ['5', '10', '15', '25', '50']
const { accountId } = useWeb3()
const { ocean } = useOcean()
const { isAssetNetwork } = useAsset()
const [amountPercent, setAmountPercent] = useState('0')
const [amountMaxPercent, setAmountMaxPercent] = useState('100')
@ -60,24 +59,23 @@ export default function Remove({
async function handleRemoveLiquidity() {
setIsLoading(true)
try {
const result =
isAdvanced === true
? await ocean.pool.removePoolLiquidity(
accountId,
poolAddress,
amountPoolShares,
minDatatokenAmount,
minOceanAmount
)
: await ocean.pool.removeOceanLiquidityWithMinimum(
accountId,
poolAddress,
amountPoolShares,
minOceanAmount
)
setTxId(result?.transactionHash)
refreshInfo()
// const result =
// isAdvanced === true
// ? await ocean.pool.removePoolLiquidity(
// accountId,
// poolAddress,
// amountPoolShares,
// minDatatokenAmount,
// minOceanAmount
// )
// : await ocean.pool.removeOceanLiquidityWithMinimum(
// accountId,
// poolAddress,
// amountPoolShares,
// minOceanAmount
// )
// setTxId(result?.transactionHash)
// refreshInfo()
} catch (error) {
LoggerInstance.error(error.message)
toast.error(error.message)
@ -88,45 +86,44 @@ export default function Remove({
// Get and set max percentage
useEffect(() => {
if (!ocean || !poolTokens) return
if (!accountId || !poolTokens) return
async function getMax() {
const amountMaxPercent =
isAdvanced === true
? '100'
: await getMaxPercentRemove(ocean, poolAddress, poolTokens)
setAmountMaxPercent(amountMaxPercent)
// const amountMaxPercent =
// isAdvanced === true
// ? '100'
// : await getMaxPercentRemove(poolAddress, poolTokens)
// setAmountMaxPercent(amountMaxPercent)
}
getMax()
}, [ocean, isAdvanced, poolAddress, poolTokens])
}, [accountId, isAdvanced, poolAddress, poolTokens])
const getValues = useRef(
debounce(async (newAmountPoolShares, isAdvanced) => {
if (isAdvanced === true) {
const tokens = await ocean.pool.getTokensRemovedforPoolShares(
poolAddress,
`${newAmountPoolShares}`
)
setAmountOcean(tokens?.oceanAmount)
setAmountDatatoken(tokens?.dtAmount)
return
}
const amountOcean = await ocean.pool.getOceanRemovedforPoolShares(
poolAddress,
newAmountPoolShares
)
setAmountOcean(amountOcean)
// if (isAdvanced === true) {
// const tokens = await ocean.pool.getTokensRemovedforPoolShares(
// poolAddress,
// `${newAmountPoolShares}`
// )
// setAmountOcean(tokens?.oceanAmount)
// setAmountDatatoken(tokens?.dtAmount)
// return
// }
// const amountOcean = await ocean.pool.getOceanRemovedforPoolShares(
// poolAddress,
// newAmountPoolShares
// )
// setAmountOcean(amountOcean)
}, 150)
)
// Check and set outputs when amountPoolShares changes
useEffect(() => {
if (!ocean || !poolTokens) return
if (!accountId || !poolTokens) return
getValues.current(amountPoolShares, isAdvanced)
}, [
amountPoolShares,
isAdvanced,
ocean,
accountId,
poolTokens,
poolAddress,
totalPoolTokens

View File

@ -1,36 +1,35 @@
import { Ocean } from '@oceanprotocol/lib'
import { isValidNumber } from '@utils/numbers'
import Decimal from 'decimal.js'
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
export async function getMaxPercentRemove(
ocean: Ocean,
poolAddress: string,
poolTokens: string
): Promise<string> {
const amountMaxOcean = await ocean.pool.getOceanMaxRemoveLiquidity(
poolAddress
)
// const amountMaxOcean = await ocean.pool.getOceanMaxRemoveLiquidity(
// poolAddress
// )
const amountMaxPoolShares =
await ocean.pool.getPoolSharesRequiredToRemoveOcean(
poolAddress,
amountMaxOcean
)
// const amountMaxPoolShares =
// await ocean.pool.getPoolSharesRequiredToRemoveOcean(
// poolAddress,
// amountMaxOcean
// )
let amountMaxPercent =
isValidNumber(amountMaxPoolShares) && isValidNumber(poolTokens)
? new Decimal(amountMaxPoolShares)
.dividedBy(new Decimal(poolTokens))
.mul(100)
.floor()
.toString()
: '0'
// let amountMaxPercent =
// isValidNumber(amountMaxPoolShares) && isValidNumber(poolTokens)
// ? new Decimal(amountMaxPoolShares)
// .dividedBy(new Decimal(poolTokens))
// .mul(100)
// .floor()
// .toString()
// : '0'
if (Number(amountMaxPercent) > 100) {
amountMaxPercent = '100'
}
// if (Number(amountMaxPercent) > 100) {
// amountMaxPercent = '100'
// }
return amountMaxPercent
// return amountMaxPercent
return '0'
}

View File

@ -9,7 +9,6 @@ import Swap from './Swap'
import Alert from '@shared/atoms/Alert'
import styles from './FormTrade.module.css'
import Decimal from 'decimal.js'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import { useAsset } from '@context/Asset'
import { FormTradeData } from './_types'
@ -30,7 +29,6 @@ export default function FormTrade({
price: BestPrice
}): ReactElement {
const { accountId } = useWeb3()
const { ocean } = useOcean()
const { isAssetNetwork } = useAsset()
const { debug } = useUserPreferences()
const [txId, setTxId] = useState<string>()
@ -69,27 +67,27 @@ export default function FormTrade({
new Decimal(100).sub(new Decimal(values.slippage))
).div(100)
const precision = 15
const tx =
values.type === 'buy'
? await ocean.pool.buyDTWithExactOcean(
accountId,
price.address,
new Decimal(values.datatoken)
.mul(impact)
.toFixed(precision)
.toString(),
new Decimal(values.ocean).toFixed(precision).toString()
)
: await ocean.pool.sellDT(
accountId,
price.address,
new Decimal(values.datatoken).toFixed(precision).toString(),
new Decimal(values.ocean)
.mul(impact)
.toFixed(precision)
.toString()
)
setTxId(tx?.transactionHash)
// const tx =
// values.type === 'buy'
// ? await ocean.pool.buyDTWithExactOcean(
// accountId,
// price.address,
// new Decimal(values.datatoken)
// .mul(impact)
// .toFixed(precision)
// .toString(),
// new Decimal(values.ocean).toFixed(precision).toString()
// )
// : await ocean.pool.sellDT(
// accountId,
// price.address,
// new Decimal(values.datatoken).toFixed(precision).toString(),
// new Decimal(values.ocean)
// .mul(impact)
// .toFixed(precision)
// .toString()
// )
// setTxId(tx?.transactionHash)
} catch (error) {
LoggerInstance.error(error.message)
toast.error(error.message)

View File

@ -1,7 +1,6 @@
import { FormikContextType, useFormikContext } from 'formik'
import React, { ReactElement, useEffect, useState } from 'react'
import { useAsset } from '@context/Asset'
import { useOcean } from '@context/Ocean'
import Token from '../Pool/Token'
import styles from './Output.module.css'
@ -21,7 +20,6 @@ export default function Output({
poolAddress: string
}): ReactElement {
const { isAssetNetwork } = useAsset()
const { ocean } = useOcean()
const [maxOutput, setMaxOutput] = useState<string>()
const [swapFee, setSwapFee] = useState<string>()
const [swapFeeValue, setSwapFeeValue] = useState<string>()
@ -30,15 +28,15 @@ export default function Output({
// Get swap fee
useEffect(() => {
if (!ocean || !poolAddress || !isAssetNetwork) return
if (!poolAddress || !isAssetNetwork) return
async function getSwapFee() {
const swapFee = await ocean.pool.getSwapFee(poolAddress)
// const swapFee = await ocean.pool.getSwapFee(poolAddress)
// swapFee is tricky: to get 0.1% you need to convert from 0.001
setSwapFee(
isValidNumber(swapFee) ? new Decimal(swapFee).mul(100).toString() : '0'
)
// // swapFee is tricky: to get 0.1% you need to convert from 0.001
// setSwapFee(
// isValidNumber(swapFee) ? new Decimal(swapFee).mul(100).toString() : '0'
// )
const value =
values.type === 'buy'
@ -51,11 +49,11 @@ export default function Output({
setSwapFeeValue(value.toString())
}
getSwapFee()
}, [ocean, poolAddress, values, isAssetNetwork])
}, [poolAddress, values, isAssetNetwork])
// Get output values
useEffect(() => {
if (!ocean || !poolAddress || !isAssetNetwork) return
if (!poolAddress || !isAssetNetwork) return
async function getOutput() {
// Minimum received
@ -75,7 +73,7 @@ export default function Output({
setMaxOutput(maxPrice)
}
getOutput()
}, [ocean, poolAddress, values, isAssetNetwork])
}, [poolAddress, values, isAssetNetwork])
return (
<div className={styles.output}>

View File

@ -4,7 +4,6 @@ import TradeInput from './TradeInput'
import Button from '@shared/atoms/Button'
import Arrow from '@images/arrow.svg'
import { FormikContextType, useFormikContext } from 'formik'
import { useOcean } from '@context/Ocean'
import Output from './Output'
import Slippage from './Slippage'
import PriceImpact from './PriceImpact'
@ -34,7 +33,6 @@ export default function Swap({
setMaximumOcean: (value: string) => void
setCoin: (value: string) => void
}): ReactElement {
const { ocean } = useOcean()
const { isAssetNetwork } = useAsset()
const [oceanItem, setOceanItem] = useState<TradeItem>({
amount: '0',
@ -72,47 +70,47 @@ export default function Swap({
? new Decimal(balance.ocean)
: new Decimal(maxOcean)
const maxBuyOcean = await ocean.pool.getOceanReceived(
price.address,
`${amountDataToken.toString()}`
)
const maxBuyDt = await ocean.pool.getDTReceived(
price.address,
`${amountOcean.toString()}`
)
// const maxBuyOcean = await ocean.pool.getOceanReceived(
// price.address,
// `${amountDataToken.toString()}`
// )
// const maxBuyDt = await ocean.pool.getDTReceived(
// price.address,
// `${amountOcean.toString()}`
// )
const maximumDt =
values.type === 'buy'
? amountDataToken.greaterThan(new Decimal(maxBuyDt))
? maxBuyDt
: amountDataToken
: amountDataToken.greaterThan(new Decimal(balance.datatoken))
? balance.datatoken
: amountDataToken
// const maximumDt =
// values.type === 'buy'
// ? amountDataToken.greaterThan(new Decimal(maxBuyDt))
// ? maxBuyDt
// : amountDataToken
// : amountDataToken.greaterThan(new Decimal(balance.datatoken))
// ? balance.datatoken
// : amountDataToken
const maximumOcean =
values.type === 'sell'
? amountOcean.greaterThan(new Decimal(maxBuyOcean))
? maxBuyOcean
: amountOcean
: amountOcean.greaterThan(new Decimal(balance.ocean))
? balance.ocean
: amountOcean
// const maximumOcean =
// values.type === 'sell'
// ? amountOcean.greaterThan(new Decimal(maxBuyOcean))
// ? maxBuyOcean
// : amountOcean
// : amountOcean.greaterThan(new Decimal(balance.ocean))
// ? balance.ocean
// : amountOcean
setMaximumDt(maximumDt.toString())
setMaximumOcean(maximumOcean.toString())
// setMaximumDt(maximumDt.toString())
// setMaximumOcean(maximumOcean.toString())
setOceanItem((prevState) => ({
...prevState,
amount: amountOcean.toString(),
maxAmount: maximumOcean.toString()
}))
// setOceanItem((prevState) => ({
// ...prevState,
// amount: amountOcean.toString(),
// maxAmount: maximumOcean.toString()
// }))
setDtItem((prevState) => ({
...prevState,
amount: amountDataToken.toString(),
maxAmount: maximumDt.toString()
}))
// setDtItem((prevState) => ({
// ...prevState,
// amount: amountDataToken.toString(),
// maxAmount: maximumDt.toString()
// }))
}
calculateMaximum()
}, [
@ -122,7 +120,6 @@ export default function Swap({
balance,
price,
values?.type,
ocean,
setMaximumDt,
setMaximumOcean
])
@ -137,63 +134,63 @@ export default function Swap({
}
const handleValueChange = async (name: string, value: number) => {
let tokenIn = ''
let tokenOut = ''
const tokenIn = ''
const tokenOut = ''
let newValue
if (name === 'ocean') {
if (values.type === 'sell') {
newValue = await ocean.pool.getDTNeeded(price.address, value.toString())
// if (name === 'ocean') {
// if (values.type === 'sell') {
// newValue = await ocean.pool.getDTNeeded(price.address, value.toString())
setTotalValue(newValue)
setTokenAmount(value.toString())
// setTotalValue(newValue)
// setTokenAmount(value.toString())
tokenIn = ddo.services[0].datatokenAddress
tokenOut = ocean.pool.oceanAddress
} else {
newValue = await ocean.pool.getDTReceived(
price.address,
value.toString()
)
// tokenIn = ddo.services[0].datatokenAddress
// tokenOut = ocean.pool.oceanAddress
// } else {
// newValue = await ocean.pool.getDTReceived(
// price.address,
// value.toString()
// )
setTotalValue(value.toString())
setTokenAmount(newValue)
tokenIn = ocean.pool.oceanAddress
tokenOut = ddo.services[0].datatokenAddress
}
} else {
if (values.type === 'sell') {
newValue = await ocean.pool.getOceanReceived(
price.address,
value.toString()
)
// setTotalValue(value.toString())
// setTokenAmount(newValue)
// tokenIn = ocean.pool.oceanAddress
// tokenOut = ddo.services[0].datatokenAddress
// }
// } else {
// if (values.type === 'sell') {
// newValue = await ocean.pool.getOceanReceived(
// price.address,
// value.toString()
// )
setTotalValue(value.toString())
setTokenAmount(newValue)
tokenIn = ddo.services[0].datatokenAddress
tokenOut = ocean.pool.oceanAddress
} else {
newValue = await ocean.pool.getOceanNeeded(
price.address,
value.toString()
)
// setTotalValue(value.toString())
// setTokenAmount(newValue)
// tokenIn = ddo.services[0].datatokenAddress
// tokenOut = ocean.pool.oceanAddress
// } else {
// newValue = await ocean.pool.getOceanNeeded(
// price.address,
// value.toString()
// )
setTotalValue(newValue)
setTokenAmount(value.toString())
tokenIn = ocean.pool.oceanAddress
tokenOut = ddo.services[0].datatokenAddress
}
}
// setTotalValue(newValue)
// setTokenAmount(value.toString())
// tokenIn = ocean.pool.oceanAddress
// tokenOut = ddo.services[0].datatokenAddress
// }
// }
await setFieldValue(name === 'ocean' ? 'datatoken' : 'ocean', newValue)
const spotPrice = await ocean.pool.getSpotPrice(
price.address,
tokenIn,
tokenOut
)
// const spotPrice = await ocean.pool.getSpotPrice(
// price.address,
// tokenIn,
// tokenOut
// )
setSpotPrice(spotPrice)
// setSpotPrice(spotPrice)
validateForm()
}

View File

@ -11,6 +11,7 @@ import Button from '@shared/atoms/Button'
import { useOcean } from '@context/Ocean'
import { FormTradeData, TradeItem } from './_types'
import UserLiquidity from '../UserLiquidity'
import { useWeb3 } from '@context/Web3'
export default function TradeInput({
name,
@ -23,7 +24,7 @@ export default function TradeInput({
disabled: boolean
handleValueChange: (name: string, value: number) => void
}): ReactElement {
const { ocean } = useOcean()
const { accountId } = useWeb3()
// Connect with form
const {
@ -64,7 +65,7 @@ export default function TradeInput({
validateForm()
handleChange(e)
}}
disabled={!ocean || disabled}
disabled={!accountId || disabled}
/>
)}
</Field>

View File

@ -1,7 +1,6 @@
import React, { ReactElement, useEffect, useState } from 'react'
import FormTrade from './FormTrade'
import { useAsset } from '@context/Asset'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import { isValidNumber } from '@utils/numbers'
@ -11,7 +10,6 @@ Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
export default function Trade(): ReactElement {
const { accountId, balance } = useWeb3()
const { ocean } = useOcean()
const { isAssetNetwork } = useAsset()
const [tokenBalance, setTokenBalance] = useState<PoolBalance>()
const { price, ddo } = useAsset()
@ -21,7 +19,7 @@ export default function Trade(): ReactElement {
// Get datatoken balance, and combine with OCEAN balance from hooks into one object
useEffect(() => {
if (
!ocean ||
!accountId ||
!isAssetNetwork ||
!balance?.ocean ||
!accountId ||
@ -30,45 +28,42 @@ export default function Trade(): ReactElement {
return
async function getTokenBalance() {
const dtBalance = await ocean.datatokens.balance(
ddo.services[0].datatokenAddress,
accountId
)
setTokenBalance({
ocean: new Decimal(balance.ocean).toString(),
datatoken: new Decimal(dtBalance).toString()
})
// const dtBalance = await ocean.datatokens.balance(
// ddo.services[0].datatokenAddress,
// accountId
// )
// setTokenBalance({
// ocean: new Decimal(balance.ocean).toString(),
// datatoken: new Decimal(dtBalance).toString()
// })
}
getTokenBalance()
}, [balance.ocean, ocean, accountId, ddo, isAssetNetwork])
}, [balance.ocean, accountId, ddo, isAssetNetwork])
// Get maximum amount for either OCEAN or datatoken
useEffect(() => {
if (!ocean || !isAssetNetwork || !price || price.value === 0) return
if (!isAssetNetwork || !price || price.value === 0) return
async function getMaximum() {
const maxTokensInPool = await ocean.pool.getDTMaxBuyQuantity(
price.address
)
setMaxDt(
isValidNumber(maxTokensInPool)
? new Decimal(maxTokensInPool).toString()
: '0'
)
const maxOceanInPool = await ocean.pool.getOceanMaxBuyQuantity(
price.address
)
setMaxOcean(
isValidNumber(maxOceanInPool)
? new Decimal(maxOceanInPool).toString()
: '0'
)
// const maxTokensInPool = await ocean.pool.getDTMaxBuyQuantity(
// price.address
// )
// setMaxDt(
// isValidNumber(maxTokensInPool)
// ? new Decimal(maxTokensInPool).toString()
// : '0'
// )
// const maxOceanInPool = await ocean.pool.getOceanMaxBuyQuantity(
// price.address
// )
// setMaxOcean(
// isValidNumber(maxOceanInPool)
// ? new Decimal(maxOceanInPool).toString()
// : '0'
// )
}
getMaximum()
}, [ocean, balance.ocean, price])
}, [isAssetNetwork, balance.ocean, price])
return (
<FormTrade

View File

@ -26,7 +26,6 @@ export default function AssetActions({
price: BestPrice
}): ReactElement {
const { accountId, balance } = useWeb3()
const { ocean, account } = useOcean()
const { isAssetNetwork } = useAsset()
const { values } = useFormikContext<FormPublishData>()
@ -87,25 +86,25 @@ export default function AssetActions({
// Get and set user DT balance
useEffect(() => {
if (!ocean || !accountId || !isAssetNetwork) return
if (!accountId || !isAssetNetwork) return
async function init() {
try {
const dtBalance = await ocean.datatokens.balance(
ddo.services[0].datatokenAddress,
accountId
)
setDtBalance(dtBalance)
// const dtBalance = await ocean.datatokens.balance(
// ddo.services[0].datatokenAddress,
// accountId
// )
// setDtBalance(dtBalance)
} catch (e) {
LoggerInstance.error(e.message)
}
}
init()
}, [ocean, accountId, ddo, isAssetNetwork])
}, [accountId, ddo, isAssetNetwork])
// Check user balance against price
useEffect(() => {
if (price?.type === 'free') setIsBalanceSufficient(true)
if (!price?.value || !account || !balance?.ocean || !dtBalance) return
if (!price?.value || !accountId || !balance?.ocean || !dtBalance) return
setIsBalanceSufficient(
compareAsBN(balance.ocean, `${price.value}`) || Number(dtBalance) >= 1
@ -114,7 +113,7 @@ export default function AssetActions({
return () => {
setIsBalanceSufficient(false)
}
}, [balance, account, price, dtBalance])
}, [balance, accountId, price, dtBalance])
const UseContent = isCompute ? (
<Compute

View File

@ -1,7 +1,6 @@
import { ServiceComputePrivacy } from '@oceanprotocol/lib'
import { ServiceComputeOptions } from '@oceanprotocol/lib'
import React, { ReactElement, useEffect, useState } from 'react'
import { useOcean } from '@context/Ocean'
import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
// import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
import DebugOutput from '@shared/DebugOutput'
export default function DebugEditCompute({
@ -11,22 +10,16 @@ export default function DebugEditCompute({
values: ComputePrivacyForm
ddo: Asset
}): ReactElement {
const { ocean } = useOcean()
const [formTransformed, setFormTransformed] =
useState<ServiceComputePrivacy>()
useState<ServiceComputeOptions>()
useEffect(() => {
if (!ocean) return
async function transformValues() {
const privacy = await transformComputeFormToServiceComputePrivacy(
values,
ocean
)
setFormTransformed(privacy)
}
transformValues()
}, [values, ddo, ocean])
// async function transformValues() {
// const privacy = await transformComputeFormToServiceComputePrivacy(values)
// setFormTransformed(privacy)
// }
// transformValues()
}, [values, ddo])
return (
<>

View File

@ -1,14 +1,13 @@
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import { Formik } from 'formik'
import React, { ReactElement, useState } from 'react'
import { useAsset } from '@context/Asset'
import FormEditComputeDataset from './FormEditComputeDataset'
import { LoggerInstance, ServiceComputePrivacy } from '@oceanprotocol/lib'
import { LoggerInstance, ServiceComputeOptions } from '@oceanprotocol/lib'
import { useUserPreferences } from '@context/UserPreferences'
import DebugEditCompute from './DebugEditCompute'
import styles from './index.module.css'
import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
// import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice'
import Web3Feedback from '@shared/Web3Feedback'
import { getInitialValues, validationSchema } from './_constants'
@ -20,7 +19,6 @@ export default function EditComputeDataset({
setShowEdit: (show: boolean) => void
}): ReactElement {
const { debug } = useUserPreferences()
const { ocean } = useOcean()
const { accountId } = useWeb3()
const { ddo, price, isAssetNetwork, refreshDdo } = useAsset()
const [success, setSuccess] = useState<string>()

View File

@ -1,8 +1,6 @@
import { FormikContextType, useFormikContext } from 'formik'
import React, { ReactElement } from 'react'
import { useAsset } from '@context/Asset'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import Button from '@shared/atoms/Button'
import styles from './FormActions.module.css'
@ -13,8 +11,6 @@ export default function FormActions({
setShowEdit: (show: boolean) => void
handleClick?: () => void
}): ReactElement {
const { accountId } = useWeb3()
const { ocean } = useOcean()
const { isAssetNetwork } = useAsset()
const { isValid }: FormikContextType<Partial<any>> = useFormikContext()
@ -22,7 +18,7 @@ export default function FormActions({
<footer className={styles.actions}>
<Button
style="primary"
disabled={!ocean || !accountId || !isValid || !isAssetNetwork}
disabled={!isValid || !isAssetNetwork}
onClick={handleClick}
>
Submit

View File

@ -11,7 +11,7 @@ import {
transformDDOToAssetSelection
} from '@utils/aquarius'
import { useAsset } from '@context/Asset'
import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanprotocol/lib'
import { PublisherTrustedAlgorithm } from '@oceanprotocol/lib'
import { useSiteMetadata } from '@hooks/useSiteMetadata'
import FormActions from './FormActions'
import { useCancelToken } from '@hooks/useCancelToken'

View File

@ -1,5 +1,5 @@
import { mapTimeoutStringToSeconds, secondsToString } from '@utils/ddo'
import { EditableMetadataLinks } from '@oceanprotocol/lib'
// import { EditableMetadataLinks } from '@oceanprotocol/lib'
import * as Yup from 'yup'
import { MetadataEditForm } from './_types'
@ -9,7 +9,7 @@ export const validationSchema = Yup.object().shape({
.required('Required'),
description: Yup.string().required('Required').min(10),
price: Yup.number().required('Required'),
links: Yup.array<EditableMetadataLinks[]>().nullable(),
links: Yup.array<any[]>().nullable(),
timeout: Yup.string().required('Required'),
author: Yup.string().nullable()
})

View File

@ -1,10 +1,10 @@
import { EditableMetadataLinks } from '@oceanprotocol/lib'
// import { EditableMetadataLinks } from '@oceanprotocol/lib'
export interface MetadataEditForm {
name: string
description: string
timeout: number
price?: number
links?: string | EditableMetadataLinks[]
links?: string | any[]
author?: string
}

View File

@ -10,7 +10,6 @@ import { getServiceByName, mapTimeoutStringToSeconds } from '@utils/ddo'
import styles from './index.module.css'
import { LoggerInstance } from '@oceanprotocol/lib'
import { useWeb3 } from '@context/Web3'
import { useOcean } from '@context/Ocean'
import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice'
import content from '../../../../content/pages/edit.json'
import { MetadataEditForm } from './_types'
@ -24,7 +23,6 @@ export default function Edit({
}): ReactElement {
const { debug } = useUserPreferences()
const { accountId } = useWeb3()
const { ocean } = useOcean()
const { ddo, refreshDdo, price } = useAsset()
const [success, setSuccess] = useState<string>()
const [error, setError] = useState<string>()
@ -34,15 +32,15 @@ export default function Edit({
const hasFeedback = error || success
async function updateFixedPrice(newPrice: number) {
const setPriceResp = await ocean.fixedRateExchange.setRate(
price.address,
newPrice,
accountId
)
if (!setPriceResp) {
setError(content.form.error)
LoggerInstance.error(content.form.error)
}
// const setPriceResp = await ocean.fixedRateExchange.setRate(
// price.address,
// newPrice,
// accountId
// )
// if (!setPriceResp) {
// setError(content.form.error)
// LoggerInstance.error(content.form.error)
// }
}
async function handleSubmit(

View File

@ -97,12 +97,12 @@ export default function Details({
/>
)}
<MetaItem title="Job ID" content={<code>{job.jobId}</code>} />
{job.resultsDid && (
{/* {job.resultsDid && (
<MetaItem
title="Published Results DID"
content={<code>{job.resultsDid}</code>}
/>
)}
)} */}
</div>
</Modal>
</>

View File

@ -3,37 +3,37 @@ import React, { ReactElement, useState } from 'react'
import Loader from '@shared/atoms/Loader'
import { ListItem } from '@shared/atoms/Lists'
import Button from '@shared/atoms/Button'
import { useOcean } from '@context/Ocean'
import styles from './Results.module.css'
import FormHelp from '@shared/FormInput/Help'
import content from '../../../../../content/pages/history.json'
import { useWeb3 } from '@context/Web3'
export default function Results({
job
}: {
job: ComputeJobMetaData
}): ReactElement {
const { ocean, account } = useOcean()
const { accountId } = useWeb3()
const [isLoading, setIsLoading] = useState(false)
const [hasFetched, setHasFetched] = useState(false)
const isFinished = job.dateFinished !== null
async function getResults() {
if (!account || !ocean || !job) return
if (!accountId || !job) return
try {
setIsLoading(true)
const jobStatus = await ocean.compute.status(
account,
job.did,
undefined,
undefined,
job.jobId
)
if (jobStatus?.length > 0) {
job.algorithmLogUrl = jobStatus[0].algorithmLogUrl
job.resultsUrl = jobStatus[0].resultsUrl
}
// const jobStatus = await ocean.compute.status(
// account,
// job.did,
// undefined,
// undefined,
// job.jobId
// )
// if (jobStatus?.length > 0) {
// job.algorithmLogUrl = jobStatus[0].algorithmLogUrl
// job.resultsUrl = jobStatus[0].resultsUrl
// }
} catch (error) {
LoggerInstance.error(error.message)
} finally {
@ -47,16 +47,16 @@ export default function Results({
{hasFetched ? (
<ul>
<ListItem>
{job.algorithmLogUrl ? (
{/* {job.algorithmLogUrl ? (
<a href={job.algorithmLogUrl} target="_blank" rel="noreferrer">
View Log
</a>
) : (
'No logs found.'
)}
)} */}
</ListItem>
{job.resultsUrl &&
{/* {job.resultsUrl &&
Array.isArray(job.resultsUrl) &&
job.resultsUrl.map((url, i) =>
url ? (
@ -68,7 +68,7 @@ export default function Results({
) : (
<ListItem>No results found.</ListItem>
)
)}
)} */}
</ul>
) : (
<Button

View File

@ -12,7 +12,7 @@ import Refresh from '@images/refresh.svg'
import { useUserPreferences } from '@context/UserPreferences'
import { getOceanConfig } from '@utils/ocean'
import NetworkName from '@shared/NetworkName'
import { getComputeJobs } from '@utils/compute'
// import { getComputeJobs } from '@utils/compute'
import styles from './index.module.css'
import { useAsset } from '@context/Asset'
import { useIsMounted } from '@hooks/useIsMounted'
@ -75,7 +75,7 @@ export default function ComputeJobs({
}: {
minimal?: boolean
}): ReactElement {
const { ocean, account, config, connect } = useOcean()
const { config } = useOcean()
const { accountId, networkId } = useWeb3()
const { ddo } = useAsset()
const [isLoading, setIsLoading] = useState(false)
@ -85,15 +85,15 @@ export default function ComputeJobs({
const columnsMinimal = [columns[4], columns[5], columns[3]]
useEffect(() => {
async function initOcean() {
const oceanInitialConfig = getOceanConfig(networkId)
await connect(oceanInitialConfig)
}
if (ocean === undefined) {
initOcean()
}
}, [networkId, ocean, connect])
// useEffect(() => {
// async function initOcean() {
// const oceanInitialConfig = getOceanConfig(networkId)
// await connect(oceanInitialConfig)
// }
// if (ocean === undefined) {
// initOcean()
// }
// }, [networkId])
const fetchJobs = useCallback(async () => {
if (!chainIds || chainIds.length === 0 || !accountId) {
@ -103,13 +103,13 @@ export default function ComputeJobs({
}
try {
setIsLoading(true)
const jobs = await getComputeJobs(chainIds, config, ocean, account, ddo)
isMounted() && setJobs(jobs.computeJobs)
setIsLoading(jobs.isLoaded)
// const jobs = await getComputeJobs(chainIds, config, ocean, account, ddo)
// isMounted() && setJobs(jobs.computeJobs)
// setIsLoading(jobs.isLoaded)
} catch (error) {
LoggerInstance.error(error.message)
}
}, [chainIds, accountId, config, ocean, account, ddo, isMounted])
}, [chainIds, accountId, config, ddo, isMounted])
useEffect(() => {
fetchJobs()