mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
handle generated dt names
* generate new name & symbol on mount * output in fixed & dynamic * pass through generated options into publish
This commit is contained in:
parent
acfa0b8d06
commit
7bda8b7c13
@ -4,7 +4,7 @@ import stylesIndex from './index.module.css'
|
|||||||
import styles from './Dynamic.module.css'
|
import styles from './Dynamic.module.css'
|
||||||
import FormHelp from '../../../atoms/Input/Help'
|
import FormHelp from '../../../atoms/Input/Help'
|
||||||
import Wallet from '../../Wallet'
|
import Wallet from '../../Wallet'
|
||||||
import { useOcean } from '@oceanprotocol/react'
|
import { DataTokenOptions, PriceOptions, useOcean } from '@oceanprotocol/react'
|
||||||
import Alert from '../../../atoms/Alert'
|
import Alert from '../../../atoms/Alert'
|
||||||
import Coin from './Coin'
|
import Coin from './Coin'
|
||||||
import { isCorrectNetwork } from '../../../../utils/wallet'
|
import { isCorrectNetwork } from '../../../../utils/wallet'
|
||||||
@ -15,21 +15,20 @@ import Tooltip from '../../../atoms/Tooltip'
|
|||||||
|
|
||||||
export default function Dynamic({
|
export default function Dynamic({
|
||||||
ocean,
|
ocean,
|
||||||
tokensToMint,
|
priceOptions,
|
||||||
weightOnDataToken,
|
datatokenOptions,
|
||||||
liquidityProviderFee,
|
|
||||||
onOceanChange,
|
onOceanChange,
|
||||||
content
|
content
|
||||||
}: {
|
}: {
|
||||||
ocean: string
|
ocean: string
|
||||||
tokensToMint: number
|
priceOptions: PriceOptions
|
||||||
weightOnDataToken: string
|
datatokenOptions: DataTokenOptions
|
||||||
liquidityProviderFee: string
|
|
||||||
onOceanChange: (event: ChangeEvent<HTMLInputElement>) => void
|
onOceanChange: (event: ChangeEvent<HTMLInputElement>) => void
|
||||||
content: any
|
content: any
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { appConfig } = useSiteMetadata()
|
const { appConfig } = useSiteMetadata()
|
||||||
const { account, balance, chainId, refreshBalance } = useOcean()
|
const { account, balance, chainId, refreshBalance } = useOcean()
|
||||||
|
const { weightOnDataToken, tokensToMint, liquidityProviderFee } = priceOptions
|
||||||
|
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
const correctNetwork = isCorrectNetwork(chainId)
|
const correctNetwork = isCorrectNetwork(chainId)
|
||||||
@ -91,7 +90,7 @@ export default function Dynamic({
|
|||||||
/>
|
/>
|
||||||
<Coin
|
<Coin
|
||||||
name="tokensToMint"
|
name="tokensToMint"
|
||||||
symbol="OCEAN-CAV"
|
symbol={datatokenOptions.symbol}
|
||||||
value={tokensToMint.toString()}
|
value={tokensToMint.toString()}
|
||||||
weight={`${Number(weightOnDataToken) * 10}%`}
|
weight={`${Number(weightOnDataToken) * 10}%`}
|
||||||
readOnly
|
readOnly
|
||||||
|
@ -5,13 +5,16 @@ import FormHelp from '../../../atoms/Input/Help'
|
|||||||
import Label from '../../../atoms/Input/Label'
|
import Label from '../../../atoms/Input/Label'
|
||||||
import InputElement from '../../../atoms/Input/InputElement'
|
import InputElement from '../../../atoms/Input/InputElement'
|
||||||
import Conversion from '../../../atoms/Price/Conversion'
|
import Conversion from '../../../atoms/Price/Conversion'
|
||||||
|
import { DataTokenOptions } from '@oceanprotocol/react'
|
||||||
|
|
||||||
export default function Fixed({
|
export default function Fixed({
|
||||||
ocean,
|
ocean,
|
||||||
|
datatokenOptions,
|
||||||
onChange,
|
onChange,
|
||||||
content
|
content
|
||||||
}: {
|
}: {
|
||||||
ocean: string
|
ocean: string
|
||||||
|
datatokenOptions: DataTokenOptions
|
||||||
onChange: (event: ChangeEvent<HTMLInputElement>) => void
|
onChange: (event: ChangeEvent<HTMLInputElement>) => void
|
||||||
content: any
|
content: any
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
@ -22,7 +25,6 @@ export default function Fixed({
|
|||||||
|
|
||||||
<div className={styles.form}>
|
<div className={styles.form}>
|
||||||
<Label htmlFor="ocean">Ocean Tokens</Label>
|
<Label htmlFor="ocean">Ocean Tokens</Label>
|
||||||
|
|
||||||
<InputElement
|
<InputElement
|
||||||
value={ocean}
|
value={ocean}
|
||||||
name="ocean"
|
name="ocean"
|
||||||
@ -30,8 +32,8 @@ export default function Fixed({
|
|||||||
prefix="OCEAN"
|
prefix="OCEAN"
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Conversion price={ocean} className={stylesIndex.conversion} />
|
<Conversion price={ocean} className={stylesIndex.conversion} />
|
||||||
|
{datatokenOptions?.symbol} | {datatokenOptions?.name}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,6 +7,7 @@ import Fixed from './Fixed'
|
|||||||
import Dynamic from './Dynamic'
|
import Dynamic from './Dynamic'
|
||||||
import { useField } from 'formik'
|
import { useField } from 'formik'
|
||||||
import { useUserPreferences } from '../../../../providers/UserPreferences'
|
import { useUserPreferences } from '../../../../providers/UserPreferences'
|
||||||
|
import { DataTokenOptions, PriceOptions, useOcean } from '@oceanprotocol/react'
|
||||||
|
|
||||||
const query = graphql`
|
const query = graphql`
|
||||||
query PriceFieldQuery {
|
query PriceFieldQuery {
|
||||||
@ -39,15 +40,17 @@ export default function Price(props: InputProps): ReactElement {
|
|||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const data = useStaticQuery(query)
|
const data = useStaticQuery(query)
|
||||||
const content = data.content.edges[0].node.childPagesJson.price
|
const content = data.content.edges[0].node.childPagesJson.price
|
||||||
|
const { ocean } = useOcean()
|
||||||
|
|
||||||
const [field, meta, helpers] = useField(props)
|
const [field, meta, helpers] = useField(props)
|
||||||
const { weightOnDataToken, liquidityProviderFee } = field.value
|
const priceOptions: PriceOptions = field.value
|
||||||
|
|
||||||
const [ocean, setOcean] = useState('1')
|
const [amountOcean, setAmountOcean] = useState('1')
|
||||||
const [tokensToMint, setTokensToMint] = useState<number>()
|
const [tokensToMint, setTokensToMint] = useState<number>()
|
||||||
|
const [datatokenOptions, setDatatokenOptions] = useState<DataTokenOptions>()
|
||||||
|
|
||||||
function handleOceanChange(event: ChangeEvent<HTMLInputElement>) {
|
function handleOceanChange(event: ChangeEvent<HTMLInputElement>) {
|
||||||
setOcean(event.target.value)
|
setAmountOcean(event.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleTabChange(tabName: string) {
|
function handleTabChange(tabName: string) {
|
||||||
@ -55,11 +58,19 @@ export default function Price(props: InputProps): ReactElement {
|
|||||||
helpers.setValue({ ...field.value, type })
|
helpers.setValue({ ...field.value, type })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always update everything when ocean changes
|
// Always update everything when amountOcean changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const tokensToMint = Number(ocean) * Number(weightOnDataToken)
|
const tokensToMint =
|
||||||
|
Number(amountOcean) * Number(priceOptions.weightOnDataToken)
|
||||||
setTokensToMint(tokensToMint)
|
setTokensToMint(tokensToMint)
|
||||||
helpers.setValue({ ...field.value, tokensToMint })
|
helpers.setValue({ ...field.value, tokensToMint })
|
||||||
|
}, [amountOcean])
|
||||||
|
|
||||||
|
// Generate new DT name & symbol
|
||||||
|
useEffect(() => {
|
||||||
|
if (!ocean) return
|
||||||
|
const newDatatokenOptions = ocean.datatokens.generateDtName()
|
||||||
|
setDatatokenOptions(newDatatokenOptions)
|
||||||
}, [ocean])
|
}, [ocean])
|
||||||
|
|
||||||
const tabs = [
|
const tabs = [
|
||||||
@ -67,7 +78,8 @@ export default function Price(props: InputProps): ReactElement {
|
|||||||
title: content.fixed.title,
|
title: content.fixed.title,
|
||||||
content: (
|
content: (
|
||||||
<Fixed
|
<Fixed
|
||||||
ocean={ocean}
|
ocean={amountOcean}
|
||||||
|
datatokenOptions={datatokenOptions}
|
||||||
onChange={handleOceanChange}
|
onChange={handleOceanChange}
|
||||||
content={content.fixed}
|
content={content.fixed}
|
||||||
/>
|
/>
|
||||||
@ -77,11 +89,10 @@ export default function Price(props: InputProps): ReactElement {
|
|||||||
title: content.dynamic.title,
|
title: content.dynamic.title,
|
||||||
content: (
|
content: (
|
||||||
<Dynamic
|
<Dynamic
|
||||||
ocean={ocean}
|
ocean={amountOcean}
|
||||||
tokensToMint={tokensToMint}
|
priceOptions={{ ...priceOptions, tokensToMint }}
|
||||||
weightOnDataToken={weightOnDataToken}
|
datatokenOptions={datatokenOptions}
|
||||||
onOceanChange={handleOceanChange}
|
onOceanChange={handleOceanChange}
|
||||||
liquidityProviderFee={liquidityProviderFee}
|
|
||||||
content={content.dynamic}
|
content={content.dynamic}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
@ -2,7 +2,12 @@ import React, { ReactElement } from 'react'
|
|||||||
import { useNavigate } from '@reach/router'
|
import { useNavigate } from '@reach/router'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { Formik } from 'formik'
|
import { Formik } from 'formik'
|
||||||
import { usePublish, useOcean, PriceOptions } from '@oceanprotocol/react'
|
import {
|
||||||
|
usePublish,
|
||||||
|
useOcean,
|
||||||
|
PriceOptions,
|
||||||
|
DataTokenOptions
|
||||||
|
} from '@oceanprotocol/react'
|
||||||
import styles from './index.module.css'
|
import styles from './index.module.css'
|
||||||
import PublishForm from './PublishForm'
|
import PublishForm from './PublishForm'
|
||||||
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
import Web3Feedback from '../../molecules/Wallet/Feedback'
|
||||||
@ -19,7 +24,8 @@ export default function PublishPage({
|
|||||||
}: {
|
}: {
|
||||||
content: { form: FormContent }
|
content: { form: FormContent }
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { marketFeeAddress, marketFeeAmount } = useSiteMetadata()
|
// TODO: implement marketFee
|
||||||
|
// const { marketFeeAddress, marketFeeAmount } = useSiteMetadata()
|
||||||
const { debug } = useUserPreferences()
|
const { debug } = useUserPreferences()
|
||||||
const { publish, publishError, isLoading, publishStepText } = usePublish()
|
const { publish, publishError, isLoading, publishStepText } = usePublish()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
@ -31,15 +37,15 @@ export default function PublishPage({
|
|||||||
const metadata = transformPublishFormToMetadata(values)
|
const metadata = transformPublishFormToMetadata(values)
|
||||||
const priceOptions = values.price
|
const priceOptions = values.price
|
||||||
const serviceType = values.access === 'Download' ? 'access' : 'compute'
|
const serviceType = values.access === 'Download' ? 'access' : 'compute'
|
||||||
|
let datatokenOptions: DataTokenOptions
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// mpAddress and mpFee are not yet implemented in ocean js so are not used
|
// mpAddress and mpFee are not yet implemented in ocean js so are not used
|
||||||
const ddo = await publish(
|
const ddo = await publish(
|
||||||
metadata as any,
|
metadata as any,
|
||||||
priceOptions,
|
priceOptions,
|
||||||
serviceType
|
serviceType,
|
||||||
// marketFeeAddress,
|
datatokenOptions
|
||||||
// marketFeeAmount
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (publishError) {
|
if (publishError) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user