1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

Fix consume of FRE assets & improve error handling (#1940)

* wait for approve tx to finish

* handle provider errors better

* more error handling updates

* cleanups

* bump ocean lib

* fix publish try catch const assign
This commit is contained in:
Bogdan Fazakas 2023-07-17 12:01:21 +03:00 committed by GitHub
parent 4d9002da07
commit 2e69739778
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 236 additions and 143 deletions

30
package-lock.json generated
View File

@ -15,7 +15,7 @@
"@coingecko/cryptoformat": "^0.5.4", "@coingecko/cryptoformat": "^0.5.4",
"@loadable/component": "^5.15.2", "@loadable/component": "^5.15.2",
"@oceanprotocol/art": "^3.2.0", "@oceanprotocol/art": "^3.2.0",
"@oceanprotocol/lib": "^3.0.1", "@oceanprotocol/lib": "^3.0.2",
"@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/typographies": "^0.1.0",
"@oceanprotocol/use-dark-mode": "^2.4.3", "@oceanprotocol/use-dark-mode": "^2.4.3",
"@orbisclub/orbis-sdk": "^0.4.40", "@orbisclub/orbis-sdk": "^0.4.40",
@ -6072,16 +6072,16 @@
"integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA==" "integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA=="
}, },
"node_modules/@oceanprotocol/contracts": { "node_modules/@oceanprotocol/contracts": {
"version": "1.1.8", "version": "1.1.14",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.8.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.14.tgz",
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ==" "integrity": "sha512-PJih7C6LHaWHHj1qgxZsSkEqKphhJrL3G7WuMOxl4N1daDrF6sooDDU+9dZkcHSVPc7cMjkFqLc5fP58NSAobw=="
}, },
"node_modules/@oceanprotocol/lib": { "node_modules/@oceanprotocol/lib": {
"version": "3.0.1", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.2.tgz",
"integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==", "integrity": "sha512-yp75eYcFzqqgUAzG+fkLXHrNaA/ZZvogEE25NOy2DI5EAUp1Wm6tZ0q6AIH0i05KCPOfXoIGwqTBlfQa0rh48A==",
"dependencies": { "dependencies": {
"@oceanprotocol/contracts": "^1.1.8", "@oceanprotocol/contracts": "^1.1.14",
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"decimal.js": "^10.4.1", "decimal.js": "^10.4.1",
@ -58441,16 +58441,16 @@
"integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA==" "integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA=="
}, },
"@oceanprotocol/contracts": { "@oceanprotocol/contracts": {
"version": "1.1.8", "version": "1.1.14",
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.8.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.14.tgz",
"integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ==" "integrity": "sha512-PJih7C6LHaWHHj1qgxZsSkEqKphhJrL3G7WuMOxl4N1daDrF6sooDDU+9dZkcHSVPc7cMjkFqLc5fP58NSAobw=="
}, },
"@oceanprotocol/lib": { "@oceanprotocol/lib": {
"version": "3.0.1", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz", "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.2.tgz",
"integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==", "integrity": "sha512-yp75eYcFzqqgUAzG+fkLXHrNaA/ZZvogEE25NOy2DI5EAUp1Wm6tZ0q6AIH0i05KCPOfXoIGwqTBlfQa0rh48A==",
"requires": { "requires": {
"@oceanprotocol/contracts": "^1.1.8", "@oceanprotocol/contracts": "^1.1.14",
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"decimal.js": "^10.4.1", "decimal.js": "^10.4.1",

View File

@ -29,7 +29,7 @@
"@coingecko/cryptoformat": "^0.5.4", "@coingecko/cryptoformat": "^0.5.4",
"@loadable/component": "^5.15.2", "@loadable/component": "^5.15.2",
"@oceanprotocol/art": "^3.2.0", "@oceanprotocol/art": "^3.2.0",
"@oceanprotocol/lib": "^3.0.1", "@oceanprotocol/lib": "^3.0.2",
"@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/typographies": "^0.1.0",
"@oceanprotocol/use-dark-mode": "^2.4.3", "@oceanprotocol/use-dark-mode": "^2.4.3",
"@orbisclub/orbis-sdk": "^0.4.40", "@orbisclub/orbis-sdk": "^0.4.40",

View File

@ -5,6 +5,7 @@ import {
TokenPriceQuery_token as TokenPrice TokenPriceQuery_token as TokenPrice
} from '../@types/subgraph/TokenPriceQuery' } from '../@types/subgraph/TokenPriceQuery'
import { import {
getErrorMessage,
LoggerInstance, LoggerInstance,
ProviderFees, ProviderFees,
ProviderInstance ProviderInstance
@ -16,6 +17,7 @@ import {
publisherMarketOrderFee publisherMarketOrderFee
} from '../../app.config' } from '../../app.config'
import { Signer } from 'ethers' import { Signer } from 'ethers'
import { toast } from 'react-toastify'
const tokenPriceQuery = gql` const tokenPriceQuery = gql`
query TokenPriceQuery($datatokenId: ID!, $account: String) { query TokenPriceQuery($datatokenId: ID!, $account: String) {
@ -82,7 +84,6 @@ function getAccessDetailsFromTokenPrice(
timeout?: number timeout?: number
): AccessDetails { ): AccessDetails {
const accessDetails = {} as AccessDetails const accessDetails = {} as AccessDetails
// Return early when no supported pricing schema found. // Return early when no supported pricing schema found.
if ( if (
tokenPrice?.dispensers?.length === 0 && tokenPrice?.dispensers?.length === 0 &&
@ -176,15 +177,22 @@ export async function getOrderPriceAndFees(
} as OrderPriceAndFees } as OrderPriceAndFees
// fetch provider fee // fetch provider fee
const initializeData = let initializeData
!providerFees && try {
(await ProviderInstance.initialize( initializeData =
asset?.id, !providerFees &&
asset?.services[0].id, (await ProviderInstance.initialize(
0, asset?.id,
accountId, asset?.services[0].id,
asset?.services[0].serviceEndpoint 0,
)) accountId,
asset?.services[0].serviceEndpoint
))
} catch (error) {
const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Initialize Provider] Error:', message)
toast.error(message)
}
orderPriceAndFee.providerFee = providerFees || initializeData.providerFee orderPriceAndFee.providerFee = providerFees || initializeData.providerFee
// fetch price and swap fees // fetch price and swap fees

View File

@ -9,7 +9,8 @@ import {
Service, Service,
ProviderInstance, ProviderInstance,
ComputeEnvironment, ComputeEnvironment,
ComputeJob ComputeJob,
getErrorMessage
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { CancelToken } from 'axios' import { CancelToken } from 'axios'
import { gql } from 'urql' import { gql } from 'urql'
@ -26,6 +27,7 @@ import { AssetSelectionAsset } from '@shared/FormInput/InputElement/AssetSelecti
import { transformAssetToAssetSelection } from './assetConvertor' import { transformAssetToAssetSelection } from './assetConvertor'
import { ComputeEditForm } from '../components/Asset/Edit/_types' import { ComputeEditForm } from '../components/Asset/Edit/_types'
import { getFileDidInfo } from './provider' import { getFileDidInfo } from './provider'
import { toast } from 'react-toastify'
const getComputeOrders = gql` const getComputeOrders = gql`
query ComputeOrders($user: String!) { query ComputeOrders($user: String!) {
@ -146,7 +148,12 @@ export async function getComputeEnviroment(
if (!computeEnvs[asset.chainId][0]) return null if (!computeEnvs[asset.chainId][0]) return null
return computeEnvs[asset.chainId][0] return computeEnvs[asset.chainId][0]
} catch (e) { } catch (e) {
LoggerInstance.error('[compute] Fetch compute enviroment: ', e.message) const message = getErrorMessage(JSON.parse(e.message))
LoggerInstance.error(
'[Compute to Data] Fetch compute environment:',
message
)
toast.error(message)
} }
} }
@ -222,8 +229,6 @@ async function getJobs(
assets: Asset[] assets: Asset[]
): Promise<ComputeJobMetaData[]> { ): Promise<ComputeJobMetaData[]> {
const computeJobs: ComputeJobMetaData[] = [] const computeJobs: ComputeJobMetaData[] = []
// commented loop since we decide how to filter jobs
// for await (const providerUrl of providerUrls) {
try { try {
const providerComputeJobs = (await ProviderInstance.computeStatus( const providerComputeJobs = (await ProviderInstance.computeStatus(
providerUrls[0], providerUrls[0],
@ -256,9 +261,10 @@ async function getJobs(
}) })
} }
} catch (err) { } catch (err) {
LoggerInstance.error(err.message) const message = getErrorMessage(JSON.parse(err.message))
LoggerInstance.error('[Compute to Data] Error:', message)
toast.error(message)
} }
// }
return computeJobs return computeJobs
} }

View File

@ -6,10 +6,12 @@ import {
ProviderInstance, ProviderInstance,
DDO, DDO,
MetadataAndTokenURI, MetadataAndTokenURI,
NftCreateData NftCreateData,
getErrorMessage
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { SvgWaves } from './SvgWaves' import { SvgWaves } from './SvgWaves'
import { Signer, ethers } from 'ethers' import { Signer, ethers } from 'ethers'
import { toast } from 'react-toastify'
// https://docs.opensea.io/docs/metadata-standards // https://docs.opensea.io/docs/metadata-standards
export interface NftMetadata { export interface NftMetadata {
@ -101,12 +103,19 @@ export async function setNftMetadata(
signer: Signer, signer: Signer,
signal: AbortSignal signal: AbortSignal
): Promise<ethers.providers.TransactionResponse> { ): Promise<ethers.providers.TransactionResponse> {
const encryptedDdo = await ProviderInstance.encrypt( let encryptedDdo
asset, try {
asset.chainId, encryptedDdo = await ProviderInstance.encrypt(
asset.services[0].serviceEndpoint, asset,
signal asset.chainId,
) asset.services[0].serviceEndpoint,
signal
)
} catch (err) {
const message = getErrorMessage(JSON.parse(err.message))
LoggerInstance.error('[Encrypt Data] Error:', message)
toast.error(message)
}
LoggerInstance.log('[setNftMetadata] Got encrypted DDO', encryptedDdo) LoggerInstance.log('[setNftMetadata] Got encrypted DDO', encryptedDdo)
const metadataHash = getHash(JSON.stringify(asset)) const metadataHash = getHash(JSON.stringify(asset))
@ -136,12 +145,19 @@ export async function setNFTMetadataAndTokenURI(
nftMetadata: NftMetadata, nftMetadata: NftMetadata,
signal: AbortSignal signal: AbortSignal
): Promise<ethers.providers.TransactionResponse> { ): Promise<ethers.providers.TransactionResponse> {
const encryptedDdo = await ProviderInstance.encrypt( let encryptedDdo
asset, try {
asset.chainId, encryptedDdo = await ProviderInstance.encrypt(
asset.services[0].serviceEndpoint, asset,
signal asset.chainId,
) asset.services[0].serviceEndpoint,
signal
)
} catch (err) {
const message = getErrorMessage(JSON.parse(err.message))
LoggerInstance.error('[Encrypt Data] Error:', message)
toast.error(message)
}
LoggerInstance.log( LoggerInstance.log(
'[setNFTMetadataAndTokenURI] Got encrypted DDO', '[setNFTMetadataAndTokenURI] Got encrypted DDO',
encryptedDdo encryptedDdo

View File

@ -11,7 +11,8 @@ import {
ProviderComputeInitialize, ProviderComputeInitialize,
ProviderFees, ProviderFees,
ProviderInstance, ProviderInstance,
ProviderInitialize ProviderInitialize,
getErrorMessage
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { Signer, ethers } from 'ethers' import { Signer, ethers } from 'ethers'
import { getOceanConfig } from './ocean' import { getOceanConfig } from './ocean'
@ -38,7 +39,9 @@ async function initializeProvider(
) )
return provider return provider
} catch (error) { } catch (error) {
LoggerInstance.log('[Initialize Provider] Error:', error) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.log('[Initialize Provider] Error:', message)
toast.error(message)
} }
} }
@ -99,19 +102,16 @@ export async function order(
if (asset.accessDetails.templateId === 1) { if (asset.accessDetails.templateId === 1) {
if (!hasDatatoken) { if (!hasDatatoken) {
// buy datatoken // buy datatoken
const txApprove = await approve( const tx: any = await approve(
signer, signer,
config, config,
accountId, await signer.getAddress(),
asset.accessDetails.baseToken.address, asset.accessDetails.baseToken.address,
config.fixedRateExchangeAddress, config.fixedRateExchangeAddress,
await amountToUnits( orderPriceAndFees.price,
signer,
asset?.accessDetails?.baseToken?.address,
orderPriceAndFees.price
),
false false
) )
const txApprove = typeof tx !== 'number' ? await tx.wait() : tx
if (!txApprove) { if (!txApprove) {
return return
} }
@ -126,6 +126,7 @@ export async function order(
marketFeeAddress, marketFeeAddress,
consumeMarketFixedSwapFee consumeMarketFixedSwapFee
) )
const buyDtTx = await freTx.wait()
} }
return await datatoken.startOrder( return await datatoken.startOrder(
asset.accessDetails.datatoken.address, asset.accessDetails.datatoken.address,
@ -136,19 +137,17 @@ export async function order(
) )
} }
if (asset.accessDetails.templateId === 2) { if (asset.accessDetails.templateId === 2) {
const txApprove = await approve( const tx: any = await approve(
signer, signer,
config, config,
accountId, accountId,
asset.accessDetails.baseToken.address, asset.accessDetails.baseToken.address,
asset.accessDetails.datatoken.address, asset.accessDetails.datatoken.address,
await amountToUnits( orderPriceAndFees.price,
signer,
asset?.accessDetails?.baseToken?.address,
orderPriceAndFees.price
),
false false
) )
const txApprove = typeof tx !== 'number' ? await tx.wait() : tx
if (!txApprove) { if (!txApprove) {
return return
} }

View File

@ -12,11 +12,14 @@ import {
ProviderComputeInitializeResults, ProviderComputeInitializeResults,
ProviderInstance, ProviderInstance,
UrlFile, UrlFile,
AbiItem AbiItem,
getErrorMessage
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { QueryHeader } from '@shared/FormInput/InputElement/Headers' import { QueryHeader } from '@shared/FormInput/InputElement/Headers'
import { Signer } from 'ethers' import { Signer } from 'ethers'
import { getValidUntilTime } from './compute' import { getValidUntilTime } from './compute'
import { toast } from 'react-toastify'
import { tr } from 'date-fns/locale'
export async function initializeProviderForCompute( export async function initializeProviderForCompute(
dataset: AssetExtended, dataset: AssetExtended,
@ -51,7 +54,9 @@ export async function initializeProviderForCompute(
accountId accountId
) )
} catch (error) { } catch (error) {
LoggerInstance.error(`Error initializing provider for the compute job!`) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Initialize Provider] Error:', message)
toast.error(message)
return null return null
} }
} }
@ -67,7 +72,9 @@ export async function getEncryptedFiles(
const response = await ProviderInstance.encrypt(files, chainId, providerUrl) const response = await ProviderInstance.encrypt(files, chainId, providerUrl)
return response return response
} catch (error) { } catch (error) {
console.error('Error parsing json: ' + error.message) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Encrypt] Error:', message)
toast.error(message)
} }
} }
@ -86,7 +93,9 @@ export async function getFileDidInfo(
) )
return response return response
} catch (error) { } catch (error) {
LoggerInstance.error(error.message) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Initialize check file did] Error:', message)
toast.error(message)
} }
} }
@ -100,76 +109,99 @@ export async function getFileInfo(
chainId?: number, chainId?: number,
method?: string method?: string
): Promise<FileInfo[]> { ): Promise<FileInfo[]> {
try { let response
let response const headersProvider = {}
const headersProvider = {} if (headers?.length > 0) {
if (headers?.length > 0) { headers.map((el) => {
headers.map((el) => { headersProvider[el.key] = el.value
headersProvider[el.key] = el.value return el
return el })
}) }
}
switch (storageType) { switch (storageType) {
case 'ipfs': { case 'ipfs': {
const fileIPFS: Ipfs = { const fileIPFS: Ipfs = {
type: storageType, type: storageType,
hash: file hash: file
} }
try {
response = await ProviderInstance.getFileInfo(fileIPFS, providerUrl) response = await ProviderInstance.getFileInfo(fileIPFS, providerUrl)
break } catch (error) {
const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Get File info] Error:', message)
toast.error(message)
} }
case 'arweave': { break
const fileArweave: Arweave = { }
type: storageType, case 'arweave': {
transactionId: file const fileArweave: Arweave = {
} type: storageType,
transactionId: file
}
try {
response = await ProviderInstance.getFileInfo(fileArweave, providerUrl) response = await ProviderInstance.getFileInfo(fileArweave, providerUrl)
break } catch (error) {
const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Get File info] Error:', message)
toast.error(message)
} }
case 'graphql': { break
const fileGraphql: GraphqlQuery = { }
type: storageType, case 'graphql': {
url: file, const fileGraphql: GraphqlQuery = {
headers: headersProvider, type: storageType,
query url: file,
} headers: headersProvider,
query
}
try {
response = await ProviderInstance.getFileInfo(fileGraphql, providerUrl) response = await ProviderInstance.getFileInfo(fileGraphql, providerUrl)
break } catch (error) {
const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Get File info] Error:', message)
toast.error(message)
} }
case 'smartcontract': { break
// clean obj }
const fileSmartContract: Smartcontract = { case 'smartcontract': {
chainId, // clean obj
type: storageType, const fileSmartContract: Smartcontract = {
address: file, chainId,
abi: JSON.parse(abi) as AbiItem type: storageType,
} address: file,
abi: JSON.parse(abi) as AbiItem
}
try {
response = await ProviderInstance.getFileInfo( response = await ProviderInstance.getFileInfo(
fileSmartContract, fileSmartContract,
providerUrl providerUrl
) )
break } catch (error) {
} const message = getErrorMessage(JSON.parse(error.message))
default: { LoggerInstance.error('[Provider Get File info] Error:', message)
const fileUrl: UrlFile = { toast.error(message)
type: 'url',
index: 0,
url: file,
headers: headersProvider,
method
}
response = await ProviderInstance.getFileInfo(fileUrl, providerUrl)
break
} }
break
}
default: {
const fileUrl: UrlFile = {
type: 'url',
index: 0,
url: file,
headers: headersProvider,
method
}
try {
response = await ProviderInstance.getFileInfo(fileUrl, providerUrl)
} catch (error) {
const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Get File info] Error:', message)
toast.error(message)
}
break
} }
return response
} catch (error) {
LoggerInstance.error(error.message)
} }
return response
} }
export async function downloadFile( export async function downloadFile(
@ -178,14 +210,21 @@ export async function downloadFile(
accountId: string, accountId: string,
validOrderTx?: string validOrderTx?: string
) { ) {
const downloadUrl = await ProviderInstance.getDownloadUrl( let downloadUrl
asset.id, try {
asset.services[0].id, downloadUrl = await ProviderInstance.getDownloadUrl(
0, asset.id,
validOrderTx || asset.accessDetails.validOrderTx, asset.services[0].id,
asset.services[0].serviceEndpoint, 0,
signer validOrderTx || asset.accessDetails.validOrderTx,
) asset.services[0].serviceEndpoint,
signer
)
} catch (error) {
const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Get download url] Error:', message)
toast.error(message)
}
await downloadFileBrowser(downloadUrl) await downloadFileBrowser(downloadUrl)
} }
@ -196,6 +235,8 @@ export async function checkValidProvider(
const response = await ProviderInstance.isValidProvider(providerUrl) const response = await ProviderInstance.isValidProvider(providerUrl)
return response return response
} catch (error) { } catch (error) {
LoggerInstance.error(error.message) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Check] Error:', message)
toast.error(message)
} }
} }

