Merge pull request #1839 from RafaelTaranto/chore/merge-release-10.2.3
chore: merge release 10.2.3
This commit is contained in:
commit
f2689fb56b
3 changed files with 22 additions and 24 deletions
42
lib/forex.js
42
lib/forex.js
|
|
@ -1,33 +1,31 @@
|
|||
const _ = require('lodash/fp')
|
||||
const axios = require('axios')
|
||||
const mem = require('mem')
|
||||
|
||||
const BN = require('./bn')
|
||||
const T = require('./time')
|
||||
|
||||
const MAX_ROTATIONS = 5
|
||||
|
||||
const getFiatRates = () => axios.get('https://bitpay.com/api/rates').then(response => response.data)
|
||||
const _getFiatRates = () => (
|
||||
axios.get('https://bitpay.com/api/rates')
|
||||
.then(response => response.data)
|
||||
)
|
||||
|
||||
const getFiatRates = mem(_getFiatRates, {
|
||||
maxAge: 6 * T.hours,
|
||||
cacheKey: () => ''
|
||||
})
|
||||
|
||||
const API_QUEUE = [
|
||||
{ api: getBitPayFxRate, name: 'bitpay', fiatCodeProperty: 'code', rateProperty: 'rate' },
|
||||
{ api: getCoinCapFxRate, name: 'coincap', fiatCodeProperty: 'symbol', rateProperty: 'rateUsd' }
|
||||
{ api: getBitPayFxRate, name: 'bitpay', fiatCodeProperty: 'code', rateProperty: 'rate' }
|
||||
]
|
||||
|
||||
function getBitPayFxRate (fiatCode, fiatCodeProperty, rateProperty) {
|
||||
return axios.get('https://bitpay.com/rates')
|
||||
.then(response => {
|
||||
const fxRates = response.data.data
|
||||
const usdRate = findCurrencyRates(fxRates, 'USD', fiatCodeProperty, rateProperty)
|
||||
const fxRate = findCurrencyRates(fxRates, fiatCode, fiatCodeProperty, rateProperty).div(usdRate)
|
||||
return {
|
||||
fxRate
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getCoinCapFxRate (fiatCode, fiatCodeProperty, rateProperty) {
|
||||
return axios.get('https://api.coincap.io/v2/rates')
|
||||
.then(response => {
|
||||
const fxRates = response.data.data
|
||||
const fxRate = new BN(1).div(findCurrencyRates(fxRates, fiatCode, fiatCodeProperty, rateProperty))
|
||||
function getBitPayFxRate (fiatCode, defaultFiatMarket, fiatCodeProperty, rateProperty) {
|
||||
return getFiatRates()
|
||||
.then(({ data: fxRates }) => {
|
||||
const defaultFiatRate = findCurrencyRates(fxRates, defaultFiatMarket, fiatCodeProperty, rateProperty)
|
||||
const fxRate = findCurrencyRates(fxRates, fiatCode, fiatCodeProperty, rateProperty).div(defaultFiatRate)
|
||||
return {
|
||||
fxRate
|
||||
}
|
||||
|
|
@ -40,7 +38,7 @@ function findCurrencyRates (fxRates, fiatCode, fiatCodeProperty, rateProperty) {
|
|||
return new BN(rates[rateProperty].toString())
|
||||
}
|
||||
|
||||
const getRate = (retries = 1, fiatCode) => {
|
||||
const getRate = (retries = 1, fiatCode, defaultFiatMarket) => {
|
||||
const selected = _.first(API_QUEUE).name
|
||||
const activeAPI = _.first(API_QUEUE).api
|
||||
const fiatCodeProperty = _.first(API_QUEUE).fiatCodeProperty
|
||||
|
|
@ -48,7 +46,7 @@ const getRate = (retries = 1, fiatCode) => {
|
|||
|
||||
if (!activeAPI) throw new Error(`FOREX api ${selected} does not exist.`)
|
||||
|
||||
return activeAPI(fiatCode, fiatCodeProperty, rateProperty)
|
||||
return activeAPI(fiatCode, defaultFiatMarket, fiatCodeProperty, rateProperty)
|
||||
.catch(() => {
|
||||
// Switch service
|
||||
const erroredService = API_QUEUE.shift()
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ const resolvers = {
|
|||
transactions: (...[, { from, until, limit, offset, txClass, deviceId, customerName, fiatCode, cryptoCode, toAddress, status, swept, excludeTestingCustomers }]) =>
|
||||
transactions.batch(from, until, limit, offset, txClass, deviceId, customerName, fiatCode, cryptoCode, toAddress, status, swept, excludeTestingCustomers),
|
||||
transactionsCsv: (...[, { from, until, limit, offset, txClass, deviceId, customerName, fiatCode, cryptoCode, toAddress, status, swept, timezone, excludeTestingCustomers, simplified }]) =>
|
||||
transactions.batch(from, until, limit, offset, null, txClass, deviceId, customerName, fiatCode, cryptoCode, toAddress, status, swept, excludeTestingCustomers, simplified)
|
||||
transactions.batch(from, until, limit, offset, txClass, deviceId, customerName, fiatCode, cryptoCode, toAddress, status, swept, excludeTestingCustomers, simplified)
|
||||
.then(data => parseAsync(logDateFormat(timezone, data, ['created', 'sendTime', 'publishedAt']))),
|
||||
transactionCsv: (...[, { id, txClass, timezone }]) =>
|
||||
transactions.getTx(id, txClass).then(data =>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ function ticker (fiatCode, cryptoCode, tickerName) {
|
|||
return getCurrencyRates(ticker, fiatCode, cryptoCode)
|
||||
}
|
||||
|
||||
return getRate(RETRIES, fiatCode)
|
||||
return getRate(RETRIES, tickerName, defaultFiatMarket(tickerName))
|
||||
.then(({ fxRate }) => {
|
||||
try {
|
||||
return getCurrencyRates(ticker, defaultFiatMarket(tickerName), cryptoCode)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue