feat: add profit field to transactions
This commit is contained in:
parent
4339e58e6a
commit
64a4860df0
3 changed files with 15 additions and 10 deletions
|
|
@ -49,6 +49,7 @@ const typeDef = gql`
|
||||||
batchTime: Date
|
batchTime: Date
|
||||||
batchError: String
|
batchError: String
|
||||||
walletScore: Int
|
walletScore: Int
|
||||||
|
profit: String
|
||||||
}
|
}
|
||||||
|
|
||||||
type Filter {
|
type Filter {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,13 @@ function addNames (txs) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addProfits (txs) {
|
||||||
|
return _.map(it => {
|
||||||
|
const profit = getProfit(it).toString()
|
||||||
|
return _.set('profit', profit, it)
|
||||||
|
}, txs)
|
||||||
|
}
|
||||||
|
|
||||||
const camelize = _.mapKeys(_.camelCase)
|
const camelize = _.mapKeys(_.camelCase)
|
||||||
|
|
||||||
function batch (
|
function batch (
|
||||||
|
|
@ -42,7 +49,7 @@ function batch (
|
||||||
excludeTestingCustomers = false,
|
excludeTestingCustomers = false,
|
||||||
simplified = false
|
simplified = false
|
||||||
) {
|
) {
|
||||||
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addNames)
|
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']), _.map(camelize), addProfits, addNames)
|
||||||
|
|
||||||
const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
|
const cashInSql = `SELECT 'cashIn' AS tx_class, txs.*,
|
||||||
c.phone AS customer_phone,
|
c.phone AS customer_phone,
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_HALF_UP })
|
||||||
|
|
||||||
const getFiats = R.map(R.prop('fiat'))
|
const getFiats = R.map(R.prop('fiat'))
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
const mapToFee = R.map(R.prop('cashInFee'))
|
|
||||||
|
|
||||||
const getDateSecondsAgo = (seconds = 0, startDate = null) => {
|
const getDateSecondsAgo = (seconds = 0, startDate = null) => {
|
||||||
const date = startDate ? new Date(startDate) : new Date()
|
const date = startDate ? new Date(startDate) : new Date()
|
||||||
|
|
@ -61,6 +60,7 @@ const GET_DATA = gql`
|
||||||
created
|
created
|
||||||
txClass
|
txClass
|
||||||
error
|
error
|
||||||
|
profit
|
||||||
}
|
}
|
||||||
fiatRates {
|
fiatRates {
|
||||||
code
|
code
|
||||||
|
|
@ -71,10 +71,6 @@ const GET_DATA = gql`
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const reducer = (acc, it) =>
|
|
||||||
(acc +=
|
|
||||||
Number.parseFloat(it.commissionPercentage) * Number.parseFloat(it.fiat))
|
|
||||||
|
|
||||||
const SystemPerformance = () => {
|
const SystemPerformance = () => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const [selectedRange, setSelectedRange] = useState('Day')
|
const [selectedRange, setSelectedRange] = useState('Day')
|
||||||
|
|
@ -123,10 +119,11 @@ const SystemPerformance = () => {
|
||||||
new BigNumber(R.sum(getFiats(transactionsToShow))).toFormat(2)
|
new BigNumber(R.sum(getFiats(transactionsToShow))).toFormat(2)
|
||||||
|
|
||||||
const getProfit = transactions => {
|
const getProfit = transactions => {
|
||||||
const cashInFees = R.sum(mapToFee(transactions))
|
return R.reduce(
|
||||||
const commissionFees = R.reduce(reducer, 0, transactions)
|
(acc, value) => acc.plus(value.profit),
|
||||||
|
new BigNumber(0),
|
||||||
return new BigNumber(commissionFees + cashInFees)
|
transactions
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPercentChange = () => {
|
const getPercentChange = () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue