chore: integrate new admin with l-s
This commit is contained in:
parent
6b3db134e7
commit
bf8f1d991c
72 changed files with 1493 additions and 1611 deletions
114
lib/routes.js
114
lib/routes.js
|
|
@ -12,9 +12,11 @@ const semver = require('semver')
|
|||
const dbErrorCodes = require('./db-error-codes')
|
||||
const options = require('./options')
|
||||
const logger = require('./logger')
|
||||
const configManager = require('./config-manager')
|
||||
const configManager = require('./new-config-manager')
|
||||
const complianceTriggers = require('./compliance-triggers')
|
||||
const pairing = require('./pairing')
|
||||
const settingsLoader = require('./settings-loader')
|
||||
// TODO new-admin: remove old settings loader from here.
|
||||
const newSettingsLoader = require('./new-settings-loader')
|
||||
const plugins = require('./plugins')
|
||||
const helpers = require('./route-helpers')
|
||||
const poller = require('./poller')
|
||||
|
|
@ -44,7 +46,7 @@ const settingsCache = {}
|
|||
const devMode = argv.dev || options.http
|
||||
|
||||
function checkHasLightning (settings) {
|
||||
return configManager.cryptoScoped('BTC', settings.config).layer2 !== 'no-layer2'
|
||||
return configManager.getWalletSettings('BTC', settings.config).layer2 !== 'no-layer2'
|
||||
}
|
||||
|
||||
function poll (req, res, next) {
|
||||
|
|
@ -54,10 +56,18 @@ function poll (req, res, next) {
|
|||
const serialNumber = req.query.sn
|
||||
const pid = req.query.pid
|
||||
const settings = req.settings
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||
const pi = plugins(settings, deviceId)
|
||||
const hasLightning = checkHasLightning(settings)
|
||||
|
||||
const triggers = configManager.getTriggers(settings.config)
|
||||
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
||||
|
||||
const operatorInfo = configManager.getOperatorInfo(settings.config)
|
||||
const terms = configManager.getTermsConditions(settings.config)
|
||||
const cashOutConfig = configManager.getCashOut(deviceId, settings.config)
|
||||
const receipt = configManager.getReceipt(settings.config)
|
||||
|
||||
pids[deviceId] = { pid, ts: Date.now() }
|
||||
|
||||
return pi.pollQueries(serialNumber, deviceTime, req.query)
|
||||
|
|
@ -66,14 +76,14 @@ function poll (req, res, next) {
|
|||
|
||||
const reboot = pid && reboots[deviceId] && reboots[deviceId] === pid
|
||||
const restartServices = pid && restartServicesMap[deviceId] && restartServicesMap[deviceId] === pid
|
||||
const langs = config.machineLanguages
|
||||
const langs = localeConfig.languages
|
||||
|
||||
const locale = {
|
||||
fiatCode: config.fiatCurrency,
|
||||
fiatCode: localeConfig.fiatCurrency,
|
||||
localeInfo: {
|
||||
primaryLocale: langs[0],
|
||||
primaryLocales: langs,
|
||||
country: config.country
|
||||
country: localeConfig.country
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,47 +91,33 @@ function poll (req, res, next) {
|
|||
error: null,
|
||||
locale,
|
||||
version,
|
||||
txLimit: config.cashInTransactionLimit,
|
||||
idVerificationEnabled: config.idVerificationEnabled,
|
||||
smsVerificationActive: config.smsVerificationActive,
|
||||
smsVerificationThreshold: config.smsVerificationThreshold,
|
||||
hardLimitVerificationActive: config.hardLimitVerificationActive,
|
||||
hardLimitVerificationThreshold: config.hardLimitVerificationThreshold,
|
||||
idCardDataVerificationActive: config.idCardDataVerificationActive,
|
||||
idCardDataVerificationThreshold: config.idCardDataVerificationThreshold,
|
||||
idCardPhotoVerificationActive: config.idCardPhotoVerificationActive,
|
||||
idCardPhotoVerificationThreshold: config.idCardPhotoVerificationThreshold,
|
||||
sanctionsVerificationActive: config.sanctionsVerificationActive,
|
||||
sanctionsVerificationThreshold: config.sanctionsVerificationThreshold,
|
||||
crossRefVerificationActive: config.crossRefVerificationActive,
|
||||
crossRefVerificationThreshold: config.crossRefVerificationThreshold,
|
||||
frontCameraVerificationActive: config.frontCameraVerificationActive,
|
||||
frontCameraVerificationThreshold: config.frontCameraVerificationThreshold,
|
||||
receiptPrintingActive: config.receiptPrintingActive,
|
||||
smsVerificationActive: !!compatTriggers.sms,
|
||||
smsVerificationThreshold: compatTriggers.sms,
|
||||
hardLimitVerificationActive: !!compatTriggers.block,
|
||||
hardLimitVerificationThreshold: compatTriggers.block,
|
||||
idCardDataVerificationActive: !!compatTriggers.idData,
|
||||
idCardDataVerificationThreshold: compatTriggers.idData,
|
||||
idCardPhotoVerificationActive: !!compatTriggers.idPhoto,
|
||||
idCardPhotoVerificationThreshold: compatTriggers.idPhoto,
|
||||
sanctionsVerificationActive: !!compatTriggers.sancations,
|
||||
sanctionsVerificationThreshold: compatTriggers.sancations,
|
||||
frontCameraVerificationActive: !!compatTriggers.facephoto,
|
||||
frontCameraVerificationThreshold: compatTriggers.facephoto,
|
||||
receiptPrintingActive: receipt.active,
|
||||
cassettes,
|
||||
twoWayMode: config.cashOutEnabled,
|
||||
zeroConfLimit: config.zeroConfLimit,
|
||||
twoWayMode: cashOutConfig.active,
|
||||
zeroConfLimit: cashOutConfig.zeroConfLimit,
|
||||
reboot,
|
||||
restartServices,
|
||||
hasLightning,
|
||||
operatorInfo: {
|
||||
active: config.operatorInfoActive,
|
||||
name: config.operatorInfoName,
|
||||
phone: config.operatorInfoPhone,
|
||||
email: config.operatorInfoEmail,
|
||||
website: config.operatorInfoWebsite,
|
||||
companyNumber: config.operatorInfoCompanyNumber
|
||||
}
|
||||
receipt,
|
||||
operatorInfo
|
||||
}
|
||||
|
||||
// BACKWARDS_COMPATIBILITY 7.5
|
||||
// machines before 7.5 expect t&c on poll
|
||||
if (!machineVersion || semver.lt(machineVersion, '7.5.0-beta')) {
|
||||
response.terms = config.termsScreenActive && config.termsScreenText ? createTerms(config) : null
|
||||
}
|
||||
|
||||
if (response.idVerificationEnabled) {
|
||||
response.idVerificationLimit = config.idVerificationLimit
|
||||
response.terms = createTerms(terms)
|
||||
}
|
||||
|
||||
return res.json(_.assign(response, results))
|
||||
|
|
@ -133,13 +129,12 @@ function getTermsConditions (req, res, next) {
|
|||
const deviceId = req.deviceId
|
||||
const settings = req.settings
|
||||
|
||||
const config = configManager.unscoped(req.settings.config)
|
||||
const terms = configManager.getTermsConditions(settings.config)
|
||||
|
||||
const pi = plugins(settings, deviceId)
|
||||
|
||||
const terms = config.termsScreenActive && config.termsScreenText ? createTerms(config) : null
|
||||
|
||||
return pi.fetchCurrentConfigVersion().then(version => {
|
||||
return res.json({ terms, version })
|
||||
return res.json({ terms: createTerms(terms), version })
|
||||
})
|
||||
.catch(next)
|
||||
}
|
||||
|
|
@ -213,7 +208,8 @@ function verifyTx (req, res, next) {
|
|||
|
||||
function addOrUpdateCustomer (req) {
|
||||
const customerData = req.body
|
||||
const config = configManager.unscoped(req.settings.config)
|
||||
const triggers = configManager.getTriggers(req.settings.config)
|
||||
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
||||
|
||||
return customers.get(customerData.phone)
|
||||
.then(customer => {
|
||||
|
|
@ -222,7 +218,7 @@ function addOrUpdateCustomer (req) {
|
|||
return customers.add(req.body)
|
||||
})
|
||||
.then(customer => {
|
||||
return compliance.validationPatch(req.deviceId, config, customer)
|
||||
return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, customer)
|
||||
.then(patch => {
|
||||
if (_.isEmpty(patch)) return customer
|
||||
return customers.update(customer.id, patch)
|
||||
|
|
@ -250,14 +246,15 @@ function updateCustomer (req, res, next) {
|
|||
const id = req.params.id
|
||||
const txId = req.query.txId
|
||||
const patch = req.body
|
||||
const config = configManager.unscoped(req.settings.config)
|
||||
const triggers = configManager.getTriggers(req.settings.config)
|
||||
const compatTriggers = complianceTriggers.getBackwardsCompatibleTriggers(triggers)
|
||||
|
||||
customers.getById(id)
|
||||
.then(customer => {
|
||||
if (!customer) { throw httpError('Not Found', 404) }
|
||||
|
||||
const mergedCustomer = _.merge(customer, patch)
|
||||
return compliance.validationPatch(req.deviceId, config, mergedCustomer)
|
||||
return compliance.validationPatch(req.deviceId, !!compatTriggers.sanctions, mergedCustomer)
|
||||
.then(_.merge(patch))
|
||||
.then(newPatch => customers.updatePhotoCard(id, newPatch))
|
||||
.then(newPatch => customers.updateFrontCamera(id, newPatch))
|
||||
|
|
@ -305,8 +302,7 @@ function pair (req, res, next) {
|
|||
return pairing.pair(token, deviceId, model)
|
||||
.then(valid => {
|
||||
if (valid) {
|
||||
return helpers.updateMachineDefaults(deviceId)
|
||||
.then(() => res.json({ status: 'paired' }))
|
||||
return res.json({ status: 'paired' })
|
||||
}
|
||||
|
||||
throw httpError('Pairing failed')
|
||||
|
|
@ -457,7 +453,7 @@ localApp.post('/restartServices', (req, res) => {
|
|||
|
||||
localApp.post('/dbChange', (req, res, next) => {
|
||||
settingsCache.cache = null
|
||||
return settingsLoader.loadLatest()
|
||||
return newSettingsLoader.loadLatest()
|
||||
.then(poller.reload)
|
||||
.then(() => logger.info('Config reloaded'))
|
||||
.catch(err => {
|
||||
|
|
@ -504,7 +500,7 @@ function populateSettings (req, res, next) {
|
|||
}
|
||||
|
||||
if (!versionId && !settingsCache.cache) {
|
||||
return settingsLoader.loadLatest()
|
||||
return newSettingsLoader.loadLatest()
|
||||
.then(settings => {
|
||||
settingsCache.cache = settings
|
||||
settingsCache.timestamp = Date.now()
|
||||
|
|
@ -514,20 +510,22 @@ function populateSettings (req, res, next) {
|
|||
.catch(next)
|
||||
}
|
||||
|
||||
settingsLoader.load(versionId)
|
||||
newSettingsLoader.load(versionId)
|
||||
.then(settings => { req.settings = settings })
|
||||
.then(() => helpers.updateDeviceConfigVersion(versionId))
|
||||
.then(() => next())
|
||||
.catch(next)
|
||||
}
|
||||
|
||||
function createTerms (config) {
|
||||
function createTerms (terms) {
|
||||
if (!terms.active || !terms.text) return null
|
||||
|
||||
return {
|
||||
active: config.termsScreenActive,
|
||||
title: config.termsScreenTitle,
|
||||
text: nmd(config.termsScreenText),
|
||||
accept: config.termsAcceptButtonText,
|
||||
cancel: config.termsCancelButtonText
|
||||
active: terms.active,
|
||||
title: terms.title,
|
||||
text: nmd(terms.text),
|
||||
accept: terms.acceptButtonText,
|
||||
cancel: terms.cancelButtonText
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue