From 24fd4de5845dcaaa234ecd26a277eca71d27f52e Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 4 Feb 2022 15:58:11 +0000 Subject: [PATCH] fix file info (#1061) --- src/@utils/provider.ts | 19 ++++++++++++++++++- .../@shared/FormFields/FilesInput/index.tsx | 4 ++-- src/components/Asset/AssetActions/index.tsx | 15 +++++++++------ 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/@utils/provider.ts b/src/@utils/provider.ts index 3fbae4b03..057194a3f 100644 --- a/src/@utils/provider.ts +++ b/src/@utils/provider.ts @@ -18,7 +18,24 @@ export async function getEncryptedFiles( } } -export async function getFileInfo( +export async function getFileDidInfo( + did: string, + serviceId: string, + providerUrl: string +): Promise { + try { + const response = await ProviderInstance.checkDidFiles( + did, + serviceId as any, // TODO: why does ocean.js want a number here? + providerUrl + ) + return response + } catch (error) { + LoggerInstance.error(error.message) + } +} + +export async function getFileUrlInfo( url: string, providerUrl: string ): Promise { diff --git a/src/components/@shared/FormFields/FilesInput/index.tsx b/src/components/@shared/FormFields/FilesInput/index.tsx index 504d9cab0..8336222a2 100644 --- a/src/components/@shared/FormFields/FilesInput/index.tsx +++ b/src/components/@shared/FormFields/FilesInput/index.tsx @@ -5,7 +5,7 @@ import FileInfo from './Info' import UrlInput from '../URLInput' import { InputProps } from '@shared/FormInput' import { initialValues } from 'src/components/Publish/_constants' -import { getFileInfo } from '@utils/provider' +import { getFileUrlInfo } from '@utils/provider' import { FormPublishData } from 'src/components/Publish/_types' export default function FilesInput(props: InputProps): ReactElement { @@ -19,7 +19,7 @@ export default function FilesInput(props: InputProps): ReactElement { async function validateUrl() { try { setIsLoading(true) - const checkedFile = await getFileInfo(url, providerUri) + const checkedFile = await getFileUrlInfo(url, providerUri) checkedFile && helpers.setValue([{ url, ...checkedFile[0] }]) } catch (error) { toast.error('Could not fetch file info. Please check URL and try again') diff --git a/src/components/Asset/AssetActions/index.tsx b/src/components/Asset/AssetActions/index.tsx index b15b9ead5..f79b98308 100644 --- a/src/components/Asset/AssetActions/index.tsx +++ b/src/components/Asset/AssetActions/index.tsx @@ -9,7 +9,7 @@ import Trade from './Trade' import { useAsset } from '@context/Asset' import { useWeb3 } from '@context/Web3' import Web3Feedback from '@shared/Web3Feedback' -import { getFileInfo } from '@utils/provider' +import { getFileDidInfo, getFileUrlInfo } from '@utils/provider' import { getOceanConfig } from '@utils/ocean' import { useCancelToken } from '@hooks/useCancelToken' import { useIsMounted } from '@hooks/useIsMounted' @@ -67,15 +67,18 @@ export default function AssetActions({ async function initFileInfo() { setFileIsLoading(true) - const fileUrl = - formikState?.values?.services?.[0].files?.[0].url || - (asset.metadata?.links ? asset.metadata?.links[0] : ' ') const providerUrl = formikState?.values?.services[0].providerUrl.url || - oceanConfig.providerUri + asset?.services[0]?.serviceEndpoint try { - const fileInfoResponse = await getFileInfo(fileUrl, providerUrl) + const fileInfoResponse = formikState?.values?.services?.[0].files?.[0] + .url + ? await getFileUrlInfo( + formikState?.values?.services?.[0].files?.[0].url, + providerUrl + ) + : await getFileDidInfo(asset?.id, asset?.services[0]?.id, providerUrl) fileInfoResponse && setFileMetadata(fileInfoResponse[0]) setFileIsLoading(false) } catch (error) {