mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
use new provider
This commit is contained in:
parent
4caf72d0c9
commit
6813462cb0
1
package-lock.json
generated
1
package-lock.json
generated
@ -108,6 +108,7 @@
|
||||
}
|
||||
},
|
||||
"../ocean.js": {
|
||||
"name": "@oceanprotocol/lib",
|
||||
"version": "1.0.0-alpha",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import axios, { CancelToken, AxiosResponse } from 'axios'
|
||||
import { DID, LoggerInstance } from '@oceanprotocol/lib'
|
||||
import { LoggerInstance, ProviderInstance } from '@oceanprotocol/lib'
|
||||
|
||||
export interface FileMetadata {
|
||||
index: number
|
||||
@ -31,15 +31,12 @@ export async function getEncryptedFileUrls(
|
||||
}
|
||||
|
||||
export async function getFileInfo(
|
||||
url: string | DID,
|
||||
url: string,
|
||||
providerUrl: string,
|
||||
cancelToken: CancelToken
|
||||
): Promise<FileMetadata[]> {
|
||||
let postBody
|
||||
try {
|
||||
if (url instanceof DID) postBody = { did: url.getDid() }
|
||||
else postBody = { url }
|
||||
|
||||
const postBody = { url }
|
||||
const response: AxiosResponse<FileMetadata[]> = await axios.post(
|
||||
`${providerUrl}/api/v1/services/fileinfo`,
|
||||
postBody,
|
||||
@ -56,3 +53,26 @@ export async function getFileInfo(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchMethod(url: string): Promise<AxiosResponse> {
|
||||
const result = await axios.get(url)
|
||||
if (!result) {
|
||||
console.error(`Error requesting ${url}`)
|
||||
console.error(`Response message: \n${result}`)
|
||||
throw result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export async function isValidProvider(url: string): Promise<boolean> {
|
||||
try {
|
||||
const response = await ProviderInstance.isValidProvider(
|
||||
url,
|
||||
fetchMethod(url)
|
||||
)
|
||||
return response
|
||||
} catch (error) {
|
||||
console.error(`Error validating provider: ${error.message}`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,23 @@
|
||||
import React, { ReactElement, useState } from 'react'
|
||||
import { ErrorMessage, useField } from 'formik'
|
||||
import UrlInput from '../URLInput'
|
||||
import { useOcean } from '@context/Ocean'
|
||||
import { InputProps } from '@shared/FormInput'
|
||||
import FileInfo from '../FilesInput/Info'
|
||||
import styles from './index.module.css'
|
||||
import Button from '@shared/atoms/Button'
|
||||
import { initialValues } from 'src/components/Publish/_constants'
|
||||
import { isValidProvider } from '@utils/provider'
|
||||
|
||||
export default function CustomProvider(props: InputProps): ReactElement {
|
||||
const [field, meta, helpers] = useField(props.name)
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const { ocean, config } = useOcean()
|
||||
|
||||
async function validateProvider(url: string) {
|
||||
setIsLoading(true)
|
||||
|
||||
try {
|
||||
// TODO: #948 Remove ocean.provider.isValidProvider dependency.
|
||||
const isValid = await ocean.provider.isValidProvider(url)
|
||||
const isValid = await isValidProvider(url)
|
||||
helpers.setValue({ url, valid: isValid })
|
||||
helpers.setError(undefined)
|
||||
} catch (error) {
|
||||
|
Loading…
Reference in New Issue
Block a user