icon stuff

This commit is contained in:
arcbtc 2024-12-28 14:16:27 +00:00
parent de77d002ee
commit 80e8bf9ff1
5 changed files with 89 additions and 65 deletions

View File

@ -33,8 +33,8 @@ class Wallet(BaseModel):
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
currency: Optional[str] = None currency: Optional[str] = None
balance_msat: int = Field(default=0, no_database=True) balance_msat: int = Field(default=0, no_database=True)
icon: str icon: str = "flash_on"
color: str color: str = "primary"
@property @property
def balance(self) -> int: def balance(self) -> int:

View File

@ -36,50 +36,54 @@
> >
<div class="row no-wrap q-gutter-md q-pr-md"> <div class="row no-wrap q-gutter-md q-pr-md">
<q-card <q-card
v-for="wallet in g.user.wallets" v-for="wallets in g.user.wallets"
:key="wallet.id" :key="wallets.id"
class="wallet-list-card" class="wallet-list-card"
bordered bordered
tag="a" tag="a"
:href="wallet.url" @click="getWallet(wallets)"
:style=" :style="
g.wallet && g.wallet.id === wallet.id wallet && wallet.id === wallets.id
? `border: 1px solid ${primaryColor}; width: 250px; text-decoration: none;` ? `border: 1px solid ${primaryColor}; width: 250px; text-decoration: none;`
: 'width: 250px; text-decoration: none;' : 'width: 250px; text-decoration: none;'
" "
:class="{ :class="{
'active-wallet-card': g.wallet && g.wallet.id === wallet.id 'active-wallet-card': wallet && wallet.id === wallets.id
}" }"
> >
<q-card-section> <q-card-section>
<div class="row items-center"> <div class="row items-center">
<q-avatar <q-avatar
size="lg" size="lg"
:color=" :icon="
g.wallet && g.wallet.id === wallet.id wallet && wallet.id === wallets.id
? $q.dark.isActive ? wallet.icon
? 'primary' : wallets.icon
: 'primary' "
: 'grey-5' :text-color="$q.dark.isActive ? 'black' : 'grey-3'"
:class="wallet && wallet.id === wallet.id
? ''
: 'disabled'
" "
> :color="
<q-icon wallet && wallet.id === wallets.id
:name="g.wallet.icon" ? wallet.color
:size="$q.dark.isActive ? '21px' : '20px'" : wallets.color
:color="$q.dark.isActive ? 'black' : 'grey-3'" "
></q-icon> >
</q-avatar> </q-avatar>
<div <div
class="text-h6 q-pl-md" class="text-h6 q-pl-md"
:class="{ :class="{
'text-bold': g.wallet && g.wallet.id === wallet.id 'text-bold': wallet && wallet.id === wallet.id
}" }"
v-text="wallet.name" v-text="wallets.name"
></div> ></div>
</div> </div>
<div class="row items-center q-pt-sm"> <div class="row items-center q-pt-sm">
<h6 class="q-my-none text-no-wrap"> <h6 class="q-my-none text-no-wrap">
<strong v-text="wallet.fsat"></strong> <strong v-text="wallets.fsat"></strong>
<small> {{LNBITS_DENOMINATION}}</small> <small> {{LNBITS_DENOMINATION}}</small>
</h6> </h6>
</div> </div>
@ -102,7 +106,7 @@
<strong v-text="formattedBalance"></strong> <strong v-text="formattedBalance"></strong>
<small> {{LNBITS_DENOMINATION}}</small> <small> {{LNBITS_DENOMINATION}}</small>
<lnbits-update-balance <lnbits-update-balance
:wallet_id="this.g.wallet.id" :wallet_id="wallet.id"
@credit-value="handleBalanceUpdate" @credit-value="handleBalanceUpdate"
class="q-ml-md" class="q-ml-md"
></lnbits-update-balance> ></lnbits-update-balance>
@ -110,7 +114,7 @@
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<div v-if="g.wallet.currency"> <div v-if="wallet.currency">
<span <span
class="text-h5 text-italic" class="text-h5 text-italic"
v-text="formattedFiatBalance" v-text="formattedFiatBalance"
@ -182,7 +186,7 @@
<q-card-section> <q-card-section>
<payment-list <payment-list
:update="updatePayments" :update="updatePayments"
:wallet="this.g.wallet" :wallet="wallet"
:mobile-simple="mobileSimple" :mobile-simple="mobileSimple"
/> />
</q-card-section> </q-card-section>
@ -200,15 +204,16 @@
<div class="row items-center"> <div class="row items-center">
<q-avatar <q-avatar
size="xl" size="lg"
color="primary"> :icon="wallet.icon"
<q-icon :text-color="$q.dark.isActive ? 'black' : 'grey-3'"
:name="g.wallet.icon" :color="
:size="$q.dark.isActive ? '21px' : '20px'" wallet && wallet.id === wallet.id
:color="$q.dark.isActive ? 'blue-grey-10' : 'grey-3'" ? wallet.color
></q-icon> : wallet.color
"
</q-avatar> >
</q-avatar>
<q-btn @click="icon.show = true" round color="grey-5" text-color="black" size="xs" icon="add" style="position: relative; left: -20px; bottom: -10px;"></q-btn> <q-btn @click="icon.show = true" round color="grey-5" text-color="black" size="xs" icon="add" style="position: relative; left: -20px; bottom: -10px;"></q-btn>
<div class="text-subtitle1 q-mt-none q-mb-none"> <div class="text-subtitle1 q-mt-none q-mb-none">
{{ SITE_TITLE }} Wallet: {{ SITE_TITLE }} Wallet:
@ -223,7 +228,7 @@
</q-card-section> </q-card-section>
<q-card-section style="padding: 0"> <q-card-section style="padding: 0">
<wallet-payment-chart <wallet-payment-chart
:wallet="this.g.wallet" :wallet="this.wallet"
></wallet-payment-chart> ></wallet-payment-chart>
</q-card-section> </q-card-section>
</q-card> </q-card>

