From 6c4b5ea406ac2f8c19dcdda6d9356945f0c884aa Mon Sep 17 00:00:00 2001 From: Kristjan Date: Tue, 29 Dec 2020 20:52:54 +0100 Subject: [PATCH] working subdomains frontend, table, popup, payments --- lnbits/extensions/subdomains/crud.py | 15 +- lnbits/extensions/subdomains/migrations.py | 1 + lnbits/extensions/subdomains/models.py | 2 + .../templates/subdomains/display.html | 27 ++-- .../templates/subdomains/index.html | 140 ++++++++++++++---- lnbits/extensions/subdomains/views.py | 4 +- lnbits/extensions/subdomains/views_api.py | 6 +- 7 files changed, 143 insertions(+), 52 deletions(-) diff --git a/lnbits/extensions/subdomains/crud.py b/lnbits/extensions/subdomains/crud.py index 4bad6768f..0ecb88147 100644 --- a/lnbits/extensions/subdomains/crud.py +++ b/lnbits/extensions/subdomains/crud.py @@ -16,13 +16,14 @@ async def create_subdomain( email: str, ip: str, sats: int, + duration: int ) -> Subdomains: await db.execute( """ - INSERT INTO subdomain (id, domain, email, subdomain, ip, wallet, sats, paid) - VALUES (?, ?, ?, ?, ?, ?, ?, ?) + INSERT INTO subdomain (id, domain, email, subdomain, ip, wallet, sats, duration, paid) + VALUES (?, ?, ?, ?, ?, ?, ?, ?,?) """, - (payment_hash, domain, email, subdomain, ip, wallet, sats, False), + (payment_hash, domain, email, subdomain, ip, wallet, sats, duration, False), ) subdomain = await get_subdomain(payment_hash) @@ -32,7 +33,7 @@ async def create_subdomain( async def set_subdomain_paid(payment_hash: str) -> Subdomains: row = await db.fetchone("SELECT * FROM subdomain WHERE id = ?", (payment_hash,)) - if row[7] == False: + if row[8] == False: await db.execute( """ UPDATE subdomain @@ -45,7 +46,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains: domaindata = await get_domain(row[1]) assert domaindata, "Couldn't get domain from paid subdomain" - amount = domaindata.amountmade + row[7] + amount = domaindata.amountmade + row[8] await db.execute( """ UPDATE domain @@ -77,7 +78,7 @@ async def set_subdomain_paid(payment_hash: str) -> Subdomains: async def get_subdomain(subdomain_id: str) -> Optional[Subdomains]: - row = await db.fetchone("SELECT * FROM subdomain WHERE id = ?", (subdomain_id,)) + row = await db.fetchone("SELECT * FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.id = ?", (subdomain_id,)) return Subdomains(**row) if row else None @@ -86,7 +87,7 @@ async def get_subdomains(wallet_ids: Union[str, List[str]]) -> List[Subdomains]: wallet_ids = [wallet_ids] q = ",".join(["?"] * len(wallet_ids)) - rows = await db.fetchall(f"SELECT * FROM subdomain WHERE wallet IN ({q})", (*wallet_ids,)) + rows = await db.fetchall(f"SELECT s.*, d.domain as domain_name FROM subdomain s INNER JOIN domain d ON (s.domain = d.id) WHERE s.wallet IN ({q})", (*wallet_ids,)) return [Subdomains(**row) for row in rows] diff --git a/lnbits/extensions/subdomains/migrations.py b/lnbits/extensions/subdomains/migrations.py index 7d4fa4d71..75080280f 100644 --- a/lnbits/extensions/subdomains/migrations.py +++ b/lnbits/extensions/subdomains/migrations.py @@ -27,6 +27,7 @@ async def m001_initial(db): ip TEXT NOT NULL, wallet TEXT NOT NULL, sats INTEGER NOT NULL, + duration INTEGER NOT NULL, paid BOOLEAN NOT NULL, time TIMESTAMP NOT NULL DEFAULT (strftime('%s', 'now')) ); diff --git a/lnbits/extensions/subdomains/models.py b/lnbits/extensions/subdomains/models.py index e248811d9..a1d14070b 100644 --- a/lnbits/extensions/subdomains/models.py +++ b/lnbits/extensions/subdomains/models.py @@ -18,9 +18,11 @@ class Subdomains(NamedTuple): id: str wallet: str domain: str + domain_name: str subdomain: str email: str ip: str sats: int + duration: int paid: bool time: int diff --git a/lnbits/extensions/subdomains/templates/subdomains/display.html b/lnbits/extensions/subdomains/templates/subdomains/display.html index f57e079f9..90c91b581 100644 --- a/lnbits/extensions/subdomains/templates/subdomains/display.html +++ b/lnbits/extensions/subdomains/templates/subdomains/display.html @@ -3,9 +3,9 @@
-

{{ form_domain }}

+

{{ domain_domain }}


-
{{ form_desc }}
+
{{ domain_desc }}

- +

{% raw %}{{amountSats}}{% endraw %}

@@ -48,7 +48,7 @@ {% endblock %} {% block scripts %}