1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 09:44:53 +01:00

make liquidityProviderFee editable

This commit is contained in:
Matthias Kretschmann 2020-09-16 11:57:02 +02:00
parent 733a2606c3
commit 865c4d7b9d
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 29 additions and 3 deletions

View File

@ -30,6 +30,7 @@ export interface InputProps {
multiple?: boolean multiple?: boolean
pattern?: string pattern?: string
min?: string min?: string
max?: string
disabled?: boolean disabled?: boolean
readOnly?: boolean readOnly?: boolean
field?: any field?: any

View File

@ -17,6 +17,7 @@ export default function Dynamic({
priceOptions, priceOptions,
datatokenOptions, datatokenOptions,
onOceanChange, onOceanChange,
onLiquidityProviderFeeChange,
generateName, generateName,
content content
}: { }: {
@ -24,6 +25,7 @@ export default function Dynamic({
priceOptions: PriceOptions priceOptions: PriceOptions
datatokenOptions: DataTokenOptions datatokenOptions: DataTokenOptions
onOceanChange: (event: ChangeEvent<HTMLInputElement>) => void onOceanChange: (event: ChangeEvent<HTMLInputElement>) => void
onLiquidityProviderFeeChange: (event: ChangeEvent<HTMLInputElement>) => void
generateName: () => void generateName: () => void
content: any content: any
}): ReactElement { }): ReactElement {
@ -104,10 +106,14 @@ export default function Dynamic({
<Tooltip content={content.tooltips.liquidityProviderFee} /> <Tooltip content={content.tooltips.liquidityProviderFee} />
</Label> </Label>
<InputElement <InputElement
type="number"
value={liquidityProviderFee} value={liquidityProviderFee}
name="liquidityProviderFee" name="liquidityProviderFee"
readOnly
postfix="%" postfix="%"
onChange={onLiquidityProviderFeeChange}
min="0.1"
max="0.9"
step="0.1"
/> />
</footer> </footer>

View File

@ -48,12 +48,22 @@ export default function Price(props: InputProps): ReactElement {
const [amountOcean, setAmountOcean] = useState('1') const [amountOcean, setAmountOcean] = useState('1')
const [tokensToMint, setTokensToMint] = useState<number>() const [tokensToMint, setTokensToMint] = useState<number>()
const [datatokenOptions, setDatatokenOptions] = useState<DataTokenOptions>() const [datatokenOptions, setDatatokenOptions] = useState<DataTokenOptions>()
const [liquidityProviderFee, setLiquidityProviderFee] = useState<string>(
priceOptions.liquidityProviderFee
)
function handleOceanChange(event: ChangeEvent<HTMLInputElement>) { function handleOceanChange(event: ChangeEvent<HTMLInputElement>) {
setAmountOcean(event.target.value) setAmountOcean(event.target.value)
helpers.setValue({ ...field.value, price: event.target.value }) helpers.setValue({ ...field.value, price: event.target.value })
} }
// TODO: trigger Yup inline validation
function handleLiquidityProviderFeeChange(
event: ChangeEvent<HTMLInputElement>
) {
setLiquidityProviderFee(event.target.value)
}
function handleTabChange(tabName: string) { function handleTabChange(tabName: string) {
const type = tabName.toLowerCase() const type = tabName.toLowerCase()
helpers.setValue({ ...field.value, type }) helpers.setValue({ ...field.value, type })
@ -73,6 +83,10 @@ export default function Price(props: InputProps): ReactElement {
helpers.setValue({ ...field.value, tokensToMint }) helpers.setValue({ ...field.value, tokensToMint })
}, [amountOcean]) }, [amountOcean])
useEffect(() => {
helpers.setValue({ ...field.value, liquidityProviderFee })
}, [liquidityProviderFee])
// Generate new DT name & symbol // Generate new DT name & symbol
useEffect(() => { useEffect(() => {
generateName() generateName()
@ -96,9 +110,10 @@ export default function Price(props: InputProps): ReactElement {
content: ( content: (
<Dynamic <Dynamic
ocean={amountOcean} ocean={amountOcean}
priceOptions={{ ...priceOptions, tokensToMint }} priceOptions={{ ...priceOptions, tokensToMint, liquidityProviderFee }}
datatokenOptions={datatokenOptions} datatokenOptions={datatokenOptions}
onOceanChange={handleOceanChange} onOceanChange={handleOceanChange}
onLiquidityProviderFeeChange={handleLiquidityProviderFeeChange}
generateName={generateName} generateName={generateName}
content={content.dynamic} content={content.dynamic}
/> />
@ -111,7 +126,7 @@ export default function Price(props: InputProps): ReactElement {
<Tabs items={tabs} handleTabChange={handleTabChange} /> <Tabs items={tabs} handleTabChange={handleTabChange} />
{debug === true && ( {debug === true && (
<pre> <pre>
<code>{JSON.stringify(field.value)}</code> <code>{JSON.stringify(field.value, null, 2)}</code>
</pre> </pre>
)} )}
</div> </div>

View File

@ -13,6 +13,10 @@ export const validationSchema = Yup.object().shape<MetadataPublishForm>({
.required('Required'), .required('Required'),
weightOnDataToken: Yup.string().required('Required'), weightOnDataToken: Yup.string().required('Required'),
liquidityProviderFee: Yup.string() liquidityProviderFee: Yup.string()
.length(3)
.min(0.1)
.max(0.9)
.required('Required')
}), }),
files: Yup.array<FileMetadata>().required('Required').nullable(), files: Yup.array<FileMetadata>().required('Required').nullable(),
description: Yup.string().required('Required'), description: Yup.string().required('Required'),