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

setting inital payment collector from EditMetadata

This commit is contained in:
Jamie Hewitt 2022-11-15 10:45:14 +03:00
parent 9429af22e2
commit e22407ad43
2 changed files with 31 additions and 14 deletions

View File

@ -1,11 +1,12 @@
import React, { ReactElement, useState } from 'react' import React, { ReactElement, useState, useEffect } from 'react'
import { Formik } from 'formik' import { Formik } from 'formik'
import { import {
LoggerInstance, LoggerInstance,
Metadata, Metadata,
FixedRateExchange, FixedRateExchange,
Asset, Asset,
Service Service,
Datatoken
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { validationSchema } from './_validation' import { validationSchema } from './_validation'
import { getInitialValues } from './_constants' import { getInitialValues } from './_constants'
@ -36,10 +37,30 @@ export default function Edit({
const { accountId, web3 } = useWeb3() const { accountId, web3 } = useWeb3()
const newAbortController = useAbortController() const newAbortController = useAbortController()
const [success, setSuccess] = useState<string>() const [success, setSuccess] = useState<string>()
const [paymentCollector, setPaymentCollector] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const isComputeType = asset?.services[0]?.type === 'compute' const isComputeType = asset?.services[0]?.type === 'compute'
const hasFeedback = error || success 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) { async function updateFixedPrice(newPrice: string) {
const config = getOceanConfig(asset.chainId) const config = getOceanConfig(asset.chainId)
@ -145,10 +166,10 @@ export default function Edit({
<Formik <Formik
enableReinitialize enableReinitialize
initialValues={getInitialValues( initialValues={getInitialValues(
asset?.nft.owner,
asset?.metadata, asset?.metadata,
asset?.services[0]?.timeout, asset?.services[0]?.timeout,
asset?.accessDetails?.price asset?.accessDetails?.price,
paymentCollector
)} )}
validationSchema={validationSchema} validationSchema={validationSchema}
onSubmit={async (values, { resetForm }) => { onSubmit={async (values, { resetForm }) => {

View File

@ -1,18 +1,14 @@
import { import { Metadata, ServiceComputeOptions, Datatoken } from '@oceanprotocol/lib'
Metadata,
ServiceComputeOptions,
getPaymentCollector
} from '@oceanprotocol/lib'
import { secondsToString } from '@utils/ddo' import { secondsToString } from '@utils/ddo'
import { ComputeEditForm, MetadataEditForm } from './_types' import { ComputeEditForm, MetadataEditForm } from './_types'
import Web3 from 'web3'
export async function getInitialValues( export function getInitialValues(
owner: string,
metadata: Metadata, metadata: Metadata,
timeout: number, timeout: number,
price: string price: string,
): Promise<Partial<MetadataEditForm>> { paymentCollector: string
const paymentCollector = await getPaymentCollector(owner) ): Partial<MetadataEditForm> {
return { return {
name: metadata?.name, name: metadata?.name,
description: metadata?.description, description: metadata?.description,