Merge pull request #524 from lnbits/docs_api_add_unit_to_invoice

Fix fiat amount entry in invoice creation
This commit is contained in:
Arc 2022-02-18 11:44:05 +00:00 committed by GitHub
commit 88df4266b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 13 deletions

View file

@ -61,7 +61,7 @@
<code <code
>curl -X POST {{ request.base_url }}api/v1/payments -d '{"out": false, >curl -X POST {{ request.base_url }}api/v1/payments -d '{"out": false,
"amount": &lt;int&gt;, "memo": &lt;string&gt;, "webhook": "amount": &lt;int&gt;, "memo": &lt;string&gt;, "webhook":
&lt;url:string&gt;}' -H "X-Api-Key: <i>{{ wallet.inkey }}</i>" -H &lt;url:string&gt;, "unit": &lt;string&gt;}' -H "X-Api-Key: <i>{{ wallet.inkey }}</i>" -H
"Content-type: application/json"</code "Content-type: application/json"</code
> >
</q-card-section> </q-card-section>

View file

@ -417,9 +417,11 @@
filled filled
dense dense
v-model.number="receive.data.amount" v-model.number="receive.data.amount"
type="number" :label="'Amount (' + receive.unit + ') *'"
label="Amount ({{LNBITS_DENOMINATION}}) *" :mask="receive.unit != 'sat' ? '#.##' : '#'"
:step="receive.unit != 'sat' ? '0.001' : '1'" fill-mask="0"
reverse-fill-mask
:step="receive.unit != 'sat' ? '0.01' : '1'"
:min="receive.minMax[0]" :min="receive.minMax[0]"
:max="receive.minMax[1]" :max="receive.minMax[1]"
:readonly="receive.lnurl && receive.lnurl.fixed" :readonly="receive.lnurl && receive.lnurl.fixed"
@ -437,7 +439,7 @@
<q-btn <q-btn
unelevated unelevated
color="primary" color="primary"
:disable="receive.data.memo == null || receive.data.amount == null || receive.data.amount <= 0" :disable="receive.data.amount == null || receive.data.amount <= 0"
type="submit" type="submit"
> >
<span v-if="receive.lnurl"> <span v-if="receive.lnurl">

View file

@ -31,6 +31,7 @@ from lnbits.utils.exchange_rates import (
fiat_amount_as_satoshis, fiat_amount_as_satoshis,
satoshis_amount_as_fiat, satoshis_amount_as_fiat,
) )
from lnbits.settings import LNBITS_SITE_TITLE
from .. import core_app, db from .. import core_app, db
from ..crud import ( from ..crud import (
@ -123,7 +124,7 @@ async def api_payments(wallet: WalletTypeInfo = Depends(get_key_type)):
class CreateInvoiceData(BaseModel): class CreateInvoiceData(BaseModel):
out: Optional[bool] = True out: Optional[bool] = True
amount: int = Query(None, ge=1) amount: float = Query(None, ge=0)
memo: str = None memo: str = None
unit: Optional[str] = "sat" unit: Optional[str] = "sat"
description_hash: Optional[str] = None description_hash: Optional[str] = None
@ -140,9 +141,9 @@ async def api_payments_create_invoice(data: CreateInvoiceData, wallet: Wallet):
memo = "" memo = ""
else: else:
description_hash = b"" description_hash = b""
memo = data.memo memo = data.memo or LNBITS_SITE_TITLE
if data.unit == "sat": if data.unit == "sat":
amount = data.amount amount = int(data.amount)
else: else:
price_in_sats = await fiat_amount_as_satoshis(data.amount, data.unit) price_in_sats = await fiat_amount_as_satoshis(data.amount, data.unit)
amount = price_in_sats amount = price_in_sats