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

Merge branch 'main' into feature/compute

This commit is contained in:
Matthias Kretschmann 2021-04-22 13:03:08 +02:00
commit 14e4cc3f68
Signed by: m
GPG Key ID: 606EEEF3C479A91F
14 changed files with 92 additions and 26 deletions

View File

@ -20,6 +20,15 @@
"rows": 10, "rows": 10,
"required": true "required": true
}, },
{
"name": "price",
"label": "New Price",
"type": "number",
"min": "1",
"placeholder": "0",
"help": "Enter a new price.",
"required": true
},
{ {
"name": "links", "name": "links",
"label": "Sample file", "label": "Sample file",

2
package-lock.json generated
View File

@ -18101,7 +18101,7 @@
} }
}, },
"ethereumjs-abi": { "ethereumjs-abi": {
"version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1a27c59c15ab1e95ee8e5c4ed6ad814c49cc439e", "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1ce6a1d64235fabe2aaf827fd606def55693508f",
"from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git",
"requires": { "requires": {
"bn.js": "^4.11.8", "bn.js": "^4.11.8",

View File

@ -61,6 +61,7 @@ export interface MetadataEditForm {
name: string name: string
description: string description: string
timeout: string timeout: string
price?: number
links?: string | EditableMetadataLinks[] links?: string | EditableMetadataLinks[]
} }

View File

@ -91,6 +91,7 @@ export default function InputElement({
id={slugify(option)} id={slugify(option)}
type={type} type={type}
name={name} name={name}
checked={props.defaultChecked}
{...props} {...props}
/> />
<label className={styles.radioLabel} htmlFor={slugify(option)}> <label className={styles.radioLabel} htmlFor={slugify(option)}>

View File

@ -27,7 +27,7 @@ export default function FileInput({
<Button <Button
style="primary" style="primary"
size="small" size="small"
onClick={(e: React.SyntheticEvent) => handleButtonClick(e, field.value)} onClick={(e: React.SyntheticEvent) => e.preventDefault()}
disabled={!field.value} disabled={!field.value}
> >
{isLoading ? <Loader /> : 'Add File'} {isLoading ? <Loader /> : 'Add File'}

View File

@ -14,7 +14,7 @@ export default function FilesInput(props: InputProps): ReactElement {
const [fileUrl, setFileUrl] = useState<string>() const [fileUrl, setFileUrl] = useState<string>()
const { config } = useOcean() const { config } = useOcean()
useEffect(() => { function loadFileInfo() {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
async function validateUrl() { async function validateUrl() {
@ -33,11 +33,16 @@ export default function FilesInput(props: InputProps): ReactElement {
setIsLoading(false) setIsLoading(false)
} }
} }
fileUrl && validateUrl() fileUrl && validateUrl()
return () => { return () => {
source.cancel() source.cancel()
} }
}
useEffect(() => {
loadFileInfo()
}, [fileUrl, config.providerUri]) }, [fileUrl, config.providerUri])
async function handleButtonClick(e: React.SyntheticEvent, url: string) { async function handleButtonClick(e: React.SyntheticEvent, url: string) {
@ -48,6 +53,11 @@ export default function FilesInput(props: InputProps): ReactElement {
// File example 'https://oceanprotocol.com/tech-whitepaper.pdf' // File example 'https://oceanprotocol.com/tech-whitepaper.pdf'
e.preventDefault() e.preventDefault()
// In the case when the user re-add the same URL after it was removed (by accident or intentionally)
if (fileUrl === url) {
loadFileInfo()
}
setFileUrl(url) setFileUrl(url)
} }

View File

@ -14,6 +14,10 @@ const query = graphql`
export default function Terms(props: InputProps): ReactElement { export default function Terms(props: InputProps): ReactElement {
const data = useStaticQuery(query) const data = useStaticQuery(query)
const termsProps: InputProps = {
...props,
defaultChecked: props.value.toString() === 'true'
}
return ( return (
<> <>
@ -21,7 +25,7 @@ export default function Terms(props: InputProps): ReactElement {
className={styles.terms} className={styles.terms}
dangerouslySetInnerHTML={{ __html: data.terms.html }} dangerouslySetInnerHTML={{ __html: data.terms.html }}
/> />
<InputElement {...props} type="checkbox" /> <InputElement {...termsProps} type="checkbox" />
</> </>
) )
} }

View File

@ -47,15 +47,17 @@ export default function FormEditMetadata({
data, data,
setShowEdit, setShowEdit,
setTimeoutStringValue, setTimeoutStringValue,
values values,
showPrice
}: { }: {
data: FormFieldProps[] data: FormFieldProps[]
setShowEdit: (show: boolean) => void setShowEdit: (show: boolean) => void
setTimeoutStringValue: (value: string) => void setTimeoutStringValue: (value: string) => void
values: Partial<MetadataPublishFormDataset> values: Partial<MetadataPublishFormDataset>
showPrice: boolean
}): ReactElement { }): ReactElement {
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { ocean } = useOcean() const { ocean, config } = useOcean()
const { const {
isValid, isValid,
validateField, validateField,
@ -79,16 +81,20 @@ export default function FormEditMetadata({
return ( return (
<Form className={styles.form}> <Form className={styles.form}>
{data.map((field: FormFieldProps) => ( {data.map(
(field: FormFieldProps) =>
(!showPrice && field.name === 'price') || (
<Field <Field
key={field.name} key={field.name}
{...field} {...field}
component={Input} component={Input}
prefix={field.name === 'price' && config.oceanTokenSymbol}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
handleFieldChange(e, field) handleFieldChange(e, field)
} }
/> />
))} )
)}
<footer className={styles.actions}> <footer className={styles.actions}>
<Button <Button

View File

@ -36,6 +36,7 @@ const contentQuery = graphql`
label label
help help
type type
min
required required
sortOptions sortOptions
options options
@ -60,7 +61,7 @@ export default function Edit({
const { debug } = useUserPreferences() const { debug } = useUserPreferences()
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { ocean } = useOcean() const { ocean } = useOcean()
const { metadata, ddo, refreshDdo } = useAsset() const { metadata, ddo, refreshDdo, price } = useAsset()
const [success, setSuccess] = useState<string>() const [success, setSuccess] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [timeoutStringValue, setTimeoutStringValue] = useState<string>() const [timeoutStringValue, setTimeoutStringValue] = useState<string>()
@ -70,6 +71,18 @@ export default function Edit({
const hasFeedback = error || success const hasFeedback = error || success
async function updateFixedPrice(newPrice: number) {
const setPriceResp = await ocean.fixedRateExchange.setRate(
price.address,
newPrice,
accountId
)
if (!setPriceResp) {
setError(content.form.error)
Logger.error(content.form.error)
}
}
async function handleSubmit( async function handleSubmit(
values: Partial<MetadataEditForm>, values: Partial<MetadataEditForm>,
resetForm: () => void resetForm: () => void
@ -82,6 +95,10 @@ export default function Edit({
links: typeof values.links !== 'string' ? values.links : [] links: typeof values.links !== 'string' ? values.links : []
}) })
price.type === 'exchange' &&
values.price !== price.value &&
(await updateFixedPrice(values.price))
if (!ddoEditedMetdata) { if (!ddoEditedMetdata) {
setError(content.form.error) setError(content.form.error)
Logger.error(content.form.error) Logger.error(content.form.error)
@ -127,7 +144,11 @@ export default function Edit({
return ( return (
<Formik <Formik
initialValues={getInitialValues(metadata, timeout)} initialValues={getInitialValues(
metadata,
ddo.findServiceByType('access').attributes.main.timeout,
price.value
)}
validationSchema={validationSchema} validationSchema={validationSchema}
onSubmit={async (values, { resetForm }) => { onSubmit={async (values, { resetForm }) => {
// move user's focus to top of screen // move user's focus to top of screen
@ -160,6 +181,7 @@ export default function Edit({
setShowEdit={setShowEdit} setShowEdit={setShowEdit}
setTimeoutStringValue={setTimeoutStringValue} setTimeoutStringValue={setTimeoutStringValue}
values={initialValues} values={initialValues}
showPrice={price.type === 'exchange'}
/> />
<aside> <aside>

View File

@ -174,7 +174,7 @@ export default function Add({
) : ( ) : (
<Alert <Alert
className={styles.warning} className={styles.warning}
text={content.warning.main} text={content.warning}
state="info" state="info"
action={{ action={{
name: 'I understand', name: 'I understand',

View File

@ -44,6 +44,7 @@ const poolLiquidityQuery = gql`
id id
totalShares totalShares
swapFee swapFee
spotPrice
tokens { tokens {
tokenAddress tokenAddress
balance balance
@ -141,7 +142,8 @@ export default function Pool(): ReactElement {
setCreatorLiquidity(creatorLiquidity) setCreatorLiquidity(creatorLiquidity)
const totalCreatorLiquidityInOcean = const totalCreatorLiquidityInOcean =
creatorLiquidity?.ocean + creatorLiquidity?.datatoken * price?.value creatorLiquidity?.ocean +
creatorLiquidity?.datatoken * dataLiquidity.pool.spotPrice
setCreatorTotalLiquidityInOcean(totalCreatorLiquidityInOcean) setCreatorTotalLiquidityInOcean(totalCreatorLiquidityInOcean)
const creatorPoolShare = const creatorPoolShare =
price?.ocean && price?.ocean &&

View File

@ -67,8 +67,11 @@ export default function FormPublish(): ReactElement {
e: ChangeEvent<HTMLInputElement>, e: ChangeEvent<HTMLInputElement>,
field: FormFieldProps field: FormFieldProps
) { ) {
const value =
field.type === 'terms' ? !JSON.parse(e.target.value) : e.target.value
validateField(field.name) validateField(field.name)
setFieldValue(field.name, e.target.value) setFieldValue(field.name, value)
} }
const resetFormAndClearStorage = (e: FormEvent<Element>) => { const resetFormAndClearStorage = (e: FormEvent<Element>) => {

View File

@ -1,4 +1,4 @@
import { MetadataMarket, MetadataPublishFormDataset } from '../@types/MetaData' import { MetadataMarket, MetadataEditForm } from '../@types/MetaData'
import { secondsToString } from '../utils/metadata' import { secondsToString } from '../utils/metadata'
import { EditableMetadataLinks } from '@oceanprotocol/lib' import { EditableMetadataLinks } from '@oceanprotocol/lib'
import * as Yup from 'yup' import * as Yup from 'yup'
@ -8,17 +8,20 @@ export const validationSchema = Yup.object().shape({
.min(4, (param) => `Title must be at least ${param.min} characters`) .min(4, (param) => `Title must be at least ${param.min} characters`)
.required('Required'), .required('Required'),
description: Yup.string().required('Required').min(10), description: Yup.string().required('Required').min(10),
price: Yup.number().required('Required'),
links: Yup.array<EditableMetadataLinks[]>().nullable(), links: Yup.array<EditableMetadataLinks[]>().nullable(),
timeout: Yup.string().required('Required') timeout: Yup.string().required('Required')
}) })
export function getInitialValues( export function getInitialValues(
metadata: MetadataMarket, metadata: MetadataMarket,
timeout: number timeout: number,
): Partial<MetadataPublishFormDataset> { price: number
): Partial<MetadataEditForm> {
return { return {
name: metadata.main.name, name: metadata.main.name,
description: metadata.additionalInformation.description, description: metadata.additionalInformation.description,
price: price,
links: metadata.additionalInformation.links, links: metadata.additionalInformation.links,
timeout: secondsToString(timeout) timeout: secondsToString(timeout)
} }

View File

@ -37,6 +37,7 @@ const poolQuery = gql`
query PoolPrice($datatoken: String) { query PoolPrice($datatoken: String) {
pools(where: { datatokenAddress: $datatoken }) { pools(where: { datatokenAddress: $datatoken }) {
spotPrice spotPrice
consumePrice
datatokenReserve datatokenReserve
oceanReserve oceanReserve
} }
@ -127,9 +128,13 @@ function AssetProvider({
return return
setPrice((prevState) => ({ setPrice((prevState) => ({
...prevState, ...prevState,
value: poolPrice.pools[0].spotPrice, value:
poolPrice.pools[0].consumePrice === '-1'
? poolPrice.pools[0].spotPrice
: poolPrice.pools[0].consumePrice,
ocean: poolPrice.pools[0].oceanReserve, ocean: poolPrice.pools[0].oceanReserve,
datatoken: poolPrice.pools[0].datatokenReserve datatoken: poolPrice.pools[0].datatokenReserve,
isConsumable: poolPrice.pools[0].consumePrice === '-1' ? 'false' : 'true'
})) }))
}, [poolPrice]) }, [poolPrice])