From a761a1cf68473394fb3723d35df2f23041f0a8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Mon, 4 Nov 2024 11:59:15 +0100 Subject: [PATCH] fix: finish refactoring --- crud.py | 15 +- migrations.py | 6 +- models.py | 7 +- static/js/index.js | 417 +++++++---------------------- templates/bitcoinswitch/index.html | 387 +++++++++----------------- views_api.py | 19 +- views_lnurl.py | 11 +- 7 files changed, 263 insertions(+), 599 deletions(-) diff --git a/crud.py b/crud.py index 5399558..de4db2d 100644 --- a/crud.py +++ b/crud.py @@ -1,3 +1,4 @@ +from datetime import datetime, timezone from typing import Optional from lnbits.db import Database @@ -7,7 +8,6 @@ Bitcoinswitch, BitcoinswitchPayment, CreateBitcoinswitch, - Switches, ) db = Database("ext_bitcoinswitch") @@ -24,13 +24,14 @@ async def create_bitcoinswitch( title=data.title, wallet=data.wallet, currency=data.currency, - switches=Switches(switches=data.switches), + switches=data.switches, ) await db.insert("bitcoinswitch.switch", device) return device async def update_bitcoinswitch(device: Bitcoinswitch) -> Bitcoinswitch: + device.updated_at = datetime.now(timezone.utc) await db.update("bitcoinswitch.switch", device) return device @@ -77,15 +78,16 @@ async def create_bitcoinswitch_payment( payment_hash=payment_hash, sats=amount_msat, ) - await db.update("bitcoinswitch.payment", payment) + await db.insert("bitcoinswitch.payment", payment) return payment async def update_bitcoinswitch_payment( - bitcoinswitchpayment: BitcoinswitchPayment, + bitcoinswitch_payment: BitcoinswitchPayment, ) -> BitcoinswitchPayment: - await db.update("bitcoinswitch.payment", bitcoinswitchpayment) - return bitcoinswitchpayment + bitcoinswitch_payment.updated_at = datetime.now(timezone.utc) + await db.update("bitcoinswitch.payment", bitcoinswitch_payment) + return bitcoinswitch_payment async def delete_bitcoinswitch_payment(bitcoinswitch_payment_id: str) -> None: @@ -101,6 +103,7 @@ async def get_bitcoinswitch_payment( return await db.fetchone( "SELECT * FROM bitcoinswitch.payment WHERE id = :id", {"id": bitcoinswitchpayment_id}, + BitcoinswitchPayment, ) diff --git a/migrations.py b/migrations.py index 0b85971..29ce8b9 100644 --- a/migrations.py +++ b/migrations.py @@ -16,7 +16,8 @@ async def m001_initial(db): wallet TEXT NOT NULL, currency TEXT NOT NULL, switches TEXT NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now} + created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}, + updated_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now} ); """ ) @@ -29,7 +30,8 @@ async def m001_initial(db): payload TEXT NOT NULL, pin INT, sats {db.big_int}, - created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now} + created_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now}, + updated_at TIMESTAMP NOT NULL DEFAULT {db.timestamp_now} ); """ ) diff --git a/models.py b/models.py index 20dded5..95e28df 100644 --- a/models.py +++ b/models.py @@ -37,17 +37,13 @@ class CreateBitcoinswitch(BaseModel): switches: list[Switch] -class Switches(BaseModel): - switches: list[Switch] - - class Bitcoinswitch(BaseModel): id: str title: str wallet: str currency: str key: str - switches: Switches + switches: list[Switch] created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) @@ -64,3 +60,4 @@ class BitcoinswitchPayment(BaseModel): pin: int sats: int created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) + updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc)) diff --git a/static/js/index.js b/static/js/index.js index ac897dc..a7d97c0 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1,32 +1,8 @@ -Vue.component(VueQrcode.name, VueQrcode) - -var maplnurldevice = obj => { - obj._data = _.clone(obj) - obj.theTime = obj.time * 60 - (Date.now() / 1000 - obj.timestamp) - obj.time = obj.time + 'mins' - - if (obj.time_elapsed) { - obj.date = 'Time elapsed' - } else { - obj.date = Quasar.utils.date.formatDate( - new Date((obj.theTime - 3600) * 1000), - 'HH:mm:ss' - ) - } - return obj -} -var mapatmpayments = obj => { - obj._data = _.clone(obj) - obj.time = obj.timestamp * 60 - (Date.now() / 1000 - obj.timestamp) - return obj -} - -new Vue({ +window.app = Vue.createApp({ el: '#vue', mixins: [windowMixin], - data: function () { + data() { return { - tab: 'mails', protocol: window.location.protocol, location: window.location.hostname, wslocation: window.location.hostname, @@ -34,25 +10,8 @@ new Vue({ currency: 'USD', lnurlValue: '', websocketMessage: '', - lnurldeviceLinks: [], - atmLinks: [], - lnurldeviceLinksObj: [], - boltzToggleState: false, - devices: [ - { - label: 'PoS', - value: 'pos' - }, - { - label: 'ATM', - value: 'atm' - }, - { - label: 'Switch', - value: 'switch' - } - ], - lnurldevicesTable: { + bitcoinswitches: [], + bitcoinswitchTable: { columns: [ { name: 'title', @@ -60,85 +19,37 @@ new Vue({ label: 'title', field: 'title' }, - { - name: 'theId', - align: 'left', - label: 'id', - field: 'id' - }, - { - name: 'key', - align: 'left', - label: 'key', - field: 'key' - }, { name: 'wallet', align: 'left', label: 'wallet', field: 'wallet' }, - { - name: 'device', - align: 'left', - label: 'device', - field: 'device' - }, { name: 'currency', align: 'left', label: 'currency', field: 'currency' - } - ], - pagination: { - rowsPerPage: 10 - } - }, - atmTable: { - columns: [ - { - name: 'id', - align: 'left', - label: 'ID', - field: 'id' }, { - name: 'deviceid', - align: 'left', - label: 'Device ID', - field: 'deviceid' - }, - { - name: 'sats', - align: 'left', - label: 'Sats', - field: 'sats' - }, - { - name: 'time', + name: 'key', align: 'left', - label: 'Date', - field: 'time' + label: 'key', + field: 'key' } ], pagination: { rowsPerPage: 10 } }, - passedlnurldevice: {}, settingsDialog: { show: false, data: {} }, formDialog: { - show: false, - data: {} - }, - formDialoglnurldevice: { show: false, data: { - extra: [], + switches: [], lnurl_toggle: false, show_message: false, show_ack: false, @@ -156,29 +67,26 @@ new Vue({ } }, computed: { - wsMessage: function () { + wsMessage() { return this.websocketMessage } }, methods: { - openQrCodeDialog: function (lnurldevice_id) { - var lnurldevice = _.findWhere(this.lnurldeviceLinks, { - id: lnurldevice_id + openQrCodeDialog(bitcoinswitchId) { + const bitcoinswitch = _.findWhere(this.bitcoinswitches, { + id: bitcoinswitchId }) - this.qrCodeDialog.data = _.clone(lnurldevice) + this.qrCodeDialog.data = _.clone(bitcoinswitch) this.qrCodeDialog.data.url = window.location.protocol + '//' + window.location.host - this.lnurlValue = this.qrCodeDialog.data.extra[0].lnurl + this.lnurlValue = this.qrCodeDialog.data.switches[0].lnurl this.websocketConnector( - 'wss://' + window.location.host + '/api/v1/ws/' + lnurldevice_id + 'wss://' + window.location.host + '/api/v1/ws/' + bitcoinswitchId ) this.qrCodeDialog.show = true }, - addSwitch: function () { - if (!this.formDialoglnurldevice.data.extra) { - this.formDialoglnurldevice.data.extra = [] - } - this.formDialoglnurldevice.data.extra.push({ + addSwitch() { + this.formDialog.data.switches.push({ amount: 10, pin: 0, duration: 1000, @@ -186,125 +94,113 @@ new Vue({ comment: false }) }, - removeSwitch: function () { - this.formDialoglnurldevice.data.extra.pop() + removeSwitch() { + this.formDialog.data.switches.pop() }, - - cancellnurldevice: function (data) { - var self = this - self.formDialoglnurldevice.show = false - self.clearFormDialoglnurldevice() + cancelFormDialog() { + this.formDialog.show = false + this.clearFormDialog() }, - closeFormDialog: function () { - this.clearFormDialoglnurldevice() + closeFormDialog() { + this.clearFormDialog() this.formDialog.data = { is_unique: false } }, - sendFormDatalnurldevice: function () { - var self = this - if (!self.formDialoglnurldevice.data.profit) { - self.formDialoglnurldevice.data.profit = 0 - } - if (self.formDialoglnurldevice.data.id) { - this.updatelnurldevice( - self.g.user.wallets[0].adminkey, - self.formDialoglnurldevice.data + sendFormData() { + if (this.formDialog.data.id) { + this.updateBitcoinswitch( + this.g.user.wallets[0].adminkey, + this.formDialog.data ) } else { - this.createlnurldevice( - self.g.user.wallets[0].adminkey, - self.formDialoglnurldevice.data + this.createBitcoinswitch( + this.g.user.wallets[0].adminkey, + this.formDialog.data ) } }, - createlnurldevice: function (wallet, data) { - var self = this - var updatedData = {} + createBitcoinswitch(wallet, data) { + const updatedData = {} for (const property in data) { if (data[property]) { updatedData[property] = data[property] } } - LNbits.api - .request('POST', '/lnurldevice/api/v1/lnurlpos', wallet, updatedData) - .then(function (response) { - self.lnurldeviceLinks.push(maplnurldevice(response.data)) - self.formDialoglnurldevice.show = false - self.clearFormDialoglnurldevice() - }) - .catch(function (error) { - LNbits.utils.notifyApiError(error) - }) - }, - getlnurldevices: function () { - var self = this LNbits.api .request( - 'GET', - '/lnurldevice/api/v1/lnurlpos', - self.g.user.wallets[0].adminkey + 'POST', + '/bitcoinswitch/api/v1/bitcoinswitch', + wallet, + updatedData ) - .then(function (response) { - if (response.data) { - self.lnurldeviceLinks = response.data.map(maplnurldevice) - } + .then(response => { + this.bitcoinswitches.push(response.data) + this.formDialog.show = false + this.clearFormDialog() }) .catch(function (error) { LNbits.utils.notifyApiError(error) }) }, - getatmpayments: function () { - var self = this + updateBitcoinswitch(wallet, data) { + const updatedData = {} + for (const property in data) { + if (data[property]) { + updatedData[property] = data[property] + } + } LNbits.api .request( - 'GET', - '/lnurldevice/api/v1/atm', - self.g.user.wallets[0].adminkey + 'PUT', + '/bitcoinswitch/api/v1/bitcoinswitch/' + updatedData.id, + wallet, + updatedData ) - .then(function (response) { - if (response.data) { - self.atmLinks = response.data.map(mapatmpayments) - } + .then(response => { + this.bitcoinswitches = _.reject(this.bitcoinswitches, function (obj) { + return obj.id === updatedData.id + }) + this.bitcoinswitches.push(response.data) + this.formDialog.show = false + this.clearFormDialog() }) .catch(function (error) { LNbits.utils.notifyApiError(error) }) }, - getlnurldevice: function (lnurldevice_id) { - var self = this + getBitcoinswitches() { LNbits.api .request( 'GET', - '/lnurldevice/api/v1/lnurlpos/' + lnurldevice_id, - self.g.user.wallets[0].adminkey + '/bitcoinswitch/api/v1/bitcoinswitch', + this.g.user.wallets[0].adminkey ) - .then(function (response) { - localStorage.setItem('lnurldevice', JSON.stringify(response.data)) - localStorage.setItem('inkey', self.g.user.wallets[0].inkey) + .then(response => { + if (response.data.length > 0) { + this.bitcoinswitches = response.data + } }) .catch(function (error) { LNbits.utils.notifyApiError(error) }) }, - deletelnurldeviceLink: function (lnurldeviceId) { - var self = this - var link = _.findWhere(this.lnurldeviceLinks, {id: lnurldeviceId}) + deleteBitcoinswitch(bitcoinswitchId) { LNbits.utils .confirmDialog('Are you sure you want to delete this pay link?') - .onOk(function () { + .onOk(() => { LNbits.api .request( 'DELETE', - '/lnurldevice/api/v1/lnurlpos/' + lnurldeviceId, - self.g.user.wallets[0].adminkey + '/bitcoinswitch/api/v1/bitcoinswitch/' + bitcoinswitchId, + this.g.user.wallets[0].adminkey ) - .then(function (response) { - self.lnurldeviceLinks = _.reject( - self.lnurldeviceLinks, + .then(() => { + this.bitcoinswitches = _.reject( + this.bitcoinswitches, function (obj) { - return obj.id === lnurldeviceId + return obj.id === bitcoinswitchId } ) }) @@ -313,108 +209,39 @@ new Vue({ }) }) }, - deleteATMLink: function (atmId) { - var self = this - var link = _.findWhere(this.atmLinks, {id: atmId}) - LNbits.utils - .confirmDialog('Are you sure you want to delete this atm link?') - .onOk(function () { - LNbits.api - .request( - 'DELETE', - '/lnurldevice/api/v1/atm/' + atmId, - self.g.user.wallets[0].adminkey - ) - .then(function (response) { - self.atmLinks = _.reject(self.atmLinks, function (obj) { - return obj.id === atmId - }) - }) - .catch(function (error) { - LNbits.utils.notifyApiError(error) - }) - }) - }, - openUpdatelnurldeviceLink: function (lnurldeviceId) { - var self = this - var lnurldevice = _.findWhere(this.lnurldeviceLinks, { - id: lnurldeviceId + openUpdateBitcoinswitch(bitcoinswitchId) { + const bitcoinswitch = _.findWhere(this.bitcoinswitches, { + id: bitcoinswitchId }) - self.formDialoglnurldevice.data = _.clone(lnurldevice._data) - if (lnurldevice.device == 'atm' && lnurldevice.extra == 'boltz') { - self.boltzToggleState = true - } else { - self.boltzToggleState = false - } - self.formDialoglnurldevice.show = true + this.formDialog.data = _.clone(bitcoinswitch) + this.formDialog.show = true }, - openlnurldeviceSettings: function (lnurldeviceId) { - var self = this - var lnurldevice = _.findWhere(this.lnurldeviceLinks, { - id: lnurldeviceId + openBitcoinswitchSettings(bitcoinswitchId) { + const bitcoinswitch = _.findWhere(this.bitcoinswitches, { + id: bitcoinswitchId }) - self.settingsDialog.data = _.clone(lnurldevice._data) - self.settingsDialog.show = true - }, - handleBoltzToggleChange(val) { - if (val) { - this.formDialoglnurldevice.data.extra = 'boltz' - } else { - this.formDialoglnurldevice.data.extra = '' - } + this.settingsDialog.data = _.clone(bitcoinswitch) + this.settingsDialog.show = true }, - updatelnurldevice: function (wallet, data) { - var self = this - var updatedData = {} - for (const property in data) { - if (data[property]) { - updatedData[property] = data[property] - } - } - - LNbits.api - .request( - 'PUT', - '/lnurldevice/api/v1/lnurlpos/' + updatedData.id, - wallet, - updatedData - ) - .then(function (response) { - self.lnurldeviceLinks = _.reject( - self.lnurldeviceLinks, - function (obj) { - return obj.id === updatedData.id - } - ) - self.lnurldeviceLinks.push(maplnurldevice(response.data)) - self.formDialoglnurldevice.show = false - self.clearFormDialoglnurldevice() - }) - .catch(function (error) { - LNbits.utils.notifyApiError(error) - }) - }, - websocketConnector: function (websocketUrl) { + websocketConnector(websocketUrl) { if ('WebSocket' in window) { - self = this - var ws = new WebSocket(websocketUrl) - self.updateWsMessage('Websocket connected') - ws.onmessage = function (evt) { - var received_msg = evt.data - self.updateWsMessage('Message received: ' + received_msg) + const ws = new WebSocket(websocketUrl) + this.updateWsMessage('Websocket connected') + ws.onmessage = evt => { + this.updateWsMessage('Message received: ' + evt.data) } - ws.onclose = function () { - self.updateWsMessage('Connection closed') + ws.onclose = () => { + this.updateWsMessage('Connection closed') } } else { - self.updateWsMessage('WebSocket NOT supported by your Browser!') + this.updateWsMessage('WebSocket NOT supported by your Browser!') } }, - updateWsMessage: function (message) { + updateWsMessage(message) { this.websocketMessage = message }, - clearFormDialoglnurldevice() { - this.formDialoglnurldevice.data = { + clearFormDialog() { + this.formDialog.data = { lnurl_toggle: false, show_message: false, show_ack: false, @@ -422,60 +249,24 @@ new Vue({ title: '' } }, - exportlnurldeviceCSV: function () { - var self = this + exportCSV() { LNbits.utils.exportCSV( - self.lnurldevicesTable.columns, - this.lnurldeviceLinks + this.bitcoinswitchTable.columns, + this.bitcoinswitches ) - }, - exportATMCSV: function () { - var self = this - LNbits.utils.exportCSV(self.atmTable.columns, this.atmLinks) - }, - openATMLink: function (deviceid, p) { - var self = this - var url = - this.location + - '/lnurldevice/api/v1/lnurl/' + - deviceid + - '?atm=1&p=' + - p - data = { - url: url - } - LNbits.api - .request( - 'POST', - '/lnurldevice/api/v1/lnurlencode', - self.g.user.wallets[0].adminkey, - data - ) - .then(function (response) { - window.open('/lnurldevice/atm?lightning=' + response.data) - }) - .catch(function (error) { - LNbits.utils.notifyApiError(error) - }) } }, - created: function () { - var self = this - var getlnurldevices = this.getlnurldevices - getlnurldevices() - var getatmpayments = this.getatmpayments - getatmpayments() - self.location = [window.location.protocol, '//', window.location.host].join( + created() { + this.getBitcoinswitches() + this.location = [window.location.protocol, '//', window.location.host].join( '' ) - self.wslocation = ['ws://', window.location.host].join('') + this.wslocation = ['ws://', window.location.host].join('') LNbits.api .request('GET', '/api/v1/currencies') .then(response => { this.currency = ['sat', 'USD', ...response.data] }) - .catch(err => { - LNbits.utils.notifyApiError(err) - }) + .catch(LNbits.utils.notifyApiError) } }) diff --git a/templates/bitcoinswitch/index.html b/templates/bitcoinswitch/index.html index 79ba722..9757562 100644 --- a/templates/bitcoinswitch/index.html +++ b/templates/bitcoinswitch/index.html @@ -4,12 +4,8 @@
- {% raw %} - New LNURLDevice instance + New Bitcoinswitch @@ -18,7 +14,7 @@
-
LNURLdevice
+
Bitcoin Switches
@@ -33,19 +29,16 @@
LNURLdevice
- Export to CSV + Export to CSV
@@ -74,11 +65,11 @@
LNURLdevice
flat dense size="xs" - @click="openUpdatelnurldeviceLink(props.row.id)" + @click="openUpdateBitcoinswitch(props.row.id)" icon="edit" color="blue" > - Edit LNURLDevice + Edit Bitcoinswitch @@ -86,11 +77,11 @@
LNURLdevice
flat dense size="xs" - @click="deletelnurldeviceLink(props.row.id)" + @click="deleteBitcoinswitch(props.row.id)" icon="cancel" color="pink" > - Delete LNURLDevice + Delete Bitcoinswitch
@@ -98,23 +89,21 @@
LNURLdevice
flat dense size="xs" - @click="openlnurldeviceSettings(props.row.id)" + @click="openBitcoinswitchSettings(props.row.id)" icon="perm_data_setting" color="primary" > - LNURLDevice Settings + Bitcoinswitch Settings
LNURLs only work over HTTPS LNURLdevice auto-width >
-
{{ col.value }}
-
- - -
-
- - - - -
-
-
ATM Payments
-
- -
- - - - Export to CSV -
-
- - - - - {% endraw %}
@@ -231,28 +130,20 @@
ATM Payments
- {{SITE_TITLE}} LNURLDevice Extension (0.4) + {{SITE_TITLE}} Bitcoinswitch Extension

- For LNURL based Points of Sale, ATMs, and relay devices
- LNPoS: - - https://lnbits.github.io/lnpos
- bitcoinSwitch: + Turn on and off things with bitcoin!
+ Bitcoin Switch Hardware: https://github.com/lnbits/bitcoinSwitch
- FOSSA: - - https://github.com/lnbits/fossa
Created by, size="md" @click="copyText(wslocation + '/api/v1/ws/' + settingsDialog.data.id, 'Link copied to clipboard!')" > - {% raw %}{{wslocation}}/api/v1/ws/{{settingsDialog.data.id}}{% endraw - %} Click to copy URL + + Click to copy URL unelevated color="primary" size="md" - @click="copyText(location + '/lnurldevice/api/v1/lnurl/' + settingsDialog.data.id + ',' + settingsDialog.data.key + ',' + settingsDialog.data.currency, 'Link copied to clipboard!')" + @click="copyText(location + '/bitcoinswitch/api/v1/lnurl/' + settingsDialog.data.id + ',' + settingsDialog.data.key + ',' + settingsDialog.data.currency, 'Link copied to clipboard!')" > - {% raw - %}{{location}}/lnurldevice/api/v1/lnurl/{{settingsDialog.data.id}}, - {{settingsDialog.data.key}}, {{settingsDialog.data.currency}}{% endraw - %} + Click to copy URL -

- + - -
+ +
@@ -342,134 +222,109 @@
filled dense emit-value - v-model="formDialoglnurldevice.data.wallet" + v-model="formDialog.data.wallet" :options="g.user.walletOptions" label="Wallet *" > - - -
- - -
-
-
- -
-
- -
-
- -
-
- Variable time (Amount * Duration) - - Enable LNURLp comments with payments - -
+ > + +
+
+
+ +
+
+ +
+
+ +
+
+ Variable time (Amount * Duration) + + Enable LNURLp comments with payments +
-
Update lnurldeviceUpdate Bitcoin Switch Create lnurldeviceCreate Bitcoin Switch - Cancel
@@ -479,13 +334,17 @@
- - - + +
+ Trigger Device text-color="white" icon="error" > - {% raw %}{{ wsMessage }}{% endraw %} + + + + - {% raw %}{{ wsMessage }}{% endraw %} -
-
{% endblock %} {% block scripts %} {{ window_vars(user) }} - + {% endblock %} diff --git a/views_api.py b/views_api.py index 2ae9113..006182f 100644 --- a/views_api.py +++ b/views_api.py @@ -31,7 +31,9 @@ async def api_bitcoinswitch_create( bitcoinswitch_id = urlsafe_short_hash() # compute lnurl for each pin of switch - url = request.url_for("bitcoinswitch.lnurl_params", device_id=bitcoinswitch_id) + url = request.url_for( + "bitcoinswitch.lnurl_params", bitcoinswitch_id=bitcoinswitch_id + ) for switch in data.switches: switch.set_lnurl(str(url)) @@ -42,15 +44,28 @@ async def api_bitcoinswitch_create( "/api/v1/bitcoinswitch/{bitcoinswitch_id}", dependencies=[Depends(require_admin_key)], ) -async def api_bitcoinswitch_update(data: CreateBitcoinswitch, bitcoinswitch_id: str): +async def api_bitcoinswitch_update( + request: Request, data: CreateBitcoinswitch, bitcoinswitch_id: str +): bitcoinswitch = await get_bitcoinswitch(bitcoinswitch_id) if not bitcoinswitch: raise HTTPException( status_code=HTTPStatus.NOT_FOUND, detail="bitcoinswitch does not exist" ) + for k, v in data.dict().items(): if v is not None: setattr(bitcoinswitch, k, v) + + # compute lnurl for each pin of switch + url = request.url_for( + "bitcoinswitch.lnurl_params", bitcoinswitch_id=bitcoinswitch_id + ) + for switch in data.switches: + switch.set_lnurl(str(url)) + + bitcoinswitch.switches = data.switches + return await update_bitcoinswitch(bitcoinswitch) diff --git a/views_lnurl.py b/views_lnurl.py index 13401a4..4b8f19f 100644 --- a/views_lnurl.py +++ b/views_lnurl.py @@ -16,24 +16,24 @@ @bitcoinswitch_lnurl_router.get( - "{switch_id}", + "{bitcoinswitch_id}", status_code=HTTPStatus.OK, name="bitcoinswitch.lnurl_params", ) async def lnurl_params( request: Request, - switch_id: str, + bitcoinswitch_id: str, pin: str, amount: str, duration: str, variable: bool = Query(None), comment: bool = Query(None), ): - switch = await get_bitcoinswitch(switch_id) + switch = await get_bitcoinswitch(bitcoinswitch_id) if not switch: return { "status": "ERROR", - "reason": f"bitcoinswitch {switch_id} not found on this server", + "reason": f"bitcoinswitch {bitcoinswitch_id} not found on this server", } price_msat = int( @@ -47,7 +47,7 @@ async def lnurl_params( # Check they're not trying to trick the switch! check = False - for _switch in switch.switches.switches: + for _switch in switch.switches: if ( _switch.pin == int(pin) and _switch.duration == int(duration) @@ -124,7 +124,6 @@ async def lnurl_callback( "id": payment_id, }, ) - bitcoinswitch_payment.payment_hash = payment.payment_hash await update_bitcoinswitch_payment(bitcoinswitch_payment)