diff --git a/.env.example b/.env.example index cb5c39b35..08a4c6ccd 100644 --- a/.env.example +++ b/.env.example @@ -7,4 +7,6 @@ GATSBY_NETWORK="rinkeby" #GATSBY_ANALYTICS_ID="xxx" #GATSBY_PORTIS_ID="xxx" #GATSBY_ALLOW_FIXED_PRICING="true" -#GATSBY_ALLOW_DYNAMIC_PRICING="true" \ No newline at end of file +#GATSBY_ALLOW_DYNAMIC_PRICING="true" +#GATSBY_ALLOW_ADVANCE_SETTINGS="true" +#GATSBY_CREDENTIAL_TYPE="address" diff --git a/app.config.js b/app.config.js index 722d0239d..e0e571849 100644 --- a/app.config.js +++ b/app.config.js @@ -43,5 +43,9 @@ module.exports = { // Used to show or hide the fixed and dynamic price options // tab to publishers during the price creation. allowFixedPricing: process.env.GATSBY_ALLOW_FIXED_PRICING || 'true', - allowDynamicPricing: process.env.GATSBY_ALLOW_DYNAMIC_PRICING || 'true' + allowDynamicPricing: process.env.GATSBY_ALLOW_DYNAMIC_PRICING || 'true', + + // Used to show or hide advance settings button in asset details page + allowAdvanceSettings: process.env.GATSBY_ALLOW_ADVANCE_SETTINGS || 'false', + credentialType: process.env.GATSBY_CREDENTIAL_TYPE || 'address' } diff --git a/src/components/organisms/AssetActions/Edit/DebugEditAdvanceSettings.tsx b/src/components/organisms/AssetActions/Edit/DebugEditAdvanceSettings.tsx index e41b3f803..cd0060926 100644 --- a/src/components/organisms/AssetActions/Edit/DebugEditAdvanceSettings.tsx +++ b/src/components/organisms/AssetActions/Edit/DebugEditAdvanceSettings.tsx @@ -1,29 +1,32 @@ -import { DDO, ServiceComputePrivacy } from '@oceanprotocol/lib' +import { DDO, Credentials, CredentialType } from '@oceanprotocol/lib' import React, { ReactElement, useEffect, useState } from 'react' import { AdvanceSettingsForm } from '../../../../models/FormEditCredential' import { useOcean } from '../../../../providers/Ocean' import DebugOutput from '../../../atoms/DebugOutput' -import { Credential } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Credentials' export default function DebugEditCredential({ values, - ddo + ddo, + credentialType }: { values: AdvanceSettingsForm ddo: DDO + credentialType: CredentialType }): ReactElement { const { ocean } = useOcean() - const [credential, setCredential] = useState() + const [credential, setCredential] = useState() useEffect(() => { if (!ocean) return async function transformValues() { - // const credential = await transformComputeFormToServiceComputePrivacy( - // values, - // ocean - // ) - // setCredential(credential) + const newDdo = await ocean.assets.updateCredentials( + ddo, + credentialType, + values.allowCredentail, + [] // TODO: denyCredential + ) + setCredential(newDdo.credentials) } transformValues() }, [values, ddo, ocean]) diff --git a/src/components/organisms/AssetActions/Edit/EditAdvanceSettings.tsx b/src/components/organisms/AssetActions/Edit/EditAdvanceSettings.tsx index e4e104c7b..bb443940f 100644 --- a/src/components/organisms/AssetActions/Edit/EditAdvanceSettings.tsx +++ b/src/components/organisms/AssetActions/Edit/EditAdvanceSettings.tsx @@ -3,7 +3,7 @@ import React, { ReactElement, useState } from 'react' import { useAsset } from '../../../../providers/Asset' import { useUserPreferences } from '../../../../providers/UserPreferences' import styles from './index.module.css' -import { DDO, Logger } from '@oceanprotocol/lib' +import { Logger, CredentialType } from '@oceanprotocol/lib' import MetadataFeedback from '../../../molecules/MetadataFeedback' import { graphql, useStaticQuery } from 'gatsby' import { useWeb3 } from '../../../../providers/Web3' @@ -15,7 +15,7 @@ import { validationSchema } from '../../../../models/FormEditCredential' import DebugEditAdvanceSettings from './DebugEditAdvanceSettings' -import { CredentialType } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Credentials' +import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' const contentQuery = graphql` query EditAvanceSettingsQuery { @@ -59,24 +59,38 @@ export default function EditAdvanceSettings({ const { metadata, ddo, refreshDdo, price } = useAsset() const [success, setSuccess] = useState() const [error, setError] = useState() + const { appConfig } = useSiteMetadata() const hasFeedback = error || success - // TODO : get from env - //const credentialType = CredentialType.address + + let credentialType: CredentialType + switch (appConfig.credentialType) { + case 'address': + credentialType = CredentialType.address + break + case 'credential3Box': + credentialType = CredentialType.credential3Box + break + default: + credentialType = CredentialType.address + } async function handleSubmit( values: Partial, resetForm: () => void ) { try { - // const ddoEditedCredential = await ocean.assets.updateCredentials( - // ddo, - // credentialType, - // values.allowCredentail, - // [] - // ) + const ddoEditedCredential = await ocean.assets.updateCredentials( + ddo, + credentialType, + values.allowCredentail, + [] // TODO: denyCredential + ) - const storedddo = await ocean.assets.updateMetadata(ddo, accountId) + const storedddo = await ocean.assets.updateMetadata( + ddoEditedCredential, + accountId + ) if (!storedddo) { setError(content.form.error) @@ -94,8 +108,7 @@ export default function EditAdvanceSettings({ return ( { window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) @@ -124,13 +137,16 @@ export default function EditAdvanceSettings({ {debug === true && (
- +
)} diff --git a/src/components/organisms/AssetActions/Edit/FormAdvanceSettings.tsx b/src/components/organisms/AssetActions/Edit/FormAdvanceSettings.tsx index 89816cf2f..3df85348c 100644 --- a/src/components/organisms/AssetActions/Edit/FormAdvanceSettings.tsx +++ b/src/components/organisms/AssetActions/Edit/FormAdvanceSettings.tsx @@ -1,5 +1,5 @@ import React, { ChangeEvent, ReactElement } from 'react' -import styles from './FormEditMetadata.module.css' //TODO +import styles from './FormEditMetadata.module.css' // TODO import { Field, Form, FormikContextType, useFormikContext } from 'formik' import Button from '../../../atoms/Button' import Input from '../../../atoms/Input' @@ -10,12 +10,10 @@ import { AdvanceSettingsForm } from '../../../../models/FormEditCredential' export default function FormAdvanceSettings({ data, - setShowEdit, - values + setShowEdit }: { data: FormFieldProps[] setShowEdit: (show: boolean) => void - values: Partial }): ReactElement { const { accountId } = useWeb3() const { ocean, config } = useOcean() @@ -40,7 +38,6 @@ export default function FormAdvanceSettings({ key={field.name} {...field} component={Input} - prefix={field.name === 'price' && config.oceanTokenSymbol} onChange={(e: ChangeEvent) => handleFieldChange(e, field) } @@ -48,6 +45,9 @@ export default function FormAdvanceSettings({ ))}