diff --git a/__init__.py b/__init__.py index 24a4578..d203a3d 100644 --- a/__init__.py +++ b/__init__.py @@ -42,7 +42,7 @@ def tpos_start(): __all__ = [ "db", "tpos_ext", - "tpos_static_files", "tpos_start", + "tpos_static_files", "tpos_stop", ] diff --git a/crud.py b/crud.py index 534d0be..d46875c 100644 --- a/crud.py +++ b/crud.py @@ -3,6 +3,7 @@ from lnbits.db import Database from lnbits.helpers import urlsafe_short_hash +from loguru import logger from .models import CreateTposData, LnurlCharge, Tpos, TposClean @@ -78,9 +79,12 @@ async def get_tposs(wallet_ids: Union[str, list[str]]) -> list[Tpos]: if isinstance(wallet_ids, str): wallet_ids = [wallet_ids] q = ",".join([f"'{wallet_id}'" for wallet_id in wallet_ids]) - return await db.fetchall( + tposs = await db.fetchall( f"SELECT * FROM tpos.pos WHERE wallet IN ({q})", model=Tpos ) + logger.debug("tposs") + logger.debug(tposs) + return tposs async def delete_tpos(tpos_id: str) -> None: diff --git a/helpers.py b/helpers.py new file mode 100644 index 0000000..f224d2a --- /dev/null +++ b/helpers.py @@ -0,0 +1,18 @@ +import httpx +from lnbits.core.views.api import api_lnurlscan + + +async def get_pr(ln_address, amount): + try: + data = await api_lnurlscan(ln_address) + if data.get("status") == "ERROR": + return + async with httpx.AsyncClient() as client: + response = await client.get( + url=f"{data['callback']}?amount={int(amount) * 1000}" + ) + if response.status_code != 200: + return + return response.json()["pr"] + except Exception: + return None diff --git a/migrations.py b/migrations.py index ea1ce00..b565efe 100644 --- a/migrations.py +++ b/migrations.py @@ -165,3 +165,25 @@ async def m010_rename_tpos_withdraw_columns(db: Database): ) await db.execute("DROP TABLE tpos.pos") await db.execute("ALTER TABLE tpos.pos_backup RENAME TO pos") + + +async def m011_lnaddress(db: Database): + """ + Add lnaddress to tpos table + """ + await db.execute( + """ + ALTER TABLE tpos.pos ADD lnaddress BOOLEAN DEFAULT false; + """ + ) + + +async def m012_addlnaddress(db: Database): + """ + Add lnaddress_cut to tpos table + """ + await db.execute( + """ + ALTER TABLE tpos.pos ADD lnaddress_cut TEXT NULL; + """ + ) diff --git a/models.py b/models.py index da71698..82b5e7c 100644 --- a/models.py +++ b/models.py @@ -15,6 +15,7 @@ class CreateTposInvoice(BaseModel): memo: Optional[str] = Query(None) details: Optional[dict] = Query(None) tip_amount: Optional[int] = Query(None, ge=1) + user_lnaddress: Optional[str] = Query(None) class CreateTposData(BaseModel): @@ -32,6 +33,8 @@ class CreateTposData(BaseModel): withdraw_time_option: Optional[str] = Field(None) withdraw_premium: Optional[float] = Field(None) withdraw_pin_disabled: bool = Field(False) + lnaddress: bool = Field(False) + lnaddress_cut: Optional[int] = Field(0) class TposClean(BaseModel): @@ -47,6 +50,8 @@ class TposClean(BaseModel): withdraw_premium: Optional[float] = None withdraw_pin_disabled: Optional[bool] = None withdrawn_amount: int = 0 + lnaddress: Optional[bool] = None + lnaddress_cut: int = 0 items: Optional[str] = None tip_options: Optional[str] = None @@ -89,6 +94,10 @@ class PayLnurlWData(BaseModel): lnurl: str +class LNaddress(BaseModel): + lnaddress: str + + class Item(BaseModel): image: Optional[str] price: float diff --git a/poetry.lock b/poetry.lock index 847d128..84b6609 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aiosqlite" @@ -1462,43 +1462,43 @@ tests = ["pytest", "simplejson"] [[package]] name = "mypy" -version = "1.12.1" +version = "1.13.0" description = "Optional static typing for Python" optional = false python-versions = ">=3.8" files = [ - {file = "mypy-1.12.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:3d7d4371829184e22fda4015278fbfdef0327a4b955a483012bd2d423a788801"}, - {file = "mypy-1.12.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:f59f1dfbf497d473201356966e353ef09d4daec48caeacc0254db8ef633a28a5"}, - {file = "mypy-1.12.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b947097fae68004b8328c55161ac9db7d3566abfef72d9d41b47a021c2fba6b1"}, - {file = "mypy-1.12.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:96af62050971c5241afb4701c15189ea9507db89ad07794a4ee7b4e092dc0627"}, - {file = "mypy-1.12.1-cp310-cp310-win_amd64.whl", hash = "sha256:d90da248f4c2dba6c44ddcfea94bb361e491962f05f41990ff24dbd09969ce20"}, - {file = "mypy-1.12.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:1230048fec1380faf240be6385e709c8570604d2d27ec6ca7e573e3bc09c3735"}, - {file = "mypy-1.12.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:02dcfe270c6ea13338210908f8cadc8d31af0f04cee8ca996438fe6a97b4ec66"}, - {file = "mypy-1.12.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a5a437c9102a6a252d9e3a63edc191a3aed5f2fcb786d614722ee3f4472e33f6"}, - {file = "mypy-1.12.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:186e0c8346efc027ee1f9acf5ca734425fc4f7dc2b60144f0fbe27cc19dc7931"}, - {file = "mypy-1.12.1-cp311-cp311-win_amd64.whl", hash = "sha256:673ba1140a478b50e6d265c03391702fa11a5c5aff3f54d69a62a48da32cb811"}, - {file = "mypy-1.12.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:9fb83a7be97c498176fb7486cafbb81decccaef1ac339d837c377b0ce3743a7f"}, - {file = "mypy-1.12.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:389e307e333879c571029d5b93932cf838b811d3f5395ed1ad05086b52148fb0"}, - {file = "mypy-1.12.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:94b2048a95a21f7a9ebc9fbd075a4fcd310410d078aa0228dbbad7f71335e042"}, - {file = "mypy-1.12.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4ee5932370ccf7ebf83f79d1c157a5929d7ea36313027b0d70a488493dc1b179"}, - {file = "mypy-1.12.1-cp312-cp312-win_amd64.whl", hash = "sha256:19bf51f87a295e7ab2894f1d8167622b063492d754e69c3c2fed6563268cb42a"}, - {file = "mypy-1.12.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:d34167d43613ffb1d6c6cdc0cc043bb106cac0aa5d6a4171f77ab92a3c758bcc"}, - {file = "mypy-1.12.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:427878aa54f2e2c5d8db31fa9010c599ed9f994b3b49e64ae9cd9990c40bd635"}, - {file = "mypy-1.12.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5fcde63ea2c9f69d6be859a1e6dd35955e87fa81de95bc240143cf00de1f7f81"}, - {file = "mypy-1.12.1-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:d54d840f6c052929f4a3d2aab2066af0f45a020b085fe0e40d4583db52aab4e4"}, - {file = "mypy-1.12.1-cp313-cp313-win_amd64.whl", hash = "sha256:20db6eb1ca3d1de8ece00033b12f793f1ea9da767334b7e8c626a4872090cf02"}, - {file = "mypy-1.12.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:b16fe09f9c741d85a2e3b14a5257a27a4f4886c171d562bc5a5e90d8591906b8"}, - {file = "mypy-1.12.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:0dcc1e843d58f444fce19da4cce5bd35c282d4bde232acdeca8279523087088a"}, - {file = "mypy-1.12.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e10ba7de5c616e44ad21005fa13450cd0de7caaa303a626147d45307492e4f2d"}, - {file = "mypy-1.12.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:0e6fe449223fa59fbee351db32283838a8fee8059e0028e9e6494a03802b4004"}, - {file = "mypy-1.12.1-cp38-cp38-win_amd64.whl", hash = "sha256:dc6e2a2195a290a7fd5bac3e60b586d77fc88e986eba7feced8b778c373f9afe"}, - {file = "mypy-1.12.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:de5b2a8988b4e1269a98beaf0e7cc71b510d050dce80c343b53b4955fff45f19"}, - {file = "mypy-1.12.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:843826966f1d65925e8b50d2b483065c51fc16dc5d72647e0236aae51dc8d77e"}, - {file = "mypy-1.12.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9fe20f89da41a95e14c34b1ddb09c80262edcc295ad891f22cc4b60013e8f78d"}, - {file = "mypy-1.12.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:8135ffec02121a75f75dc97c81af7c14aa4ae0dda277132cfcd6abcd21551bfd"}, - {file = "mypy-1.12.1-cp39-cp39-win_amd64.whl", hash = "sha256:a7b76fa83260824300cc4834a3ab93180db19876bce59af921467fd03e692810"}, - {file = "mypy-1.12.1-py3-none-any.whl", hash = "sha256:ce561a09e3bb9863ab77edf29ae3a50e65685ad74bba1431278185b7e5d5486e"}, - {file = "mypy-1.12.1.tar.gz", hash = "sha256:f5b3936f7a6d0e8280c9bdef94c7ce4847f5cdfc258fbb2c29a8c1711e8bb96d"}, + {file = "mypy-1.13.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6607e0f1dd1fb7f0aca14d936d13fd19eba5e17e1cd2a14f808fa5f8f6d8f60a"}, + {file = "mypy-1.13.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8a21be69bd26fa81b1f80a61ee7ab05b076c674d9b18fb56239d72e21d9f4c80"}, + {file = "mypy-1.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7b2353a44d2179846a096e25691d54d59904559f4232519d420d64da6828a3a7"}, + {file = "mypy-1.13.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:0730d1c6a2739d4511dc4253f8274cdd140c55c32dfb0a4cf8b7a43f40abfa6f"}, + {file = "mypy-1.13.0-cp310-cp310-win_amd64.whl", hash = "sha256:c5fc54dbb712ff5e5a0fca797e6e0aa25726c7e72c6a5850cfd2adbc1eb0a372"}, + {file = "mypy-1.13.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:581665e6f3a8a9078f28d5502f4c334c0c8d802ef55ea0e7276a6e409bc0d82d"}, + {file = "mypy-1.13.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3ddb5b9bf82e05cc9a627e84707b528e5c7caaa1c55c69e175abb15a761cec2d"}, + {file = "mypy-1.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:20c7ee0bc0d5a9595c46f38beb04201f2620065a93755704e141fcac9f59db2b"}, + {file = "mypy-1.13.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3790ded76f0b34bc9c8ba4def8f919dd6a46db0f5a6610fb994fe8efdd447f73"}, + {file = "mypy-1.13.0-cp311-cp311-win_amd64.whl", hash = "sha256:51f869f4b6b538229c1d1bcc1dd7d119817206e2bc54e8e374b3dfa202defcca"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:5c7051a3461ae84dfb5dd15eff5094640c61c5f22257c8b766794e6dd85e72d5"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:39bb21c69a5d6342f4ce526e4584bc5c197fd20a60d14a8624d8743fffb9472e"}, + {file = "mypy-1.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:164f28cb9d6367439031f4c81e84d3ccaa1e19232d9d05d37cb0bd880d3f93c2"}, + {file = "mypy-1.13.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a4c1bfcdbce96ff5d96fc9b08e3831acb30dc44ab02671eca5953eadad07d6d0"}, + {file = "mypy-1.13.0-cp312-cp312-win_amd64.whl", hash = "sha256:a0affb3a79a256b4183ba09811e3577c5163ed06685e4d4b46429a271ba174d2"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a7b44178c9760ce1a43f544e595d35ed61ac2c3de306599fa59b38a6048e1aa7"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:5d5092efb8516d08440e36626f0153b5006d4088c1d663d88bf79625af3d1d62"}, + {file = "mypy-1.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:de2904956dac40ced10931ac967ae63c5089bd498542194b436eb097a9f77bc8"}, + {file = "mypy-1.13.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:7bfd8836970d33c2105562650656b6846149374dc8ed77d98424b40b09340ba7"}, + {file = "mypy-1.13.0-cp313-cp313-win_amd64.whl", hash = "sha256:9f73dba9ec77acb86457a8fc04b5239822df0c14a082564737833d2963677dbc"}, + {file = "mypy-1.13.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:100fac22ce82925f676a734af0db922ecfea991e1d7ec0ceb1e115ebe501301a"}, + {file = "mypy-1.13.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7bcb0bb7f42a978bb323a7c88f1081d1b5dee77ca86f4100735a6f541299d8fb"}, + {file = "mypy-1.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:bde31fc887c213e223bbfc34328070996061b0833b0a4cfec53745ed61f3519b"}, + {file = "mypy-1.13.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:07de989f89786f62b937851295ed62e51774722e5444a27cecca993fc3f9cd74"}, + {file = "mypy-1.13.0-cp38-cp38-win_amd64.whl", hash = "sha256:4bde84334fbe19bad704b3f5b78c4abd35ff1026f8ba72b29de70dda0916beb6"}, + {file = "mypy-1.13.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:0246bcb1b5de7f08f2826451abd947bf656945209b140d16ed317f65a17dc7dc"}, + {file = "mypy-1.13.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:7f5b7deae912cf8b77e990b9280f170381fdfbddf61b4ef80927edd813163732"}, + {file = "mypy-1.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7029881ec6ffb8bc233a4fa364736789582c738217b133f1b55967115288a2bc"}, + {file = "mypy-1.13.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:3e38b980e5681f28f033f3be86b099a247b13c491f14bb8b1e1e134d23bb599d"}, + {file = "mypy-1.13.0-cp39-cp39-win_amd64.whl", hash = "sha256:a6789be98a2017c912ae6ccb77ea553bbaf13d27605d2ca20a76dfbced631b24"}, + {file = "mypy-1.13.0-py3-none-any.whl", hash = "sha256:9c250883f9fd81d212e0952c92dbfcc96fc237f4b7c92f56ac81fd48460b3e5a"}, + {file = "mypy-1.13.0.tar.gz", hash = "sha256:0291a61b6fbf3e6673e3405cfcc0e7650bebc7939659fdca2702958038bd835e"}, ] [package.dependencies] @@ -1508,6 +1508,7 @@ typing-extensions = ">=4.6.0" [package.extras] dmypy = ["psutil (>=4.0)"] +faster-cache = ["orjson"] install-types = ["pip"] mypyc = ["setuptools (>=50)"] reports = ["lxml"] @@ -2612,4 +2613,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.10 | ^3.9" -content-hash = "3c44aa4c67a390622291459f117b591302ed643bf86e0953c9f3b6c31dc3d504" +content-hash = "ba2fa741b55e7b4759151deb8865997840aca9638576c310241ab2091f18e2b1" diff --git a/pyproject.toml b/pyproject.toml index 1fa6fbe..eabb526 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,7 @@ authors = ["Alan Bits "] [tool.poetry.dependencies] python = "^3.10 | ^3.9" lnbits = {version = "*", allow-prereleases = true} +mypy = "^1.13.0" [tool.poetry.group.dev.dependencies] black = "^24.3.0" diff --git a/static/js/index.js b/static/js/index.js index 9b72e81..37e6121 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -47,6 +47,18 @@ window.app = Vue.createApp({ align: 'left', label: 'atm pin disabled', field: 'withdraw_pin_disabled' + }, + { + name: 'lnaddress', + align: 'left', + label: 'LNaddress', + field: 'lnaddress' + }, + { + name: 'lnaddress_cut', + align: 'left', + label: 'LNaddress Cut', + field: 'lnaddress_cut' } ], pagination: { @@ -71,7 +83,9 @@ window.app = Vue.createApp({ withdraw_between: 10, withdraw_time_option: '', withdraw_pin_disabled: false, - tax_inclusive: true + tax_inclusive: true, + lnaddress: false, + lnaddress_cut: 2 }, advanced: { tips: false, @@ -170,7 +184,6 @@ window.app = Vue.createApp({ }, getTposs: function () { var self = this - LNbits.api .request( 'GET', diff --git a/static/js/tpos.js b/static/js/tpos.js index 062dc7c..3e770f0 100644 --- a/static/js/tpos.js +++ b/static/js/tpos.js @@ -21,6 +21,10 @@ window.app = Vue.createApp({ atmMode: false, atmToken: '', nfcTagReading: false, + lnaddressDialog: { + show: false, + lnaddress: '' + }, lastPaymentsDialog: { show: false, data: [] @@ -283,6 +287,29 @@ window.app = Vue.createApp({ LNbits.utils.notifyApiError(error) }) }, + lnaddressSubmit() { + LNbits.api + .request( + 'GET', + `/tpos/api/v1/tposs/lnaddresscheck?lnaddress=${encodeURIComponent(this.lnaddressDialog.lnaddress)}`, + null + ) + .then(response => { + if (response.data) { + this.$q.localStorage.set( + 'tpos.lnaddress', + this.lnaddressDialog.lnaddress + ) + this.lnaddressDialog.show = false + this.lnaddress = true + } + }) + .catch(error => { + const errorMessage = + error.response?.data?.detail || 'An unknown error occurred.' + LNbits.utils.notifyApiError(errorMessage) + }) + }, atmGetWithdraw() { var dialog = this.invoiceDialog if (this.sat > this.withdrawMaximum) { @@ -452,7 +479,9 @@ window.app = Vue.createApp({ taxValue: this.cartTax } } - + if (this.lnaddress) { + params.user_lnaddress = this.lnaddressDialog.lnaddress + } axios .post(`/tpos/api/v1/tposs/${this.tposId}/invoices`, params) .then(response => { @@ -630,6 +659,7 @@ window.app = Vue.createApp({ .request('GET', `/tpos/api/v1/rate/${this.currency}`) .then(response => { this.exchangeRate = response.data.rate + console.log(this.exchangeRate) Quasar.Loading.hide() }) .catch(e => console.error(e)) @@ -669,6 +699,15 @@ window.app = Vue.createApp({ handleColorScheme(val) { this.$q.localStorage.set('lnbits.tpos.color', val) }, + clearLNaddress() { + this.$q.localStorage.remove('tpos.lnaddress') + this.lnaddressDialog.lnaddress = '' + const url = new URL(window.location.href) + url.searchParams.delete('lnaddress') + window.history.replaceState({}, document.title, url.toString()) + this.lnaddressDialog.show = true + this.lnaddress = false + }, extractCategories(items) { let categories = new Set() items @@ -718,6 +757,8 @@ window.app = Vue.createApp({ this.pinDisabled = tpos.withdraw_pin_disabled this.taxInclusive = tpos.tax_inclusive this.taxDefault = tpos.tax_default + this.tposLNaddress = tpos.lnaddress + this.tposLNaddressCut = tpos.lnaddress_cut this.tip_options = tpos.tip_options == 'null' ? null : tpos.tip_options @@ -735,6 +776,23 @@ window.app = Vue.createApp({ this.showPoS = false this.categories = this.extractCategories(this.items) } + if (this.tposLNaddress) { + this.lnaddressDialog.lnaddress = + this.$q.localStorage.getItem('tpos.lnaddress') + if (lnaddressparam != '') { + this.lnaddressDialog.lnaddress = lnaddressparam + this.$q.localStorage.set( + 'tpos.lnaddress', + this.lnaddressDialog.lnaddress + ) + this.lnaddress = true + } else if (!this.lnaddressDialog.lnaddress) { + this.lnaddress = false + this.lnaddressDialog.show = true + } else { + this.lnaddress = true + } + } window.addEventListener('keyup', event => { // do nothing if the event was already processed diff --git a/tasks.py b/tasks.py index 404b41c..21ee94a 100644 --- a/tasks.py +++ b/tasks.py @@ -6,6 +6,7 @@ from loguru import logger from .crud import get_tpos +from .helpers import get_pr async def wait_for_paid_invoices(): @@ -40,6 +41,17 @@ async def on_invoice_paid(payment: Payment) -> None: tpos = await get_tpos(tpos_id) assert tpos + if payment.extra.get("lnaddress") and payment.extra["lnaddress"] != "": + calc_amount = payment.amount - ((payment.amount / 100) * tpos.lnaddress_cut) + pr = await get_pr(payment.extra.get("lnaddress"), calc_amount / 1000) + if pr: + payment.extra["lnaddress"] = "" + paid_payment = await pay_invoice( + payment_request=pr, + wallet_id=payment.wallet_id, + extra={**payment.extra}, + ) + logger.debug(f"tpos: LNaddress paid cut: {paid_payment.checking_id}") await websocket_updater(tpos_id, str(stripped_payment)) diff --git a/templates/tpos/dialogs.html b/templates/tpos/dialogs.html index f09f6bb..8044900 100644 --- a/templates/tpos/dialogs.html +++ b/templates/tpos/dialogs.html @@ -192,4 +192,21 @@
+ + + + +
LNaddress
+
+ + + + +
+ +
+
+
+
+
diff --git a/templates/tpos/index.html b/templates/tpos/index.html index 99491f9..b12d4df 100644 --- a/templates/tpos/index.html +++ b/templates/tpos/index.html @@ -315,6 +315,35 @@
{{SITE_TITLE}} TPoS extension
:options="currencyOptions" label="Currency *" > +
+
+ + + + +
+
+ + + +
+
:disable="atmMode" > + + Clear LNaddress +