/* global _, Vue, moment, LNbits, EventHub, decryptLnurlPayAES */
Vue.component('lnbits-fsat', {
props: {
amount: {
type: Number,
default: 0
}
},
template: '{{ fsat }}',
computed: {
fsat: function () {
return LNbits.utils.formatSat(this.amount)
}
}
})
Vue.component('lnbits-wallet-list', {
data: function () {
return {
user: null,
activeWallet: null,
activeBalance: [],
showForm: false,
walletName: '',
LNBITS_DENOMINATION: LNBITS_DENOMINATION
}
},
template: `
Wallets
{{ wallet.name }}
{{ parseFloat(String(wallet.live_fsat).replaceAll(",", "")) / 100 }} {{ LNBITS_DENOMINATION }}
{{ wallet.live_fsat }} {{ LNBITS_DENOMINATION }}
Add a wallet
`,
computed: {
wallets: function () {
var bal = this.activeBalance
return this.user.wallets.map(function (obj) {
obj.live_fsat =
bal.length && bal[0] === obj.id
? LNbits.utils.formatSat(bal[1])
: obj.fsat
return obj
})
}
},
methods: {
createWallet: function () {
LNbits.href.createWallet(this.walletName, this.user.id)
},
updateWalletBalance: function (payload) {
this.activeBalance = payload
}
},
created: function () {
if (window.user) {
this.user = LNbits.map.user(window.user)
}
if (window.wallet) {
this.activeWallet = LNbits.map.wallet(window.wallet)
}
EventHub.$on('update-wallet-balance', this.updateWalletBalance)
}
})
Vue.component('lnbits-extension-list', {
data: function () {
return {
extensions: [],
user: null
}
},
template: `
Extensions
{{ extension.name }}
Manage extensions
`,
computed: {
userExtensions: function () {
if (!this.user) return []
var path = window.location.pathname
var userExtensions = this.user.extensions
return this.extensions
.filter(function (obj) {
return userExtensions.indexOf(obj.code) !== -1
})
.map(function (obj) {
obj.isActive = path.startsWith(obj.url)
return obj
})
}
},
created: function () {
if (window.extensions) {
this.extensions = window.extensions
.map(function (data) {
return LNbits.map.extension(data)
})
.sort(function (a, b) {
return a.name.localeCompare(b.name)
})
}
if (window.user) {
this.user = LNbits.map.user(window.user)
}
}
})
Vue.component('lnbits-payment-details', {
props: ['payment'],
data: function () {
return {
LNBITS_DENOMINATION: LNBITS_DENOMINATION
}
},
template: `
#{{ payment.tag }}
Created:
{{ payment.date }} ({{ payment.dateFrom }})
Expiry:
{{ payment.expirydate }} ({{ payment.expirydateFrom }})
Description:
{{ payment.memo }}
Amount:
{{ (payment.amount / 1000).toFixed(3) }} {{LNBITS_DENOMINATION}}
Fee:
{{ (payment.fee / 1000).toFixed(3) }} {{LNBITS_DENOMINATION}}
Payment hash:
{{ payment.payment_hash }}
Webhook:
{{ payment.webhook }}
{{ webhookStatusText }}
Payment proof:
{{ payment.preimage }}
extra
{{ entry.key }}:
{{ entry.value }}
`,
computed: {
hasPreimage() {
return (
this.payment.preimage &&
this.payment.preimage !==
'0000000000000000000000000000000000000000000000000000000000000000'
)
},
hasSuccessAction() {
return (
this.hasPreimage &&
this.payment.extra &&
this.payment.extra.success_action
)
},
webhookStatusColor() {
return this.payment.webhook_status >= 300 ||
this.payment.webhook_status < 0
? 'red-10'
: !this.payment.webhook_status
? 'cyan-7'
: 'green-10'
},
webhookStatusText() {
return this.payment.webhook_status
? this.payment.webhook_status
: 'not sent yet'
},
hasTag() {
return this.payment.extra && !!this.payment.extra.tag
},
extras() {
if (!this.payment.extra) return []
let extras = _.omit(this.payment.extra, ['tag', 'success_action'])
return Object.keys(extras).map(key => ({key, value: extras[key]}))
}
}
})
Vue.component('lnbits-lnurlpay-success-action', {
props: ['payment', 'success_action'],
data() {
return {
decryptedValue: this.success_action.ciphertext
}
},
template: `
`,
mounted: function () {
if (this.success_action.tag !== 'aes') return null
decryptLnurlPayAES(this.success_action, this.payment.preimage).then(
value => {
this.decryptedValue = value
}
)
}
})