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,
"required": true
},
{
"name": "price",
"label": "New Price",
"type": "number",
"min": "1",
"placeholder": "0",
"help": "Enter a new price.",
"required": true
},
{
"name": "links",
"label": "Sample file",

2
package-lock.json generated
View File

@ -18101,7 +18101,7 @@
}
},
"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",
"requires": {
"bn.js": "^4.11.8",

View File

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

View File

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

View File

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

View File

@ -14,7 +14,7 @@ export default function FilesInput(props: InputProps): ReactElement {
const [fileUrl, setFileUrl] = useState<string>()
const { config } = useOcean()
useEffect(() => {
function loadFileInfo() {
const source = axios.CancelToken.source()
async function validateUrl() {
@ -33,11 +33,16 @@ export default function FilesInput(props: InputProps): ReactElement {
setIsLoading(false)
}
}
fileUrl && validateUrl()
return () => {
source.cancel()
}
}
useEffect(() => {
loadFileInfo()
}, [fileUrl, config.providerUri])
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'
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)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -67,8 +67,11 @@ export default function FormPublish(): ReactElement {
e: ChangeEvent<HTMLInputElement>,
field: FormFieldProps
) {
const value =
field.type === 'terms' ? !JSON.parse(e.target.value) : e.target.value
validateField(field.name)
setFieldValue(field.name, e.target.value)
setFieldValue(field.name, value)
}
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 { EditableMetadataLinks } from '@oceanprotocol/lib'
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`)
.required('Required'),
description: Yup.string().required('Required').min(10),
price: Yup.number().required('Required'),
links: Yup.array<EditableMetadataLinks[]>().nullable(),
timeout: Yup.string().required('Required')
})
export function getInitialValues(
metadata: MetadataMarket,
timeout: number
): Partial<MetadataPublishFormDataset> {
timeout: number,
price: number
): Partial<MetadataEditForm> {
return {
name: metadata.main.name,
description: metadata.additionalInformation.description,
price: price,
links: metadata.additionalInformation.links,
timeout: secondsToString(timeout)
}

View File

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