Merge pull request #1721 from siiky/refactor/lam-1163/avoid-unnecessary-version-bumps
LAM-1163 Avoid unnecessary version bumps in l-s
This commit is contained in:
commit
f5dd813464
27 changed files with 141 additions and 272 deletions
|
|
@ -92,7 +92,7 @@ function loadLatestConfig (filterSchemaVersion = true) {
|
|||
order by id desc
|
||||
limit 1`
|
||||
|
||||
return db.one(sql, ['config', configValidate.SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
return db.oneOrNone(sql, ['config', configValidate.SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row.data.config)
|
||||
.then(configValidate.validate)
|
||||
.catch(err => {
|
||||
|
|
@ -240,6 +240,7 @@ module.exports = {
|
|||
loadRecentConfig,
|
||||
load,
|
||||
loadLatest,
|
||||
loadLatestConfig,
|
||||
save,
|
||||
loadFixture,
|
||||
mergeValues,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -474,8 +474,4 @@ function migrate (config, accounts) {
|
|||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
migrateConfig,
|
||||
migrateAccounts,
|
||||
migrate
|
||||
}
|
||||
module.exports = { migrate }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ const nmd = require('nano-markdown')
|
|||
|
||||
const plugins = require('../plugins')
|
||||
const configManager = require('../new-config-manager')
|
||||
const settingsLoader = require('../new-settings-loader')
|
||||
const { batchGetCustomInfoRequest, getCustomInfoRequests } = require('../new-admin/services/customInfoRequests')
|
||||
const state = require('../middlewares/state')
|
||||
const { getMachine } = require('../machine-loader')
|
||||
|
|
@ -323,8 +324,7 @@ const terms = (parent, { currentConfigVersion, currentHash }, { deviceId, settin
|
|||
const isHashNew = hash !== currentHash
|
||||
const text = isHashNew ? latestTerms.text : null
|
||||
|
||||
return plugins(settings, deviceId)
|
||||
.fetchCurrentConfigVersion()
|
||||
return settingsLoader.fetchCurrentConfigVersion()
|
||||
.catch(() => null)
|
||||
.then(configVersion => isHashNew || _.isNil(currentConfigVersion) || currentConfigVersion < configVersion)
|
||||
.then(isVersionNew => isVersionNew ? _.omit(['text'], latestTerms) : null)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ type OperatorInfo {
|
|||
}
|
||||
|
||||
type MachineInfo {
|
||||
deviceId: String!
|
||||
deviceId: String! @deprecated(reason: "unused by the machine")
|
||||
deviceName: String
|
||||
numberOfCassettes: Int
|
||||
numberOfRecyclers: Int
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ const pairing = require('./pairing')
|
|||
const { checkPings, checkStuckScreen } = require('./notifier')
|
||||
const dbm = require('./postgresql_interface')
|
||||
const configManager = require('./new-config-manager')
|
||||
const settingsLoader = require('./new-settings-loader')
|
||||
const notifierUtils = require('./notifier/utils')
|
||||
const notifierQueries = require('./notifier/queries')
|
||||
const { ApolloError } = require('apollo-server-errors');
|
||||
|
|
@ -94,9 +93,7 @@ function getUnpairedMachines () {
|
|||
}
|
||||
|
||||
function getConfig (defaultConfig) {
|
||||
if (defaultConfig) return Promise.resolve(defaultConfig)
|
||||
|
||||
return settingsLoader.loadLatest().config
|
||||
return defaultConfig ? Promise.resolve(defaultConfig) : loadLatestConfig()
|
||||
}
|
||||
|
||||
const getStatus = (ping, stuck) => {
|
||||
|
|
@ -529,7 +526,6 @@ module.exports = {
|
|||
updateNetworkHeartbeat,
|
||||
getNetworkPerformance,
|
||||
getNetworkHeartbeat,
|
||||
getConfig,
|
||||
getMachineIds,
|
||||
emptyMachineUnits,
|
||||
refillMachineUnits,
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ const resolvers = {
|
|||
},
|
||||
Mutation: {
|
||||
saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts),
|
||||
// resetAccounts: (...[, { schemaVersion }]) => settingsLoader.resetAccounts(schemaVersion),
|
||||
saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config),
|
||||
// resetConfig: (...[, { schemaVersion }]) => settingsLoader.resetConfig(schemaVersion),
|
||||
// migrateConfigAndAccounts: () => settingsLoader.migrate()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@ const typeDef = gql`
|
|||
|
||||
type Mutation {
|
||||
saveAccounts(accounts: JSONObject): JSONObject @auth
|
||||
# resetAccounts(schemaVersion: Int): JSONObject @auth
|
||||
saveConfig(config: JSONObject): JSONObject @auth
|
||||
# resetConfig(schemaVersion: Int): JSONObject @auth
|
||||
# migrateConfigAndAccounts: JSONObject @auth
|
||||
}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -56,10 +56,17 @@ const addTermsHash = configs => {
|
|||
)(terms)
|
||||
}
|
||||
|
||||
const accountsSql = `update user_config set data = $2, valid = $3, schema_version = $4 where type = $1;
|
||||
insert into user_config (type, data, valid, schema_version)
|
||||
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
||||
const notifyReload = (dbOrTx, operatorId) =>
|
||||
dbOrTx.none(
|
||||
'NOTIFY $1:name, $2',
|
||||
['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })]
|
||||
)
|
||||
|
||||
function saveAccounts (accounts) {
|
||||
const accountsSql = `UPDATE user_config SET data = $1, valid = TRUE, schema_version = $2 WHERE type = 'accounts';
|
||||
INSERT INTO user_config (type, data, valid, schema_version)
|
||||
SELECT 'accounts', $1, TRUE, $2 WHERE 'accounts' NOT IN (SELECT type FROM user_config)`
|
||||
|
||||
return Promise.all([loadAccounts(), getOperatorId('middleware')])
|
||||
.then(([currentAccounts, operatorId]) => {
|
||||
const newAccounts = _.merge(currentAccounts, accounts)
|
||||
|
|
@ -73,32 +80,21 @@ function saveAccounts (accounts) {
|
|||
newAccounts.elliptic.enabled = false
|
||||
}
|
||||
|
||||
return db.tx(t => {
|
||||
return t.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(() => t.none('NOTIFY $1:name, $2', ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })]))
|
||||
}).catch(console.error)
|
||||
return db.tx(t =>
|
||||
t.none(accountsSql, [{ accounts: newAccounts }, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(() => notifyReload(t, operatorId))
|
||||
).catch(console.error)
|
||||
})
|
||||
}
|
||||
function resetAccounts (schemaVersion) {
|
||||
return db.none(
|
||||
accountsSql,
|
||||
[
|
||||
'accounts',
|
||||
{ accounts: NEW_SETTINGS_LOADER_SCHEMA_VERSION ? {} : [] },
|
||||
true,
|
||||
schemaVersion
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
function loadAccounts (schemaVersion) {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
and valid
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE type = $1
|
||||
AND schema_version = $2
|
||||
AND valid
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.oneOrNone(sql, ['accounts', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(_.compose(_.defaultTo({}), _.get('data.accounts')))
|
||||
|
|
@ -116,15 +112,20 @@ function showAccounts (schemaVersion) {
|
|||
})
|
||||
}
|
||||
|
||||
const configSql = 'insert into user_config (type, data, valid, schema_version) values ($1, $2, $3, $4)'
|
||||
const insertConfigRow = (dbOrTx, data) =>
|
||||
dbOrTx.none(
|
||||
"INSERT INTO user_config (type, data, valid, schema_version) VALUES ('config', $1, TRUE, $2)",
|
||||
[data, NEW_SETTINGS_LOADER_SCHEMA_VERSION]
|
||||
)
|
||||
|
||||
function saveConfig (config) {
|
||||
return Promise.all([loadLatestConfigOrNone(), getOperatorId('middleware')])
|
||||
.then(([currentConfig, operatorId]) => {
|
||||
const newConfig = addTermsHash(_.assign(currentConfig, config))
|
||||
return db.tx(t => {
|
||||
return t.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(() => t.none('NOTIFY $1:name, $2', ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })]))
|
||||
}).catch(console.error)
|
||||
return db.tx(t =>
|
||||
insertConfigRow(t, { config: newConfig })
|
||||
.then(() => notifyReload(t, operatorId))
|
||||
).catch(console.error)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -132,10 +133,10 @@ function removeFromConfig (fields) {
|
|||
return Promise.all([loadLatestConfigOrNone(), getOperatorId('middleware')])
|
||||
.then(([currentConfig, operatorId]) => {
|
||||
const newConfig = _.omit(fields, currentConfig)
|
||||
return db.tx(t => {
|
||||
return t.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(() => t.none('NOTIFY $1:name, $2', ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })]))
|
||||
}).catch(console.error)
|
||||
return db.tx(t =>
|
||||
insertConfigRow(t, { config: newConfig })
|
||||
.then(() => notifyReload(t, operatorId))
|
||||
).catch(console.error)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -143,23 +144,11 @@ function migrationSaveConfig (config) {
|
|||
return loadLatestConfigOrNone()
|
||||
.then(currentConfig => {
|
||||
const newConfig = _.assign(currentConfig, config)
|
||||
return db.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
return insertConfigRow(db, { config: newConfig })
|
||||
.catch(console.error)
|
||||
})
|
||||
}
|
||||
|
||||
function resetConfig (schemaVersion) {
|
||||
return db.none(
|
||||
configSql,
|
||||
[
|
||||
'config',
|
||||
{ config: schemaVersion === NEW_SETTINGS_LOADER_SCHEMA_VERSION ? {} : [] },
|
||||
true,
|
||||
schemaVersion
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
function loadLatest (schemaVersion) {
|
||||
return Promise.all([loadLatestConfigOrNoneReturningVersion(schemaVersion), loadAccounts(schemaVersion)])
|
||||
.then(([configObj, accounts]) => ({
|
||||
|
|
@ -170,15 +159,15 @@ function loadLatest (schemaVersion) {
|
|||
}
|
||||
|
||||
function loadLatestConfig () {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
and valid
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE type = 'config'
|
||||
AND schema_version = $1
|
||||
AND valid
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.one(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
return db.oneOrNone(sql, [NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row ? row.data.config : {})
|
||||
.catch(err => {
|
||||
throw err
|
||||
|
|
@ -186,38 +175,39 @@ function loadLatestConfig () {
|
|||
}
|
||||
|
||||
function loadLatestConfigOrNoneReturningVersion (schemaVersion) {
|
||||
const sql = `select data, id
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data, id
|
||||
FROM user_config
|
||||
WHERE type = 'config'
|
||||
AND schema_version = $1
|
||||
AND valid
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
return db.oneOrNone(sql, [schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row ? { config: row.data.config, version: row.id } : {})
|
||||
}
|
||||
|
||||
function loadLatestConfigOrNone (schemaVersion) {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE type = 'config'
|
||||
AND schema_version = $1
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
return db.oneOrNone(sql, [schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row ? row.data.config : {})
|
||||
}
|
||||
|
||||
function loadConfig (versionId) {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where id=$1
|
||||
and type=$2
|
||||
and schema_version=$3
|
||||
and valid`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE id = $1
|
||||
AND type = 'config'
|
||||
AND schema_version = $2
|
||||
AND valid`
|
||||
|
||||
return db.one(sql, [versionId, 'config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
return db.one(sql, [versionId, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row.data.config)
|
||||
.catch(err => {
|
||||
if (err.name === 'QueryResultError') {
|
||||
|
|
@ -238,29 +228,25 @@ function load (versionId) {
|
|||
}))
|
||||
}
|
||||
|
||||
function migrate () {
|
||||
return loadLatest(OLD_SETTINGS_LOADER_SCHEMA_VERSION)
|
||||
.then(res => {
|
||||
const migrated = migration.migrate(res.config, res.accounts)
|
||||
saveConfig(migrated.config)
|
||||
saveAccounts(migrated.accounts)
|
||||
|
||||
return migrated
|
||||
})
|
||||
const fetchCurrentConfigVersion = () => {
|
||||
const sql = `SELECT id FROM user_config
|
||||
WHERE type = 'config'
|
||||
AND valid
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
return db.one(sql).then(row => row.id)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
saveConfig,
|
||||
migrationSaveConfig,
|
||||
resetConfig,
|
||||
saveAccounts,
|
||||
resetAccounts,
|
||||
loadAccounts,
|
||||
showAccounts,
|
||||
loadLatest,
|
||||
loadLatestConfig,
|
||||
loadLatestConfigOrNone,
|
||||
load,
|
||||
migrate,
|
||||
removeFromConfig
|
||||
removeFromConfig,
|
||||
fetchCurrentConfigVersion,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ const logger = require('./logger')
|
|||
const logs = require('./logs')
|
||||
const T = require('./time')
|
||||
const configManager = require('./new-config-manager')
|
||||
const settingsLoader = require('./new-settings-loader')
|
||||
const ticker = require('./ticker')
|
||||
const wallet = require('./wallet')
|
||||
const walletScoring = require('./wallet-scoring')
|
||||
|
|
@ -237,17 +238,6 @@ function plugins (settings, deviceId) {
|
|||
.then(([cassettes, recyclers]) => ({ cassettes: cassettes.cassettes, recyclers: recyclers.recyclers }))
|
||||
}
|
||||
|
||||
function fetchCurrentConfigVersion () {
|
||||
const sql = `select id from user_config
|
||||
where type=$1
|
||||
and valid
|
||||
order by id desc
|
||||
limit 1`
|
||||
|
||||
return db.one(sql, ['config'])
|
||||
.then(row => row.id)
|
||||
}
|
||||
|
||||
function mapCoinSettings (coinParams) {
|
||||
const [ cryptoCode, cryptoNetwork ] = coinParams
|
||||
const commissions = configManager.getCommissions(cryptoCode, deviceId, settings.config)
|
||||
|
|
@ -289,7 +279,7 @@ function plugins (settings, deviceId) {
|
|||
return Promise.all([
|
||||
buildAvailableCassettes(),
|
||||
buildAvailableRecyclers(),
|
||||
fetchCurrentConfigVersion(),
|
||||
settingsLoader.fetchCurrentConfigVersion(),
|
||||
millisecondsToMinutes(getTimezoneOffset(localeConfig.timezone)),
|
||||
loyalty.getNumberOfAvailablePromoCodes(),
|
||||
Promise.all(supportsBatchingPromise),
|
||||
|
|
@ -1032,7 +1022,6 @@ function plugins (settings, deviceId) {
|
|||
sell,
|
||||
getNotificationConfig,
|
||||
notifyOperator,
|
||||
fetchCurrentConfigVersion,
|
||||
pruneMachinesHeartbeat,
|
||||
rateAddress,
|
||||
isWalletScoringEnabled,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const nmd = require('nano-markdown')
|
|||
const router = express.Router()
|
||||
|
||||
const configManager = require('../new-config-manager')
|
||||
const plugins = require('../plugins')
|
||||
const settingsLoader = require('../new-settings-loader')
|
||||
|
||||
const createTerms = terms => (terms.active && terms.text) ? ({
|
||||
delay: terms.delay,
|
||||
|
|
@ -18,15 +18,10 @@ const createTerms = terms => (terms.active && terms.text) ? ({
|
|||
|
||||
function getTermsConditions (req, res, next) {
|
||||
const deviceId = req.deviceId
|
||||
const settings = req.settings
|
||||
|
||||
const terms = configManager.getTermsConditions(settings.config)
|
||||
|
||||
const pi = plugins(settings, deviceId)
|
||||
|
||||
return pi.fetchCurrentConfigVersion().then(version => {
|
||||
return res.json({ terms: createTerms(terms), version })
|
||||
})
|
||||
const { config } = req.settings
|
||||
const terms = configManager.getTermsConditions(config)
|
||||
return settingsLoader.fetchCurrentConfigVersion()
|
||||
.then(version => res.json({ terms: createTerms(terms), version }))
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
const db = require('./db')
|
||||
const { migrationSaveConfig, loadLatest } = require('../lib/new-settings-loader')
|
||||
const { migrationSaveConfig } = require('../lib/new-settings-loader')
|
||||
|
||||
exports.up = function (next) {
|
||||
const sql = [
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,82 +0,0 @@
|
|||
import { useMutation } from '@apollo/react-hooks'
|
||||
import { Box } from '@material-ui/core'
|
||||
import { makeStyles } from '@material-ui/core/styles'
|
||||
import gql from 'graphql-tag'
|
||||
import React, { useState } from 'react'
|
||||
|
||||
import Title from 'src/components/Title'
|
||||
import { Button } from 'src/components/buttons'
|
||||
|
||||
const styles = {
|
||||
button: {
|
||||
marginBottom: 10
|
||||
}
|
||||
}
|
||||
const useStyles = makeStyles(styles)
|
||||
|
||||
const RESET = gql`
|
||||
mutation Reset($schemaVersion: Int) {
|
||||
resetConfig(schemaVersion: $schemaVersion)
|
||||
resetAccounts(schemaVersion: $schemaVersion)
|
||||
}
|
||||
`
|
||||
|
||||
const MIGRATE = gql`
|
||||
mutation Migrate {
|
||||
migrateConfigAndAccounts
|
||||
}
|
||||
`
|
||||
|
||||
const OLD_SCHEMA_VERSION = 1
|
||||
const NEW_SCHEMA_VERSION = 2
|
||||
|
||||
const ConfigMigration = () => {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [reset] = useMutation(RESET, {
|
||||
onCompleted: () => setLoading(false)
|
||||
})
|
||||
|
||||
const [migrate] = useMutation(MIGRATE, {
|
||||
onCompleted: () => setLoading(false)
|
||||
})
|
||||
|
||||
const classes = useStyles()
|
||||
|
||||
const innerReset = schemaVersion => {
|
||||
setLoading(true)
|
||||
reset({ variables: { schemaVersion } })
|
||||
}
|
||||
|
||||
const innerMigrate = () => {
|
||||
setLoading(true)
|
||||
migrate()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Title>Config Migration</Title>
|
||||
<Box display="flex" alignItems="center" flexDirection="column">
|
||||
<Button
|
||||
className={classes.button}
|
||||
disabled={loading}
|
||||
onClick={() => innerReset(OLD_SCHEMA_VERSION)}>
|
||||
Reset old admin
|
||||
</Button>
|
||||
<Button
|
||||
className={classes.button}
|
||||
disabled={loading}
|
||||
onClick={() => innerReset(NEW_SCHEMA_VERSION)}>
|
||||
Reset new admin
|
||||
</Button>
|
||||
<Button
|
||||
className={classes.button}
|
||||
disabled={loading}
|
||||
onClick={() => innerMigrate()}>
|
||||
Migrate
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default ConfigMigration
|
||||
|
|
@ -143,7 +143,6 @@ const Routes = () => {
|
|||
<PrivateRoute path="/machines" component={Machines} />
|
||||
<PrivateRoute path="/wizard" component={Wizard} />
|
||||
<PublicRoute path="/register" component={Register} />
|
||||
{/* <PublicRoute path="/configmigration" component={ConfigMigration} /> */}
|
||||
<PublicRoute path="/login" restricted component={Login} />
|
||||
<PublicRoute path="/resetpassword" component={ResetPassword} />
|
||||
<PublicRoute path="/reset2fa" component={Reset2FA} />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue