From 857f922e97b58cf70f7f2607df1b362a59dfe276 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Fri, 3 Feb 2023 16:01:47 +0200 Subject: [PATCH] update payment collector --- src/@context/Asset.tsx | 8 +++++-- .../Asset/AssetContent/MetaFull.tsx | 23 ++----------------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/@context/Asset.tsx b/src/@context/Asset.tsx index 0b135beef..88e1b92a5 100644 --- a/src/@context/Asset.tsx +++ b/src/@context/Asset.tsx @@ -23,6 +23,7 @@ import { useIsMounted } from '@hooks/useIsMounted' import { useMarketMetadata } from './MarketMetadata' import { assetStateToString } from '@utils/assetState' import { isValidDid } from '@utils/ddo' +import { getDummyWeb3 } from '@utils/web3' export interface AssetProviderValue { isInPurgatory: boolean @@ -50,7 +51,7 @@ function AssetProvider({ }): ReactElement { const { appConfig } = useMarketMetadata() - const { chainId, accountId, web3 } = useWeb3() + const { chainId, accountId } = useWeb3() const [isInPurgatory, setIsInPurgatory] = useState(false) const [purgatoryData, setPurgatoryData] = useState() const [asset, setAsset] = useState() @@ -128,10 +129,13 @@ function AssetProvider({ async function getInitialPaymentCollector() { if (!asset?.datatokens || !asset.datatokens[0]?.address) return try { + const web3 = await getDummyWeb3(asset.chainId) const datatoken = new Datatoken(web3) + console.log('datatoken', datatoken) const paymentCollector = await datatoken.getPaymentCollector( asset.datatokens[0].address ) + console.log('paymentCollector', paymentCollector) setAsset((prevState) => ({ ...prevState, paymentCollector @@ -141,7 +145,7 @@ function AssetProvider({ } } getInitialPaymentCollector() - }, [asset?.datatokens, web3]) + }, [asset?.chainId, asset?.datatokens]) // ----------------------------------- // Helper: Get and set asset access details diff --git a/src/components/Asset/AssetContent/MetaFull.tsx b/src/components/Asset/AssetContent/MetaFull.tsx index a477df3dd..ac56bc380 100644 --- a/src/components/Asset/AssetContent/MetaFull.tsx +++ b/src/components/Asset/AssetContent/MetaFull.tsx @@ -3,33 +3,14 @@ import MetaItem from './MetaItem' import styles from './MetaFull.module.css' import Publisher from '@shared/Publisher' import { useAsset } from '@context/Asset' -import { getDummyWeb3 } from '@utils/web3' -import { Datatoken, LoggerInstance } from '@oceanprotocol/lib' export default function MetaFull({ ddo }: { ddo: AssetExtended }): ReactElement { - const [paymentCollector, setPaymentCollector] = useState() const { isInPurgatory, assetState } = useAsset() - - useEffect(() => { - async function getInitialPaymentCollector() { - try { - if (!ddo) return - const web3 = await getDummyWeb3(ddo.chainId) - const datatoken = new Datatoken(web3) - setPaymentCollector( - await datatoken.getPaymentCollector(ddo.datatokens[0].address) - ) - } catch (error) { - LoggerInstance.error('[MetaFull: getInitialPaymentCollector]', error) - } - } - getInitialPaymentCollector() - }, [ddo]) - + console.log('ddo', ddo) function DockerImage() { const containerInfo = ddo?.metadata?.algorithm?.container const { image, tag } = containerInfo @@ -48,7 +29,7 @@ export default function MetaFull({ {assetState !== 'Active' && ( )} - {paymentCollector && paymentCollector !== ddo?.nft?.owner && ( + {ddo?.paymentCollector && ddo?.paymentCollector !== ddo?.nft?.owner && ( }