From 30ffcf7f554a2cf8eae7a36f5f569ec34bb49d1d Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Fri, 24 Feb 2023 16:37:21 +0200 Subject: [PATCH] fix: show `wss` & invoice generation --- templates/nostrrelay/public.html | 203 +++++++++++++++---------------- views_api.py | 15 ++- 2 files changed, 110 insertions(+), 108 deletions(-) diff --git a/templates/nostrrelay/public.html b/templates/nostrrelay/public.html index d300cb7..7334568 100644 --- a/templates/nostrrelay/public.html +++ b/templates/nostrrelay/public.html @@ -11,43 +11,90 @@

+
+ + +
- Public Key: - +
+
+ Relay Link: +
+
+ +
+
+ Copy +
+
-
+
+
+ Public Key: +
+
+ +
+
+
+ + +
Cost to join:
- - sats +
+ + sats +
- Pay to Join +
+ Pay to Join +
+
+ Free to join + +
- +
+
-
+
Storage cost:
-
+
sats per @@ -56,6 +103,7 @@
-
- - sats +
+
+ + sats +
- Buy storage space +
+ Buy storage space +
+
+ Free storage + +
- This is a free relay +
+ This is a free Nostr Relay +
@@ -118,77 +177,6 @@
-
- - - - - - - - - - GET - /lnurlp/api/v1/links -
Headers
- {"X-Api-Key": <invoice_key>}
-
- Body (application/json) -
-
- Returns 200 OK (application/json) -
- [<pay_link_object>, ...] -
Curl example
-
-
-
- - - - - - - - - - - - - - - -
-
-
-
@@ -211,11 +199,20 @@ storageCost: function () { if (!this.relay || !this.relay.config.storageCostValue) return 0 return this.unitsToBuy * this.relay.config.storageCostValue + }, + wssLink: function () { + this.relay.config.domain = + this.relay.config.domain || window.location.hostname + return ( + 'wss://' + this.relay.config.domain + '/nostrrelay/' + this.relay.id + ) } }, methods: { createInvoice: async function (action) { + console.log('### action', action) if (!action) return + this.invoice = '' if (!this.pubkey) { this.$q.notify({ timeout: 5000, diff --git a/views_api.py b/views_api.py index 61f361f..347b197 100644 --- a/views_api.py +++ b/views_api.py @@ -283,11 +283,13 @@ async def api_pay_to_join(data: BuyOrder): detail="Relay not found", ) - if data.action == "join" and relay.is_free_to_join: - raise ValueError("Relay is free to join") - + amount = 0 storage_to_buy = 0 - if data.action == "storage": + if data.action == "join": + if relay.is_free_to_join: + raise ValueError("Relay is free to join") + amount = int(relay.config.cost_to_join) + elif data.action == "storage": if relay.config.storage_cost_value == 0: raise ValueError("Relay storage cost is zero. Cannot buy!") if data.units_to_buy == 0: @@ -295,10 +297,13 @@ async def api_pay_to_join(data: BuyOrder): storage_to_buy = data.units_to_buy * relay.config.storage_cost_value * 1024 if relay.config.storage_cost_unit == "MB": storage_to_buy *= 1024 + amount = data.units_to_buy * relay.config.storage_cost_value + else: + raise ValueError(f"Unknown action: '{data.action}'") _, payment_request = await create_invoice( wallet_id=relay.config.wallet, - amount=int(relay.config.cost_to_join), + amount=amount, memo=f"Pubkey '{data.pubkey}' wants to join {relay.id}", extra={ "tag": "nostrrely",