diff --git a/lib/admin/settings-loader.js b/lib/admin/settings-loader.js index eccd677f..ef5b2f2c 100644 --- a/lib/admin/settings-loader.js +++ b/lib/admin/settings-loader.js @@ -240,6 +240,7 @@ module.exports = { loadRecentConfig, load, loadLatest, + loadLatestConfig, save, loadFixture, mergeValues, diff --git a/lib/cash-in/cash-in-tx.js b/lib/cash-in/cash-in-tx.js index 57ea8ccf..8f7703cb 100644 --- a/lib/cash-in/cash-in-tx.js +++ b/lib/cash-in/cash-in-tx.js @@ -36,7 +36,7 @@ function post (machineTx, pi) { let addressReuse = false let walletScore = {} - const promises = [settingsLoader.loadLatest()] + const promises = [settingsLoader.loadLatestConfig()] const isFirstPost = !r.tx.fiat || r.tx.fiat.isZero() if (isFirstPost) { @@ -44,7 +44,7 @@ function post (machineTx, pi) { } return Promise.all(promises) - .then(([{ config }, blacklistItems = false, isReusedAddress = false, fetchedWalletScore = null]) => { + .then(([config, blacklistItems = false, isReusedAddress = false, fetchedWalletScore = null]) => { const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse walletScore = fetchedWalletScore diff --git a/lib/notifier/index.js b/lib/notifier/index.js index 8bad9a51..8e61f162 100644 --- a/lib/notifier/index.js +++ b/lib/notifier/index.js @@ -130,8 +130,8 @@ function checkStuckScreen (deviceEvents, machine) { } function transactionNotify (tx, rec) { - return settingsLoader.loadLatest().then(settings => { - const notifSettings = configManager.getGlobalNotifications(settings.config) + return settingsLoader.loadLatestConfig().then(config => { + const notifSettings = configManager.getGlobalNotifications(config) const highValueTx = tx.fiat.gt(notifSettings.highValueTransaction || Infinity) const isCashOut = tx.direction === 'cashOut' @@ -147,7 +147,7 @@ function transactionNotify (tx, rec) { } // alert through sms or email any transaction or high value transaction, if SMS || email alerts are enabled - const walletSettings = configManager.getWalletSettings(tx.cryptoCode, settings.config) + const walletSettings = configManager.getWalletSettings(tx.cryptoCode, config) const zeroConfLimit = walletSettings.zeroConfLimit || 0 const zeroConf = isCashOut && tx.fiat.lte(zeroConfLimit) const notificationsEnabled = notifSettings.sms.transactions || notifSettings.email.transactions @@ -308,8 +308,8 @@ function cashboxNotify (deviceId) { // for notification center, check if type of notification is active before calling the respective notify function const notifyIfActive = (type, fnName, ...args) => { - return settingsLoader.loadLatest().then(settings => { - const notificationSettings = configManager.getGlobalNotifications(settings.config).notificationCenter + return settingsLoader.loadLatestConfig().then(config => { + const notificationSettings = configManager.getGlobalNotifications(config).notificationCenter if (!notificationCenter[fnName]) return Promise.reject(new Error(`Notification function ${fnName} for type ${type} does not exist`)) if (!(notificationSettings.active && notificationSettings[type])) return Promise.resolve() return notificationCenter[fnName](...args) diff --git a/migrations/1617742522808-zeroConfLimit-migrate.js b/migrations/1617742522808-zeroConfLimit-migrate.js index 789c0656..4aa746a9 100644 --- a/migrations/1617742522808-zeroConfLimit-migrate.js +++ b/migrations/1617742522808-zeroConfLimit-migrate.js @@ -5,9 +5,9 @@ const configManager = require('../lib/new-config-manager') exports.up = function (next) { return db.tx(async t => { - const settingsPromise = settingsLoader.loadLatest() + const settingsPromise = settingsLoader.loadLatestConfig() 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 deviceIds = _.map(_.get('device_id'))(machines) diff --git a/migrations/1618507684019-rename-0-conf.js b/migrations/1618507684019-rename-0-conf.js index 7a416239..79d7e437 100644 --- a/migrations/1618507684019-rename-0-conf.js +++ b/migrations/1618507684019-rename-0-conf.js @@ -3,7 +3,7 @@ const settingsLoader = require('../lib/new-settings-loader') const configManager = require('../lib/new-config-manager') exports.up = async function (next) { - const { config } = await settingsLoader.loadLatest() + const config = await settingsLoader.loadLatestConfig() const cryptoCodes = configManager.getCryptosFromWalletNamespace(config) _.forEach(cryptoCode => { const key = `wallets_${cryptoCode}_zeroConf` diff --git a/migrations/1619968992683-fiat-balance-notification-to-percent.js b/migrations/1619968992683-fiat-balance-notification-to-percent.js index a3d6b500..ed0f6628 100644 --- a/migrations/1619968992683-fiat-balance-notification-to-percent.js +++ b/migrations/1619968992683-fiat-balance-notification-to-percent.js @@ -1,10 +1,10 @@ const _ = require('lodash/fp') -const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader') +const { migrationSaveConfig, loadLatestConfig } = require('../lib/new-settings-loader') const CASSETTE_MAX_CAPACITY = 500 exports.up = function (next) { - return loadLatest() - .then(({ config }) => { + return loadLatestConfig() + .then(config => { const fiatBalance1 = config.notifications_fiatBalanceCassette1 const fiatBalance2 = config.notifications_fiatBalanceCassette2 const fiatBalance3 = config.notifications_fiatBalanceCassette3 diff --git a/migrations/1620319260238-timezones.js b/migrations/1620319260238-timezones.js index c2d08484..789655b8 100644 --- a/migrations/1620319260238-timezones.js +++ b/migrations/1620319260238-timezones.js @@ -2,8 +2,8 @@ const _ = require('lodash/fp') const settingsLoader = require('../lib/new-settings-loader') exports.up = function (next) { - settingsLoader.loadLatest() - .then(({ config }) => { + settingsLoader.loadLatestConfig() + .then(config => { if (!_.isEmpty(config)) config.locale_timezone = '0:0' return settingsLoader.migrationSaveConfig(config) diff --git a/migrations/1623975493095-add-crypto-units-to-config.js b/migrations/1623975493095-add-crypto-units-to-config.js index 95d87c07..c251b2b1 100644 --- a/migrations/1623975493095-add-crypto-units-to-config.js +++ b/migrations/1623975493095-add-crypto-units-to-config.js @@ -1,13 +1,13 @@ -const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader') +const { migrationSaveConfig, loadLatestConfig } = require('../lib/new-settings-loader') const { getCryptosFromWalletNamespace } = require('../lib/new-config-manager.js') const { utils: coinUtils } = require('@lamassu/coins') const _ = require('lodash/fp') exports.up = function (next) { - loadLatest() - .then(settings => { + loadLatestConfig() + .then(config => { const newSettings = {} - const activeCryptos = getCryptosFromWalletNamespace(settings.config) + const activeCryptos = getCryptosFromWalletNamespace(config) if (!activeCryptos.length) return Promise.resolve() _.map(crypto => { const defaultUnit = _.head(_.keys(coinUtils.getCryptoCurrency(crypto).units)) diff --git a/migrations/1630432869178-add-more-cassette-support.js b/migrations/1630432869178-add-more-cassette-support.js index 70c906fe..5c73a17b 100644 --- a/migrations/1630432869178-add-more-cassette-support.js +++ b/migrations/1630432869178-add-more-cassette-support.js @@ -1,6 +1,6 @@ var db = require('./db') const _ = require('lodash/fp') -const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader') +const { migrationSaveConfig, loadLatestConfig } = require('../lib/new-settings-loader') const { getMachineIds } = require('../lib/machine-loader') exports.up = function (next) { @@ -25,16 +25,16 @@ exports.up = function (next) { ADD COLUMN denomination_4 INTEGER` ] - return Promise.all([loadLatest(), getMachineIds()]) + return Promise.all([loadLatestConfig(), getMachineIds()]) .then(([config, machineIds]) => { const newConfig = _.reduce((acc, value) => { const deviceId = value.device_id - if (_.includes(`cashOut_${deviceId}_top`, _.keys(config.config))) { - acc[`cashOut_${deviceId}_cassette1`] = config.config[`cashOut_${deviceId}_top`] + if (_.includes(`cashOut_${deviceId}_top`, _.keys(config))) { + acc[`cashOut_${deviceId}_cassette1`] = config[`cashOut_${deviceId}_top`] } - if (_.includes(`cashOut_${deviceId}_bottom`, _.keys(config.config))) { - acc[`cashOut_${deviceId}_cassette2`] = config.config[`cashOut_${deviceId}_bottom`] + if (_.includes(`cashOut_${deviceId}_bottom`, _.keys(config))) { + acc[`cashOut_${deviceId}_cassette2`] = config[`cashOut_${deviceId}_bottom`] } return acc diff --git a/migrations/1645010873828-add-advanced-wallet-settings.js b/migrations/1645010873828-add-advanced-wallet-settings.js index 34252cc6..1b2fad5d 100644 --- a/migrations/1645010873828-add-advanced-wallet-settings.js +++ b/migrations/1645010873828-add-advanced-wallet-settings.js @@ -1,16 +1,14 @@ const uuid = require('uuid') -const { saveConfig, loadLatest } = require('../lib/new-settings-loader') +const { saveConfig } = require('../lib/new-settings-loader') exports.up = function (next) { - const newConfig = {} - return loadLatest() - .then(config => { - newConfig[`wallets_advanced_feeMultiplier`] = '1' - newConfig[`wallets_advanced_cryptoUnits`] = 'full' - newConfig[`wallets_advanced_allowTransactionBatching`] = false - newConfig[`wallets_advanced_id`] = uuid.v4() - return saveConfig(newConfig) - }) + const newConfig = { + wallets_advanced_feeMultiplier: '1', + wallets_advanced_cryptoUnits: 'full', + wallets_advanced_allowTransactionBatching: false, + wallets_advanced_id: uuid.v4(), + } + return saveConfig(newConfig) .then(next) .catch(err => { return next(err) diff --git a/migrations/1645459054117-default-timezone.js b/migrations/1645459054117-default-timezone.js index d2e64fb0..de8ef590 100644 --- a/migrations/1645459054117-default-timezone.js +++ b/migrations/1645459054117-default-timezone.js @@ -1,12 +1,11 @@ const _ = require('lodash/fp') -const { saveConfig, loadLatest } = require('../lib/new-settings-loader') +const { saveConfig, loadLatestConfig } = require('../lib/new-settings-loader') exports.up = function (next) { - const newConfig = {} - return loadLatest() + return loadLatestConfig() .then(config => { - if (!_.isNil(config.config.locale_timezone)) return - newConfig[`locale_timezone`] = 'GMT' + if (!_.isNil(config.locale_timezone)) return + const newConfig = { locale_timezone: 'GMT' } return saveConfig(newConfig) }) .then(next) diff --git a/migrations/1655807727853-default_timezone_fix.js b/migrations/1655807727853-default_timezone_fix.js index fba11a26..6d2cc4a7 100644 --- a/migrations/1655807727853-default_timezone_fix.js +++ b/migrations/1655807727853-default_timezone_fix.js @@ -1,11 +1,10 @@ -const { saveConfig, loadLatest } = require('../lib/new-settings-loader') +const { saveConfig, loadLatestConfig } = require('../lib/new-settings-loader') exports.up = function (next) { - const newConfig = {} - return loadLatest() + return loadLatestConfig() .then(config => { - if (config.config.locale_timezone === "0:0") { - newConfig[`locale_timezone`] = 'GMT' + if (config.locale_timezone === "0:0") { + const newConfig = { locale_timezone: 'GMT' } return saveConfig(newConfig) } }) diff --git a/migrations/1658940716689-remove-coin-specific-cryptounits.js b/migrations/1658940716689-remove-coin-specific-cryptounits.js index e91bca7c..d9bada35 100644 --- a/migrations/1658940716689-remove-coin-specific-cryptounits.js +++ b/migrations/1658940716689-remove-coin-specific-cryptounits.js @@ -1,11 +1,11 @@ -const { removeFromConfig, loadLatest } = require('../lib/new-settings-loader') +const { removeFromConfig, loadLatestConfig } = require('../lib/new-settings-loader') const { getCryptosFromWalletNamespace } = require('../lib/new-config-manager.js') const _ = require('lodash/fp') exports.up = function (next) { - loadLatest() - .then(settings => { - const configuredCryptos = getCryptosFromWalletNamespace(settings.config) + loadLatestConfig() + .then(config => { + const configuredCryptos = getCryptosFromWalletNamespace(config) if (!configuredCryptos.length) return Promise.resolve() return removeFromConfig(_.map(it => `wallets_${it}_cryptoUnits`, configuredCryptos)) diff --git a/migrations/1661125970289-eth-zero-conf-value.js b/migrations/1661125970289-eth-zero-conf-value.js index 4376d67e..1dda9e4e 100644 --- a/migrations/1661125970289-eth-zero-conf-value.js +++ b/migrations/1661125970289-eth-zero-conf-value.js @@ -1,13 +1,12 @@ const _ = require('lodash/fp') -const { saveConfig, loadLatest } = require('../lib/new-settings-loader') +const { saveConfig, loadLatestConfig } = require('../lib/new-settings-loader') exports.up = function (next) { - const newConfig = {} - return loadLatest() + return loadLatestConfig() .then(config => { - if (!_.isNil(config.config.wallets_ETH_zeroConfLimit) && config.config.wallets_ETH_zeroConfLimit !== 0) { - newConfig[`wallets_ETH_zeroConfLimit`] = 0 + if (!_.isNil(config.wallets_ETH_zeroConfLimit) && config.wallets_ETH_zeroConfLimit !== 0) { + const newConfig = { wallets_ETH_zeroConfLimit: 0 } return saveConfig(newConfig) } }) diff --git a/migrations/migrate-tools.js b/migrations/migrate-tools.js index 06f5c463..0aa1f62c 100644 --- a/migrations/migrate-tools.js +++ b/migrations/migrate-tools.js @@ -9,8 +9,8 @@ module.exports = {migrateNames} function migrateNames () { const cs = new pgp.helpers.ColumnSet(['?device_id', 'name'], {table: 'devices'}) - return settingsLoader.loadLatest(false) - .then(r => machineLoader.getMachineNames(r.config)) + return settingsLoader.loadLatestConfig(false) + .then(config => machineLoader.getMachineNames(config)) .then(_.map(r => ({device_id: r.deviceId, name: r.name}))) .then(data => pgp.helpers.update(data, cs) + ' WHERE t.device_id=v.device_id') }