refactor: use loadLatestConfig() in place of loadLatest() where applicable

This commit is contained in:
siiky 2024-09-17 15:38:35 +01:00
parent 5342e9a8be
commit cac88fda45
15 changed files with 52 additions and 56 deletions

View file

@ -240,6 +240,7 @@ module.exports = {
loadRecentConfig, loadRecentConfig,
load, load,
loadLatest, loadLatest,
loadLatestConfig,
save, save,
loadFixture, loadFixture,
mergeValues, mergeValues,

View file

@ -36,7 +36,7 @@ function post (machineTx, pi) {
let addressReuse = false let addressReuse = false
let walletScore = {} let walletScore = {}
const promises = [settingsLoader.loadLatest()] const promises = [settingsLoader.loadLatestConfig()]
const isFirstPost = !r.tx.fiat || r.tx.fiat.isZero() const isFirstPost = !r.tx.fiat || r.tx.fiat.isZero()
if (isFirstPost) { if (isFirstPost) {
@ -44,7 +44,7 @@ function post (machineTx, pi) {
} }
return Promise.all(promises) 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 const rejectAddressReuse = configManager.getCompliance(config).rejectAddressReuse
walletScore = fetchedWalletScore walletScore = fetchedWalletScore

View file

@ -130,8 +130,8 @@ function checkStuckScreen (deviceEvents, machine) {
} }
function transactionNotify (tx, rec) { function transactionNotify (tx, rec) {
return settingsLoader.loadLatest().then(settings => { return settingsLoader.loadLatestConfig().then(config => {
const notifSettings = configManager.getGlobalNotifications(settings.config) const notifSettings = configManager.getGlobalNotifications(config)
const highValueTx = tx.fiat.gt(notifSettings.highValueTransaction || Infinity) const highValueTx = tx.fiat.gt(notifSettings.highValueTransaction || Infinity)
const isCashOut = tx.direction === 'cashOut' 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 // 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 zeroConfLimit = walletSettings.zeroConfLimit || 0
const zeroConf = isCashOut && tx.fiat.lte(zeroConfLimit) const zeroConf = isCashOut && tx.fiat.lte(zeroConfLimit)
const notificationsEnabled = notifSettings.sms.transactions || notifSettings.email.transactions 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 // for notification center, check if type of notification is active before calling the respective notify function
const notifyIfActive = (type, fnName, ...args) => { const notifyIfActive = (type, fnName, ...args) => {
return settingsLoader.loadLatest().then(settings => { return settingsLoader.loadLatestConfig().then(config => {
const notificationSettings = configManager.getGlobalNotifications(settings.config).notificationCenter const notificationSettings = configManager.getGlobalNotifications(config).notificationCenter
if (!notificationCenter[fnName]) return Promise.reject(new Error(`Notification function ${fnName} for type ${type} does not exist`)) 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() if (!(notificationSettings.active && notificationSettings[type])) return Promise.resolve()
return notificationCenter[fnName](...args) return notificationCenter[fnName](...args)

View file

@ -5,9 +5,9 @@ const configManager = require('../lib/new-config-manager')
exports.up = function (next) { exports.up = function (next) {
return db.tx(async t => { return db.tx(async t => {
const settingsPromise = settingsLoader.loadLatest() const settingsPromise = settingsLoader.loadLatestConfig()
const machinesPromise = t.any('SELECT device_id FROM devices') 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 cryptoCodes = configManager.getCryptosFromWalletNamespace(config)
const deviceIds = _.map(_.get('device_id'))(machines) const deviceIds = _.map(_.get('device_id'))(machines)

View file

@ -3,7 +3,7 @@ const settingsLoader = require('../lib/new-settings-loader')
const configManager = require('../lib/new-config-manager') const configManager = require('../lib/new-config-manager')
exports.up = async function (next) { exports.up = async function (next) {
const { config } = await settingsLoader.loadLatest() const config = await settingsLoader.loadLatestConfig()
const cryptoCodes = configManager.getCryptosFromWalletNamespace(config) const cryptoCodes = configManager.getCryptosFromWalletNamespace(config)
_.forEach(cryptoCode => { _.forEach(cryptoCode => {
const key = `wallets_${cryptoCode}_zeroConf` const key = `wallets_${cryptoCode}_zeroConf`

View file

@ -1,10 +1,10 @@
const _ = require('lodash/fp') 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 const CASSETTE_MAX_CAPACITY = 500
exports.up = function (next) { exports.up = function (next) {
return loadLatest() return loadLatestConfig()
.then(({ config }) => { .then(config => {
const fiatBalance1 = config.notifications_fiatBalanceCassette1 const fiatBalance1 = config.notifications_fiatBalanceCassette1
const fiatBalance2 = config.notifications_fiatBalanceCassette2 const fiatBalance2 = config.notifications_fiatBalanceCassette2
const fiatBalance3 = config.notifications_fiatBalanceCassette3 const fiatBalance3 = config.notifications_fiatBalanceCassette3

View file

@ -2,8 +2,8 @@ const _ = require('lodash/fp')
const settingsLoader = require('../lib/new-settings-loader') const settingsLoader = require('../lib/new-settings-loader')
exports.up = function (next) { exports.up = function (next) {
settingsLoader.loadLatest() settingsLoader.loadLatestConfig()
.then(({ config }) => { .then(config => {
if (!_.isEmpty(config)) if (!_.isEmpty(config))
config.locale_timezone = '0:0' config.locale_timezone = '0:0'
return settingsLoader.migrationSaveConfig(config) return settingsLoader.migrationSaveConfig(config)

View file

@ -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 { getCryptosFromWalletNamespace } = require('../lib/new-config-manager.js')
const { utils: coinUtils } = require('@lamassu/coins') const { utils: coinUtils } = require('@lamassu/coins')
const _ = require('lodash/fp') const _ = require('lodash/fp')
exports.up = function (next) { exports.up = function (next) {
loadLatest() loadLatestConfig()
.then(settings => { .then(config => {
const newSettings = {} const newSettings = {}
const activeCryptos = getCryptosFromWalletNamespace(settings.config) const activeCryptos = getCryptosFromWalletNamespace(config)
if (!activeCryptos.length) return Promise.resolve() if (!activeCryptos.length) return Promise.resolve()
_.map(crypto => { _.map(crypto => {
const defaultUnit = _.head(_.keys(coinUtils.getCryptoCurrency(crypto).units)) const defaultUnit = _.head(_.keys(coinUtils.getCryptoCurrency(crypto).units))

View file

@ -1,6 +1,6 @@
var db = require('./db') var db = require('./db')
const _ = require('lodash/fp') 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') const { getMachineIds } = require('../lib/machine-loader')
exports.up = function (next) { exports.up = function (next) {
@ -25,16 +25,16 @@ exports.up = function (next) {
ADD COLUMN denomination_4 INTEGER` ADD COLUMN denomination_4 INTEGER`
] ]
return Promise.all([loadLatest(), getMachineIds()]) return Promise.all([loadLatestConfig(), getMachineIds()])
.then(([config, machineIds]) => { .then(([config, machineIds]) => {
const newConfig = _.reduce((acc, value) => { const newConfig = _.reduce((acc, value) => {
const deviceId = value.device_id const deviceId = value.device_id
if (_.includes(`cashOut_${deviceId}_top`, _.keys(config.config))) { if (_.includes(`cashOut_${deviceId}_top`, _.keys(config))) {
acc[`cashOut_${deviceId}_cassette1`] = config.config[`cashOut_${deviceId}_top`] acc[`cashOut_${deviceId}_cassette1`] = config[`cashOut_${deviceId}_top`]
} }
if (_.includes(`cashOut_${deviceId}_bottom`, _.keys(config.config))) { if (_.includes(`cashOut_${deviceId}_bottom`, _.keys(config))) {
acc[`cashOut_${deviceId}_cassette2`] = config.config[`cashOut_${deviceId}_bottom`] acc[`cashOut_${deviceId}_cassette2`] = config[`cashOut_${deviceId}_bottom`]
} }
return acc return acc

View file

@ -1,16 +1,14 @@
const uuid = require('uuid') const uuid = require('uuid')
const { saveConfig, loadLatest } = require('../lib/new-settings-loader') const { saveConfig } = require('../lib/new-settings-loader')
exports.up = function (next) { exports.up = function (next) {
const newConfig = {} const newConfig = {
return loadLatest() wallets_advanced_feeMultiplier: '1',
.then(config => { wallets_advanced_cryptoUnits: 'full',
newConfig[`wallets_advanced_feeMultiplier`] = '1' wallets_advanced_allowTransactionBatching: false,
newConfig[`wallets_advanced_cryptoUnits`] = 'full' wallets_advanced_id: uuid.v4(),
newConfig[`wallets_advanced_allowTransactionBatching`] = false }
newConfig[`wallets_advanced_id`] = uuid.v4() return saveConfig(newConfig)
return saveConfig(newConfig)
})
.then(next) .then(next)
.catch(err => { .catch(err => {
return next(err) return next(err)

View file

@ -1,12 +1,11 @@
const _ = require('lodash/fp') const _ = require('lodash/fp')
const { saveConfig, loadLatest } = require('../lib/new-settings-loader') const { saveConfig, loadLatestConfig } = require('../lib/new-settings-loader')
exports.up = function (next) { exports.up = function (next) {
const newConfig = {} return loadLatestConfig()
return loadLatest()
.then(config => { .then(config => {
if (!_.isNil(config.config.locale_timezone)) return if (!_.isNil(config.locale_timezone)) return
newConfig[`locale_timezone`] = 'GMT' const newConfig = { locale_timezone: 'GMT' }
return saveConfig(newConfig) return saveConfig(newConfig)
}) })
.then(next) .then(next)

View file

@ -1,11 +1,10 @@
const { saveConfig, loadLatest } = require('../lib/new-settings-loader') const { saveConfig, loadLatestConfig } = require('../lib/new-settings-loader')
exports.up = function (next) { exports.up = function (next) {
const newConfig = {} return loadLatestConfig()
return loadLatest()
.then(config => { .then(config => {
if (config.config.locale_timezone === "0:0") { if (config.locale_timezone === "0:0") {
newConfig[`locale_timezone`] = 'GMT' const newConfig = { locale_timezone: 'GMT' }
return saveConfig(newConfig) return saveConfig(newConfig)
} }
}) })

View file

@ -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 { getCryptosFromWalletNamespace } = require('../lib/new-config-manager.js')
const _ = require('lodash/fp') const _ = require('lodash/fp')
exports.up = function (next) { exports.up = function (next) {
loadLatest() loadLatestConfig()
.then(settings => { .then(config => {
const configuredCryptos = getCryptosFromWalletNamespace(settings.config) const configuredCryptos = getCryptosFromWalletNamespace(config)
if (!configuredCryptos.length) return Promise.resolve() if (!configuredCryptos.length) return Promise.resolve()
return removeFromConfig(_.map(it => `wallets_${it}_cryptoUnits`, configuredCryptos)) return removeFromConfig(_.map(it => `wallets_${it}_cryptoUnits`, configuredCryptos))

View file

@ -1,13 +1,12 @@
const _ = require('lodash/fp') const _ = require('lodash/fp')
const { saveConfig, loadLatest } = require('../lib/new-settings-loader') const { saveConfig, loadLatestConfig } = require('../lib/new-settings-loader')
exports.up = function (next) { exports.up = function (next) {
const newConfig = {} return loadLatestConfig()
return loadLatest()
.then(config => { .then(config => {
if (!_.isNil(config.config.wallets_ETH_zeroConfLimit) && config.config.wallets_ETH_zeroConfLimit !== 0) { if (!_.isNil(config.wallets_ETH_zeroConfLimit) && config.wallets_ETH_zeroConfLimit !== 0) {
newConfig[`wallets_ETH_zeroConfLimit`] = 0 const newConfig = { wallets_ETH_zeroConfLimit: 0 }
return saveConfig(newConfig) return saveConfig(newConfig)
} }
}) })

View file

@ -9,8 +9,8 @@ module.exports = {migrateNames}
function migrateNames () { function migrateNames () {
const cs = new pgp.helpers.ColumnSet(['?device_id', 'name'], {table: 'devices'}) const cs = new pgp.helpers.ColumnSet(['?device_id', 'name'], {table: 'devices'})
return settingsLoader.loadLatest(false) return settingsLoader.loadLatestConfig(false)
.then(r => machineLoader.getMachineNames(r.config)) .then(config => machineLoader.getMachineNames(config))
.then(_.map(r => ({device_id: r.deviceId, name: r.name}))) .then(_.map(r => ({device_id: r.deviceId, name: r.name})))
.then(data => pgp.helpers.update(data, cs) + ' WHERE t.device_id=v.device_id') .then(data => pgp.helpers.update(data, cs) + ' WHERE t.device_id=v.device_id')
} }