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

kick out getPaymentCollector completely, use wagmi hooks instead

This commit is contained in:
Matthias Kretschmann 2023-02-13 10:38:15 +00:00
parent 074a6ccd13
commit 54c7d1ef1a
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 16 additions and 39 deletions

View File

@ -30,17 +30,3 @@ export function getDevelopmentConfig(): Config {
subgraphUri: 'https://v4.subgraph.goerli.oceanprotocol.com' subgraphUri: 'https://v4.subgraph.goerli.oceanprotocol.com'
} as Config } as Config
} }
/**
* getPaymentCollector - returns the current paymentCollector
* @param dtAddress datatoken address
* @return {Promise<string>}
*/
export async function getPaymentCollector(
dtAddress: string,
provider: ethers.providers.Provider
): Promise<string> {
const dtContract = new ethers.Contract(dtAddress, abiDatatoken.abi, provider)
const paymentCollector = await dtContract.getPaymentCollector()
return paymentCollector
}

View File

@ -1,37 +1,28 @@
import React, { ReactElement, useState, useEffect } from 'react' import React, { ReactElement } from 'react'
import MetaItem from './MetaItem' import MetaItem from './MetaItem'
import styles from './MetaFull.module.css' import styles from './MetaFull.module.css'
import Publisher from '@shared/Publisher' import Publisher from '@shared/Publisher'
import { useAsset } from '@context/Asset' import { useAsset } from '@context/Asset'
import { Asset, LoggerInstance } from '@oceanprotocol/lib' import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { getPaymentCollector } from '@utils/ocean' import { useContractRead } from 'wagmi'
import { useProvider } from 'wagmi'
import abiDatatoken from '@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json'
export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement { export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
const { isInPurgatory, assetState } = useAsset() const { isInPurgatory, assetState } = useAsset()
const provider = useProvider() const { data: paymentCollector, error }: { data: string; error: Error } =
useContractRead({
address: ddo?.datatokens[0].address,
abi: abiDatatoken.abi,
functionName: 'getPaymentCollector'
})
const [paymentCollector, setPaymentCollector] = useState<string>() if (error) {
useEffect(() => {
if (!ddo || !provider) return
async function getInitialPaymentCollector() {
try {
const paymentCollector = await getPaymentCollector(
ddo.datatokens[0].address,
provider
)
setPaymentCollector(paymentCollector)
} catch (error) {
LoggerInstance.error( LoggerInstance.error(
'[MetaFull: getInitialPaymentCollector]', '[MetaFull: getInitialPaymentCollector]',
error.message error.message
) )
} }
}
getInitialPaymentCollector()
}, [ddo, provider])
function DockerImage() { function DockerImage() {
const containerInfo = ddo?.metadata?.algorithm?.container const containerInfo = ddo?.metadata?.algorithm?.container