fix(payment): consume first recharge offer after payment

This commit is contained in:
2026-07-03 10:54:46 +08:00
parent bb6ebbae7e
commit 489554cd78
13 changed files with 137 additions and 27 deletions
@@ -38,6 +38,8 @@ interface DismissalState {
dismissed: boolean;
}
const FIRST_RECHARGE_DEFAULT_DISCOUNT_PERCENT = 50;
export function shouldShowFirstRechargeOfferBanner(
input: FirstRechargeOfferBannerEligibility,
): boolean {
@@ -66,7 +68,7 @@ export function useFirstRechargeOfferBanner({
loaded: false,
dismissed: false,
}));
const discountPercent = payment.firstRechargeOffer?.discountPercent ?? 50;
const discountPercent = FIRST_RECHARGE_DEFAULT_DISCOUNT_PERCENT;
useEffect(() => {
if (!isAuthenticatedUser) return;
@@ -174,7 +174,6 @@ describe("subscription screen helpers", () => {
expect(
getFirstRechargeOfferView({
isFirstRecharge: true,
discountPercent: 50,
vipPlans: vipViews,
coinPlans: coinViews,
}),
@@ -182,6 +181,13 @@ describe("subscription screen helpers", () => {
badgeText: "50% OFF",
title: "First Recharge Offer",
});
expect(
getFirstRechargeOfferView({
isFirstRecharge: false,
vipPlans: vipViews,
coinPlans: coinViews,
}),
).toBeNull();
});
it("selects the first VIP plan by default when VIP can be purchased", () => {
@@ -157,17 +157,17 @@ export function getDefaultSubscriptionPlanId(input: {
export function getFirstRechargeOfferView(input: {
isFirstRecharge: boolean;
discountPercent?: number | null;
vipPlans: readonly VipOfferPlanView[];
coinPlans: readonly CoinsOfferPlanView[];
}): FirstRechargeOfferView | null {
if (!input.isFirstRecharge) return null;
const promotedPlan = [...input.vipPlans, ...input.coinPlans].find(
(plan) => plan.isFirstRechargeOffer,
);
if (!input.isFirstRecharge && !promotedPlan) return null;
const discountPercent =
promotedPlan?.firstRechargeDiscountPercent ?? input.discountPercent ?? 50;
promotedPlan?.firstRechargeDiscountPercent ?? 50;
const badgeText = `${discountPercent}% OFF`;
return {
badgeText,
+1 -7
View File
@@ -77,16 +77,10 @@ export function SubscriptionScreen({
() =>
getFirstRechargeOfferView({
isFirstRecharge: payment.isFirstRecharge,
discountPercent: payment.firstRechargeOffer?.discountPercent,
vipPlans: vipOfferPlans,
coinPlans: directCoinsPlans,
}),
[
directCoinsPlans,
payment.firstRechargeOffer?.discountPercent,
payment.isFirstRecharge,
vipOfferPlans,
],
[directCoinsPlans, payment.isFirstRecharge, vipOfferPlans],
);
const selectedPlan = findSelectedSubscriptionPlan({