@blocklet/payment-react 1.25.10 → 1.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/checkout-v2/checkout-v2.d.ts +2 -0
- package/es/checkout-v2/checkout-v2.js +121 -0
- package/es/checkout-v2/components/dialogs/checkout-dialogs.d.ts +1 -0
- package/es/checkout-v2/components/dialogs/checkout-dialogs.js +106 -0
- package/es/checkout-v2/components/left/billing-toggle.d.ts +6 -0
- package/es/checkout-v2/components/left/billing-toggle.js +118 -0
- package/es/checkout-v2/components/left/cross-sell-card.d.ts +10 -0
- package/es/checkout-v2/components/left/cross-sell-card.js +167 -0
- package/es/checkout-v2/components/left/product-item-card.d.ts +26 -0
- package/es/checkout-v2/components/left/product-item-card.js +571 -0
- package/es/checkout-v2/components/left/promotion-input.d.ts +19 -0
- package/es/checkout-v2/components/left/promotion-input.js +178 -0
- package/es/checkout-v2/components/left/staking-breakdown.d.ts +9 -0
- package/es/checkout-v2/components/left/staking-breakdown.js +48 -0
- package/es/checkout-v2/components/left/trial-info.d.ts +13 -0
- package/es/checkout-v2/components/left/trial-info.js +48 -0
- package/es/checkout-v2/components/right/currency-grid.d.ts +8 -0
- package/es/checkout-v2/components/right/currency-grid.js +48 -0
- package/es/checkout-v2/components/right/customer-info-card.d.ts +17 -0
- package/es/checkout-v2/components/right/customer-info-card.js +156 -0
- package/es/checkout-v2/components/right/status-feedback.d.ts +7 -0
- package/es/checkout-v2/components/right/status-feedback.js +17 -0
- package/es/checkout-v2/components/right/submit-button.d.ts +10 -0
- package/es/checkout-v2/components/right/submit-button.js +29 -0
- package/es/checkout-v2/components/right/subscription-disclaimer.d.ts +11 -0
- package/es/checkout-v2/components/right/subscription-disclaimer.js +8 -0
- package/es/checkout-v2/components/shared/exchange-rate-footer.d.ts +23 -0
- package/es/checkout-v2/components/shared/exchange-rate-footer.js +182 -0
- package/es/checkout-v2/components/shared/scenario-badge.d.ts +6 -0
- package/es/checkout-v2/components/shared/scenario-badge.js +47 -0
- package/es/checkout-v2/components/shared/total-display.d.ts +7 -0
- package/es/checkout-v2/components/shared/total-display.js +84 -0
- package/es/checkout-v2/index.d.ts +2 -0
- package/es/checkout-v2/index.js +1 -0
- package/es/checkout-v2/layouts/checkout-layout.d.ts +7 -0
- package/es/checkout-v2/layouts/checkout-layout.js +226 -0
- package/es/checkout-v2/panels/left/composite-panel.d.ts +1 -0
- package/es/checkout-v2/panels/left/composite-panel.js +423 -0
- package/es/checkout-v2/panels/left/credit-topup-panel.d.ts +1 -0
- package/es/checkout-v2/panels/left/credit-topup-panel.js +611 -0
- package/es/checkout-v2/panels/left/scenario-router.d.ts +1 -0
- package/es/checkout-v2/panels/left/scenario-router.js +19 -0
- package/es/checkout-v2/panels/right/payment-panel.d.ts +1 -0
- package/es/checkout-v2/panels/right/payment-panel.js +644 -0
- package/es/checkout-v2/types.d.ts +15 -0
- package/es/checkout-v2/types.js +0 -0
- package/es/checkout-v2/utils/format.d.ts +59 -0
- package/es/checkout-v2/utils/format.js +125 -0
- package/es/checkout-v2/utils/scenario-detector.d.ts +3 -0
- package/es/checkout-v2/utils/scenario-detector.js +17 -0
- package/es/checkout-v2/views/error-view.d.ts +7 -0
- package/es/checkout-v2/views/error-view.js +269 -0
- package/es/checkout-v2/views/loading-view.d.ts +5 -0
- package/es/checkout-v2/views/loading-view.js +158 -0
- package/es/checkout-v2/views/success-view.d.ts +29 -0
- package/es/checkout-v2/views/success-view.js +614 -0
- package/es/components/phone-field.d.ts +14 -0
- package/es/components/phone-field.js +96 -0
- package/es/index.d.ts +3 -1
- package/es/index.js +3 -1
- package/es/locales/en.js +45 -6
- package/es/locales/zh.js +45 -6
- package/es/payment/form/index.js +10 -1
- package/lib/checkout-v2/checkout-v2.d.ts +2 -0
- package/lib/checkout-v2/checkout-v2.js +151 -0
- package/lib/checkout-v2/components/dialogs/checkout-dialogs.d.ts +1 -0
- package/lib/checkout-v2/components/dialogs/checkout-dialogs.js +131 -0
- package/lib/checkout-v2/components/left/billing-toggle.d.ts +6 -0
- package/lib/checkout-v2/components/left/billing-toggle.js +126 -0
- package/lib/checkout-v2/components/left/cross-sell-card.d.ts +10 -0
- package/lib/checkout-v2/components/left/cross-sell-card.js +257 -0
- package/lib/checkout-v2/components/left/product-item-card.d.ts +26 -0
- package/lib/checkout-v2/components/left/product-item-card.js +738 -0
- package/lib/checkout-v2/components/left/promotion-input.d.ts +19 -0
- package/lib/checkout-v2/components/left/promotion-input.js +220 -0
- package/lib/checkout-v2/components/left/staking-breakdown.d.ts +9 -0
- package/lib/checkout-v2/components/left/staking-breakdown.js +96 -0
- package/lib/checkout-v2/components/left/trial-info.d.ts +13 -0
- package/lib/checkout-v2/components/left/trial-info.js +82 -0
- package/lib/checkout-v2/components/right/currency-grid.d.ts +8 -0
- package/lib/checkout-v2/components/right/currency-grid.js +96 -0
- package/lib/checkout-v2/components/right/customer-info-card.d.ts +17 -0
- package/lib/checkout-v2/components/right/customer-info-card.js +246 -0
- package/lib/checkout-v2/components/right/status-feedback.d.ts +7 -0
- package/lib/checkout-v2/components/right/status-feedback.js +30 -0
- package/lib/checkout-v2/components/right/submit-button.d.ts +10 -0
- package/lib/checkout-v2/components/right/submit-button.js +35 -0
- package/lib/checkout-v2/components/right/subscription-disclaimer.d.ts +11 -0
- package/lib/checkout-v2/components/right/subscription-disclaimer.js +33 -0
- package/lib/checkout-v2/components/shared/exchange-rate-footer.d.ts +23 -0
- package/lib/checkout-v2/components/shared/exchange-rate-footer.js +282 -0
- package/lib/checkout-v2/components/shared/scenario-badge.d.ts +6 -0
- package/lib/checkout-v2/components/shared/scenario-badge.js +57 -0
- package/lib/checkout-v2/components/shared/total-display.d.ts +7 -0
- package/lib/checkout-v2/components/shared/total-display.js +154 -0
- package/lib/checkout-v2/index.d.ts +2 -0
- package/lib/checkout-v2/index.js +13 -0
- package/lib/checkout-v2/layouts/checkout-layout.d.ts +7 -0
- package/lib/checkout-v2/layouts/checkout-layout.js +308 -0
- package/lib/checkout-v2/panels/left/composite-panel.d.ts +1 -0
- package/lib/checkout-v2/panels/left/composite-panel.js +515 -0
- package/lib/checkout-v2/panels/left/credit-topup-panel.d.ts +1 -0
- package/lib/checkout-v2/panels/left/credit-topup-panel.js +795 -0
- package/lib/checkout-v2/panels/left/scenario-router.d.ts +1 -0
- package/lib/checkout-v2/panels/left/scenario-router.js +29 -0
- package/lib/checkout-v2/panels/right/payment-panel.d.ts +1 -0
- package/lib/checkout-v2/panels/right/payment-panel.js +906 -0
- package/lib/checkout-v2/types.d.ts +15 -0
- package/lib/checkout-v2/types.js +1 -0
- package/lib/checkout-v2/utils/format.d.ts +59 -0
- package/lib/checkout-v2/utils/format.js +158 -0
- package/lib/checkout-v2/utils/scenario-detector.d.ts +3 -0
- package/lib/checkout-v2/utils/scenario-detector.js +23 -0
- package/lib/checkout-v2/views/error-view.d.ts +7 -0
- package/lib/checkout-v2/views/error-view.js +321 -0
- package/lib/checkout-v2/views/loading-view.d.ts +5 -0
- package/lib/checkout-v2/views/loading-view.js +168 -0
- package/lib/checkout-v2/views/success-view.d.ts +29 -0
- package/lib/checkout-v2/views/success-view.js +735 -0
- package/lib/components/phone-field.d.ts +14 -0
- package/lib/components/phone-field.js +130 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +8 -0
- package/lib/locales/en.js +45 -6
- package/lib/locales/zh.js +45 -6
- package/lib/payment/form/index.js +10 -1
- package/package.json +4 -3
- package/src/checkout-v2/checkout-v2.tsx +155 -0
- package/src/checkout-v2/components/dialogs/checkout-dialogs.tsx +134 -0
- package/src/checkout-v2/components/left/billing-toggle.tsx +122 -0
- package/src/checkout-v2/components/left/cross-sell-card.tsx +170 -0
- package/src/checkout-v2/components/left/product-item-card.tsx +642 -0
- package/src/checkout-v2/components/left/promotion-input.tsx +207 -0
- package/src/checkout-v2/components/left/staking-breakdown.tsx +57 -0
- package/src/checkout-v2/components/left/trial-info.tsx +63 -0
- package/src/checkout-v2/components/right/currency-grid.tsx +59 -0
- package/src/checkout-v2/components/right/customer-info-card.tsx +214 -0
- package/src/checkout-v2/components/right/status-feedback.tsx +35 -0
- package/src/checkout-v2/components/right/submit-button.tsx +37 -0
- package/src/checkout-v2/components/right/subscription-disclaimer.tsx +27 -0
- package/src/checkout-v2/components/shared/exchange-rate-footer.tsx +221 -0
- package/src/checkout-v2/components/shared/scenario-badge.tsx +51 -0
- package/src/checkout-v2/components/shared/total-display.tsx +112 -0
- package/src/checkout-v2/index.ts +2 -0
- package/src/checkout-v2/layouts/checkout-layout.tsx +232 -0
- package/src/checkout-v2/panels/left/composite-panel.tsx +465 -0
- package/src/checkout-v2/panels/left/credit-topup-panel.tsx +677 -0
- package/src/checkout-v2/panels/left/scenario-router.tsx +22 -0
- package/src/checkout-v2/panels/right/payment-panel.tsx +703 -0
- package/src/checkout-v2/types.ts +18 -0
- package/src/checkout-v2/utils/format.ts +205 -0
- package/src/checkout-v2/utils/scenario-detector.ts +30 -0
- package/src/checkout-v2/views/error-view.tsx +293 -0
- package/src/checkout-v2/views/loading-view.tsx +162 -0
- package/src/checkout-v2/views/success-view.tsx +770 -0
- package/src/components/phone-field.tsx +119 -0
- package/src/index.ts +3 -0
- package/src/locales/en.tsx +45 -4
- package/src/locales/zh.tsx +43 -4
- package/src/payment/form/index.tsx +16 -1
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useMemo, useEffect, useRef, useCallback } from "react";
|
|
3
|
+
import { Box, IconButton, Typography, InputBase, Stack } from "@mui/material";
|
|
4
|
+
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
5
|
+
import AccessTimeOutlinedIcon from "@mui/icons-material/AccessTimeOutlined";
|
|
6
|
+
import Inventory2OutlinedIcon from "@mui/icons-material/Inventory2Outlined";
|
|
7
|
+
import { useRequest } from "ahooks";
|
|
8
|
+
import { BN, fromTokenToUnit } from "@ocap/util";
|
|
9
|
+
import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
|
|
10
|
+
import WarningAmberIcon from "@mui/icons-material/WarningAmber";
|
|
11
|
+
import {
|
|
12
|
+
useCheckoutStatus,
|
|
13
|
+
useLineItems,
|
|
14
|
+
useSessionContext,
|
|
15
|
+
useProduct,
|
|
16
|
+
useExchangeRate,
|
|
17
|
+
useSlippage,
|
|
18
|
+
usePaymentMethodContext,
|
|
19
|
+
useSubmitFeature
|
|
20
|
+
} from "@blocklet/payment-react-headless";
|
|
21
|
+
import { usePaymentContext } from "../../../contexts/payment.js";
|
|
22
|
+
import api from "../../../libs/api.js";
|
|
23
|
+
import { formatNumber, formatBNStr, formatCreditForCheckout, formatCreditAmount } from "../../../libs/util.js";
|
|
24
|
+
import { tSafe } from "../../utils/format.js";
|
|
25
|
+
import ScenarioBadge from "../../components/shared/scenario-badge.js";
|
|
26
|
+
import ExchangeRateFooter from "../../components/shared/exchange-rate-footer.js";
|
|
27
|
+
export default function CreditTopupPanel() {
|
|
28
|
+
const { t, locale } = useLocaleContext();
|
|
29
|
+
const { session, sessionData } = useSessionContext();
|
|
30
|
+
const { livemode } = useCheckoutStatus();
|
|
31
|
+
const { product } = useProduct();
|
|
32
|
+
const { currency, isStripe } = usePaymentMethodContext();
|
|
33
|
+
const lineItems = useLineItems();
|
|
34
|
+
const rate = useExchangeRate();
|
|
35
|
+
const slippage = useSlippage();
|
|
36
|
+
const { locked: configLocked } = useSubmitFeature();
|
|
37
|
+
const item = lineItems.items[0];
|
|
38
|
+
const activePrice = item ? item.upsell_price || item.price : null;
|
|
39
|
+
const creditConfig = activePrice?.metadata?.credit_config;
|
|
40
|
+
const creditAmount = creditConfig?.credit_amount ? Number(creditConfig.credit_amount) : 0;
|
|
41
|
+
const creditCurrencyId = creditConfig?.currency_id;
|
|
42
|
+
const { session: didSession, getCurrency } = usePaymentContext();
|
|
43
|
+
const creditCurrency = creditCurrencyId ? getCurrency(creditCurrencyId) : null;
|
|
44
|
+
const userDid = didSession?.user?.did || sessionData?.customer?.did;
|
|
45
|
+
const creditCurrencyDecimal = creditCurrency?.decimal;
|
|
46
|
+
const creditCurrencySymbol = creditCurrency?.symbol || "Credits";
|
|
47
|
+
const currencySymbol = "Credits";
|
|
48
|
+
const meterId = activePrice?.metadata?.meter_id;
|
|
49
|
+
const { data: meterData } = useRequest(
|
|
50
|
+
async () => {
|
|
51
|
+
if (!meterId) return null;
|
|
52
|
+
try {
|
|
53
|
+
const { data } = await api.get(`/api/meters/public/${meterId}`);
|
|
54
|
+
return data;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{ refreshDeps: [meterId] }
|
|
60
|
+
);
|
|
61
|
+
const creditName = meterData?.name || product?.name || "Credits";
|
|
62
|
+
const validDuration = creditConfig?.valid_duration_value;
|
|
63
|
+
const validDurationUnit = creditConfig?.valid_duration_unit || "days";
|
|
64
|
+
const scheduleConfig = creditConfig?.schedule;
|
|
65
|
+
const hasSchedule = scheduleConfig?.enabled && scheduleConfig?.delivery_mode && scheduleConfig.delivery_mode !== "invoice";
|
|
66
|
+
const hasExpiry = validDuration && validDuration > 0;
|
|
67
|
+
const step = Math.max(creditAmount, 1);
|
|
68
|
+
const adjustableQty = item?.adjustable_quantity;
|
|
69
|
+
const canAdjust = adjustableQty?.enabled !== false;
|
|
70
|
+
const minQuantity = Math.max(adjustableQty?.minimum || 1, 1);
|
|
71
|
+
const quantityAvailable = Math.min(
|
|
72
|
+
activePrice?.quantity_limit_per_checkout ?? Infinity,
|
|
73
|
+
activePrice?.quantity_available ?? Infinity
|
|
74
|
+
);
|
|
75
|
+
const maxQuantity = quantityAvailable ? Math.min(adjustableQty?.maximum || Infinity, quantityAvailable) : adjustableQty?.maximum || Infinity;
|
|
76
|
+
const { data: pendingAmount } = useRequest(
|
|
77
|
+
async () => {
|
|
78
|
+
if (!creditConfig || !userDid || !creditCurrencyId || creditCurrencyDecimal == null) return null;
|
|
79
|
+
try {
|
|
80
|
+
const { data } = await api.get("/api/meter-events/pending-amount", {
|
|
81
|
+
params: { customer_id: userDid, currency_id: creditCurrencyId }
|
|
82
|
+
});
|
|
83
|
+
return data?.[creditCurrencyId];
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{ refreshDeps: [creditConfig, userDid, creditCurrencyId, creditCurrencyDecimal] }
|
|
89
|
+
);
|
|
90
|
+
const minQtyForPending = useMemo(() => {
|
|
91
|
+
if (!pendingAmount || !creditAmount || creditAmount <= 0) return null;
|
|
92
|
+
const pendingBN = new BN(pendingAmount || "0");
|
|
93
|
+
if (!pendingBN.gt(new BN(0))) return null;
|
|
94
|
+
const creditBN = fromTokenToUnit(creditAmount, creditCurrencyDecimal);
|
|
95
|
+
if (!creditBN || creditBN.isZero()) return null;
|
|
96
|
+
return Math.ceil(pendingBN.mul(new BN(100)).div(creditBN).toNumber() / 100);
|
|
97
|
+
}, [pendingAmount, creditAmount, creditCurrencyDecimal]);
|
|
98
|
+
const hasPendingAmount = pendingAmount && new BN(pendingAmount || "0").gt(new BN(0));
|
|
99
|
+
const pendingDisplayAmount = useMemo(() => {
|
|
100
|
+
if (!hasPendingAmount) return "";
|
|
101
|
+
return formatCreditForCheckout(formatBNStr(pendingAmount, creditCurrencyDecimal), creditCurrencySymbol, locale);
|
|
102
|
+
}, [hasPendingAmount, pendingAmount, creditCurrencyDecimal, creditCurrencySymbol, locale]);
|
|
103
|
+
const minCreditsForPending = minQtyForPending ? minQtyForPending * step : 0;
|
|
104
|
+
const minCreditsForPendingFormatted = minCreditsForPending ? formatCreditForCheckout(formatNumber(minCreditsForPending), creditCurrencySymbol, locale) : "";
|
|
105
|
+
const creditInfoText = useMemo(() => {
|
|
106
|
+
if (hasSchedule && scheduleConfig) {
|
|
107
|
+
const intervalUnit = scheduleConfig.interval_unit;
|
|
108
|
+
const intervalValue = scheduleConfig.interval_value;
|
|
109
|
+
let amountPerGrant;
|
|
110
|
+
if (scheduleConfig.amount_per_grant) {
|
|
111
|
+
amountPerGrant = Number(scheduleConfig.amount_per_grant);
|
|
112
|
+
} else {
|
|
113
|
+
amountPerGrant = creditAmount;
|
|
114
|
+
}
|
|
115
|
+
const formattedAmount = formatCreditAmount(formatNumber(amountPerGrant), currencySymbol);
|
|
116
|
+
const intervalDisplay = intervalValue === 1 ? t(`common.${intervalUnit}`) : `${intervalValue} ${t(`common.${intervalUnit}s`)}`;
|
|
117
|
+
return scheduleConfig.expire_with_next_grant ? t("payment.checkout.credit.schedule.withRefresh", { amount: formattedAmount, interval: intervalDisplay }) : t("payment.checkout.credit.schedule.periodic", { amount: formattedAmount, interval: intervalDisplay });
|
|
118
|
+
}
|
|
119
|
+
return "";
|
|
120
|
+
}, [creditAmount, currencySymbol, hasSchedule, scheduleConfig, t]);
|
|
121
|
+
const validityText = useMemo(() => {
|
|
122
|
+
if (!hasExpiry) return "";
|
|
123
|
+
return t("payment.checkout.creditTopup.validFor", {
|
|
124
|
+
duration: validDuration,
|
|
125
|
+
unit: t(`common.${validDurationUnit}`)
|
|
126
|
+
});
|
|
127
|
+
}, [hasExpiry, validDuration, validDurationUnit, t]);
|
|
128
|
+
const hasSubtitle = !!creditInfoText;
|
|
129
|
+
const currentQty = item?.quantity || 1;
|
|
130
|
+
const [localQty, setLocalQty] = useState(currentQty);
|
|
131
|
+
const [desiredCredits, setDesiredCredits] = useState(currentQty * step);
|
|
132
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
133
|
+
const [editValue, setEditValue] = useState("");
|
|
134
|
+
const inputRef = useRef(null);
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (configLocked || session?.status === "complete") return;
|
|
137
|
+
if (item?.quantity && item.quantity !== localQty) {
|
|
138
|
+
setLocalQty(item.quantity);
|
|
139
|
+
setDesiredCredits(item.quantity * step);
|
|
140
|
+
}
|
|
141
|
+
}, [item?.quantity]);
|
|
142
|
+
const pendingEnforcedRef = useRef(false);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (configLocked || session?.status === "complete") return;
|
|
145
|
+
if (pendingEnforcedRef.current) return;
|
|
146
|
+
if (minQtyForPending && minQtyForPending > localQty) {
|
|
147
|
+
pendingEnforcedRef.current = true;
|
|
148
|
+
const newQty = Math.min(Math.max(minQtyForPending, minQuantity), maxQuantity);
|
|
149
|
+
setLocalQty(newQty);
|
|
150
|
+
setDesiredCredits(newQty * step);
|
|
151
|
+
if (item) lineItems.updateQuantity(item.price_id, newQty);
|
|
152
|
+
}
|
|
153
|
+
}, [minQtyForPending]);
|
|
154
|
+
const maxCredits = maxQuantity * step;
|
|
155
|
+
const minCredits = minQuantity * step;
|
|
156
|
+
const commitCredits = useCallback(
|
|
157
|
+
(credits) => {
|
|
158
|
+
if (credits <= 0) return;
|
|
159
|
+
const clamped = Math.max(minCredits, Math.min(maxCredits, credits));
|
|
160
|
+
const packs = Math.ceil(clamped / step);
|
|
161
|
+
const clampedPacks = Math.max(minQuantity, Math.min(maxQuantity, packs));
|
|
162
|
+
setLocalQty(clampedPacks);
|
|
163
|
+
setDesiredCredits(clamped);
|
|
164
|
+
if (item) lineItems.updateQuantity(item.price_id, clampedPacks);
|
|
165
|
+
},
|
|
166
|
+
[step, minQuantity, maxQuantity, minCredits, maxCredits, item, lineItems]
|
|
167
|
+
);
|
|
168
|
+
const handleStep = useCallback(
|
|
169
|
+
(delta) => {
|
|
170
|
+
const newCredits = desiredCredits + delta * step;
|
|
171
|
+
if (newCredits < step * minQuantity || Math.ceil(newCredits / step) > maxQuantity) return;
|
|
172
|
+
commitCredits(newCredits);
|
|
173
|
+
},
|
|
174
|
+
[desiredCredits, step, minQuantity, maxQuantity, commitCredits]
|
|
175
|
+
);
|
|
176
|
+
const actualPacks = Math.max(minQuantity, Math.min(maxQuantity, Math.ceil(desiredCredits / step)));
|
|
177
|
+
const actualCredits = actualPacks * step;
|
|
178
|
+
const actualCreditsFormatted = formatNumber(actualCredits, 6, true, true);
|
|
179
|
+
const desiredCreditsFormatted = formatNumber(desiredCredits, 6, true, true);
|
|
180
|
+
const showReceiveSection = canAdjust && step > 1;
|
|
181
|
+
const pendingMessage = useMemo(() => {
|
|
182
|
+
if (!hasPendingAmount) return "";
|
|
183
|
+
if (actualCredits >= minCreditsForPending) {
|
|
184
|
+
return t("payment.checkout.creditTopup.pendingEnough", {
|
|
185
|
+
pendingAmount: pendingDisplayAmount,
|
|
186
|
+
availableAmount: formatCreditForCheckout(
|
|
187
|
+
formatNumber(actualCredits - minCreditsForPending),
|
|
188
|
+
creditCurrencySymbol,
|
|
189
|
+
locale
|
|
190
|
+
)
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return t("payment.checkout.creditTopup.pendingWarning", {
|
|
194
|
+
pendingAmount: pendingDisplayAmount,
|
|
195
|
+
minCredits: minCreditsForPendingFormatted
|
|
196
|
+
});
|
|
197
|
+
}, [
|
|
198
|
+
hasPendingAmount,
|
|
199
|
+
actualCredits,
|
|
200
|
+
minCreditsForPending,
|
|
201
|
+
pendingDisplayAmount,
|
|
202
|
+
creditCurrencySymbol,
|
|
203
|
+
locale,
|
|
204
|
+
minCreditsForPendingFormatted,
|
|
205
|
+
t
|
|
206
|
+
]);
|
|
207
|
+
const startEditing = useCallback(() => {
|
|
208
|
+
if (!canAdjust) return;
|
|
209
|
+
setEditValue(String(desiredCredits));
|
|
210
|
+
setIsEditing(true);
|
|
211
|
+
setTimeout(() => inputRef.current?.select(), 0);
|
|
212
|
+
}, [canAdjust, desiredCredits]);
|
|
213
|
+
const commitEdit = useCallback(() => {
|
|
214
|
+
setIsEditing(false);
|
|
215
|
+
const parsed = parseInt(editValue.replace(/,/g, ""), 10);
|
|
216
|
+
if (!Number.isFinite(parsed) || parsed <= 0) return;
|
|
217
|
+
commitCredits(parsed);
|
|
218
|
+
}, [editValue, commitCredits]);
|
|
219
|
+
const handleEditKeyDown = useCallback(
|
|
220
|
+
(e) => {
|
|
221
|
+
if (e.key === "Enter") commitEdit();
|
|
222
|
+
else if (e.key === "Escape") setIsEditing(false);
|
|
223
|
+
},
|
|
224
|
+
[commitEdit]
|
|
225
|
+
);
|
|
226
|
+
const numberHeight = { xs: 48, md: 72 };
|
|
227
|
+
const numberFontSx = {
|
|
228
|
+
fontSize: numberHeight,
|
|
229
|
+
fontWeight: 800,
|
|
230
|
+
lineHeight: 1,
|
|
231
|
+
letterSpacing: "-0.03em"
|
|
232
|
+
};
|
|
233
|
+
const circleBtnSx = {
|
|
234
|
+
width: { xs: 40, md: 56 },
|
|
235
|
+
height: { xs: 40, md: 56 },
|
|
236
|
+
borderRadius: "50%",
|
|
237
|
+
bgcolor: "background.paper",
|
|
238
|
+
border: "1px solid",
|
|
239
|
+
borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.12)" : "divider",
|
|
240
|
+
color: "text.secondary",
|
|
241
|
+
transition: "all 0.2s ease",
|
|
242
|
+
"&:hover": {
|
|
243
|
+
borderColor: "primary.main",
|
|
244
|
+
color: "primary.main",
|
|
245
|
+
bgcolor: "background.paper"
|
|
246
|
+
},
|
|
247
|
+
"&.Mui-disabled": {
|
|
248
|
+
borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.06)" : "rgba(0,0,0,0.06)",
|
|
249
|
+
color: (theme) => theme.palette.mode === "dark" ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.12)"
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return /* @__PURE__ */ jsxs(
|
|
253
|
+
Box,
|
|
254
|
+
{
|
|
255
|
+
sx: {
|
|
256
|
+
display: "flex",
|
|
257
|
+
flexDirection: "column",
|
|
258
|
+
height: "100%"
|
|
259
|
+
},
|
|
260
|
+
children: [
|
|
261
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flex: 1, display: "flex", flexDirection: "column", justifyContent: "center" }, children: [
|
|
262
|
+
/* @__PURE__ */ jsx(ScenarioBadge, { livemode, label: tSafe(t, "payment.checkout.typeBadge.topup", "TOP-UP") }),
|
|
263
|
+
/* @__PURE__ */ jsx(
|
|
264
|
+
Typography,
|
|
265
|
+
{
|
|
266
|
+
sx: {
|
|
267
|
+
fontWeight: 800,
|
|
268
|
+
fontSize: { xs: 28, md: 48 },
|
|
269
|
+
lineHeight: 1.1,
|
|
270
|
+
letterSpacing: "-0.03em",
|
|
271
|
+
color: "text.primary",
|
|
272
|
+
mb: { xs: 0.5, md: 1 }
|
|
273
|
+
},
|
|
274
|
+
children: t("payment.checkout.creditTopup.title", { name: creditName })
|
|
275
|
+
}
|
|
276
|
+
),
|
|
277
|
+
hasSubtitle && /* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "flex-start", gap: 1, mb: { xs: 1.5, md: 2.5 } }, children: /* @__PURE__ */ jsx(
|
|
278
|
+
Typography,
|
|
279
|
+
{
|
|
280
|
+
sx: { fontSize: { xs: 13, md: 15 }, fontWeight: 500, color: "text.secondary", lineHeight: 1.5 },
|
|
281
|
+
children: creditInfoText
|
|
282
|
+
}
|
|
283
|
+
) }),
|
|
284
|
+
hasPendingAmount && /* @__PURE__ */ jsxs(
|
|
285
|
+
Stack,
|
|
286
|
+
{
|
|
287
|
+
direction: "row",
|
|
288
|
+
alignItems: "flex-start",
|
|
289
|
+
spacing: 1.5,
|
|
290
|
+
sx: {
|
|
291
|
+
mb: { xs: 1.5, md: 2.5 },
|
|
292
|
+
p: { xs: 1.5, md: 2 },
|
|
293
|
+
borderRadius: "12px",
|
|
294
|
+
bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(255,152,0,0.12)" : "rgba(255,152,0,0.08)",
|
|
295
|
+
border: "1px solid",
|
|
296
|
+
borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(255,152,0,0.25)" : "rgba(255,152,0,0.2)"
|
|
297
|
+
},
|
|
298
|
+
children: [
|
|
299
|
+
/* @__PURE__ */ jsx(WarningAmberIcon, { sx: { fontSize: 18, color: "warning.main", mt: 0.25, flexShrink: 0 } }),
|
|
300
|
+
/* @__PURE__ */ jsx(Typography, { sx: { fontSize: { xs: 12, md: 13 }, fontWeight: 600, lineHeight: 1.5, color: "text.primary" }, children: pendingMessage })
|
|
301
|
+
]
|
|
302
|
+
}
|
|
303
|
+
),
|
|
304
|
+
canAdjust ? /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", maxWidth: 480 }, children: [
|
|
305
|
+
/* @__PURE__ */ jsx(
|
|
306
|
+
Typography,
|
|
307
|
+
{
|
|
308
|
+
sx: {
|
|
309
|
+
fontSize: { xs: 14, md: 17 },
|
|
310
|
+
fontWeight: 700,
|
|
311
|
+
color: "text.secondary",
|
|
312
|
+
mt: { xs: 3, md: 5 },
|
|
313
|
+
mb: { xs: 2, md: 3 }
|
|
314
|
+
},
|
|
315
|
+
children: t("payment.checkout.creditTopup.question", { symbol: currencySymbol })
|
|
316
|
+
}
|
|
317
|
+
),
|
|
318
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: { xs: 1.5, md: 2 } }, children: [
|
|
319
|
+
/* @__PURE__ */ jsx(IconButton, { onClick: () => handleStep(-1), disabled: actualPacks <= minQuantity, sx: circleBtnSx, children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: { xs: 22, md: 28 }, fontWeight: 300, lineHeight: 1, mt: "-1px" }, children: "\u2212" }) }),
|
|
320
|
+
/* @__PURE__ */ jsxs(
|
|
321
|
+
Box,
|
|
322
|
+
{
|
|
323
|
+
sx: { flex: 1, minWidth: 0, textAlign: "center", cursor: canAdjust ? "text" : "default" },
|
|
324
|
+
onClick: startEditing,
|
|
325
|
+
children: [
|
|
326
|
+
/* @__PURE__ */ jsx(
|
|
327
|
+
Box,
|
|
328
|
+
{
|
|
329
|
+
sx: {
|
|
330
|
+
height: numberHeight,
|
|
331
|
+
display: "flex",
|
|
332
|
+
alignItems: "center",
|
|
333
|
+
justifyContent: "center"
|
|
334
|
+
},
|
|
335
|
+
children: isEditing ? /* @__PURE__ */ jsx(
|
|
336
|
+
InputBase,
|
|
337
|
+
{
|
|
338
|
+
inputRef,
|
|
339
|
+
value: editValue,
|
|
340
|
+
onChange: (e) => setEditValue(e.target.value.replace(/\D/g, "")),
|
|
341
|
+
onBlur: commitEdit,
|
|
342
|
+
onKeyDown: handleEditKeyDown,
|
|
343
|
+
autoFocus: true,
|
|
344
|
+
inputProps: { inputMode: "numeric", pattern: "[0-9]*" },
|
|
345
|
+
sx: {
|
|
346
|
+
width: "100%",
|
|
347
|
+
bgcolor: "transparent",
|
|
348
|
+
"&.Mui-focused": { bgcolor: "transparent" },
|
|
349
|
+
"& input": {
|
|
350
|
+
textAlign: "center",
|
|
351
|
+
...numberFontSx,
|
|
352
|
+
p: 0,
|
|
353
|
+
fontFamily: "inherit",
|
|
354
|
+
bgcolor: "transparent",
|
|
355
|
+
"&:focus": { bgcolor: "transparent" }
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
) : /* @__PURE__ */ jsx(Typography, { sx: { ...numberFontSx, color: "text.primary", userSelect: "none" }, children: desiredCreditsFormatted })
|
|
360
|
+
}
|
|
361
|
+
),
|
|
362
|
+
/* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "center", gap: 0.75, mt: 1 }, children: /* @__PURE__ */ jsx(
|
|
363
|
+
Typography,
|
|
364
|
+
{
|
|
365
|
+
sx: {
|
|
366
|
+
fontSize: { xs: 12, md: 14 },
|
|
367
|
+
fontWeight: 700,
|
|
368
|
+
color: "text.secondary",
|
|
369
|
+
textTransform: "uppercase",
|
|
370
|
+
letterSpacing: "0.05em"
|
|
371
|
+
},
|
|
372
|
+
children: currencySymbol
|
|
373
|
+
}
|
|
374
|
+
) })
|
|
375
|
+
]
|
|
376
|
+
}
|
|
377
|
+
),
|
|
378
|
+
/* @__PURE__ */ jsx(IconButton, { onClick: () => handleStep(1), disabled: actualPacks >= maxQuantity, sx: circleBtnSx, children: /* @__PURE__ */ jsx(Box, { component: "span", sx: { fontSize: { xs: 22, md: 28 }, fontWeight: 300, lineHeight: 1 }, children: "+" }) })
|
|
379
|
+
] }),
|
|
380
|
+
step > 1 && /* @__PURE__ */ jsx(
|
|
381
|
+
Typography,
|
|
382
|
+
{
|
|
383
|
+
sx: {
|
|
384
|
+
fontSize: 11,
|
|
385
|
+
fontWeight: 600,
|
|
386
|
+
color: "grey.500",
|
|
387
|
+
textTransform: "uppercase",
|
|
388
|
+
letterSpacing: "0.08em",
|
|
389
|
+
textAlign: "center",
|
|
390
|
+
mt: { xs: 1.5, md: 2 }
|
|
391
|
+
},
|
|
392
|
+
children: t("payment.checkout.creditTopup.increment", {
|
|
393
|
+
step: formatNumber(step, 6, true, true),
|
|
394
|
+
symbol: currencySymbol
|
|
395
|
+
})
|
|
396
|
+
}
|
|
397
|
+
),
|
|
398
|
+
showReceiveSection && /* @__PURE__ */ jsxs(
|
|
399
|
+
Box,
|
|
400
|
+
{
|
|
401
|
+
sx: {
|
|
402
|
+
display: "flex",
|
|
403
|
+
flexDirection: "column",
|
|
404
|
+
mt: { xs: 3, md: 4 },
|
|
405
|
+
borderRadius: "20px",
|
|
406
|
+
backdropFilter: "blur(12px)",
|
|
407
|
+
bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.04)",
|
|
408
|
+
border: "1px solid",
|
|
409
|
+
borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.18)" : "rgba(59,130,246,0.10)",
|
|
410
|
+
boxShadow: (theme) => theme.palette.mode === "dark" ? "0 8px 32px rgba(59,130,246,0.06)" : "0 8px 32px rgba(59,130,246,0.04)"
|
|
411
|
+
},
|
|
412
|
+
children: [
|
|
413
|
+
/* @__PURE__ */ jsxs(Box, { sx: { p: { xs: 2.5, md: 3.5 } }, children: [
|
|
414
|
+
/* @__PURE__ */ jsxs(
|
|
415
|
+
Typography,
|
|
416
|
+
{
|
|
417
|
+
sx: {
|
|
418
|
+
fontSize: { xs: 16, md: 20 },
|
|
419
|
+
fontWeight: 700,
|
|
420
|
+
color: "primary.main",
|
|
421
|
+
mb: 0.5
|
|
422
|
+
},
|
|
423
|
+
children: [
|
|
424
|
+
t("payment.checkout.creditTopup.willReceive"),
|
|
425
|
+
": ",
|
|
426
|
+
/* @__PURE__ */ jsx(Box, { component: "span", sx: { fontWeight: 800 }, children: formatCreditForCheckout(actualCreditsFormatted, currencySymbol, locale) })
|
|
427
|
+
]
|
|
428
|
+
}
|
|
429
|
+
),
|
|
430
|
+
/* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.75, mb: 0.5 }, children: [
|
|
431
|
+
/* @__PURE__ */ jsx(Inventory2OutlinedIcon, { sx: { fontSize: 16, color: "text.secondary" } }),
|
|
432
|
+
/* @__PURE__ */ jsx(Typography, { sx: { fontSize: { xs: 12, md: 14 }, fontWeight: 600, color: "text.secondary" }, children: t("payment.checkout.creditTopup.packInfo", {
|
|
433
|
+
packs: actualPacks,
|
|
434
|
+
perPack: formatNumber(step, 6, true, true)
|
|
435
|
+
}) })
|
|
436
|
+
] }),
|
|
437
|
+
/* @__PURE__ */ jsx(
|
|
438
|
+
Typography,
|
|
439
|
+
{
|
|
440
|
+
sx: {
|
|
441
|
+
fontSize: { xs: 12, md: 13 },
|
|
442
|
+
fontWeight: 500,
|
|
443
|
+
color: "grey.500"
|
|
444
|
+
},
|
|
445
|
+
children: t("payment.checkout.creditTopup.autoMatch")
|
|
446
|
+
}
|
|
447
|
+
)
|
|
448
|
+
] }),
|
|
449
|
+
validityText && /* @__PURE__ */ jsxs(
|
|
450
|
+
Box,
|
|
451
|
+
{
|
|
452
|
+
sx: {
|
|
453
|
+
display: "flex",
|
|
454
|
+
alignItems: "center",
|
|
455
|
+
gap: 0.75,
|
|
456
|
+
px: { xs: 2.5, md: 3.5 },
|
|
457
|
+
py: { xs: 1.5, md: 2 },
|
|
458
|
+
borderTop: "1px solid",
|
|
459
|
+
borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.15)" : "rgba(59,130,246,0.08)"
|
|
460
|
+
},
|
|
461
|
+
children: [
|
|
462
|
+
/* @__PURE__ */ jsx(AccessTimeOutlinedIcon, { sx: { fontSize: 14, color: "grey.500" } }),
|
|
463
|
+
/* @__PURE__ */ jsx(
|
|
464
|
+
Typography,
|
|
465
|
+
{
|
|
466
|
+
sx: {
|
|
467
|
+
fontSize: { xs: 12, md: 13 },
|
|
468
|
+
fontWeight: 500,
|
|
469
|
+
color: "grey.500"
|
|
470
|
+
},
|
|
471
|
+
children: validityText
|
|
472
|
+
}
|
|
473
|
+
)
|
|
474
|
+
]
|
|
475
|
+
}
|
|
476
|
+
)
|
|
477
|
+
]
|
|
478
|
+
}
|
|
479
|
+
),
|
|
480
|
+
!showReceiveSection && validityText && /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.75, mt: { xs: 2.5, md: 3.5 } }, children: [
|
|
481
|
+
/* @__PURE__ */ jsx(InfoOutlinedIcon, { sx: { fontSize: 14, color: "grey.500" } }),
|
|
482
|
+
/* @__PURE__ */ jsx(
|
|
483
|
+
Typography,
|
|
484
|
+
{
|
|
485
|
+
sx: {
|
|
486
|
+
fontSize: { xs: 12, md: 13 },
|
|
487
|
+
fontWeight: 500,
|
|
488
|
+
color: "grey.500"
|
|
489
|
+
},
|
|
490
|
+
children: validityText
|
|
491
|
+
}
|
|
492
|
+
)
|
|
493
|
+
] })
|
|
494
|
+
] }) : (
|
|
495
|
+
// ── Non-adjustable: show fixed credit amount in a styled card ──
|
|
496
|
+
/* @__PURE__ */ jsxs(
|
|
497
|
+
Box,
|
|
498
|
+
{
|
|
499
|
+
sx: {
|
|
500
|
+
display: "flex",
|
|
501
|
+
flexDirection: "column",
|
|
502
|
+
mt: { xs: 2, md: 3 },
|
|
503
|
+
borderRadius: "20px",
|
|
504
|
+
backdropFilter: "blur(12px)",
|
|
505
|
+
bgcolor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.08)" : "rgba(59,130,246,0.04)",
|
|
506
|
+
border: "1px solid",
|
|
507
|
+
borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.18)" : "rgba(59,130,246,0.10)",
|
|
508
|
+
boxShadow: (theme) => theme.palette.mode === "dark" ? "0 8px 32px rgba(59,130,246,0.06)" : "0 8px 32px rgba(59,130,246,0.04)"
|
|
509
|
+
},
|
|
510
|
+
children: [
|
|
511
|
+
/* @__PURE__ */ jsxs(Box, { sx: { p: { xs: 2.5, md: 3.5 } }, children: [
|
|
512
|
+
/* @__PURE__ */ jsx(
|
|
513
|
+
Typography,
|
|
514
|
+
{
|
|
515
|
+
sx: {
|
|
516
|
+
fontSize: { xs: 13, md: 14 },
|
|
517
|
+
fontWeight: 600,
|
|
518
|
+
color: "text.secondary",
|
|
519
|
+
mb: 1
|
|
520
|
+
},
|
|
521
|
+
children: t("payment.checkout.creditTopup.willReceive")
|
|
522
|
+
}
|
|
523
|
+
),
|
|
524
|
+
/* @__PURE__ */ jsx(Box, { sx: { display: "flex", alignItems: "center", gap: 1.5 }, children: /* @__PURE__ */ jsx(
|
|
525
|
+
Typography,
|
|
526
|
+
{
|
|
527
|
+
sx: {
|
|
528
|
+
fontSize: { xs: 32, md: 48 },
|
|
529
|
+
fontWeight: 800,
|
|
530
|
+
lineHeight: 1,
|
|
531
|
+
letterSpacing: "-0.03em",
|
|
532
|
+
color: "primary.main"
|
|
533
|
+
},
|
|
534
|
+
children: formatCreditForCheckout(actualCreditsFormatted, currencySymbol, locale)
|
|
535
|
+
}
|
|
536
|
+
) })
|
|
537
|
+
] }),
|
|
538
|
+
validityText && /* @__PURE__ */ jsxs(
|
|
539
|
+
Box,
|
|
540
|
+
{
|
|
541
|
+
sx: {
|
|
542
|
+
display: "flex",
|
|
543
|
+
alignItems: "center",
|
|
544
|
+
gap: 0.75,
|
|
545
|
+
px: { xs: 2.5, md: 3.5 },
|
|
546
|
+
py: { xs: 1.5, md: 2 },
|
|
547
|
+
borderTop: "1px solid",
|
|
548
|
+
borderColor: (theme) => theme.palette.mode === "dark" ? "rgba(59,130,246,0.15)" : "rgba(59,130,246,0.08)"
|
|
549
|
+
},
|
|
550
|
+
children: [
|
|
551
|
+
/* @__PURE__ */ jsx(AccessTimeOutlinedIcon, { sx: { fontSize: 14, color: "grey.500" } }),
|
|
552
|
+
/* @__PURE__ */ jsx(
|
|
553
|
+
Typography,
|
|
554
|
+
{
|
|
555
|
+
sx: {
|
|
556
|
+
fontSize: { xs: 12, md: 13 },
|
|
557
|
+
fontWeight: 500,
|
|
558
|
+
color: "grey.500"
|
|
559
|
+
},
|
|
560
|
+
children: validityText
|
|
561
|
+
}
|
|
562
|
+
)
|
|
563
|
+
]
|
|
564
|
+
}
|
|
565
|
+
)
|
|
566
|
+
]
|
|
567
|
+
}
|
|
568
|
+
)
|
|
569
|
+
)
|
|
570
|
+
] }),
|
|
571
|
+
/* @__PURE__ */ jsxs(Box, { sx: { flexShrink: 0 }, children: [
|
|
572
|
+
rate.hasDynamicPricing && rate.status === "unavailable" && !isStripe && /* @__PURE__ */ jsxs(Stack, { direction: "row", alignItems: "center", spacing: 0.75, sx: { mb: 2 }, children: [
|
|
573
|
+
/* @__PURE__ */ jsx(Typography, { sx: { fontSize: 13, color: "text.secondary", fontWeight: 500 }, children: t("payment.dynamicPricing.unavailable.title") }),
|
|
574
|
+
/* @__PURE__ */ jsx(
|
|
575
|
+
Typography,
|
|
576
|
+
{
|
|
577
|
+
component: "span",
|
|
578
|
+
onClick: rate.refresh,
|
|
579
|
+
sx: {
|
|
580
|
+
fontSize: 13,
|
|
581
|
+
color: "primary.main",
|
|
582
|
+
fontWeight: 600,
|
|
583
|
+
cursor: "pointer",
|
|
584
|
+
"&:hover": { textDecoration: "underline" }
|
|
585
|
+
},
|
|
586
|
+
children: t("payment.dynamicPricing.unavailable.retry")
|
|
587
|
+
}
|
|
588
|
+
)
|
|
589
|
+
] }),
|
|
590
|
+
/* @__PURE__ */ jsx(
|
|
591
|
+
ExchangeRateFooter,
|
|
592
|
+
{
|
|
593
|
+
hasDynamicPricing: rate.hasDynamicPricing,
|
|
594
|
+
rate: {
|
|
595
|
+
value: rate.value,
|
|
596
|
+
display: rate.display,
|
|
597
|
+
provider: rate.provider,
|
|
598
|
+
providerDisplay: rate.providerDisplay,
|
|
599
|
+
fetchedAt: rate.fetchedAt,
|
|
600
|
+
status: rate.status
|
|
601
|
+
},
|
|
602
|
+
slippage: { percent: slippage.percent, set: slippage.set },
|
|
603
|
+
currencySymbol: currency?.symbol || "",
|
|
604
|
+
isSubscription: ["subscription", "setup"].includes(session?.mode || "payment")
|
|
605
|
+
}
|
|
606
|
+
)
|
|
607
|
+
] })
|
|
608
|
+
]
|
|
609
|
+
}
|
|
610
|
+
);
|
|
611
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function ScenarioRouter(): import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSessionContext } from "@blocklet/payment-react-headless";
|
|
3
|
+
import { detectScenario } from "../../utils/scenario-detector.js";
|
|
4
|
+
import CompositePanel from "./composite-panel.js";
|
|
5
|
+
import CreditTopupPanel from "./credit-topup-panel.js";
|
|
6
|
+
const SubscriptionPanel = CompositePanel;
|
|
7
|
+
export default function ScenarioRouter() {
|
|
8
|
+
const { session, items } = useSessionContext();
|
|
9
|
+
const scenario = detectScenario(session, items);
|
|
10
|
+
switch (scenario) {
|
|
11
|
+
case "subscription":
|
|
12
|
+
return /* @__PURE__ */ jsx(SubscriptionPanel, {});
|
|
13
|
+
case "credit-topup":
|
|
14
|
+
return /* @__PURE__ */ jsx(CreditTopupPanel, {});
|
|
15
|
+
case "composite":
|
|
16
|
+
default:
|
|
17
|
+
return /* @__PURE__ */ jsx(CompositePanel, {});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function PaymentPanel(): import("react").JSX.Element;
|