From eac1e9bce2d49f2353db12a91794faf21f3dafaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Wed, 16 Feb 2022 16:42:52 +0000 Subject: [PATCH] fix: don't show 0conf steps for coins that don't have them --- new-lamassu-admin/src/pages/Wallet/Wizard.js | 63 ++++++++++--------- .../src/pages/Wallet/WizardStep.js | 15 +++-- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/new-lamassu-admin/src/pages/Wallet/Wizard.js b/new-lamassu-admin/src/pages/Wallet/Wizard.js index 4787f8db..42f11940 100644 --- a/new-lamassu-admin/src/pages/Wallet/Wizard.js +++ b/new-lamassu-admin/src/pages/Wallet/Wizard.js @@ -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 ( diff --git a/new-lamassu-admin/src/pages/Wallet/WizardStep.js b/new-lamassu-admin/src/pages/Wallet/WizardStep.js index d391e4fe..4631046b 100644 --- a/new-lamassu-admin/src/pages/Wallet/WizardStep.js +++ b/new-lamassu-admin/src/pages/Wallet/WizardStep.js @@ -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 ( <> {startCase(displayName)} - +

- {step < 4 + {step < maxSteps - 1 ? `Select a ${displayName} or set up a new one` : `Select ${displayName} for ${coin}`}

- {step !== 5 && ( + {!(isLastStep && step === maxSteps) && ( )} - {step === 5 && ( + {/* Hack to support optional 0conf setup */ + isLastStep && step === maxSteps && (