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