diff --git a/lib/plugins.js b/lib/plugins.js index a6d2dad3..f1f1deb6 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -15,6 +15,7 @@ const wallet = require('./wallet') const exchange = require('./exchange') const sms = require('./sms') const email = require('./email') +const settingsLoader = require('./settings-loader') const mapValuesWithKey = _.mapValues.convert({cap: false}) @@ -515,12 +516,48 @@ function plugins (settings, deviceId) { // // However, we should make all config changes atomic in the future. const config = configManager.machineScoped(deviceId, settings.config) - config.topCashOutDenomination -= tx.bills[0].actualDispense + - tx.bills[0].rejected - config.bottomCashOutDenomination -= tx.bills[1].actualDispense + - tx.bills[1].rejected + const topCashOutDenomination = config.topCashOutDenomination - + (tx.bills[0].actualDispense + tx.bills[0].rejected) + const bottomCashOutDenomination = config.bottomCashOutDenomination - + (tx.bills[1].actualDispense + tx.bills[1].rejected) - // save + const newFields = [ + { + fieldLocator: { + fieldScope: { + crypto: 'global', + machine: deviceId + }, + code: 'topCashOutDenomination', + fieldType: 'integer', + fieldClass: null + }, + fieldValue: { + fieldType: 'integer', + value: topCashOutDenomination + } + }, + { + fieldLocator: { + fieldScope: { + crypto: 'global', + machine: deviceId + }, + code: 'bottomCashOutDenomination', + fieldType: 'integer', + fieldClass: null + }, + fieldValue: { + fieldType: 'integer', + value: bottomCashOutDenomination + } + } + ] + + return settingsLoader.loadLatest() + .then(settings => { + return settingsLoader.save({config: settingsLoader.mergeValues(settings.config, newFields)}) + }) } return {