fix: hide device topup button when no HWID packages or unlimited devices

This commit is contained in:
3252a8
2026-05-17 17:26:37 +03:00
parent cb5d59571e
commit 91e79388d1
3 changed files with 19 additions and 2 deletions
@@ -193,6 +193,7 @@ def _serialize_subscription(
can_topup_regular_traffic = False
can_topup_premium_traffic = False
can_topup_traffic = False
can_topup_devices = False
if settings.tariffs_config and active.get("tariff_key"):
try:
tariff = settings.tariffs_config.require(str(active.get("tariff_key")))
@@ -204,10 +205,16 @@ def _serialize_subscription(
and tariff.premium_topup_packages.has_any()
)
can_topup_traffic = bool(can_topup_regular_traffic or can_topup_premium_traffic)
# max_devices == 0 means unlimited — top-up is pointless in that case.
can_topup_devices = bool(
tariff.has_hwid_device_packages()
and _coerce_int_or_none(active.get("max_devices")) != 0
)
except Exception:
can_topup_regular_traffic = False
can_topup_premium_traffic = False
can_topup_traffic = False
can_topup_devices = False
return {
"active": seconds_left > 0,
@@ -249,6 +256,7 @@ def _serialize_subscription(
"can_topup_traffic": can_topup_traffic,
"can_topup_regular_traffic": can_topup_regular_traffic,
"can_topup_premium_traffic": can_topup_premium_traffic,
"can_topup_devices": can_topup_devices,
"period_start_at": active.get("period_start_at").isoformat()
if active.get("period_start_at")
else None,