refactor: create lnbits-wallet-paylinks component (#3523)

This commit is contained in:
dni ⚡ 2025-11-21 11:05:38 +01:00 committed by GitHub
parent 98d4dbab8b
commit 3f7a1798d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 155 additions and 131 deletions

View file

@ -237,87 +237,10 @@
</q-card-section> </q-card-section>
<q-card-section class="q-pa-none"> <q-card-section class="q-pa-none">
<q-separator></q-separator> <q-separator></q-separator>
<q-list> <q-list>
<q-expansion-item <lnbits-wallet-paylinks
group="extras" @send-lnurl="handleSendLnurl"
icon="qr_code" ></lnbits-wallet-paylinks>
v-if="stored_paylinks.length > 0"
:label="$t('stored_paylinks')"
>
<q-card>
<q-card-section>
<div class="row flex" v-for="paylink in stored_paylinks">
<q-btn
dense
flat
color="primary"
icon="send"
size="xs"
@click="sendToPaylink(paylink.lnurl)"
>
<q-tooltip>
<span v-text="`send to: ${paylink.lnurl}`"></span>
</q-tooltip>
</q-btn>
<q-btn
dense
flat
color="secondary"
icon="content_copy"
size="xs"
@click="copyText(paylink.lnurl)"
>
<q-tooltip>
<span v-text="`copy: ${paylink.lnurl}`"></span>
</q-tooltip>
</q-btn>
<span
v-text="paylink.label"
class="q-mr-xs q-ml-xs"
></span>
<q-btn dense flat color="primary" icon="edit" size="xs">
<q-popup-edit
@update:model-value="editPaylink()"
v-model="paylink.label"
v-slot="scope"
>
<q-input
dark
color="white"
v-model="scope.value"
dense
autofocus
counter
@keyup.enter="scope.set"
>
<template v-slot:append>
<q-icon name="edit" />
</template>
</q-input>
</q-popup-edit>
<q-tooltip>
<span v-text="$t('edit')"></span>
</q-tooltip>
</q-btn>
<span style="flex-grow: 1"></span>
<q-btn
dense
flat
color="red"
icon="delete"
size="xs"
@click="deletePaylink(paylink.lnurl)"
>
<q-tooltip>
<span v-text="$t('delete')"></span>
</q-tooltip>
</q-btn>
<span v-text="dateFromNow(paylink.last_used)"></span>
</div>
</q-card-section>
</q-card>
</q-expansion-item>
<q-separator></q-separator> <q-separator></q-separator>
<lnbits-wallet-share></lnbits-wallet-share> <lnbits-wallet-share></lnbits-wallet-share>
<q-separator></q-separator> <q-separator></q-separator>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -75,6 +75,7 @@ window.LNbits = {
newWallet.canSendPayments = perms.includes('send-payments') newWallet.canSendPayments = perms.includes('send-payments')
} }
newWallet.url = `/wallet?&wal=${data.id}` newWallet.url = `/wallet?&wal=${data.id}`
newWallet.storedPaylinks = data.stored_paylinks.links
return newWallet return newWallet
}, },
payment(data) { payment(data) {

View file

@ -0,0 +1,62 @@
window.app.component('lnbits-wallet-paylinks', {
template: '#lnbits-wallet-paylinks',
mixins: [window.windowMixin],
data() {
return {
storedPaylinks: []
}
},
watch: {
'g.wallet'(val) {
this.storedPaylinks = val.storedPaylinks ?? []
}
},
created() {
this.storedPaylinks = this.g.wallet.storedPaylinks
},
methods: {
dateFromNow(unix) {
const date = new Date(unix * 1000)
return moment.utc(date).local().fromNow()
},
updatePaylinks() {
LNbits.api
.request(
'PUT',
`/api/v1/wallet/stored_paylinks/${this.g.wallet.id}`,
this.g.wallet.adminkey,
{
links: this.storedPaylinks
}
)
.then(() => {
this.$q.notify({
message: 'Paylinks updated.',
type: 'positive',
timeout: 3500
})
})
.catch(err => {
LNbits.utils.notifyApiError(err)
})
},
sendToPaylink(lnurl) {
this.$emit('send-lnurl', lnurl)
},
editPaylink() {
this.$nextTick(() => {
this.updatePaylinks()
})
},
deletePaylink(lnurl) {
const links = []
this.storedPaylinks.forEach(link => {
if (link.lnurl !== lnurl) {
links.push(link)
}
})
this.storedPaylinks = links
this.updatePaylinks()
}
}
})

View file

@ -5,7 +5,6 @@ window.WalletPageLogic = {
origin: window.location.origin, origin: window.location.origin,
baseUrl: `${window.location.protocol}//${window.location.host}/`, baseUrl: `${window.location.protocol}//${window.location.host}/`,
websocketUrl: `${'http:' ? 'ws://' : 'wss://'}${window.location.host}/api/v1/ws`, websocketUrl: `${'http:' ? 'ws://' : 'wss://'}${window.location.host}/api/v1/ws`,
stored_paylinks: [],
parse: { parse: {
show: false, show: false,
invoice: null, invoice: null,
@ -150,9 +149,10 @@ window.WalletPageLogic = {
} }
}, },
methods: { methods: {
dateFromNow(unix) { handleSendLnurl(lnurl) {
const date = new Date(unix * 1000) this.parse.data.request = lnurl
return moment.utc(date).local().fromNow() this.parse.show = true
this.lnurlScan()
}, },
formatFiatAmount(amount, currency) { formatFiatAmount(amount, currency) {
this.update.currency = currency this.update.currency = currency
@ -790,51 +790,9 @@ window.WalletPageLogic = {
this.update.currency = '' this.update.currency = ''
this.g.fiatTracking = false this.g.fiatTracking = false
} }
},
updatePaylinks() {
LNbits.api
.request(
'PUT',
`/api/v1/wallet/stored_paylinks/${this.g.wallet.id}`,
this.g.wallet.adminkey,
{
links: this.stored_paylinks
}
)
.then(() => {
Quasar.Notify.create({
message: 'Paylinks updated.',
type: 'positive',
timeout: 3500
})
})
.catch(err => {
LNbits.utils.notifyApiError(err)
})
},
sendToPaylink(lnurl) {
this.parse.data.request = lnurl
this.parse.show = true
this.lnurlScan()
},
editPaylink() {
this.$nextTick(() => {
this.updatePaylinks()
})
},
deletePaylink(lnurl) {
const links = []
this.stored_paylinks.forEach(link => {
if (link.lnurl !== lnurl) {
links.push(link)
}
})
this.stored_paylinks = links
this.updatePaylinks()
} }
}, },
created() { created() {
this.stored_paylinks = wallet.stored_paylinks.links
const urlParams = new URLSearchParams(window.location.search) const urlParams = new URLSearchParams(window.location.search)
if (urlParams.has('lightning') || urlParams.has('lnurl')) { if (urlParams.has('lightning') || urlParams.has('lnurl')) {
this.parse.data.request = this.parse.data.request =

View file

@ -66,8 +66,7 @@ window.windowMixin = {
}) })
}, },
selectWallet(wallet) { selectWallet(wallet) {
Object.assign(this.g.wallet, wallet) this.g.wallet = wallet
// this.wallet = this.g.wallet
this.g.updatePayments = !this.g.updatePayments this.g.updatePayments = !this.g.updatePayments
this.balance = parseInt(wallet.balance_msat / 1000) this.balance = parseInt(wallet.balance_msat / 1000)
const currentPath = this.$route.path const currentPath = this.$route.path

View file

@ -71,6 +71,7 @@
"js/components/lnbits-wallet-api-docs.js", "js/components/lnbits-wallet-api-docs.js",
"js/components/lnbits-wallet-new.js", "js/components/lnbits-wallet-new.js",
"js/components/lnbits-wallet-share.js", "js/components/lnbits-wallet-share.js",
"js/components/lnbits-wallet-paylinks.js",
"js/components/lnbits-home-logos.js", "js/components/lnbits-home-logos.js",
"js/components/lnbits-qrcode.js", "js/components/lnbits-qrcode.js",
"js/components/lnbits-qrcode-lnurl.js", "js/components/lnbits-qrcode-lnurl.js",

View file

@ -24,7 +24,8 @@ include('components/lnbits-wallet-new.vue') %} {%
include('components/lnbits-label-selector.vue') %} {% include('components/lnbits-label-selector.vue') %} {%
include('components/lnbits-wallet-api-docs.vue') %} {% include('components/lnbits-wallet-api-docs.vue') %} {%
include('components/lnbits-wallet-share.vue') %} {% include('components/lnbits-wallet-share.vue') %} {%
include('components/lnbits-wallet-charts.vue') %} include('components/lnbits-wallet-charts.vue') %} {%
include('components/lnbits-wallet-paylinks.vue') %}
<template id="lnbits-manage"> <template id="lnbits-manage">
<q-list v-if="g.user" dense class="lnbits-drawer__q-list"> <q-list v-if="g.user" dense class="lnbits-drawer__q-list">

View file

@ -0,0 +1,78 @@
<template id="lnbits-wallet-paylinks">
<q-expansion-item
group="extras"
icon="qr_code"
v-if="storedPaylinks.length > 0"
:label="$t('stored_paylinks')"
>
<q-card>
<q-card-section>
<div class="row flex" v-for="paylink in storedPaylinks">
<q-btn
dense
flat
color="primary"
icon="send"
size="xs"
@click="sendToPaylink(paylink.lnurl)"
>
<q-tooltip>
<span v-text="`send to: ${paylink.lnurl}`"></span>
</q-tooltip>
</q-btn>
<q-btn
dense
flat
color="secondary"
icon="content_copy"
size="xs"
@click="copyText(paylink.lnurl)"
>
<q-tooltip>
<span v-text="`copy: ${paylink.lnurl}`"></span>
</q-tooltip>
</q-btn>
<span v-text="paylink.label" class="q-mr-xs q-ml-xs"></span>
<q-btn dense flat color="primary" icon="edit" size="xs">
<q-popup-edit
@update:model-value="editPaylink()"
v-model="paylink.label"
v-slot="scope"
>
<q-input
dark
color="white"
v-model="scope.value"
dense
autofocus
counter
@keyup.enter="scope.set"
>
<template v-slot:append>
<q-icon name="edit" />
</template>
</q-input>
</q-popup-edit>
<q-tooltip>
<span v-text="$t('edit')"></span>
</q-tooltip>
</q-btn>
<span style="flex-grow: 1"></span>
<q-btn
dense
flat
color="red"
icon="delete"
size="xs"
@click="deletePaylink(paylink.lnurl)"
>
<q-tooltip>
<span v-text="$t('delete')"></span>
</q-tooltip>
</q-btn>
<span v-text="dateFromNow(paylink.last_used)"></span>
</div>
</q-card-section>
</q-card>
</q-expansion-item>
</template>

View file

@ -123,6 +123,7 @@
"js/components/lnbits-wallet-api-docs.js", "js/components/lnbits-wallet-api-docs.js",
"js/components/lnbits-wallet-new.js", "js/components/lnbits-wallet-new.js",
"js/components/lnbits-wallet-share.js", "js/components/lnbits-wallet-share.js",
"js/components/lnbits-wallet-paylinks.js",
"js/components/lnbits-home-logos.js", "js/components/lnbits-home-logos.js",
"js/components/lnbits-qrcode.js", "js/components/lnbits-qrcode.js",
"js/components/lnbits-qrcode-lnurl.js", "js/components/lnbits-qrcode-lnurl.js",