View File

@ -5,12 +5,17 @@ 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 { LoggerInstance, ProviderInstance } from '@oceanprotocol/lib' import {
LoggerInstance,
ProviderInstance,
getErrorMessage
} from '@oceanprotocol/lib'
import { FormPublishData } from '@components/Publish/_types' import { FormPublishData } from '@components/Publish/_types'
import { getOceanConfig } from '@utils/ocean' import { getOceanConfig } from '@utils/ocean'
import axios from 'axios' import axios from 'axios'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
import { useNetwork } from 'wagmi' import { useNetwork } from 'wagmi'
import { toast } from 'react-toastify'
export default function CustomProvider(props: InputProps): ReactElement { export default function CustomProvider(props: InputProps): ReactElement {
const { chain } = useNetwork() const { chain } = useNetwork()
@ -56,8 +61,9 @@ export default function CustomProvider(props: InputProps): ReactElement {
// if all good, add provider to formik state // if all good, add provider to formik state
helpers.setValue({ url: field.value.url, valid: isValid, custom: true }) helpers.setValue({ url: field.value.url, valid: isValid, custom: true })
} catch (error) { } catch (error) {
setFieldError(`${field.name}.url`, error.message) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error(error.message) setFieldError(`${field.name}.url`, message)
LoggerInstance.error('[Custom Provider]:', message)
} finally { } finally {
setIsLoading(false) setIsLoading(false)
} }

View File

@ -14,7 +14,8 @@ import {
ProviderComputeInitializeResults, ProviderComputeInitializeResults,
unitsToAmount, unitsToAmount,
minAbi, minAbi,
ProviderFees ProviderFees,
getErrorMessage
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import Price from '@shared/Price' import Price from '@shared/Price'
@ -430,9 +431,10 @@ export default function Compute({
setRefetchJobs(!refetchJobs) setRefetchJobs(!refetchJobs)
initPriceAndFees() initPriceAndFees()
} catch (error) { } catch (error) {
setError(error.message) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Compute] Error:', message)
setError(message)
setRetry(true) setRetry(true)
LoggerInstance.error(`[compute] ${error.message} `)
} finally { } finally {
setIsOrdering(false) setIsOrdering(false)
} }

View File

@ -1,6 +1,7 @@
import { import {
ComputeResultType, ComputeResultType,
downloadFileBrowser, downloadFileBrowser,
getErrorMessage,
LoggerInstance, LoggerInstance,
Provider Provider
} from '@oceanprotocol/lib' } from '@oceanprotocol/lib'
@ -13,6 +14,7 @@ import content from '../../../../../content/pages/history.json'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
import { getAsset } from '@utils/aquarius' import { getAsset } from '@utils/aquarius'
import { useAccount, useSigner } from 'wagmi' import { useAccount, useSigner } from 'wagmi'
import { toast } from 'react-toastify'
export default function Results({ export default function Results({
job job
@ -70,7 +72,9 @@ export default function Results({
) )
await downloadFileBrowser(jobResult) await downloadFileBrowser(jobResult)
} catch (error) { } catch (error) {
LoggerInstance.error(error.message) const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Get c2d results url] Error:', message)
toast.error(message)
} }
} }

