Merge pull request #1351 from siiky/fix/lam-590/profits

fix: don't add fixed fee twice for profit calculation
This commit is contained in:
Rafael Taranto 2022-08-18 10:21:49 +01:00 committed by GitHub
commit 5949764389
3 changed files with 5 additions and 22 deletions

View file

@ -169,8 +169,8 @@ function simplifiedBatch (data) {
const getCryptoAmount = it => coinUtils.toUnit(BN(it.cryptoAtoms), it.cryptoCode) const getCryptoAmount = it => coinUtils.toUnit(BN(it.cryptoAtoms), it.cryptoCode)
const getProfit = it => { const getProfit = it => {
/* fiat - crypto*tickerPrice + fee */ /* fiat - crypto*tickerPrice */
const calcCashInProfit = (fiat, crypto, tickerPrice, fee) => fiat.minus(crypto.times(tickerPrice)).plus(fee) const calcCashInProfit = (fiat, crypto, tickerPrice) => fiat.minus(crypto.times(tickerPrice))
/* crypto*tickerPrice - fiat */ /* crypto*tickerPrice - fiat */
const calcCashOutProfit = (fiat, crypto, tickerPrice) => crypto.times(tickerPrice).minus(fiat) const calcCashOutProfit = (fiat, crypto, tickerPrice) => crypto.times(tickerPrice).minus(fiat)
@ -180,7 +180,7 @@ const getProfit = it => {
const isCashIn = it.txClass === 'cashIn' const isCashIn = it.txClass === 'cashIn'
return isCashIn return isCashIn
? calcCashInProfit(fiat, crypto, tickerPrice, BN(it.cashInFee)) ? calcCashInProfit(fiat, crypto, tickerPrice)
: calcCashOutProfit(fiat, crypto, tickerPrice) : calcCashOutProfit(fiat, crypto, tickerPrice)
} }

View file

@ -88,24 +88,6 @@ const CANCEL_CASH_IN_TRANSACTION = gql`
const getCryptoAmount = tx => const getCryptoAmount = tx =>
coinUtils.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode).toNumber() coinUtils.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode).toNumber()
/* Port of getProfit() from lib/new-admin/services/transactions.js */
const getCommission = tx => {
const calcCashInProfit = (fiat, crypto, tickerPrice, fee) =>
fiat - crypto * tickerPrice + fee
const calcCashOutProfit = (fiat, crypto, tickerPrice) =>
crypto * tickerPrice - fiat
const fiat = Number.parseFloat(tx.fiat)
const crypto = getCryptoAmount(tx)
const tickerPrice = Number.parseFloat(tx.rawTickerPrice)
const isCashIn = tx.txClass === 'cashIn'
const cashInFee = isCashIn ? Number.parseFloat(tx.cashInFee) : 0
return isCashIn
? calcCashInProfit(fiat, crypto, tickerPrice, cashInFee)
: calcCashOutProfit(fiat, crypto, tickerPrice)
}
const formatAddress = (cryptoCode = '', address = '') => const formatAddress = (cryptoCode = '', address = '') =>
coinUtils.formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ') coinUtils.formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ')
@ -136,7 +118,7 @@ const DetailsRow = ({ it: tx, timezone }) => {
} }
) )
const commission = BigNumber(getCommission(tx)) const commission = BigNumber(tx.profit)
.abs() .abs()
.toFixed(2, 1) // ROUND_DOWN .toFixed(2, 1) // ROUND_DOWN
const commissionPercentage = const commissionPercentage =

View file

@ -121,6 +121,7 @@ const GET_TRANSACTIONS = gql`
rawTickerPrice rawTickerPrice
batchError batchError
walletScore walletScore
profit
} }
} }
` `