mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
parent
fa6bedf543
commit
9f2cbaafc1
@ -1,9 +1,10 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useEffect, useState } from 'react'
|
||||||
import Button from '../../../atoms/Button'
|
import Button from '../../../atoms/Button'
|
||||||
import { FieldInputProps, useField } from 'formik'
|
import { FieldInputProps, useField } from 'formik'
|
||||||
import Loader from '../../../atoms/Loader'
|
import Loader from '../../../atoms/Loader'
|
||||||
import styles from './Input.module.css'
|
import styles from './Input.module.css'
|
||||||
import InputGroup from '../../../atoms/Input/InputGroup'
|
import InputGroup from '../../../atoms/Input/InputGroup'
|
||||||
|
import isUrl from 'is-url-superb'
|
||||||
|
|
||||||
export default function URLInput({
|
export default function URLInput({
|
||||||
submitText,
|
submitText,
|
||||||
@ -17,6 +18,20 @@ export default function URLInput({
|
|||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const [field, meta] = useField(props as FieldInputProps<any>)
|
const [field, meta] = useField(props as FieldInputProps<any>)
|
||||||
|
|
||||||
|
const [isButtonDisabled, setIsButtonDisabled] = useState(true)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!field?.value) return
|
||||||
|
|
||||||
|
setIsButtonDisabled(
|
||||||
|
!field?.value ||
|
||||||
|
field.value === '' ||
|
||||||
|
!isUrl(field.value) ||
|
||||||
|
field.value.includes('javascript:') ||
|
||||||
|
meta?.error
|
||||||
|
)
|
||||||
|
}, [field?.value, meta?.error])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputGroup>
|
<InputGroup>
|
||||||
<input
|
<input
|
||||||
@ -30,7 +45,7 @@ export default function URLInput({
|
|||||||
style="primary"
|
style="primary"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={(e: React.SyntheticEvent) => e.preventDefault()}
|
onClick={(e: React.SyntheticEvent) => e.preventDefault()}
|
||||||
disabled={!field.value}
|
disabled={isButtonDisabled}
|
||||||
>
|
>
|
||||||
{isLoading ? <Loader /> : submitText}
|
{isLoading ? <Loader /> : submitText}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -9,7 +9,7 @@ import {
|
|||||||
import { toStringNoMS } from '.'
|
import { toStringNoMS } from '.'
|
||||||
import AssetModel from '../models/Asset'
|
import AssetModel from '../models/Asset'
|
||||||
import slugify from '@sindresorhus/slugify'
|
import slugify from '@sindresorhus/slugify'
|
||||||
import { DDO, MetadataAlgorithm, Logger } from '@oceanprotocol/lib'
|
import { DDO, File, MetadataAlgorithm, Logger } from '@oceanprotocol/lib'
|
||||||
|
|
||||||
export function transformTags(value: string): string[] {
|
export function transformTags(value: string): string[] {
|
||||||
const originalTags = value?.split(',')
|
const originalTags = value?.split(',')
|
||||||
@ -113,6 +113,18 @@ export function transformPublishFormToMetadata(
|
|||||||
): MetadataMarket {
|
): MetadataMarket {
|
||||||
const currentTime = toStringNoMS(new Date())
|
const currentTime = toStringNoMS(new Date())
|
||||||
|
|
||||||
|
const filesTransformed = typeof files !== 'string' &&
|
||||||
|
files?.length && [
|
||||||
|
{
|
||||||
|
...(files as File[])[0],
|
||||||
|
url: (files as File[])[0].url.replace('javascript:', '')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
const linksTransformed = typeof links !== 'string' &&
|
||||||
|
links?.length && [
|
||||||
|
{ ...links[0], url: links[0].url.replace('javascript:', '') }
|
||||||
|
]
|
||||||
|
|
||||||
const metadata: MetadataMarket = {
|
const metadata: MetadataMarket = {
|
||||||
main: {
|
main: {
|
||||||
...AssetModel.main,
|
...AssetModel.main,
|
||||||
@ -120,14 +132,14 @@ export function transformPublishFormToMetadata(
|
|||||||
author,
|
author,
|
||||||
dateCreated: ddo ? ddo.created : currentTime,
|
dateCreated: ddo ? ddo.created : currentTime,
|
||||||
datePublished: '',
|
datePublished: '',
|
||||||
files: typeof files !== 'string' && files,
|
files: filesTransformed,
|
||||||
license: 'https://market.oceanprotocol.com/terms'
|
license: 'https://market.oceanprotocol.com/terms'
|
||||||
},
|
},
|
||||||
additionalInformation: {
|
additionalInformation: {
|
||||||
...AssetModel.additionalInformation,
|
...AssetModel.additionalInformation,
|
||||||
description,
|
description,
|
||||||
tags: transformTags(tags),
|
tags: transformTags(tags),
|
||||||
links: typeof links !== 'string' ? links : [],
|
links: linksTransformed,
|
||||||
termsAndConditions
|
termsAndConditions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -212,7 +224,8 @@ export function transformPublishAlgorithmFormToMetadata(
|
|||||||
ddo?: DDO
|
ddo?: DDO
|
||||||
): MetadataMarket {
|
): MetadataMarket {
|
||||||
const currentTime = toStringNoMS(new Date())
|
const currentTime = toStringNoMS(new Date())
|
||||||
const fileUrl = typeof files !== 'string' && files[0].url
|
const fileUrl =
|
||||||
|
typeof files !== 'string' && files[0].url.replace('javascript:', '')
|
||||||
const algorithmLanguage = getAlgorithmFileExtension(fileUrl)
|
const algorithmLanguage = getAlgorithmFileExtension(fileUrl)
|
||||||
const algorithm = getAlgorithmComponent(
|
const algorithm = getAlgorithmComponent(
|
||||||
image,
|
image,
|
||||||
@ -220,6 +233,14 @@ export function transformPublishAlgorithmFormToMetadata(
|
|||||||
entrypoint,
|
entrypoint,
|
||||||
algorithmLanguage
|
algorithmLanguage
|
||||||
)
|
)
|
||||||
|
const filesTransformed = typeof files !== 'string' &&
|
||||||
|
files?.length && [
|
||||||
|
{
|
||||||
|
...(files as File[])[0],
|
||||||
|
url: (files as File[])[0].url.replace('javascript:', '')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
const metadata: MetadataMarket = {
|
const metadata: MetadataMarket = {
|
||||||
main: {
|
main: {
|
||||||
...AssetModel.main,
|
...AssetModel.main,
|
||||||
@ -227,7 +248,7 @@ export function transformPublishAlgorithmFormToMetadata(
|
|||||||
type: 'algorithm',
|
type: 'algorithm',
|
||||||
author,
|
author,
|
||||||
dateCreated: ddo ? ddo.created : currentTime,
|
dateCreated: ddo ? ddo.created : currentTime,
|
||||||
files: typeof files !== 'string' && files,
|
files: filesTransformed,
|
||||||
license: 'https://market.oceanprotocol.com/terms',
|
license: 'https://market.oceanprotocol.com/terms',
|
||||||
algorithm
|
algorithm
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user