From 4baee6aaffec11aaa0f55549fd188cea02f27296 Mon Sep 17 00:00:00 2001 From: EnzoVezzaro Date: Tue, 26 Jul 2022 07:48:30 -0400 Subject: [PATCH] catch nft state on asset detail (#1601) * catch nft state * use warnings for nft state * update disabled message * changes to messages * removed case 4 * change message title * fix similar block codeclimate * restore `error` state instead of `warning` * removed unnecessary warning state * removed warning completely --- src/@context/Asset.tsx | 27 ++++++++++++++++++++- src/components/Asset/AssetContent/index.tsx | 2 +- src/components/Asset/index.tsx | 4 +-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/@context/Asset.tsx b/src/@context/Asset.tsx index a554e528e..3df0c85f9 100644 --- a/src/@context/Asset.tsx +++ b/src/@context/Asset.tsx @@ -78,7 +78,32 @@ function AssetProvider({ '\n\nWe could not find an asset for this DID in the cache. If you just published a new asset, wait some seconds and refresh this page.' ) LoggerInstance.error(`[asset] Failed getting asset for ${did}`, asset) - } else { + return + } + + if (asset.nft.state) { + // handle nft states as documented in https://docs.oceanprotocol.com/concepts/did-ddo/#state + let state + switch (asset.nft.state) { + case 1: + state = 'end-of-life' + break + case 2: + state = 'deprecated' + break + case 3: + state = 'revoked' + break + } + + setTitle(`This asset has been flagged as "${state}" by the publisher`) + setIsV3Asset(await checkV3Asset(did, token)) + setError(`\`${did}\`` + `\n\nPublisher Address: ${asset.nft.owner}`) + LoggerInstance.error(`[asset] Failed getting asset for ${did}`, asset) + return + } + + if (asset) { setError(undefined) setAsset((prevState) => ({ ...prevState, diff --git a/src/components/Asset/AssetContent/index.tsx b/src/components/Asset/AssetContent/index.tsx index f9ea05266..ab779e568 100644 --- a/src/components/Asset/AssetContent/index.tsx +++ b/src/components/Asset/AssetContent/index.tsx @@ -60,7 +60,7 @@ export default function AssetContent({ <> diff --git a/src/components/Asset/index.tsx b/src/components/Asset/index.tsx index 4bd104cbe..c971fbd03 100644 --- a/src/components/Asset/index.tsx +++ b/src/components/Asset/index.tsx @@ -17,7 +17,7 @@ export default function AssetDetails({ uri }: { uri: string }): ReactElement { router.push(`${v3MarketUri}${uri}`) } if (!asset || error) { - setPageTitle('Could not retrieve asset') + setPageTitle(title || 'Could not retrieve asset') return } setPageTitle(isInPurgatory ? '' : title) @@ -29,7 +29,7 @@ export default function AssetDetails({ uri }: { uri: string }): ReactElement { ) : error && isV3Asset === false ? ( - + ) : (