Feat: move zeroConfLimit to wallet_CRYPTOCODE namespace

This commit is contained in:
csrapr 2021-04-07 18:50:19 +01:00 committed by Josh Harvey
parent 4681de4033
commit 5da28bc830
10 changed files with 178 additions and 119 deletions

View file

@ -2,11 +2,13 @@ import { makeStyles } from '@material-ui/core'
import classnames from 'classnames'
import * as R from 'ramda'
import React, { useReducer, useEffect } from 'react'
import * as Yup from 'yup'
import ErrorMessage from 'src/components/ErrorMessage'
import Stepper from 'src/components/Stepper'
import { Button } from 'src/components/buttons'
import { RadioGroup, Autocomplete } from 'src/components/inputs'
import { NumberInput } from 'src/components/inputs/formik'
import { H4, Info2 } from 'src/components/typography'
import FormRenderer from 'src/pages/Services/FormRenderer'
import schema from 'src/pages/Services/schemas'
@ -59,7 +61,8 @@ const WizardStep = ({
onContinue,
filled,
unfilled,
getValue
getValue,
locale
}) => {
const classes = useStyles()
const [{ innerError, selected, form, isNew }, dispatch] = useReducer(
@ -68,6 +71,9 @@ const WizardStep = ({
)
useEffect(() => {
if (step === 5) {
return dispatch({ type: 'form', form: { code: 'zeroConfLimit' } })
}
dispatch({ type: 'reset' })
}, [step])
@ -78,64 +84,99 @@ const WizardStep = ({
onContinue(config, account)
}
const zeroConfLimitSchema = Yup.object().shape({
zeroConfLimit: Yup.number()
.integer()
.required()
.min(0)
.max(999999999)
})
const label = lastStep ? 'Finish' : 'Next'
const displayName = name ?? type
const subtitleClass = {
[classes.subtitle]: true,
[classes.error]: innerError
}
return (
<>
<Info2 className={classes.title}>{startCase(type)}</Info2>
<Stepper steps={4} currentStep={step} />
<H4 className={classnames(subtitleClass)}>
Select a {displayName} or set up a new one
</H4>
<RadioGroup
options={filled}
value={selected}
className={classes.radioGroup}
onChange={(evt, it) => {
dispatch({ type: 'select', selected: it })
}}
labelClassName={classes.radioLabel}
radioClassName={classes.radio}
/>
<div className={classes.setupNew}>
{!R.isEmpty(unfilled) && !R.isNil(unfilled) && (
<Stepper steps={5} currentStep={step} />
{step <= 4 && (
<>
<H4 className={classnames(subtitleClass)}>
Select a {displayName} or set up a new one
</H4>
<RadioGroup
value={isNew}
options={filled}
value={selected}
className={classes.radioGroup}
onChange={(evt, it) => {
dispatch({ type: 'new' })
dispatch({ type: 'select', selected: it })
}}
labelClassName={classes.radioLabel}
radioClassName={classes.radio}
options={[{ display: 'Set up new', code: true }]}
/>
)}
{isNew && (
<Autocomplete
fullWidth
label={`Select ${displayName}`}
className={classes.picker}
getOptionSelected={R.eqProps('code')}
labelProp={'display'}
options={unfilled}
onChange={(evt, it) => {
dispatch({ type: 'form', form: it })
}}
<div className={classes.setupNew}>
{!R.isEmpty(unfilled) && !R.isNil(unfilled) && (
<RadioGroup
value={isNew}
onChange={(evt, it) => {
dispatch({ type: 'new' })
}}
labelClassName={classes.radioLabel}
radioClassName={classes.radio}
options={[{ display: 'Set up new', code: true }]}
/>
)}
{isNew && (
<Autocomplete
fullWidth
label={`Select ${displayName}`}
className={classes.picker}
getOptionSelected={R.eqProps('code')}
labelProp={'display'}
options={unfilled}
onChange={(evt, it) => {
dispatch({ type: 'form', form: it })
}}
/>
)}
</div>
{form && (
<FormRenderer
save={it =>
innerContinue({ [type]: form.code }, { [form.code]: it })
}
elements={schema[form.code].elements}
validationSchema={schema[form.code].validationSchema}
value={getValue(form.code)}
buttonLabel={label}
/>
)}
</>
)}
{step === 5 && (
<>
<H4 className={classnames(subtitleClass)}>Edit 0-conf Limit</H4>
<FormRenderer
save={it =>
innerContinue(
{ [type]: Number(it.zeroConfLimit) },
{ [form.code]: it }
)
}
elements={[
{
code: 'zeroConfLimit',
display: `Choose a ${locale.fiatCurrency} limit`,
component: NumberInput
}
]}
validationSchema={zeroConfLimitSchema}
buttonLabel={label}
value={0}
/>
)}
</div>
{form && (
<FormRenderer
save={it => innerContinue({ [type]: form.code }, { [form.code]: it })}
elements={schema[form.code].elements}
validationSchema={schema[form.code].validationSchema}
value={getValue(form.code)}
buttonLabel={label}
/>
</>
)}
{!form && (
<div className={classes.submit}>