works with l-m again
This commit is contained in:
parent
5d6cc78b37
commit
03edd9c7e0
5 changed files with 62 additions and 51 deletions
|
|
@ -1,18 +1,4 @@
|
|||
[
|
||||
{
|
||||
"code": "cryptos",
|
||||
"display": "Supported cryptocurrencies",
|
||||
"cryptoScope": "global",
|
||||
"machineScope": "both",
|
||||
"entries": [
|
||||
{
|
||||
"code": "cryptos",
|
||||
"display": "Cryptocurrencies",
|
||||
"fieldType": "crypto",
|
||||
"fieldClass": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"code": "commissions",
|
||||
"display": "Commissions",
|
||||
|
|
@ -72,11 +58,17 @@
|
|||
]
|
||||
},
|
||||
{
|
||||
"code": "fiat",
|
||||
"display": "Fiat",
|
||||
"code": "currencies",
|
||||
"display": "Currencies",
|
||||
"cryptoScope": "global",
|
||||
"machineScope": "both",
|
||||
"entries": [
|
||||
{
|
||||
"code": "cryptoCurrencies",
|
||||
"display": "Crypto Currencies",
|
||||
"fieldType": "cryptoCurrency",
|
||||
"fieldClass": null
|
||||
},
|
||||
{
|
||||
"code": "fiatCurrency",
|
||||
"display": "Fiat Currency",
|
||||
|
|
@ -132,7 +124,7 @@
|
|||
{
|
||||
"code": "idVerificationEnabled",
|
||||
"display": "ID verification",
|
||||
"fieldType": "bool",
|
||||
"fieldType": "onOff",
|
||||
"fieldClass": null
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -52,10 +52,7 @@ function permutations (crypto, machine) {
|
|||
|
||||
function fallbackValue (crypto, machine, instances) {
|
||||
const notNil = R.pipe(R.isNil, R.not)
|
||||
console.log('DEBUG10: %j', instances)
|
||||
const pickValue = arr => R.find(instance => matchesValue(arr[0], arr[1], instance), instances)
|
||||
console.log('DEBUG11: %j', permutations(crypto, machine))
|
||||
console.log('DEBUG14: %j', R.map(pickValue, permutations(crypto, machine)))
|
||||
const fallbackRec = R.find(notNil, R.map(pickValue, permutations(crypto, machine)))
|
||||
return fallbackRec && fallbackRec.fieldValue.value
|
||||
}
|
||||
|
|
@ -69,7 +66,6 @@ function generalScoped (crypto, machine, config) {
|
|||
|
||||
const scopedGroups = group => {
|
||||
const instances = group.values
|
||||
console.log('DEBUG66: %j', keys(instances))
|
||||
return [group.code, R.fromPairs(keys(instances).map(key => scopedValue(key, instances)))]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -297,9 +297,9 @@ function buildCartridges (cartridges, virtualCartridges, rec) {
|
|||
|
||||
exports.pollQueries = function pollQueries (deviceId) {
|
||||
const config = getConfig(deviceId)
|
||||
const cartridges = [ config.fiat.topCashOutDenomination,
|
||||
config.fiat.bottomCashOutDenomination ]
|
||||
const virtualCartridges = [config.fiat.virtualCashOutDenomination]
|
||||
const cartridges = [ config.currencies.topCashOutDenomination,
|
||||
config.currencies.bottomCashOutDenomination ]
|
||||
const virtualCartridges = [config.currencies.virtualCashOutDenomination]
|
||||
|
||||
return db.cartridgeCounts(deviceId)
|
||||
.then(result => ({
|
||||
|
|
@ -426,8 +426,8 @@ exports.cashOut = function cashOut (deviceId, tx) {
|
|||
exports.dispenseAck = function (deviceId, tx) {
|
||||
console.log('DEBUG23: %j', tx)
|
||||
const config = getConfig(deviceId)
|
||||
const cartridges = [ config.fiat.topCashOutDenomination,
|
||||
config.fiat.bottomCashOutDenomination ]
|
||||
const cartridges = [ config.currencies.topCashOutDenomination,
|
||||
config.currencies.bottomCashOutDenomination ]
|
||||
|
||||
return db.addDispense(deviceId, tx, cartridges)
|
||||
}
|
||||
|
|
@ -707,12 +707,6 @@ exports.verifyTx = function verifyTx (data, cb) {
|
|||
idVerifierPlugin.verifyTransaction(data, cb)
|
||||
}
|
||||
|
||||
function getCryptoCodes () {
|
||||
console.log('DEBUG17 TODO: generalize')
|
||||
return ['BTC']
|
||||
}
|
||||
exports.getCryptoCodes = getCryptoCodes
|
||||
|
||||
function sendMessage (rec) {
|
||||
const pluginPromises = []
|
||||
const config = configManager.unscoped(cachedConfig)
|
||||
|
|
@ -786,16 +780,30 @@ function checkNotification () {
|
|||
})
|
||||
}
|
||||
|
||||
function checkBalances () {
|
||||
const cryptoCodes = exports.getCryptoCodes()
|
||||
function getCryptoCodes (deviceId) {
|
||||
return configManager.machineScoped(deviceId, cachedConfig).currencies.cryptoCurrencies
|
||||
}
|
||||
exports.getCryptoCodes = getCryptoCodes
|
||||
|
||||
// Get union of all cryptoCodes from all machines
|
||||
function getAllCryptoCodes () {
|
||||
return db.devices()
|
||||
.then(rows => {
|
||||
return rows.reduce((acc, r) => getCryptoCodes(r.device_id).forEach(c => acc.add(c)), new Set())
|
||||
})
|
||||
}
|
||||
|
||||
function checkBalances () {
|
||||
return Promise.all(getAllCryptoCodes(), db.devices())
|
||||
.then(arr => {
|
||||
const cryptoCodes = arr[0]
|
||||
const deviceIds = arr[1].map(r => r.device_id)
|
||||
const balances = []
|
||||
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
const minBalance = rows.map(r => exports.fiatBalance(cryptoCode, r.device_id).balance)
|
||||
const minBalance = deviceIds.map(deviceId => exports.fiatBalance(cryptoCode, deviceId).balance)
|
||||
.reduce((min, cur) => Math.min(min, cur), Infinity)
|
||||
|
||||
if (!balanceRec) return
|
||||
const rec = {fiatBalance: minBalance, cryptoCode, fiatCode: deviceCurrency}
|
||||
balances.push(rec)
|
||||
})
|
||||
|
|
@ -806,9 +814,12 @@ function checkBalances () {
|
|||
|
||||
exports.startCheckingNotification = function startCheckingNotification () {
|
||||
const config = configManager.unscoped(cachedConfig)
|
||||
notifier.init(db, checkBalances, config.notifications)
|
||||
checkNotification()
|
||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
||||
return checkBalances()
|
||||
.then(balances => {
|
||||
notifier.init(db, balances, config.notifications)
|
||||
checkNotification()
|
||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
||||
})
|
||||
}
|
||||
|
||||
exports.getPhoneCode = function getPhoneCode (phone) {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ function buildRates (deviceId) {
|
|||
}
|
||||
|
||||
function buildBalances (deviceId) {
|
||||
const cryptoCodes = plugins.getCryptoCodes()
|
||||
const cryptoCodes = plugins.getCryptoCodes(deviceId)
|
||||
|
||||
const _balances = {}
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
|
|
@ -73,19 +73,30 @@ function poll (req, res) {
|
|||
|
||||
const config = plugins.getConfig(deviceId)
|
||||
|
||||
console.log('DEBUG30')
|
||||
|
||||
plugins.pollQueries(deviceId)
|
||||
.then(results => {
|
||||
console.log('DEBUG31')
|
||||
|
||||
const cartridges = results.cartridges
|
||||
|
||||
const reboot = reboots[deviceId] === pid
|
||||
const reboot = pid && reboots[deviceId] && reboots[deviceId] === pid
|
||||
console.log('DEBUG2: %j, %s, %s', reboots, reboot, pid)
|
||||
const langs = config.languages.machineLanguages
|
||||
|
||||
console.log('DEBUG33')
|
||||
|
||||
const locale = {
|
||||
currency: config.fiat.fiatCurrency,
|
||||
primaryLocale: langs[0],
|
||||
primaryLocales: langs
|
||||
currency: config.currencies.fiatCurrency,
|
||||
localeInfo: {
|
||||
primaryLocale: langs[0],
|
||||
primaryLocales: langs
|
||||
}
|
||||
}
|
||||
|
||||
console.log('DEBUG34')
|
||||
|
||||
const response = {
|
||||
err: null,
|
||||
locale,
|
||||
|
|
@ -98,16 +109,20 @@ function poll (req, res) {
|
|||
reboot,
|
||||
rates,
|
||||
balances,
|
||||
coins: config.cryptos.cryptos
|
||||
coins: config.currencies.cryptos
|
||||
}
|
||||
|
||||
console.log('DEBUG35')
|
||||
|
||||
if (response.idVerificationEnabled) {
|
||||
response.idVerificationLimit = config.compliance.idVerificationLimit
|
||||
}
|
||||
|
||||
console.log('DEBUG32')
|
||||
|
||||
res.json(response)
|
||||
})
|
||||
.catch(logger.error)
|
||||
.catch(e => { console.log(e); logger.error(e) })
|
||||
|
||||
plugins.recordPing(deviceId, deviceTime, req.query)
|
||||
.catch(logger.error)
|
||||
|
|
@ -140,8 +155,6 @@ function send (req, res) {
|
|||
|
||||
return plugins.sendCoins(getDeviceId(req), tx)
|
||||
.then(status => {
|
||||
console.log('DEBUG14: %j', status)
|
||||
|
||||
res.json({
|
||||
txHash: status && status.txHash,
|
||||
txId: status && status.txId
|
||||
|
|
|
|||
5
todo.txt
5
todo.txt
|
|
@ -99,7 +99,6 @@ options: configure per machine; configure per crypto/fiat
|
|||
|
||||
- need to rethink cachedConfig, don't use global variables [later]
|
||||
|
||||
-------------
|
||||
|
||||
- fiatBalance should really be per machine
|
||||
- cartridge counts -- where to store? already in db, not ideal but can fix later
|
||||
|
||||
- twoWayMode should be per crypto
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue