From 33edc3f5f48c1022b2e64ff0a7c274ee68abc102 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 16 Jun 2022 03:10:08 -0700 Subject: [PATCH] Update file (#1518) * update version and file Signed-off-by: mihaisc * update label and description Signed-off-by: mihaisc * remove dot Signed-off-by: mihaisc * remove helper props so we don't add them on chain Signed-off-by: mihaisc * bump ocean.js to v1.1.2 * build fix Co-authored-by: Matthias Kretschmann --- content/pages/edit.json | 17 +++++++--- package-lock.json | 14 ++++---- package.json | 2 +- src/@utils/provider.ts | 6 ++-- src/components/@shared/FileIcon/index.tsx | 4 +-- .../@shared/FormFields/FilesInput/Info.tsx | 4 +-- .../Asset/AssetActions/Compute/index.tsx | 4 +-- .../Asset/AssetActions/Download.tsx | 4 +-- src/components/Asset/AssetActions/index.tsx | 4 +-- src/components/Asset/Edit/EditMetadata.tsx | 32 +++++++++++++++++-- .../Asset/Edit/FormEditMetadata.tsx | 3 +- src/components/Asset/Edit/_constants.ts | 4 ++- src/components/Asset/Edit/_types.ts | 1 + src/components/Publish/_types.ts | 6 ++-- src/components/Publish/_validation.ts | 4 +-- 15 files changed, 74 insertions(+), 35 deletions(-) diff --git a/content/pages/edit.json b/content/pages/edit.json index 59d901dbb..2d526f630 100644 --- a/content/pages/edit.json +++ b/content/pages/edit.json @@ -30,13 +30,22 @@ "required": true }, { - "name": "links", - "label": "Sample file", - "placeholder": "e.g. https://file.com/samplefile.json", - "help": "Please provide a URL to a sample of your data set file. This file should reveal the data structure of your data set, e.g. by including the header and one line of a CSV file. This file URL will be publicly available after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.**", + "name": "files", + "label": "New file", + "placeholder": "e.g. https://file.com/file.json", + "help": "This URL will be stored encrypted after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.** For a compute data set, your file should match the file type required by the algorithm, and should not exceed 1 GB in file size. Leaving this field empty will not remove the current value.", "prominentHelp": true, "type": "files" }, + { + "name": "links", + "label": "New sample file", + "placeholder": "e.g. https://file.com/samplefile.json", + "help": "Please provide a URL to a sample of your data set file. This file should reveal the data structure of your data set, e.g. by including the header and one line of a CSV file. This file URL will be publicly available after publishing. **Please make sure that the endpoint is accessible over the internet and is not protected by a firewall or by credentials.** Leaving this field empty will not remove the current value.", + "prominentHelp": true, + "type": "files" + }, + { "name": "timeout", "label": "Timeout", diff --git a/package-lock.json b/package-lock.json index fc0a91f13..3643a118a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@coingecko/cryptoformat": "^0.5.4", "@loadable/component": "^5.15.2", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^1.0.0", + "@oceanprotocol/lib": "^1.1.2", "@oceanprotocol/typographies": "^0.1.0", "@portis/web3": "^4.0.7", "@tippyjs/react": "^4.2.6", @@ -4589,9 +4589,9 @@ "integrity": "sha512-rDCIooe1WHipLejuGhx2Wv/88SB7bWrN3+XHCWxXyPKTmmSQsgxKZPPzbIVBQ0ESChQZqGSBBJyqErqwwW4eBw==" }, "node_modules/@oceanprotocol/lib": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0.tgz", - "integrity": "sha512-nJ8MBQZtv4fldTc9m2BlpvirImVOa3V2/ckJH1xGPQ4PZ4k5FZWmOQqM7LOdnwUJje661GT+SewR5MtNj/ewmw==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.1.2.tgz", + "integrity": "sha512-7NrD0qhmIKyv3GVkFlX31BdQ17aZU18a6HRogm0kpGK1Ldt9QwgEVQ157JA/lF+gUt4PB95u1OZSxsPUsBMx/g==", "dependencies": { "@oceanprotocol/contracts": "^1.0.0", "bignumber.js": "^9.0.2", @@ -44975,9 +44975,9 @@ "integrity": "sha512-rDCIooe1WHipLejuGhx2Wv/88SB7bWrN3+XHCWxXyPKTmmSQsgxKZPPzbIVBQ0ESChQZqGSBBJyqErqwwW4eBw==" }, "@oceanprotocol/lib": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.0.0.tgz", - "integrity": "sha512-nJ8MBQZtv4fldTc9m2BlpvirImVOa3V2/ckJH1xGPQ4PZ4k5FZWmOQqM7LOdnwUJje661GT+SewR5MtNj/ewmw==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@oceanprotocol/lib/-/lib-1.1.2.tgz", + "integrity": "sha512-7NrD0qhmIKyv3GVkFlX31BdQ17aZU18a6HRogm0kpGK1Ldt9QwgEVQ157JA/lF+gUt4PB95u1OZSxsPUsBMx/g==", "requires": { "@oceanprotocol/contracts": "^1.0.0", "bignumber.js": "^9.0.2", diff --git a/package.json b/package.json index 1a9b95e7c..6d4e438ed 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "@coingecko/cryptoformat": "^0.5.4", "@loadable/component": "^5.15.2", "@oceanprotocol/art": "^3.2.0", - "@oceanprotocol/lib": "^1.0.0", + "@oceanprotocol/lib": "^1.1.2", "@oceanprotocol/typographies": "^0.1.0", "@portis/web3": "^4.0.7", "@tippyjs/react": "^4.2.6", diff --git a/src/@utils/provider.ts b/src/@utils/provider.ts index 30497d5f6..817b6d376 100644 --- a/src/@utils/provider.ts +++ b/src/@utils/provider.ts @@ -1,6 +1,6 @@ import { downloadFileBrowser, - FileMetadata, + FileInfo, LoggerInstance, ProviderInstance } from '@oceanprotocol/lib' @@ -25,7 +25,7 @@ export async function getFileDidInfo( did: string, serviceId: string, providerUrl: string -): Promise { +): Promise { try { const response = await ProviderInstance.checkDidFiles( did, @@ -41,7 +41,7 @@ export async function getFileDidInfo( export async function getFileUrlInfo( url: string, providerUrl: string -): Promise { +): Promise { try { const response = await ProviderInstance.checkFileUrl(url, providerUrl) return response diff --git a/src/components/@shared/FileIcon/index.tsx b/src/components/@shared/FileIcon/index.tsx index 95429f6c5..e86128412 100644 --- a/src/components/@shared/FileIcon/index.tsx +++ b/src/components/@shared/FileIcon/index.tsx @@ -4,7 +4,7 @@ import classNames from 'classnames/bind' import cleanupContentType from '@utils/cleanupContentType' import styles from './index.module.css' import Loader from '@shared/atoms/Loader' -import { FileMetadata } from '@oceanprotocol/lib' +import { FileInfo } from '@oceanprotocol/lib' const cx = classNames.bind(styles) @@ -22,7 +22,7 @@ export default function FileIcon({ small, isLoading }: { - file: FileMetadata + file: FileInfo className?: string small?: boolean isLoading?: boolean diff --git a/src/components/@shared/FormFields/FilesInput/Info.tsx b/src/components/@shared/FormFields/FilesInput/Info.tsx index 1971760f5..2f1e8b782 100644 --- a/src/components/@shared/FormFields/FilesInput/Info.tsx +++ b/src/components/@shared/FormFields/FilesInput/Info.tsx @@ -2,13 +2,13 @@ import React, { ReactElement } from 'react' import { prettySize } from './utils' import cleanupContentType from '@utils/cleanupContentType' import styles from './Info.module.css' -import { FileMetadata } from '@oceanprotocol/lib' +import { FileInfo as FileInfoData } from '@oceanprotocol/lib' export default function FileInfo({ file, handleClose }: { - file: FileMetadata + file: FileInfoData handleClose(): void }): ReactElement { const contentTypeCleaned = file.contentType diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 2c3f49ce8..e07179539 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -3,7 +3,7 @@ import { Asset, DDO, PublisherTrustedAlgorithm, - FileMetadata + FileInfo } from '@oceanprotocol/lib' import { toast } from 'react-toastify' import Price from '@shared/Price' @@ -47,7 +47,7 @@ export default function Compute({ ddo: Asset accessDetails: AccessDetails dtBalance: string - file: FileMetadata + file: FileInfo fileIsLoading?: boolean isConsumable?: boolean consumableFeedback?: string diff --git a/src/components/Asset/AssetActions/Download.tsx b/src/components/Asset/AssetActions/Download.tsx index a63fb5996..fe536b94f 100644 --- a/src/components/Asset/AssetActions/Download.tsx +++ b/src/components/Asset/AssetActions/Download.tsx @@ -7,7 +7,7 @@ import ButtonBuy from '@shared/ButtonBuy' import { secondsToString } from '@utils/ddo' import AlgorithmDatasetsListForCompute from './Compute/AlgorithmDatasetsListForCompute' import styles from './Download.module.css' -import { FileMetadata, LoggerInstance, ZERO_ADDRESS } from '@oceanprotocol/lib' +import { FileInfo, LoggerInstance, ZERO_ADDRESS } from '@oceanprotocol/lib' import { order } from '@utils/order' import { AssetExtended } from 'src/@types/AssetExtended' import { buyDtFromPool } from '@utils/pool' @@ -29,7 +29,7 @@ export default function Download({ consumableFeedback }: { asset: AssetExtended - file: FileMetadata + file: FileInfo isBalanceSufficient: boolean dtBalance: string fileIsLoading?: boolean diff --git a/src/components/Asset/AssetActions/index.tsx b/src/components/Asset/AssetActions/index.tsx index e9ee4b509..4995acbc0 100644 --- a/src/components/Asset/AssetActions/index.tsx +++ b/src/components/Asset/AssetActions/index.tsx @@ -1,7 +1,7 @@ import React, { ReactElement, useState, useEffect } from 'react' import Compute from './Compute' import Consume from './Download' -import { FileMetadata, LoggerInstance, Datatoken } from '@oceanprotocol/lib' +import { FileInfo, LoggerInstance, Datatoken } from '@oceanprotocol/lib' import Tabs, { TabsItem } from '@shared/atoms/Tabs' import { compareAsBN } from '@utils/numbers' import Pool from './Pool' @@ -37,7 +37,7 @@ export default function AssetActions({ const [isBalanceSufficient, setIsBalanceSufficient] = useState() const [dtBalance, setDtBalance] = useState() - const [fileMetadata, setFileMetadata] = useState() + const [fileMetadata, setFileMetadata] = useState() const [fileIsLoading, setFileIsLoading] = useState(false) const isCompute = Boolean( asset?.services.filter((service) => service.type === 'compute')[0] diff --git a/src/components/Asset/Edit/EditMetadata.tsx b/src/components/Asset/Edit/EditMetadata.tsx index 1028c9ba8..c34abfd01 100644 --- a/src/components/Asset/Edit/EditMetadata.tsx +++ b/src/components/Asset/Edit/EditMetadata.tsx @@ -24,6 +24,7 @@ import EditFeedback from './EditFeedback' import { useAsset } from '@context/Asset' import { setNftMetadata } from '@utils/nft' import { sanitizeUrl } from '@utils/url' +import { getEncryptedFiles } from '@utils/provider' export default function Edit({ asset @@ -64,6 +65,7 @@ export default function Edit({ resetForm: () => void ) { try { + let updatedFiles = asset.services[0].files const linksTransformed = values.links?.length && values.links[0].valid && [sanitizeUrl(values.links[0].url)] const updatedMetadata: Metadata = { @@ -78,17 +80,43 @@ export default function Edit({ values.price !== asset.accessDetails.price && (await updateFixedPrice(values.price)) + if (values.files[0]?.url) { + const file = { + nftAddress: asset.nftAddress, + datatokenAddress: asset.services[0].datatokenAddress, + files: [ + { + type: 'url', + index: 0, + url: values.files[0].url, + method: 'GET' + } + ] + } + const filesEncrypted = await getEncryptedFiles( + file, + asset.services[0].serviceEndpoint + ) + updatedFiles = filesEncrypted + } const updatedService: Service = { ...asset.services[0], - timeout: mapTimeoutStringToSeconds(values.timeout) + timeout: mapTimeoutStringToSeconds(values.timeout), + files: updatedFiles } + // TODO: remove version update at a later time const updatedAsset: Asset = { - ...asset, + ...(asset as Asset), + version: '4.1.0', metadata: updatedMetadata, services: [updatedService] } + // delete custom helper properties injected in the market so we don't write them on chain + delete (updatedAsset as AssetExtended).accessDetails + delete (updatedAsset as AssetExtended).datatokens + delete (updatedAsset as AssetExtended).stats const setMetadataTx = await setNftMetadata( updatedAsset, accountId, diff --git a/src/components/Asset/Edit/FormEditMetadata.tsx b/src/components/Asset/Edit/FormEditMetadata.tsx index e7e5af8f2..a0a556fac 100644 --- a/src/components/Asset/Edit/FormEditMetadata.tsx +++ b/src/components/Asset/Edit/FormEditMetadata.tsx @@ -1,9 +1,8 @@ -import React, { ChangeEvent, ReactElement, useState } from 'react' +import React, { ChangeEvent, ReactElement } from 'react' import { Field, Form, FormikContextType, useFormikContext } from 'formik' import Input, { InputProps } from '@shared/FormInput' import FormActions from './FormActions' import styles from './FormEdit.module.css' -import { FormPublishData } from '../../Publish/_types' import { useAsset } from '@context/Asset' import { MetadataEditForm } from './_types' diff --git a/src/components/Asset/Edit/_constants.ts b/src/components/Asset/Edit/_constants.ts index a03a1416a..d27e5e2d9 100644 --- a/src/components/Asset/Edit/_constants.ts +++ b/src/components/Asset/Edit/_constants.ts @@ -1,4 +1,4 @@ -import { Metadata, ServiceComputeOptions } from '@oceanprotocol/lib' +import { FileInfo, Metadata, ServiceComputeOptions } from '@oceanprotocol/lib' import { secondsToString } from '@utils/ddo' import * as Yup from 'yup' import { MetadataEditForm } from './_types' @@ -10,6 +10,7 @@ export const validationSchema = Yup.object().shape({ description: Yup.string().required('Required').min(10), price: Yup.number().required('Required'), links: Yup.array().nullable(), + files: Yup.array().nullable(), timeout: Yup.string().required('Required'), author: Yup.string().nullable() }) @@ -24,6 +25,7 @@ export function getInitialValues( description: metadata?.description, price, links: metadata?.links, + files: '', timeout: secondsToString(timeout), author: metadata?.author } diff --git a/src/components/Asset/Edit/_types.ts b/src/components/Asset/Edit/_types.ts index b510246c3..0553ffa23 100644 --- a/src/components/Asset/Edit/_types.ts +++ b/src/components/Asset/Edit/_types.ts @@ -6,5 +6,6 @@ export interface MetadataEditForm { timeout: string price?: string links?: string | any[] + files: string | any[] author?: string } diff --git a/src/components/Publish/_types.ts b/src/components/Publish/_types.ts index 95c7cfed8..ee1c7409d 100644 --- a/src/components/Publish/_types.ts +++ b/src/components/Publish/_types.ts @@ -3,7 +3,7 @@ import { NftMetadata } from '@utils/nft' import { ReactElement } from 'react' import { PriceOptions } from 'src/@types/Price' -interface FileMetadata { +interface FileInfo { url: string valid?: boolean contentLength?: string @@ -11,8 +11,8 @@ interface FileMetadata { } export interface FormPublishService { - files: FileMetadata[] - links?: FileMetadata[] + files: FileInfo[] + links?: FileInfo[] timeout: string dataTokenOptions: { name: string; symbol: string } access: 'Download' | 'Compute' | string diff --git a/src/components/Publish/_validation.ts b/src/components/Publish/_validation.ts index fddce2af8..4a07332cf 100644 --- a/src/components/Publish/_validation.ts +++ b/src/components/Publish/_validation.ts @@ -146,7 +146,7 @@ export const validationSchema: Yup.SchemaOf = Yup.object().shape({ // .min(4, (param) => `Title must be at least ${param.min} characters`) // .required('Required'), // description: Yup.string().min(10).required('Required'), -// files: Yup.array().required('Required').nullable(), +// files: Yup.array().required('Required').nullable(), // timeout: Yup.string().required('Required'), // dataTokenOptions: Yup.object() // .shape({ @@ -167,6 +167,6 @@ export const validationSchema: Yup.SchemaOf = Yup.object().shape({ // // ---- optional fields ---- // algorithmPrivacy: Yup.boolean().nullable(), // tags: Yup.string().nullable(), -// links: Yup.array().nullable() +// links: Yup.array().nullable() // }) // .defined()