From e1168a451dfa40102176ef640519d47bfb9a47c6 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Thu, 23 Jun 2022 08:04:39 +0300 Subject: [PATCH] move isOwner to asset provider --- src/@context/Asset.tsx | 5 +++++ src/components/Asset/AssetContent/index.tsx | 19 +------------------ 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/@context/Asset.tsx b/src/@context/Asset.tsx index abaed455f..6c0850af0 100644 --- a/src/@context/Asset.tsx +++ b/src/@context/Asset.tsx @@ -27,6 +27,7 @@ export interface AssetProviderValue { error?: string isAssetNetwork: boolean isV3Asset: boolean + isOwner: boolean oceanConfig: Config loading: boolean fetchAsset: (token?: CancelToken) => Promise @@ -49,6 +50,7 @@ function AssetProvider({ const [asset, setAsset] = useState() const [title, setTitle] = useState() const [owner, setOwner] = useState() + const [isOwner, setIsOwner] = useState() const [error, setError] = useState() const [loading, setLoading] = useState(false) const [isAssetNetwork, setIsAssetNetwork] = useState() @@ -84,6 +86,7 @@ function AssetProvider({ })) setTitle(asset.metadata?.name) setOwner(asset.nft?.owner) + setIsOwner(accountId?.toLowerCase() === asset?.nft?.owner.toLowerCase()) setIsInPurgatory(asset.purgatory?.state) setPurgatoryData(asset.purgatory) LoggerInstance.log('[asset] Got asset', asset) @@ -127,6 +130,7 @@ function AssetProvider({ useEffect(() => { if (!isMounted) return + setIsOwner(accountId?.toLowerCase() === asset?.nft?.owner.toLowerCase()) fetchAccessDetails() }, [accountId, fetchAccessDetails, isMounted]) @@ -172,6 +176,7 @@ function AssetProvider({ fetchAsset, isAssetNetwork, isV3Asset, + isOwner, oceanConfig } as AssetProviderValue } diff --git a/src/components/Asset/AssetContent/index.tsx b/src/components/Asset/AssetContent/index.tsx index e493c3853..b7caf86e6 100644 --- a/src/components/Asset/AssetContent/index.tsx +++ b/src/components/Asset/AssetContent/index.tsx @@ -15,7 +15,6 @@ import styles from './index.module.css' import NetworkName from '@shared/NetworkName' import content from '../../../../content/purgatory.json' import { AssetExtended } from 'src/@types/AssetExtended' -import { useWeb3 } from '@context/Web3' import Web3 from 'web3' export default function AssetContent({ @@ -23,9 +22,7 @@ export default function AssetContent({ }: { asset: AssetExtended }): ReactElement { - const [isOwner, setIsOwner] = useState(false) - const { accountId } = useWeb3() - const { isInPurgatory, purgatoryData, owner, isAssetNetwork } = useAsset() + const { isInPurgatory, purgatoryData, isOwner, isAssetNetwork } = useAsset() const { debug } = useUserPreferences() const [receipts, setReceipts] = useState([]) const [nftPublisher, setNftPublisher] = useState() @@ -38,20 +35,6 @@ export default function AssetContent({ ) }, [receipts]) - useEffect(() => { - if (!accountId || !owner) return - - const isOwner = accountId.toLowerCase() === owner.toLowerCase() - setIsOwner(isOwner) - }, [accountId, owner, asset]) - - useEffect(() => { - if (!accountId || !owner) return - - const isOwner = accountId.toLowerCase() === owner.toLowerCase() - setIsOwner(isOwner) - }, [accountId, asset?.accessDetails, owner, asset]) - return ( <>