diff --git a/src/components/organisms/AssetActions/index.tsx b/src/components/organisms/AssetActions/index.tsx
index 967760a57..290dd6d4e 100644
--- a/src/components/organisms/AssetActions/index.tsx
+++ b/src/components/organisms/AssetActions/index.tsx
@@ -2,7 +2,7 @@ import React, { ReactElement, useState, useEffect } from 'react'
import styles from './index.module.css'
import Compute from './Compute'
import Consume from './Consume'
-import { Logger } from '@oceanprotocol/lib'
+import { Logger, File as FileMetadata, DID } from '@oceanprotocol/lib'
import Tabs from '../../atoms/Tabs'
import compareAsBN from '../../../utils/compareAsBN'
import Pool from './Pool'
@@ -10,20 +10,44 @@ import Trade from './Trade'
import { useAsset } from '../../../providers/Asset'
import { useOcean } from '../../../providers/Ocean'
import { useWeb3 } from '../../../providers/Web3'
+import { getFileInfo } from '../../../utils/provider'
+import axios from 'axios'
export default function AssetActions(): ReactElement {
const { accountId } = useWeb3()
- const { ocean, balance, account } = useOcean()
- const { price, ddo, metadata } = useAsset()
+ const { config, ocean, balance, account } = useOcean()
+ const { price, ddo } = useAsset()
const [isBalanceSufficient, setIsBalanceSufficient] = useState
()
const [dtBalance, setDtBalance] = useState()
+ const [fileMetadata, setFileMetadata] = useState(Object)
+ const [fileIsLoading, setFileIsLoading] = useState(false)
const isCompute = Boolean(ddo?.findServiceByType('compute'))
+ useEffect(() => {
+ if (!config) return
+ const source = axios.CancelToken.source()
+ async function initFileInfo() {
+ setFileIsLoading(true)
+ try {
+ const fileInfo = await getFileInfo(
+ DID.parse(`${ddo.id}`),
+ config.providerUri,
+ source.token
+ )
+ setFileMetadata(fileInfo.data[0])
+ } catch (error) {
+ Logger.error(error.message)
+ } finally {
+ setFileIsLoading(false)
+ }
+ }
+ initFileInfo()
+ }, [config, ddo.id])
+
// Get and set user DT balance
useEffect(() => {
if (!ocean || !accountId) return
-
async function init() {
try {
const dtBalance = await ocean.datatokens.balance(
@@ -55,14 +79,16 @@ export default function AssetActions(): ReactElement {
) : (
)
diff --git a/src/utils/provider.ts b/src/utils/provider.ts
index 31889187d..898894eee 100644
--- a/src/utils/provider.ts
+++ b/src/utils/provider.ts
@@ -1,6 +1,6 @@
import axios, { CancelToken, AxiosResponse } from 'axios'
import { toast } from 'react-toastify'
-import { File as FileMetadata, Logger } from '@oceanprotocol/lib'
+import { DID, File as FileMetadata, Logger } from '@oceanprotocol/lib'
export async function fileinfo(
url: string,
@@ -57,3 +57,26 @@ export async function fileinfo(
Logger.error(error.message)
}
}
+
+export async function getFileInfo(
+ url: string | DID,
+ providerUri: string,
+ cancelToken: CancelToken
+): Promise {
+ let postBody
+ try {
+ if (url instanceof DID)
+ postBody = {
+ did: url.getDid(),
+ cancelToken
+ }
+ else
+ postBody = {
+ url,
+ cancelToken
+ }
+ return await axios.post(`${providerUri}/api/v1/services/fileinfo`, postBody)
+ } catch (error) {
+ Logger.error(error.message)
+ }
+}