diff --git a/src/components/Asset/Edit/EditMetadata.tsx b/src/components/Asset/Edit/EditMetadata.tsx index 26639b0c3..f5eab1bdf 100644 --- a/src/components/Asset/Edit/EditMetadata.tsx +++ b/src/components/Asset/Edit/EditMetadata.tsx @@ -1,11 +1,12 @@ -import React, { ReactElement, useState } from 'react' +import React, { ReactElement, useState, useEffect } from 'react' import { Formik } from 'formik' import { LoggerInstance, Metadata, FixedRateExchange, Asset, - Service + Service, + Datatoken } from '@oceanprotocol/lib' import { validationSchema } from './_validation' import { getInitialValues } from './_constants' @@ -36,10 +37,30 @@ export default function Edit({ const { accountId, web3 } = useWeb3() const newAbortController = useAbortController() const [success, setSuccess] = useState() + const [paymentCollector, setPaymentCollector] = useState() const [error, setError] = useState() const isComputeType = asset?.services[0]?.type === 'compute' const hasFeedback = error || success + useEffect(() => { + async function getInitialPaymentCollector() { + let paymentCollector + try { + console.log('owner', asset?.nft.owner) + const datatoken = new Datatoken(web3) + console.log('datatoken', datatoken) + paymentCollector = await datatoken.getPaymentCollector( + asset?.datatokens[0].address + ) + console.log('paymentCollector', paymentCollector) + setPaymentCollector(paymentCollector) + } catch (error) { + console.log(error) + } + } + getInitialPaymentCollector() + }, [asset]) + async function updateFixedPrice(newPrice: string) { const config = getOceanConfig(asset.chainId) @@ -145,10 +166,10 @@ export default function Edit({ { diff --git a/src/components/Asset/Edit/_constants.ts b/src/components/Asset/Edit/_constants.ts index 703955330..35ba73258 100644 --- a/src/components/Asset/Edit/_constants.ts +++ b/src/components/Asset/Edit/_constants.ts @@ -1,18 +1,14 @@ -import { - Metadata, - ServiceComputeOptions, - getPaymentCollector -} from '@oceanprotocol/lib' +import { Metadata, ServiceComputeOptions, Datatoken } from '@oceanprotocol/lib' import { secondsToString } from '@utils/ddo' import { ComputeEditForm, MetadataEditForm } from './_types' +import Web3 from 'web3' -export async function getInitialValues( - owner: string, +export function getInitialValues( metadata: Metadata, timeout: number, - price: string -): Promise> { - const paymentCollector = await getPaymentCollector(owner) + price: string, + paymentCollector: string +): Partial { return { name: metadata?.name, description: metadata?.description,