refactor: extract models (#2759)

This commit is contained in:
Vlad Stan
2024-11-05 13:26:12 +02:00
committed by GitHub
parent acb1b1ed91
commit ba5f79da2d
30 changed files with 791 additions and 716 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -29
View File
@@ -217,8 +217,7 @@ window.LNbits = {
'name',
'shortDescription',
'tile',
'contributors',
'hidden'
'contributors'
],
data
)
@@ -719,33 +718,7 @@ window.windowMixin = {
this.g.wallet = Object.freeze(window.LNbits.map.wallet(window.wallet))
}
if (window.extensions) {
const user = this.g.user
const extensions = Object.freeze(
window.extensions
.map(function (data) {
return window.LNbits.map.extension(data)
})
.filter(function (obj) {
return !obj.hidden
})
.filter(function (obj) {
if (window.user?.admin) return obj
return !obj.isAdminOnly
})
.map(function (obj) {
if (user) {
obj.isEnabled = user.extensions.indexOf(obj.code) !== -1
} else {
obj.isEnabled = false
}
return obj
})
.sort(function (a, b) {
const nameA = a.name.toUpperCase()
const nameB = b.name.toUpperCase()
return nameA < nameB ? -1 : nameA > nameB ? 1 : 0
})
)
const extensions = Object.freeze(window.extensions)
this.g.extensions = extensions
}
+10 -7
View File
@@ -87,19 +87,22 @@ window.app.component('lnbits-extension-list', {
})
}
},
created: function () {
if (window.extensions) {
this.extensions = window.extensions
created: async function () {
if (window.user) {
this.user = LNbits.map.user(window.user)
}
try {
const {data} = await LNbits.api.request('GET', '/api/v1/extension')
this.extensions = data
.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)
} catch (error) {
LNbits.utils.notifyApiError(error)
}
}
})