View File

@ -40,7 +40,7 @@ async def api_wallet(key_info: WalletTypeInfo = Depends(require_invoice_key)):
return res return res
@wallet_router.put("/{new_name}") @wallet_router.put("/")
async def api_update_wallet_name( async def api_update_wallet_name(
new_name: str, key_info: WalletTypeInfo = Depends(require_admin_key) new_name: str, key_info: WalletTypeInfo = Depends(require_admin_key)
): ):
@ -59,6 +59,8 @@ async def api_update_wallet_name(
@wallet_router.patch("") @wallet_router.patch("")
async def api_update_wallet( async def api_update_wallet(
name: Optional[str] = Body(None), name: Optional[str] = Body(None),
icon: Optional[str] = Body(None),
color: Optional[str] = Body(None),
currency: Optional[str] = Body(None), currency: Optional[str] = Body(None),
key_info: WalletTypeInfo = Depends(require_admin_key), key_info: WalletTypeInfo = Depends(require_admin_key),
) -> Wallet: ) -> Wallet:
@ -66,6 +68,8 @@ async def api_update_wallet(
if not wallet: if not wallet:
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Wallet not found") raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Wallet not found")
wallet.name = name or wallet.name wallet.name = name or wallet.name
wallet.icon = icon or wallet.icon
wallet.color = color or wallet.color
wallet.currency = currency if currency is not None else wallet.currency wallet.currency = currency if currency is not None else wallet.currency
await update_wallet(wallet) await update_wallet(wallet)
return wallet return wallet

View File

@ -211,6 +211,12 @@ window.app = Vue.createApp({
console.log(this.icon.data) console.log(this.icon.data)
this.updateWallet(this.icon.data) this.updateWallet(this.icon.data)
}, },
getWallet(wallet) {
console.log(wallet)
console.log(this.g.wallet)
this.wallet = LNbits.map.wallet(wallet)
console.log(this.g.wallet)
},
createInvoice() { createInvoice() {
this.receive.status = 'loading' this.receive.status = 'loading'
if (LNBITS_DENOMINATION != 'sats') { if (LNBITS_DENOMINATION != 'sats') {
@ -566,13 +572,15 @@ window.app = Vue.createApp({
updateWallet(data) { updateWallet(data) {
LNbits.api LNbits.api
.request('PATCH', '/api/v1/wallet', this.g.wallet.adminkey, data) .request('PATCH', '/api/v1/wallet', this.g.wallet.adminkey, data)
.then(_ => { .then(response => {
console.log(response.data)
this.wallet = LNbits.map.wallet(response.data)
Quasar.Notify.create({ Quasar.Notify.create({
message: `Wallet updated.`, message: `Wallet updated.`,
type: 'positive', type: 'positive',
timeout: 3500 timeout: 3500
}) })
window.location.reload() // window.location.reload()
}) })
.catch(err => { .catch(err => {
LNbits.utils.notifyApiError(err) LNbits.utils.notifyApiError(err)
@ -709,7 +717,24 @@ window.app = Vue.createApp({
dismissPaymentMsg() dismissPaymentMsg()
LNbits.utils.notifyApiError(err) LNbits.utils.notifyApiError(err)
}) })
},
walletColorAlpha(color){
console.log(LNbits.utils.getPaletteColor(color))
console.log(LNbits.utils.hexAlpha(LNbits.utils.getPaletteColor(color),0.3))
return LNbits.utils.hexAlpha(LNbits.utils.getPaletteColor(color),0.3)
},
incoming(wallet){
// listen to incoming payments
LNbits.events.onInvoicePaid(wallet, data => {
console.log('Payment received:', data.payment.payment_hash)
console.log('Wallet balance:', data.wallet_balance)
console.log('Wallet ID:', wallet)
this.onPaymentReceived(data.payment.payment_hash)
this.balance = data.wallet_balance
eventReaction(data.payment.amount)
})
} }
}, },
created() { created() {
const urlParams = new URLSearchParams(window.location.search) const urlParams = new URLSearchParams(window.location.search)
@ -726,7 +751,6 @@ window.app = Vue.createApp({
this.update.currency = this.g.wallet.currency this.update.currency = this.g.wallet.currency
this.receive.units = ['sat', ...window.currencies] this.receive.units = ['sat', ...window.currencies]
this.updateFiatBalance() this.updateFiatBalance()
console.log('Wallet:', this.wallet)
}, },
watch: { watch: {
updatePayments() { updatePayments() {
@ -744,15 +768,7 @@ window.app = Vue.createApp({
this.disclaimerDialog.show = true this.disclaimerDialog.show = true
this.$q.localStorage.set('lnbits.disclaimerShown', true) this.$q.localStorage.set('lnbits.disclaimerShown', true)
} }
// listen to incoming payments this.incoming(this.g.wallet)
LNbits.events.onInvoicePaid(this.g.wallet, data => {
console.log('Payment received:', data.payment.payment_hash)
console.log('Wallet balance:', data.wallet_balance)
console.log('Wallet ID:', this.g.wallet)
this.onPaymentReceived(data.payment.payment_hash)
this.balance = data.wallet_balance
eventReaction(data.payment.amount)
})
} }
}) })

View File

@ -15,21 +15,20 @@
> >
<q-item-section side> <q-item-section side>
<q-avatar <q-avatar
size="md" size="lg"
:color=" :icon="wallet.icon"
activeWallet && activeWallet.id === wallet.id :text-color="$q.dark.isActive ? 'black' : 'grey-3'"
? $q.dark.isActive :class="activeWallet && activeWallet.id === wallet.id
? 'primary' ? ''
: 'primary' : 'disabled'
: 'grey-5' "
" :color="
> activeWallet && activeWallet.id === wallet.id
<q-icon ? wallet.color
name="flash_on" : wallet.color
:size="$q.dark.isActive ? '21px' : '20px'" "
:color="$q.dark.isActive ? 'blue-grey-10' : 'grey-3'" >
></q-icon> </q-avatar>
</q-avatar>
</q-item-section> </q-item-section>
<q-item-section> <q-item-section>
<q-item-label lines="1" <q-item-label lines="1"