chore: clean up javascript functions and var/let into const (#2791)

* chore: clean up javascript functions and var/let into const
This commit is contained in:
dni ⚡
2024-12-10 13:42:01 +01:00
committed by GitHub
parent d1cc317044
commit 8f290a647d
14 changed files with 226 additions and 281 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
window.app = Vue.createApp({
el: '#vue',
mixins: [window.windowMixin],
data: function () {
data() {
return {
user: null,
hasUsername: false,
@@ -25,21 +25,21 @@ window.app = Vue.createApp({
}
},
methods: {
activeLanguage: function (lang) {
activeLanguage(lang) {
return window.i18n.global.locale === lang
},
changeLanguage: function (newValue) {
changeLanguage(newValue) {
window.i18n.global.locale = newValue
this.$q.localStorage.set('lnbits.lang', newValue)
},
toggleDarkMode: function () {
toggleDarkMode() {
this.$q.dark.toggle()
this.$q.localStorage.set('lnbits.darkMode', this.$q.dark.isActive)
if (!this.$q.dark.isActive && this.gradientChoice) {
this.toggleGradient()
}
},
applyGradient: function () {
applyGradient() {
darkBgColor = this.$q.localStorage.getItem('lnbits.darkBgColor')
primaryColor = this.$q.localStorage.getItem('lnbits.primaryColor')
if (this.gradientChoice) {
@@ -64,8 +64,7 @@ window.app = Vue.createApp({
this.$q.localStorage.set('lnbits.gradientBg', false)
}
},
applyBorder: function () {
slef = this
applyBorder() {
if (this.borderChoice) {
this.$q.localStorage.setItem('lnbits.border', this.borderChoice)
}
@@ -85,7 +84,7 @@ window.app = Vue.createApp({
style.innerHTML = `body[data-theme="${this.$q.localStorage.getItem('lnbits.theme')}"] .q-card.q-card--dark, .q-date--dark { ${borderStyleCSS} }`
document.head.appendChild(style)
},
toggleGradient: function () {
toggleGradient() {
this.gradientChoice = !this.gradientChoice
this.applyGradient()
if (!this.gradientChoice) {
@@ -93,10 +92,10 @@ window.app = Vue.createApp({
}
this.gradientChoice = this.$q.localStorage.getItem('lnbits.gradientBg')
},
reactionChoiceFunc: function () {
reactionChoiceFunc() {
this.$q.localStorage.set('lnbits.reactions', this.reactionChoice)
},
changeColor: function (newValue) {
changeColor(newValue) {
document.body.setAttribute('data-theme', newValue)
this.$q.localStorage.set('lnbits.theme', newValue)
this.setColors()
@@ -104,7 +103,7 @@ window.app = Vue.createApp({
this.applyGradient()
}
},
updateAccount: async function () {
async updateAccount() {
try {
const {data} = await LNbits.api.request(
'PUT',
@@ -127,7 +126,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(e)
}
},
disableUpdatePassword: function () {
disableUpdatePassword() {
return (
!this.credentialsData.newPassword ||
!this.credentialsData.newPasswordRepeat ||
@@ -135,7 +134,7 @@ window.app = Vue.createApp({
this.credentialsData.newPasswordRepeat
)
},
updatePassword: async function () {
async updatePassword() {
if (!this.credentialsData.username) {
Quasar.Notify.create({
type: 'warning',
@@ -167,7 +166,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(e)
}
},
updatePubkey: async function () {
async updatePubkey() {
try {
const {data} = await LNbits.api.request(
'PUT',
@@ -189,7 +188,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(e)
}
},
showUpdateCredentials: function () {
showUpdateCredentials() {
this.credentialsData = {
show: true,
oldPassword: null,
@@ -200,7 +199,7 @@ window.app = Vue.createApp({
}
}
},
created: async function () {
async created() {
try {
const {data} = await LNbits.api.getAuthenticatedUser()
this.user = data

View File

@@ -1,7 +1,7 @@
window.app = Vue.createApp({
el: '#vue',
mixins: [windowMixin],
data: function () {
data() {
return {
settings: {},
logs: [],
@@ -258,9 +258,7 @@ window.app = Vue.createApp({
})
this.needsRestart = false
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
formatDate(date) {
return moment(date * 1000).fromNow()
@@ -286,9 +284,7 @@ window.app = Vue.createApp({
.then(response => {
this.auditData = response.data
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
getSettings() {
LNbits.api
@@ -303,12 +299,10 @@ window.app = Vue.createApp({
this.formData = {...this.settings}
this.getNotifications()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
updateSettings() {
let data = _.omit(this.formData, [
const data = _.omit(this.formData, [
'is_super_user',
'lnbits_allowed_funding_sources'
])
@@ -334,9 +328,7 @@ window.app = Vue.createApp({
icon: null
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
deleteSettings() {
LNbits.utils
@@ -353,9 +345,7 @@ window.app = Vue.createApp({
})
this.needsRestart = true
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
})
},
downloadBackup() {

View File

@@ -1,7 +1,7 @@
window.app = Vue.createApp({
el: '#vue',
mixins: [window.windowMixin],
data: function () {
data() {
return {
auditEntries: [],
searchData: {

View File

@@ -8,7 +8,7 @@ window.i18n = new VueI18n.createI18n({
window.LNbits = {
api: {
request: function (method, url, apiKey, data) {
request(method, url, apiKey, data) {
return axios({
method: method,
url: url,
@@ -18,10 +18,10 @@ window.LNbits = {
data: data
})
},
getServerHealth: function () {
getServerHealth() {
return this.request('get', '/api/v1/health')
},
createInvoice: async function (
async createInvoice(
wallet,
amount,
memo,
@@ -36,13 +36,13 @@ window.LNbits = {
unit: unit
})
},
payInvoice: function (wallet, bolt11) {
payInvoice(wallet, bolt11) {
return this.request('post', '/api/v1/payments', wallet.adminkey, {
out: true,
bolt11: bolt11
})
},
payLnurl: function (
payLnurl(
wallet,
callback,
description_hash,
@@ -60,17 +60,17 @@ window.LNbits = {
unit
})
},
authLnurl: function (wallet, callback) {
authLnurl(wallet, callback) {
return this.request('post', '/api/v1/lnurlauth', wallet.adminkey, {
callback
})
},
createAccount: function (name) {
createAccount(name) {
return this.request('post', '/api/v1/account', null, {
name: name
})
},
register: function (username, email, password, password_repeat) {
register(username, email, password, password_repeat) {
return axios({
method: 'POST',
url: '/api/v1/auth/register',
@@ -82,7 +82,7 @@ window.LNbits = {
}
})
},
reset: function (reset_key, password, password_repeat) {
reset(reset_key, password, password_repeat) {
return axios({
method: 'PUT',
url: '/api/v1/auth/reset',
@@ -93,14 +93,14 @@ window.LNbits = {
}
})
},
login: function (username, password) {
login(username, password) {
return axios({
method: 'POST',
url: '/api/v1/auth',
data: {username, password}
})
},
loginByProvider: function (provider, headers, data) {
loginByProvider(provider, headers, data) {
return axios({
method: 'POST',
url: `/api/v1/auth/${provider}`,
@@ -108,38 +108,38 @@ window.LNbits = {
data
})
},
loginUsr: function (usr) {
loginUsr(usr) {
return axios({
method: 'POST',
url: '/api/v1/auth/usr',
data: {usr}
})
},
logout: function () {
logout() {
return axios({
method: 'POST',
url: '/api/v1/auth/logout'
})
},
getAuthenticatedUser: function () {
getAuthenticatedUser() {
return this.request('get', '/api/v1/auth')
},
getWallet: function (wallet) {
getWallet(wallet) {
return this.request('get', '/api/v1/wallet', wallet.inkey)
},
createWallet: function (wallet, name) {
createWallet(wallet, name) {
return this.request('post', '/api/v1/wallet', wallet.adminkey, {
name: name
}).then(res => {
window.location = '/wallet?wal=' + res.data.id
})
},
updateWallet: function (name, wallet) {
updateWallet(name, wallet) {
return this.request('patch', '/api/v1/wallet', wallet.adminkey, {
name: name
})
},
deleteWallet: function (wallet) {
deleteWallet(wallet) {
return this.request('delete', '/api/v1/wallet', wallet.adminkey).then(
_ => {
let url = new URL(window.location.href)
@@ -148,21 +148,21 @@ window.LNbits = {
}
)
},
getPayments: function (wallet, params) {
getPayments(wallet, params) {
return this.request(
'get',
'/api/v1/payments/paginated?' + params,
wallet.inkey
)
},
getPayment: function (wallet, paymentHash) {
getPayment(wallet, paymentHash) {
return this.request(
'get',
'/api/v1/payments/' + paymentHash,
wallet.inkey
)
},
updateBalance: function (credit, wallet_id) {
updateBalance(credit, wallet_id) {
return this.request('PUT', '/users/api/v1/topup', null, {
amount: credit,
id: wallet_id
@@ -175,7 +175,7 @@ window.LNbits = {
}
},
events: {
onInvoicePaid: function (wallet, cb) {
onInvoicePaid(wallet, cb) {
let listener = ev => {
cb(JSON.parse(ev.data))
}
@@ -209,12 +209,12 @@ window.LNbits = {
}
},
map: {
extension: function (data) {
extension(data) {
const obj = {...data}
obj.url = ['/', obj.code, '/'].join('')
return obj
},
user: function (data) {
user(data) {
const obj = {
id: data.id,
admin: data.admin,
@@ -225,13 +225,13 @@ window.LNbits = {
}
const mapWallet = this.wallet
obj.wallets = obj.wallets
.map(function (obj) {
.map(obj => {
return mapWallet(obj)
})
.sort(function (a, b) {
.sort((a, b) => {
return a.name.localeCompare(b.name)
})
obj.walletOptions = obj.wallets.map(function (obj) {
obj.walletOptions = obj.wallets.map(obj => {
return {
label: [obj.name, ' - ', obj.id].join(''),
value: obj.id
@@ -239,7 +239,7 @@ window.LNbits = {
})
return obj
},
wallet: function (data) {
wallet(data) {
newWallet = {
id: data.id,
name: data.name,
@@ -255,7 +255,7 @@ window.LNbits = {
newWallet.url = `/wallet?&wal=${data.id}`
return newWallet
},
payment: function (data) {
payment(data) {
obj = {
checking_id: data.checking_id,
status: data.status,
@@ -301,7 +301,7 @@ window.LNbits = {
}
},
utils: {
confirmDialog: function (msg) {
confirmDialog(msg) {
return Quasar.Dialog.create({
message: msg,
ok: {
@@ -314,7 +314,7 @@ window.LNbits = {
}
})
},
digestMessage: async function (message) {
async digestMessage(message) {
const msgUint8 = new TextEncoder().encode(message)
const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8)
const hashArray = Array.from(new Uint8Array(hashBuffer))
@@ -332,19 +332,19 @@ window.LNbits = {
formatDateString(isoDateString) {
return Quasar.date.formatDate(new Date(isoDateString), window.dateFormat)
},
formatCurrency: function (value, currency) {
formatCurrency(value, currency) {
return new Intl.NumberFormat(window.LOCALE, {
style: 'currency',
currency: currency
}).format(value)
},
formatSat: function (value) {
formatSat(value) {
return new Intl.NumberFormat(window.LOCALE).format(value)
},
formatMsat: function (value) {
formatMsat(value) {
return this.formatSat(value / 1000)
},
notifyApiError: function (error) {
notifyApiError(error) {
if (!error.response) {
return console.error(error)
}
@@ -365,12 +365,12 @@ window.LNbits = {
icon: null
})
},
search: function (data, q, field, separator) {
search(data, q, field, separator) {
try {
const queries = q.toLowerCase().split(separator || ' ')
return data.filter(function (obj) {
return data.filter(obj => {
let matches = 0
_.each(queries, function (q) {
_.each(queries, q => {
if (obj[field].indexOf(q) !== -1) matches++
})
return matches === queries.length
@@ -384,7 +384,7 @@ window.LNbits = {
tableConfig.pagination = props.pagination
tableConfig.filter = props.filter
}
let pagination = tableConfig.pagination
const pagination = tableConfig.pagination
tableConfig.loading = true
const query = {
limit: pagination.rowsPerPage,
@@ -398,8 +398,8 @@ window.LNbits = {
}
return new URLSearchParams(query)
},
exportCSV: function (columns, data, fileName) {
const wrapCsvValue = function (val, formatFn) {
exportCSV(columns, data, fileName) {
const wrapCsvValue = (val, formatFn) => {
let formatted = formatFn !== void 0 ? formatFn(val) : val
formatted =
@@ -411,14 +411,14 @@ window.LNbits = {
}
const content = [
columns.map(function (col) {
columns.map(col => {
return wrapCsvValue(col.label)
})
]
.concat(
data.map(function (row) {
data.map(row => {
return columns
.map(function (col) {
.map(col => {
return wrapCsvValue(
typeof col.field === 'function'
? col.field(row)
@@ -451,16 +451,16 @@ window.LNbits = {
converter.setOption('simpleLineBreaks', true)
return converter.makeHtml(text)
},
hexToRgb: function (hex) {
hexToRgb(hex) {
return Quasar.colors.hexToRgb(hex)
},
hexDarken: function (hex, percent) {
hexDarken(hex, percent) {
return Quasar.colors.lighten(hex, percent)
},
hexAlpha: function (hex, alpha) {
hexAlpha(hex, alpha) {
return Quasar.colors.changeAlpha(hex, alpha)
},
getPaletteColor: function (color) {
getPaletteColor(color) {
return Quasar.colors.getPaletteColor(color)
}
}
@@ -468,7 +468,7 @@ window.LNbits = {
window.windowMixin = {
i18n: window.i18n,
data: function () {
data() {
return {
toggleSubs: true,
reactionChoice: 'confettiBothSides',
@@ -490,11 +490,11 @@ window.windowMixin = {
},
methods: {
changeColor: function (newValue) {
changeColor(newValue) {
document.body.setAttribute('data-theme', newValue)
this.$q.localStorage.set('lnbits.theme', newValue)
},
applyGradient: function () {
applyGradient() {
if (this.$q.localStorage.getItem('lnbits.gradientBg')) {
this.setColors()
darkBgColor = this.$q.localStorage.getItem('lnbits.darkBgColor')
@@ -514,7 +514,7 @@ window.windowMixin = {
document.head.appendChild(style)
}
},
applyBorder: function () {
applyBorder() {
if (this.borderChoice) {
this.$q.localStorage.setItem('lnbits.border', this.borderChoice)
}
@@ -538,7 +538,7 @@ window.windowMixin = {
style.innerHTML = `body[data-theme="${this.$q.localStorage.getItem('lnbits.theme')}"] .q-card.q-card--dark, .q-date--dark { ${borderStyleCSS} }`
document.head.appendChild(style)
},
setColors: function () {
setColors() {
this.$q.localStorage.set(
'lnbits.primaryColor',
LNbits.utils.getPaletteColor('primary')
@@ -552,15 +552,15 @@ window.windowMixin = {
LNbits.utils.getPaletteColor('dark')
)
},
copyText: function (text, message, position) {
Quasar.copyToClipboard(text).then(function () {
copyText(text, message, position) {
Quasar.copyToClipboard(text).then(() => {
Quasar.Notify.create({
message: message || 'Copied to clipboard!',
position: position || 'bottom'
})
})
},
checkUsrInUrl: async function () {
async checkUsrInUrl() {
try {
const params = new URLSearchParams(window.location.search)
const usr = params.get('usr')
@@ -586,7 +586,7 @@ window.windowMixin = {
)
}
},
logout: async function () {
async logout() {
LNbits.utils
.confirmDialog(
'Do you really want to logout?' +
@@ -652,7 +652,7 @@ window.windowMixin = {
this.setColors()
}
},
created: async function () {
async created() {
if (
this.$q.localStorage.getItem('lnbits.darkMode') == true ||
this.$q.localStorage.getItem('lnbits.darkMode') == false
@@ -721,7 +721,7 @@ window.windowMixin = {
}
}
window.decryptLnurlPayAES = function (success_action, preimage) {
window.decryptLnurlPayAES = (success_action, preimage) => {
let keyb = new Uint8Array(
preimage.match(/[\da-f]{2}/gi).map(h => parseInt(h, 16))
)

View File

@@ -15,7 +15,7 @@ window.app.component('lnbits-fsat', {
}
},
computed: {
fsat: function () {
fsat() {
return LNbits.utils.formatSat(this.amount)
}
}
@@ -24,7 +24,7 @@ window.app.component('lnbits-fsat', {
window.app.component('lnbits-wallet-list', {
template: '#lnbits-wallet-list',
props: ['balance'],
data: function () {
data() {
return {
user: null,
activeWallet: null,
@@ -35,9 +35,9 @@ window.app.component('lnbits-wallet-list', {
}
},
computed: {
wallets: function () {
var bal = this.balance
return this.user.wallets.map(function (obj) {
wallets() {
const bal = this.balance
return this.user.wallets.map(obj => {
obj.live_fsat =
bal.length && bal[0] === obj.id
? LNbits.utils.formatSat(bal[1])
@@ -47,11 +47,11 @@ window.app.component('lnbits-wallet-list', {
}
},
methods: {
createWallet: function () {
createWallet() {
LNbits.api.createWallet(this.user.wallets[0], this.walletName)
}
},
created: function () {
created() {
if (window.user) {
this.user = LNbits.map.user(window.user)
}
@@ -64,7 +64,7 @@ window.app.component('lnbits-wallet-list', {
window.app.component('lnbits-extension-list', {
template: '#lnbits-extension-list',
data: function () {
data() {
return {
extensions: [],
user: null,
@@ -78,17 +78,17 @@ window.app.component('lnbits-extension-list', {
}
},
methods: {
updateUserExtensions: function (filterBy) {
updateUserExtensions(filterBy) {
if (!this.user) return []
const path = window.location.pathname
const userExtensions = this.user.extensions
return this.extensions
.filter(function (o) {
.filter(o => {
return userExtensions.indexOf(o.code) !== -1
})
.filter(function (o) {
.filter(o => {
if (!filterBy) return true
return (
`${o.code} ${o.name} ${o.short_description} ${o.url}`
@@ -96,13 +96,13 @@ window.app.component('lnbits-extension-list', {
.indexOf(filterBy.toLocaleLowerCase()) !== -1
)
})
.map(function (obj) {
.map(obj => {
obj.isActive = path.startsWith(obj.url)
return obj
})
}
},
created: async function () {
async created() {
if (window.user) {
this.user = LNbits.map.user(window.user)
}
@@ -110,10 +110,10 @@ window.app.component('lnbits-extension-list', {
try {
const {data} = await LNbits.api.request('GET', '/api/v1/extension')
this.extensions = data
.map(function (data) {
.map(data => {
return LNbits.map.extension(data)
})
.sort(function (a, b) {
.sort((a, b) => {
return a.name.localeCompare(b.name)
})
this.userExtensions = this.updateUserExtensions()
@@ -127,7 +127,7 @@ window.app.component('lnbits-manage', {
template: '#lnbits-manage',
props: ['showAdmin', 'showNode', 'showExtensions', 'showUsers', 'showAudit'],
methods: {
isActive: function (path) {
isActive(path) {
return window.location.pathname === path
}
},
@@ -148,7 +148,7 @@ window.app.component('lnbits-payment-details', {
template: '#lnbits-payment-details',
props: ['payment'],
mixins: [window.windowMixin],
data: function () {
data() {
return {
LNBITS_DENOMINATION: LNBITS_DENOMINATION
}
@@ -203,7 +203,7 @@ window.app.component('lnbits-lnurlpay-success-action', {
decryptedValue: this.success_action.ciphertext
}
},
mounted: function () {
mounted() {
if (this.success_action.tag !== 'aes') return null
decryptLnurlPayAES(this.success_action, this.payment.preimage).then(
value => {
@@ -302,8 +302,6 @@ window.app.component('lnbits-notifications-btn', {
return subscribedUsers.includes(user)
},
subscribe() {
var self = this
// catch clicks from disabled type='a' button (https://github.com/quasarframework/quasar/issues/9258)
if (!this.isSupported || this.isPermissionDenied) {
return
@@ -315,56 +313,48 @@ window.app.component('lnbits-notifications-btn', {
this.isPermissionGranted = permission === 'granted'
this.isPermissionDenied = permission === 'denied'
})
.catch(function (e) {
console.log(e)
})
.catch(console.log)
// create push subscription
navigator.serviceWorker.ready.then(registration => {
navigator.serviceWorker.getRegistration().then(registration => {
registration.pushManager
.getSubscription()
.then(function (subscription) {
.then(subscription => {
if (
subscription === null ||
!self.isUserSubscribed(self.g.user.id)
!this.isUserSubscribed(this.g.user.id)
) {
const applicationServerKey = self.urlB64ToUint8Array(
self.pubkey
const applicationServerKey = this.urlB64ToUint8Array(
this.pubkey
)
const options = {applicationServerKey, userVisibleOnly: true}
registration.pushManager
.subscribe(options)
.then(function (subscription) {
.then(subscription => {
LNbits.api
.request(
'POST',
'/api/v1/webpush',
self.g.user.wallets[0].adminkey,
this.g.user.wallets[0].adminkey,
{
subscription: JSON.stringify(subscription)
}
)
.then(function (response) {
self.saveUserSubscribed(response.data.user)
self.isSubscribed = true
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
.then(response => {
this.saveUserSubscribed(response.data.user)
this.isSubscribed = true
})
.catch(LNbits.utils.notifyApiError)
})
}
})
.catch(function (e) {
console.log(e)
})
.catch(console.log)
})
})
},
unsubscribe() {
var self = this
navigator.serviceWorker.ready
.then(registration => {
registration.pushManager.getSubscription().then(subscription => {
@@ -373,23 +363,19 @@ window.app.component('lnbits-notifications-btn', {
.request(
'DELETE',
'/api/v1/webpush?endpoint=' + btoa(subscription.endpoint),
self.g.user.wallets[0].adminkey
this.g.user.wallets[0].adminkey
)
.then(function () {
self.removeUserSubscribed(self.g.user.id)
self.isSubscribed = false
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
.then(() => {
this.removeUserSubscribed(this.g.user.id)
this.isSubscribed = false
})
.catch(LNbits.utils.notifyApiError)
}
})
})
.catch(function (e) {
console.log(e)
})
.catch(console.log)
},
checkSupported: function () {
checkSupported() {
let https = window.location.protocol === 'https:'
let serviceWorkerApi = 'serviceWorker' in navigator
let notificationApi = 'Notification' in window
@@ -411,22 +397,18 @@ window.app.component('lnbits-notifications-btn', {
return this.isSupported
},
updateSubscriptionStatus: async function () {
var self = this
async updateSubscriptionStatus() {
await navigator.serviceWorker.ready
.then(registration => {
registration.pushManager.getSubscription().then(subscription => {
self.isSubscribed =
!!subscription && self.isUserSubscribed(self.g.user.id)
this.isSubscribed =
!!subscription && this.isUserSubscribed(this.g.user.id)
})
})
.catch(function (e) {
console.log(e)
})
.catch(console.log)
}
},
created: function () {
created() {
this.isPermissionDenied = Notification.permission === 'denied'
if (this.checkSupported()) {
@@ -511,13 +493,13 @@ window.app.component('lnbits-update-balance', {
return user.super_user
}
},
data: function () {
data() {
return {
credit: 0
}
},
methods: {
updateBalance: function (credit) {
updateBalance(credit) {
LNbits.api
.updateBalance(credit, this.wallet_id)
.then(res => {
@@ -541,9 +523,7 @@ window.app.component('lnbits-update-balance', {
})
return credit
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
}
}
})

View File

@@ -22,7 +22,7 @@ window.app.component('lnbits-extension-settings-form', {
LNbits.utils.notifyApiError(error)
}
},
getSettings: async function () {
async getSettings() {
try {
const {data} = await LNbits.api.request(
'GET',
@@ -34,7 +34,7 @@ window.app.component('lnbits-extension-settings-form', {
LNbits.utils.notifyApiError(error)
}
},
resetSettings: async function () {
async resetSettings() {
LNbits.utils
.confirmDialog('Are you sure you want to reset the settings?')
.onOk(async () => {
@@ -47,10 +47,10 @@ window.app.component('lnbits-extension-settings-form', {
})
}
},
created: async function () {
async created() {
await this.getSettings()
},
data: function () {
data() {
return {
settings: undefined
}
@@ -61,7 +61,7 @@ window.app.component('lnbits-extension-settings-btn-dialog', {
template: '#lnbits-extension-settings-btn-dialog',
name: 'lnbits-extension-settings-btn-dialog',
props: ['options', 'adminkey', 'endpoint'],
data: function () {
data() {
return {
show: false
}

View File

@@ -85,7 +85,7 @@ window.app.component('payment-chart', {
name: 'payment-chart',
props: ['wallet'],
mixins: [window.windowMixin],
data: function () {
data() {
return {
paymentsChart: {
show: false,
@@ -105,7 +105,7 @@ window.app.component('payment-chart', {
}
},
methods: {
showChart: function () {
showChart() {
this.paymentsChart.show = true
LNbits.api
.request(

View File

@@ -3,7 +3,7 @@ window.app.component('payment-list', {
template: '#payment-list',
props: ['update', 'wallet', 'mobileSimple', 'lazy'],
mixins: [window.windowMixin],
data: function () {
data() {
return {
denomination: LNBITS_DENOMINATION,
failedPaymentsToggle: false,
@@ -116,8 +116,8 @@ window.app.component('payment-list', {
}
},
computed: {
filteredPayments: function () {
var q = this.paymentsTable.search
filteredPayments() {
const q = this.paymentsTable.search
if (!q || q === '') return this.payments
return LNbits.utils.search(this.payments, q)
@@ -128,12 +128,12 @@ window.app.component('payment-list', {
}
return this.payments
},
pendingPaymentsExist: function () {
pendingPaymentsExist() {
return this.payments.findIndex(payment => payment.pending) !== -1
}
},
methods: {
fetchPayments: function (props) {
fetchPayments(props) {
const params = LNbits.utils.prepareFilterQuery(this.paymentsTable, props)
return LNbits.api
.getPayments(this.wallet, params)
@@ -149,7 +149,7 @@ window.app.component('payment-list', {
LNbits.utils.notifyApiError(err)
})
},
paymentTableRowKey: function (row) {
paymentTableRowKey(row) {
return row.payment_hash + row.amount
},
exportCSV(detailed = false) {
@@ -194,7 +194,7 @@ window.app.component('payment-list', {
)
})
},
addFilterTag: function () {
addFilterTag() {
if (!this.exportTagName) return
const value = this.exportTagName.trim()
this.exportPaymentTagList = this.exportPaymentTagList.filter(
@@ -203,12 +203,12 @@ window.app.component('payment-list', {
this.exportPaymentTagList.push(value)
this.exportTagName = ''
},
removeExportTag: function (value) {
removeExportTag(value) {
this.exportPaymentTagList = this.exportPaymentTagList.filter(
v => v !== value
)
},
formatCurrency: function (amount, currency) {
formatCurrency(amount, currency) {
try {
return LNbits.utils.formatCurrency(amount, currency)
} catch (e) {
@@ -228,14 +228,14 @@ window.app.component('payment-list', {
}
this.fetchPayments()
},
lazy: function (newVal) {
lazy(newVal) {
if (newVal === true) this.fetchPayments()
},
update: function () {
update() {
this.fetchPayments()
}
},
created: function () {
created() {
if (this.lazy === undefined) this.fetchPayments()
}
})

View File

@@ -1,7 +1,7 @@
window.app = Vue.createApp({
el: '#vue',
mixins: [window.windowMixin],
data: function () {
data() {
return {
disclaimerDialog: {
show: false,
@@ -30,11 +30,11 @@ window.app = Vue.createApp({
}
},
methods: {
showLogin: function (authMethod) {
showLogin(authMethod) {
this.authAction = 'login'
this.authMethod = authMethod
},
showRegister: function (authMethod) {
showRegister(authMethod) {
this.user = ''
this.username = null
this.password = null
@@ -43,7 +43,7 @@ window.app = Vue.createApp({
this.authAction = 'register'
this.authMethod = authMethod
},
signInWithNostr: async function () {
async signInWithNostr() {
try {
const nostrToken = await this.createNostrToken()
if (!nostrToken) {
@@ -65,7 +65,7 @@ window.app = Vue.createApp({
})
}
},
createNostrToken: async function () {
async createNostrToken() {
try {
async function _signEvent(e) {
try {
@@ -116,7 +116,7 @@ window.app = Vue.createApp({
})
}
},
register: async function () {
async register() {
try {
await LNbits.api.register(
this.username,
@@ -129,7 +129,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(e)
}
},
reset: async function () {
async reset() {
try {
await LNbits.api.reset(
this.reset_key,
@@ -141,7 +141,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(e)
}
},
login: async function () {
async login() {
try {
await LNbits.api.login(this.username, this.password)
window.location.href = '/wallet'
@@ -149,7 +149,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(e)
}
},
loginUsr: async function () {
async loginUsr() {
try {
await LNbits.api.loginUsr(this.usr)
this.usr = ''
@@ -159,19 +159,19 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(e)
}
},
createWallet: function () {
createWallet() {
LNbits.api.createAccount(this.walletName).then(res => {
window.location = '/wallet?usr=' + res.data.user + '&wal=' + res.data.id
})
},
processing: function () {
processing() {
Quasar.Notify.create({
timeout: 0,
message: 'Processing...',
icon: null
})
},
validateUsername: function (val) {
validateUsername(val) {
const usernameRegex = new RegExp(
'^(?=[a-zA-Z0-9._]{2,20}$)(?!.*[_.]{2})[^_.].*[^_.]$'
)

View File

@@ -1,6 +1,6 @@
window.app.component('lnbits-node-ranks', {
props: ['ranks'],
data: function () {
data() {
return {
user: {},
stats: [
@@ -31,7 +31,7 @@ window.app.component('lnbits-node-ranks', {
window.app.component('lnbits-channel-stats', {
props: ['stats'],
data: function () {
data() {
return {
states: [
{label: 'Active', value: 'active', color: 'green'},
@@ -58,7 +58,7 @@ window.app.component('lnbits-channel-stats', {
</div>
</q-card>
`,
created: function () {
created() {
if (window.user) {
this.user = LNbits.map.user(window.user)
}
@@ -68,7 +68,7 @@ window.app.component('lnbits-channel-stats', {
window.app.component('lnbits-stat', {
props: ['title', 'amount', 'msat', 'btc'],
computed: {
value: function () {
value() {
return (
this.amount ??
(this.btc
@@ -178,7 +178,7 @@ window.app.component('lnbits-node-info', {
window.app.component('lnbits-stat', {
props: ['title', 'amount', 'msat', 'btc'],
computed: {
value: function () {
value() {
return (
this.amount ??
(this.btc
@@ -206,7 +206,7 @@ window.app.component('lnbits-stat', {
window.app.component('lnbits-channel-balance', {
props: ['balance', 'color'],
methods: {
formatMsat: function (msat) {
formatMsat(msat) {
return LNbits.utils.formatMsat(msat)
}
},
@@ -247,10 +247,10 @@ window.app.component('lnbits-channel-balance', {
window.app.component('lnbits-date', {
props: ['ts'],
computed: {
date: function () {
date() {
return LNbits.utils.formatDate(this.ts)
},
dateFrom: function () {
dateFrom() {
return moment(this.date).fromNow()
}
},

View File

@@ -1,7 +1,7 @@
window.app = Vue.createApp({
el: '#vue',
mixins: [window.windowMixin],
data: function () {
data() {
return {
paymentsWallet: {},
wallet: {},
@@ -175,7 +175,7 @@ window.app = Vue.createApp({
formatDate(date) {
return LNbits.utils.formatDateString(date)
},
formatSat: function (value) {
formatSat(value) {
return LNbits.utils.formatSat(Math.floor(value / 1000))
},
backToUsersPage() {
@@ -197,9 +197,7 @@ window.app = Vue.createApp({
this.copyText(url)
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
createUser() {
LNbits.api
@@ -215,9 +213,7 @@ window.app = Vue.createApp({
this.activeUser.data = resp.data
this.fetchUsers()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
updateUser() {
LNbits.api
@@ -237,9 +233,7 @@ window.app = Vue.createApp({
this.activeUser.show = false
this.fetchUsers()
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
createWallet() {
const userId = this.activeWallet.userId
@@ -265,9 +259,7 @@ window.app = Vue.createApp({
message: 'Wallet created!'
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
deleteUser(user_id) {
LNbits.utils
@@ -285,9 +277,7 @@ window.app = Vue.createApp({
this.activeUser.data = null
this.activeUser.show = false
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
})
},
undeleteUserWallet(user_id, wallet) {
@@ -304,9 +294,7 @@ window.app = Vue.createApp({
icon: null
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
deleteUserWallet(user_id, wallet, deleted) {
const dialogText = deleted
@@ -323,9 +311,7 @@ window.app = Vue.createApp({
icon: null
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
})
},
copyWalletLink(walletId) {
@@ -342,9 +328,7 @@ window.app = Vue.createApp({
this.usersTable.pagination.rowsNumber = res.data.total
this.users = res.data.data
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
fetchWallets(userId) {
LNbits.api
@@ -354,9 +338,7 @@ window.app = Vue.createApp({
this.activeWallet.userId = userId
this.activeWallet.show = true
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
toggleAdmin(userId) {
@@ -370,9 +352,7 @@ window.app = Vue.createApp({
icon: null
})
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
exportUsers() {
console.log('export users')
@@ -438,9 +418,7 @@ window.app = Vue.createApp({
this.wallet = {}
this.fetchWallets(this.activeWallet.userId)
})
.catch(function (error) {
LNbits.utils.notifyApiError(error)
})
.catch(LNbits.utils.notifyApiError)
},
searchUserBy(fieldName) {
const fieldValue = this.searchData[fieldName]

View File

@@ -1,7 +1,7 @@
window.app = Vue.createApp({
el: '#vue',
mixins: [window.windowMixin],
data: function () {
data() {
return {
updatePayments: false,
origin: window.location.origin,
@@ -63,7 +63,7 @@ window.app = Vue.createApp({
}
},
computed: {
formattedBalance: function () {
formattedBalance() {
if (LNBITS_DENOMINATION != 'sats') {
return this.balance / 100
} else {
@@ -78,11 +78,11 @@ window.app = Vue.createApp({
)
}
},
canPay: function () {
canPay() {
if (!this.parse.invoice) return false
return this.parse.invoice.sat <= this.balance
},
formattedAmount: function () {
formattedAmount() {
if (this.receive.unit != 'sat') {
return LNbits.utils.formatCurrency(
Number(this.receive.data.amount).toFixed(2),
@@ -92,24 +92,24 @@ window.app = Vue.createApp({
return LNbits.utils.formatMsat(this.receive.amountMsat) + ' sat'
}
},
formattedSatAmount: function () {
formattedSatAmount() {
return LNbits.utils.formatMsat(this.receive.amountMsat) + ' sat'
}
},
methods: {
msatoshiFormat: function (value) {
msatoshiFormat(value) {
return LNbits.utils.formatSat(value / 1000)
},
closeCamera: function () {
closeCamera() {
this.parse.camera.show = false
},
showCamera: function () {
showCamera() {
this.parse.camera.show = true
},
focusInput(el) {
this.$nextTick(() => this.$refs[el].focus())
},
showReceiveDialog: function () {
showReceiveDialog() {
this.receive.show = true
this.receive.status = 'pending'
this.receive.paymentReq = null
@@ -121,12 +121,12 @@ window.app = Vue.createApp({
this.receive.lnurl = null
this.focusInput('setAmount')
},
onReceiveDialogHide: function () {
onReceiveDialogHide() {
if (this.hasNfc) {
this.nfcReaderAbortController.abort()
}
},
showParseDialog: function () {
showParseDialog() {
this.parse.show = true
this.parse.invoice = null
this.parse.lnurlpay = null
@@ -139,19 +139,19 @@ window.app = Vue.createApp({
this.parse.camera.show = false
this.focusInput('textArea')
},
closeParseDialog: function () {
closeParseDialog() {
setTimeout(() => {
clearInterval(this.parse.paymentChecker)
}, 10000)
},
onPaymentReceived: function (paymentHash) {
onPaymentReceived(paymentHash) {
this.updatePayments = !this.updatePayments
if (this.receive.paymentHash === paymentHash) {
this.receive.show = false
this.receive.paymentHash = null
}
},
createInvoice: function () {
createInvoice() {
this.receive.status = 'loading'
if (LNBITS_DENOMINATION != 'sats') {
this.receive.data.amount = this.receive.data.amount * 100
@@ -206,11 +206,11 @@ window.app = Vue.createApp({
this.receive.status = 'pending'
})
},
onInitQR: async function (promise) {
async onInitQR(promise) {
try {
await promise
} catch (error) {
let mapping = {
const mapping = {
NotAllowedError: 'ERROR: you need to grant camera access permission',
NotFoundError: 'ERROR: no camera on this device',
NotSupportedError:
@@ -222,10 +222,10 @@ window.app = Vue.createApp({
InsecureContextError:
'ERROR: Camera access is only permitted in secure context. Use HTTPS or localhost rather than HTTP.'
}
let valid_error = Object.keys(mapping).filter(key => {
const valid_error = Object.keys(mapping).filter(key => {
return error.name === key
})
let camera_error = valid_error
const camera_error = valid_error
? mapping[valid_error]
: `ERROR: Camera error (${error.name})`
this.parse.camera.show = false
@@ -246,7 +246,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(err)
})
.then(response => {
let data = response.data
const data = response.data
if (data.status === 'ERROR') {
Quasar.Notify.create({
@@ -283,15 +283,15 @@ window.app = Vue.createApp({
}
})
},
decodeQR: function (res) {
decodeQR(res) {
this.parse.data.request = res[0].rawValue
this.decodeRequest()
this.parse.camera.show = false
},
decodeRequest: function () {
decodeRequest() {
this.parse.show = true
this.parse.data.request = this.parse.data.request.trim().toLowerCase()
let req = this.parse.data.request
const req = this.parse.data.request
if (req.startsWith('lightning:')) {
this.parse.data.request = req.slice(10)
} else if (req.startsWith('lnurl:')) {
@@ -342,7 +342,7 @@ window.app = Vue.createApp({
} else if (tag.description === 'description') {
cleanInvoice.description = tag.value
} else if (tag.description === 'expiry') {
var expireDate = new Date(
const expireDate = new Date(
(invoice.data.time_stamp + tag.value) * 1000
)
cleanInvoice.expireDate = Quasar.date.formatDate(
@@ -356,8 +356,8 @@ window.app = Vue.createApp({
this.parse.invoice = Object.freeze(cleanInvoice)
},
payInvoice: function () {
let dismissPaymentMsg = Quasar.Notify.create({
payInvoice() {
const dismissPaymentMsg = Quasar.Notify.create({
timeout: 0,
message: this.$t('processing_payment')
})
@@ -389,8 +389,8 @@ window.app = Vue.createApp({
this.parse.show = false
})
},
payLnurl: function () {
let dismissPaymentMsg = Quasar.Notify.create({
payLnurl() {
const dismissPaymentMsg = Quasar.Notify.create({
timeout: 0,
message: 'Processing payment...'
})
@@ -472,8 +472,8 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(err)
})
},
authLnurl: function () {
let dismissAuthMsg = Quasar.Notify.create({
authLnurl() {
const dismissAuthMsg = Quasar.Notify.create({
timeout: 10,
message: 'Performing authentication...'
})
@@ -503,7 +503,7 @@ window.app = Vue.createApp({
}
})
},
updateWallet: function (data) {
updateWallet(data) {
LNbits.api
.request('PATCH', '/api/v1/wallet', this.g.wallet.adminkey, data)
.then(_ => {
@@ -518,7 +518,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(err)
})
},
deleteWallet: function () {
deleteWallet() {
LNbits.utils
.confirmDialog('Are you sure you want to delete this wallet?')
.onOk(() => {
@@ -536,7 +536,7 @@ window.app = Vue.createApp({
})
})
},
fetchBalance: function () {
fetchBalance() {
LNbits.api.getWallet(this.g.wallet).then(response => {
this.balance = Math.floor(response.data.balance / 1000)
document.dispatchEvent(
@@ -561,18 +561,18 @@ window.app = Vue.createApp({
})
.catch(e => console.error(e))
},
updateBalanceCallback: function (res) {
updateBalanceCallback(res) {
if (res.success && wallet.id === res.wallet_id) {
this.balance += res.credit
}
},
pasteToTextArea: function () {
pasteToTextArea() {
this.$refs.textArea.focus() // Set cursor to textarea
navigator.clipboard.readText().then(text => {
this.parse.data.request = text.trim()
})
},
readNfcTag: function () {
readNfcTag() {
try {
if (typeof NDEFReader == 'undefined') {
console.debug('NFC not supported on this device or browser.')
@@ -587,7 +587,7 @@ window.app = Vue.createApp({
}
this.hasNfc = true
let dismissNfcTapMsg = Quasar.Notify.create({
const dismissNfcTapMsg = Quasar.Notify.create({
message: 'Tap your NFC tag to pay this invoice with LNURLw.'
})
@@ -635,8 +635,8 @@ window.app = Vue.createApp({
})
}
},
payInvoiceWithNfc: function (lnurl) {
let dismissPaymentMsg = Quasar.Notify.create({
payInvoiceWithNfc(lnurl) {
const dismissPaymentMsg = Quasar.Notify.create({
timeout: 0,
spinner: true,
message: this.$t('processing_payment')
@@ -669,8 +669,8 @@ window.app = Vue.createApp({
})
}
},
created: function () {
let urlParams = new URLSearchParams(window.location.search)
created() {
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has('lightning') || urlParams.has('lnurl')) {
this.parse.data.request =
urlParams.get('lightning') || urlParams.get('lnurl')
@@ -686,11 +686,11 @@ window.app = Vue.createApp({
this.updateFiatBalance()
},
watch: {
updatePayments: function () {
updatePayments() {
this.fetchBalance()
}
},
mounted: function () {
mounted() {
// show disclaimer
if (!this.$q.localStorage.getItem('lnbits.disclaimerShown')) {
this.disclaimerDialog.show = true
@@ -705,9 +705,7 @@ window.app = Vue.createApp({
})
if (navigator.serviceWorker != null) {
navigator.serviceWorker
.register('/service-worker.js')
.then(function (registration) {
console.log('Registered events at scope: ', registration.scope)
})
navigator.serviceWorker.register('/service-worker.js').then(registration => {
console.log('Registered events at scope: ', registration.scope)
})
}