mirror of https://github.com/lukechilds/lnbits.git
Eneko Illarramendi
5 years ago
18 changed files with 133 additions and 114 deletions
@ -0,0 +1,13 @@ |
|||
new Vue({ |
|||
el: '#vue', |
|||
mixins: [windowMixin], |
|||
methods: { |
|||
notify: function () { |
|||
this.$q.notify({ |
|||
timeout: 0, |
|||
message: 'Processing...', |
|||
icon: null |
|||
}); |
|||
} |
|||
} |
|||
}); |
@ -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 %} |
@ -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)) |
@ -1,15 +0,0 @@ |
|||
<!-- @format --> |
|||
|
|||
{% extends "index.html" %} {% block call_to_action %} |
|||
|
|||
<button |
|||
class="btn btn-block btn-primary btn-lg" |
|||
onclick="processing()" |
|||
data-toggle="modal" |
|||
data-target=".proc" |
|||
> |
|||
Press to claim bitcoin! |
|||
</button> |
|||
<div id="processing"> |
|||
</div> |
|||
{% endblock %} |
Loading…
Reference in new issue