Skip to content

Commit

Permalink
offline payments
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Nov 7, 2024
1 parent c19c79f commit f0ecdbf
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 301 deletions.
14 changes: 5 additions & 9 deletions crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,15 @@

async def create_lnpos(data: CreateLnpos) -> Lnpos:

if data.device == "pos" or data.device == "atm":
lnpos_id = shortuuid.uuid()[:5]
else:
lnpos_id = urlsafe_short_hash()

lnpos_id = shortuuid.uuid()[:5]
lnpos_key = urlsafe_short_hash()

device = Lnpos(
id=lnpos_id,
key=lnpos_key,
title=data.title,
wallet=data.wallet,
profit=data.profit,
currency=data.currency,
device=data.device,
profit=data.profit or 0.0,
currency=data.currency or "sat",
)

await db.insert("lnpos.lnpos", device)
Expand Down Expand Up @@ -80,6 +74,7 @@ async def get_lnpos_payment(
return await db.fetchone(
"SELECT * FROM lnpos.lnpos_payment WHERE id = :id",
{"id": lnpos_payment_id},
LnposPayment,
)


Expand All @@ -104,6 +99,7 @@ async def get_lnpos_payment_by_payhash(
return await db.fetchone(
"SELECT * FROM lnpos.lnpos_payment WHERE payhash = :payhash",
{"payhash": payhash},
LnposPayment,
)


Expand Down
1 change: 0 additions & 1 deletion migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ async def m001_initial(db):
title TEXT NOT NULL,
wallet TEXT NOT NULL,
currency TEXT NOT NULL,
device TEXT NOT NULL,
profit FLOAT NOT NULL,
timestamp TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}
);
Expand Down
11 changes: 3 additions & 8 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Optional

from lnurl.types import LnurlPayMetadata
from pydantic import BaseModel
Expand All @@ -7,9 +8,8 @@
class CreateLnpos(BaseModel):
title: str
wallet: str
currency: str
device: str
profit: float
currency: Optional[str] = "sat"
profit: Optional[float] = None


class Lnpos(BaseModel):
Expand All @@ -19,7 +19,6 @@ class Lnpos(BaseModel):
wallet: str
profit: float
currency: str
device: str

@property
def lnurlpay_metadata(self) -> LnurlPayMetadata:
Expand All @@ -33,7 +32,3 @@ class LnposPayment(BaseModel):
payload: str
pin: int
sats: int


