Fix: remove unnecessary variables

This commit is contained in:
csrapr 2021-05-13 00:20:58 +01:00 committed by Josh Harvey
parent a521b679c4
commit 7210406a8a
7 changed files with 14 additions and 34 deletions

View file

@ -104,8 +104,7 @@ const getGlobalNotifications = config => getNotifications(null, null, config)
const getTriggers = _.get('triggers') const getTriggers = _.get('triggers')
const split = _.curry(_.split) const splitGetFirst = _.compose(_.head, _.split('_'))
const splitGetFirst = _.compose(_.head, split('_'))
const getCryptosFromWalletNamespace = config => { const getCryptosFromWalletNamespace = config => {
return _.uniq(_.map(splitGetFirst, _.keys(fromNamespace('wallets', config)))) return _.uniq(_.map(splitGetFirst, _.keys(fromNamespace('wallets', config))))

View file

@ -3,7 +3,6 @@ var db = require('../lib/db')
const settingsLoader = require('../lib/new-settings-loader') const settingsLoader = require('../lib/new-settings-loader')
const configManager = require('../lib/new-config-manager') const configManager = require('../lib/new-config-manager')
const isNil = val => val == null
const curriedGetCashout = _.curry(configManager.getCashOut) const curriedGetCashout = _.curry(configManager.getCashOut)
exports.up = function (next) { exports.up = function (next) {
@ -12,24 +11,25 @@ exports.up = function (next) {
const machinesPromise = t.any('SELECT device_id FROM devices') const machinesPromise = t.any('SELECT device_id FROM devices')
const [{ config }, machines] = await Promise.all([settingsPromise, machinesPromise]) const [{ config }, machines] = await Promise.all([settingsPromise, machinesPromise])
const cryptoCodes = configManager.getCryptosFromWalletNamespace(config) const cryptoCodes = configManager.getCryptosFromWalletNamespace(config)
const zeroConfLimits = _.map(_.flow(_.get('device_id'), curriedGetCashout(_, config), _.get('zeroConfLimit')), machines) const zeroConfLimits = _.map(_.flow(_.get('device_id'), curriedGetCashout(_, config), _.get('zeroConfLimit')), machines)
const minArr = _.min(zeroConfLimits) const minArr = _.min(zeroConfLimits)
const min = !isNil(minArr) && minArr < Infinity ? Number(minArr) : 0 const min = !_.isNil(minArr) && minArr < Infinity ? Number(minArr) : 0
_.forEach(cryptoCode => { _.forEach(cryptoCode => {
const walletConfig = configManager.getWalletSettings(cryptoCode, config) const walletConfig = configManager.getWalletSettings(cryptoCode, config)
const zeroConfLimit = _.get('zeroConfLimit', walletConfig) const zeroConfLimit = _.get('zeroConfLimit', walletConfig)
const key = `wallets_${cryptoCode}_zeroConfLimit` const key = `wallets_${cryptoCode}_zeroConfLimit`
if (isNil(zeroConfLimit)) { if (_.isNil(zeroConfLimit)) {
config[key] = min config[key] = min
} }
}, cryptoCodes) }, cryptoCodes)
const regexp = /^cashOut_[0-9a-z]+_zeroConfLimit$/ const keysToErase = machines.map(machine =>
const keysToErase = _.keys(config).filter(key => key.match(regexp)) config[`cashOut_${machine.device_id}_zeroConfLimit`] ? `cashOut_${machine.device_id}_zeroConfLimit` : null
)
_.forEach(key => { _.forEach(key => {
if (_.isNil(key)) return
config[key] = null config[key] = null
}, keysToErase) }, keysToErase)

View file

@ -224,8 +224,6 @@ const Locales = ({ name: SCREEN_KEY }) => {
userAccounts={data?.config?.accounts} userAccounts={data?.config?.accounts}
accounts={accounts} accounts={accounts}
accountsConfig={accountsConfig} accountsConfig={accountsConfig}
locale={locale}
zeroConfLimit={wallets[`${wizard}_zeroConfLimit`]}
/> />
)} )}
</> </>

View file

@ -123,8 +123,6 @@ const Wallet = ({ name: SCREEN_KEY }) => {
userAccounts={data?.config?.accounts} userAccounts={data?.config?.accounts}
accounts={accounts} accounts={accounts}
accountsConfig={accountsConfig} accountsConfig={accountsConfig}
locale={data?.config && fromNamespace('locale')(data.config)}
zeroConfLimit={config[`${wizard}_zeroConfLimit`]}
/> />
)} )}
{editingSchema && ( {editingSchema && (

View file

@ -33,16 +33,7 @@ const getItems = (accountsConfig, accounts, type, crypto) => {
return { filled, unfilled } return { filled, unfilled }
} }
const Wizard = ({ const Wizard = ({ coin, onClose, accountsConfig, accounts, save, error }) => {
coin,
onClose,
accountsConfig,
accounts,
save,
error,
locale,
zeroConfLimit
}) => {
const [{ step, config, accountsToSave }, setState] = useState({ const [{ step, config, accountsToSave }, setState] = useState({
step: 0, step: 0,
config: { active: true }, config: { active: true },
@ -66,8 +57,8 @@ const Wizard = ({
: accountsToSave : accountsToSave
if (isLastStep) { if (isLastStep) {
newConfig.zeroConfLimit = zeroConfLimit || 0 const configToSave = { ...newConfig, zeroConfLimit: 0 }
return save(toNamespace(coin.code, newConfig), newAccounts) return save(toNamespace(coin.code, configToSave), newAccounts)
} }
setState({ setState({
@ -113,7 +104,6 @@ const Wizard = ({
{...getStepData()} {...getStepData()}
onContinue={onContinue} onContinue={onContinue}
getValue={getValue} getValue={getValue}
locale={locale}
/> />
)} )}
</Modal> </Modal>

View file

@ -59,8 +59,7 @@ const WizardStep = ({
onContinue, onContinue,
filled, filled,
unfilled, unfilled,
getValue, getValue
locale
}) => { }) => {
const classes = useStyles() const classes = useStyles()
const [{ innerError, selected, form, isNew }, dispatch] = useReducer( const [{ innerError, selected, form, isNew }, dispatch] = useReducer(
@ -69,9 +68,6 @@ const WizardStep = ({
) )
useEffect(() => { useEffect(() => {
if (step === 5) {
return dispatch({ type: 'form', form: { code: 'zeroConfLimit' } })
}
dispatch({ type: 'reset' }) dispatch({ type: 'reset' })
}, [step]) }, [step])

View file

@ -52,12 +52,11 @@ const AllSet = ({ data: currentData, doContinue }) => {
const accountsConfig = data?.accountsConfig const accountsConfig = data?.accountsConfig
const cryptoCurrencies = data?.cryptoCurrencies ?? [] const cryptoCurrencies = data?.cryptoCurrencies ?? []
currentData.zeroConfLimit = 0
const save = () => { const save = () => {
if (!WalletSchema.isValidSync(currentData)) return setError(true) const adjustedData = { zeroConfLimit: 0, ...currentData }
if (!WalletSchema.isValidSync(adjustedData)) return setError(true)
const withCoin = toNamespace(coin, R.omit('coin', currentData)) const withCoin = toNamespace(coin, R.omit('coin', adjustedData))
const config = toNamespace(namespaces.WALLETS)(withCoin) const config = toNamespace(namespaces.WALLETS)(withCoin)
setError(false) setError(false)
return saveConfig({ variables: { config } }) return saveConfig({ variables: { config } })