mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-03-10 17:26:15 +01:00
Enabled Editing the Price for NIP-5 Domains
This commit is contained in:
parent
e886d17f15
commit
a5825f1aa9
4 changed files with 111 additions and 2 deletions
|
@ -3,7 +3,7 @@ from typing import List, Optional, Union
|
|||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
from . import db
|
||||
from .models import Address, CreateAddressData, CreateDomainData, Domain
|
||||
from .models import Address, CreateAddressData, CreateDomainData, EditDomainData, Domain
|
||||
|
||||
|
||||
async def get_domain(domain_id: str) -> Optional[Domain]:
|
||||
|
@ -169,6 +169,24 @@ async def create_address_internal(domain_id: str, data: CreateAddressData) -> Ad
|
|||
assert address, "Newly created address couldn't be retrieved"
|
||||
return address
|
||||
|
||||
async def update_domain_internal(wallet_id: str, data: EditDomainData) -> Domain:
|
||||
if data.currency != "Satoshis":
|
||||
amount = data.amount * 100
|
||||
else:
|
||||
amount = data.amount
|
||||
print(data)
|
||||
await db.execute(
|
||||
"""
|
||||
UPDATE nostrnip5.domains
|
||||
SET amount = ?, currency = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
(int(amount), data.currency, data.id),
|
||||
)
|
||||
|
||||
domain = await get_domain(data.id)
|
||||
assert domain, "Domain couldn't be updated"
|
||||
return domain
|
||||
|
||||
async def create_domain_internal(wallet_id: str, data: CreateDomainData) -> Domain:
|
||||
domain_id = urlsafe_short_hash()
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from enum import Enum
|
||||
from locale import currency
|
||||
from sqlite3 import Row
|
||||
from typing import List, Optional
|
||||
|
||||
|
@ -23,6 +24,14 @@ class CreateDomainData(BaseModel):
|
|||
amount: float = Query(..., ge=0.01)
|
||||
domain: str
|
||||
|
||||
class EditDomainData(BaseModel):
|
||||
id: str
|
||||
currency: str
|
||||
amount: float = Query(..., ge=0.01)
|
||||
|
||||
@classmethod
|
||||
def from_row(cls, row: Row) -> "Domain":
|
||||
return cls(**dict(row))
|
||||
|
||||
class Domain(BaseModel):
|
||||
id: str
|
||||
|
|
|
@ -73,6 +73,14 @@
|
|||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
@click="deleteDomain(props.row.id)"
|
||||
></q-btn>
|
||||
<q-btn
|
||||
unelevated
|
||||
dense
|
||||
size="xs"
|
||||
icon="edit"
|
||||
:color="($q.dark.isActive) ? 'grey-7' : 'grey-5'"
|
||||
@click="editDomain(props.row.id)"
|
||||
></q-btn>
|
||||
</q-td>
|
||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||
{{ col.value }}
|
||||
|
@ -226,6 +234,40 @@
|
|||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<q-dialog v-model="editFormDialog.show" position="top" @hide="closeFormDialog">
|
||||
<q-card class="q-pa-lg q-pt-xl" style="width: 500px">
|
||||
<q-form @submit="saveEditedDomain" class="q-gutter-md">
|
||||
<q-select
|
||||
filled
|
||||
dense
|
||||
emit-value
|
||||
v-model="editFormDialog.data.currency"
|
||||
:options="currencyOptions"
|
||||
label="Currency *"
|
||||
></q-select>
|
||||
<q-input
|
||||
filled
|
||||
dense
|
||||
v-model.trim="editFormDialog.data.amount"
|
||||
label="Amount"
|
||||
placeholder="How much do you want to charge?"
|
||||
></q-input>
|
||||
<div class="row q-mt-lg">
|
||||
<q-btn
|
||||
unelevated
|
||||
color="primary"
|
||||
type="submit"
|
||||
>Update Amount</q-btn
|
||||
>
|
||||
<q-btn v-close-popup flat color="grey" class="q-ml-auto"
|
||||
>Cancel</q-btn
|
||||
>
|
||||
</div>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</q-dialog>
|
||||
|
||||
<q-dialog
|
||||
v-model="addressFormDialog.show"
|
||||
position="top"
|
||||
|
@ -513,6 +555,10 @@
|
|||
show: false,
|
||||
data: {}
|
||||
},
|
||||
editFormDialog: {
|
||||
show: false,
|
||||
data: {}
|
||||
},
|
||||
addressFormDialog: {
|
||||
show: false,
|
||||
data: {}
|
||||
|
@ -578,6 +624,33 @@
|
|||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
saveEditedDomain: function () {
|
||||
var data = this.editFormDialog.data
|
||||
var self = this
|
||||
|
||||
LNbits.api
|
||||
.request(
|
||||
'PUT',
|
||||
'/nostrnip5/api/v1/domain',
|
||||
_.findWhere(this.g.user.wallets, {id: this.editFormDialog.data.wallet})
|
||||
.inkey,
|
||||
data
|
||||
)
|
||||
.then(function (response) {
|
||||
self.editFormDialog.show = false
|
||||
self.editFormDialog.data = {}
|
||||
})
|
||||
.catch(function (error) {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
editDomain: function (domain_id) {
|
||||
var self = this
|
||||
var data = _.findWhere(this.domains, {id: domain_id})
|
||||
|
||||
self.editFormDialog.show = true
|
||||
self.editFormDialog.data = data
|
||||
},
|
||||
deleteDomain: function (domain_id) {
|
||||
var self = this
|
||||
var domain = _.findWhere(this.domains, {id: domain_id})
|
||||
|
|
|
@ -26,8 +26,9 @@ from .crud import (
|
|||
get_domain_by_name,
|
||||
get_domains,
|
||||
rotate_address,
|
||||
update_domain_internal,
|
||||
)
|
||||
from .models import CreateAddressData, CreateDomainData, RotateAddressData
|
||||
from .models import CreateAddressData, CreateDomainData, RotateAddressData, EditDomainData
|
||||
|
||||
|
||||
@nostrnip5_ext.get("/api/v1/domains", status_code=HTTPStatus.OK)
|
||||
|
@ -88,6 +89,14 @@ async def api_domain_create(
|
|||
|
||||
return domain
|
||||
|
||||
@nostrnip5_ext.put("/api/v1/domain", status_code=HTTPStatus.OK)
|
||||
async def api_domain_update(
|
||||
data: EditDomainData, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
|
||||
domain = await update_domain_internal(wallet_id=wallet.wallet.id, data=data)
|
||||
|
||||
return domain
|
||||
|
||||
@nostrnip5_ext.delete("/api/v1/domain/{domain_id}", status_code=HTTPStatus.CREATED)
|
||||
async def api_domain_delete(
|
||||
|
|
Loading…
Add table
Reference in a new issue