Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Oct 30, 2024
1 parent 6839b4f commit fdc1ed5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 43 deletions.
16 changes: 4 additions & 12 deletions static/js/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ window.app = Vue.createApp({
if (!this.isValidUsername) {
return true
}
let available = await axios
return await axios
.get(`/lnaddress/api/v1/address/availabity/${domain_id}/${username}`)
.then(res => {
return res.data < 1
return res.data
})
console.log(available)
return available
},
isValidUsername() {
let username = this.formDialog.data.username
Expand Down Expand Up @@ -77,8 +75,8 @@ window.app = Vue.createApp({
.then(res => {
if (res) {
let dt = {}
let result = new Date(res.data.time * 1000)
dt.start = new Date(res.data.time * 1000)
let result = new Date(res.data.time)
dt.start = new Date(res.data.time)
dt.expiration = moment(
result.setDate(result.getDate() + res.data.duration)
).format('dddd, MMMM Do YYYY, h:mm:ss a')
Expand All @@ -89,7 +87,6 @@ window.app = Vue.createApp({
...dt
}
this.renewDialog.info = true
console.log(this.renewDialog)
}
})
.catch(function (error) {
Expand Down Expand Up @@ -178,7 +175,6 @@ window.app = Vue.createApp({
axios
.get(`/lnaddress/api/v1/addresses/${this.paymentCheck}`)
.then(res => {
console.log('pay_check', res.data)
if (res.data.paid) {
clearInterval(paymentChecker)
this.receive = {
Expand All @@ -188,24 +184,20 @@ window.app = Vue.createApp({
}
dismissMsg()

console.log(this.formDialog)
this.formDialog.data = {}
this.$q.notify({
type: 'positive',
message: 'Sent, thank you!',
icon: 'thumb_up'
})
console.log('END')
}
})
.catch(function (error) {
console.log(error)
LNbits.utils.notifyApiError(error)
})
}, 5000)
})
.catch(function (error) {
console.log(error)
LNbits.utils.notifyApiError(error)
})
}
Expand Down
11 changes: 4 additions & 7 deletions templates/lnaddress/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,10 @@ <h6 class="q-my-none">
<q-card v-else class="q-pa-lg q-pt-xl lnbits__dialog-card">
<div class="text-center q-mb-lg">
<a class="text-secondary" :href="'lightning:' + receive.paymentReq">
<q-responsive :ratio="1" class="q-mx-xl">
<qrcode
:value="'lightning:' + paymentReq.toUpperCase()"
:options="{width: 340}"
class="rounded-borders"
></qrcode>
</q-responsive>
<lnbits-qrcode
:value="'lightning:' + paymentReq.toUpperCase()"
class="rounded-borders"
></lnbits-qrcode>
</a>
</div>
<div class="row q-mt-lg">
Expand Down
41 changes: 17 additions & 24 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@
get_domains,
update_domain,
)
from .models import CreateAddress, CreateDomain
from .models import Address, CreateAddress, CreateDomain, Domain

lnaddress_api_router = APIRouter()


@lnaddress_api_router.get("/api/v1/domains")
async def api_domains(
g: WalletTypeInfo = Depends(require_invoice_key), all_wallets: bool = Query(False)
):
) -> list[Domain]:
wallet_ids = [g.wallet.id]

if all_wallets:
user = await get_user(g.wallet.user)
wallet_ids = user.wallet_ids if user else []

return [domain.dict() for domain in await get_domains(wallet_ids)]
return await get_domains(wallet_ids)


@lnaddress_api_router.post("/api/v1/domains")
Expand All @@ -47,7 +46,7 @@ async def api_domain_create(
data: CreateDomain,
domain_id=None,
g: WalletTypeInfo = Depends(require_admin_key),
):
) -> Domain:
if domain_id:
domain = await get_domain(domain_id)

Expand Down Expand Up @@ -77,11 +76,13 @@ async def api_domain_create(
status_code=HTTPStatus.BAD_REQUEST, detail="Problem with cloudflare."
)

return domain.dict()
return domain


@lnaddress_api_router.delete("/api/v1/domains/{domain_id}")
async def api_domain_delete(domain_id, g: WalletTypeInfo = Depends(require_admin_key)):
async def api_domain_delete(
domain_id: str, g: WalletTypeInfo = Depends(require_admin_key)
):
domain = await get_domain(domain_id)

if not domain:
Expand All @@ -93,34 +94,27 @@ async def api_domain_delete(domain_id, g: WalletTypeInfo = Depends(require_admin
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Not your domain")

await delete_domain(domain_id)
return "", HTTPStatus.NO_CONTENT


# ADDRESSES


@lnaddress_api_router.get("/api/v1/addresses")
async def api_addresses(
g: WalletTypeInfo = Depends(require_invoice_key), all_wallets: bool = Query(False)
):
) -> list[Address]:
wallet_ids = [g.wallet.id]

if all_wallets:
user = await get_user(g.wallet.user)
wallet_ids = user.wallet_ids if user else []

return [address.dict() for address in await get_addresses(wallet_ids)]
return await get_addresses(wallet_ids)


@lnaddress_api_router.get("/api/v1/address/availabity/{domain_id}/{username}")
async def api_check_available_username(domain_id, username):
async def api_check_available_username(domain_id, username) -> bool:
used_username = await check_address_available(username, domain_id)

return used_username


@lnaddress_api_router.get("/api/v1/address/{domain}/{username}/{wallet_key}")
async def api_get_user_info(username, wallet_key, domain):
async def api_get_user_info(username, wallet_key, domain) -> Address:
address = await get_address_by_username(username, domain)

if not address:
Expand All @@ -134,7 +128,7 @@ async def api_get_user_info(username, wallet_key, domain):
detail="Incorrect user/wallet information.",
)

return address.dict()
return address


@lnaddress_api_router.post("/api/v1/address/{domain_id}")
Expand Down Expand Up @@ -193,9 +187,9 @@ async def api_lnaddress_make_address(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(exc)
) from exc
else:
used_username = await check_address_available(data.username, data.domain)
username_free = await check_address_available(data.username, data.domain)
# If username is already taken
if used_username:
if not username_free:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
detail="Alias/username already taken.",
Expand Down Expand Up @@ -251,17 +245,16 @@ async def api_address_send_address(payment_hash):

@lnaddress_api_router.delete("/api/v1/addresses/{address_id}")
async def api_address_delete(
address_id, g: WalletTypeInfo = Depends(require_admin_key)
address_id, key_info: WalletTypeInfo = Depends(require_admin_key)
):
address = await get_address(address_id)
if not address:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="Address does not exist."
)
if address.wallet != g.wallet.id:
if address.wallet != key_info.wallet.id:
raise HTTPException(
status_code=HTTPStatus.FORBIDDEN, detail="Not your address."
)

await delete_address(address_id)
return "", HTTPStatus.NO_CONTENT

0 comments on commit fdc1ed5

Please sign in to comment.