support enabledIfAny enabledIfAll
This commit is contained in:
parent
87fdb355b2
commit
8a725a54f1
4 changed files with 129 additions and 97 deletions
|
|
@ -128,7 +128,7 @@
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"cryptoScope": "both",
|
"cryptoScope": "both",
|
||||||
"machineScope": "both",
|
"machineScope": "both",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
|
|
@ -170,7 +170,7 @@
|
||||||
"cryptoScope": "both",
|
"cryptoScope": "both",
|
||||||
"machineScope": "both",
|
"machineScope": "both",
|
||||||
"default": 0,
|
"default": 0,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
{
|
{
|
||||||
|
|
@ -190,7 +190,7 @@
|
||||||
"fieldClass": "fiat",
|
"fieldClass": "fiat",
|
||||||
"cryptoScope": "both",
|
"cryptoScope": "both",
|
||||||
"machineScope": "global",
|
"machineScope": "global",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"notificationsEnabled"
|
"notificationsEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
|
|
@ -211,7 +211,7 @@
|
||||||
"fieldClass": "banknotes",
|
"fieldClass": "banknotes",
|
||||||
"cryptoScope": "global",
|
"cryptoScope": "global",
|
||||||
"machineScope": "both",
|
"machineScope": "both",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"notificationsEnabled"
|
"notificationsEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
|
|
@ -234,8 +234,9 @@
|
||||||
"cryptoScope": "global",
|
"cryptoScope": "global",
|
||||||
"machineScope": "both",
|
"machineScope": "both",
|
||||||
"default": 10,
|
"default": 10,
|
||||||
"enabledIf": [
|
"enabledIfAll": [
|
||||||
"notificationsEnabled"
|
"notificationsEnabled",
|
||||||
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
{
|
{
|
||||||
|
|
@ -256,8 +257,9 @@
|
||||||
"cryptoScope": "global",
|
"cryptoScope": "global",
|
||||||
"machineScope": "both",
|
"machineScope": "both",
|
||||||
"default": 10,
|
"default": 10,
|
||||||
"enabledIf": [
|
"enabledIfAll": [
|
||||||
"notificationsEnabled"
|
"notificationsEnabled",
|
||||||
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
{
|
{
|
||||||
|
|
@ -277,7 +279,7 @@
|
||||||
"fieldClass": "fiat",
|
"fieldClass": "fiat",
|
||||||
"cryptoScope": "global",
|
"cryptoScope": "global",
|
||||||
"machineScope": "both",
|
"machineScope": "both",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
@ -375,7 +377,7 @@
|
||||||
"displayTopCount": 3,
|
"displayTopCount": 3,
|
||||||
"fieldType": "integer",
|
"fieldType": "integer",
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
@ -386,7 +388,7 @@
|
||||||
"displayTopCount": 0,
|
"displayTopCount": 0,
|
||||||
"fieldType": "integer",
|
"fieldType": "integer",
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
@ -397,7 +399,7 @@
|
||||||
"displayTopCount": 0,
|
"displayTopCount": 0,
|
||||||
"fieldType": "integer",
|
"fieldType": "integer",
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
@ -408,7 +410,7 @@
|
||||||
"displayBottom": "Margin",
|
"displayBottom": "Margin",
|
||||||
"fieldType": "integer",
|
"fieldType": "integer",
|
||||||
"fieldClass": "banknotes",
|
"fieldClass": "banknotes",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}],
|
"fieldValidation": [{"code": "required"}],
|
||||||
|
|
@ -433,7 +435,7 @@
|
||||||
"displayTopCount": 0,
|
"displayTopCount": 0,
|
||||||
"fieldType": "integer",
|
"fieldType": "integer",
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
@ -472,7 +474,7 @@
|
||||||
"displayBottom": "Service",
|
"displayBottom": "Service",
|
||||||
"fieldType": "account",
|
"fieldType": "account",
|
||||||
"fieldClass": "idVerifier",
|
"fieldClass": "idVerifier",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"idVerificationEnabled"
|
"idVerificationEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
@ -483,7 +485,7 @@
|
||||||
"displayTopCount": 0,
|
"displayTopCount": 0,
|
||||||
"fieldType": "integer",
|
"fieldType": "integer",
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"idVerificationEnabled"
|
"idVerificationEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
@ -546,7 +548,7 @@
|
||||||
"displayTopCount": 0,
|
"displayTopCount": 0,
|
||||||
"fieldType": "onOff",
|
"fieldType": "onOff",
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"notificationsEnabled"
|
"notificationsEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
|
|
@ -562,7 +564,7 @@
|
||||||
"displayTopCount": 0,
|
"displayTopCount": 0,
|
||||||
"fieldType": "onOff",
|
"fieldType": "onOff",
|
||||||
"fieldClass": null,
|
"fieldClass": null,
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"notificationsEnabled"
|
"notificationsEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [
|
"fieldValidation": [
|
||||||
|
|
@ -579,7 +581,7 @@
|
||||||
"displayTopCount": 2,
|
"displayTopCount": 2,
|
||||||
"fieldType": "account",
|
"fieldType": "account",
|
||||||
"fieldClass": "sms",
|
"fieldClass": "sms",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"notificationsSMSEnabled",
|
"notificationsSMSEnabled",
|
||||||
"cashOutEnabled"
|
"cashOutEnabled"
|
||||||
],
|
],
|
||||||
|
|
@ -591,7 +593,7 @@
|
||||||
"displayTopCount": 0,
|
"displayTopCount": 0,
|
||||||
"fieldType": "account",
|
"fieldType": "account",
|
||||||
"fieldClass": "email",
|
"fieldClass": "email",
|
||||||
"enabledIf": [
|
"enabledIfAny": [
|
||||||
"notificationsEmailEnabled"
|
"notificationsEmailEnabled"
|
||||||
],
|
],
|
||||||
"fieldValidation": [{"code": "required"}]
|
"fieldValidation": [{"code": "required"}]
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,11 @@ 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)
|
||||||
return _.set('fieldEnabledIf', field.enabledIf || [], schemaField)
|
|
||||||
|
return _.assign(schemaField, {
|
||||||
|
fieldEnabledIfAny: field.enabledIfAny || [],
|
||||||
|
fieldEnabledIfAll: field.enabledIfAll || []
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchConfigGroup (code) {
|
function fetchConfigGroup (code) {
|
||||||
|
|
@ -88,10 +92,15 @@ function fetchConfigGroup (code) {
|
||||||
|
|
||||||
const schemaFields = groupSchema.fields
|
const schemaFields = groupSchema.fields
|
||||||
.map(R.curry(getField)(schema, groupSchema))
|
.map(R.curry(getField)(schema, groupSchema))
|
||||||
|
.map(f => _.assign(f, {
|
||||||
|
fieldEnabledIfAny: f.enabledIfAny || [],
|
||||||
|
fieldEnabledIfAll: f.enabledIfAll || []
|
||||||
|
}))
|
||||||
|
|
||||||
const candidateFields = [
|
const candidateFields = [
|
||||||
schemaFields.map(R.prop('requiredIf')),
|
schemaFields.map(R.prop('requiredIf')),
|
||||||
schemaFields.map(R.prop('enabledIf')),
|
schemaFields.map(R.prop('enabledIfAny')),
|
||||||
|
schemaFields.map(R.prop('enabledIfAll')),
|
||||||
groupSchema.fields,
|
groupSchema.fields,
|
||||||
'fiatCurrency'
|
'fiatCurrency'
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ function allMachineScopes (machineList, machineScope) {
|
||||||
return machineScopes
|
return machineScopes
|
||||||
}
|
}
|
||||||
|
|
||||||
function satisfiesRequire (config, cryptos, machineList, field, refFields) {
|
function satisfiesRequireAny (config, cryptos, machineList, field, refFields) {
|
||||||
const fieldCode = field.code
|
const fieldCode = field.code
|
||||||
|
|
||||||
const scopes = allScopes(
|
const scopes = allScopes(
|
||||||
|
|
@ -54,6 +54,28 @@ function satisfiesRequire (config, cryptos, machineList, field, refFields) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function satisfiesRequireAll (config, cryptos, machineList, field, refFields) {
|
||||||
|
const fieldCode = field.code
|
||||||
|
|
||||||
|
const scopes = allScopes(
|
||||||
|
allCryptoScopes(cryptos, field.cryptoScope),
|
||||||
|
allMachineScopes(machineList, field.machineScope)
|
||||||
|
)
|
||||||
|
|
||||||
|
return scopes.every(scope => {
|
||||||
|
const isEnabled = () => _.isEmpty(refFields) || refFields.every(refField => {
|
||||||
|
return isScopeEnabled(config, cryptos, machineList, refField, scope)
|
||||||
|
})
|
||||||
|
|
||||||
|
const isBlank = _.isNil(configManager.scopedValue(scope[0], scope[1], fieldCode, config))
|
||||||
|
const isRequired = refFields.length === 0 || isEnabled()
|
||||||
|
|
||||||
|
const isValid = isRequired ? !isBlank : true
|
||||||
|
|
||||||
|
return isValid
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function isScopeEnabled (config, cryptos, machineList, refField, scope) {
|
function isScopeEnabled (config, cryptos, machineList, refField, scope) {
|
||||||
const [cryptoScope, machineScope] = scope
|
const [cryptoScope, machineScope] = scope
|
||||||
const candidateCryptoScopes = cryptoScope === 'global'
|
const candidateCryptoScopes = cryptoScope === 'global'
|
||||||
|
|
@ -150,9 +172,11 @@ function validateRequires (config) {
|
||||||
|
|
||||||
if (!field.fieldValidation.find(r => r.code === 'required')) return false
|
if (!field.fieldValidation.find(r => r.code === 'required')) return false
|
||||||
|
|
||||||
const refFields = _.map(_.partial(getField, group), field.enabledIf)
|
const refFieldsAny = _.map(_.partial(getField, group), field.enabledIfAny)
|
||||||
|
const refFieldsAll = _.map(_.partial(getField, group), field.enabledIfAll)
|
||||||
|
|
||||||
return !satisfiesRequire(config, cryptos, machineList, field, refFields)
|
return !satisfiesRequireAny(config, cryptos, machineList, field, refFieldsAny) &&
|
||||||
|
!satisfiesRequireAll(config, cryptos, machineList, field, refFieldsAll)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue