Fix: default 0 zeroConfLimit for new coins

This commit is contained in:
csrapr 2021-04-09 19:44:08 +01:00 committed by Josh Harvey
parent fafee1a727
commit 65a55a669d
7 changed files with 63 additions and 138 deletions

View file

@ -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