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

Fix complexity issue

This commit is contained in:
KY Lau 2021-06-10 10:20:22 +08:00
parent 9fc5de69b4
commit 80955b9065
2 changed files with 26 additions and 20 deletions

View File

@ -1,5 +1,5 @@
import React, { ChangeEvent, ReactElement } from 'react'
import styles from './FormEditMetadata.module.css' // TODO
import styles from './FormEditMetadata.module.css'
import { Field, Form, FormikContextType, useFormikContext } from 'formik'
import Button from '../../../atoms/Button'
import Input from '../../../atoms/Input'

View File

@ -1,5 +1,6 @@
import {
CredentialAction,
Credential,
Credentials,
CredentialType,
DDO
@ -19,48 +20,53 @@ export const validationSchema: Yup.SchemaOf<AdvanceSettingsForm> =
isOrderDisabled: Yup.boolean().nullable()
})
function getCredentialList(
credential: Credential[],
credentialType: CredentialType
): string[] {
const credentialByType = credential.find(
(credential) => credential.type === credentialType
)
return credentialByType.value && credentialByType.value.length > 0
? credentialByType.value
: []
}
function getAssetCredentials(
credentials: Credentials,
credentialType: CredentialType,
credentialAction: CredentialAction
): string[] {
let values: string[] = []
if (!credentials) return []
if (credentialAction === 'allow') {
if (credentials && credentials.allow) {
const allowList = credentials.allow.find(
(credential) => credential.type === credentialType
)
values = allowList && allowList.value.length > 0 ? allowList.value : []
}
} else {
if (credentials && credentials.deny) {
const dennyList = credentials.deny.find(
(credential) => credential.type === credentialType
)
values = dennyList && dennyList.value.length > 0 ? dennyList.value : []
}
return credentials.allow
? getCredentialList(credentials.allow, credentialType)
: []
}
return values
return credentials.deny
? getCredentialList(credentials.deny, credentialType)
: []
}
export function getInitialValues(
ddo: DDO,
credentailType: CredentialType
): AdvanceSettingsForm {
const allowCrendtail = getAssetCredentials(
const allowCredential = getAssetCredentials(
ddo.credentials,
credentailType,
'allow'
)
const denyCrendtail = getAssetCredentials(
const denyCredential = getAssetCredentials(
ddo.credentials,
credentailType,
'deny'
)
const metadata = ddo.findServiceByType('metadata')
return {
allow: allowCrendtail,
deny: denyCrendtail,
allow: allowCredential,
deny: denyCredential,
isOrderDisabled: metadata.attributes?.status?.isOrderDisabled || false
}
}