fix: don't show 0conf steps for coins that don't have them
This commit is contained in:
parent
3c33695b9d
commit
eac1e9bce2
2 changed files with 43 additions and 35 deletions
|
|
@ -10,7 +10,7 @@ import { toNamespace } from 'src/utils/config'
|
|||
import WizardSplash from './WizardSplash'
|
||||
import WizardStep from './WizardStep'
|
||||
|
||||
const LAST_STEP = 5
|
||||
const MAX_STEPS = 5
|
||||
const MODAL_WIDTH = 554
|
||||
|
||||
const contains = crypto => R.compose(R.contains(crypto), R.prop('cryptos'))
|
||||
|
|
@ -51,7 +51,6 @@ const Wizard = ({
|
|||
})
|
||||
|
||||
const title = `Enable ${coin.display}`
|
||||
const isLastStep = step === LAST_STEP
|
||||
|
||||
const tickers = { filled: filterConfig(coin.code, 'ticker')(accountsConfig) }
|
||||
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 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 newConfig = R.merge(config, stepConfig)
|
||||
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 (
|
||||
<Modal
|
||||
title={step === 0 ? null : title}
|
||||
|
|
@ -123,12 +126,14 @@ const Wizard = ({
|
|||
)}
|
||||
{step !== 0 && (
|
||||
<WizardStep
|
||||
step={step}
|
||||
coin={coin.display}
|
||||
fiatCurrency={fiatCurrency}
|
||||
error={error}
|
||||
lastStep={isLastStep}
|
||||
{...getStepData()}
|
||||
step={step}
|
||||
maxSteps={MAX_STEPS}
|
||||
lastStep={lastStep}
|
||||
isLastStep={isLastStep}
|
||||
{...stepData}
|
||||
onContinue={onContinue}
|
||||
getValue={getValue}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -57,9 +57,11 @@ const WizardStep = ({
|
|||
schema: stepSchema,
|
||||
coin,
|
||||
name,
|
||||
step,
|
||||
error,
|
||||
step,
|
||||
maxSteps,
|
||||
lastStep,
|
||||
isLastStep,
|
||||
onContinue,
|
||||
fiatCurrency,
|
||||
filled,
|
||||
|
|
@ -83,7 +85,7 @@ const WizardStep = ({
|
|||
onContinue(config, account)
|
||||
}
|
||||
|
||||
const label = lastStep ? 'Finish' : 'Next'
|
||||
const label = isLastStep ? 'Finish' : 'Next'
|
||||
const displayName = name ?? type
|
||||
const subtitleClass = {
|
||||
[classes.subtitle]: true,
|
||||
|
|
@ -92,13 +94,13 @@ const WizardStep = ({
|
|||
return (
|
||||
<>
|
||||
<Info2 className={classes.title}>{startCase(displayName)}</Info2>
|
||||
<Stepper steps={5} currentStep={step} />
|
||||
<Stepper steps={lastStep} currentStep={step} />
|
||||
<H4 className={classnames(subtitleClass)}>
|
||||
{step < 4
|
||||
{step < maxSteps - 1
|
||||
? `Select a ${displayName} or set up a new one`
|
||||
: `Select ${displayName} for ${coin}`}
|
||||
</H4>
|
||||
{step !== 5 && (
|
||||
{!(isLastStep && step === maxSteps) && (
|
||||
<RadioGroup
|
||||
options={filled}
|
||||
value={selected}
|
||||
|
|
@ -110,7 +112,8 @@ const WizardStep = ({
|
|||
radioClassName={classes.radio}
|
||||
/>
|
||||
)}
|
||||
{step === 5 && (
|
||||
{/* Hack to support optional 0conf setup */
|
||||
isLastStep && step === maxSteps && (
|
||||
<Formik
|
||||
validateOnBlur={false}
|
||||
validateOnChange={true}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue