Feat: make dashboard and machine profile page

This commit is contained in:
Cesar 2020-11-17 12:13:10 +00:00 committed by Josh Harvey
parent 1df90c3196
commit c21cdb13e1
29 changed files with 717 additions and 135 deletions

View file

@ -240,6 +240,10 @@ const typeDefs = gql`
created: Date
age: Float
deviceTime: Date
type Rate {
code: String
name: String
rate: Float
}
type Rate {

View file

@ -36,7 +36,7 @@ function batch (from = new Date(0).toISOString(), until = new Date().toISOString
c.front_camera_path as customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_path,
((not txs.send_confirmed) and (txs.created <= now() - interval $1)) as expired
from cash_in_txs as txs
from cash_in_txs as txs
left outer join customers c on txs.customer_id = c.id
where txs.created >= $2 and txs.created <= $3 ${
id !== null ? `and txs.device_id = $6` : ``
@ -54,7 +54,7 @@ function batch (from = new Date(0).toISOString(), until = new Date().toISOString
c.front_camera_path as customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_path,
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $1 as expired
from cash_out_txs txs
from cash_out_txs txs
inner join cash_out_actions actions on txs.id = actions.tx_id
and actions.action = 'provisionAddress'
left outer join customers c on txs.customer_id = c.id

View file

@ -147,21 +147,6 @@ function plugins (settings, deviceId) {
]
}
<<<<<<< HEAD
=======
function getLcmOrBigx2 (n1, n2) {
let big = Math.max(n1, n2)
let small = Math.min(n1, n2)
let i = big * 2
while (i % small !== 0) {
i += lar
}
return i
}
>>>>>>> 1706b2c... Feat: save highVolumeTxs on DB and plugins code refactor
function buildAvailableCassettes (excludeTxId) {
const cashOutConfig = configManager.getCashOut(deviceId, settings.config)
@ -169,7 +154,6 @@ function plugins (settings, deviceId) {
const denominations = [cashOutConfig.top, cashOutConfig.bottom]
<<<<<<< HEAD
const virtualCassettes = [Math.max(cashOutConfig.top, cashOutConfig.bottom) * 2]
return Promise.all([dbm.cassetteCounts(deviceId), cashOutHelper.redeemableTxs(deviceId, excludeTxId)])
@ -179,11 +163,6 @@ function plugins (settings, deviceId) {
const counts = argv.cassettes
? argv.cassettes.split(',')
: rec.counts
=======
const virtualCassettes = [
getLcmOrBigx2(cashOutConfig.top, cashOutConfig.bottom)
]
>>>>>>> 1706b2c... Feat: save highVolumeTxs on DB and plugins code refactor
return Promise.all([
dbm.cassetteCounts(deviceId),
@ -288,7 +267,6 @@ function plugins (settings, deviceId) {
currentConfigVersionPromise
].concat(tickerPromises, balancePromises, testnetPromises, currentAvailablePromoCodes)
<<<<<<< HEAD
return Promise.all(promises)
.then(arr => {
const cassettes = arr[0]
@ -310,26 +288,6 @@ function plugins (settings, deviceId) {
areThereAvailablePromoCodes
}
})
=======
return Promise.all(promises).then(arr => {
const cassettes = arr[0]
const configVersion = arr[2]
const cryptoCodesCount = cryptoCodes.length
const tickers = arr.slice(3, cryptoCodesCount + 3)
const balances = arr.slice(cryptoCodesCount + 3, 2 * cryptoCodesCount + 3)
const testNets = arr.slice(2 * cryptoCodesCount + 3)
const coinParams = _.zip(cryptoCodes, testNets)
const coinsWithoutRate = _.map(mapCoinSettings, coinParams)
return {
cassettes,
rates: buildRates(tickers),
balances: buildBalances(balances),
coins: _.zipWith(_.assign, coinsWithoutRate, tickers),
configVersion
}
})
>>>>>>> 1706b2c... Feat: save highVolumeTxs on DB and plugins code refactor
}
function sendCoins (tx) {
@ -648,15 +606,8 @@ function plugins (settings, deviceId) {
const notifications = configManager.getGlobalNotifications(settings.config)
let promises = []
<<<<<<< HEAD
if (notifications.email.active && rec.email) promises.push(email.sendMessage(settings, rec))
if (notifications.sms.active && rec.sms) promises.push(sms.sendMessage(settings, rec))
=======
if (notifications.email.active && rec.email)
promises.push(email.sendMessage(settings, rec))
if (notifications.sms.active && rec.sms)
promises.push(sms.sendMessage(settings, rec))
>>>>>>> 1706b2c... Feat: save highVolumeTxs on DB and plugins code refactor
return Promise.all(promises)
}
@ -757,25 +708,11 @@ function plugins (settings, deviceId) {
fiatCode
}
<<<<<<< HEAD
if (_.isFinite(lowAlertThreshold) && BN(fiatBalance.balance).lt(lowAlertThreshold)) {
=======
if (
_.isFinite(lowAlertThreshold) &&
BN(fiatBalance.balance).lt(lowAlertThreshold)
)
>>>>>>> 1706b2c... Feat: save highVolumeTxs on DB and plugins code refactor
return _.set('code')('LOW_CRYPTO_BALANCE')(req)
}
<<<<<<< HEAD
if (_.isFinite(highAlertThreshold) && BN(fiatBalance.balance).gt(highAlertThreshold)) {
=======
if (
_.isFinite(highAlertThreshold) &&
BN(fiatBalance.balance).gt(highAlertThreshold)
)
>>>>>>> 1706b2c... Feat: save highVolumeTxs on DB and plugins code refactor
return _.set('code')('HIGH_CRYPTO_BALANCE')(req)
}

View file

@ -2,6 +2,7 @@ const mem = require('mem')
const configManager = require('./new-config-manager')
const ph = require('./plugin-helper')
const logger = require('./logger')
const axios = require('axios')
const lastRate = {}
@ -39,4 +40,26 @@ const getRates = mem(_getRates, {
cacheKey: (settings, fiatCode, cryptoCode) => JSON.stringify([fiatCode, cryptoCode])
})
module.exports = { getRates }
const getBtcRates = (to = null, from = 'USD') => {
// if to !== null, then we return only the rates with from (default USD) and to (so an array with 2 items)
return axios.get('https://bitpay.com/api/rates').then(response => {
const fxRates = response.data
if (to === null) {
return fxRates
}
const toRate = fxRates.find(o => o.code === to)
const fromRate = fxRates.find(o => o.code === from)
let res = []
if (toRate && to !== from) {
res = [...res, toRate]
}
if (fromRate) {
res = [...res, fromRate]
}
return res
})
}
module.exports = { getBtcRates, getRates }