From 686f4d1803f1e68d43d997a7fb3f7b33fc3cdaf1 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Mon, 2 Jan 2023 17:56:55 +0200 Subject: [PATCH] fix asset route (#1836) --- src/@context/Asset.tsx | 8 ++++++++ src/@utils/ddo.ts | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/@context/Asset.tsx b/src/@context/Asset.tsx index ce473e339..5c1b75367 100644 --- a/src/@context/Asset.tsx +++ b/src/@context/Asset.tsx @@ -16,6 +16,7 @@ import { getOceanConfig, getDevelopmentConfig } from '@utils/ocean' import { getAccessDetails } from '@utils/accessDetailsAndPricing' import { useIsMounted } from '@hooks/useIsMounted' import { useMarketMetadata } from './MarketMetadata' +import { isValidDid } from '@utils/ddo' export interface AssetProviderValue { isInPurgatory: boolean @@ -63,6 +64,13 @@ function AssetProvider({ const fetchAsset = useCallback( async (token?: CancelToken) => { if (!did) return + const isDid = isValidDid(did) + + if (!isDid) { + setError(`The url is not for a valid DID`) + LoggerInstance.error(`[asset] Not a valid DID`) + return + } LoggerInstance.log('[asset] Fetching asset...') setLoading(true) diff --git a/src/@utils/ddo.ts b/src/@utils/ddo.ts index 0bc817e4f..d477e201b 100644 --- a/src/@utils/ddo.ts +++ b/src/@utils/ddo.ts @@ -1,5 +1,10 @@ import { Asset, DDO, Service } from '@oceanprotocol/lib' +export function isValidDid(did: string): boolean { + const regex = /did:op:[A-Za-z0-9]{64}/ + return regex.test(did) +} + export function getServiceByName( ddo: Asset | DDO, name: 'access' | 'compute'