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:
commit
d9b52e6da5
12
package-lock.json
generated
12
package-lock.json
generated
@ -107,7 +107,7 @@
|
|||||||
},
|
},
|
||||||
"../ocean.js": {
|
"../ocean.js": {
|
||||||
"name": "@oceanprotocol/lib",
|
"name": "@oceanprotocol/lib",
|
||||||
"version": "1.0.0-next.0",
|
"version": "1.0.0-next.2",
|
||||||
"extraneous": true,
|
"extraneous": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -17096,6 +17096,11 @@
|
|||||||
"node": ">=12"
|
"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": {
|
"node_modules/js-sha3": {
|
||||||
"version": "0.8.0",
|
"version": "0.8.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.1.tgz",
|
||||||
"integrity": "sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw=="
|
"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": {
|
"js-sha3": {
|
||||||
"version": "0.8.0",
|
"version": "0.8.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
|
||||||
|
@ -7,7 +7,7 @@ import React, {
|
|||||||
useCallback,
|
useCallback,
|
||||||
ReactNode
|
ReactNode
|
||||||
} from 'react'
|
} from 'react'
|
||||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
import { LoggerInstance, Purgatory } from '@oceanprotocol/lib'
|
||||||
import getAssetPurgatoryData from '@utils/purgatory'
|
import getAssetPurgatoryData from '@utils/purgatory'
|
||||||
import { CancelToken } from 'axios'
|
import { CancelToken } from 'axios'
|
||||||
import { retrieveDDO } from '@utils/aquarius'
|
import { retrieveDDO } from '@utils/aquarius'
|
||||||
@ -18,7 +18,7 @@ import { useCancelToken } from '@hooks/useCancelToken'
|
|||||||
|
|
||||||
interface AssetProviderValue {
|
interface AssetProviderValue {
|
||||||
isInPurgatory: boolean
|
isInPurgatory: boolean
|
||||||
purgatoryData: PurgatoryData
|
purgatoryData: Purgatory
|
||||||
ddo: Asset
|
ddo: Asset
|
||||||
title: string
|
title: string
|
||||||
owner: string
|
owner: string
|
||||||
@ -30,12 +30,6 @@ interface AssetProviderValue {
|
|||||||
refreshDdo: (token?: CancelToken) => Promise<void>
|
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 AssetContext = createContext({} as AssetProviderValue)
|
||||||
|
|
||||||
const refreshInterval = 10000 // 10 sec.
|
const refreshInterval = 10000 // 10 sec.
|
||||||
@ -51,7 +45,7 @@ function AssetProvider({
|
|||||||
|
|
||||||
const { networkId } = useWeb3()
|
const { networkId } = useWeb3()
|
||||||
const [isInPurgatory, setIsInPurgatory] = useState(false)
|
const [isInPurgatory, setIsInPurgatory] = useState(false)
|
||||||
const [purgatoryData, setPurgatoryData] = useState<PurgatoryData>()
|
const [purgatoryData, setPurgatoryData] = useState<Purgatory>()
|
||||||
const [ddo, setDDO] = useState<Asset>()
|
const [ddo, setDDO] = useState<Asset>()
|
||||||
const [did, setDID] = useState<string>()
|
const [did, setDID] = useState<string>()
|
||||||
const [title, setTitle] = useState<string>()
|
const [title, setTitle] = useState<string>()
|
||||||
@ -92,7 +86,7 @@ function AssetProvider({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await getAssetPurgatoryData(did)
|
const result = await getAssetPurgatoryData(did)
|
||||||
const isInPurgatory = result?.did !== undefined
|
const isInPurgatory = result?.state === true
|
||||||
setIsInPurgatory(isInPurgatory)
|
setIsInPurgatory(isInPurgatory)
|
||||||
isInPurgatory && setPurgatoryData(result)
|
isInPurgatory && setPurgatoryData(result)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -261,9 +261,9 @@ function Web3Provider({ children }: { children: ReactNode }): ReactElement {
|
|||||||
setNetworkDisplayName(networkDisplayName)
|
setNetworkDisplayName(networkDisplayName)
|
||||||
|
|
||||||
// Figure out if we're on a chain's testnet, or not
|
// Figure out if we're on a chain's testnet, or not
|
||||||
setIsTestnet(
|
// setIsTestnet(
|
||||||
networkData?.network !== 'mainnet' && networkData?.network !== 'moonriver'
|
// networkData?.network !== 'mainnet' && networkData.network !== 'moonriver'
|
||||||
)
|
// )
|
||||||
|
|
||||||
LoggerInstance.log(
|
LoggerInstance.log(
|
||||||
`[web3] Network display name set to: ${networkDisplayName}`
|
`[web3] Network display name set to: ${networkDisplayName}`
|
||||||
|
@ -7,7 +7,6 @@ export const networkDataGaiaX: EthereumListsChain = {
|
|||||||
chainId: 2021000,
|
chainId: 2021000,
|
||||||
shortName: 'GAIA-X',
|
shortName: 'GAIA-X',
|
||||||
chain: 'GAIA-X',
|
chain: 'GAIA-X',
|
||||||
network: 'testnet',
|
|
||||||
networkId: 2021000,
|
networkId: 2021000,
|
||||||
nativeCurrency: { name: 'Gaia-X', symbol: 'GX', decimals: 18 },
|
nativeCurrency: { name: 'Gaia-X', symbol: 'GX', decimals: 18 },
|
||||||
rpc: [configGaiaX.nodeUri],
|
rpc: [configGaiaX.nodeUri],
|
||||||
|
2
src/@types/Compute.d.ts
vendored
2
src/@types/Compute.d.ts
vendored
@ -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'
|
import { OrdersData_tokenOrders_datatokenId as OrdersDatatoken } from './apollo/OrdersData'
|
||||||
|
|
||||||
// declaring into global scope to be able to use this as
|
// declaring into global scope to be able to use this as
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { PurgatoryData as PurgatoryDataAsset } from '@oceanprotocol/lib'
|
import { Purgatory } from '@oceanprotocol/lib'
|
||||||
import { fetchData } from './fetch'
|
import { fetchData } from './fetch'
|
||||||
|
|
||||||
const purgatoryUrl = 'https://market-purgatory.oceanprotocol.com/api/'
|
const purgatoryUrl = 'https://market-purgatory.oceanprotocol.com/api/'
|
||||||
@ -10,12 +10,12 @@ export interface PurgatoryDataAccount {
|
|||||||
|
|
||||||
export default async function getAssetPurgatoryData(
|
export default async function getAssetPurgatoryData(
|
||||||
did: string
|
did: string
|
||||||
): Promise<PurgatoryDataAsset> {
|
): Promise<Purgatory> {
|
||||||
const data = (await fetchData(
|
const data = (await fetchData(
|
||||||
`${purgatoryUrl}asset?did=${did}`
|
`${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(
|
export async function getAccountPurgatoryData(
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React, { ReactElement, ReactNode, useEffect, useState } from 'react'
|
import React, { ReactElement, ReactNode, useEffect, useState } from 'react'
|
||||||
import External from '@images/external.svg'
|
import External from '@images/external.svg'
|
||||||
import classNames from 'classnames/bind'
|
import classNames from 'classnames/bind'
|
||||||
import { ConfigHelperConfig } from '@oceanprotocol/lib'
|
import { Config } from '@oceanprotocol/lib'
|
||||||
import { useOcean } from '@context/Ocean'
|
import { useOcean } from '@context/Ocean'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import { getOceanConfig } from '@utils/ocean'
|
import { getOceanConfig } from '@utils/ocean'
|
||||||
@ -19,9 +19,9 @@ export default function ExplorerLink({
|
|||||||
children: ReactNode
|
children: ReactNode
|
||||||
className?: string
|
className?: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { config, ocean } = useOcean()
|
const { config } = useOcean()
|
||||||
const [url, setUrl] = useState<string>()
|
const [url, setUrl] = useState<string>()
|
||||||
const [oceanConfig, setOceanConfig] = useState<ConfigHelperConfig>()
|
const [oceanConfig, setOceanConfig] = useState<Config>()
|
||||||
const styleClasses = cx({
|
const styleClasses = cx({
|
||||||
link: true,
|
link: true,
|
||||||
[className]: className
|
[className]: className
|
||||||
@ -38,7 +38,7 @@ export default function ExplorerLink({
|
|||||||
if (oceanConfig === undefined) {
|
if (oceanConfig === undefined) {
|
||||||
initOcean()
|
initOcean()
|
||||||
}
|
}
|
||||||
}, [config, oceanConfig, networkId, ocean])
|
}, [config, oceanConfig, networkId])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import React, { ReactElement, useCallback, useEffect, useState } from 'react'
|
import React, { ReactElement, useCallback, useEffect, useState } from 'react'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
@ -20,7 +19,6 @@ export default function TokenApproval({
|
|||||||
const { ddo, price, isAssetNetwork } = useAsset()
|
const { ddo, price, isAssetNetwork } = useAsset()
|
||||||
const [tokenApproved, setTokenApproved] = useState(false)
|
const [tokenApproved, setTokenApproved] = useState(false)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
|
|
||||||
const config = getOceanConfig(ddo.chainId)
|
const config = getOceanConfig(ddo.chainId)
|
||||||
@ -32,21 +30,18 @@ export default function TokenApproval({
|
|||||||
const spender = price.address
|
const spender = price.address
|
||||||
|
|
||||||
const checkTokenApproval = useCallback(async () => {
|
const checkTokenApproval = useCallback(async () => {
|
||||||
if (!ocean || !tokenAddress || !spender || !isAssetNetwork || !amount)
|
// if (!tokenAddress || !spender || !isAssetNetwork || !amount) return
|
||||||
return
|
// const allowance = await ocean.datatokens.allowance(
|
||||||
|
// tokenAddress,
|
||||||
const allowance = await ocean.datatokens.allowance(
|
// accountId,
|
||||||
tokenAddress,
|
// spender
|
||||||
accountId,
|
// )
|
||||||
spender
|
// amount &&
|
||||||
)
|
// new Decimal(amount).greaterThan(new Decimal('0')) &&
|
||||||
|
// setTokenApproved(
|
||||||
amount &&
|
// new Decimal(allowance).greaterThanOrEqualTo(new Decimal(amount))
|
||||||
new Decimal(amount).greaterThan(new Decimal('0')) &&
|
// )
|
||||||
setTokenApproved(
|
}, [tokenAddress, spender, accountId, amount, isAssetNetwork])
|
||||||
new Decimal(allowance).greaterThanOrEqualTo(new Decimal(amount))
|
|
||||||
)
|
|
||||||
}, [ocean, tokenAddress, spender, accountId, amount, isAssetNetwork])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
checkTokenApproval()
|
checkTokenApproval()
|
||||||
@ -56,7 +51,7 @@ export default function TokenApproval({
|
|||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ocean.datatokens.approve(tokenAddress, spender, amount, accountId)
|
// await ocean.datatokens.approve(tokenAddress, spender, amount, accountId)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,6 @@ export default function FormStartCompute({
|
|||||||
const [totalPrice, setTotalPrice] = useState(price?.value)
|
const [totalPrice, setTotalPrice] = useState(price?.value)
|
||||||
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false)
|
const [isBalanceSufficient, setIsBalanceSufficient] = useState<boolean>(false)
|
||||||
const { accountId, balance } = useWeb3()
|
const { accountId, balance } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
|
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
|
||||||
useState<number>()
|
useState<number>()
|
||||||
|
|
||||||
@ -85,11 +84,11 @@ export default function FormStartCompute({
|
|||||||
|
|
||||||
if (!accountId || !isConsumable) return
|
if (!accountId || !isConsumable) return
|
||||||
async function checkIsConsumable() {
|
async function checkIsConsumable() {
|
||||||
const consumable = await ocean.assets.isConsumable(
|
// const consumable = await ocean.assets.isConsumable(
|
||||||
algorithmDDO as any,
|
// algorithmDDO as any,
|
||||||
accountId.toLowerCase()
|
// accountId.toLowerCase()
|
||||||
)
|
// )
|
||||||
if (consumable) setAlgorithmConsumableStatus(consumable.status)
|
// if (consumable) setAlgorithmConsumableStatus(consumable.status)
|
||||||
}
|
}
|
||||||
checkIsConsumable()
|
checkIsConsumable()
|
||||||
}, [values.algorithm, accountId, isConsumable])
|
}, [values.algorithm, accountId, isConsumable])
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
import React, { useState, ReactElement, useEffect, useCallback } from 'react'
|
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 { toast } from 'react-toastify'
|
||||||
import Price from '@shared/Price'
|
import Price from '@shared/Price'
|
||||||
import FileIcon from '@shared/FileIcon'
|
import FileIcon from '@shared/FileIcon'
|
||||||
@ -17,10 +21,6 @@ import {
|
|||||||
} from '@utils/aquarius'
|
} from '@utils/aquarius'
|
||||||
import { Formik } from 'formik'
|
import { Formik } from 'formik'
|
||||||
import { getInitialValues, validationSchema } from './_constants'
|
import { getInitialValues, validationSchema } from './_constants'
|
||||||
import {
|
|
||||||
ComputeAlgorithm,
|
|
||||||
ComputeOutput
|
|
||||||
} from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute'
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import FormStartComputeDataset from './FormComputeDataset'
|
import FormStartComputeDataset from './FormComputeDataset'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
@ -55,7 +55,6 @@ export default function Compute({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { buyDT, pricingError, pricingStepText } = usePricing()
|
const { buyDT, pricingError, pricingStepText } = usePricing()
|
||||||
const [isJobStarting, setIsJobStarting] = useState(false)
|
const [isJobStarting, setIsJobStarting] = useState(false)
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
@ -83,7 +82,6 @@ export default function Compute({
|
|||||||
const isComputeButtonDisabled =
|
const isComputeButtonDisabled =
|
||||||
isJobStarting === true ||
|
isJobStarting === true ||
|
||||||
file === null ||
|
file === null ||
|
||||||
!ocean ||
|
|
||||||
(!hasPreviousDatasetOrder && !hasDatatoken && !isConsumablePrice) ||
|
(!hasPreviousDatasetOrder && !hasDatatoken && !isConsumablePrice) ||
|
||||||
(!hasPreviousAlgorithmOrder &&
|
(!hasPreviousAlgorithmOrder &&
|
||||||
!hasAlgoAssetDatatoken &&
|
!hasAlgoAssetDatatoken &&
|
||||||
@ -111,12 +109,12 @@ export default function Compute({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function checkAssetDTBalance(asset: DDO) {
|
async function checkAssetDTBalance(asset: DDO) {
|
||||||
const AssetDtBalance = await ocean.datatokens.balance(
|
// const AssetDtBalance = await ocean.datatokens.balance(
|
||||||
asset.services[0].datatokenAddress,
|
// asset.services[0].datatokenAddress,
|
||||||
accountId
|
// accountId
|
||||||
)
|
// )
|
||||||
setalgorithmDTBalance(AssetDtBalance)
|
// setalgorithmDTBalance(AssetDtBalance)
|
||||||
setHasAlgoAssetDatatoken(Number(AssetDtBalance) >= 1)
|
// setHasAlgoAssetDatatoken(Number(AssetDtBalance) >= 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuerryString(
|
function getQuerryString(
|
||||||
@ -204,9 +202,9 @@ export default function Compute({
|
|||||||
}, [ddo])
|
}, [ddo])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !accountId) return
|
if (!accountId) return
|
||||||
checkPreviousOrders(ddo)
|
checkPreviousOrders(ddo)
|
||||||
}, [ocean, ddo, accountId])
|
}, [ddo, accountId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!selectedAlgorithmAsset) return
|
if (!selectedAlgorithmAsset) return
|
||||||
@ -231,8 +229,8 @@ export default function Compute({
|
|||||||
checkPreviousOrders(selectedAlgorithmAsset)
|
checkPreviousOrders(selectedAlgorithmAsset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ocean && checkAssetDTBalance(selectedAlgorithmAsset)
|
// ocean && checkAssetDTBalance(selectedAlgorithmAsset)
|
||||||
}, [ddo, selectedAlgorithmAsset, ocean, accountId, hasPreviousAlgorithmOrder])
|
}, [ddo, selectedAlgorithmAsset, accountId, hasPreviousAlgorithmOrder])
|
||||||
|
|
||||||
// Output errors in toast UI
|
// Output errors in toast UI
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -4,7 +4,6 @@ import Button from '@shared/atoms/Button'
|
|||||||
import styles from './Actions.module.css'
|
import styles from './Actions.module.css'
|
||||||
import ExplorerLink from '@shared/ExplorerLink'
|
import ExplorerLink from '@shared/ExplorerLink'
|
||||||
import SuccessConfetti from '@shared/SuccessConfetti'
|
import SuccessConfetti from '@shared/SuccessConfetti'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
import TokenApproval from '@shared/TokenApproval'
|
import TokenApproval from '@shared/TokenApproval'
|
||||||
|
|
||||||
@ -30,14 +29,13 @@ export default function Actions({
|
|||||||
isDisabled?: boolean
|
isDisabled?: boolean
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { networkId } = useWeb3()
|
const { networkId } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
|
|
||||||
const actionButton = (
|
const actionButton = (
|
||||||
<Button
|
<Button
|
||||||
style="primary"
|
style="primary"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={() => action()}
|
onClick={() => action()}
|
||||||
disabled={!ocean || isDisabled}
|
disabled={isDisabled}
|
||||||
>
|
>
|
||||||
{actionName}
|
{actionName}
|
||||||
</Button>
|
</Button>
|
||||||
@ -53,7 +51,7 @@ export default function Actions({
|
|||||||
actionButton={actionButton}
|
actionButton={actionButton}
|
||||||
amount={amount}
|
amount={amount}
|
||||||
coin={coin}
|
coin={coin}
|
||||||
disabled={!ocean || isDisabled}
|
disabled={isDisabled}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
actionButton
|
actionButton
|
||||||
|
@ -11,7 +11,6 @@ import Button from '@shared/atoms/Button'
|
|||||||
import CoinSelect from '../CoinSelect'
|
import CoinSelect from '../CoinSelect'
|
||||||
import { FormAddLiquidity } from '.'
|
import { FormAddLiquidity } from '.'
|
||||||
import UserLiquidity from '../../UserLiquidity'
|
import UserLiquidity from '../../UserLiquidity'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
|
|
||||||
import { isValidNumber } from '@utils/numbers'
|
import { isValidNumber } from '@utils/numbers'
|
||||||
@ -43,8 +42,7 @@ export default function FormAdd({
|
|||||||
setNewPoolTokens: (value: string) => void
|
setNewPoolTokens: (value: string) => void
|
||||||
setNewPoolShare: (value: string) => void
|
setNewPoolShare: (value: string) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { balance } = useWeb3()
|
const { balance, web3 } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
|
|
||||||
// Connect with form
|
// Connect with form
|
||||||
@ -69,36 +67,31 @@ export default function FormAdd({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function calculatePoolShares() {
|
async function calculatePoolShares() {
|
||||||
if (!ocean) return
|
// if (!web3) return
|
||||||
const tokenInAddress =
|
// const tokenInAddress =
|
||||||
coin === 'OCEAN' ? ocean.pool.oceanAddress : ocean.pool.dtAddress
|
// coin === 'OCEAN' ? ocean.pool.oceanAddress : ocean.pool.dtAddress
|
||||||
if (!values.amount || !tokenInAddress) {
|
// if (!values.amount || !tokenInAddress) {
|
||||||
setNewPoolTokens('0')
|
// setNewPoolTokens('0')
|
||||||
setNewPoolShare('0')
|
// setNewPoolShare('0')
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
// if (Number(values.amount) > Number(amountMax)) return
|
||||||
if (Number(values.amount) > Number(amountMax)) return
|
// const poolTokens = await ocean.pool.calcPoolOutGivenSingleIn(
|
||||||
|
// poolAddress,
|
||||||
const poolTokens = await ocean.pool.calcPoolOutGivenSingleIn(
|
// tokenInAddress,
|
||||||
poolAddress,
|
// `${values.amount}`
|
||||||
tokenInAddress,
|
// )
|
||||||
`${values.amount}`
|
// setNewPoolTokens(poolTokens)
|
||||||
)
|
// const newPoolShareDecimal =
|
||||||
|
// isValidNumber(poolTokens) && isValidNumber(totalPoolTokens)
|
||||||
setNewPoolTokens(poolTokens)
|
// ? new Decimal(poolTokens)
|
||||||
|
// .dividedBy(
|
||||||
const newPoolShareDecimal =
|
// new Decimal(totalPoolTokens).plus(new Decimal(poolTokens))
|
||||||
isValidNumber(poolTokens) && isValidNumber(totalPoolTokens)
|
// )
|
||||||
? new Decimal(poolTokens)
|
// .mul(100)
|
||||||
.dividedBy(
|
// .toString()
|
||||||
new Decimal(totalPoolTokens).plus(new Decimal(poolTokens))
|
// : '0'
|
||||||
)
|
// totalBalance && setNewPoolShare(newPoolShareDecimal)
|
||||||
.mul(100)
|
|
||||||
.toString()
|
|
||||||
: '0'
|
|
||||||
|
|
||||||
totalBalance && setNewPoolShare(newPoolShareDecimal)
|
|
||||||
}
|
}
|
||||||
calculatePoolShares()
|
calculatePoolShares()
|
||||||
}, [
|
}, [
|
||||||
@ -108,7 +101,6 @@ export default function FormAdd({
|
|||||||
amountMax,
|
amountMax,
|
||||||
coin,
|
coin,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
ocean?.pool,
|
|
||||||
setNewPoolTokens,
|
setNewPoolTokens,
|
||||||
setNewPoolShare
|
setNewPoolShare
|
||||||
])
|
])
|
||||||
@ -144,14 +136,14 @@ export default function FormAdd({
|
|||||||
<CoinSelect
|
<CoinSelect
|
||||||
dtSymbol={dtSymbol}
|
dtSymbol={dtSymbol}
|
||||||
setCoin={setCoin}
|
setCoin={setCoin}
|
||||||
disabled={!ocean || !isAssetNetwork}
|
disabled={!web3 || !isAssetNetwork}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
placeholder="0"
|
placeholder="0"
|
||||||
field={field}
|
field={field}
|
||||||
form={form}
|
form={form}
|
||||||
onChange={handleFieldChange}
|
onChange={handleFieldChange}
|
||||||
disabled={!ocean || !isAssetNetwork}
|
disabled={!isAssetNetwork}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
@ -161,7 +153,7 @@ export default function FormAdd({
|
|||||||
className={styles.buttonMax}
|
className={styles.buttonMax}
|
||||||
style="text"
|
style="text"
|
||||||
size="small"
|
size="small"
|
||||||
disabled={!ocean}
|
disabled={!web3}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setAmount(amountMax)
|
setAmount(amountMax)
|
||||||
setFieldValue('amount', amountMax)
|
setFieldValue('amount', amountMax)
|
||||||
|
@ -10,7 +10,6 @@ import Alert from '@shared/atoms/Alert'
|
|||||||
import { useUserPreferences } from '@context/UserPreferences'
|
import { useUserPreferences } from '@context/UserPreferences'
|
||||||
import Output from './Output'
|
import Output from './Output'
|
||||||
import DebugOutput from '@shared/DebugOutput'
|
import DebugOutput from '@shared/DebugOutput'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import content from '../../../../../../content/price.json'
|
import content from '../../../../../../content/price.json'
|
||||||
@ -43,7 +42,6 @@ export default function Add({
|
|||||||
dtAddress: string
|
dtAddress: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { accountId, balance } = useWeb3()
|
const { accountId, balance } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const [txId, setTxId] = useState<string>()
|
const [txId, setTxId] = useState<string>()
|
||||||
@ -69,53 +67,50 @@ export default function Add({
|
|||||||
|
|
||||||
// Get datatoken balance when datatoken selected
|
// Get datatoken balance when datatoken selected
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !isAssetNetwork || coin === 'OCEAN') return
|
// if (!accountId || !isAssetNetwork || coin === 'OCEAN') return
|
||||||
|
// async function getDtBalance() {
|
||||||
async function getDtBalance() {
|
// const dtBalance = await ocean.datatokens.balance(dtAddress, accountId)
|
||||||
const dtBalance = await ocean.datatokens.balance(dtAddress, accountId)
|
// setDtBalance(dtBalance)
|
||||||
setDtBalance(dtBalance)
|
// }
|
||||||
}
|
// getDtBalance()
|
||||||
getDtBalance()
|
}, [accountId, dtAddress, coin])
|
||||||
}, [ocean, accountId, dtAddress, coin])
|
|
||||||
|
|
||||||
// Get maximum amount for either OCEAN or datatoken
|
// Get maximum amount for either OCEAN or datatoken
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !isAssetNetwork || !poolAddress) return
|
if (!accountId || !isAssetNetwork || !poolAddress) return
|
||||||
|
|
||||||
async function getMaximum() {
|
async function getMaximum() {
|
||||||
const amountMaxPool =
|
// const amountMaxPool =
|
||||||
coin === 'OCEAN'
|
// coin === 'OCEAN'
|
||||||
? await ocean.pool.getOceanMaxAddLiquidity(poolAddress)
|
// ? await ocean.pool.getOceanMaxAddLiquidity(poolAddress)
|
||||||
: await ocean.pool.getDTMaxAddLiquidity(poolAddress)
|
// : await ocean.pool.getDTMaxAddLiquidity(poolAddress)
|
||||||
|
// const amountMax =
|
||||||
const amountMax =
|
// coin === 'OCEAN'
|
||||||
coin === 'OCEAN'
|
// ? Number(balance.ocean) > Number(amountMaxPool)
|
||||||
? Number(balance.ocean) > Number(amountMaxPool)
|
// ? amountMaxPool
|
||||||
? amountMaxPool
|
// : balance.ocean
|
||||||
: balance.ocean
|
// : Number(dtBalance) > Number(amountMaxPool)
|
||||||
: Number(dtBalance) > Number(amountMaxPool)
|
// ? amountMaxPool
|
||||||
? amountMaxPool
|
// : dtBalance
|
||||||
: dtBalance
|
// setAmountMax(Number(amountMax).toFixed(3))
|
||||||
setAmountMax(Number(amountMax).toFixed(3))
|
|
||||||
}
|
}
|
||||||
getMaximum()
|
getMaximum()
|
||||||
}, [ocean, poolAddress, coin, dtBalance, balance.ocean])
|
}, [accountId, isAssetNetwork, poolAddress, coin, dtBalance, balance.ocean])
|
||||||
|
|
||||||
// Submit
|
// Submit
|
||||||
async function handleAddLiquidity(amount: number, resetForm: () => void) {
|
async function handleAddLiquidity(amount: number, resetForm: () => void) {
|
||||||
try {
|
try {
|
||||||
const result =
|
// const result =
|
||||||
coin === 'OCEAN'
|
// coin === 'OCEAN'
|
||||||
? await ocean.pool.addOceanLiquidity(
|
// ? await ocean.pool.addOceanLiquidity(
|
||||||
accountId,
|
// accountId,
|
||||||
poolAddress,
|
// poolAddress,
|
||||||
`${amount}`
|
// `${amount}`
|
||||||
)
|
// )
|
||||||
: await ocean.pool.addDTLiquidity(accountId, poolAddress, `${amount}`)
|
// : await ocean.pool.addDTLiquidity(accountId, poolAddress, `${amount}`)
|
||||||
|
// setTxId(result?.transactionHash)
|
||||||
setTxId(result?.transactionHash)
|
// resetForm()
|
||||||
resetForm()
|
// refreshInfo()
|
||||||
refreshInfo()
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error.message)
|
console.error(error.message)
|
||||||
toast.error(error.message)
|
toast.error(error.message)
|
||||||
|
@ -41,7 +41,6 @@ export default function Remove({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const slippagePresets = ['5', '10', '15', '25', '50']
|
const slippagePresets = ['5', '10', '15', '25', '50']
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const [amountPercent, setAmountPercent] = useState('0')
|
const [amountPercent, setAmountPercent] = useState('0')
|
||||||
const [amountMaxPercent, setAmountMaxPercent] = useState('100')
|
const [amountMaxPercent, setAmountMaxPercent] = useState('100')
|
||||||
@ -60,24 +59,23 @@ export default function Remove({
|
|||||||
async function handleRemoveLiquidity() {
|
async function handleRemoveLiquidity() {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
try {
|
try {
|
||||||
const result =
|
// const result =
|
||||||
isAdvanced === true
|
// isAdvanced === true
|
||||||
? await ocean.pool.removePoolLiquidity(
|
// ? await ocean.pool.removePoolLiquidity(
|
||||||
accountId,
|
// accountId,
|
||||||
poolAddress,
|
// poolAddress,
|
||||||
amountPoolShares,
|
// amountPoolShares,
|
||||||
minDatatokenAmount,
|
// minDatatokenAmount,
|
||||||
minOceanAmount
|
// minOceanAmount
|
||||||
)
|
// )
|
||||||
: await ocean.pool.removeOceanLiquidityWithMinimum(
|
// : await ocean.pool.removeOceanLiquidityWithMinimum(
|
||||||
accountId,
|
// accountId,
|
||||||
poolAddress,
|
// poolAddress,
|
||||||
amountPoolShares,
|
// amountPoolShares,
|
||||||
minOceanAmount
|
// minOceanAmount
|
||||||
)
|
// )
|
||||||
|
// setTxId(result?.transactionHash)
|
||||||
setTxId(result?.transactionHash)
|
// refreshInfo()
|
||||||
refreshInfo()
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(error.message)
|
LoggerInstance.error(error.message)
|
||||||
toast.error(error.message)
|
toast.error(error.message)
|
||||||
@ -88,45 +86,44 @@ export default function Remove({
|
|||||||
|
|
||||||
// Get and set max percentage
|
// Get and set max percentage
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !poolTokens) return
|
if (!accountId || !poolTokens) return
|
||||||
|
|
||||||
async function getMax() {
|
async function getMax() {
|
||||||
const amountMaxPercent =
|
// const amountMaxPercent =
|
||||||
isAdvanced === true
|
// isAdvanced === true
|
||||||
? '100'
|
// ? '100'
|
||||||
: await getMaxPercentRemove(ocean, poolAddress, poolTokens)
|
// : await getMaxPercentRemove(poolAddress, poolTokens)
|
||||||
setAmountMaxPercent(amountMaxPercent)
|
// setAmountMaxPercent(amountMaxPercent)
|
||||||
}
|
}
|
||||||
getMax()
|
getMax()
|
||||||
}, [ocean, isAdvanced, poolAddress, poolTokens])
|
}, [accountId, isAdvanced, poolAddress, poolTokens])
|
||||||
|
|
||||||
const getValues = useRef(
|
const getValues = useRef(
|
||||||
debounce(async (newAmountPoolShares, isAdvanced) => {
|
debounce(async (newAmountPoolShares, isAdvanced) => {
|
||||||
if (isAdvanced === true) {
|
// if (isAdvanced === true) {
|
||||||
const tokens = await ocean.pool.getTokensRemovedforPoolShares(
|
// const tokens = await ocean.pool.getTokensRemovedforPoolShares(
|
||||||
poolAddress,
|
// poolAddress,
|
||||||
`${newAmountPoolShares}`
|
// `${newAmountPoolShares}`
|
||||||
)
|
// )
|
||||||
setAmountOcean(tokens?.oceanAmount)
|
// setAmountOcean(tokens?.oceanAmount)
|
||||||
setAmountDatatoken(tokens?.dtAmount)
|
// setAmountDatatoken(tokens?.dtAmount)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
// const amountOcean = await ocean.pool.getOceanRemovedforPoolShares(
|
||||||
const amountOcean = await ocean.pool.getOceanRemovedforPoolShares(
|
// poolAddress,
|
||||||
poolAddress,
|
// newAmountPoolShares
|
||||||
newAmountPoolShares
|
// )
|
||||||
)
|
// setAmountOcean(amountOcean)
|
||||||
setAmountOcean(amountOcean)
|
|
||||||
}, 150)
|
}, 150)
|
||||||
)
|
)
|
||||||
// Check and set outputs when amountPoolShares changes
|
// Check and set outputs when amountPoolShares changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !poolTokens) return
|
if (!accountId || !poolTokens) return
|
||||||
getValues.current(amountPoolShares, isAdvanced)
|
getValues.current(amountPoolShares, isAdvanced)
|
||||||
}, [
|
}, [
|
||||||
amountPoolShares,
|
amountPoolShares,
|
||||||
isAdvanced,
|
isAdvanced,
|
||||||
ocean,
|
accountId,
|
||||||
poolTokens,
|
poolTokens,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
totalPoolTokens
|
totalPoolTokens
|
||||||
|
@ -1,36 +1,35 @@
|
|||||||
import { Ocean } from '@oceanprotocol/lib'
|
|
||||||
import { isValidNumber } from '@utils/numbers'
|
import { isValidNumber } from '@utils/numbers'
|
||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
|
|
||||||
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
|
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
|
||||||
|
|
||||||
export async function getMaxPercentRemove(
|
export async function getMaxPercentRemove(
|
||||||
ocean: Ocean,
|
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
poolTokens: string
|
poolTokens: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const amountMaxOcean = await ocean.pool.getOceanMaxRemoveLiquidity(
|
// const amountMaxOcean = await ocean.pool.getOceanMaxRemoveLiquidity(
|
||||||
poolAddress
|
// poolAddress
|
||||||
)
|
// )
|
||||||
|
|
||||||
const amountMaxPoolShares =
|
// const amountMaxPoolShares =
|
||||||
await ocean.pool.getPoolSharesRequiredToRemoveOcean(
|
// await ocean.pool.getPoolSharesRequiredToRemoveOcean(
|
||||||
poolAddress,
|
// poolAddress,
|
||||||
amountMaxOcean
|
// amountMaxOcean
|
||||||
)
|
// )
|
||||||
|
|
||||||
let amountMaxPercent =
|
// let amountMaxPercent =
|
||||||
isValidNumber(amountMaxPoolShares) && isValidNumber(poolTokens)
|
// isValidNumber(amountMaxPoolShares) && isValidNumber(poolTokens)
|
||||||
? new Decimal(amountMaxPoolShares)
|
// ? new Decimal(amountMaxPoolShares)
|
||||||
.dividedBy(new Decimal(poolTokens))
|
// .dividedBy(new Decimal(poolTokens))
|
||||||
.mul(100)
|
// .mul(100)
|
||||||
.floor()
|
// .floor()
|
||||||
.toString()
|
// .toString()
|
||||||
: '0'
|
// : '0'
|
||||||
|
|
||||||
if (Number(amountMaxPercent) > 100) {
|
// if (Number(amountMaxPercent) > 100) {
|
||||||
amountMaxPercent = '100'
|
// amountMaxPercent = '100'
|
||||||
}
|
// }
|
||||||
|
|
||||||
return amountMaxPercent
|
// return amountMaxPercent
|
||||||
|
return '0'
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import Swap from './Swap'
|
|||||||
import Alert from '@shared/atoms/Alert'
|
import Alert from '@shared/atoms/Alert'
|
||||||
import styles from './FormTrade.module.css'
|
import styles from './FormTrade.module.css'
|
||||||
import Decimal from 'decimal.js'
|
import Decimal from 'decimal.js'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { FormTradeData } from './_types'
|
import { FormTradeData } from './_types'
|
||||||
@ -30,7 +29,6 @@ export default function FormTrade({
|
|||||||
price: BestPrice
|
price: BestPrice
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const [txId, setTxId] = useState<string>()
|
const [txId, setTxId] = useState<string>()
|
||||||
@ -69,27 +67,27 @@ export default function FormTrade({
|
|||||||
new Decimal(100).sub(new Decimal(values.slippage))
|
new Decimal(100).sub(new Decimal(values.slippage))
|
||||||
).div(100)
|
).div(100)
|
||||||
const precision = 15
|
const precision = 15
|
||||||
const tx =
|
// const tx =
|
||||||
values.type === 'buy'
|
// values.type === 'buy'
|
||||||
? await ocean.pool.buyDTWithExactOcean(
|
// ? await ocean.pool.buyDTWithExactOcean(
|
||||||
accountId,
|
// accountId,
|
||||||
price.address,
|
// price.address,
|
||||||
new Decimal(values.datatoken)
|
// new Decimal(values.datatoken)
|
||||||
.mul(impact)
|
// .mul(impact)
|
||||||
.toFixed(precision)
|
// .toFixed(precision)
|
||||||
.toString(),
|
// .toString(),
|
||||||
new Decimal(values.ocean).toFixed(precision).toString()
|
// new Decimal(values.ocean).toFixed(precision).toString()
|
||||||
)
|
// )
|
||||||
: await ocean.pool.sellDT(
|
// : await ocean.pool.sellDT(
|
||||||
accountId,
|
// accountId,
|
||||||
price.address,
|
// price.address,
|
||||||
new Decimal(values.datatoken).toFixed(precision).toString(),
|
// new Decimal(values.datatoken).toFixed(precision).toString(),
|
||||||
new Decimal(values.ocean)
|
// new Decimal(values.ocean)
|
||||||
.mul(impact)
|
// .mul(impact)
|
||||||
.toFixed(precision)
|
// .toFixed(precision)
|
||||||
.toString()
|
// .toString()
|
||||||
)
|
// )
|
||||||
setTxId(tx?.transactionHash)
|
// setTxId(tx?.transactionHash)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(error.message)
|
LoggerInstance.error(error.message)
|
||||||
toast.error(error.message)
|
toast.error(error.message)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { FormikContextType, useFormikContext } from 'formik'
|
import { FormikContextType, useFormikContext } from 'formik'
|
||||||
import React, { ReactElement, useEffect, useState } from 'react'
|
import React, { ReactElement, useEffect, useState } from 'react'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import Token from '../Pool/Token'
|
import Token from '../Pool/Token'
|
||||||
import styles from './Output.module.css'
|
import styles from './Output.module.css'
|
||||||
|
|
||||||
@ -21,7 +20,6 @@ export default function Output({
|
|||||||
poolAddress: string
|
poolAddress: string
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const [maxOutput, setMaxOutput] = useState<string>()
|
const [maxOutput, setMaxOutput] = useState<string>()
|
||||||
const [swapFee, setSwapFee] = useState<string>()
|
const [swapFee, setSwapFee] = useState<string>()
|
||||||
const [swapFeeValue, setSwapFeeValue] = useState<string>()
|
const [swapFeeValue, setSwapFeeValue] = useState<string>()
|
||||||
@ -30,15 +28,15 @@ export default function Output({
|
|||||||
|
|
||||||
// Get swap fee
|
// Get swap fee
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !poolAddress || !isAssetNetwork) return
|
if (!poolAddress || !isAssetNetwork) return
|
||||||
|
|
||||||
async function getSwapFee() {
|
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
|
// // swapFee is tricky: to get 0.1% you need to convert from 0.001
|
||||||
setSwapFee(
|
// setSwapFee(
|
||||||
isValidNumber(swapFee) ? new Decimal(swapFee).mul(100).toString() : '0'
|
// isValidNumber(swapFee) ? new Decimal(swapFee).mul(100).toString() : '0'
|
||||||
)
|
// )
|
||||||
|
|
||||||
const value =
|
const value =
|
||||||
values.type === 'buy'
|
values.type === 'buy'
|
||||||
@ -51,11 +49,11 @@ export default function Output({
|
|||||||
setSwapFeeValue(value.toString())
|
setSwapFeeValue(value.toString())
|
||||||
}
|
}
|
||||||
getSwapFee()
|
getSwapFee()
|
||||||
}, [ocean, poolAddress, values, isAssetNetwork])
|
}, [poolAddress, values, isAssetNetwork])
|
||||||
|
|
||||||
// Get output values
|
// Get output values
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !poolAddress || !isAssetNetwork) return
|
if (!poolAddress || !isAssetNetwork) return
|
||||||
|
|
||||||
async function getOutput() {
|
async function getOutput() {
|
||||||
// Minimum received
|
// Minimum received
|
||||||
@ -75,7 +73,7 @@ export default function Output({
|
|||||||
setMaxOutput(maxPrice)
|
setMaxOutput(maxPrice)
|
||||||
}
|
}
|
||||||
getOutput()
|
getOutput()
|
||||||
}, [ocean, poolAddress, values, isAssetNetwork])
|
}, [poolAddress, values, isAssetNetwork])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.output}>
|
<div className={styles.output}>
|
||||||
|
@ -4,7 +4,6 @@ import TradeInput from './TradeInput'
|
|||||||
import Button from '@shared/atoms/Button'
|
import Button from '@shared/atoms/Button'
|
||||||
import Arrow from '@images/arrow.svg'
|
import Arrow from '@images/arrow.svg'
|
||||||
import { FormikContextType, useFormikContext } from 'formik'
|
import { FormikContextType, useFormikContext } from 'formik'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import Output from './Output'
|
import Output from './Output'
|
||||||
import Slippage from './Slippage'
|
import Slippage from './Slippage'
|
||||||
import PriceImpact from './PriceImpact'
|
import PriceImpact from './PriceImpact'
|
||||||
@ -34,7 +33,6 @@ export default function Swap({
|
|||||||
setMaximumOcean: (value: string) => void
|
setMaximumOcean: (value: string) => void
|
||||||
setCoin: (value: string) => void
|
setCoin: (value: string) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const [oceanItem, setOceanItem] = useState<TradeItem>({
|
const [oceanItem, setOceanItem] = useState<TradeItem>({
|
||||||
amount: '0',
|
amount: '0',
|
||||||
@ -72,47 +70,47 @@ export default function Swap({
|
|||||||
? new Decimal(balance.ocean)
|
? new Decimal(balance.ocean)
|
||||||
: new Decimal(maxOcean)
|
: new Decimal(maxOcean)
|
||||||
|
|
||||||
const maxBuyOcean = await ocean.pool.getOceanReceived(
|
// const maxBuyOcean = await ocean.pool.getOceanReceived(
|
||||||
price.address,
|
// price.address,
|
||||||
`${amountDataToken.toString()}`
|
// `${amountDataToken.toString()}`
|
||||||
)
|
// )
|
||||||
const maxBuyDt = await ocean.pool.getDTReceived(
|
// const maxBuyDt = await ocean.pool.getDTReceived(
|
||||||
price.address,
|
// price.address,
|
||||||
`${amountOcean.toString()}`
|
// `${amountOcean.toString()}`
|
||||||
)
|
// )
|
||||||
|
|
||||||
const maximumDt =
|
// const maximumDt =
|
||||||
values.type === 'buy'
|
// values.type === 'buy'
|
||||||
? amountDataToken.greaterThan(new Decimal(maxBuyDt))
|
// ? amountDataToken.greaterThan(new Decimal(maxBuyDt))
|
||||||
? maxBuyDt
|
// ? maxBuyDt
|
||||||
: amountDataToken
|
// : amountDataToken
|
||||||
: amountDataToken.greaterThan(new Decimal(balance.datatoken))
|
// : amountDataToken.greaterThan(new Decimal(balance.datatoken))
|
||||||
? balance.datatoken
|
// ? balance.datatoken
|
||||||
: amountDataToken
|
// : amountDataToken
|
||||||
|
|
||||||
const maximumOcean =
|
// const maximumOcean =
|
||||||
values.type === 'sell'
|
// values.type === 'sell'
|
||||||
? amountOcean.greaterThan(new Decimal(maxBuyOcean))
|
// ? amountOcean.greaterThan(new Decimal(maxBuyOcean))
|
||||||
? maxBuyOcean
|
// ? maxBuyOcean
|
||||||
: amountOcean
|
// : amountOcean
|
||||||
: amountOcean.greaterThan(new Decimal(balance.ocean))
|
// : amountOcean.greaterThan(new Decimal(balance.ocean))
|
||||||
? balance.ocean
|
// ? balance.ocean
|
||||||
: amountOcean
|
// : amountOcean
|
||||||
|
|
||||||
setMaximumDt(maximumDt.toString())
|
// setMaximumDt(maximumDt.toString())
|
||||||
setMaximumOcean(maximumOcean.toString())
|
// setMaximumOcean(maximumOcean.toString())
|
||||||
|
|
||||||
setOceanItem((prevState) => ({
|
// setOceanItem((prevState) => ({
|
||||||
...prevState,
|
// ...prevState,
|
||||||
amount: amountOcean.toString(),
|
// amount: amountOcean.toString(),
|
||||||
maxAmount: maximumOcean.toString()
|
// maxAmount: maximumOcean.toString()
|
||||||
}))
|
// }))
|
||||||
|
|
||||||
setDtItem((prevState) => ({
|
// setDtItem((prevState) => ({
|
||||||
...prevState,
|
// ...prevState,
|
||||||
amount: amountDataToken.toString(),
|
// amount: amountDataToken.toString(),
|
||||||
maxAmount: maximumDt.toString()
|
// maxAmount: maximumDt.toString()
|
||||||
}))
|
// }))
|
||||||
}
|
}
|
||||||
calculateMaximum()
|
calculateMaximum()
|
||||||
}, [
|
}, [
|
||||||
@ -122,7 +120,6 @@ export default function Swap({
|
|||||||
balance,
|
balance,
|
||||||
price,
|
price,
|
||||||
values?.type,
|
values?.type,
|
||||||
ocean,
|
|
||||||
setMaximumDt,
|
setMaximumDt,
|
||||||
setMaximumOcean
|
setMaximumOcean
|
||||||
])
|
])
|
||||||
@ -137,63 +134,63 @@ export default function Swap({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleValueChange = async (name: string, value: number) => {
|
const handleValueChange = async (name: string, value: number) => {
|
||||||
let tokenIn = ''
|
const tokenIn = ''
|
||||||
let tokenOut = ''
|
const tokenOut = ''
|
||||||
let newValue
|
let newValue
|
||||||
|
|
||||||
if (name === 'ocean') {
|
// if (name === 'ocean') {
|
||||||
if (values.type === 'sell') {
|
// if (values.type === 'sell') {
|
||||||
newValue = await ocean.pool.getDTNeeded(price.address, value.toString())
|
// newValue = await ocean.pool.getDTNeeded(price.address, value.toString())
|
||||||
|
|
||||||
setTotalValue(newValue)
|
// setTotalValue(newValue)
|
||||||
setTokenAmount(value.toString())
|
// setTokenAmount(value.toString())
|
||||||
|
|
||||||
tokenIn = ddo.services[0].datatokenAddress
|
// tokenIn = ddo.services[0].datatokenAddress
|
||||||
tokenOut = ocean.pool.oceanAddress
|
// tokenOut = ocean.pool.oceanAddress
|
||||||
} else {
|
// } else {
|
||||||
newValue = await ocean.pool.getDTReceived(
|
// newValue = await ocean.pool.getDTReceived(
|
||||||
price.address,
|
// price.address,
|
||||||
value.toString()
|
// value.toString()
|
||||||
)
|
// )
|
||||||
|
|
||||||
setTotalValue(value.toString())
|
// setTotalValue(value.toString())
|
||||||
setTokenAmount(newValue)
|
// setTokenAmount(newValue)
|
||||||
tokenIn = ocean.pool.oceanAddress
|
// tokenIn = ocean.pool.oceanAddress
|
||||||
tokenOut = ddo.services[0].datatokenAddress
|
// tokenOut = ddo.services[0].datatokenAddress
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
if (values.type === 'sell') {
|
// if (values.type === 'sell') {
|
||||||
newValue = await ocean.pool.getOceanReceived(
|
// newValue = await ocean.pool.getOceanReceived(
|
||||||
price.address,
|
// price.address,
|
||||||
value.toString()
|
// value.toString()
|
||||||
)
|
// )
|
||||||
|
|
||||||
setTotalValue(value.toString())
|
// setTotalValue(value.toString())
|
||||||
setTokenAmount(newValue)
|
// setTokenAmount(newValue)
|
||||||
tokenIn = ddo.services[0].datatokenAddress
|
// tokenIn = ddo.services[0].datatokenAddress
|
||||||
tokenOut = ocean.pool.oceanAddress
|
// tokenOut = ocean.pool.oceanAddress
|
||||||
} else {
|
// } else {
|
||||||
newValue = await ocean.pool.getOceanNeeded(
|
// newValue = await ocean.pool.getOceanNeeded(
|
||||||
price.address,
|
// price.address,
|
||||||
value.toString()
|
// value.toString()
|
||||||
)
|
// )
|
||||||
|
|
||||||
setTotalValue(newValue)
|
// setTotalValue(newValue)
|
||||||
setTokenAmount(value.toString())
|
// setTokenAmount(value.toString())
|
||||||
tokenIn = ocean.pool.oceanAddress
|
// tokenIn = ocean.pool.oceanAddress
|
||||||
tokenOut = ddo.services[0].datatokenAddress
|
// tokenOut = ddo.services[0].datatokenAddress
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
await setFieldValue(name === 'ocean' ? 'datatoken' : 'ocean', newValue)
|
await setFieldValue(name === 'ocean' ? 'datatoken' : 'ocean', newValue)
|
||||||
|
|
||||||
const spotPrice = await ocean.pool.getSpotPrice(
|
// const spotPrice = await ocean.pool.getSpotPrice(
|
||||||
price.address,
|
// price.address,
|
||||||
tokenIn,
|
// tokenIn,
|
||||||
tokenOut
|
// tokenOut
|
||||||
)
|
// )
|
||||||
|
|
||||||
setSpotPrice(spotPrice)
|
// setSpotPrice(spotPrice)
|
||||||
validateForm()
|
validateForm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import Button from '@shared/atoms/Button'
|
|||||||
import { useOcean } from '@context/Ocean'
|
import { useOcean } from '@context/Ocean'
|
||||||
import { FormTradeData, TradeItem } from './_types'
|
import { FormTradeData, TradeItem } from './_types'
|
||||||
import UserLiquidity from '../UserLiquidity'
|
import UserLiquidity from '../UserLiquidity'
|
||||||
|
import { useWeb3 } from '@context/Web3'
|
||||||
|
|
||||||
export default function TradeInput({
|
export default function TradeInput({
|
||||||
name,
|
name,
|
||||||
@ -23,7 +24,7 @@ export default function TradeInput({
|
|||||||
disabled: boolean
|
disabled: boolean
|
||||||
handleValueChange: (name: string, value: number) => void
|
handleValueChange: (name: string, value: number) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean } = useOcean()
|
const { accountId } = useWeb3()
|
||||||
|
|
||||||
// Connect with form
|
// Connect with form
|
||||||
const {
|
const {
|
||||||
@ -64,7 +65,7 @@ export default function TradeInput({
|
|||||||
validateForm()
|
validateForm()
|
||||||
handleChange(e)
|
handleChange(e)
|
||||||
}}
|
}}
|
||||||
disabled={!ocean || disabled}
|
disabled={!accountId || disabled}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Field>
|
</Field>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import React, { ReactElement, useEffect, useState } from 'react'
|
import React, { ReactElement, useEffect, useState } from 'react'
|
||||||
import FormTrade from './FormTrade'
|
import FormTrade from './FormTrade'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
|
|
||||||
import { isValidNumber } from '@utils/numbers'
|
import { isValidNumber } from '@utils/numbers'
|
||||||
@ -11,7 +10,6 @@ Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
|
|||||||
|
|
||||||
export default function Trade(): ReactElement {
|
export default function Trade(): ReactElement {
|
||||||
const { accountId, balance } = useWeb3()
|
const { accountId, balance } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const [tokenBalance, setTokenBalance] = useState<PoolBalance>()
|
const [tokenBalance, setTokenBalance] = useState<PoolBalance>()
|
||||||
const { price, ddo } = useAsset()
|
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
|
// Get datatoken balance, and combine with OCEAN balance from hooks into one object
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
!ocean ||
|
!accountId ||
|
||||||
!isAssetNetwork ||
|
!isAssetNetwork ||
|
||||||
!balance?.ocean ||
|
!balance?.ocean ||
|
||||||
!accountId ||
|
!accountId ||
|
||||||
@ -30,45 +28,42 @@ export default function Trade(): ReactElement {
|
|||||||
return
|
return
|
||||||
|
|
||||||
async function getTokenBalance() {
|
async function getTokenBalance() {
|
||||||
const dtBalance = await ocean.datatokens.balance(
|
// const dtBalance = await ocean.datatokens.balance(
|
||||||
ddo.services[0].datatokenAddress,
|
// ddo.services[0].datatokenAddress,
|
||||||
accountId
|
// accountId
|
||||||
)
|
// )
|
||||||
setTokenBalance({
|
// setTokenBalance({
|
||||||
ocean: new Decimal(balance.ocean).toString(),
|
// ocean: new Decimal(balance.ocean).toString(),
|
||||||
datatoken: new Decimal(dtBalance).toString()
|
// datatoken: new Decimal(dtBalance).toString()
|
||||||
})
|
// })
|
||||||
}
|
}
|
||||||
getTokenBalance()
|
getTokenBalance()
|
||||||
}, [balance.ocean, ocean, accountId, ddo, isAssetNetwork])
|
}, [balance.ocean, accountId, ddo, isAssetNetwork])
|
||||||
|
|
||||||
// Get maximum amount for either OCEAN or datatoken
|
// Get maximum amount for either OCEAN or datatoken
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !isAssetNetwork || !price || price.value === 0) return
|
if (!isAssetNetwork || !price || price.value === 0) return
|
||||||
|
|
||||||
async function getMaximum() {
|
async function getMaximum() {
|
||||||
const maxTokensInPool = await ocean.pool.getDTMaxBuyQuantity(
|
// const maxTokensInPool = await ocean.pool.getDTMaxBuyQuantity(
|
||||||
price.address
|
// price.address
|
||||||
)
|
// )
|
||||||
|
// setMaxDt(
|
||||||
setMaxDt(
|
// isValidNumber(maxTokensInPool)
|
||||||
isValidNumber(maxTokensInPool)
|
// ? new Decimal(maxTokensInPool).toString()
|
||||||
? new Decimal(maxTokensInPool).toString()
|
// : '0'
|
||||||
: '0'
|
// )
|
||||||
)
|
// const maxOceanInPool = await ocean.pool.getOceanMaxBuyQuantity(
|
||||||
|
// price.address
|
||||||
const maxOceanInPool = await ocean.pool.getOceanMaxBuyQuantity(
|
// )
|
||||||
price.address
|
// setMaxOcean(
|
||||||
)
|
// isValidNumber(maxOceanInPool)
|
||||||
|
// ? new Decimal(maxOceanInPool).toString()
|
||||||
setMaxOcean(
|
// : '0'
|
||||||
isValidNumber(maxOceanInPool)
|
// )
|
||||||
? new Decimal(maxOceanInPool).toString()
|
|
||||||
: '0'
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
getMaximum()
|
getMaximum()
|
||||||
}, [ocean, balance.ocean, price])
|
}, [isAssetNetwork, balance.ocean, price])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormTrade
|
<FormTrade
|
||||||
|
@ -26,7 +26,6 @@ export default function AssetActions({
|
|||||||
price: BestPrice
|
price: BestPrice
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { accountId, balance } = useWeb3()
|
const { accountId, balance } = useWeb3()
|
||||||
const { ocean, account } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const { values } = useFormikContext<FormPublishData>()
|
const { values } = useFormikContext<FormPublishData>()
|
||||||
|
|
||||||
@ -87,25 +86,25 @@ export default function AssetActions({
|
|||||||
|
|
||||||
// Get and set user DT balance
|
// Get and set user DT balance
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean || !accountId || !isAssetNetwork) return
|
if (!accountId || !isAssetNetwork) return
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
const dtBalance = await ocean.datatokens.balance(
|
// const dtBalance = await ocean.datatokens.balance(
|
||||||
ddo.services[0].datatokenAddress,
|
// ddo.services[0].datatokenAddress,
|
||||||
accountId
|
// accountId
|
||||||
)
|
// )
|
||||||
setDtBalance(dtBalance)
|
// setDtBalance(dtBalance)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(e.message)
|
LoggerInstance.error(e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
}, [ocean, accountId, ddo, isAssetNetwork])
|
}, [accountId, ddo, isAssetNetwork])
|
||||||
|
|
||||||
// Check user balance against price
|
// Check user balance against price
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (price?.type === 'free') setIsBalanceSufficient(true)
|
if (price?.type === 'free') setIsBalanceSufficient(true)
|
||||||
if (!price?.value || !account || !balance?.ocean || !dtBalance) return
|
if (!price?.value || !accountId || !balance?.ocean || !dtBalance) return
|
||||||
|
|
||||||
setIsBalanceSufficient(
|
setIsBalanceSufficient(
|
||||||
compareAsBN(balance.ocean, `${price.value}`) || Number(dtBalance) >= 1
|
compareAsBN(balance.ocean, `${price.value}`) || Number(dtBalance) >= 1
|
||||||
@ -114,7 +113,7 @@ export default function AssetActions({
|
|||||||
return () => {
|
return () => {
|
||||||
setIsBalanceSufficient(false)
|
setIsBalanceSufficient(false)
|
||||||
}
|
}
|
||||||
}, [balance, account, price, dtBalance])
|
}, [balance, accountId, price, dtBalance])
|
||||||
|
|
||||||
const UseContent = isCompute ? (
|
const UseContent = isCompute ? (
|
||||||
<Compute
|
<Compute
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { ServiceComputePrivacy } from '@oceanprotocol/lib'
|
import { ServiceComputeOptions } from '@oceanprotocol/lib'
|
||||||
import React, { ReactElement, useEffect, useState } from 'react'
|
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'
|
import DebugOutput from '@shared/DebugOutput'
|
||||||
|
|
||||||
export default function DebugEditCompute({
|
export default function DebugEditCompute({
|
||||||
@ -11,22 +10,16 @@ export default function DebugEditCompute({
|
|||||||
values: ComputePrivacyForm
|
values: ComputePrivacyForm
|
||||||
ddo: Asset
|
ddo: Asset
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean } = useOcean()
|
|
||||||
const [formTransformed, setFormTransformed] =
|
const [formTransformed, setFormTransformed] =
|
||||||
useState<ServiceComputePrivacy>()
|
useState<ServiceComputeOptions>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ocean) return
|
// async function transformValues() {
|
||||||
|
// const privacy = await transformComputeFormToServiceComputePrivacy(values)
|
||||||
async function transformValues() {
|
// setFormTransformed(privacy)
|
||||||
const privacy = await transformComputeFormToServiceComputePrivacy(
|
// }
|
||||||
values,
|
// transformValues()
|
||||||
ocean
|
}, [values, ddo])
|
||||||
)
|
|
||||||
setFormTransformed(privacy)
|
|
||||||
}
|
|
||||||
transformValues()
|
|
||||||
}, [values, ddo, ocean])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
import { Formik } from 'formik'
|
import { Formik } from 'formik'
|
||||||
import React, { ReactElement, useState } from 'react'
|
import React, { ReactElement, useState } from 'react'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import FormEditComputeDataset from './FormEditComputeDataset'
|
import FormEditComputeDataset from './FormEditComputeDataset'
|
||||||
import { LoggerInstance, ServiceComputePrivacy } from '@oceanprotocol/lib'
|
import { LoggerInstance, ServiceComputeOptions } from '@oceanprotocol/lib'
|
||||||
import { useUserPreferences } from '@context/UserPreferences'
|
import { useUserPreferences } from '@context/UserPreferences'
|
||||||
import DebugEditCompute from './DebugEditCompute'
|
import DebugEditCompute from './DebugEditCompute'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
|
// import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
|
||||||
import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice'
|
import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice'
|
||||||
import Web3Feedback from '@shared/Web3Feedback'
|
import Web3Feedback from '@shared/Web3Feedback'
|
||||||
import { getInitialValues, validationSchema } from './_constants'
|
import { getInitialValues, validationSchema } from './_constants'
|
||||||
@ -20,7 +19,6 @@ export default function EditComputeDataset({
|
|||||||
setShowEdit: (show: boolean) => void
|
setShowEdit: (show: boolean) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
const { ddo, price, isAssetNetwork, refreshDdo } = useAsset()
|
const { ddo, price, isAssetNetwork, refreshDdo } = useAsset()
|
||||||
const [success, setSuccess] = useState<string>()
|
const [success, setSuccess] = useState<string>()
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { FormikContextType, useFormikContext } from 'formik'
|
import { FormikContextType, useFormikContext } from 'formik'
|
||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement } from 'react'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { useWeb3 } from '@context/Web3'
|
|
||||||
import Button from '@shared/atoms/Button'
|
import Button from '@shared/atoms/Button'
|
||||||
import styles from './FormActions.module.css'
|
import styles from './FormActions.module.css'
|
||||||
|
|
||||||
@ -13,8 +11,6 @@ export default function FormActions({
|
|||||||
setShowEdit: (show: boolean) => void
|
setShowEdit: (show: boolean) => void
|
||||||
handleClick?: () => void
|
handleClick?: () => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { accountId } = useWeb3()
|
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { isAssetNetwork } = useAsset()
|
const { isAssetNetwork } = useAsset()
|
||||||
const { isValid }: FormikContextType<Partial<any>> = useFormikContext()
|
const { isValid }: FormikContextType<Partial<any>> = useFormikContext()
|
||||||
|
|
||||||
@ -22,7 +18,7 @@ export default function FormActions({
|
|||||||
<footer className={styles.actions}>
|
<footer className={styles.actions}>
|
||||||
<Button
|
<Button
|
||||||
style="primary"
|
style="primary"
|
||||||
disabled={!ocean || !accountId || !isValid || !isAssetNetwork}
|
disabled={!isValid || !isAssetNetwork}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
transformDDOToAssetSelection
|
transformDDOToAssetSelection
|
||||||
} from '@utils/aquarius'
|
} from '@utils/aquarius'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanprotocol/lib'
|
import { PublisherTrustedAlgorithm } from '@oceanprotocol/lib'
|
||||||
import { useSiteMetadata } from '@hooks/useSiteMetadata'
|
import { useSiteMetadata } from '@hooks/useSiteMetadata'
|
||||||
import FormActions from './FormActions'
|
import FormActions from './FormActions'
|
||||||
import { useCancelToken } from '@hooks/useCancelToken'
|
import { useCancelToken } from '@hooks/useCancelToken'
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { mapTimeoutStringToSeconds, secondsToString } from '@utils/ddo'
|
import { mapTimeoutStringToSeconds, secondsToString } from '@utils/ddo'
|
||||||
import { EditableMetadataLinks } from '@oceanprotocol/lib'
|
// import { EditableMetadataLinks } from '@oceanprotocol/lib'
|
||||||
import * as Yup from 'yup'
|
import * as Yup from 'yup'
|
||||||
import { MetadataEditForm } from './_types'
|
import { MetadataEditForm } from './_types'
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ export const validationSchema = Yup.object().shape({
|
|||||||
.required('Required'),
|
.required('Required'),
|
||||||
description: Yup.string().required('Required').min(10),
|
description: Yup.string().required('Required').min(10),
|
||||||
price: Yup.number().required('Required'),
|
price: Yup.number().required('Required'),
|
||||||
links: Yup.array<EditableMetadataLinks[]>().nullable(),
|
links: Yup.array<any[]>().nullable(),
|
||||||
timeout: Yup.string().required('Required'),
|
timeout: Yup.string().required('Required'),
|
||||||
author: Yup.string().nullable()
|
author: Yup.string().nullable()
|
||||||
})
|
})
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { EditableMetadataLinks } from '@oceanprotocol/lib'
|
// import { EditableMetadataLinks } from '@oceanprotocol/lib'
|
||||||
|
|
||||||
export interface MetadataEditForm {
|
export interface MetadataEditForm {
|
||||||
name: string
|
name: string
|
||||||
description: string
|
description: string
|
||||||
timeout: number
|
timeout: number
|
||||||
price?: number
|
price?: number
|
||||||
links?: string | EditableMetadataLinks[]
|
links?: string | any[]
|
||||||
author?: string
|
author?: string
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import { getServiceByName, mapTimeoutStringToSeconds } from '@utils/ddo'
|
|||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import { LoggerInstance } from '@oceanprotocol/lib'
|
import { LoggerInstance } from '@oceanprotocol/lib'
|
||||||
import { useWeb3 } from '@context/Web3'
|
import { useWeb3 } from '@context/Web3'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice'
|
import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice'
|
||||||
import content from '../../../../content/pages/edit.json'
|
import content from '../../../../content/pages/edit.json'
|
||||||
import { MetadataEditForm } from './_types'
|
import { MetadataEditForm } from './_types'
|
||||||
@ -24,7 +23,6 @@ export default function Edit({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
const { ocean } = useOcean()
|
|
||||||
const { ddo, refreshDdo, price } = useAsset()
|
const { ddo, refreshDdo, price } = useAsset()
|
||||||
const [success, setSuccess] = useState<string>()
|
const [success, setSuccess] = useState<string>()
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
@ -34,15 +32,15 @@ export default function Edit({
|
|||||||
const hasFeedback = error || success
|
const hasFeedback = error || success
|
||||||
|
|
||||||
async function updateFixedPrice(newPrice: number) {
|
async function updateFixedPrice(newPrice: number) {
|
||||||
const setPriceResp = await ocean.fixedRateExchange.setRate(
|
// const setPriceResp = await ocean.fixedRateExchange.setRate(
|
||||||
price.address,
|
// price.address,
|
||||||
newPrice,
|
// newPrice,
|
||||||
accountId
|
// accountId
|
||||||
)
|
// )
|
||||||
if (!setPriceResp) {
|
// if (!setPriceResp) {
|
||||||
setError(content.form.error)
|
// setError(content.form.error)
|
||||||
LoggerInstance.error(content.form.error)
|
// LoggerInstance.error(content.form.error)
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSubmit(
|
async function handleSubmit(
|
||||||
|
@ -97,12 +97,12 @@ export default function Details({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<MetaItem title="Job ID" content={<code>{job.jobId}</code>} />
|
<MetaItem title="Job ID" content={<code>{job.jobId}</code>} />
|
||||||
{job.resultsDid && (
|
{/* {job.resultsDid && (
|
||||||
<MetaItem
|
<MetaItem
|
||||||
title="Published Results DID"
|
title="Published Results DID"
|
||||||
content={<code>{job.resultsDid}</code>}
|
content={<code>{job.resultsDid}</code>}
|
||||||
/>
|
/>
|
||||||
)}
|
)} */}
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</>
|
</>
|
||||||
|
@ -3,37 +3,37 @@ import React, { ReactElement, useState } from 'react'
|
|||||||
import Loader from '@shared/atoms/Loader'
|
import Loader from '@shared/atoms/Loader'
|
||||||
import { ListItem } from '@shared/atoms/Lists'
|
import { ListItem } from '@shared/atoms/Lists'
|
||||||
import Button from '@shared/atoms/Button'
|
import Button from '@shared/atoms/Button'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import styles from './Results.module.css'
|
import styles from './Results.module.css'
|
||||||
import FormHelp from '@shared/FormInput/Help'
|
import FormHelp from '@shared/FormInput/Help'
|
||||||
import content from '../../../../../content/pages/history.json'
|
import content from '../../../../../content/pages/history.json'
|
||||||
|
import { useWeb3 } from '@context/Web3'
|
||||||
|
|
||||||
export default function Results({
|
export default function Results({
|
||||||
job
|
job
|
||||||
}: {
|
}: {
|
||||||
job: ComputeJobMetaData
|
job: ComputeJobMetaData
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean, account } = useOcean()
|
const { accountId } = useWeb3()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const [hasFetched, setHasFetched] = useState(false)
|
const [hasFetched, setHasFetched] = useState(false)
|
||||||
const isFinished = job.dateFinished !== null
|
const isFinished = job.dateFinished !== null
|
||||||
|
|
||||||
async function getResults() {
|
async function getResults() {
|
||||||
if (!account || !ocean || !job) return
|
if (!accountId || !job) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
const jobStatus = await ocean.compute.status(
|
// const jobStatus = await ocean.compute.status(
|
||||||
account,
|
// account,
|
||||||
job.did,
|
// job.did,
|
||||||
undefined,
|
// undefined,
|
||||||
undefined,
|
// undefined,
|
||||||
job.jobId
|
// job.jobId
|
||||||
)
|
// )
|
||||||
if (jobStatus?.length > 0) {
|
// if (jobStatus?.length > 0) {
|
||||||
job.algorithmLogUrl = jobStatus[0].algorithmLogUrl
|
// job.algorithmLogUrl = jobStatus[0].algorithmLogUrl
|
||||||
job.resultsUrl = jobStatus[0].resultsUrl
|
// job.resultsUrl = jobStatus[0].resultsUrl
|
||||||
}
|
// }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(error.message)
|
LoggerInstance.error(error.message)
|
||||||
} finally {
|
} finally {
|
||||||
@ -47,16 +47,16 @@ export default function Results({
|
|||||||
{hasFetched ? (
|
{hasFetched ? (
|
||||||
<ul>
|
<ul>
|
||||||
<ListItem>
|
<ListItem>
|
||||||
{job.algorithmLogUrl ? (
|
{/* {job.algorithmLogUrl ? (
|
||||||
<a href={job.algorithmLogUrl} target="_blank" rel="noreferrer">
|
<a href={job.algorithmLogUrl} target="_blank" rel="noreferrer">
|
||||||
View Log
|
View Log
|
||||||
</a>
|
</a>
|
||||||
) : (
|
) : (
|
||||||
'No logs found.'
|
'No logs found.'
|
||||||
)}
|
)} */}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|
||||||
{job.resultsUrl &&
|
{/* {job.resultsUrl &&
|
||||||
Array.isArray(job.resultsUrl) &&
|
Array.isArray(job.resultsUrl) &&
|
||||||
job.resultsUrl.map((url, i) =>
|
job.resultsUrl.map((url, i) =>
|
||||||
url ? (
|
url ? (
|
||||||
@ -68,7 +68,7 @@ export default function Results({
|
|||||||
) : (
|
) : (
|
||||||
<ListItem>No results found.</ListItem>
|
<ListItem>No results found.</ListItem>
|
||||||
)
|
)
|
||||||
)}
|
)} */}
|
||||||
</ul>
|
</ul>
|
||||||
) : (
|
) : (
|
||||||
<Button
|
<Button
|
||||||
|
@ -12,7 +12,7 @@ import Refresh from '@images/refresh.svg'
|
|||||||
import { useUserPreferences } from '@context/UserPreferences'
|
import { useUserPreferences } from '@context/UserPreferences'
|
||||||
import { getOceanConfig } from '@utils/ocean'
|
import { getOceanConfig } from '@utils/ocean'
|
||||||
import NetworkName from '@shared/NetworkName'
|
import NetworkName from '@shared/NetworkName'
|
||||||
import { getComputeJobs } from '@utils/compute'
|
// import { getComputeJobs } from '@utils/compute'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import { useAsset } from '@context/Asset'
|
import { useAsset } from '@context/Asset'
|
||||||
import { useIsMounted } from '@hooks/useIsMounted'
|
import { useIsMounted } from '@hooks/useIsMounted'
|
||||||
@ -75,7 +75,7 @@ export default function ComputeJobs({
|
|||||||
}: {
|
}: {
|
||||||
minimal?: boolean
|
minimal?: boolean
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { ocean, account, config, connect } = useOcean()
|
const { config } = useOcean()
|
||||||
const { accountId, networkId } = useWeb3()
|
const { accountId, networkId } = useWeb3()
|
||||||
const { ddo } = useAsset()
|
const { ddo } = useAsset()
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
@ -85,15 +85,15 @@ export default function ComputeJobs({
|
|||||||
|
|
||||||
const columnsMinimal = [columns[4], columns[5], columns[3]]
|
const columnsMinimal = [columns[4], columns[5], columns[3]]
|
||||||
|
|
||||||
useEffect(() => {
|
// useEffect(() => {
|
||||||
async function initOcean() {
|
// async function initOcean() {
|
||||||
const oceanInitialConfig = getOceanConfig(networkId)
|
// const oceanInitialConfig = getOceanConfig(networkId)
|
||||||
await connect(oceanInitialConfig)
|
// await connect(oceanInitialConfig)
|
||||||
}
|
// }
|
||||||
if (ocean === undefined) {
|
// if (ocean === undefined) {
|
||||||
initOcean()
|
// initOcean()
|
||||||
}
|
// }
|
||||||
}, [networkId, ocean, connect])
|
// }, [networkId])
|
||||||
|
|
||||||
const fetchJobs = useCallback(async () => {
|
const fetchJobs = useCallback(async () => {
|
||||||
if (!chainIds || chainIds.length === 0 || !accountId) {
|
if (!chainIds || chainIds.length === 0 || !accountId) {
|
||||||
@ -103,13 +103,13 @@ export default function ComputeJobs({
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
const jobs = await getComputeJobs(chainIds, config, ocean, account, ddo)
|
// const jobs = await getComputeJobs(chainIds, config, ocean, account, ddo)
|
||||||
isMounted() && setJobs(jobs.computeJobs)
|
// isMounted() && setJobs(jobs.computeJobs)
|
||||||
setIsLoading(jobs.isLoaded)
|
// setIsLoading(jobs.isLoaded)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(error.message)
|
LoggerInstance.error(error.message)
|
||||||
}
|
}
|
||||||
}, [chainIds, accountId, config, ocean, account, ddo, isMounted])
|
}, [chainIds, accountId, config, ddo, isMounted])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchJobs()
|
fetchJobs()
|
||||||
|
Loading…
Reference in New Issue
Block a user