View File

@ -13,7 +13,12 @@ import { Steps } from './Steps'
import { FormPublishData } from './_types' import { FormPublishData } from './_types'
import { useUserPreferences } from '@context/UserPreferences' import { useUserPreferences } from '@context/UserPreferences'
import useNftFactory from '@hooks/useNftFactory' import useNftFactory from '@hooks/useNftFactory'
import { ProviderInstance, LoggerInstance, DDO } from '@oceanprotocol/lib' import {
ProviderInstance,
LoggerInstance,
DDO,
getErrorMessage
} from '@oceanprotocol/lib'
import { getOceanConfig } from '@utils/ocean' import { getOceanConfig } from '@utils/ocean'
import { validationSchema } from './_validation' import { validationSchema } from './_validation'
import { useAbortController } from '@hooks/useAbortController' import { useAbortController } from '@hooks/useAbortController'
@ -134,12 +139,18 @@ export default function PublishPage({
setDdo(ddo) setDdo(ddo)
LoggerInstance.log('[publish] Got new DDO', ddo) LoggerInstance.log('[publish] Got new DDO', ddo)
const ddoEncrypted = await ProviderInstance.encrypt( let ddoEncrypted: string
ddo, try {
ddo.chainId, ddoEncrypted = await ProviderInstance.encrypt(
values.services[0].providerUrl.url, ddo,
newAbortController() ddo.chainId,
) values.services[0].providerUrl.url,
newAbortController()
)
} catch (error) {
const message = getErrorMessage(JSON.parse(error.message))
LoggerInstance.error('[Provider Encrypt] Error:', message)
}
if (!ddoEncrypted) if (!ddoEncrypted)
throw new Error('No encrypted DDO received. Please try again.') throw new Error('No encrypted DDO received. Please try again.')