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": {
|
"../ocean.js": {
|
||||||
|
"name": "@oceanprotocol/lib",
|
||||||
"version": "1.0.0-alpha",
|
"version": "1.0.0-alpha",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import axios, { CancelToken, AxiosResponse } from 'axios'
|
import axios, { CancelToken, AxiosResponse } from 'axios'
|
||||||
import { DID, LoggerInstance } from '@oceanprotocol/lib'
|
import { LoggerInstance, ProviderInstance } from '@oceanprotocol/lib'
|
||||||
|
|
||||||
export interface FileMetadata {
|
export interface FileMetadata {
|
||||||
index: number
|
index: number
|
||||||
@ -31,15 +31,12 @@ export async function getEncryptedFileUrls(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getFileInfo(
|
export async function getFileInfo(
|
||||||
url: string | DID,
|
url: string,
|
||||||
providerUrl: string,
|
providerUrl: string,
|
||||||
cancelToken: CancelToken
|
cancelToken: CancelToken
|
||||||
): Promise<FileMetadata[]> {
|
): Promise<FileMetadata[]> {
|
||||||
let postBody
|
|
||||||
try {
|
try {
|
||||||
if (url instanceof DID) postBody = { did: url.getDid() }
|
const postBody = { url }
|
||||||
else postBody = { url }
|
|
||||||
|
|
||||||
const response: AxiosResponse<FileMetadata[]> = await axios.post(
|
const response: AxiosResponse<FileMetadata[]> = await axios.post(
|
||||||
`${providerUrl}/api/v1/services/fileinfo`,
|
`${providerUrl}/api/v1/services/fileinfo`,
|
||||||
postBody,
|
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 React, { ReactElement, useState } from 'react'
|
||||||
import { ErrorMessage, useField } from 'formik'
|
import { ErrorMessage, useField } from 'formik'
|
||||||
import UrlInput from '../URLInput'
|
import UrlInput from '../URLInput'
|
||||||
import { useOcean } from '@context/Ocean'
|
|
||||||
import { InputProps } from '@shared/FormInput'
|
import { InputProps } from '@shared/FormInput'
|
||||||
import FileInfo from '../FilesInput/Info'
|
import FileInfo from '../FilesInput/Info'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import Button from '@shared/atoms/Button'
|
import Button from '@shared/atoms/Button'
|
||||||
import { initialValues } from 'src/components/Publish/_constants'
|
import { initialValues } from 'src/components/Publish/_constants'
|
||||||
|
import { isValidProvider } from '@utils/provider'
|
||||||
|
|
||||||
export default function CustomProvider(props: InputProps): ReactElement {
|
export default function CustomProvider(props: InputProps): ReactElement {
|
||||||
const [field, meta, helpers] = useField(props.name)
|
const [field, meta, helpers] = useField(props.name)
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
const { ocean, config } = useOcean()
|
|
||||||
|
|
||||||
async function validateProvider(url: string) {
|
async function validateProvider(url: string) {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: #948 Remove ocean.provider.isValidProvider dependency.
|
// 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.setValue({ url, valid: isValid })
|
||||||
helpers.setError(undefined)
|
helpers.setError(undefined)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user