lnurlpay comment.

This commit is contained in:
fiatjaf 2020-10-13 15:18:34 -03:00
parent bcdc065cc0
commit 1529ebb689
4 changed files with 56 additions and 19 deletions

View File

@ -129,7 +129,8 @@ new Vue({
lnurlpay: null, lnurlpay: null,
data: { data: {
request: '', request: '',
amount: 0 amount: 0,
comment: ''
}, },
paymentChecker: null, paymentChecker: null,
camera: { camera: {
@ -235,6 +236,7 @@ new Vue({
this.parse.invoice = null this.parse.invoice = null
this.parse.lnurlpay = null this.parse.lnurlpay = null
this.parse.data.request = '' this.parse.data.request = ''
this.parse.data.comment = ''
this.parse.data.paymentChecker = null this.parse.data.paymentChecker = null
this.parse.camera.show = false this.parse.camera.show = false
}, },
@ -449,7 +451,8 @@ new Vue({
this.parse.lnurlpay.callback, this.parse.lnurlpay.callback,
this.parse.lnurlpay.description_hash, this.parse.lnurlpay.description_hash,
this.parse.data.amount * 1000, this.parse.data.amount * 1000,
this.parse.lnurlpay.description.slice(0, 120) this.parse.lnurlpay.description.slice(0, 120),
this.parse.data.comment
) )
.then(response => { .then(response => {
this.parse.show = false this.parse.show = false

View File

@ -349,27 +349,53 @@
<p v-if="parse.lnurlpay.fixed" class="q-my-none text-h6"> <p v-if="parse.lnurlpay.fixed" class="q-my-none text-h6">
<b>{{ parse.lnurlpay.domain }}</b> is requesting {{ <b>{{ parse.lnurlpay.domain }}</b> is requesting {{
parse.lnurlpay.maxSendable | msatoshiFormat }} sat parse.lnurlpay.maxSendable | msatoshiFormat }} sat
<span v-if="parse.lnurlpay.commentAllowed > 0">
<br />
and a {{parse.lnurlpay.commentAllowed}}-char comment
</span>
</p> </p>
<p v-else class="q-my-none text-h6 text-center"> <p v-else class="q-my-none text-h6 text-center">
<b>{{ parse.lnurlpay.domain }}</b> is requesting <br /> <b>{{ parse.lnurlpay.domain }}</b> is requesting <br />
between <b>{{ parse.lnurlpay.minSendable | msatoshiFormat }}</b> and between <b>{{ parse.lnurlpay.minSendable | msatoshiFormat }}</b> and
<b>{{ parse.lnurlpay.maxSendable | msatoshiFormat }}</b> sat <b>{{ parse.lnurlpay.maxSendable | msatoshiFormat }}</b> sat
<span v-if="parse.lnurlpay.commentAllowed > 0">
<br />
and a {{parse.lnurlpay.commentAllowed}}-char comment
</span>
</p> </p>
<q-separator class="q-my-sm"></q-separator> <q-separator class="q-my-sm"></q-separator>
<p class="text-justify text-italic">{{ parse.lnurlpay.description }}</p> <div class="row">
<p v-if="parse.lnurlpay.image"> <p class="col text-justify text-italic">
<q-img :src="parse.lnurlpay.image" width="50%" /> {{ parse.lnurlpay.description }}
</p> </p>
<q-input <p class="col-4 q-pl-md" v-if="parse.lnurlpay.image">
filled <q-img :src="parse.lnurlpay.image" />
dense </p>
v-model.number="parse.data.amount" </div>
type="number" <div class="row">
label="Amount (sat) *" <div class="col">
min="parse.lnurlpay.minSendable / 1000" <q-input
max="parse.lnurlpay.maxSendable / 1000" filled
:readonly="parse.lnurlpay.fixed" dense
></q-input> v-model.number="parse.data.amount"
type="number"
label="Amount (sat) *"
:min="parse.lnurlpay.minSendable / 1000"
:max="parse.lnurlpay.maxSendable / 1000"
:readonly="parse.lnurlpay.fixed"
></q-input>
</div>
<div class="col-8 q-pl-md" v-if="parse.lnurlpay.commentAllowed > 0">
<q-input
filled
dense
v-model.number="parse.data.comment"
:type="parse.lnurlpay.commentAllowed > 64 ? 'textarea' : 'text'"
label="Comment (optional)"
:maxlength="parse.lnurlpay.commentAllowed"
></q-input>
</div>
</div>
<div class="row q-mt-lg"> <div class="row q-mt-lg">
<q-btn unelevated color="deep-purple" type="submit" <q-btn unelevated color="deep-purple" type="submit"
>Send satoshis</q-btn >Send satoshis</q-btn

View File

@ -142,12 +142,17 @@ async def api_payments_create():
"description_hash": {"type": "string", "empty": False, "required": True}, "description_hash": {"type": "string", "empty": False, "required": True},
"callback": {"type": "string", "empty": False, "required": True}, "callback": {"type": "string", "empty": False, "required": True},
"amount": {"type": "number", "empty": False, "required": True}, "amount": {"type": "number", "empty": False, "required": True},
"description": {"type": "string", "empty": True, "required": False}, "comment": {"type": "string", "nullable": True, "empty": True, "required": False},
"description": {"type": "string", "nullable": True, "empty": True, "required": False},
} }
) )
async def api_payments_pay_lnurl(): async def api_payments_pay_lnurl():
try: try:
r = httpx.get(g.data["callback"], params={"amount": g.data["amount"]}, timeout=20) r = httpx.get(
g.data["callback"],
params={"amount": g.data["amount"], "comment": g.data["comment"]},
timeout=40,
)
if r.is_error: if r.is_error:
return jsonify({"message": "failed to connect"}), HTTPStatus.BAD_REQUEST return jsonify({"message": "failed to connect"}), HTTPStatus.BAD_REQUEST
except (httpx.ConnectError, httpx.RequestError): except (httpx.ConnectError, httpx.RequestError):
@ -321,6 +326,7 @@ async def api_lnurlscan(code: str):
image = min(data.metadata.images, key=lambda image: len(image[1])) image = min(data.metadata.images, key=lambda image: len(image[1]))
data_uri = "data:" + image[0] + "," + image[1] data_uri = "data:" + image[0] + "," + image[1]
params.update(image=data_uri) params.update(image=data_uri)
params.update(commentAllowed=jdata.get("commentAllowed", 0))
params.update(domain=domain) params.update(domain=domain)
return jsonify(params) return jsonify(params)

View File

@ -33,12 +33,14 @@ window.LNbits = {
callback, callback,
description_hash, description_hash,
amount, amount,
description = '' description = '',
comment = ''
) { ) {
return this.request('post', '/api/v1/payments/lnurl', wallet.adminkey, { return this.request('post', '/api/v1/payments/lnurl', wallet.adminkey, {
callback, callback,
description_hash, description_hash,
amount, amount,
comment,
description description
}) })
}, },