Feat: make dashboard and machine profile page
This commit is contained in:
parent
d17ca43abb
commit
19cd086436
54 changed files with 11680 additions and 2611 deletions
|
|
@ -16,12 +16,15 @@ const machineEventsByIdBatch = require("../../postgresql_interface").machineEven
|
|||
const couponManager = require('../../coupons')
|
||||
|
||||
const serverVersion = require('../../../package.json').version
|
||||
|
||||
const transactions = require('../transactions')
|
||||
const funding = require('../funding')
|
||||
const supervisor = require('../supervisor')
|
||||
const serverLogs = require('../server-logs')
|
||||
const pairing = require('../pairing')
|
||||
|
||||
const plugins = require('../../plugins')
|
||||
const ticker = require('../../ticker')
|
||||
|
||||
const {
|
||||
accounts: accountsConfig,
|
||||
coins,
|
||||
|
|
@ -237,6 +240,10 @@ const typeDefs = gql`
|
|||
created: Date
|
||||
age: Float
|
||||
deviceTime: Date
|
||||
type Rate {
|
||||
code: String
|
||||
name: String
|
||||
rate: Float
|
||||
}
|
||||
|
||||
type Query {
|
||||
|
|
@ -256,12 +263,19 @@ const typeDefs = gql`
|
|||
uptime: [ProcessStatus]
|
||||
serverLogs(from: Date, until: Date, limit: Int, offset: Int): [ServerLog]
|
||||
serverLogsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
transactions(from: Date, until: Date, limit: Int, offset: Int): [Transaction]
|
||||
transactions(
|
||||
from: Date
|
||||
until: Date
|
||||
limit: Int
|
||||
offset: Int
|
||||
id: ID
|
||||
): [Transaction]
|
||||
transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
accounts: JSONObject
|
||||
config: JSONObject
|
||||
blacklist: [Blacklist]
|
||||
# userTokens: [UserToken]
|
||||
<<<<<<< HEAD
|
||||
coupons: [Coupon]
|
||||
}
|
||||
|
||||
|
|
@ -269,6 +283,10 @@ const typeDefs = gql`
|
|||
id: ID!
|
||||
timestamp: Date!
|
||||
deviceId: ID
|
||||
=======
|
||||
rates: JSONObject
|
||||
btcRates(to: String, from: String): [Rate]
|
||||
>>>>>>> 9d88b4f... Feat: make dashboard and machine profile page
|
||||
}
|
||||
|
||||
enum MachineAction {
|
||||
|
|
|
|||
|
|
@ -24,8 +24,19 @@ function addNames (txs) {
|
|||
|
||||
const camelize = _.mapKeys(_.camelCase)
|
||||
|
||||
function batch (from = new Date(0).toISOString(), until = new Date().toISOString(), limit = null, offset = 0) {
|
||||
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
||||
function batch (
|
||||
from = new Date(0).toISOString(),
|
||||
until = new Date().toISOString(),
|
||||
limit = null,
|
||||
offset = 0,
|
||||
id = null
|
||||
) {
|
||||
const packager = _.flow(
|
||||
_.flatten,
|
||||
_.orderBy(_.property('created'), ['desc']),
|
||||
_.map(camelize),
|
||||
addNames
|
||||
)
|
||||
|
||||
const cashInSql = `select 'cashIn' as tx_class, txs.*,
|
||||
c.phone as customer_phone,
|
||||
|
|
@ -36,9 +47,11 @@ 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
|
||||
where txs.created >= $2 and txs.created <= $3 ${
|
||||
id !== null ? `and txs.device_id = $6` : ``
|
||||
}
|
||||
order by created desc limit $4 offset $5`
|
||||
|
||||
const cashOutSql = `select 'cashOut' as tx_class,
|
||||
|
|
@ -52,18 +65,26 @@ 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
|
||||
where txs.created >= $2 and txs.created <= $3
|
||||
where txs.created >= $2 and txs.created <= $3 ${
|
||||
id !== null ? `and txs.device_id = $6` : ``
|
||||
}
|
||||
order by created desc limit $4 offset $5`
|
||||
|
||||
return Promise.all([
|
||||
db.any(cashInSql, [cashInTx.PENDING_INTERVAL, from, until, limit, offset]),
|
||||
db.any(cashOutSql, [REDEEMABLE_AGE, from, until, limit, offset])
|
||||
])
|
||||
.then(packager)
|
||||
db.any(cashInSql, [
|
||||
cashInTx.PENDING_INTERVAL,
|
||||
from,
|
||||
until,
|
||||
limit,
|
||||
offset,
|
||||
id
|
||||
]),
|
||||
db.any(cashOutSql, [REDEEMABLE_AGE, from, until, limit, offset, id])
|
||||
]).then(packager)
|
||||
}
|
||||
|
||||
function getCustomerTransactionsBatch (ids) {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,29 @@ const PONG_TTL = '1 week'
|
|||
const tradesQueues = {}
|
||||
|
||||
function plugins (settings, deviceId) {
|
||||
function buildRatesNoCommission (tickers) {
|
||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||
|
||||
const rates = {}
|
||||
|
||||
cryptoCodes.forEach((cryptoCode, i) => {
|
||||
const rateRec = tickers[i]
|
||||
|
||||
if (!rateRec) return
|
||||
|
||||
if (Date.now() - rateRec.timestamp > STALE_TICKER)
|
||||
return logger.warn('Stale rate for ' + cryptoCode)
|
||||
const rate = rateRec.rates
|
||||
rates[cryptoCode] = {
|
||||
cashIn: rate.ask.round(5),
|
||||
cashOut: rate.bid.round(5)
|
||||
}
|
||||
})
|
||||
|
||||
return rates
|
||||
}
|
||||
|
||||
function buildRates (tickers) {
|
||||
const localeConfig = configManager.getLocale(deviceId, settings.config)
|
||||
const cryptoCodes = localeConfig.cryptoCurrencies
|
||||
|
|
@ -791,6 +814,7 @@ function plugins (settings, deviceId) {
|
|||
getRates,
|
||||
buildRates,
|
||||
getRawRates,
|
||||
buildRatesNoCommission,
|
||||
pollQueries,
|
||||
sendCoins,
|
||||
newAddress,
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue