Skip to content

Commit

Permalink
fix: update 1.0.0-rc5-3
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Oct 22, 2024
1 parent e3d5295 commit b299508
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
9 changes: 8 additions & 1 deletion models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
from typing import Optional

from fastapi import Request
from fastapi import Query, Request
from lnurl import Lnurl
from lnurl import encode as lnurl_encode
from pydantic import BaseModel, Field, validator


class CreateTposInvoice(BaseModel):
amount: int = Query(..., ge=1)
tip_amount: int = Query(0, ge=1)
memo: str = Query(None)
details: str = Query(None)


class CreateTposData(BaseModel):
wallet: Optional[str]
name: Optional[str]
Expand Down
13 changes: 3 additions & 10 deletions static/js/tpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ window.app = Vue.createApp({
let params = {
amount: this.sat,
memo: this.amountFormatted,
tipAmount: this.tipAmountSat
tip_amount: this.tipAmountSat
}
if (this.cart.size) {
let details = [...this.cart.values()].map(item => {
Expand All @@ -449,9 +449,7 @@ window.app = Vue.createApp({
}

axios
.post('/tpos/api/v1/tposs/' + this.tposId + '/invoices', null, {
params: {...params}
})
.post(`/tpos/api/v1/tposs/${this.tposId}/invoices`, params)
.then(response => {
dialog.data = response.data
dialog.show = true
Expand All @@ -464,12 +462,7 @@ window.app = Vue.createApp({

dialog.paymentChecker = setInterval(() => {
axios
.get(
'/tpos/api/v1/tposs/' +
this.tposId +
'/invoices/' +
response.data.payment_hash
)
.get(`/tpos/api/v1/tposs/${this.tposId}/invoices/${response.data.payment_hash}`)
.then(res => {
if (res.data.paid) {
clearInterval(dialog.paymentChecker)
Expand Down
12 changes: 6 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def on_invoice_paid(payment: Payment) -> None:
):
return

tip_amount = payment.extra.get("tipAmount")
tip_amount = payment.extra.get("tip_amount")

stripped_payment = {
"amount": payment.amount,
Expand All @@ -35,7 +35,7 @@ async def on_invoice_paid(payment: Payment) -> None:
"bolt11": payment.bolt11,
}

tpos_id = payment.extra.get("tposId")
tpos_id = payment.extra.get("tpos_id")
assert tpos_id

tpos = await get_tpos(tpos_id)
Expand All @@ -50,17 +50,17 @@ async def on_invoice_paid(payment: Payment) -> None:
wallet_id = tpos.tip_wallet
assert wallet_id

payment = await create_invoice(
tip_payment = await create_invoice(
wallet_id=wallet_id,
amount=int(tip_amount),
internal=True,
memo="tpos tip",
)
logger.debug(f"tpos: tip invoice created: {payment.payment_hash}")

payment = await pay_invoice(
payment_request=payment.bolt11,
paid_payment = await pay_invoice(
payment_request=tip_payment.bolt11,
wallet_id=payment.wallet_id,
extra={**payment.extra, "tipSplitted": True},
)
logger.debug(f"tpos: tip invoice paid: {payment.checking_id}")
logger.debug(f"tpos: tip invoice paid: {paid_payment.checking_id}")
2 changes: 1 addition & 1 deletion templates/tpos/tpos.html
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ <h5 v-show="!denomIsSats" class="q-mt-none q-mb-sm">
tpos.currency = '{{ tpos.currency }}'
tpos.withdraw_premium = Number('{{ tpos.withdraw_premium }}') / 100
withdraw_maximum = Number('{{ withdraw_maximum }}')
const items = '{{ items | safe }}'
const items = '{{ tpos.items | safe }}'
tpos.items = items ? JSON.parse(items) : []
const options = '{{ tpos.tip_options | safe }}'
tpos.tip_options = options ? JSON.parse(options) : []
Expand Down
25 changes: 9 additions & 16 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
)
from .models import (
CreateTposData,
CreateTposInvoice,
CreateUpdateItemData,
LnurlCharge,
PayLnurlWData,
Expand Down Expand Up @@ -101,34 +102,26 @@ async def api_tpos_delete(
@tpos_api_router.post(
"/api/v1/tposs/{tpos_id}/invoices", status_code=HTTPStatus.CREATED
)
async def api_tpos_create_invoice(
tpos_id: str,
amount: int = Query(..., ge=1),
memo: str = "",
tip_amount: int = 0,
details: str = Query(None),
) -> dict:
async def api_tpos_create_invoice(tpos_id: str, data: CreateTposInvoice) -> dict:

tpos = await get_tpos(tpos_id)

if not tpos:
raise HTTPException(
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
)

if tip_amount > 0:
amount += tip_amount

try:
payment = await create_invoice(
wallet_id=tpos.wallet,
amount=amount,
memo=f"{memo} to {tpos.name}" if memo else f"{tpos.name}",
amount=data.amount + data.tip_amount,
memo=f"{data.memo} to {tpos.name}" if data.memo else f"{tpos.name}",
extra={
"tag": "tpos",
"tipAmount": tip_amount,
"tposId": tpos_id,
"amount": amount - tip_amount if tip_amount else False,
"details": details if details else None,
"tip_amount": data.tip_amount,
"tpos_id": tpos_id,
"amount": data.amount,
"details": data.details if data.details else None,
},
)
except Exception as exc:
Expand Down

0 comments on commit b299508

Please sign in to comment.