lnbits-legend/lnbits/extensions/watchonly/static/components/fee-rate/fee-rate.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-07-25 20:03:48 +03:00
async function feeRate(path) {
2022-07-25 19:37:16 +03:00
const template = await loadTemplateAsync(path)
2022-07-26 10:11:29 +03:00
Vue.component('fee-rate', {
name: 'fee-rate',
2022-07-25 19:37:16 +03:00
template,
2022-07-29 18:42:05 +03:00
props: ['rate', 'fee-value', 'sats-denominated', 'mempool-endpoint'],
2022-07-26 14:29:00 +03:00
2022-07-26 10:11:29 +03:00
computed: {
feeRate: {
get: function () {
return this['rate']
},
set: function (value) {
this.$emit('update:rate', +value)
}
}
},
2022-07-25 19:37:16 +03:00
data: function () {
return {
recommededFees: {
fastestFee: 1,
halfHourFee: 1,
hourFee: 1,
economyFee: 1,
minimumFee: 1
}
}
},
methods: {
satBtc(val, showUnit = true) {
2022-07-28 12:39:06 +03:00
return satOrBtc(val, showUnit, this.satsDenominated)
2022-07-25 19:37:16 +03:00
},
2022-07-26 10:11:29 +03:00
2022-07-25 19:37:16 +03:00
refreshRecommendedFees: async function () {
const fn = async () => {
const {
bitcoin: {fees: feesAPI}
} = mempoolJS({
hostname: this.mempoolEndpoint
})
return feesAPI.getFeesRecommended()
}
2022-07-25 19:37:16 +03:00
this.recommededFees = await retryWithDelay(fn)
},
getFeeRateLabel: function (feeRate) {
const fees = this.recommededFees
if (feeRate >= fees.fastestFee)
return `High Priority (${feeRate} sat/vB)`
if (feeRate >= fees.halfHourFee)
return `Medium Priority (${feeRate} sat/vB)`
if (feeRate >= fees.hourFee) return `Low Priority (${feeRate} sat/vB)`
return `No Priority (${feeRate} sat/vB)`
}
},
created: async function () {
await this.refreshRecommendedFees()
this.feeRate = this.recommededFees.halfHourFee
}
})
}