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:
commit
5949764389
3 changed files with 5 additions and 22 deletions
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 =
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ const GET_TRANSACTIONS = gql`
|
||||||
rawTickerPrice
|
rawTickerPrice
|
||||||
batchError
|
batchError
|
||||||
walletScore
|
walletScore
|
||||||
|
profit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue