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

fix asset route (#1836)

This commit is contained in:
mihaisc 2023-01-02 17:56:55 +02:00 committed by GitHub
parent 3c9dd3bbd0
commit 686f4d1803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import { getOceanConfig, getDevelopmentConfig } from '@utils/ocean'
import { getAccessDetails } from '@utils/accessDetailsAndPricing' import { getAccessDetails } from '@utils/accessDetailsAndPricing'
import { useIsMounted } from '@hooks/useIsMounted' import { useIsMounted } from '@hooks/useIsMounted'
import { useMarketMetadata } from './MarketMetadata' import { useMarketMetadata } from './MarketMetadata'
import { isValidDid } from '@utils/ddo'
export interface AssetProviderValue { export interface AssetProviderValue {
isInPurgatory: boolean isInPurgatory: boolean
@ -63,6 +64,13 @@ function AssetProvider({
const fetchAsset = useCallback( const fetchAsset = useCallback(
async (token?: CancelToken) => { async (token?: CancelToken) => {
if (!did) return 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...') LoggerInstance.log('[asset] Fetching asset...')
setLoading(true) setLoading(true)

View File

@ -1,5 +1,10 @@
import { Asset, DDO, Service } from '@oceanprotocol/lib' 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( export function getServiceByName(
ddo: Asset | DDO, ddo: Asset | DDO,
name: 'access' | 'compute' name: 'access' | 'compute'