Merge pull request #1639 from RafaelTaranto/merge-8.1-into-9

Merge 8.1 into 9
This commit is contained in:
Rafael Taranto 2024-01-08 10:38:08 +00:00 committed by GitHub
commit 462d3c72ed
8 changed files with 1443 additions and 786 deletions

View file

@ -0,0 +1,8 @@
const axios = require("axios");
const getEstimateFeeBtc = () => {
return axios.get('https://mempool.space/api/v1/fees/recommended')
.then(r => r.data.hourFee)
}
module.exports = { getEstimateFeeBtc }

View file

@ -174,7 +174,7 @@ function advancedBatch (data) {
}
function simplifiedBatch (data) {
const fields = ['txClass', 'id', 'created', 'machineName',
const fields = ['txClass', 'id', 'created', 'machineName', 'fee',
'cryptoCode', 'cryptoAtoms', 'fiat', 'fiatCode', 'phone', 'email', 'toAddress',
'txHash', 'dispense', 'error', 'status', 'fiatProfit', 'cryptoAmount']

View file

@ -1,5 +1,6 @@
const _ = require('lodash/fp')
const jsonRpc = require('../../common/json-rpc')
const { getEstimateFeeBtc } = require('../../../blockexplorers/mempool.space')
const BN = require('../../../bn')
const E = require('../../../error')
@ -55,20 +56,27 @@ function balance (account, cryptoCode, settings, operatorId) {
}
function estimateFee () {
return fetch('estimatesmartfee', [6, 'unset'])
.then(result => BN(result.feerate))
.catch(() => {})
return getEstimateFeeBtc()
.then(result => BN(result))
.catch(err => {
logger.error('failure estimating fes', err)
})
}
function calculateFeeDiscount (feeMultiplier) {
function calculateFeeDiscount (feeMultiplier = 1) {
// 0 makes bitcoind do automatic fee selection
const AUTOMATIC_FEE = 0
if (!feeMultiplier || feeMultiplier.eq(1)) return AUTOMATIC_FEE
return estimateFee()
.then(estimatedFee => {
if (!estimatedFee) return AUTOMATIC_FEE
if (!estimatedFee) {
logger.info('failure estimating fee, using bitcoind automatic fee selection')
return AUTOMATIC_FEE
}
const newFee = estimatedFee.times(feeMultiplier)
if (newFee.lt(0.00001) || newFee.gt(0.1)) return AUTOMATIC_FEE
if (newFee.lt(0.00001) || newFee.gt(0.1)) {
logger.info('fee outside safety parameters, defaulting to automatic fee selection')
return AUTOMATIC_FEE
}
return newFee.toFixed(8)
})
}

View file

@ -89,6 +89,17 @@ const CANCEL_CASH_IN_TRANSACTION = gql`
const getCryptoAmount = tx =>
coinUtils.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode).toNumber()
const getCryptoFeeAmount = tx => {
const feeAmount = coinUtils
.toUnit(new BigNumber(tx.cryptoAtoms), tx.cryptoCode)
.toNumber()
return new BigNumber(feeAmount)
.times(tx.rawTickerPrice)
.toNumber()
.toFixed(2, 1)
}
const formatAddress = (cryptoCode = '', address = '') =>
coinUtils.formatCryptoAddress(cryptoCode, address).replace(/(.{5})/g, '$1 ')
@ -129,6 +140,7 @@ const DetailsRow = ({ it: tx, timezone }) => {
.minus(cashInFee)
.toFixed(2, 1) // ROUND_DOWN
const crypto = getCryptoAmount(tx)
const cryptoFee = getCryptoFeeAmount(tx)
const exchangeRate = BigNumber(fiat)
.div(crypto)
.toFixed(2, 1) // ROUND_DOWN
@ -369,6 +381,12 @@ const DetailsRow = ({ it: tx, timezone }) => {
)}
</div>
</div>
{tx.txClass === 'cashIn' && (
<div className={classes.blockFee}>
<Label>Network Fee</Label>
{cryptoFee} {tx.fiatCode}
</div>
)}
<div className={classes.sessionId}>
<Label>Session ID</Label>
<CopyToClipboard>{tx.id}</CopyToClipboard>

View file

@ -90,6 +90,9 @@ export default {
transactionId: {
width: 280
},
blockFee: {
width: 140
},
sessionId: {
width: 215
},

View file

@ -104,6 +104,7 @@ const GET_TRANSACTIONS = gql`
errorCode
deviceId
fiat
fee
cashInFee
fiatCode
cryptoAtoms

2161
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -6,6 +6,12 @@
"license": "./LICENSE",
"author": "Lamassu (https://lamassu.is)",
"dependencies": {
"@bitgo/sdk-api": "1.33.0",
"@bitgo/sdk-coin-bch": "1.5.22",
"@bitgo/sdk-coin-btc": "1.7.22",
"@bitgo/sdk-coin-dash": "1.5.22",
"@bitgo/sdk-coin-ltc": "2.2.22",
"@bitgo/sdk-coin-zec": "1.5.22",
"@ethereumjs/common": "^2.6.4",
"@ethereumjs/tx": "^3.5.1",
"@graphql-tools/merge": "^6.2.5",
@ -22,12 +28,7 @@
"bchaddrjs": "^0.3.0",
"bignumber.js": "9.0.1",
"bip39": "^2.3.1",
"@bitgo/sdk-api": "1.33.0",
"@bitgo/sdk-coin-bch": "1.5.22",
"@bitgo/sdk-coin-btc": "1.7.22",
"@bitgo/sdk-coin-dash": "1.5.22",
"@bitgo/sdk-coin-ltc": "2.2.22",
"@bitgo/sdk-coin-zec": "1.5.22",
"bitcoind-rpc": "^0.7.0",
"ccxt": "2.9.16",
"compression": "^1.7.4",
"connect-pg-simple": "^6.2.1",
@ -37,6 +38,7 @@
"dataloader": "^2.0.0",
"date-fns": "^2.26.0",
"date-fns-tz": "^1.1.6",
"dateformat": "^3.0.3",
"dotenv": "^16.0.0",
"ethereumjs-tx": "^1.3.3",
"ethereumjs-util": "^5.2.0",