feat: remove selectWallet and use path params instead of url params (#3591)

This commit is contained in:
dni ⚡ 2025-11-27 12:17:01 +01:00 committed by GitHub
parent ef752cbeca
commit 9c257aa23d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 29 additions and 49 deletions

View file

@ -197,6 +197,7 @@ admin_ui_checks = [Depends(check_admin), Depends(check_admin_ui)]
@generic_router.get("/payments") @generic_router.get("/payments")
@generic_router.get("/wallet") @generic_router.get("/wallet")
@generic_router.get("/wallet/{wallet_id}")
@generic_router.get("/wallets") @generic_router.get("/wallets")
@generic_router.get("/account") @generic_router.get("/account")
@generic_router.get("/extensions") @generic_router.get("/extensions")

View file

@ -183,7 +183,7 @@ async def api_payments_paginated(
False, description="Force check and update of pending payments." False, description="Force check and update of pending payments."
), ),
filters: Filters = Depends(parse_filters(PaymentFilters)), filters: Filters = Depends(parse_filters(PaymentFilters)),
): ) -> Page[Payment]:
page = await get_payments_paginated( page = await get_payments_paginated(
wallet_id=key_info.wallet.id, wallet_id=key_info.wallet.id,
filters=filters, filters=filters,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -126,9 +126,6 @@ window.app.component('lnbits-payment-list', {
} }
}, },
computed: { computed: {
currentWallet() {
return this.wallet || this.g.wallet
},
filteredPayments() { filteredPayments() {
const q = this.paymentsTable.search const q = this.paymentsTable.search
if (!q || q === '') return this.payments if (!q || q === '') return this.payments
@ -200,7 +197,6 @@ window.app.component('lnbits-payment-list', {
if (this.searchDate.to) { if (this.searchDate.to) {
this.paymentFilter['time[le]'] = this.searchDate.to + 'T23:59:59' this.paymentFilter['time[le]'] = this.searchDate.to + 'T23:59:59'
} }
this.fetchPayments() this.fetchPayments()
}, },
searchByLabels(labels) { searchByLabels(labels) {
@ -224,24 +220,24 @@ window.app.component('lnbits-payment-list', {
this.fetchPayments() this.fetchPayments()
}, },
fetchPayments(props) { fetchPayments(props) {
this.paymentsTable.loading = true
const params = LNbits.utils.prepareFilterQuery( const params = LNbits.utils.prepareFilterQuery(
this.paymentsTable, this.paymentsTable,
props, props,
this.paymentFilter this.paymentFilter
) )
this.paymentsTable.loading = true
return LNbits.api return LNbits.api
.getPayments(this.currentWallet, params) .getPayments(this.wallet, params)
.then(response => { .then(response => {
this.paymentsTable.loading = false
this.paymentsTable.pagination.rowsNumber = response.data.total this.paymentsTable.pagination.rowsNumber = response.data.total
this.payments = response.data.data.map(this.mapPayment) this.payments = response.data.data.map(this.mapPayment)
this.paymentsTable.loading = false
this.recheckPendingPayments() this.recheckPendingPayments()
}) })
.catch(err => { .catch(err => {
this.paymentsTable.loading = false this.paymentsTable.loading = false
if (g.user.admin) { if (g.user.admin) {
this.fetchPaymentsAsAdmin(this.currentWallet.id, params) this.fetchPaymentsAsAdmin(this.wallet.id, params)
} else { } else {
LNbits.utils.notifyApiError(err) LNbits.utils.notifyApiError(err)
} }
@ -291,7 +287,7 @@ window.app.component('lnbits-payment-list', {
].join('&') ].join('&')
LNbits.api LNbits.api
.getPayments(this.currentWallet, params) .getPayments(this.wallet, params)
.then(response => { .then(response => {
let updatedPayments = 0 let updatedPayments = 0
response.data.data.forEach(updatedPayment => { response.data.data.forEach(updatedPayment => {

View file

@ -29,6 +29,13 @@ const routes = [
}, },
{ {
path: '/wallet', path: '/wallet',
redirect: to => {
const walletId = window.g?.lastActiveWallet || window.user?.wallets[0].id
return `/wallet/${to.query.val || walletId || 'default'}`
}
},
{
path: '/wallet/:id',
name: 'Wallet', name: 'Wallet',
component: PageWallet component: PageWallet
}, },

View file

@ -639,24 +639,18 @@ window.PageWallet = {
this.decodeRequest() this.decodeRequest()
this.parse.show = true this.parse.show = true
} }
if (urlParams.has('wal')) { let wallet = g.user.wallets.find(w => w.id === this.$route.params.id)
const wallet = g.user.wallets.find(w => w.id === urlParams.get('wal')) if (!wallet) {
if (wallet) { const walletId = g.lastActiveWallet || g.user.wallets[0].id
this.selectWallet(wallet) wallet = g.user.wallets.find(w => w.id === walletId)
} // TODO: should show PageError(404) if wallet not found
} else {
const wallet = g.user.wallets.find(w => w.id === this.g.lastActiveWallet)
if (wallet) {
this.selectWallet(wallet)
} else if (g.user.wallets.length > 0) {
this.selectWallet(g.user.wallets[0])
}
} }
this.g.wallet = wallet
this.g.lastActiveWallet = wallet.id
this.$q.localStorage.setItem('lnbits.lastActiveWallet', wallet.id)
this.$router.replace(`/wallet/${wallet.id}`)
}, },
watch: { watch: {
'g.lastActiveWallet'(val) {
this.$q.localStorage.setItem('lnbits.lastActiveWallet', val)
},
'g.updatePaymentsHash'() { 'g.updatePaymentsHash'() {
this.receive.show = false this.receive.show = false
}, },

View file

@ -60,24 +60,6 @@ window.windowMixin = {
} }
}) })
}, },
selectWallet(wallet) {
this.g.wallet = wallet
this.g.lastActiveWallet = wallet.id
this.g.updatePayments = !this.g.updatePayments
this.balance = parseInt(wallet.balance_msat / 1000)
const currentPath = this.$route.path
if (currentPath !== '/wallet') {
this.$router.push({
path: '/wallet',
query: {wal: this.g.wallet.id}
})
} else {
this.$router.replace({
path: '/wallet',
query: {wal: this.g.wallet.id}
})
}
},
formatBalance(amount) { formatBalance(amount) {
if (LNBITS_DENOMINATION != 'sats') { if (LNBITS_DENOMINATION != 'sats') {
return LNbits.utils.formatCurrency(amount / 100, LNBITS_DENOMINATION) return LNbits.utils.formatCurrency(amount / 100, LNBITS_DENOMINATION)

View file

@ -43,7 +43,7 @@
<q-page class="q-px-md q-py-lg" :class="{'q-px-lg': $q.screen.gt.xs}"> <q-page class="q-px-md q-py-lg" :class="{'q-px-lg': $q.screen.gt.xs}">
<lnbits-wallet-new></lnbits-wallet-new> <lnbits-wallet-new></lnbits-wallet-new>
<lnbits-header-wallets></lnbits-header-wallets> <lnbits-header-wallets></lnbits-header-wallets>
<router-view v-if="isVueRoute"></router-view> <router-view v-if="isVueRoute" :key="$route.path"></router-view>
<!-- FastAPI Content --> <!-- FastAPI Content -->
<div v-else>{% block page %}{% endblock %}</div> <div v-else>{% block page %}{% endblock %}</div>
</q-page> </q-page>

View file

@ -48,7 +48,7 @@
)" )"
:key="wallet.id" :key="wallet.id"
clickable clickable
@click="selectWallet(wallet)" @click="$router.push('/wallet/' + wallet.id)"
class="wallet-list-card" class="wallet-list-card"
:class="{ :class="{
'active-wallet-card': g.wallet && g.wallet.id === wallet.id 'active-wallet-card': g.wallet && g.wallet.id === wallet.id

View file

@ -12,7 +12,7 @@
:key="walletRec.id" :key="walletRec.id"
clickable clickable
:active="g.wallet && g.wallet.id === walletRec.id" :active="g.wallet && g.wallet.id === walletRec.id"
@click="selectWallet(walletRec)" @click="$router.push('/wallet/' + walletRec.id)"
> >
<q-item-section side> <q-item-section side>
<q-avatar <q-avatar

View file

@ -174,7 +174,7 @@
<q-card class="wallet-card"> <q-card class="wallet-card">
<q-card-section> <q-card-section>
<lnbits-payment-list <lnbits-payment-list
:expand-details="expandDetails" :wallet="g.wallet"
:payment-filter="paymentFilter" :payment-filter="paymentFilter"
></lnbits-payment-list> ></lnbits-payment-list>
</q-card-section> </q-card-section>