From 65a55a669dc21cb66d18bb13a54338b57fe1c7f0 Mon Sep 17 00:00:00 2001 From: csrapr <26280794+csrapr@users.noreply.github.com> Date: Fri, 9 Apr 2021 19:44:08 +0100 Subject: [PATCH] Fix: default 0 zeroConfLimit for new coins --- .../1617742522808-zeroConfLimit-migrate.js | 20 ++- .../src/pages/Locales/Locales.js | 1 + new-lamassu-admin/src/pages/Wallet/Wizard.js | 5 +- .../src/pages/Wallet/WizardStep.js | 120 ++++++------------ .../pages/Wizard/components/Wallet/AllSet.js | 2 + .../pages/Wizard/components/Wallet/Wallet.js | 5 - .../Wizard/components/Wallet/ZeroConfLimit.js | 48 ------- 7 files changed, 63 insertions(+), 138 deletions(-) delete mode 100644 new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js diff --git a/migrations/1617742522808-zeroConfLimit-migrate.js b/migrations/1617742522808-zeroConfLimit-migrate.js index 56d42f9b..6e5a4789 100644 --- a/migrations/1617742522808-zeroConfLimit-migrate.js +++ b/migrations/1617742522808-zeroConfLimit-migrate.js @@ -3,13 +3,27 @@ var db = require('../lib/db') const settingsLoader = require('../lib/new-settings-loader') const configManager = require('../lib/new-config-manager') +const stripl = _.curry((q, str) => _.startsWith(q, str) ? str.slice(q.length) : str) +const filter = namespace => _.pickBy((value, key) => _.startsWith(`${namespace}_`)(key)) +const strip = key => _.mapKeys(stripl(`${key}_`)) + +const fromNamespace = _.curry((key, config) => _.compose(strip(key), filter(key))(config)) + +const split = _.curry(_.split) +const composed = _.compose(_.head, split('_')) + +const getCryptoCodes = (config) => { + const walletKeys = _.keys(fromNamespace('wallets', config)) + return _.uniq(_.map(composed, walletKeys)) +} + exports.up = function (next) { db.tx(async t => { let min = Infinity const sp = settingsLoader.loadLatest() const mp = t.any('SELECT device_id FROM devices') const [{ config }, machines] = await Promise.all([sp, mp]) - const cryptoCurrencies = config.locale_cryptoCurrencies + const cryptoCodes = getCryptoCodes(config) _.forEach(o => { const machineId = o.device_id @@ -29,10 +43,10 @@ exports.up = function (next) { if (!zeroConfLimit) { config[key] = Number(min) } - }, cryptoCurrencies) + }, cryptoCodes) const regexp = /^cashOut_[0-9a-z]+_zeroConfLimit$/ - const keysToErase = Object.keys(config).filter(key => key.match(regexp)) + const keysToErase = _.keys(config).filter(key => key.match(regexp)) _.forEach(key => { config[key] = null diff --git a/new-lamassu-admin/src/pages/Locales/Locales.js b/new-lamassu-admin/src/pages/Locales/Locales.js index faf88974..a22a6ded 100644 --- a/new-lamassu-admin/src/pages/Locales/Locales.js +++ b/new-lamassu-admin/src/pages/Locales/Locales.js @@ -149,6 +149,7 @@ const Locales = ({ name: SCREEN_KEY }) => { if (!coin) return setValue(curr) const namespaced = fromNamespace(coin)(wallets) + console.log(namespaced) if (!WalletSchema.isValidSync(namespaced)) { setOnChangeFunction(() => () => setValue(curr)) setWizard(coin) diff --git a/new-lamassu-admin/src/pages/Wallet/Wizard.js b/new-lamassu-admin/src/pages/Wallet/Wizard.js index 4e3e24ac..2af2b618 100644 --- a/new-lamassu-admin/src/pages/Wallet/Wizard.js +++ b/new-lamassu-admin/src/pages/Wallet/Wizard.js @@ -8,7 +8,7 @@ import { toNamespace } from 'src/utils/config' import WizardSplash from './WizardSplash' import WizardStep from './WizardStep' -const LAST_STEP = 5 +const LAST_STEP = 4 const MODAL_WIDTH = 554 const contains = crypto => R.compose(R.contains(crypto), R.prop('cryptos')) @@ -65,6 +65,7 @@ const Wizard = ({ : accountsToSave if (isLastStep) { + newConfig.zeroConfLimit = 0 return save(toNamespace(coin.code, newConfig), newAccounts) } @@ -85,8 +86,6 @@ const Wizard = ({ return { type: 'exchange', ...exchanges } case 4: return { type: 'zeroConf', name: 'zero conf', ...zeroConfs } - case 5: - return { type: 'zeroConfLimit' } default: return null } diff --git a/new-lamassu-admin/src/pages/Wallet/WizardStep.js b/new-lamassu-admin/src/pages/Wallet/WizardStep.js index 475b40b8..1699115a 100644 --- a/new-lamassu-admin/src/pages/Wallet/WizardStep.js +++ b/new-lamassu-admin/src/pages/Wallet/WizardStep.js @@ -2,13 +2,11 @@ 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' @@ -84,13 +82,6 @@ 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 = { @@ -100,83 +91,54 @@ const WizardStep = ({ return ( <> {startCase(type)} - - {step <= 4 && ( - <> -

- Select a {displayName} or set up a new one -

+ +

+ Select a {displayName} or set up a new one +

+ { + dispatch({ type: 'select', selected: it }) + }} + labelClassName={classes.radioLabel} + radioClassName={classes.radio} + /> +
+ {!R.isEmpty(unfilled) && !R.isNil(unfilled) && ( { - dispatch({ type: 'select', selected: it }) + dispatch({ type: 'new' }) }} labelClassName={classes.radioLabel} radioClassName={classes.radio} + options={[{ display: 'Set up new', code: true }]} /> -
- {!R.isEmpty(unfilled) && !R.isNil(unfilled) && ( - { - dispatch({ type: 'new' }) - }} - labelClassName={classes.radioLabel} - radioClassName={classes.radio} - options={[{ display: 'Set up new', code: true }]} - /> - )} - {isNew && ( - { - dispatch({ type: 'form', form: it }) - }} - /> - )} -
- {form && ( - - 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 && ( - <> -

Edit 0-conf Limit

- - innerContinue( - { [type]: Number(it.zeroConfLimit) }, - { [form.code]: it } - ) - } - elements={[ - { - code: 'zeroConfLimit', - display: `Choose a ${locale.fiatCurrency} limit`, - component: NumberInput - } - ]} - validationSchema={zeroConfLimitSchema} - buttonLabel={label} - value={null} + )} + {isNew && ( + { + dispatch({ type: 'form', form: it }) + }} /> - + )} +
+ {form && ( + innerContinue({ [type]: form.code }, { [form.code]: it })} + elements={schema[form.code].elements} + validationSchema={schema[form.code].validationSchema} + value={getValue(form.code)} + buttonLabel={label} + /> )} {!form && (
diff --git a/new-lamassu-admin/src/pages/Wizard/components/Wallet/AllSet.js b/new-lamassu-admin/src/pages/Wizard/components/Wallet/AllSet.js index 489ace16..15209af8 100644 --- a/new-lamassu-admin/src/pages/Wizard/components/Wallet/AllSet.js +++ b/new-lamassu-admin/src/pages/Wizard/components/Wallet/AllSet.js @@ -52,6 +52,8 @@ const AllSet = ({ data: currentData, doContinue }) => { const accountsConfig = data?.accountsConfig const cryptoCurrencies = data?.cryptoCurrencies ?? [] + currentData.zeroConfLimit = 0 + const save = () => { if (!WalletSchema.isValidSync(currentData)) return setError(true) diff --git a/new-lamassu-admin/src/pages/Wizard/components/Wallet/Wallet.js b/new-lamassu-admin/src/pages/Wizard/components/Wallet/Wallet.js index 7707cdde..0a9c77af 100644 --- a/new-lamassu-admin/src/pages/Wizard/components/Wallet/Wallet.js +++ b/new-lamassu-admin/src/pages/Wizard/components/Wallet/Wallet.js @@ -12,7 +12,6 @@ import ChooseCoin from './ChooseCoin' import ChooseExchange from './ChooseExchange' import ChooseTicker from './ChooseTicker' import ChooseWallet from './ChooseWallet' -import ZeroConfLimit from './ZeroConfLimit' const useStyles = makeStyles(styles) @@ -37,10 +36,6 @@ const steps = [ label: 'Blockcypher', component: Blockcypher }, - { - label: 'Set 0-conf Limit', - component: ZeroConfLimit - }, { label: 'All set', component: AllSet diff --git a/new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js b/new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js deleted file mode 100644 index b9c705d3..00000000 --- a/new-lamassu-admin/src/pages/Wizard/components/Wallet/ZeroConfLimit.js +++ /dev/null @@ -1,48 +0,0 @@ -import { makeStyles } from '@material-ui/core' -import React from 'react' -import * as Yup from 'yup' - -import { NumberInput } from 'src/components/inputs/formik' -import { H4 } from 'src/components/typography' -import FormRenderer from 'src/pages/Services/FormRenderer' - -import styles from './Shared.styles' - -const useStyles = makeStyles(styles) - -const zeroConfLimitSchema = Yup.object().shape({ - zeroConfLimit: Yup.number() - .integer() - .required() - .min(0) - .max(999999999) -}) - -const ZeroConfLimit = ({ data: currentData, addData }) => { - const classes = useStyles() - - const submit = value => { - addData({ zeroConfLimit: value }) - } - - return ( -
-

Set the 0-conf limit

- submit(Number(it.zeroConfLimit))} - /> -
- ) -} - -export default ZeroConfLimit