fix: consistent js

This commit is contained in:
Tiago Vasconcelos 2024-10-25 15:16:50 +01:00
commit 8d731dccfc

View file

@ -21,7 +21,7 @@ const CUSTOM_URL = '/static/images/default_voucher.png'
window.app = Vue.createApp({ window.app = Vue.createApp({
el: '#vue', el: '#vue',
mixins: [window.windowMixin], mixins: [window.windowMixin],
data: function () { data() {
return { return {
checker: null, checker: null,
withdrawLinks: [], withdrawLinks: [],
@ -93,14 +93,14 @@ window.app = Vue.createApp({
} }
}, },
computed: { computed: {
sortedWithdrawLinks: function () { sortedWithdrawLinks() {
return this.withdrawLinks.sort(function (a, b) { return this.withdrawLinks.sort(function (a, b) {
return b.uses_left - a.uses_left return b.uses_left - a.uses_left
}) })
} }
}, },
methods: { methods: {
getWithdrawLinks: function (props) { getWithdrawLinks(props) {
if (props) { if (props) {
this.withdrawLinksTable.pagination = props.pagination this.withdrawLinksTable.pagination = props.pagination
} }
@ -118,9 +118,7 @@ window.app = Vue.createApp({
this.g.user.wallets[0].inkey this.g.user.wallets[0].inkey
) )
.then(response => { .then(response => {
this.withdrawLinks = response.data.data.map(function (obj) { this.withdrawLinks = response.data.data.map(mapWithdrawLink)
return mapWithdrawLink(obj)
})
this.withdrawLinksTable.pagination.rowsNumber = response.data.total this.withdrawLinksTable.pagination.rowsNumber = response.data.total
}) })
.catch(error => { .catch(error => {
@ -128,20 +126,20 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
closeFormDialog: function () { closeFormDialog() {
this.formDialog.data = { this.formDialog.data = {
is_unique: false, is_unique: false,
use_custom: false, use_custom: false,
has_webhook: false has_webhook: false
} }
}, },
simplecloseFormDialog: function () { simplecloseFormDialog() {
this.simpleformDialog.data = { this.simpleformDialog.data = {
is_unique: false, is_unique: false,
use_custom: false use_custom: false
} }
}, },
openQrCodeDialog: function (linkId) { openQrCodeDialog(linkId) {
const link = _.findWhere(this.withdrawLinks, {id: linkId}) const link = _.findWhere(this.withdrawLinks, {id: linkId})
this.qrCodeDialog.data = _.clone(link) this.qrCodeDialog.data = _.clone(link)
@ -149,13 +147,13 @@ window.app = Vue.createApp({
window.location.protocol + '//' + window.location.host window.location.protocol + '//' + window.location.host
this.qrCodeDialog.show = true this.qrCodeDialog.show = true
}, },
openUpdateDialog: function (linkId) { openUpdateDialog(linkId) {
let link = _.findWhere(this.withdrawLinks, {id: linkId}) let link = _.findWhere(this.withdrawLinks, {id: linkId})
link._data.has_webhook = link._data.webhook_url ? true : false link._data.has_webhook = link._data.webhook_url ? true : false
this.formDialog.data = _.clone(link._data) this.formDialog.data = _.clone(link._data)
this.formDialog.show = true this.formDialog.show = true
}, },
sendFormData: function () { sendFormData() {
const wallet = _.findWhere(this.g.user.wallets, { const wallet = _.findWhere(this.g.user.wallets, {
id: this.formDialog.data.wallet id: this.formDialog.data.wallet
}) })
@ -183,7 +181,7 @@ window.app = Vue.createApp({
this.createWithdrawLink(wallet, data) this.createWithdrawLink(wallet, data)
} }
}, },
simplesendFormData: function () { simplesendFormData() {
const wallet = _.findWhere(this.g.user.wallets, { const wallet = _.findWhere(this.g.user.wallets, {
id: this.simpleformDialog.data.wallet id: this.simpleformDialog.data.wallet
}) })
@ -208,7 +206,7 @@ window.app = Vue.createApp({
this.createWithdrawLink(wallet, data) this.createWithdrawLink(wallet, data)
} }
}, },
updateWithdrawLink: function (wallet, data) { updateWithdrawLink(wallet, data) {
// Remove webhook info if toggle is set to false // Remove webhook info if toggle is set to false
if (!data.has_webhook) { if (!data.has_webhook) {
data.webhook_url = null data.webhook_url = null
@ -235,7 +233,7 @@ window.app = Vue.createApp({
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
createWithdrawLink: function (wallet, data) { createWithdrawLink(wallet, data) {
LNbits.api LNbits.api
.request('POST', '/withdraw/api/v1/links', wallet.adminkey, data) .request('POST', '/withdraw/api/v1/links', wallet.adminkey, data)
.then(response => { .then(response => {
@ -270,7 +268,7 @@ window.app = Vue.createApp({
}) })
}) })
}, },
writeNfcTag: async function (lnurl) { async writeNfcTag(lnurl) {
try { try {
if (typeof NDEFReader == 'undefined') { if (typeof NDEFReader == 'undefined') {
throw { throw {
@ -314,7 +312,7 @@ window.app = Vue.createApp({
) )
} }
}, },
created: function () { created() {
if (this.g.user.wallets.length) { if (this.g.user.wallets.length) {
this.getWithdrawLinks() this.getWithdrawLinks()
this.checker = setInterval(this.getWithdrawLinks, 300000) this.checker = setInterval(this.getWithdrawLinks, 300000)