refactor: breaking bad
This commit is contained in:
@@ -4,5 +4,6 @@ from flask import Blueprint
|
||||
core_app = Blueprint("core", __name__, template_folder="templates", static_folder="static")
|
||||
|
||||
|
||||
from .views_api import * # noqa
|
||||
from .views import * # noqa
|
||||
from .views.api import * # noqa
|
||||
from .views.generic import * # noqa
|
||||
from .views.lnurl import * # noqa
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
from uuid import uuid4
|
||||
|
||||
from lnbits.db import open_db
|
||||
from lnbits.settings import DEFAULT_USER_WALLET_NAME, FEE_RESERVE
|
||||
from lnbits.settings import DEFAULT_WALLET_NAME, FEE_RESERVE
|
||||
from typing import List, Optional
|
||||
|
||||
from .models import User, Wallet, Payment
|
||||
@@ -71,7 +71,7 @@ def create_wallet(*, user_id: str, wallet_name: Optional[str]) -> Wallet:
|
||||
INSERT INTO wallets (id, name, user, adminkey, inkey)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
""",
|
||||
(wallet_id, wallet_name or DEFAULT_USER_WALLET_NAME, user_id, uuid4().hex, uuid4().hex),
|
||||
(wallet_id, wallet_name or DEFAULT_WALLET_NAME, user_id, uuid4().hex, uuid4().hex),
|
||||
)
|
||||
|
||||
return get_wallet(wallet_id=wallet_id)
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
new Vue({
|
||||
el: '#vue',
|
||||
mixins: [windowMixin],
|
||||
methods: {
|
||||
notify: function () {
|
||||
this.$q.notify({
|
||||
timeout: 0,
|
||||
message: 'Processing...',
|
||||
icon: null
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -15,20 +15,22 @@
|
||||
<div class="row q-col-gutter-md justify-between">
|
||||
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
|
||||
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<q-form class="q-gutter-md">
|
||||
<q-input filled dense
|
||||
v-model="walletName"
|
||||
label="Name your LNbits wallet *"
|
||||
></q-input>
|
||||
<q-btn unelevated
|
||||
color="deep-purple"
|
||||
:disable="walletName == ''"
|
||||
@click="createWallet">Add a new wallet</q-btn>
|
||||
</q-form>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
{% block call_to_action %}
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<q-form class="q-gutter-md">
|
||||
<q-input filled dense
|
||||
v-model="walletName"
|
||||
label="Name your LNbits wallet *"
|
||||
></q-input>
|
||||
<q-btn unelevated
|
||||
color="deep-purple"
|
||||
:disable="walletName == ''"
|
||||
@click="createWallet">Add a new wallet</q-btn>
|
||||
</q-form>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
{% endblock %}
|
||||
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
{% extends "core/index.html" %}
|
||||
|
||||
|
||||
{% block scripts %}
|
||||
{% assets filters='rjsmin', output='__bundle__/core/lnurl.js',
|
||||
'core/js/lnurl.js' %}
|
||||
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
|
||||
{% endassets %}
|
||||
{% endblock %}
|
||||
|
||||
{% block call_to_action %}
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<q-btn unelevated
|
||||
color="deep-purple"
|
||||
@click="notify"
|
||||
type="a" href="{{ url_for('core.lnurlwallet', lightning=lnurl) }}">
|
||||
Press to claim bitcoin
|
||||
</q-btn>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
{% endblock %}
|
||||
@@ -6,7 +6,7 @@ from lnbits.decorators import api_check_wallet_macaroon, api_validate_post_reque
|
||||
from lnbits.helpers import Status
|
||||
from lnbits.settings import FEE_RESERVE, WALLET
|
||||
|
||||
from .crud import create_payment
|
||||
from ..crud import create_payment
|
||||
|
||||
|
||||
@core_app.route("/api/v1/payments", methods=["GET"])
|
||||
@@ -5,7 +5,7 @@ from lnbits.core import core_app
|
||||
from lnbits.decorators import check_user_exists, validate_uuids
|
||||
from lnbits.helpers import Status
|
||||
|
||||
from .crud import (
|
||||
from ..crud import (
|
||||
create_account,
|
||||
get_user,
|
||||
update_user_extension,
|
||||
@@ -0,0 +1,55 @@
|
||||
import json
|
||||
import requests
|
||||
|
||||
from flask import redirect, render_template, request, url_for
|
||||
from lnurl import LnurlWithdrawResponse, handle as handle_lnurl
|
||||
from lnurl.exceptions import LnurlException
|
||||
from time import sleep
|
||||
|
||||
from lnbits.core import core_app
|
||||
from lnbits.settings import WALLET
|
||||
|
||||
from ..crud import create_account, get_user, create_wallet, create_payment
|
||||
|
||||
|
||||
@core_app.route("/lnurl")
|
||||
def lnurl():
|
||||
lnurl = request.args.get("lightning")
|
||||
return render_template("core/lnurl.html", lnurl=lnurl)
|
||||
|
||||
|
||||
@core_app.route("/lnurlwallet")
|
||||
def lnurlwallet():
|
||||
try:
|
||||
withdraw_res = handle_lnurl(request.args.get("lightning"), response_class=LnurlWithdrawResponse)
|
||||
except LnurlException:
|
||||
return redirect(url_for("core.home"))
|
||||
|
||||
_, payhash, payment_request = WALLET.create_invoice(withdraw_res.max_sats, "LNbits LNURL funding")
|
||||
|
||||
r = requests.get(
|
||||
withdraw_res.callback.base,
|
||||
params={**withdraw_res.callback.query_params, **{"k1": withdraw_res.k1, "pr": payment_request}},
|
||||
)
|
||||
|
||||
if not r.ok:
|
||||
return redirect(url_for("core.home")) # TODO: custom error
|
||||
data = json.loads(r.text)
|
||||
|
||||
for i in range(10):
|
||||
r = WALLET.get_invoice_status(payhash).raw_response
|
||||
sleep(i)
|
||||
if not r.ok:
|
||||
continue
|
||||
break
|
||||
|
||||
user = get_user(create_account().id)
|
||||
wallet = create_wallet(user_id=user.id)
|
||||
create_payment( # TODO: not pending?
|
||||
wallet_id=wallet.id,
|
||||
payhash=payhash,
|
||||
amount=withdraw_res.max_sats * 1000,
|
||||
memo="LNbits lnurl funding",
|
||||
)
|
||||
|
||||
return redirect(url_for("core.wallet", usr=user.id, wal=wallet.id))
|
||||
Reference in New Issue
Block a user