fix: improve subscription email renewal flow
This commit is contained in:
@@ -110,25 +110,43 @@ export function createBillingStore({
|
||||
tariffCatalog,
|
||||
subscription,
|
||||
plans,
|
||||
defaultMethod = ""
|
||||
defaultMethod = "",
|
||||
options = {}
|
||||
) {
|
||||
state.update((s) => {
|
||||
let step;
|
||||
let plan = s.selectedPlan;
|
||||
let tariffKey = s.selectedTariffKey;
|
||||
const catalog = tariffCatalog || [];
|
||||
const planList = plans || [];
|
||||
const preferredTariffKey = String(options?.preferredTariffKey || "").trim();
|
||||
const preferredTariff = preferredTariffKey
|
||||
? catalog.find((tariff) => tariff.key === preferredTariffKey)
|
||||
: null;
|
||||
const fallbackTariff =
|
||||
catalog.find((tariff) => tariff.is_default) ||
|
||||
catalog.find((tariff) => tariff.key === "standard") ||
|
||||
catalog[0] ||
|
||||
null;
|
||||
const deeplinkTariff =
|
||||
preferredTariff || (options?.selectDefaultTariff ? fallbackTariff : null);
|
||||
|
||||
if (tariffMode) {
|
||||
if (singleTariffMode && tariffCatalog[0]?.key) {
|
||||
tariffKey = tariffCatalog[0].key;
|
||||
plan = plans.find((p) => p?.tariff_key === tariffKey) || null;
|
||||
if (deeplinkTariff?.key) {
|
||||
tariffKey = deeplinkTariff.key;
|
||||
plan = planList.find((p) => p?.tariff_key === tariffKey) || null;
|
||||
step = options?.preferCheckout && plan ? "checkout" : "tariff";
|
||||
} else if (singleTariffMode && catalog[0]?.key) {
|
||||
tariffKey = catalog[0].key;
|
||||
plan = planList.find((p) => p?.tariff_key === tariffKey) || null;
|
||||
step = "checkout";
|
||||
} else if (
|
||||
subscription?.active &&
|
||||
subscription?.tariff_key &&
|
||||
tariffCatalog.some((t) => t.key === subscription.tariff_key)
|
||||
catalog.some((t) => t.key === subscription.tariff_key)
|
||||
) {
|
||||
tariffKey = subscription.tariff_key;
|
||||
plan = plans.find((p) => p?.tariff_key === tariffKey) || null;
|
||||
plan = planList.find((p) => p?.tariff_key === tariffKey) || null;
|
||||
step = "checkout";
|
||||
} else {
|
||||
step = "tariff";
|
||||
|
||||
@@ -21,11 +21,13 @@ export function buildTariffCatalog(planList) {
|
||||
(plan?.sale_mode === "traffic_package" || plan?.sale_mode === "traffic"
|
||||
? "traffic"
|
||||
: "period"),
|
||||
is_default: Boolean(plan?.is_default_tariff),
|
||||
monthly_gb: Number(plan?.monthly_gb || 0),
|
||||
traffic_packages: [],
|
||||
plans_count: 0,
|
||||
};
|
||||
if (!entry.description && plan?.description) entry.description = plan.description;
|
||||
if (plan?.is_default_tariff) entry.is_default = true;
|
||||
if (!entry.monthly_gb && Number(plan?.monthly_gb || 0) > 0)
|
||||
entry.monthly_gb = Number(plan.monthly_gb);
|
||||
const trafficGb = Number(plan?.traffic_gb || 0);
|
||||
|
||||
@@ -21,6 +21,7 @@ export async function runWebappBoot({
|
||||
clearToken,
|
||||
clearManualLogoutFlag,
|
||||
isManuallyLoggedOut,
|
||||
hasEmailCodeLoginDeeplink,
|
||||
finalizeMagicLogin,
|
||||
finalizeTelegramAuth,
|
||||
setAuthStatus,
|
||||
@@ -38,6 +39,13 @@ export async function runWebappBoot({
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasEmailCodeLoginDeeplink?.()) {
|
||||
clearManualLogoutFlag();
|
||||
clearToken();
|
||||
showLogin();
|
||||
return;
|
||||
}
|
||||
|
||||
const magicToken = readMagicLoginToken();
|
||||
if (magicToken && (await finalizeMagicLogin(magicToken))) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user