mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-30 10:34:28 +02:00
* small fastapi convertion * make tip add up to invoice * make tip add to invoice * display existing tpos * clean console logs * suggestion from @leesalminen * blacked
This commit is contained in:
committed by
GitHub
parent
4bb184e08b
commit
ff5b1189b5
@ -30,7 +30,7 @@ async def create_tpos(wallet_id: str, data: CreateTposData) -> TPoS:
|
|||||||
|
|
||||||
async def get_tpos(tpos_id: str) -> Optional[TPoS]:
|
async def get_tpos(tpos_id: str) -> Optional[TPoS]:
|
||||||
row = await db.fetchone("SELECT * FROM tpos.tposs WHERE id = ?", (tpos_id,))
|
row = await db.fetchone("SELECT * FROM tpos.tposs WHERE id = ?", (tpos_id,))
|
||||||
return TPoS.from_row(row) if row else None
|
return TPoS(**row) if row else None
|
||||||
|
|
||||||
|
|
||||||
async def get_tposs(wallet_ids: Union[str, List[str]]) -> List[TPoS]:
|
async def get_tposs(wallet_ids: Union[str, List[str]]) -> List[TPoS]:
|
||||||
@ -42,7 +42,7 @@ async def get_tposs(wallet_ids: Union[str, List[str]]) -> List[TPoS]:
|
|||||||
f"SELECT * FROM tpos.tposs WHERE wallet IN ({q})", (*wallet_ids,)
|
f"SELECT * FROM tpos.tposs WHERE wallet IN ({q})", (*wallet_ids,)
|
||||||
)
|
)
|
||||||
|
|
||||||
return [TPoS.from_row(row) for row in rows]
|
return [TPoS(**row) for row in rows]
|
||||||
|
|
||||||
|
|
||||||
async def delete_tpos(tpos_id: str) -> None:
|
async def delete_tpos(tpos_id: str) -> None:
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
from sqlite3 import Row
|
from sqlite3 import Row
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from fastapi import Query
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
class CreateTposData(BaseModel):
|
class CreateTposData(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
currency: str
|
currency: str
|
||||||
tip_options: str
|
tip_options: str = Query(None)
|
||||||
tip_wallet: str
|
tip_wallet: str = Query(None)
|
||||||
|
|
||||||
|
|
||||||
class TPoS(BaseModel):
|
class TPoS(BaseModel):
|
||||||
@ -15,8 +17,8 @@ class TPoS(BaseModel):
|
|||||||
wallet: str
|
wallet: str
|
||||||
name: str
|
name: str
|
||||||
currency: str
|
currency: str
|
||||||
tip_options: str
|
tip_options: Optional[str]
|
||||||
tip_wallet: str
|
tip_wallet: Optional[str]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_row(cls, row: Row) -> "TPoS":
|
def from_row(cls, row: Row) -> "TPoS":
|
||||||
|
@ -26,7 +26,6 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
|
|
||||||
# now we make some special internal transfers (from no one to the receiver)
|
# now we make some special internal transfers (from no one to the receiver)
|
||||||
tpos = await get_tpos(payment.extra.get("tposId"))
|
tpos = await get_tpos(payment.extra.get("tposId"))
|
||||||
|
|
||||||
tipAmount = payment.extra.get("tipAmount")
|
tipAmount = payment.extra.get("tipAmount")
|
||||||
|
|
||||||
if tipAmount is None:
|
if tipAmount is None:
|
||||||
@ -34,6 +33,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
return
|
return
|
||||||
|
|
||||||
tipAmount = tipAmount * 1000
|
tipAmount = tipAmount * 1000
|
||||||
|
amount = payment.amount - tipAmount
|
||||||
|
|
||||||
# mark the original payment with one extra key, "splitted"
|
# mark the original payment with one extra key, "splitted"
|
||||||
# (this prevents us from doing this process again and it's informative)
|
# (this prevents us from doing this process again and it's informative)
|
||||||
@ -41,13 +41,13 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
await core_db.execute(
|
await core_db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE apipayments
|
UPDATE apipayments
|
||||||
SET extra = ?, amount = amount - ?
|
SET extra = ?, amount = ?
|
||||||
WHERE hash = ?
|
WHERE hash = ?
|
||||||
AND checking_id NOT LIKE 'internal_%'
|
AND checking_id NOT LIKE 'internal_%'
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
json.dumps(dict(**payment.extra, tipSplitted=True)),
|
json.dumps(dict(**payment.extra, tipSplitted=True)),
|
||||||
tipAmount,
|
amount,
|
||||||
payment.payment_hash,
|
payment.payment_hash,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -60,7 +60,7 @@ async def on_invoice_paid(payment: Payment) -> None:
|
|||||||
payment_request="",
|
payment_request="",
|
||||||
payment_hash=payment.payment_hash,
|
payment_hash=payment.payment_hash,
|
||||||
amount=tipAmount,
|
amount=tipAmount,
|
||||||
memo=payment.memo,
|
memo=f"Tip for {payment.memo}",
|
||||||
pending=False,
|
pending=False,
|
||||||
extra={"tipSplitted": True},
|
extra={"tipSplitted": True},
|
||||||
)
|
)
|
||||||
|
@ -54,8 +54,8 @@
|
|||||||
></q-btn>
|
></q-btn>
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
||||||
{{ (col.name == 'tip_options' ? JSON.parse(col.value).join(", ")
|
{{ (col.name == 'tip_options' && col.value ?
|
||||||
: col.value) }}
|
JSON.parse(col.value).join(", ") : col.value) }}
|
||||||
</q-td>
|
</q-td>
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
<q-btn
|
<q-btn
|
||||||
|
@ -167,7 +167,10 @@
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h3 class="q-my-md">{% raw %}{{ famount }}{% endraw %}</h3>
|
<h3 class="q-my-md">{% raw %}{{ famount }}{% endraw %}</h3>
|
||||||
<h5 class="q-mt-none">
|
<h5 class="q-mt-none">
|
||||||
{% raw %}{{ fsat }}{% endraw %} <small>sat</small>
|
{% raw %}{{ fsat }}
|
||||||
|
<small>sat</small>
|
||||||
|
<span style="font-size: 0.75rem">( + {{ tipAmountSat }} tip)</span>
|
||||||
|
{% endraw %}
|
||||||
</h5>
|
</h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="row q-mt-lg">
|
<div class="row q-mt-lg">
|
||||||
@ -310,7 +313,6 @@
|
|||||||
return Math.ceil((this.tipAmount / this.exchangeRate) * 100000000)
|
return Math.ceil((this.tipAmount / this.exchangeRate) * 100000000)
|
||||||
},
|
},
|
||||||
fsat: function () {
|
fsat: function () {
|
||||||
console.log('sat', this.sat, LNbits.utils.formatSat(this.sat))
|
|
||||||
return LNbits.utils.formatSat(this.sat)
|
return LNbits.utils.formatSat(this.sat)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -362,7 +364,6 @@
|
|||||||
showInvoice: function () {
|
showInvoice: function () {
|
||||||
var self = this
|
var self = this
|
||||||
var dialog = this.invoiceDialog
|
var dialog = this.invoiceDialog
|
||||||
console.log(this.sat, this.tposId)
|
|
||||||
axios
|
axios
|
||||||
.post('/tpos/api/v1/tposs/' + this.tposId + '/invoices', null, {
|
.post('/tpos/api/v1/tposs/' + this.tposId + '/invoices', null, {
|
||||||
params: {
|
params: {
|
||||||
|
@ -17,7 +17,7 @@ from .models import CreateTposData
|
|||||||
|
|
||||||
@tpos_ext.get("/api/v1/tposs", status_code=HTTPStatus.OK)
|
@tpos_ext.get("/api/v1/tposs", status_code=HTTPStatus.OK)
|
||||||
async def api_tposs(
|
async def api_tposs(
|
||||||
all_wallets: bool = Query(None), wallet: WalletTypeInfo = Depends(get_key_type)
|
all_wallets: bool = Query(False), wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
wallet_ids = [wallet.wallet.id]
|
wallet_ids = [wallet.wallet.id]
|
||||||
if all_wallets:
|
if all_wallets:
|
||||||
@ -63,6 +63,9 @@ async def api_tpos_create_invoice(
|
|||||||
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
status_code=HTTPStatus.NOT_FOUND, detail="TPoS does not exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if tipAmount:
|
||||||
|
amount += tipAmount
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payment_hash, payment_request = await create_invoice(
|
payment_hash, payment_request = await create_invoice(
|
||||||
wallet_id=tpos.wallet,
|
wallet_id=tpos.wallet,
|
||||||
|
Reference in New Issue
Block a user