stacker.news/api/resolvers/chainFee.js

26 lines
571 B
JavaScript
Raw Normal View History

import { cachedFetcher } from '@/lib/fetch'
const getChainFeeRate = cachedFetcher(async () => {
const url = 'https://mempool.space/api/v1/fees/recommended'
try {
const res = await fetch(url)
const body = await res.json()
return body.hourFee
} catch (err) {
console.error('fetchChainFee', err)
return 0
}
}, {
maxSize: 1,
cacheExpiry: 60 * 1000, // 1 minute
forceRefreshThreshold: 0 // never force refresh
})
export default {
Query: {
chainFee: async (parent, opts, ctx) => {
return await getChainFeeRate() || 0
}
}
}