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

#638 Add deny credential and isOrderDisabled

This commit is contained in:
KY Lau 2021-06-09 14:12:52 +08:00
parent 9f44ee9833
commit bfe70a3ff7
7 changed files with 97 additions and 32 deletions

View File

@ -7,10 +7,24 @@
"data": [ "data": [
{ {
"name": "allow", "name": "allow",
"label": "Wallet Address", "label": "Allow Credential",
"placeholder": "e.g. 0x12345678901234567890abcd", "placeholder": "e.g. 0x12345678901234567890abcd",
"help": "Enter wallet address and click ADD button to append the list", "help": "Enter wallet address and click ADD button to append the list",
"type": "credential" "type": "credential"
},
{
"name": "deny",
"label": "Deny Credential",
"placeholder": "e.g. 0x12345678901234567890abcd",
"help": "Enter wallet address and click ADD button to append the list",
"type": "credential"
},
{
"name": "isDisable",
"label": "Disable Consumption",
"help": "Disable dataset being consume when dataset undergoing maintenance.",
"type": "checkbox",
"options": ["Disable"]
} }
] ]
} }

View File

@ -1,4 +1,5 @@
.chip { .chip {
border: 1px solid var(--border-color);
display: flex; display: flex;
margin-top: 5px; margin-top: 5px;
margin-bottom: 5px; margin-bottom: 5px;
@ -7,7 +8,6 @@
.input { .input {
font-size: var(--font-size-base); font-size: var(--font-size-base);
font-family: var(--font-family-base); font-family: var(--font-family-base);
font-weight: var(--font-weight-bold);
color: var(--font-color-heading); color: var(--font-color-heading);
border: 1px solid var(--border-color); border: 1px solid var(--border-color);
box-shadow: none; box-shadow: none;
@ -30,3 +30,23 @@
fill: var(--brand-pink); fill: var(--brand-pink);
transform: rotate(90deg); transform: rotate(90deg);
} }
.scroll {
border-top: 1px solid var(--border-color);
margin-top: calc(var(--spacer) / 4);
min-height: fit-content;
max-height: 50vh;
position: relative;
overflow: auto;
-webkit-overflow-scrolling: touch;
}
.credential {
padding: 0;
border: 1px solid var(--border-color);
background-color: var(--background-highlight);
border-radius: var(--border-radius);
margin-bottom: calc(var(--spacer) / 2);
font-size: var(--font-size-small);
min-height: 200px;
}

View File

@ -42,7 +42,7 @@ export default function Credential(props: InputProps) {
} }
return ( return (
<div> <div className={styles.credential}>
<InputGroup> <InputGroup>
<input <input
className={styles.input} className={styles.input}
@ -57,21 +57,23 @@ export default function Credential(props: InputProps) {
Add Add
</Button> </Button>
</InputGroup> </InputGroup>
{arrayInput && <div className={styles.scroll}>
arrayInput.map((value) => { {arrayInput &&
return ( arrayInput.map((value) => {
<div className={styles.chip} key={value}> return (
{value} <div className={styles.chip} key={value}>
<Button {value}
className={styles.crossButton} <Button
style="text" className={styles.crossButton}
onClick={(even) => handleDeleteChip(value)} style="text"
> onClick={(even) => handleDeleteChip(value)}
<Cross /> >
</Button> <Cross />
</div> </Button>
) </div>
})} )
})}
</div>
</div> </div>
) )
} }

View File

