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

View file

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

View file

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

View file

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

View file

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

View file

@ -52,12 +52,11 @@ 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)
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)
setError(false)
return saveConfig({ variables: { config } })