For now it doesn't have any functionality, CSS styling, or tables feat: added tables to the Coin ATM Radar screen No styles or icons yet. feat: added Edit links to the Coin ATM Radar Setup screen chore: added some TODOs to the Coin ATM Radar Setup screen refactor: make a function to render both Coin ATM Radar Setup tables feat: toggle function on table (not working on table content yet) feat: added toggle state to the Share Information switch feat: make the Share Information toggle change the tables contents feat: added a 'Help' link Later will be replaced by a '?' button with a pop-up help text. feat: added radio groups when in editing mode of Coin ATM Radar screen chore: replaced edit and help placeholders with proper buttons style: defined some CSS styles feat: added a help popper feat: enable radio change events, so they can be selected style: defined row styles for the radio button groups For now the help popper contains only a placeholder text, which must be replaced. refactor: replaced help and edit Links with Buttons fix: fixed the margin spacing for buttons style: added more spacing between before the share information Switch refactor: made a function to check a table element boolean value fix: changed some typography styles for titles (from TL2 to H4) style: added the alternating row style to the information tables style: added true and false table icons replacing the placeholder texts style: fixed the radio groups right margin refactor: renamed everything from CoinATMRadarSetup to CoinATMRadar feat: integrate share information switch with graphql api Still needs to finish the tables api integration. refactor: rename properties from 'show' to 'send' feat: integrate tables with graphql api feat: updated the coinatmradar module with the new config properties feat: added logic to show only currently available CAR config properties feat: disable the edit button when 'Share Information' is set to 'No' chore: replaced the lorem ipsum with the correct text on the help popup fix: fixed some css styling errors chore: added link to the CAR page on the corresponding button refactor: refactored the information table to make a component out of it refactor: changed the name of the 'active' property of the properties table to 'disabled' and inverted it's logic refactor: created a component from the boolean property table refactor: delete repeated styling code on the car page and it's table style: update styles to be in accordance with the guidelines refactor: rename properties to make them more concise fix: readded the old coinatmradar module and renamed the current one refactor: replaced ternary if with a coalescing operator fix: make the info table always visible, and it's values not dependent on the disabled status fix: move link style to jss refactor: simplify the use of car properties, and remove currently unused ones fix: put hooks on their correct places fix: when changing the value of the switch, update only it's own config fix: rename booleanPropertiesTable file so it starts with a capital letter. chore: readd removed properties on the car settings (all commented out) chore: integrated CAR settings page into Operator Info page fix: replaced broken white and disabled versions of the edit icon
178 lines
5.1 KiB
JavaScript
178 lines
5.1 KiB
JavaScript
const axios = require('axios')
|
|
const _ = require('lodash/fp')
|
|
const hkdf = require('futoin-hkdf')
|
|
|
|
const pify = require('pify')
|
|
const fs = pify(require('fs'))
|
|
|
|
const db = require('../db')
|
|
const mnemonicHelpers = require('../mnemonic-helpers')
|
|
const configManager = require('../config-manager')
|
|
const options = require('../options')
|
|
const logger = require('../logger')
|
|
const plugins = require('../plugins')
|
|
|
|
const TIMEOUT = 10000
|
|
const MAX_CONTENT_LENGTH = 2000
|
|
|
|
// How long a machine can be down before it's considered offline
|
|
const STALE_INTERVAL = '2 minutes'
|
|
|
|
module.exports = { update, mapRecord }
|
|
|
|
function mapCoin (info, deviceId, settings, cryptoCode) {
|
|
const config = info.config
|
|
const rates = plugins(settings, deviceId).buildRates(info.rates)[cryptoCode] || { cashIn: null, cashOut: null }
|
|
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, config)
|
|
const unscoped = configManager.unscoped(config)
|
|
const showCommissions = unscoped.coinAtmRadar.sendCommissions
|
|
|
|
const cashInFee = showCommissions ? cryptoConfig.cashInCommission / 100 : null
|
|
const cashOutFee = showCommissions ? cryptoConfig.cashOutCommission / 100 : null
|
|
const cashInRate = showCommissions ? _.invoke('cashIn.toNumber', rates) : null
|
|
const cashOutRate = showCommissions ? _.invoke('cashOut.toNumber', rates) : null
|
|
|
|
return {
|
|
cryptoCode,
|
|
cashInFee,
|
|
cashOutFee,
|
|
cashInRate,
|
|
cashOutRate
|
|
}
|
|
}
|
|
|
|
function mapIdentification (info, deviceId) {
|
|
const machineConfig = configManager.machineScoped(deviceId, info.config)
|
|
|
|
return {
|
|
isPhone: machineConfig.smsVerificationActive,
|
|
isPalmVein: false,
|
|
isPhoto: false,
|
|
isIdDocScan: machineConfig.idCardDataVerificationActive,
|
|
isFingerprint: false
|
|
}
|
|
}
|
|
|
|
function mapMachine (info, settings, machineRow) {
|
|
const deviceId = machineRow.device_id
|
|
const config = info.config
|
|
const unscoped = configManager.unscoped(config)
|
|
const machineConfig = configManager.machineScoped(deviceId, config)
|
|
|
|
const lastOnline = machineRow.last_online.toISOString()
|
|
const status = machineRow.stale ? 'online' : 'offline'
|
|
const showSupportedCryptocurrencies =
|
|
unscoped.coinAtmRadar.sendSupportedCryptocurrencies
|
|
const showSupportedFiat =
|
|
unscoped.coinAtmRadar.sendSupportedFiat
|
|
const showSupportedBuySellDirection =
|
|
unscoped.coinAtmRadar.sendSupportedBuySellDirection
|
|
const showLimitsAndVerification =
|
|
unscoped.coinAtmRadar.sendLimitsAndVerification
|
|
|
|
const cashLimit = showLimitsAndVerification ? (
|
|
machineConfig.hardLimitVerificationActive
|
|
? machineConfig.hardLimitVerificationThreshold
|
|
: Infinity ) : null
|
|
|
|
const cryptoCurrencies = machineConfig.cryptoCurrencies
|
|
const cashInEnabled = showSupportedBuySellDirection ? true : null
|
|
const cashOutEnabled = showSupportedBuySellDirection
|
|
? machineConfig.cashOutEnabled
|
|
: null
|
|
const fiat = showSupportedFiat ? machineConfig.fiatCurrency : null
|
|
const identification = mapIdentification(info, deviceId)
|
|
const coins = showSupportedCryptocurrencies ?
|
|
_.map(_.partial(mapCoin, [info, deviceId, settings]), cryptoCurrencies)
|
|
: null
|
|
|
|
return {
|
|
machineId: deviceId,
|
|
address: {
|
|
streetAddress: null,
|
|
city: null,
|
|
region: null,
|
|
postalCode: null,
|
|
country: null
|
|
},
|
|
location: {
|
|
name: null,
|
|
url: null,
|
|
phone: null
|
|
},
|
|
status,
|
|
lastOnline,
|
|
cashIn: cashInEnabled,
|
|
cashOut: cashOutEnabled,
|
|
manufacturer: 'lamassu',
|
|
cashInTxLimit: cashLimit,
|
|
cashOutTxLimit: cashLimit,
|
|
cashInDailyLimit: cashLimit,
|
|
cashOutDailyLimit: cashLimit,
|
|
fiatCurrency: fiat,
|
|
identification,
|
|
coins
|
|
}
|
|
}
|
|
|
|
function getMachines (info, settings) {
|
|
const sql = `select device_id, last_online, now() - last_online < $1 as stale from devices
|
|
where display=TRUE and
|
|
paired=TRUE
|
|
order by created`
|
|
|
|
return db.any(sql, [STALE_INTERVAL])
|
|
.then(_.map(_.partial(mapMachine, [info, settings])))
|
|
}
|
|
|
|
function sendRadar (data) {
|
|
const url = _.get(['coinAtmRadar', 'url'], options)
|
|
|
|
if (_.isEmpty(url)) {
|
|
return Promise.reject(new Error('Missing coinAtmRadar url!'))
|
|
}
|
|
|
|
const config = {
|
|
url,
|
|
method: 'post',
|
|
data,
|
|
timeout: TIMEOUT,
|
|
maxContentLength: MAX_CONTENT_LENGTH
|
|
}
|
|
|
|
console.log('%j', data)
|
|
|
|
return axios(config)
|
|
.then(r => console.log(r.status))
|
|
}
|
|
|
|
function mapRecord (info, settings) {
|
|
const timestamp = new Date().toISOString()
|
|
return Promise.all([getMachines(info, settings), fs.readFile(options.mnemonicPath, 'utf8')])
|
|
.then(([machines, mnemonic]) => {
|
|
return {
|
|
operatorId: computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic)),
|
|
operator: {
|
|
name: null,
|
|
phone: null,
|
|
email: null
|
|
},
|
|
timestamp,
|
|
machines
|
|
}
|
|
})
|
|
}
|
|
|
|
function update (info, settings) {
|
|
const config = configManager.unscoped(info.config)
|
|
|
|
if (!config.coinAtmRadar.active) return Promise.resolve()
|
|
|
|
return mapRecord(info, settings)
|
|
.then(sendRadar)
|
|
.catch(err => logger.error(`Failure to update CoinATMRadar`, err))
|
|
}
|
|
|
|
function computeOperatorId (masterSeed) {
|
|
return hkdf(masterSeed, 16, { salt: 'lamassu-server-salt', info: 'operator-id' }).toString('hex')
|
|
}
|