track fiat value of payments (#1789)

* save fiat_amounts on payment creation

* show fiat amount in frontend

* add lnbits_default_accounting_currency

* extract fiat calculation logic into service

* move all currency conversions to calc_fiat_amounts

move all conversion logic into create_invoice so extensions can benefit aswell

* show user-defined and wallet-defined currency in frontend

* remove sat from fiat units

* make bundle

* improve tests

* debug log
This commit is contained in:
jackstar12
2023-08-28 11:00:59 +01:00
committed by GitHub
parent 7a37e72915
commit 2623e9247a
14 changed files with 233 additions and 42 deletions
+12 -11
View File
@@ -114,7 +114,7 @@ async def api_wallet(wallet: WalletTypeInfo = Depends(get_key_type)):
@core_app.put("/api/v1/wallet/{new_name}")
async def api_update_wallet(
async def api_update_wallet_name(
new_name: str, wallet: WalletTypeInfo = Depends(require_admin_key)
):
await update_wallet(wallet.wallet.id, new_name)
@@ -125,6 +125,15 @@ async def api_update_wallet(
}
@core_app.patch("/api/v1/wallet", response_model=Wallet)
async def api_update_wallet(
name: Optional[str] = Body(None),
currency: Optional[str] = Body(None),
wallet: WalletTypeInfo = Depends(require_admin_key),
):
return await update_wallet(wallet.wallet.id, name, currency)
@core_app.get(
"/api/v1/payments",
name="Payment List",
@@ -187,7 +196,6 @@ async def api_payments_paginated(
async def api_payments_create_invoice(data: CreateInvoice, wallet: Wallet):
data.extra = data.extra or {}
description_hash = b""
unhashed_description = b""
memo = data.memo or settings.lnbits_site_title
@@ -211,20 +219,13 @@ async def api_payments_create_invoice(data: CreateInvoice, wallet: Wallet):
# do not save memo if description_hash or unhashed_description is set
memo = ""
if data.unit == "sat":
amount = int(data.amount)
else:
assert data.unit is not None, "unit not set"
price_in_sats = await fiat_amount_as_satoshis(data.amount, data.unit)
amount = price_in_sats
data.extra.update({"fiat_amount": data.amount, "fiat_currency": data.unit})
async with db.connect() as conn:
try:
payment_hash, payment_request = await create_invoice(
wallet_id=wallet.id,
amount=amount,
amount=data.amount,
memo=memo,
currency=data.unit,
description_hash=description_hash,
unhashed_description=unhashed_description,
expiry=data.expiry,