Chore: use constant for currencyMax
This commit is contained in:
parent
7210406a8a
commit
d2b7224c73
7 changed files with 39 additions and 38 deletions
|
|
@ -23,12 +23,6 @@ const createTerms = terms => (terms.active && terms.text) ? ({
|
|||
cancel: terms.cancelButtonText
|
||||
}) : null
|
||||
|
||||
const buildZeroConfLimits = (cryptoCodes, config) => {
|
||||
const zeroConfLimits = {}
|
||||
_.forEach(cryptoCode => { zeroConfLimits[cryptoCode] = configManager.getWalletSettings(cryptoCode, config).zeroConfLimit }, cryptoCodes)
|
||||
return zeroConfLimits
|
||||
}
|
||||
|
||||
function poll (req, res, next) {
|
||||
const machineVersion = req.query.version
|
||||
const machineModel = req.query.model
|
||||
|
|
@ -38,7 +32,10 @@ function poll (req, res, next) {
|
|||
const pid = req.query.pid
|
||||
const settings = req.settings
|
||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||
const zeroConfLimits = buildZeroConfLimits(localeConfig.cryptoCurrencies, settings.config)
|
||||
const zeroConfLimits = _.reduce((acc, cryptoCode) => {
|
||||
acc[cryptoCode] = configManager.getWalletSettings(cryptoCode, settings.config).zeroConfLimit
|
||||
return acc
|
||||
}, {}, localeConfig.cryptoCurrencies)
|
||||
const pi = plugins(settings, deviceId)
|
||||
const hasLightning = checkHasLightning(settings)
|
||||
|
||||
|
|
|
|||
|
|
@ -3,35 +3,35 @@ var db = require('../lib/db')
|
|||
const settingsLoader = require('../lib/new-settings-loader')
|
||||
const configManager = require('../lib/new-config-manager')
|
||||
|
||||
const curriedGetCashout = _.curry(configManager.getCashOut)
|
||||
|
||||
exports.up = function (next) {
|
||||
db.tx(async t => {
|
||||
return db.tx(async t => {
|
||||
const settingsPromise = settingsLoader.loadLatest()
|
||||
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 deviceIds = _.map(_.get('device_id'))(machines)
|
||||
const getZeroConfLimit = _.compose(_.get('zeroConfLimit'), it => configManager.getCashOut(it, config))
|
||||
const zeroConfLimits = _.map(getZeroConfLimit)(deviceIds)
|
||||
|
||||
const configMin = _.min(zeroConfLimits)
|
||||
const smallerZeroConf = _.isFinite(configMin) ? Number(configMin) : 0
|
||||
|
||||
_.forEach(cryptoCode => {
|
||||
const walletConfig = configManager.getWalletSettings(cryptoCode, config)
|
||||
const zeroConfLimit = _.get('zeroConfLimit', walletConfig)
|
||||
const key = `wallets_${cryptoCode}_zeroConfLimit`
|
||||
|
||||
if (_.isNil(zeroConfLimit)) {
|
||||
config[key] = min
|
||||
config[`wallets_${cryptoCode}_zeroConfLimit`] = smallerZeroConf
|
||||
}
|
||||
}, cryptoCodes)
|
||||
|
||||
const keysToErase = machines.map(machine =>
|
||||
config[`cashOut_${machine.device_id}_zeroConfLimit`] ? `cashOut_${machine.device_id}_zeroConfLimit` : null
|
||||
)
|
||||
|
||||
_.forEach(key => {
|
||||
if (_.isNil(key)) return
|
||||
_.forEach(deviceId => {
|
||||
const key = `cashOut_${deviceId}_zeroConfLimit`
|
||||
if (_.has(key, config)) {
|
||||
config[key] = null
|
||||
}, keysToErase)
|
||||
}
|
||||
})(deviceIds)
|
||||
|
||||
return settingsLoader.saveConfig(config)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -2,19 +2,19 @@ import * as Yup from 'yup'
|
|||
|
||||
import { NumberInput } from 'src/components/inputs/formik'
|
||||
import { bold } from 'src/styling/helpers'
|
||||
import { CURRENCY_MAX } from 'src/utils/constants'
|
||||
|
||||
const currencyMax = 999999999
|
||||
const DenominationsSchema = Yup.object().shape({
|
||||
top: Yup.number()
|
||||
.label('Cassette 1 (Top)')
|
||||
.required()
|
||||
.min(1)
|
||||
.max(currencyMax),
|
||||
.max(CURRENCY_MAX),
|
||||
bottom: Yup.number()
|
||||
.label('Cassette 2 (Bottom)')
|
||||
.required()
|
||||
.min(1)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
})
|
||||
|
||||
const getElements = (machines, { fiatCurrency } = {}) => {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import { bold } from 'src/styling/helpers'
|
|||
import { ReactComponent as TxInIcon } from 'src/styling/icons/direction/cash-in.svg'
|
||||
import { ReactComponent as TxOutIcon } from 'src/styling/icons/direction/cash-out.svg'
|
||||
import { primaryColor, secondaryColorDark } from 'src/styling/variables'
|
||||
import { CURRENCY_MAX } from 'src/utils/constants'
|
||||
|
||||
const ALL_MACHINES = {
|
||||
name: 'All Machines',
|
||||
|
|
@ -225,7 +226,6 @@ const overrides = (auxData, currency, auxElements) => {
|
|||
}
|
||||
|
||||
const percentMax = 100
|
||||
const currencyMax = 9999999
|
||||
const schema = Yup.object().shape({
|
||||
cashIn: Yup.number()
|
||||
.label('Cash-in')
|
||||
|
|
@ -240,12 +240,12 @@ const schema = Yup.object().shape({
|
|||
fixedFee: Yup.number()
|
||||
.label('Fixed Fee')
|
||||
.min(0)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.required(),
|
||||
minimumTx: Yup.number()
|
||||
.label('Minimum Tx')
|
||||
.min(0)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.required()
|
||||
})
|
||||
|
||||
|
|
@ -329,12 +329,12 @@ const getOverridesSchema = (values, rawData) => {
|
|||
fixedFee: Yup.number()
|
||||
.label('Fixed Fee')
|
||||
.min(0)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.required(),
|
||||
minimumTx: Yup.number()
|
||||
.label('Minimum Tx')
|
||||
.min(0)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.required()
|
||||
})
|
||||
}
|
||||
|
|
@ -435,12 +435,12 @@ const getListCommissionsSchema = () => {
|
|||
fixedFee: Yup.number()
|
||||
.label('Fixed Fee')
|
||||
.min(0)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.required(),
|
||||
minimumTx: Yup.number()
|
||||
.label('Minimum Tx')
|
||||
.min(0)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.required()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import * as Yup from 'yup'
|
|||
import { Table as EditableTable } from 'src/components/editableTable'
|
||||
import { NumberInput } from 'src/components/inputs/formik'
|
||||
import Autocomplete from 'src/components/inputs/formik/Autocomplete.js'
|
||||
import { CURRENCY_MAX } from 'src/utils/constants'
|
||||
import { transformNumber } from 'src/utils/number'
|
||||
|
||||
import NotificationsCtx from '../NotificationsContext'
|
||||
|
|
@ -54,7 +55,6 @@ const CryptoBalanceOverrides = ({ section }) => {
|
|||
}
|
||||
|
||||
const notesMin = 0
|
||||
const currencyMax = 9999999
|
||||
const validationSchema = Yup.object().shape(
|
||||
{
|
||||
[CRYPTOCURRENCY_KEY]: Yup.string()
|
||||
|
|
@ -70,7 +70,7 @@ const CryptoBalanceOverrides = ({ section }) => {
|
|||
.transform(transformNumber)
|
||||
.integer()
|
||||
.min(notesMin)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.nullable(),
|
||||
[HIGH_BALANCE_KEY]: Yup.number()
|
||||
.label('High Balance')
|
||||
|
|
@ -81,7 +81,7 @@ const CryptoBalanceOverrides = ({ section }) => {
|
|||
.transform(transformNumber)
|
||||
.integer()
|
||||
.min(notesMin)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
.nullable()
|
||||
},
|
||||
[LOW_BALANCE_KEY, HIGH_BALANCE_KEY]
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ import * as Yup from 'yup'
|
|||
|
||||
import { NumberInput } from 'src/components/inputs/formik'
|
||||
import Autocomplete from 'src/components/inputs/formik/Autocomplete.js'
|
||||
import { CURRENCY_MAX } from 'src/utils/constants'
|
||||
|
||||
const filterClass = type => R.filter(it => it.class === type)
|
||||
const filterCoins = ({ id }) => R.filter(it => R.contains(id)(it.cryptos))
|
||||
const currencyMax = 999999999
|
||||
|
||||
const WalletSchema = Yup.object().shape({
|
||||
ticker: Yup.string().required(),
|
||||
wallet: Yup.string().required(),
|
||||
|
|
@ -16,7 +17,7 @@ const WalletSchema = Yup.object().shape({
|
|||
.integer()
|
||||
.required()
|
||||
.min(0)
|
||||
.max(currencyMax)
|
||||
.max(CURRENCY_MAX)
|
||||
})
|
||||
|
||||
const getElements = (cryptoCurrencies, accounts, onChange, wizard = false) => {
|
||||
|
|
|
|||
3
new-lamassu-admin/src/utils/constants.js
Normal file
3
new-lamassu-admin/src/utils/constants.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
const CURRENCY_MAX = 9999999
|
||||
|
||||
export { CURRENCY_MAX }
|
||||
Loading…
Add table
Add a link
Reference in a new issue