fix: don't show 0conf steps for coins that don't have them

This commit is contained in:
André Sá 2022-02-16 16:42:52 +00:00
parent 3c33695b9d
commit eac1e9bce2
2 changed files with 43 additions and 35 deletions

View file

@ -10,7 +10,7 @@ import { toNamespace } from 'src/utils/config'
import WizardSplash from './WizardSplash' import WizardSplash from './WizardSplash'
import WizardStep from './WizardStep' import WizardStep from './WizardStep'
const LAST_STEP = 5 const MAX_STEPS = 5
const MODAL_WIDTH = 554 const MODAL_WIDTH = 554
const contains = crypto => R.compose(R.contains(crypto), R.prop('cryptos')) const contains = crypto => R.compose(R.contains(crypto), R.prop('cryptos'))
@ -51,7 +51,6 @@ const Wizard = ({
}) })
const title = `Enable ${coin.display}` const title = `Enable ${coin.display}`
const isLastStep = step === LAST_STEP
const tickers = { filled: filterConfig(coin.code, 'ticker')(accountsConfig) } const tickers = { filled: filterConfig(coin.code, 'ticker')(accountsConfig) }
const wallets = getItems(accountsConfig, accounts, 'wallet', coin.code) const wallets = getItems(accountsConfig, accounts, 'wallet', coin.code)
@ -60,6 +59,34 @@ const Wizard = ({
const getValue = code => R.find(R.propEq('code', code))(accounts) const getValue = code => R.find(R.propEq('code', code))(accounts)
const commonWizardSteps = [
{ type: 'ticker', ...tickers },
{ type: 'wallet', ...wallets },
{ type: 'exchange', ...exchanges }
]
const hasZeroConfs =
!R.isEmpty(zeroConfs.filled) ||
(!R.isNil(zeroConfs.unfilled) && !R.isEmpty(zeroConfs.unfilled))
const wizardSteps = hasZeroConfs
? R.concat(commonWizardSteps, [
{
type: 'zeroConf',
name: 'confidence checking',
schema: Yup.object().shape({
zeroConfLimit: Yup.number().required()
}),
...zeroConfs
},
{ type: 'zeroConfLimit', name: '0-conf limit', ...zeroConfs }
])
: commonWizardSteps
const lastStep = wizardSteps.length
const isLastStep = step === lastStep
const stepData = step > 0 ? wizardSteps[step - 1] : null
const onContinue = async (stepConfig, stepAccount) => { const onContinue = async (stepConfig, stepAccount) => {
const newConfig = R.merge(config, stepConfig) const newConfig = R.merge(config, stepConfig)
const newAccounts = stepAccount const newAccounts = stepAccount
@ -84,30 +111,6 @@ const Wizard = ({
}) })
} }
const getStepData = () => {
switch (step) {
case 1:
return { type: 'ticker', ...tickers }
case 2:
return { type: 'wallet', ...wallets }
case 3:
return { type: 'exchange', ...exchanges }
case 4:
return {
type: 'zeroConf',
name: 'confidence checking',
schema: Yup.object().shape({
zeroConfLimit: Yup.number().required()
}),
...zeroConfs
}
case 5:
return { type: 'zeroConfLimit', name: '0-conf limit', ...zeroConfs }
default:
return null
}
}
return ( return (
<Modal <Modal
title={step === 0 ? null : title} title={step === 0 ? null : title}
@ -123,12 +126,14 @@ const Wizard = ({
)} )}
{step !== 0 && ( {step !== 0 && (
<WizardStep <WizardStep
step={step}
coin={coin.display} coin={coin.display}
fiatCurrency={fiatCurrency} fiatCurrency={fiatCurrency}
error={error} error={error}
lastStep={isLastStep} step={step}
{...getStepData()} maxSteps={MAX_STEPS}
lastStep={lastStep}
isLastStep={isLastStep}
{...stepData}
onContinue={onContinue} onContinue={onContinue}
getValue={getValue} getValue={getValue}
/> />

View file

@ -57,9 +57,11 @@ const WizardStep = ({
schema: stepSchema, schema: stepSchema,
coin, coin,
name, name,
step,
error, error,
step,
maxSteps,
lastStep, lastStep,
isLastStep,
onContinue, onContinue,
fiatCurrency, fiatCurrency,
filled, filled,
@ -83,7 +85,7 @@ const WizardStep = ({
onContinue(config, account) onContinue(config, account)
} }
const label = lastStep ? 'Finish' : 'Next' const label = isLastStep ? 'Finish' : 'Next'
const displayName = name ?? type const displayName = name ?? type
const subtitleClass = { const subtitleClass = {
[classes.subtitle]: true, [classes.subtitle]: true,
@ -92,13 +94,13 @@ const WizardStep = ({
return ( return (
<> <>
<Info2 className={classes.title}>{startCase(displayName)}</Info2> <Info2 className={classes.title}>{startCase(displayName)}</Info2>
<Stepper steps={5} currentStep={step} /> <Stepper steps={lastStep} currentStep={step} />
<H4 className={classnames(subtitleClass)}> <H4 className={classnames(subtitleClass)}>
{step < 4 {step < maxSteps - 1
? `Select a ${displayName} or set up a new one` ? `Select a ${displayName} or set up a new one`
: `Select ${displayName} for ${coin}`} : `Select ${displayName} for ${coin}`}
</H4> </H4>
{step !== 5 && ( {!(isLastStep && step === maxSteps) && (
<RadioGroup <RadioGroup
options={filled} options={filled}
value={selected} value={selected}
@ -110,7 +112,8 @@ const WizardStep = ({
radioClassName={classes.radio} radioClassName={classes.radio}
/> />
)} )}
{step === 5 && ( {/* Hack to support optional 0conf setup */
isLastStep && step === maxSteps && (
<Formik <Formik
validateOnBlur={false} validateOnBlur={false}
validateOnChange={true} validateOnChange={true}