mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-18 19:41:11 +02:00
Revert "proposal to allow decimal valued items in fiat"
This reverts commit e58a6923fc
.
This commit is contained in:
@@ -1,19 +1,20 @@
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
from lnbits.extensions.offlineshop.models import Item
|
||||||
from fastapi.params import Query
|
from fastapi.params import Query
|
||||||
from lnurl import ( # type: ignore
|
|
||||||
LnurlErrorResponse,
|
|
||||||
LnurlPayActionResponse,
|
|
||||||
LnurlPayResponse,
|
|
||||||
)
|
|
||||||
from starlette.requests import Request
|
from starlette.requests import Request
|
||||||
|
from lnbits.helpers import url_for
|
||||||
|
from lnurl import (
|
||||||
|
LnurlPayResponse,
|
||||||
|
LnurlPayActionResponse,
|
||||||
|
LnurlErrorResponse,
|
||||||
|
) # type: ignore
|
||||||
|
|
||||||
from lnbits.core.services import create_invoice
|
from lnbits.core.services import create_invoice
|
||||||
from lnbits.extensions.offlineshop.models import Item
|
|
||||||
from lnbits.utils.exchange_rates import fiat_amount_as_satoshis
|
from lnbits.utils.exchange_rates import fiat_amount_as_satoshis
|
||||||
|
|
||||||
from . import offlineshop_ext
|
from . import offlineshop_ext
|
||||||
from .crud import get_item, get_shop
|
from .crud import get_shop, get_item
|
||||||
|
|
||||||
|
|
||||||
@offlineshop_ext.get("/lnurl/{item_id}", name="offlineshop.lnurl_response")
|
@offlineshop_ext.get("/lnurl/{item_id}", name="offlineshop.lnurl_response")
|
||||||
@@ -26,7 +27,7 @@ async def lnurl_response(req: Request, item_id: int = Query(...)):
|
|||||||
return {"status": "ERROR", "reason": "Item disabled."}
|
return {"status": "ERROR", "reason": "Item disabled."}
|
||||||
|
|
||||||
price_msat = (
|
price_msat = (
|
||||||
await fiat_amount_as_satoshis(item.price / 1000, item.unit)
|
await fiat_amount_as_satoshis(item.price, item.unit)
|
||||||
if item.unit != "sat"
|
if item.unit != "sat"
|
||||||
else item.price
|
else item.price
|
||||||
) * 1000
|
) * 1000
|
||||||
@@ -46,12 +47,12 @@ async def lnurl_callback(request: Request, item_id: int):
|
|||||||
item = await get_item(item_id) # type: Item
|
item = await get_item(item_id) # type: Item
|
||||||
if not item:
|
if not item:
|
||||||
return {"status": "ERROR", "reason": "Couldn't find item."}
|
return {"status": "ERROR", "reason": "Couldn't find item."}
|
||||||
|
|
||||||
if item.unit == "sat":
|
if item.unit == "sat":
|
||||||
min = item.price * 1000
|
min = item.price * 1000
|
||||||
max = item.price * 1000
|
max = item.price * 1000
|
||||||
else:
|
else:
|
||||||
price = await fiat_amount_as_satoshis(item.price / 1000, item.unit)
|
price = await fiat_amount_as_satoshis(item.price, item.unit)
|
||||||
# allow some fluctuation (the fiat price may have changed between the calls)
|
# allow some fluctuation (the fiat price may have changed between the calls)
|
||||||
min = price * 995
|
min = price * 995
|
||||||
max = price * 1010
|
max = price * 1010
|
||||||
@@ -67,6 +68,7 @@ async def lnurl_callback(request: Request, item_id: int):
|
|||||||
).dict()
|
).dict()
|
||||||
|
|
||||||
shop = await get_shop(item.shop)
|
shop = await get_shop(item.shop)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payment_hash, payment_request = await create_invoice(
|
payment_hash, payment_request = await create_invoice(
|
||||||
wallet_id=shop.wallet,
|
wallet_id=shop.wallet,
|
||||||
|
@@ -27,6 +27,3 @@ async def m001_initial(db):
|
|||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
async def m002_store_fiat_in_cents(db):
|
|
||||||
await db.execute("UPDATE offlineshop.items SET price = (price * 1000) WHERE unit NOT LIKE 'sat'")
|
|
||||||
|
@@ -31,7 +31,7 @@ new Vue({
|
|||||||
computed: {
|
computed: {
|
||||||
printItems() {
|
printItems() {
|
||||||
return this.offlineshop.items.filter(({enabled}) => enabled)
|
return this.offlineshop.items.filter(({enabled}) => enabled)
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
openNewDialog() {
|
openNewDialog() {
|
||||||
@@ -119,9 +119,6 @@ new Vue({
|
|||||||
},
|
},
|
||||||
async sendItem() {
|
async sendItem() {
|
||||||
let {id, name, image, description, price, unit} = this.itemDialog.data
|
let {id, name, image, description, price, unit} = this.itemDialog.data
|
||||||
//convert fiat price to milli (int)
|
|
||||||
price = unit == 'sat' ? price : price * 1000
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
@@ -3,17 +3,17 @@ from datetime import datetime
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fastapi import HTTPException, Request
|
|
||||||
from fastapi.params import Depends, Query
|
from fastapi.params import Depends, Query
|
||||||
from starlette.responses import HTMLResponse
|
from starlette.responses import HTMLResponse
|
||||||
|
|
||||||
from lnbits.core.crud import get_standalone_payment
|
|
||||||
from lnbits.core.models import Payment, User
|
|
||||||
from lnbits.decorators import check_user_exists
|
from lnbits.decorators import check_user_exists
|
||||||
|
from lnbits.core.models import Payment, User
|
||||||
|
from lnbits.core.crud import get_standalone_payment
|
||||||
|
|
||||||
from . import offlineshop_ext, offlineshop_renderer
|
from . import offlineshop_ext, offlineshop_renderer
|
||||||
from .crud import get_item, get_shop
|
|
||||||
from .models import Item
|
from .models import Item
|
||||||
|
from .crud import get_item, get_shop
|
||||||
|
from fastapi import Request, HTTPException
|
||||||
|
|
||||||
|
|
||||||
@offlineshop_ext.get("/", response_class=HTMLResponse)
|
@offlineshop_ext.get("/", response_class=HTMLResponse)
|
||||||
@@ -29,8 +29,6 @@ async def print_qr_codes(request: Request, items: List[int] = None):
|
|||||||
for item_id in request.query_params.get("items").split(","):
|
for item_id in request.query_params.get("items").split(","):
|
||||||
item = await get_item(item_id) # type: Item
|
item = await get_item(item_id) # type: Item
|
||||||
if item:
|
if item:
|
||||||
if item.unit != 'sat':
|
|
||||||
item.price = (item.price / 1000)
|
|
||||||
items.append(
|
items.append(
|
||||||
{
|
{
|
||||||
"lnurl": item.lnurl(request),
|
"lnurl": item.lnurl(request),
|
||||||
|
@@ -27,7 +27,7 @@ from .models import ShopCounter
|
|||||||
|
|
||||||
@offlineshop_ext.get("/api/v1/currencies")
|
@offlineshop_ext.get("/api/v1/currencies")
|
||||||
async def api_list_currencies_available():
|
async def api_list_currencies_available():
|
||||||
return list(currencies.keys())
|
return json.dumps(list(currencies.keys()))
|
||||||
|
|
||||||
|
|
||||||
@offlineshop_ext.get("/api/v1/offlineshop")
|
@offlineshop_ext.get("/api/v1/offlineshop")
|
||||||
@@ -37,12 +37,7 @@ async def api_shop_from_wallet(
|
|||||||
):
|
):
|
||||||
shop = await get_or_create_shop_by_wallet(wallet.wallet.id)
|
shop = await get_or_create_shop_by_wallet(wallet.wallet.id)
|
||||||
items = await get_items(shop.id)
|
items = await get_items(shop.id)
|
||||||
|
|
||||||
#revert millicents to unit
|
|
||||||
for item in items:
|
|
||||||
if item.unit != 'sat':
|
|
||||||
item.price = item.price / 1000
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return {
|
return {
|
||||||
**shop.dict(),
|
**shop.dict(),
|
||||||
@@ -65,11 +60,11 @@ class CreateItemsData(BaseModel):
|
|||||||
|
|
||||||
@offlineshop_ext.post("/api/v1/offlineshop/items")
|
@offlineshop_ext.post("/api/v1/offlineshop/items")
|
||||||
@offlineshop_ext.put("/api/v1/offlineshop/items/{item_id}")
|
@offlineshop_ext.put("/api/v1/offlineshop/items/{item_id}")
|
||||||
|
# @api_check_wallet_key("invoice")
|
||||||
async def api_add_or_update_item(
|
async def api_add_or_update_item(
|
||||||
data: CreateItemsData, item_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
|
data: CreateItemsData, item_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
|
||||||
):
|
):
|
||||||
shop = await get_or_create_shop_by_wallet(wallet.wallet.id)
|
shop = await get_or_create_shop_by_wallet(wallet.wallet.id)
|
||||||
|
|
||||||
if item_id == None:
|
if item_id == None:
|
||||||
await add_item(
|
await add_item(
|
||||||
shop.id, data.name, data.description, data.image, data.price, data.unit
|
shop.id, data.name, data.description, data.image, data.price, data.unit
|
||||||
|
Reference in New Issue
Block a user