@@ -45,11 +30,10 @@ export default function AssetContent({
{categories && (
- {categories[0]}
+ {categories[0]}
)}
- {/*
*/}
@@ -73,8 +57,6 @@ export default function AssetContent({
diff --git a/src/components/pages/Home.tsx b/src/components/pages/Home.tsx
index a0decf4f9..6a6b35896 100644
--- a/src/components/pages/Home.tsx
+++ b/src/components/pages/Home.tsx
@@ -11,19 +11,23 @@ export default function HomePage(): ReactElement {
useEffect(() => {
async function getLatestAssets() {
- const metadataStore = new MetadataStore(
- oceanConfig.metadataStoreUri,
- Logger
- )
+ try {
+ const metadataStore = new MetadataStore(
+ oceanConfig.metadataStoreUri,
+ Logger
+ )
- const result = await metadataStore.queryMetadata({
- page: 1,
- offset: 10,
- query: {},
- sort: { created: -1 }
- })
+ const result = await metadataStore.queryMetadata({
+ page: 1,
+ offset: 10,
+ query: {},
+ sort: { created: -1 }
+ })
- result && result.results && setAssets(result.results)
+ result && result.results && setAssets(result.results)
+ } catch (error) {
+ console.error(error.message)
+ }
}
getLatestAssets()
}, [])
diff --git a/src/utils/getAssetRating.ts b/src/utils/getAssetRating.ts
deleted file mode 100644
index 8e663a4fb..000000000
--- a/src/utils/getAssetRating.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import axios from 'axios'
-import { DID } from '@oceanprotocol/lib'
-import { oceanConfig } from '../../app.config'
-
-export declare type GetRatingResponse = {
- comment: string
- datePublished: string
- vote: number
-}
-
-const url = oceanConfig.ratingUri + '/api/v1/rating'
-
-export default async function getAssetRating(
- did: DID | string,
- account: string
-): Promise
{
- try {
- if (!account) return
-
- const response = await axios.get(url, {
- params: {
- did: did,
- address: account
- }
- })
- const votesLength = response.data.length
-
- if (votesLength > 0) {
- return response.data[votesLength - 1]
- }
- } catch (error) {
- console.error(error.message)
- }
-}
diff --git a/src/utils/rateAsset.ts b/src/utils/rateAsset.ts
deleted file mode 100644
index c8ab26210..000000000
--- a/src/utils/rateAsset.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import axios, { AxiosResponse } from 'axios'
-import Web3 from 'web3'
-import { DID } from '@oceanprotocol/lib'
-import { oceanConfig } from '../../app.config'
-
-export declare type RatingResponse = [string, number]
-
-const url = oceanConfig.ratingUri + '/api/v1/rating'
-
-export function gethash(message: string) {
- let hex = ''
- for (let i = 0; i < message.length; i++) {
- hex += '' + message.charCodeAt(i).toString(16)
- }
- const hexMessage = '0x' + hex
- return hexMessage
-}
-
-export default async function rateAsset(
- did: DID | string,
- web3: Web3,
- value: number
-): Promise {
- try {
- const timestamp = Math.floor(+new Date() / 1000)
- const accounts = await web3.eth.getAccounts()
- const signature = await web3.eth.personal.sign(
- gethash(`${timestamp}`),
- accounts ? accounts[0] : '',
- ''
- )
-
- const ratingBody = {
- did,
- vote: value,
- comment: '',
- address: accounts[0],
- timestamp: timestamp,
- signature: signature
- }
-
- const response: AxiosResponse = await axios.post(url, ratingBody)
- if (!response) return 'No Response'
- return response.data
- } catch (error) {
- console.error(error.message)
- return `Error: ${error.message}`
- }
-}
diff --git a/tests/unit/utils/getAssetRating.test.ts b/tests/unit/utils/getAssetRating.test.ts
deleted file mode 100644
index 6d3a5fa2d..000000000
--- a/tests/unit/utils/getAssetRating.test.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import axios, { AxiosResponse } from 'axios'
-import getAssetRating, {
- GetRatingResponse
-} from '../../../src/utils/getAssetRating'
-
-jest.mock('axios')
-
-describe('getAssetRating()', () => {
- it('success', async () => {
- const ratingResponse: GetRatingResponse = {
- comment: '',
- datePublished: '',
- vote: 5
- }
-
- ;(axios.get as any).mockResolvedValueOnce({
- data: [ratingResponse, ratingResponse]
- } as AxiosResponse)
-
- const response = await getAssetRating('0x00', '0x00')
- expect(response && response.vote).toBe(5)
- })
-})
diff --git a/tests/unit/utils/rateAsset.test.ts b/tests/unit/utils/rateAsset.test.ts
deleted file mode 100644
index a725131b0..000000000
--- a/tests/unit/utils/rateAsset.test.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import axios, { AxiosResponse } from 'axios'
-import rateAsset, { RatingResponse } from '../../../src/utils/rateAsset'
-import web3 from '../__mocks__/web3'
-
-jest.mock('axios')
-
-describe('rateAsset()', () => {
- it('success', async () => {
- ;(axios.post as any).mockResolvedValueOnce({
- data: ['4.0', 1]
- } as AxiosResponse)
-
- const response: RatingResponse | string = await rateAsset('0x00', web3, 5)
- expect(response && response[0]).toBe('4.0')
- })
-
- it('string return', async () => {
- ;(axios.post as any).mockResolvedValueOnce({
- data: 'Missing signature'
- } as AxiosResponse)
-
- const response: RatingResponse | string = await rateAsset('0x00', web3, 5)
- expect(response && response).toBe('Missing signature')
- })
-
- it('error catch', async () => {
- ;(axios.post as any).mockResolvedValueOnce({
- data: {}
- } as AxiosResponse)
-
- const response: RatingResponse | string = await rateAsset(
- '0x00',
- {} as any,
- 5
- )
- expect(response && response).toContain('Error: ')
- })
-})