add crypto defaults
This commit is contained in:
parent
3eadb45344
commit
bcf72a0285
3 changed files with 22 additions and 7 deletions
|
|
@ -75,7 +75,6 @@ function validateCurrentConfig () {
|
||||||
function decorateEnabledIf (schemaFields, schemaField) {
|
function decorateEnabledIf (schemaFields, schemaField) {
|
||||||
const code = schemaField.fieldLocator.code
|
const code = schemaField.fieldLocator.code
|
||||||
const field = _.find(f => f.code === code, schemaFields)
|
const field = _.find(f => f.code === code, schemaFields)
|
||||||
console.log('DEBUG200: %j', [schemaField, code, field, schemaFields])
|
|
||||||
return _.set('fieldEnabledIf', field.enabledIf || [], schemaField)
|
return _.set('fieldEnabledIf', field.enabledIf || [], schemaField)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,12 +131,9 @@ function settings () {
|
||||||
return settingsCache
|
return settingsCache
|
||||||
}
|
}
|
||||||
|
|
||||||
const pp = require('./pp')
|
|
||||||
function save (config) {
|
function save (config) {
|
||||||
const sql = 'insert into user_config (type, data, valid) values ($1, $2, $3)'
|
const sql = 'insert into user_config (type, data, valid) values ($1, $2, $3)'
|
||||||
|
|
||||||
console.log(pp('DEBUG101')(config))
|
|
||||||
|
|
||||||
return configValidate.validate(config)
|
return configValidate.validate(config)
|
||||||
.then(() => db.none(sql, ['config', {config}, true]))
|
.then(() => db.none(sql, ['config', {config}, true]))
|
||||||
.catch(() => db.none(sql, ['config', {config}, false]))
|
.catch(() => db.none(sql, ['config', {config}, false]))
|
||||||
|
|
@ -170,6 +167,25 @@ function configDeleteField (scope, fieldCode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cryptoCodeDefaults (cryptoCode) {
|
||||||
|
const scope = {crypto: cryptoCode, machine: 'global'}
|
||||||
|
const fieldCode = 'exchange'
|
||||||
|
const fieldType = 'account'
|
||||||
|
const fieldClass = 'exchange'
|
||||||
|
const value = 'no-exchange'
|
||||||
|
|
||||||
|
return configAddField(scope, fieldCode, fieldType, fieldClass, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function addCryptoDefaults (oldConfig, newFields) {
|
||||||
|
const cryptoCodeEntries = _.filter(v => v.fieldLocator.code === 'cryptoCurrencies', newFields)
|
||||||
|
const cryptoCodes = _.map(v => v.fieldValue.value, cryptoCodeEntries)
|
||||||
|
const uniqueCryptoCodes = _.uniq(_.flatten(cryptoCodes))
|
||||||
|
const defaults = _.map(cryptoCodeDefaults, uniqueCryptoCodes)
|
||||||
|
|
||||||
|
return mergeValues(defaults, oldConfig)
|
||||||
|
}
|
||||||
|
|
||||||
function modifyConfig (newFields) {
|
function modifyConfig (newFields) {
|
||||||
const TransactionMode = pgp.txMode.TransactionMode
|
const TransactionMode = pgp.txMode.TransactionMode
|
||||||
const isolationLevel = pgp.txMode.isolationLevel
|
const isolationLevel = pgp.txMode.isolationLevel
|
||||||
|
|
@ -178,8 +194,9 @@ function modifyConfig (newFields) {
|
||||||
function transaction (t) {
|
function transaction (t) {
|
||||||
return loadRecentConfig()
|
return loadRecentConfig()
|
||||||
.then(oldConfig => {
|
.then(oldConfig => {
|
||||||
|
const oldConfigWithDefaults = addCryptoDefaults(oldConfig, newFields)
|
||||||
const doSave = _.flow(mergeValues, save)
|
const doSave = _.flow(mergeValues, save)
|
||||||
return doSave(oldConfig, newFields)
|
return doSave(oldConfigWithDefaults, newFields)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
const settingsLoader = require('../lib/settings-loader')
|
const settingsLoader = require('../lib/settings-loader')
|
||||||
|
|
||||||
const fields = [
|
const fields = [
|
||||||
settingsLoader.configDeleteField({crypto: 'global', machine: 'global'}, 'cashOutFee'),
|
settingsLoader.configDeleteField({crypto: 'ETH', machine: 'global'}, 'exchange')
|
||||||
settingsLoader.configDeleteField({crypto: 'global', machine: 'global'}, 'minTx')
|
|
||||||
]
|
]
|
||||||
|
|
||||||
settingsLoader.modifyConfig(fields)
|
settingsLoader.modifyConfig(fields)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue