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