don't use cachedConfig directly
This commit is contained in:
parent
a24f8d6a5a
commit
910bdd5f69
3 changed files with 31 additions and 20 deletions
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"typescript.tsdk": "./node_modules/typescript/lib"
|
||||
}
|
||||
|
|
@ -210,7 +210,7 @@ exports.configure = function configure (config) {
|
|||
|
||||
loadOrConfigPlugin(
|
||||
walletPlugins[cryptoCode],
|
||||
'transfer',
|
||||
'wallet',
|
||||
cryptoCode,
|
||||
cryptoScopedConfig,
|
||||
accounts,
|
||||
|
|
@ -241,7 +241,7 @@ exports.configure = function configure (config) {
|
|||
|
||||
console.log('DEBUG32')
|
||||
|
||||
const unscopedCfg = config.unscoped(cachedConfig)
|
||||
const unscopedCfg = configManager.unscoped(cachedConfig)
|
||||
|
||||
// ID VERIFIER [optional] configure (or load)
|
||||
idVerifierPlugin = loadOrConfigPlugin(
|
||||
|
|
@ -271,12 +271,11 @@ exports.configure = function configure (config) {
|
|||
console.log('DEBUG33')
|
||||
}
|
||||
|
||||
exports.getConfig = function getConfig (machineId) {
|
||||
console.log('DEBUG3: %j', cachedConfig)
|
||||
console.log('DEBUG55: %j', configManager.machineScoped(machineId, cachedConfig))
|
||||
function getConfig (machineId) {
|
||||
return configManager.machineScoped(machineId, cachedConfig)
|
||||
}
|
||||
|
||||
exports.getConfig = getConfig
|
||||
exports.logEvent = db.recordDeviceEvent
|
||||
|
||||
function buildCartridges (cartridges, virtualCartridges, rec) {
|
||||
|
|
@ -297,9 +296,10 @@ function buildCartridges (cartridges, virtualCartridges, rec) {
|
|||
}
|
||||
|
||||
exports.pollQueries = function pollQueries (deviceId) {
|
||||
const cartridges = [ cachedConfig.fiat.topCashOutDenomination,
|
||||
cachedConfig.fiat.bottomCashOutDenomination ]
|
||||
const virtualCartridges = [cachedConfig.fiat.virtualCashOutDenomination]
|
||||
const config = getConfig(deviceId)
|
||||
const cartridges = [ config.fiat.topCashOutDenomination,
|
||||
config.fiat.bottomCashOutDenomination ]
|
||||
const virtualCartridges = [config.fiat.virtualCashOutDenomination]
|
||||
|
||||
return db.cartridgeCounts(deviceId)
|
||||
.then(result => ({
|
||||
|
|
@ -425,17 +425,19 @@ exports.cashOut = function cashOut (deviceId, tx) {
|
|||
|
||||
exports.dispenseAck = function (deviceId, tx) {
|
||||
console.log('DEBUG23: %j', tx)
|
||||
const cartridges = [ cachedConfig.fiat.topCashOutDenomination,
|
||||
cachedConfig.fiat.bottomCashOutDenomination ]
|
||||
const config = getConfig(deviceId)
|
||||
const cartridges = [ config.fiat.topCashOutDenomination,
|
||||
config.fiat.bottomCashOutDenomination ]
|
||||
|
||||
return db.addDispense(deviceId, tx, cartridges)
|
||||
}
|
||||
|
||||
exports.fiatBalance = function fiatBalance (cryptoCode) {
|
||||
exports.fiatBalance = function fiatBalance (cryptoCode, deviceId) {
|
||||
const config = configManager.scoped(cryptoCode, deviceId, cachedConfig)
|
||||
const deviceRate = exports.getDeviceRate(cryptoCode)
|
||||
if (!deviceRate) return null
|
||||
const rawRate = deviceRate.rates.ask
|
||||
const commission = new BigNumber(cachedConfig.commissions.cashInCommission).div(100)
|
||||
const commission = new BigNumber(config.commissions.cashInCommission).div(100)
|
||||
const lastBalanceRec = lastBalances[cryptoCode]
|
||||
if (!lastBalanceRec) return null
|
||||
const lastBalance = lastBalanceRec.balance
|
||||
|
|
@ -447,7 +449,7 @@ exports.fiatBalance = function fiatBalance (cryptoCode) {
|
|||
|
||||
// `lowBalanceMargin` is our safety net. It's a number > 1, and we divide
|
||||
// all our balances by it to provide a safety margin.
|
||||
const lowBalanceMargin = cachedConfig.commissions.lowBalanceMargin || LOW_BALANCE_MARGIN_DEFAULT
|
||||
const lowBalanceMargin = config.commissions.lowBalanceMargin || LOW_BALANCE_MARGIN_DEFAULT
|
||||
|
||||
const unitScale = new BigNumber(10).pow(coins[cryptoCode].unitScale)
|
||||
const fiatTransferBalance = lastBalance.div(unitScale).times(rate).div(lowBalanceMargin)
|
||||
|
|
@ -575,6 +577,7 @@ function pollBalance (cryptoCode, cb) {
|
|||
|
||||
function pollRate (cryptoCode, cb) {
|
||||
const tickerPlugin = tickerPlugins[cryptoCode]
|
||||
pp(tickerPlugins)
|
||||
logger.debug('[%s] polling for rates (%s)', cryptoCode, tickerPlugin.NAME)
|
||||
|
||||
let currencies = deviceCurrency
|
||||
|
|
@ -706,19 +709,23 @@ exports.verifyTx = function verifyTx (data, cb) {
|
|||
|
||||
function getCryptoCodes () {
|
||||
console.log('DEBUG17 TODO: generalize')
|
||||
return ['BTC', 'ETC']
|
||||
return ['BTC']
|
||||
}
|
||||
exports.getCryptoCodes = getCryptoCodes
|
||||
|
||||
function sendMessage (rec) {
|
||||
const pluginPromises = []
|
||||
if (!cachedConfig.notifications.notificationsEnabled) return Promise.all([])
|
||||
const config = configManager.unscoped(cachedConfig)
|
||||
console.log('DEBUG35')
|
||||
pp(config)
|
||||
|
||||
if (cachedConfig.notifications.notificationsEmailEnabled) {
|
||||
if (!config.notifications.notificationsEnabled) return Promise.all([])
|
||||
|
||||
if (config.notifications.notificationsEmailEnabled) {
|
||||
pluginPromises.push(emailPlugin.sendMessage(rec))
|
||||
}
|
||||
|
||||
if (cachedConfig.notifications.notificationsSMSEnabled) {
|
||||
if (config.notifications.notificationsSMSEnabled) {
|
||||
pluginPromises.push(smsPlugin.sendMessage(rec))
|
||||
}
|
||||
|
||||
|
|
@ -795,8 +802,8 @@ function checkBalances () {
|
|||
}
|
||||
|
||||
exports.startCheckingNotification = function startCheckingNotification () {
|
||||
const config = cachedConfig.notifications
|
||||
notifier.init(db, checkBalances, config)
|
||||
const config = configManager.unscoped(cachedConfig)
|
||||
notifier.init(db, checkBalances, config.notifications)
|
||||
checkNotification()
|
||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
||||
}
|
||||
|
|
|
|||
3
todo.txt
3
todo.txt
|
|
@ -97,4 +97,5 @@ options: configure per machine; configure per crypto/fiat
|
|||
- need to think hard about how to do required checks for scopes
|
||||
- what to do if validation fails?
|
||||
|
||||
- need to rethink cachedConfig, don't use global variables
|
||||
- need to rethink cachedConfig, don't use global variables [later]
|
||||
- add notifications to admin
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue