Merge pull request #1136 from chaotixkilla/fix-dashboard-tx-profits

Fix profits from dashboard
This commit is contained in:
Rafael Taranto 2022-03-01 12:17:35 +00:00 committed by GitHub
commit bedc355124
3 changed files with 15 additions and 10 deletions

View file

@ -49,6 +49,7 @@ const typeDef = gql`
batchTime: Date
batchError: String
walletScore: Int
profit: String
}
type Filter {

View file

@ -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)
function batch (
@ -42,7 +49,7 @@ function batch (
excludeTestingCustomers = 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.*,
c.phone AS customer_phone,

View file

@ -29,7 +29,6 @@ BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_HALF_UP })
const getFiats = R.map(R.prop('fiat'))
const useStyles = makeStyles(styles)
const mapToFee = R.map(R.prop('cashInFee'))
const getDateSecondsAgo = (seconds = 0, startDate = null) => {
const date = startDate ? new Date(startDate) : new Date()
@ -61,6 +60,7 @@ const GET_DATA = gql`
created
txClass
error
profit
}
fiatRates {
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 classes = useStyles()
const [selectedRange, setSelectedRange] = useState('Day')
@ -123,10 +119,11 @@ const SystemPerformance = () => {
new BigNumber(R.sum(getFiats(transactionsToShow))).toFormat(2)
const getProfit = transactions => {
const cashInFees = R.sum(mapToFee(transactions))
const commissionFees = R.reduce(reducer, 0, transactions)
return new BigNumber(commissionFees + cashInFees)
return R.reduce(
(acc, value) => acc.plus(value.profit),
new BigNumber(0),
transactions
)
}
const getPercentChange = () => {