From 6a59208297cd100063b7534e6ef35e92b541b585 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Mon, 7 Jun 2021 22:54:22 +0100 Subject: [PATCH 01/11] Fix form reset on LNURLp (#201) Co-authored-by: Tiago Vasconcelos --- lnbits/extensions/lnurlp/lnurl.py | 2 +- lnbits/extensions/lnurlp/static/js/index.js | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lnbits/extensions/lnurlp/lnurl.py b/lnbits/extensions/lnurlp/lnurl.py index 13a5e85a3..d4f36e47b 100644 --- a/lnbits/extensions/lnurlp/lnurl.py +++ b/lnbits/extensions/lnurlp/lnurl.py @@ -104,4 +104,4 @@ async def api_lnurl_callback(link_id): if success_action: resp["success_action"] = success_action - return jsonify(), HTTPStatus.OK + return jsonify(resp), HTTPStatus.OK diff --git a/lnbits/extensions/lnurlp/static/js/index.js b/lnbits/extensions/lnurlp/static/js/index.js index dbc0df1e3..fbf6a60fc 100644 --- a/lnbits/extensions/lnurlp/static/js/index.js +++ b/lnbits/extensions/lnurlp/static/js/index.js @@ -62,7 +62,9 @@ new Vue({ LNbits.utils.notifyApiError(err) }) }, - closeFormDialog() {}, + closeFormDialog() { + this.resetFormData() + }, openQrCodeDialog(linkId) { var link = _.findWhere(this.payLinks, {id: linkId}) if (link.currency) this.updateFiatRate(link.currency) @@ -116,6 +118,13 @@ new Vue({ this.createPayLink(wallet, data) } }, + resetFormData() { + this.formDialog = { + show: false, + fixedAmount: true, + data: {} + } + }, updatePayLink(wallet, data) { let values = _.omit( _.pick( @@ -147,6 +156,7 @@ new Vue({ this.payLinks = _.reject(this.payLinks, obj => obj.id === data.id) this.payLinks.push(mapPayLink(response.data)) this.formDialog.show = false + this.resetFormData() }) .catch(err => { LNbits.utils.notifyApiError(err) @@ -158,6 +168,7 @@ new Vue({ .then(response => { this.payLinks.push(mapPayLink(response.data)) this.formDialog.show = false + this.resetFormData() }) .catch(err => { LNbits.utils.notifyApiError(err) From a1e12fcd0eeccd7e79733d7fe3fe89b254c04881 Mon Sep 17 00:00:00 2001 From: keblek <68111648+keblek@users.noreply.github.com> Date: Wed, 9 Jun 2021 15:18:50 +0200 Subject: [PATCH 02/11] Adding clarity for LNPay webhooks --- docs/guide/wallets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/guide/wallets.md b/docs/guide/wallets.md index 64b61bae9..888fc8d6c 100644 --- a/docs/guide/wallets.md +++ b/docs/guide/wallets.md @@ -54,7 +54,7 @@ Using this wallet requires the installation of the `lndgrpc` and `purerpc` Pytho ### LNPay -For the invoice listener to work you have a publicly accessible URL in your LNbits and must set up [LNPay webhooks](https://dashboard.lnpay.co/webhook/) pointing to `/wallet/webhook` with the "Wallet Receive" event and no secret. +For the invoice listener to work you have a publicly accessible URL in your LNbits and must set up [LNPay webhooks](https://dashboard.lnpay.co/webhook/) pointing to `/wallet/webhook` with the "Wallet Receive" event and no secret. For example, `https://mylnbits/wallet/webhook` will be the Endpoint Url that gets notified about the payment. - `LNBITS_BACKEND_WALLET_CLASS`: **LNPayWallet** - `LNPAY_API_ENDPOINT`: https://api.lnpay.co/v1/ From 2e8145faac302ecb21ca9ce109e2873e128b4c53 Mon Sep 17 00:00:00 2001 From: Tiago Vasconcelos Date: Wed, 9 Jun 2021 16:07:42 +0100 Subject: [PATCH 03/11] Documentation Updates (#202) Updates for user manager and subdomains extensions Co-authored-by: Tiago Vasconcelos --- docs/devs/installation.md | 26 +++---- lnbits/extensions/subdomains/README.md | 26 +++---- lnbits/extensions/usermanager/README.md | 29 +++++++- .../templates/usermanager/index.html | 67 ++++++++++--------- 4 files changed, 86 insertions(+), 62 deletions(-) diff --git a/docs/devs/installation.md b/docs/devs/installation.md index 81ae2a4c6..55636181d 100644 --- a/docs/devs/installation.md +++ b/docs/devs/installation.md @@ -5,15 +5,11 @@ title: Installation nav_order: 1 --- - -Installation -============ +# Installation Download the latest stable release https://github.com/lnbits/lnbits/releases - -Application dependencies ------------------------- +## Application dependencies The application uses [Pipenv][pipenv] to manage Python packages. While in development, you will need to install all dependencies: @@ -24,7 +20,7 @@ $ pipenv install --dev ``` If any of the modules fails to install, try checking and upgrading your setupTool module. -`pip install -U setuptools` +`pip install -U setuptools` If you wish to use a version of Python higher than 3.7: @@ -41,9 +37,7 @@ E.g. when you want to use LND you have to `pipenv run pip install lndgrpc` and ` Take a look at [Polar][polar] for an excellent way of spinning up a Lightning Network dev environment. - -Running the server ------------------- +## Running the server LNbits uses [Quart][quart] as an application server. @@ -51,12 +45,18 @@ LNbits uses [Quart][quart] as an application server. $ pipenv run python -m lnbits ``` -Frontend --------- +**Note**: You'll need to use _https_ for some endpoints and/or extensions. You can use [ngrok](https://ngrok.com/) for that. Follow the installation instructions on the website and when it's all set you can run: + +```sh +$ ./nrok http 5000 +``` + +this will give you an _https_ tunnel for the _localhost_, use that URL for navigating to LNBits. + +## Frontend The frontend uses [Vue.js and Quasar][quasar]. - [quart]: https://pgjones.gitlab.io/ [pipenv]: https://pipenv.pypa.io/ [polar]: https://lightningpolar.com/ diff --git a/lnbits/extensions/subdomains/README.md b/lnbits/extensions/subdomains/README.md index 49dfc223d..729f40f41 100644 --- a/lnbits/extensions/subdomains/README.md +++ b/lnbits/extensions/subdomains/README.md @@ -1,27 +1,29 @@

Subdomains Extension

-So the goal of the extension is to allow the owner of a domain to sell their subdomain to the anyone who is willing to pay some money for it. +So the goal of the extension is to allow the owner of a domain to sell subdomains to anyone who is willing to pay some money for it. + +[![video tutorial livestream](http://img.youtube.com/vi/O1X0fy3uNpw/0.jpg)](https://youtu.be/O1X0fy3uNpw 'video tutorial subdomains') ## Requirements -- Free cloudflare account -- Cloudflare as a dns server provider -- Cloudflare TOKEN and Cloudflare zone-id where the domain is parked +- Free Cloudflare account +- Cloudflare as a DNS server provider +- Cloudflare TOKEN and Cloudflare zone-ID where the domain is parked ## Usage -1. Register at cloudflare and setup your domain with them. (Just follow instructions they provide...) -2. Change DNS server at your domain registrar to point to cloudflare's -3. Get Cloudflare zoneID for your domain +1. Register at Cloudflare and setup your domain with them. (Just follow instructions they provide...) +2. Change DNS server at your domain registrar to point to Cloudflare's +3. Get Cloudflare zone-ID for your domain -4. get Cloudflare API TOKEN +4. Get Cloudflare API TOKEN -5. Open the lnbits subdomains extension and register your domain with lnbits +5. Open the LNBits subdomains extension and register your domain 6. Click on the button in the table to open the public form that was generated for your domain -- Extension also supports webhooks so you can get notified when someone buys a new domain - + - Extension also supports webhooks so you can get notified when someone buys a new subdomain\ + ## API Endpoints @@ -36,8 +38,6 @@ So the goal of the extension is to allow the owner of a domain to sell their sub - GET /api/v1/subdomains/ - DELETE /api/v1/subdomains/ -## Useful - ### Cloudflare - Cloudflare offers programmatic subdomain registration... (create new A record) diff --git a/lnbits/extensions/usermanager/README.md b/lnbits/extensions/usermanager/README.md index 6cb9deca9..b6f306275 100644 --- a/lnbits/extensions/usermanager/README.md +++ b/lnbits/extensions/usermanager/README.md @@ -1,3 +1,26 @@ -

User Manager

-

Make and manager users/wallets

-To help developers use LNbits to manage their users, the User Manager extension allows the creation and management of users and wallets. For example, a games developer may be developing a game that needs each user to have their own wallet, LNbits can be included in the develpoers stack as the user and wallet manager. +# User Manager + +## Make and manage users/wallets + +To help developers use LNbits to manage their users, the User Manager extension allows the creation and management of users and wallets. + +For example, a games developer may be developing a game that needs each user to have their own wallet, LNbits can be included in the developers stack as the user and wallet manager. Or someone wanting to manage their family's wallets (wife, children, parents, etc...) or you want to host a community Lightning Network node and want to manage wallets for the users. + +## Usage + +1. Click the button "NEW USER" to create a new user\ + ![new user](https://i.imgur.com/4yZyfJE.png) +2. Fill the user information\ + - username + - the generated wallet name, user can create other wallets later on + - email + - set a password + ![user information](https://i.imgur.com/40du7W5.png) +3. After creating your user, it will appear in the **Users** section, and a user's wallet in the **Wallets** section. +4. Next you can share the wallet with the corresponding user\ + ![user wallet](https://i.imgur.com/gAyajbx.png) +5. If you need to create more wallets for some user, click "NEW WALLET" at the top\ + ![multiple wallets](https://i.imgur.com/wovVnim.png) + - select the existing user you wish to add the wallet + - set a wallet name\ + ![new wallet](https://i.imgur.com/sGwG8dC.png) diff --git a/lnbits/extensions/usermanager/templates/usermanager/index.html b/lnbits/extensions/usermanager/templates/usermanager/index.html index a75140894..06e5423ab 100644 --- a/lnbits/extensions/usermanager/templates/usermanager/index.html +++ b/lnbits/extensions/usermanager/templates/usermanager/index.html @@ -214,7 +214,7 @@ {% endblock %} {% block scripts %} {{ window_vars(user) }} +{% endblock %} diff --git a/lnbits/extensions/splitpayments/views.py b/lnbits/extensions/splitpayments/views.py new file mode 100644 index 000000000..acded737e --- /dev/null +++ b/lnbits/extensions/splitpayments/views.py @@ -0,0 +1,12 @@ +from quart import g, render_template + +from lnbits.decorators import check_user_exists, validate_uuids + +from . import splitpayments_ext + + +@splitpayments_ext.route("/") +@validate_uuids(["usr"], required=True) +@check_user_exists() +async def index(): + return await render_template("splitpayments/index.html", user=g.user) diff --git a/lnbits/extensions/splitpayments/views_api.py b/lnbits/extensions/splitpayments/views_api.py new file mode 100644 index 000000000..e0fe475ed --- /dev/null +++ b/lnbits/extensions/splitpayments/views_api.py @@ -0,0 +1,70 @@ +from quart import g, jsonify +from http import HTTPStatus + +from lnbits.decorators import api_check_wallet_key, api_validate_post_request +from lnbits.core.crud import get_wallet, get_wallet_for_key + +from . import splitpayments_ext +from .crud import get_targets, set_targets +from .models import Target + + +@splitpayments_ext.route("/api/v1/targets", methods=["GET"]) +@api_check_wallet_key("admin") +async def api_targets_get(): + targets = await get_targets(g.wallet.id) + return jsonify([target._asdict() for target in targets] or []) + + +@splitpayments_ext.route("/api/v1/targets", methods=["PUT"]) +@api_check_wallet_key("admin") +@api_validate_post_request( + schema={ + "targets": { + "type": "list", + "schema": { + "type": "dict", + "schema": { + "wallet": {"type": "string"}, + "alias": {"type": "string"}, + "percent": {"type": "integer"}, + }, + }, + } + } +) +async def api_targets_set(): + targets = [] + + for entry in g.data["targets"]: + wallet = await get_wallet(entry["wallet"]) + if not wallet: + wallet = await get_wallet_for_key(entry["wallet"], "invoice") + if not wallet: + return ( + jsonify({"message": f"Invalid wallet '{entry['wallet']}'."}), + HTTPStatus.BAD_REQUEST, + ) + + if wallet.id == g.wallet.id: + return ( + jsonify({"message": "Can't split to itself."}), + HTTPStatus.BAD_REQUEST, + ) + + if entry["percent"] < 0: + return ( + jsonify({"message": f"Invalid percent '{entry['percent']}'."}), + HTTPStatus.BAD_REQUEST, + ) + + targets.append( + Target(wallet.id, g.wallet.id, entry["percent"], entry["alias"] or "") + ) + + percent_sum = sum([target.percent for target in targets]) + if percent_sum > 100: + return jsonify({"message": "Splitting over 100%."}), HTTPStatus.BAD_REQUEST + + await set_targets(g.wallet.id, targets) + return "", HTTPStatus.OK From 8500b7767c7f7ed12fb4309c24e1b642341abe4c Mon Sep 17 00:00:00 2001 From: Ben Arc Date: Thu, 10 Jun 2021 23:09:24 +0100 Subject: [PATCH 11/11] Fixed button bug --- lnbits/extensions/satspay/templates/satspay/display.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnbits/extensions/satspay/templates/satspay/display.html b/lnbits/extensions/satspay/templates/satspay/display.html index d23814b4a..b3386074e 100644 --- a/lnbits/extensions/satspay/templates/satspay/display.html +++ b/lnbits/extensions/satspay/templates/satspay/display.html @@ -169,7 +169,7 @@ >