Merge pull request #1116 from lnbits/add/add_tpos_last_tx_list

Add the ability to check for last (5) transactions
This commit is contained in:
Vlad Stan
2022-11-18 13:13:55 +02:00
committed by GitHub
3 changed files with 106 additions and 1 deletions

View File

@@ -229,6 +229,24 @@ async def get_wallet_payment(
return Payment.from_row(row) if row else None return Payment.from_row(row) if row else None
async def get_latest_payments_by_extension(ext_name: str, ext_id: str, limit: int = 5):
rows = await db.fetchall(
f"""
SELECT * FROM apipayments
WHERE pending = 'false'
AND extra LIKE ?
AND extra LIKE ?
ORDER BY time DESC LIMIT {limit}
""",
(
f"%{ext_name}%",
f"%{ext_id}%",
),
)
return rows
async def get_payments( async def get_payments(
*, *,
wallet_id: Optional[str] = None, wallet_id: Optional[str] = None,

View File

@@ -148,6 +148,14 @@
</div> </div>
</div> </div>
</q-page-sticky> </q-page-sticky>
<q-page-sticky position="top-right" :offset="[18, 18]">
<q-btn
@click="showLastPayments"
fab
icon="receipt_long"
color="primary"
/>
</q-page-sticky>
<q-dialog <q-dialog
v-model="invoiceDialog.show" v-model="invoiceDialog.show"
position="top" position="top"
@@ -256,6 +264,38 @@
style="font-size: min(90vw, 40em)" style="font-size: min(90vw, 40em)"
></q-icon> ></q-icon>
</q-dialog> </q-dialog>
<q-dialog v-model="lastPaymentsDialog.show" position="bottom">
<q-card class="lnbits__dialog-card">
<q-card-section class="row items-center q-pb-none">
<q-space />
<q-btn icon="close" flat round dense v-close-popup />
</q-card-section>
<q-list separator class="q-mb-lg">
<q-item v-if="!lastPaymentsDialog.data.length">
<q-item-section>
<q-item-label class="text-bold">No paid invoices</q-item-label>
</q-item-section>
</q-item>
<q-item v-for="(payment, idx) in lastPaymentsDialog.data" :key="idx">
{%raw%}
<q-item-section>
<q-item-label class="text-bold"
>{{payment.amount / 1000}} sats</q-item-label
>
<q-item-label caption lines="2"
>Hash: {{payment.checking_id.slice(0, 30)}}...</q-item-label
>
</q-item-section>
<q-item-section side top>
<q-item-label caption>{{payment.dateFrom}}</q-item-label>
<q-icon name="check" color="green" />
</q-item-section>
{%endraw%}
</q-item>
</q-list>
</q-card>
</q-dialog>
</q-page> </q-page>
</q-page-container> </q-page-container>
{% endblock %} {% block styles %} {% endblock %} {% block styles %}
@@ -296,6 +336,10 @@
tipAmount: 0.0, tipAmount: 0.0,
hasNFC: false, hasNFC: false,
nfcTagReading: false, nfcTagReading: false,
lastPaymentsDialog: {
show: false,
data: []
},
invoiceDialog: { invoiceDialog: {
show: false, show: false,
data: null, data: null,
@@ -520,6 +564,24 @@
self.exchangeRate = self.exchangeRate =
response.data.data['BTC' + self.currency][self.currency] response.data.data['BTC' + self.currency][self.currency]
}) })
},
getLastPayments() {
return axios
.get(`/tpos/api/v1/tposs/${this.tposId}/invoices`)
.then(res => {
if (res.data && res.data.length) {
let last = [...res.data]
this.lastPaymentsDialog.data = last.map(obj => {
obj.dateFrom = moment(obj.time * 1000).fromNow()
return obj
})
}
})
.catch(e => console.error(e))
},
showLastPayments() {
this.getLastPayments()
this.lastPaymentsDialog.show = true
} }
}, },
created: function () { created: function () {

View File

@@ -7,7 +7,8 @@ from lnurl import decode as decode_lnurl
from loguru import logger from loguru import logger
from starlette.exceptions import HTTPException from starlette.exceptions import HTTPException
from lnbits.core.crud import get_user from lnbits.core.crud import get_latest_payments_by_extension, get_user
from lnbits.core.models import Payment
from lnbits.core.services import create_invoice from lnbits.core.services import create_invoice
from lnbits.core.views.api import api_payment from lnbits.core.views.api import api_payment
from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key
@@ -81,6 +82,30 @@ async def api_tpos_create_invoice(
return {"payment_hash": payment_hash, "payment_request": payment_request} return {"payment_hash": payment_hash, "payment_request": payment_request}
@tpos_ext.get("/api/v1/tposs/{tpos_id}/invoices")
async def api_tpos_get_latest_invoices(tpos_id: str = None):
try:
payments = [
Payment.from_row(row)
for row in await get_latest_payments_by_extension(
ext_name="tpos", ext_id=tpos_id
)
]
except Exception as e:
raise HTTPException(status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=str(e))
return [
{
"checking_id": payment.checking_id,
"amount": payment.amount,
"time": payment.time,
"pending": payment.pending,
}
for payment in payments
]
@tpos_ext.post( @tpos_ext.post(
"/api/v1/tposs/{tpos_id}/invoices/{payment_request}/pay", status_code=HTTPStatus.OK "/api/v1/tposs/{tpos_id}/invoices/{payment_request}/pay", status_code=HTTPStatus.OK
) )