fix: backwards compatible (#2853)
This commit is contained in:
parent
d234ab12d8
commit
32c042741d
2 changed files with 10 additions and 5 deletions
|
|
@ -35,7 +35,7 @@ from lnbits.settings import settings
|
|||
from lnbits.utils.exchange_rates import (
|
||||
allowed_currencies,
|
||||
fiat_amount_as_satoshis,
|
||||
get_fiat_rate_satoshis,
|
||||
get_fiat_rate_and_price_satoshis,
|
||||
satoshis_amount_as_fiat,
|
||||
)
|
||||
from lnbits.wallets import get_funding_source
|
||||
|
|
@ -235,7 +235,7 @@ async def api_exchange_rate_history() -> list[dict]:
|
|||
|
||||
@api_router.get("/api/v1/rate/{currency}")
|
||||
async def api_check_fiat_rate(currency: str) -> dict[str, float]:
|
||||
rate, price = await get_fiat_rate_satoshis(currency)
|
||||
rate, price = await get_fiat_rate_and_price_satoshis(currency)
|
||||
return {"rate": rate, "price": price}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -247,7 +247,7 @@ async def btc_price(currency: str) -> float:
|
|||
return sum(rates_values) / len(rates_values)
|
||||
|
||||
|
||||
async def get_fiat_rate_satoshis(currency: str) -> tuple[float, float]:
|
||||
async def get_fiat_rate_and_price_satoshis(currency: str) -> tuple[float, float]:
|
||||
price = await cache.save_result(
|
||||
lambda: btc_price(currency),
|
||||
f"btc-price-{currency}",
|
||||
|
|
@ -256,11 +256,16 @@ async def get_fiat_rate_satoshis(currency: str) -> tuple[float, float]:
|
|||
return float(100_000_000 / price), price
|
||||
|
||||
|
||||
async def get_fiat_rate_satoshis(currency: str) -> float:
|
||||
rate, _ = await get_fiat_rate_and_price_satoshis(currency)
|
||||
return rate
|
||||
|
||||
|
||||
async def fiat_amount_as_satoshis(amount: float, currency: str) -> int:
|
||||
rate, _ = await get_fiat_rate_satoshis(currency)
|
||||
rate = await get_fiat_rate_satoshis(currency)
|
||||
return int(amount * (rate))
|
||||
|
||||
|
||||
async def satoshis_amount_as_fiat(amount: float, currency: str) -> float:
|
||||
rate, _ = await get_fiat_rate_satoshis(currency)
|
||||
rate = await get_fiat_rate_satoshis(currency)
|
||||
return float(amount / rate)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue