lnbits-legend/lnbits/extensions/watchonly/static/components/send-to/send-to.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-07-26 10:11:29 +03:00
async function sendTo(path) {
const template = await loadTemplateAsync(path)
Vue.component('send-to', {
name: 'send-to',
template,
2022-07-26 14:09:16 +03:00
props: [
'data',
'tx-size',
'selected-amount',
'fee-rate',
'sats_denominated'
],
2022-07-26 10:11:29 +03:00
computed: {
dataLocal: {
get: function () {
return this.data
},
set: function (value) {
2022-07-26 11:08:10 +03:00
console.log('### computed update data', value)
2022-07-26 10:11:29 +03:00
this.$emit('update:data', value)
}
}
},
data: function () {
return {
DUST_LIMIT: 546,
2022-07-26 10:11:29 +03:00
paymentTable: {
columns: [
{
name: 'data',
align: 'left'
}
],
pagination: {
rowsPerPage: 10
},
filter: ''
}
}
},
methods: {
satBtc(val, showUnit = true) {
return satOrBtc(val, showUnit, this['sats_denominated'])
},
addPaymentAddress: function () {
this.dataLocal.push({address: '', amount: undefined})
},
deletePaymentAddress: function (v) {
const index = this.dataLocal.indexOf(v)
if (index !== -1) {
this.dataLocal.splice(index, 1)
}
},
2022-07-26 14:09:16 +03:00
sendMaxToAddress: function (paymentAddress = {}) {
const feeValue = this.feeRate * this.txSize
const inputAmount = this.selectedAmount
const currentAmount = Math.max(0, paymentAddress.amount || 0)
const payedAmount = this.getTotalPaymentAmount() - currentAmount
paymentAddress.amount = Math.max(
0,
inputAmount - payedAmount - feeValue
)
},
2022-07-26 10:11:29 +03:00
getTotalPaymentAmount: function () {
return this.dataLocal.reduce((t, a) => t + (a.amount || 0), 0)
}
},
2022-07-26 11:31:23 +03:00
created: async function () {}
2022-07-26 10:11:29 +03:00
})
}