fix: hide device topup button when no HWID packages or unlimited devices
This commit is contained in:
@@ -193,6 +193,7 @@ def _serialize_subscription(
|
|||||||
can_topup_regular_traffic = False
|
can_topup_regular_traffic = False
|
||||||
can_topup_premium_traffic = False
|
can_topup_premium_traffic = False
|
||||||
can_topup_traffic = False
|
can_topup_traffic = False
|
||||||
|
can_topup_devices = False
|
||||||
if settings.tariffs_config and active.get("tariff_key"):
|
if settings.tariffs_config and active.get("tariff_key"):
|
||||||
try:
|
try:
|
||||||
tariff = settings.tariffs_config.require(str(active.get("tariff_key")))
|
tariff = settings.tariffs_config.require(str(active.get("tariff_key")))
|
||||||
@@ -204,10 +205,16 @@ def _serialize_subscription(
|
|||||||
and tariff.premium_topup_packages.has_any()
|
and tariff.premium_topup_packages.has_any()
|
||||||
)
|
)
|
||||||
can_topup_traffic = bool(can_topup_regular_traffic or can_topup_premium_traffic)
|
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:
|
except Exception:
|
||||||
can_topup_regular_traffic = False
|
can_topup_regular_traffic = False
|
||||||
can_topup_premium_traffic = False
|
can_topup_premium_traffic = False
|
||||||
can_topup_traffic = False
|
can_topup_traffic = False
|
||||||
|
can_topup_devices = False
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"active": seconds_left > 0,
|
"active": seconds_left > 0,
|
||||||
@@ -249,6 +256,7 @@ def _serialize_subscription(
|
|||||||
"can_topup_traffic": can_topup_traffic,
|
"can_topup_traffic": can_topup_traffic,
|
||||||
"can_topup_regular_traffic": can_topup_regular_traffic,
|
"can_topup_regular_traffic": can_topup_regular_traffic,
|
||||||
"can_topup_premium_traffic": can_topup_premium_traffic,
|
"can_topup_premium_traffic": can_topup_premium_traffic,
|
||||||
|
"can_topup_devices": can_topup_devices,
|
||||||
"period_start_at": active.get("period_start_at").isoformat()
|
"period_start_at": active.get("period_start_at").isoformat()
|
||||||
if active.get("period_start_at")
|
if active.get("period_start_at")
|
||||||
else None,
|
else None,
|
||||||
|
|||||||
@@ -994,7 +994,16 @@ async def my_subscription_command_handler(
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
if settings.tariffs_config and local_sub and local_sub.tariff_key:
|
# Skip the buy-devices button entirely when the user has unlimited
|
||||||
|
# devices (max_devices == 0). Otherwise the button leads to an
|
||||||
|
# alert "hwid_devices_unlimited_no_topup" — confusing dead end.
|
||||||
|
devices_topup_allowed = (
|
||||||
|
settings.tariffs_config
|
||||||
|
and local_sub
|
||||||
|
and local_sub.tariff_key
|
||||||
|
and max_devices_value not in (None, 0)
|
||||||
|
)
|
||||||
|
if devices_topup_allowed:
|
||||||
try:
|
try:
|
||||||
tariff_for_devices = settings.tariffs_config.require(local_sub.tariff_key)
|
tariff_for_devices = settings.tariffs_config.require(local_sub.tariff_key)
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
value={devicesPercent(devicesData)}
|
value={devicesPercent(devicesData)}
|
||||||
label={t("wa_devices_title")}
|
label={t("wa_devices_title")}
|
||||||
/>
|
/>
|
||||||
{#if subscription?.active && subscription?.max_devices !== 0}
|
{#if subscription?.active && subscription?.max_devices !== 0 && subscription?.can_topup_devices}
|
||||||
<Button variant="secondary" class="wide" onclick={openDeviceTopupModal}>
|
<Button variant="secondary" class="wide" onclick={openDeviceTopupModal}>
|
||||||
<Plus size={17} />
|
<Plus size={17} />
|
||||||
{t("wa_buy_hwid_devices")}
|
{t("wa_buy_hwid_devices")}
|
||||||
|
|||||||
Reference in New Issue
Block a user