feat: simplified tx exports
This commit is contained in:
parent
2f6aac8f6d
commit
5826a29c53
4 changed files with 102 additions and 12 deletions
|
|
@ -302,6 +302,7 @@ const typeDefs = gql`
|
|||
deviceId: ID
|
||||
): [Transaction]
|
||||
transactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
simplifiedTransactionsCsv(from: Date, until: Date, limit: Int, offset: Int): String
|
||||
accounts: JSONObject
|
||||
config: JSONObject
|
||||
blacklist: [Blacklist]
|
||||
|
|
@ -399,6 +400,8 @@ const resolvers = {
|
|||
transactions.batch(from, until, limit, offset, deviceId),
|
||||
transactionsCsv: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.batch(from, until, limit, offset).then(parseAsync),
|
||||
simplifiedTransactionsCsv: (...[, { from, until, limit, offset }]) =>
|
||||
transactions.simplifiedBatch(from, until, limit, offset).then(parseAsync),
|
||||
config: () => settingsLoader.loadLatestConfigOrNone(),
|
||||
accounts: () => settingsLoader.showAccounts(),
|
||||
blacklist: () => blacklist.getBlacklist(),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ const machineLoader = require('../machine-loader')
|
|||
const tx = require('../tx')
|
||||
const cashInTx = require('../cash-in/cash-in-tx')
|
||||
const { REDEEMABLE_AGE } = require('../cash-out/cash-out-helper')
|
||||
const coinUtils = require('../coin-utils')
|
||||
const BN = require('../bn')
|
||||
|
||||
const NUM_RESULTS = 1000
|
||||
|
||||
|
|
@ -76,6 +78,46 @@ function batch (from = new Date(0).toISOString(), until = new Date().toISOString
|
|||
]).then(packager)
|
||||
}
|
||||
|
||||
function simplifiedBatch (from = new Date(0).toISOString(), until = new Date().toISOString(), limit = null, offset = 0) {
|
||||
return batch(from, until, limit, offset)
|
||||
.then(res => {
|
||||
const fields = ['txClass', 'id', 'created', 'machineName',
|
||||
'cryptoCode', 'fiat', 'fiatCode', 'phone', 'toAddress',
|
||||
'txHash', 'dispense', 'error', 'status', 'fiatProfit', 'cryptoAmount']
|
||||
return _.map(_.compose(_.pick(fields), getStatus, getProfit, getCryptoAmount))(res)
|
||||
})
|
||||
}
|
||||
|
||||
const getCryptoAmount = it => { return { ...it, cryptoAmount: coinUtils.toUnit(BN(it.cryptoAtoms), it.cryptoCode).toString() } }
|
||||
|
||||
const getProfit = it => {
|
||||
const getCommissionFee = it => Number.parseFloat(it.commissionPercentage) * Number.parseFloat(it.fiat)
|
||||
if (!it.cashInFee) return { ...it, fiatProfit: getCommissionFee(it) }
|
||||
return { ...it, fiatProfit: getCommissionFee(it) + Number.parseFloat(it.cashInFee) }
|
||||
}
|
||||
|
||||
const getCashOutStatus = it => {
|
||||
if (it.hasError) return { ...it, status: 'Error' }
|
||||
if (it.dispense) return { ...it, status: 'Success' }
|
||||
if (it.expired) return { ...it, status: 'Expired' }
|
||||
return { ...it, status: 'Pending' }
|
||||
}
|
||||
|
||||
const getCashInStatus = it => {
|
||||
if (it.operatorCompleted) return { ...it, status: 'Cancelled' }
|
||||
if (it.hasError) return { ...it, status: 'Error' }
|
||||
if (it.sendConfirmed) return { ...it, status: 'Sent' }
|
||||
if (it.expired) return { ...it, status: 'Expired' }
|
||||
return { ...it, status: 'Pending' }
|
||||
}
|
||||
|
||||
const getStatus = it => {
|
||||
if (it.txClass === 'cashOut') {
|
||||
return getCashOutStatus(it)
|
||||
}
|
||||
return getCashInStatus(it)
|
||||
}
|
||||
|
||||
function getCustomerTransactionsBatch (ids) {
|
||||
const packager = _.flow(it => {
|
||||
return it
|
||||
|
|
@ -168,4 +210,4 @@ function cancel (txId) {
|
|||
.then(() => single(txId))
|
||||
}
|
||||
|
||||
module.exports = { batch, single, cancel, getCustomerTransactionsBatch }
|
||||
module.exports = { simplifiedBatch, batch, single, cancel, getCustomerTransactionsBatch }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue