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

rewrite getPaymentCollector()

This commit is contained in:
Matthias Kretschmann 2023-02-13 10:30:15 +00:00
parent 51470343fd
commit 074a6ccd13
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 27 additions and 9 deletions

View File

@ -1,5 +1,7 @@
import { ConfigHelper, Config } from '@oceanprotocol/lib'
// import contractAddresses from '@oceanprotocol/contracts/artifacts/address.json'
import { ethers } from 'ethers'
import abiDatatoken from '@oceanprotocol/contracts/artifacts/contracts/interfaces/IERC20Template.sol/IERC20Template.json'
export function getOceanConfig(network: string | number): Config {
const config = new ConfigHelper().getConfig(
@ -28,3 +30,17 @@ export function getDevelopmentConfig(): Config {
subgraphUri: 'https://v4.subgraph.goerli.oceanprotocol.com'
} 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

@ -3,24 +3,26 @@ import MetaItem from './MetaItem'
import styles from './MetaFull.module.css'
import Publisher from '@shared/Publisher'
import { useAsset } from '@context/Asset'
import { Asset, Datatoken, LoggerInstance } from '@oceanprotocol/lib'
import { useWeb3Legacy } from '@context/Web3Legacy'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { getPaymentCollector } from '@utils/ocean'
import { useProvider } from 'wagmi'
export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
const { isInPurgatory, assetState } = useAsset()
const { web3 } = useWeb3Legacy()
const provider = useProvider()
const [paymentCollector, setPaymentCollector] = useState<string>()
useEffect(() => {
if (!ddo || !web3) return
if (!ddo || !provider) return
async function getInitialPaymentCollector() {
try {
const datatoken = new Datatoken(web3)
setPaymentCollector(
await datatoken.getPaymentCollector(ddo.datatokens[0].address)
const paymentCollector = await getPaymentCollector(
ddo.datatokens[0].address,
provider
)
setPaymentCollector(paymentCollector)
} catch (error) {
LoggerInstance.error(
'[MetaFull: getInitialPaymentCollector]',
@ -29,7 +31,7 @@ export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
}
}
getInitialPaymentCollector()
}, [ddo, web3])
}, [ddo, provider])
function DockerImage() {
const containerInfo = ddo?.metadata?.algorithm?.container