@ -4,6 +4,11 @@ import { AdvanceSettingsForm } from '../../../../models/FormEditCredential'
import { useOcean } from '../../../../providers/Ocean' import { useOcean } from '../../../../providers/Ocean'
import DebugOutput from '../../../atoms/DebugOutput' import DebugOutput from '../../../atoms/DebugOutput'
export interface AdvanceSettings {
credentail: Credentials
isOrderDisabled: boolean
}
export default function DebugEditCredential({ export default function DebugEditCredential({
values, values,
ddo, ddo,
@ -14,7 +19,7 @@ export default function DebugEditCredential({
credentialType: CredentialType credentialType: CredentialType
}): ReactElement { }): ReactElement {
const { ocean } = useOcean() const { ocean } = useOcean()
const [credential, setCredential] = useState<Credentials>() const [advanceSettings, setAdvanceSettings] = useState<AdvanceSettings>()
useEffect(() => { useEffect(() => {
if (!ocean) return if (!ocean) return
@ -24,9 +29,12 @@ export default function DebugEditCredential({
ddo, ddo,
credentialType, credentialType,
values.allow, values.allow,
[] // TODO: denyCredential values.deny
) )
setCredential(newDdo.credentials) setAdvanceSettings({
credentail: newDdo.credentials,
isOrderDisabled: values.isOrderDisabled
})
} }
transformValues() transformValues()
}, [values, ddo, ocean]) }, [values, ddo, ocean])
@ -34,7 +42,7 @@ export default function DebugEditCredential({
return ( return (
<> <>
<DebugOutput title="Collected Form Values" output={values} /> <DebugOutput title="Collected Form Values" output={values} />
<DebugOutput title="Transformed Form Values" output={ddo.credentials} /> <DebugOutput title="Transformed Form Values" output={advanceSettings} />
</> </>
) )
} }

View File

@ -3,7 +3,7 @@ import React, { ReactElement, useState } from 'react'
import { useAsset } from '../../../../providers/Asset' import { useAsset } from '../../../../providers/Asset'
import { useUserPreferences } from '../../../../providers/UserPreferences' import { useUserPreferences } from '../../../../providers/UserPreferences'
import styles from './index.module.css' import styles from './index.module.css'
import { Logger, CredentialType } from '@oceanprotocol/lib' import { Logger, CredentialType, DDO } from '@oceanprotocol/lib'
import MetadataFeedback from '../../../molecules/MetadataFeedback' import MetadataFeedback from '../../../molecules/MetadataFeedback'
import { graphql, useStaticQuery } from 'gatsby' import { graphql, useStaticQuery } from 'gatsby'
import { useWeb3 } from '../../../../providers/Web3' import { useWeb3 } from '../../../../providers/Web3'
@ -36,6 +36,7 @@ const contentQuery = graphql`
label label
help help
type type
options
} }
} }
} }
@ -80,17 +81,21 @@ export default function EditAdvanceSettings({
resetForm: () => void resetForm: () => void
) { ) {
try { try {
const ddoEditedCredential = await ocean.assets.updateCredentials( let newDdo: DDO
newDdo = await ocean.assets.updateCredentials(
ddo, ddo,
credentialType, credentialType,
values.allow, values.allow,
[] // TODO: denyCredential values.deny
) )
const storedddo = await ocean.assets.updateMetadata( newDdo = await ocean.assets.editMetadata(newDdo, {
ddoEditedCredential, status: {
accountId isOrderDisabled: values.isOrderDisabled
) }
})
const storedddo = await ocean.assets.updateMetadata(newDdo, accountId)
if (!storedddo) { if (!storedddo) {
setError(content.form.error) setError(content.form.error)

View File

@ -28,7 +28,9 @@ export default function FormAdvanceSettings({
field: FormFieldProps field: FormFieldProps
) { ) {
validateField(field.name) validateField(field.name)
setFieldValue(field.name, e.target.value) if (e.target.type === 'checkbox')
setFieldValue(field.name, e.target.checked)
else setFieldValue(field.name, e.target.value)
} }
return ( return (

View File

@ -8,11 +8,15 @@ import * as Yup from 'yup'
export interface AdvanceSettingsForm { export interface AdvanceSettingsForm {
allow: string[] allow: string[]
deny: string[]
isOrderDisabled: boolean
} }
export const validationSchema: Yup.SchemaOf<AdvanceSettingsForm> = Yup.object().shape( export const validationSchema: Yup.SchemaOf<AdvanceSettingsForm> = Yup.object().shape(
{ {
allow: Yup.array().nullable() allow: Yup.array().nullable(),
deny: Yup.array().nullable(),
isOrderDisabled: Yup.boolean().nullable()
} }
) )
@ -49,5 +53,15 @@ export function getInitialValues(
credentailType, credentailType,
'allow' 'allow'
) )
return { allow: allowCrendtail } const denyCrendtail = getAssetCredentials(
ddo.credentials,
credentailType,
'deny'
)
const metadata = ddo.findServiceByType('metadata')
return {
allow: allowCrendtail,
deny: denyCrendtail,
isOrderDisabled: metadata.attributes?.status?.isOrderDisabled || false
}
} }