From 55f4b35a322cab6c2ad3ae7402459a3b215a21c3 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Wed, 28 Jun 2023 13:02:24 +0300 Subject: [PATCH 1/6] wait for approve tx to finish --- src/@utils/order.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/@utils/order.ts b/src/@utils/order.ts index 2e73f3afc..8b2e1a116 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -99,7 +99,7 @@ export async function order( if (asset.accessDetails.templateId === 1) { if (!hasDatatoken) { // buy datatoken - const txApprove = await approve( + const tx: any = await approve( signer, config, accountId, @@ -112,6 +112,7 @@ export async function order( ), false ) + const txApprove = await tx.wait() if (!txApprove) { return } @@ -136,7 +137,7 @@ export async function order( ) } if (asset.accessDetails.templateId === 2) { - const txApprove = await approve( + const tx: any = await approve( signer, config, accountId, @@ -149,6 +150,7 @@ export async function order( ), false ) + const txApprove = await tx.wait() if (!txApprove) { return } From 01c9c6beeb00642c3a4955677782fd43cec7f6d2 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Tue, 4 Jul 2023 12:17:24 +0300 Subject: [PATCH 2/6] handle provider errors better --- src/@utils/accessDetailsAndPricing.ts | 28 ++- src/@utils/compute.ts | 18 +- src/@utils/nft.ts | 42 +++-- src/@utils/order.ts | 57 ++++-- src/@utils/provider.ts | 175 +++++++++++------- .../FormInput/InputElement/Provider/index.tsx | 12 +- .../Asset/AssetActions/Compute/index.tsx | 8 +- .../Profile/History/ComputeJobs/Results.tsx | 6 +- src/components/Publish/index.tsx | 24 ++- 9 files changed, 245 insertions(+), 125 deletions(-) diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index ab9188aec..016e26903 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -5,6 +5,7 @@ import { TokenPriceQuery_token as TokenPrice } from '../@types/subgraph/TokenPriceQuery' import { + getErrorMessage, LoggerInstance, ProviderFees, ProviderInstance @@ -16,6 +17,7 @@ import { publisherMarketOrderFee } from '../../app.config' import { Signer } from 'ethers' +import { toast } from 'react-toastify' const tokenPriceQuery = gql` query TokenPriceQuery($datatokenId: ID!, $account: String) { @@ -82,7 +84,6 @@ function getAccessDetailsFromTokenPrice( timeout?: number ): AccessDetails { const accessDetails = {} as AccessDetails - // Return early when no supported pricing schema found. if ( tokenPrice?.dispensers?.length === 0 && @@ -176,15 +177,22 @@ export async function getOrderPriceAndFees( } as OrderPriceAndFees // fetch provider fee - const initializeData = - !providerFees && - (await ProviderInstance.initialize( - asset?.id, - asset?.services[0].id, - 0, - accountId, - asset?.services[0].serviceEndpoint - )) + let initializeData + try { + initializeData = + !providerFees && + (await ProviderInstance.initialize( + asset?.id, + asset?.services[0].id, + 0, + accountId, + asset?.services[0].serviceEndpoint + )) + } catch (error) { + const message = getErrorMessage(error) + LoggerInstance.error('[Initialize Provider] Error:', message) + toast.error(message) + } orderPriceAndFee.providerFee = providerFees || initializeData.providerFee // fetch price and swap fees diff --git a/src/@utils/compute.ts b/src/@utils/compute.ts index 61418afba..05928e75d 100644 --- a/src/@utils/compute.ts +++ b/src/@utils/compute.ts @@ -9,7 +9,8 @@ import { Service, ProviderInstance, ComputeEnvironment, - ComputeJob + ComputeJob, + getErrorMessage } from '@oceanprotocol/lib' import { CancelToken } from 'axios' import { gql } from 'urql' @@ -26,6 +27,7 @@ import { AssetSelectionAsset } from '@shared/FormInput/InputElement/AssetSelecti import { transformAssetToAssetSelection } from './assetConvertor' import { ComputeEditForm } from '../components/Asset/Edit/_types' import { getFileDidInfo } from './provider' +import { toast } from 'react-toastify' const getComputeOrders = gql` query ComputeOrders($user: String!) { @@ -146,7 +148,12 @@ export async function getComputeEnviroment( if (!computeEnvs[asset.chainId][0]) return null return computeEnvs[asset.chainId][0] } catch (e) { - LoggerInstance.error('[compute] Fetch compute enviroment: ', e.message) + const message = getErrorMessage(e) + LoggerInstance.error( + '[Compute to Data] Fetch compute environment:', + message + ) + toast.error(message) } } @@ -222,8 +229,6 @@ async function getJobs( assets: Asset[] ): Promise { const computeJobs: ComputeJobMetaData[] = [] - // commented loop since we decide how to filter jobs - // for await (const providerUrl of providerUrls) { try { const providerComputeJobs = (await ProviderInstance.computeStatus( providerUrls[0], @@ -256,9 +261,10 @@ async function getJobs( }) } } catch (err) { - LoggerInstance.error(err.message) + const message = getErrorMessage(err) + LoggerInstance.error('[Compute to Data] Error:', message) + toast.error(message) } - // } return computeJobs } diff --git a/src/@utils/nft.ts b/src/@utils/nft.ts index e6962ba63..0b83e5dbb 100644 --- a/src/@utils/nft.ts +++ b/src/@utils/nft.ts @@ -6,10 +6,12 @@ import { ProviderInstance, DDO, MetadataAndTokenURI, - NftCreateData + NftCreateData, + getErrorMessage } from '@oceanprotocol/lib' import { SvgWaves } from './SvgWaves' import { Signer, ethers } from 'ethers' +import { toast } from 'react-toastify' // https://docs.opensea.io/docs/metadata-standards export interface NftMetadata { @@ -101,12 +103,19 @@ export async function setNftMetadata( signer: Signer, signal: AbortSignal ): Promise { - const encryptedDdo = await ProviderInstance.encrypt( - asset, - asset.chainId, - asset.services[0].serviceEndpoint, - signal - ) + let encryptedDdo + try { + encryptedDdo = await ProviderInstance.encrypt( + asset, + asset.chainId, + asset.services[0].serviceEndpoint, + signal + ) + } catch (err) { + const message = getErrorMessage(err) + LoggerInstance.error('[Encrypt Data] Error:', message) + toast.error(message) + } LoggerInstance.log('[setNftMetadata] Got encrypted DDO', encryptedDdo) const metadataHash = getHash(JSON.stringify(asset)) @@ -136,12 +145,19 @@ export async function setNFTMetadataAndTokenURI( nftMetadata: NftMetadata, signal: AbortSignal ): Promise { - const encryptedDdo = await ProviderInstance.encrypt( - asset, - asset.chainId, - asset.services[0].serviceEndpoint, - signal - ) + let encryptedDdo + try { + encryptedDdo = await ProviderInstance.encrypt( + asset, + asset.chainId, + asset.services[0].serviceEndpoint, + signal + ) + } catch (err) { + const message = getErrorMessage(err) + LoggerInstance.error('[Encrypt Data] Error:', message) + toast.error(message) + } LoggerInstance.log( '[setNFTMetadataAndTokenURI] Got encrypted DDO', encryptedDdo diff --git a/src/@utils/order.ts b/src/@utils/order.ts index 8b2e1a116..2f5457274 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -11,7 +11,8 @@ import { ProviderComputeInitialize, ProviderFees, ProviderInstance, - ProviderInitialize + ProviderInitialize, + getErrorMessage } from '@oceanprotocol/lib' import { Signer, ethers } from 'ethers' import { getOceanConfig } from './ocean' @@ -38,7 +39,9 @@ async function initializeProvider( ) return provider } catch (error) { - LoggerInstance.log('[Initialize Provider] Error:', error) + const message = getErrorMessage(error) + LoggerInstance.log('[Initialize Provider] Error:', message) + toast.error(message) } } @@ -102,17 +105,15 @@ export async function order( const tx: any = await approve( signer, config, - accountId, + await signer.getAddress(), asset.accessDetails.baseToken.address, config.fixedRateExchangeAddress, - await amountToUnits( - signer, - asset?.accessDetails?.baseToken?.address, - orderPriceAndFees.price - ), + orderPriceAndFees.price, false ) - const txApprove = await tx.wait() + console.log('typeof(tx) ', typeof tx) + const txApprove = typeof tx !== 'number' ? await tx.wait() : tx + console.log('txApprove', txApprove) if (!txApprove) { return } @@ -120,6 +121,25 @@ export async function order( config.fixedRateExchangeAddress, signer ) + console.log( + ' await fixedRate.getDatatokenSupply(exchangeId)', + await fre.getDatatokenSupply(asset.accessDetails?.addressOrId) + ) + + console.log( + ' await fixedRate.getBasetokenSupply(exchangeId)', + await fre.getBasetokenSupply(asset.accessDetails?.addressOrId) + ) + console.log( + 'await signer.getAddress(), ==', + await signer.getAddress() + ) + console.log('account id ==', accountId) + console.log('orderPriceAndFees.price, ==', orderPriceAndFees.price) + console.log( + ' asset.accessDetails?.addressOrId ==', + asset.accessDetails?.addressOrId + ) const freTx = await fre.buyDatatokens( asset.accessDetails?.addressOrId, '1', @@ -127,6 +147,9 @@ export async function order( marketFeeAddress, consumeMarketFixedSwapFee ) + console.log('freTx ==', freTx) + const buyDtTx = await freTx.wait() + console.log('buyDtTx ==', buyDtTx) } return await datatoken.startOrder( asset.accessDetails.datatoken.address, @@ -143,14 +166,18 @@ export async function order( accountId, asset.accessDetails.baseToken.address, asset.accessDetails.datatoken.address, - await amountToUnits( - signer, - asset?.accessDetails?.baseToken?.address, - orderPriceAndFees.price - ), + orderPriceAndFees.price, + // await amountToUnits( + // signer, + // asset?.accessDetails?.baseToken?.address, + + // ), false ) - const txApprove = await tx.wait() + console.log('tx 2', tx) + // const txApprove = await tx.wait() + const txApprove = typeof tx !== 'number' ? await tx.wait() : tx + console.log('txApprove 2', txApprove) if (!txApprove) { return } diff --git a/src/@utils/provider.ts b/src/@utils/provider.ts index c433fd7b0..2f3d39c78 100644 --- a/src/@utils/provider.ts +++ b/src/@utils/provider.ts @@ -12,11 +12,14 @@ import { ProviderComputeInitializeResults, ProviderInstance, UrlFile, - AbiItem + AbiItem, + getErrorMessage } from '@oceanprotocol/lib' import { QueryHeader } from '@shared/FormInput/InputElement/Headers' import { Signer } from 'ethers' import { getValidUntilTime } from './compute' +import { toast } from 'react-toastify' +import { tr } from 'date-fns/locale' export async function initializeProviderForCompute( dataset: AssetExtended, @@ -51,7 +54,9 @@ export async function initializeProviderForCompute( accountId ) } catch (error) { - LoggerInstance.error(`Error initializing provider for the compute job!`) + const message = getErrorMessage(error) + LoggerInstance.error('[Initialize Provider] Error:', message) + toast.error(message) return null } } @@ -67,7 +72,9 @@ export async function getEncryptedFiles( const response = await ProviderInstance.encrypt(files, chainId, providerUrl) return response } catch (error) { - console.error('Error parsing json: ' + error.message) + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Encrypt] Error:', message) + toast.error(message) } } @@ -86,7 +93,9 @@ export async function getFileDidInfo( ) return response } catch (error) { - LoggerInstance.error(error.message) + const message = getErrorMessage(error) + LoggerInstance.error('[Initialize check file did] Error:', message) + toast.error(message) } } @@ -100,76 +109,99 @@ export async function getFileInfo( chainId?: number, method?: string ): Promise { - try { - let response - const headersProvider = {} - if (headers?.length > 0) { - headers.map((el) => { - headersProvider[el.key] = el.value - return el - }) - } + let response + const headersProvider = {} + if (headers?.length > 0) { + headers.map((el) => { + headersProvider[el.key] = el.value + return el + }) + } - switch (storageType) { - case 'ipfs': { - const fileIPFS: Ipfs = { - type: storageType, - hash: file - } + switch (storageType) { + case 'ipfs': { + const fileIPFS: Ipfs = { + type: storageType, + hash: file + } + try { response = await ProviderInstance.getFileInfo(fileIPFS, providerUrl) - break + } catch (error) { + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Get File info] Error:', message) + toast.error(message) + } + break + } + case 'arweave': { + const fileArweave: Arweave = { + type: storageType, + transactionId: file } - case 'arweave': { - const fileArweave: Arweave = { - type: storageType, - transactionId: file - } + try { response = await ProviderInstance.getFileInfo(fileArweave, providerUrl) - break + } catch (error) { + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Get File info] Error:', message) + toast.error(message) } - case 'graphql': { - const fileGraphql: GraphqlQuery = { - type: storageType, - url: file, - headers: headersProvider, - query - } - + break + } + case 'graphql': { + const fileGraphql: GraphqlQuery = { + type: storageType, + url: file, + headers: headersProvider, + query + } + try { response = await ProviderInstance.getFileInfo(fileGraphql, providerUrl) - break + } catch (error) { + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Get File info] Error:', message) + toast.error(message) } - case 'smartcontract': { - // clean obj - const fileSmartContract: Smartcontract = { - chainId, - type: storageType, - address: file, - abi: JSON.parse(abi) as AbiItem - } - + break + } + case 'smartcontract': { + // clean obj + const fileSmartContract: Smartcontract = { + chainId, + type: storageType, + address: file, + abi: JSON.parse(abi) as AbiItem + } + try { response = await ProviderInstance.getFileInfo( fileSmartContract, providerUrl ) - break + } catch (error) { + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Get File info] Error:', message) + toast.error(message) } - default: { - const fileUrl: UrlFile = { - type: 'url', - index: 0, - url: file, - headers: headersProvider, - method - } - + break + } + default: { + const fileUrl: UrlFile = { + type: 'url', + index: 0, + url: file, + headers: headersProvider, + method + } + try { response = await ProviderInstance.getFileInfo(fileUrl, providerUrl) - break + } catch (error) { + const message = getErrorMessage(error) + 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( @@ -178,14 +210,21 @@ export async function downloadFile( accountId: string, validOrderTx?: string ) { - const downloadUrl = await ProviderInstance.getDownloadUrl( - asset.id, - asset.services[0].id, - 0, - validOrderTx || asset.accessDetails.validOrderTx, - asset.services[0].serviceEndpoint, - signer - ) + let downloadUrl + try { + downloadUrl = await ProviderInstance.getDownloadUrl( + asset.id, + asset.services[0].id, + 0, + validOrderTx || asset.accessDetails.validOrderTx, + asset.services[0].serviceEndpoint, + signer + ) + } catch (error) { + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Get download url] Error:', message) + toast.error(message) + } await downloadFileBrowser(downloadUrl) } @@ -196,6 +235,8 @@ export async function checkValidProvider( const response = await ProviderInstance.isValidProvider(providerUrl) return response } catch (error) { - LoggerInstance.error(error.message) + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Check] Error:', message) + toast.error(message) } } diff --git a/src/components/@shared/FormInput/InputElement/Provider/index.tsx b/src/components/@shared/FormInput/InputElement/Provider/index.tsx index d54899b67..645d68d3f 100644 --- a/src/components/@shared/FormInput/InputElement/Provider/index.tsx +++ b/src/components/@shared/FormInput/InputElement/Provider/index.tsx @@ -5,12 +5,17 @@ import { InputProps } from '@shared/FormInput' import FileInfo from '../FilesInput/Info' import styles from './index.module.css' 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 { getOceanConfig } from '@utils/ocean' import axios from 'axios' import { useCancelToken } from '@hooks/useCancelToken' import { useNetwork } from 'wagmi' +import { toast } from 'react-toastify' export default function CustomProvider(props: InputProps): ReactElement { const { chain } = useNetwork() @@ -56,8 +61,9 @@ export default function CustomProvider(props: InputProps): ReactElement { // if all good, add provider to formik state helpers.setValue({ url: field.value.url, valid: isValid, custom: true }) } catch (error) { - setFieldError(`${field.name}.url`, error.message) - LoggerInstance.error(error.message) + const message = getErrorMessage(error) + setFieldError(`${field.name}.url`, message) + LoggerInstance.error('[Custom Provider]:', message) } finally { setIsLoading(false) } diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index a001898b8..dc42f4814 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -14,7 +14,8 @@ import { ProviderComputeInitializeResults, unitsToAmount, minAbi, - ProviderFees + ProviderFees, + getErrorMessage } from '@oceanprotocol/lib' import { toast } from 'react-toastify' import Price from '@shared/Price' @@ -430,9 +431,10 @@ export default function Compute({ setRefetchJobs(!refetchJobs) initPriceAndFees() } catch (error) { - setError(error.message) + const message = getErrorMessage(error) + LoggerInstance.error('[Compute] Error:', message) + setError(message) setRetry(true) - LoggerInstance.error(`[compute] ${error.message} `) } finally { setIsOrdering(false) } diff --git a/src/components/Profile/History/ComputeJobs/Results.tsx b/src/components/Profile/History/ComputeJobs/Results.tsx index 6df9cd926..dd3810167 100644 --- a/src/components/Profile/History/ComputeJobs/Results.tsx +++ b/src/components/Profile/History/ComputeJobs/Results.tsx @@ -1,6 +1,7 @@ import { ComputeResultType, downloadFileBrowser, + getErrorMessage, LoggerInstance, Provider } from '@oceanprotocol/lib' @@ -13,6 +14,7 @@ import content from '../../../../../content/pages/history.json' import { useCancelToken } from '@hooks/useCancelToken' import { getAsset } from '@utils/aquarius' import { useAccount, useSigner } from 'wagmi' +import { toast } from 'react-toastify' export default function Results({ job @@ -70,7 +72,9 @@ export default function Results({ ) await downloadFileBrowser(jobResult) } catch (error) { - LoggerInstance.error(error.message) + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Get c2d results url] Error:', message) + toast.error(message) } } diff --git a/src/components/Publish/index.tsx b/src/components/Publish/index.tsx index 065dcbacb..067472df1 100644 --- a/src/components/Publish/index.tsx +++ b/src/components/Publish/index.tsx @@ -13,7 +13,12 @@ import { Steps } from './Steps' import { FormPublishData } from './_types' import { useUserPreferences } from '@context/UserPreferences' 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 { validationSchema } from './_validation' import { useAbortController } from '@hooks/useAbortController' @@ -134,12 +139,17 @@ export default function PublishPage({ setDdo(ddo) LoggerInstance.log('[publish] Got new DDO', ddo) - const ddoEncrypted = await ProviderInstance.encrypt( - ddo, - ddo.chainId, - values.services[0].providerUrl.url, - newAbortController() - ) + try { + const ddoEncrypted = await ProviderInstance.encrypt( + ddo, + ddo.chainId, + values.services[0].providerUrl.url, + newAbortController() + ) + } catch (error) { + const message = getErrorMessage(error) + LoggerInstance.error('[Provider Encrypt] Error:', message) + } if (!ddoEncrypted) throw new Error('No encrypted DDO received. Please try again.') From 5bab5e5580d4dc9156cf0563f175e2b092c65d7e Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Wed, 5 Jul 2023 00:51:56 +0300 Subject: [PATCH 3/6] more error handling updates --- src/@utils/accessDetailsAndPricing.ts | 2 +- src/@utils/compute.ts | 4 ++-- src/@utils/nft.ts | 4 ++-- src/@utils/order.ts | 2 +- src/@utils/provider.ts | 20 +++++++++---------- .../FormInput/InputElement/Provider/index.tsx | 2 +- .../Asset/AssetActions/Compute/index.tsx | 2 +- .../Profile/History/ComputeJobs/Results.tsx | 2 +- src/components/Publish/index.tsx | 2 +- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index 016e26903..400358ff0 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -189,7 +189,7 @@ export async function getOrderPriceAndFees( asset?.services[0].serviceEndpoint )) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Initialize Provider] Error:', message) toast.error(message) } diff --git a/src/@utils/compute.ts b/src/@utils/compute.ts index 05928e75d..d6ddfaa16 100644 --- a/src/@utils/compute.ts +++ b/src/@utils/compute.ts @@ -148,7 +148,7 @@ export async function getComputeEnviroment( if (!computeEnvs[asset.chainId][0]) return null return computeEnvs[asset.chainId][0] } catch (e) { - const message = getErrorMessage(e) + const message = getErrorMessage(JSON.parse(e.message)) LoggerInstance.error( '[Compute to Data] Fetch compute environment:', message @@ -261,7 +261,7 @@ async function getJobs( }) } } catch (err) { - const message = getErrorMessage(err) + const message = getErrorMessage(JSON.parse(err.message)) LoggerInstance.error('[Compute to Data] Error:', message) toast.error(message) } diff --git a/src/@utils/nft.ts b/src/@utils/nft.ts index 0b83e5dbb..6ce8c41f8 100644 --- a/src/@utils/nft.ts +++ b/src/@utils/nft.ts @@ -112,7 +112,7 @@ export async function setNftMetadata( signal ) } catch (err) { - const message = getErrorMessage(err) + const message = getErrorMessage(JSON.parse(err.message)) LoggerInstance.error('[Encrypt Data] Error:', message) toast.error(message) } @@ -154,7 +154,7 @@ export async function setNFTMetadataAndTokenURI( signal ) } catch (err) { - const message = getErrorMessage(err) + const message = getErrorMessage(JSON.parse(err.message)) LoggerInstance.error('[Encrypt Data] Error:', message) toast.error(message) } diff --git a/src/@utils/order.ts b/src/@utils/order.ts index 2f5457274..63b29462c 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -39,7 +39,7 @@ async function initializeProvider( ) return provider } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.log('[Initialize Provider] Error:', message) toast.error(message) } diff --git a/src/@utils/provider.ts b/src/@utils/provider.ts index 2f3d39c78..b5bc852c7 100644 --- a/src/@utils/provider.ts +++ b/src/@utils/provider.ts @@ -54,7 +54,7 @@ export async function initializeProviderForCompute( accountId ) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Initialize Provider] Error:', message) toast.error(message) return null @@ -72,7 +72,7 @@ export async function getEncryptedFiles( const response = await ProviderInstance.encrypt(files, chainId, providerUrl) return response } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Encrypt] Error:', message) toast.error(message) } @@ -93,7 +93,7 @@ export async function getFileDidInfo( ) return response } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Initialize check file did] Error:', message) toast.error(message) } @@ -127,7 +127,7 @@ export async function getFileInfo( try { response = await ProviderInstance.getFileInfo(fileIPFS, providerUrl) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Get File info] Error:', message) toast.error(message) } @@ -141,7 +141,7 @@ export async function getFileInfo( try { response = await ProviderInstance.getFileInfo(fileArweave, providerUrl) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Get File info] Error:', message) toast.error(message) } @@ -157,7 +157,7 @@ export async function getFileInfo( try { response = await ProviderInstance.getFileInfo(fileGraphql, providerUrl) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Get File info] Error:', message) toast.error(message) } @@ -177,7 +177,7 @@ export async function getFileInfo( providerUrl ) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Get File info] Error:', message) toast.error(message) } @@ -194,7 +194,7 @@ export async function getFileInfo( try { response = await ProviderInstance.getFileInfo(fileUrl, providerUrl) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Get File info] Error:', message) toast.error(message) } @@ -221,7 +221,7 @@ export async function downloadFile( signer ) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Get download url] Error:', message) toast.error(message) } @@ -235,7 +235,7 @@ export async function checkValidProvider( const response = await ProviderInstance.isValidProvider(providerUrl) return response } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Check] Error:', message) toast.error(message) } diff --git a/src/components/@shared/FormInput/InputElement/Provider/index.tsx b/src/components/@shared/FormInput/InputElement/Provider/index.tsx index 645d68d3f..b734749d4 100644 --- a/src/components/@shared/FormInput/InputElement/Provider/index.tsx +++ b/src/components/@shared/FormInput/InputElement/Provider/index.tsx @@ -61,7 +61,7 @@ export default function CustomProvider(props: InputProps): ReactElement { // if all good, add provider to formik state helpers.setValue({ url: field.value.url, valid: isValid, custom: true }) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) setFieldError(`${field.name}.url`, message) LoggerInstance.error('[Custom Provider]:', message) } finally { diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index dc42f4814..1c0f82e89 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -431,7 +431,7 @@ export default function Compute({ setRefetchJobs(!refetchJobs) initPriceAndFees() } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Compute] Error:', message) setError(message) setRetry(true) diff --git a/src/components/Profile/History/ComputeJobs/Results.tsx b/src/components/Profile/History/ComputeJobs/Results.tsx index dd3810167..a4a564bae 100644 --- a/src/components/Profile/History/ComputeJobs/Results.tsx +++ b/src/components/Profile/History/ComputeJobs/Results.tsx @@ -72,7 +72,7 @@ export default function Results({ ) await downloadFileBrowser(jobResult) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Get c2d results url] Error:', message) toast.error(message) } diff --git a/src/components/Publish/index.tsx b/src/components/Publish/index.tsx index 067472df1..27bb81c7e 100644 --- a/src/components/Publish/index.tsx +++ b/src/components/Publish/index.tsx @@ -147,7 +147,7 @@ export default function PublishPage({ newAbortController() ) } catch (error) { - const message = getErrorMessage(error) + const message = getErrorMessage(JSON.parse(error.message)) LoggerInstance.error('[Provider Encrypt] Error:', message) } From 0c4074500d89f1c8060f0fd4aecd603f01ca0ccd Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Wed, 5 Jul 2023 15:48:35 +0300 Subject: [PATCH 4/6] cleanups --- src/@utils/order.ts | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/@utils/order.ts b/src/@utils/order.ts index 63b29462c..b9966af1a 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -111,9 +111,7 @@ export async function order( orderPriceAndFees.price, false ) - console.log('typeof(tx) ', typeof tx) const txApprove = typeof tx !== 'number' ? await tx.wait() : tx - console.log('txApprove', txApprove) if (!txApprove) { return } @@ -121,25 +119,6 @@ export async function order( config.fixedRateExchangeAddress, signer ) - console.log( - ' await fixedRate.getDatatokenSupply(exchangeId)', - await fre.getDatatokenSupply(asset.accessDetails?.addressOrId) - ) - - console.log( - ' await fixedRate.getBasetokenSupply(exchangeId)', - await fre.getBasetokenSupply(asset.accessDetails?.addressOrId) - ) - console.log( - 'await signer.getAddress(), ==', - await signer.getAddress() - ) - console.log('account id ==', accountId) - console.log('orderPriceAndFees.price, ==', orderPriceAndFees.price) - console.log( - ' asset.accessDetails?.addressOrId ==', - asset.accessDetails?.addressOrId - ) const freTx = await fre.buyDatatokens( asset.accessDetails?.addressOrId, '1', @@ -147,9 +126,7 @@ export async function order( marketFeeAddress, consumeMarketFixedSwapFee ) - console.log('freTx ==', freTx) const buyDtTx = await freTx.wait() - console.log('buyDtTx ==', buyDtTx) } return await datatoken.startOrder( asset.accessDetails.datatoken.address, @@ -167,17 +144,10 @@ export async function order( asset.accessDetails.baseToken.address, asset.accessDetails.datatoken.address, orderPriceAndFees.price, - // await amountToUnits( - // signer, - // asset?.accessDetails?.baseToken?.address, - - // ), false ) - console.log('tx 2', tx) - // const txApprove = await tx.wait() + const txApprove = typeof tx !== 'number' ? await tx.wait() : tx - console.log('txApprove 2', txApprove) if (!txApprove) { return } From a8a902ff0bf9e486345cf63937d33816c3c06fa2 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 14 Jul 2023 15:06:08 +0300 Subject: [PATCH 5/6] bump ocean lib --- package-lock.json | 30 +++++++++++++++--------------- package.json | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 18cc96deb..893bf6df1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@coingecko/cryptoformat": "^0.5.4", "@loadable/component": "^5.15.2", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^3.0.1", + "@oceanprotocol/lib": "^3.0.2", "@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/use-dark-mode": "^2.4.3", "@orbisclub/orbis-sdk": "^0.4.40", @@ -6076,16 +6076,16 @@ "integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA==" }, "node_modules/@oceanprotocol/contracts": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.8.tgz", - "integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ==" + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.14.tgz", + "integrity": "sha512-PJih7C6LHaWHHj1qgxZsSkEqKphhJrL3G7WuMOxl4N1daDrF6sooDDU+9dZkcHSVPc7cMjkFqLc5fP58NSAobw==" }, "node_modules/@oceanprotocol/lib": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz", - "integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.2.tgz", + "integrity": "sha512-yp75eYcFzqqgUAzG+fkLXHrNaA/ZZvogEE25NOy2DI5EAUp1Wm6tZ0q6AIH0i05KCPOfXoIGwqTBlfQa0rh48A==", "dependencies": { - "@oceanprotocol/contracts": "^1.1.8", + "@oceanprotocol/contracts": "^1.1.14", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", @@ -58452,16 +58452,16 @@ "integrity": "sha512-aUQtg4m5hJlQ0u8C29O9TXJWcAenO3G9vP+vf6LNFkpTDOCMycN/F0SzHS89VNrvGUha8oTDEg7FAkfZBPv2WA==" }, "@oceanprotocol/contracts": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.8.tgz", - "integrity": "sha512-I6xoADZpP/8EyN3VWZ+dLYv24DbJj3xzmSDcYv0FolXeAUF3FluzminL5AgQtAaoyUtlHl1D3ij1B++KupWcQQ==" + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.1.14.tgz", + "integrity": "sha512-PJih7C6LHaWHHj1qgxZsSkEqKphhJrL3G7WuMOxl4N1daDrF6sooDDU+9dZkcHSVPc7cMjkFqLc5fP58NSAobw==" }, "@oceanprotocol/lib": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.1.tgz", - "integrity": "sha512-9GPwQ5SBv4tej6YfrNmZpCnQPte6kinU3U7jPCdFAAVCpRc+IuQymu0/PfzYb1yo3GrMyGsp3ht6wjZDhy37QA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-3.0.2.tgz", + "integrity": "sha512-yp75eYcFzqqgUAzG+fkLXHrNaA/ZZvogEE25NOy2DI5EAUp1Wm6tZ0q6AIH0i05KCPOfXoIGwqTBlfQa0rh48A==", "requires": { - "@oceanprotocol/contracts": "^1.1.8", + "@oceanprotocol/contracts": "^1.1.14", "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.4.1", diff --git a/package.json b/package.json index 3cf452a79..848e55777 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@coingecko/cryptoformat": "^0.5.4", "@loadable/component": "^5.15.2", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^3.0.1", + "@oceanprotocol/lib": "^3.0.2", "@oceanprotocol/typographies": "^0.1.0", "@oceanprotocol/use-dark-mode": "^2.4.3", "@orbisclub/orbis-sdk": "^0.4.40", From 2d507292b6473900c9d9c2346a26904b849052ce Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Mon, 17 Jul 2023 08:16:52 +0300 Subject: [PATCH 6/6] fix publish try catch const assign --- src/components/Publish/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/Publish/index.tsx b/src/components/Publish/index.tsx index 27bb81c7e..a255fb7a2 100644 --- a/src/components/Publish/index.tsx +++ b/src/components/Publish/index.tsx @@ -139,8 +139,9 @@ export default function PublishPage({ setDdo(ddo) LoggerInstance.log('[publish] Got new DDO', ddo) + let ddoEncrypted: string try { - const ddoEncrypted = await ProviderInstance.encrypt( + ddoEncrypted = await ProviderInstance.encrypt( ddo, ddo.chainId, values.services[0].providerUrl.url,