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

move isOwner to asset provider

This commit is contained in:
Bogdan Fazakas 2022-06-23 08:04:39 +03:00
parent a030cdecdb
commit e1168a451d
2 changed files with 6 additions and 18 deletions

View File

@ -27,6 +27,7 @@ export interface AssetProviderValue {
error?: string
isAssetNetwork: boolean
isV3Asset: boolean
isOwner: boolean
oceanConfig: Config
loading: boolean
fetchAsset: (token?: CancelToken) => Promise<void>
@ -49,6 +50,7 @@ function AssetProvider({
const [asset, setAsset] = useState<AssetExtended>()
const [title, setTitle] = useState<string>()
const [owner, setOwner] = useState<string>()
const [isOwner, setIsOwner] = useState<boolean>()
const [error, setError] = useState<string>()
const [loading, setLoading] = useState(false)
const [isAssetNetwork, setIsAssetNetwork] = useState<boolean>()
@ -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
}

View File

@ -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<string>()
@ -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 (
<>
<div className={styles.networkWrap}>