mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-06 18:02:38 +02:00
make price optional then fix min/max issues.
This commit is contained in:
@@ -21,8 +21,8 @@ async def lnurl_response(ls_id):
|
|||||||
|
|
||||||
resp = LnurlPayResponse(
|
resp = LnurlPayResponse(
|
||||||
callback=url_for("livestream.lnurl_callback", track_id=track.id, _external=True),
|
callback=url_for("livestream.lnurl_callback", track_id=track.id, _external=True),
|
||||||
min_sendable=min(100000, track.price_msat),
|
min_sendable=track.min_sendable,
|
||||||
max_sendable=track.price_msat * 5,
|
max_sendable=track.max_sendable,
|
||||||
metadata=await track.lnurlpay_metadata(),
|
metadata=await track.lnurlpay_metadata(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -40,19 +40,19 @@ async def lnurl_callback(track_id):
|
|||||||
|
|
||||||
amount_received = int(request.args.get("amount"))
|
amount_received = int(request.args.get("amount"))
|
||||||
|
|
||||||
if amount_received < track.price_msat:
|
if amount_received < track.min_sendable:
|
||||||
return (
|
return (
|
||||||
jsonify(
|
jsonify(
|
||||||
LnurlErrorResponse(
|
LnurlErrorResponse(
|
||||||
reason=f"Amount {round(amount_received / 1000)} is smaller than minimum {math.floor(track.price_msat / 1000)}."
|
reason=f"Amount {round(amount_received / 1000)} is smaller than minimum {math.floor(track.min_sendable)}."
|
||||||
).dict()
|
).dict()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
elif track.price_msat * 5 < amount_received:
|
elif track.max_sendable < amount_received:
|
||||||
return (
|
return (
|
||||||
jsonify(
|
jsonify(
|
||||||
LnurlErrorResponse(
|
LnurlErrorResponse(
|
||||||
reason=f"Amount {round(amount_received / 1000)} is greater than maximum {math.floor(track.price_msat * 5 / 1000)}."
|
reason=f"Amount {round(amount_received / 1000)} is greater than maximum {math.floor(track.max_sendable)}."
|
||||||
).dict()
|
).dict()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@@ -25,6 +25,14 @@ class Track(NamedTuple):
|
|||||||
name: str
|
name: str
|
||||||
producer: int
|
producer: int
|
||||||
|
|
||||||
|
@property
|
||||||
|
def min_sendable(self) -> int:
|
||||||
|
return min(100_000, self.price_msat or 100_000)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_sendable(self) -> int:
|
||||||
|
return max(50_000_000, self.price_msat * 5)
|
||||||
|
|
||||||
async def fullname(self) -> str:
|
async def fullname(self) -> str:
|
||||||
from .crud import get_producer
|
from .crud import get_producer
|
||||||
|
|
||||||
|
@@ -44,7 +44,6 @@ new Vue({
|
|||||||
return (
|
return (
|
||||||
!this.trackDialog.data.name ||
|
!this.trackDialog.data.name ||
|
||||||
this.trackDialog.data.name.length === 0 ||
|
this.trackDialog.data.name.length === 0 ||
|
||||||
!this.trackDialog.data.price_sat ||
|
|
||||||
!this.trackDialog.data.producer ||
|
!this.trackDialog.data.producer ||
|
||||||
this.trackDialog.data.producer.length === 0
|
this.trackDialog.data.producer.length === 0
|
||||||
)
|
)
|
||||||
@@ -107,7 +106,7 @@ new Vue({
|
|||||||
? download_url
|
? download_url
|
||||||
: undefined,
|
: undefined,
|
||||||
name,
|
name,
|
||||||
price_msat: price_sat * 1000,
|
price_msat: price_sat * 1000 || 0,
|
||||||
producer_name: typeof producer === 'string' ? producer : undefined,
|
producer_name: typeof producer === 'string' ? producer : undefined,
|
||||||
producer_id: typeof producer === 'object' ? producer.id : undefined
|
producer_id: typeof producer === 'object' ? producer.id : undefined
|
||||||
}
|
}
|
||||||
|
@@ -252,7 +252,7 @@
|
|||||||
type="number"
|
type="number"
|
||||||
min="1"
|
min="1"
|
||||||
label="Track price (sat)"
|
label="Track price (sat)"
|
||||||
hint="This is a minimum price. Payments up to 5x bigger than this will be accepted."
|
hint="This is the minimum price for buying the track download link. It does nothing for tracks without a download URL."
|
||||||
></q-input>
|
></q-input>
|
||||||
<q-input
|
<q-input
|
||||||
filled
|
filled
|
||||||
|
@@ -73,7 +73,7 @@ async def api_update_fee(fee_pct):
|
|||||||
schema={
|
schema={
|
||||||
"name": {"type": "string", "empty": False, "required": True},
|
"name": {"type": "string", "empty": False, "required": True},
|
||||||
"download_url": {"type": "string", "empty": False, "required": False},
|
"download_url": {"type": "string", "empty": False, "required": False},
|
||||||
"price_msat": {"type": "number", "min": 1, "required": True},
|
"price_msat": {"type": "number", "min": 0, "required": False},
|
||||||
"producer_id": {"type": "number", "required": True, "excludes": "producer_name"},
|
"producer_id": {"type": "number", "required": True, "excludes": "producer_name"},
|
||||||
"producer_name": {"type": "string", "required": True, "excludes": "producer_id"},
|
"producer_name": {"type": "string", "required": True, "excludes": "producer_id"},
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,7 @@ async def api_add_track():
|
|||||||
ls.id,
|
ls.id,
|
||||||
g.data["name"],
|
g.data["name"],
|
||||||
g.data.get("download_url"),
|
g.data.get("download_url"),
|
||||||
g.data["price_msat"],
|
g.data.get("price_msat", 0),
|
||||||
g.data.get("producer_name"),
|
g.data.get("producer_name"),
|
||||||
g.data.get("producer_id"),
|
g.data.get("producer_id"),
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user