class Lnurlencode(BaseModel):
url: str
33 changes: 17 additions & 16 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ window.app = Vue.createApp({
location: window.location.hostname,
filter: '',
currency: 'USD',
lnurlValue: '',
deviceString: '',
lnposs: [],
lnposTable: {
columns: [
Expand Down Expand Up @@ -86,8 +86,8 @@ window.app = Vue.createApp({
}
}
LNbits.api
.request('POST', '/lnpos/api/v1/lnurlpos', wallet, updatedData)
.then((response) => {
.request('POST', '/lnpos/api/v1', wallet, updatedData)
.then(response => {
this.lnposs.push(response.data)
this.formDialog.show = false
this.clearFormDialog()
Expand All @@ -98,24 +98,24 @@ window.app = Vue.createApp({
LNbits.api
.request(
'GET',
'/lnpos/api/v1/lnurlpos',
'/lnpos/api/v1',
this.g.user.wallets[0].adminkey
)
.then((response) => {
.then(response => {
if (response.data) {
this.lnposs = response.data
}
})
.catch(LNbits.utils.notifyApiError)
},
getLnpos: (lnpos_id) => {
getLnpos: lnpos_id => {
LNbits.api
.request(
'GET',
'/lnpos/api/v1/lnurlpos/' + lnpos_id,
'/lnpos/api/v1/' + lnpos_id,
this.g.user.wallets[0].adminkey
)
.then((response) => {
.then(response => {
localStorage.setItem('lnpos', JSON.stringify(response.data))
localStorage.setItem('inkey', this.g.user.wallets[0].inkey)
})
Expand All @@ -128,11 +128,11 @@ window.app = Vue.createApp({
LNbits.api
.request(
'DELETE',
'/lnpos/api/v1/lnurlpos/' + lnposId,
'/lnpos/api/v1/' + lnposId,
this.g.user.wallets[0].adminkey
)
.then((response) => {
this.lnposs = _.reject(this.lnposs, (obj) => {
.then(response => {
this.lnposs = _.reject(this.lnposs, obj => {
return obj.id === lnposId
})
})
Expand All @@ -143,14 +143,15 @@ window.app = Vue.createApp({
const lnpos = _.findWhere(this.lnposs, {
id: lnposId
})
this.formDialog.data = _.clone(lnpos._data)
this.formDialog.data = _.clone(lnpos)
this.formDialog.show = true
},
openSettings(lnposId) {
const lnpos = _.findWhere(this.lnposs, {
id: lnposId
})
this.settingsDialog.data = _.clone(lnpos._data)
this.deviceString = this.protocol + '//' + this.location + '/lnpos/api/v1/lnurl/' + lnpos.id + ',' + lnpos.key + ',' + lnpos.currency
this.settingsDialog.data = _.clone(lnpos)
this.settingsDialog.show = true
},
updateLnpos(wallet, data) {
Expand All @@ -164,12 +165,12 @@ window.app = Vue.createApp({
LNbits.api
.request(
'PUT',
'/lnpos/api/v1/lnurlpos/' + updatedData.id,
'/lnpos/api/v1/' + updatedData.id,
wallet,
updatedData
)
.then((response) => {
this.lnposs = _.reject(this.lnposs, (obj) => {
.then(response => {
this.lnposs = _.reject(this.lnposs, obj => {
return obj.id === updatedData.id
})
this.lnposs.push(response.data)
Expand Down
19 changes: 8 additions & 11 deletions templates/lnpos/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ <h3 class="q-my-none">LNURL-pay not paid</h3>
</q-card-section>
</q-card>
</div>

{% endblock %} {% block scripts %}

<script>
window.app = Vue.createApp({
el: '#vue',
mixins: [windowMixin]
})
</script>

{% endblock %}
</div>
{% endblock %} {% block scripts %}
<script>
window.app = Vue.createApp({
el: '#vue',
mixins: [windowMixin]
})
</script>
{% endblock %}
21 changes: 21 additions & 0 deletions templates/lnpos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,27 @@ <h6 class="text-subtitle1 q-my-none">{{SITE_TITLE}} LNPoS Extension</h6>
</q-card>
</div>

<q-dialog
v-model="settingsDialog.show"
deviceition="top"
@hide="closeFormDialog"
>
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
<div class="text-h6">Device string</div>
<q-btn
dense
outline
unelevated
color="primary"
size="md"
@click="copyText(deviceString, 'Link copied to clipboard!')"
>
<span v-text="deviceString"></span>
<q-tooltip>Click to copy URL</q-tooltip>
</q-btn>
</q-card>
</q-dialog>

<q-dialog v-model="formDialog.show" deviceition="top" @hide="closeFormDialog">
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
<q-form @submit="sendFormData" class="q-gutter-md">
Expand Down
22 changes: 8 additions & 14 deletions templates/lnpos/paid.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ <h3 class="q-my-none">{{ pin }}</h3>
</q-card-section>
</q-card>
</div>

{% endblock %} {% block scripts %}

<script>
new Vue({
el: '#vue',
mixins: [windowMixin],
data: function () {
return {}
}
})
</script>

{% endblock %}
</div>
{% endblock %} {% block scripts %}
<script>
window.app = Vue.createApp({
el: '#vue',
mixins: [windowMixin]
})
</script>
{% endblock %}
Loading

0 comments on commit f0ecdbf

Please sign in to comment.