payment-kit 1.18.19 → 1.18.20
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/blocklet.yml
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payment-kit",
|
|
3
|
-
"version": "1.18.
|
|
3
|
+
"version": "1.18.20",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "blocklet dev --open",
|
|
6
6
|
"eject": "vite eject",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@arcblock/validator": "^1.19.15",
|
|
54
54
|
"@blocklet/js-sdk": "^1.16.40",
|
|
55
55
|
"@blocklet/logger": "^1.16.40",
|
|
56
|
-
"@blocklet/payment-react": "1.18.
|
|
56
|
+
"@blocklet/payment-react": "1.18.20",
|
|
57
57
|
"@blocklet/sdk": "^1.16.40",
|
|
58
58
|
"@blocklet/ui-react": "^2.12.36",
|
|
59
59
|
"@blocklet/uploader": "^0.1.79",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"devDependencies": {
|
|
122
122
|
"@abtnode/types": "^1.16.40",
|
|
123
123
|
"@arcblock/eslint-config-ts": "^0.3.3",
|
|
124
|
-
"@blocklet/payment-types": "1.18.
|
|
124
|
+
"@blocklet/payment-types": "1.18.20",
|
|
125
125
|
"@types/cookie-parser": "^1.4.7",
|
|
126
126
|
"@types/cors": "^2.8.17",
|
|
127
127
|
"@types/debug": "^4.1.12",
|
|
@@ -167,5 +167,5 @@
|
|
|
167
167
|
"parser": "typescript"
|
|
168
168
|
}
|
|
169
169
|
},
|
|
170
|
-
"gitHead": "
|
|
170
|
+
"gitHead": "f71a0013f704d58e4c04ebfcc5a35480a0942bcc"
|
|
171
171
|
}
|
package/src/libs/dayjs.ts
CHANGED
|
@@ -54,8 +54,9 @@ export const formatSmartDuration = (
|
|
|
54
54
|
{ t, separator = ' ' }: FormatDurationOptions
|
|
55
55
|
): string => {
|
|
56
56
|
// Format single unit
|
|
57
|
-
const formatUnit = (val: number, unitType: TimeUnit): string =>
|
|
58
|
-
`${val} ${t(`common.${unitType}${val > 1 ? 's' : ''}`).toLowerCase()}`;
|
|
57
|
+
const formatUnit = (val: number, unitType: TimeUnit): string => {
|
|
58
|
+
return `${val || 0} ${t(`common.${unitType}${val > 1 ? 's' : ''}`).toLowerCase()}`;
|
|
59
|
+
};
|
|
59
60
|
|
|
60
61
|
// Convert to largest possible unit
|
|
61
62
|
const convertToLargest = (val: number, fromUnit: TimeUnit): [TimeUnit, number][] => {
|
|
@@ -129,7 +130,7 @@ export const formatSmartDuration = (
|
|
|
129
130
|
|
|
130
131
|
// Get units and filter out zero values
|
|
131
132
|
const units = convertToLargest(value, unit).filter(([, val]) => val > 0);
|
|
132
|
-
|
|
133
|
+
if (units.length === 0) return formatUnit(0, unit);
|
|
133
134
|
// Format all units
|
|
134
135
|
return units.map(([u, val]) => formatUnit(val, u)).join(separator);
|
|
135
136
|
};
|
|
@@ -178,7 +178,7 @@ type CardType = 'balance' | 'spent' | 'stake' | 'refund' | 'due';
|
|
|
178
178
|
|
|
179
179
|
// 定义一个统一的卡片配置
|
|
180
180
|
const CARD_CONFIG: Record<CardType, { key: keyof typeof summaryKeyMap; alwaysShow?: boolean }> = {
|
|
181
|
-
balance: { key: 'token'
|
|
181
|
+
balance: { key: 'token' },
|
|
182
182
|
spent: { key: 'paid', alwaysShow: true },
|
|
183
183
|
stake: { key: 'stake' },
|
|
184
184
|
refund: { key: 'refund' },
|
|
@@ -194,16 +194,22 @@ const summaryKeyMap = {
|
|
|
194
194
|
due: 'due',
|
|
195
195
|
} as const;
|
|
196
196
|
|
|
197
|
-
|
|
198
|
-
const
|
|
197
|
+
const isCardVisible = (type: string, config: any, data: any, currency: any, method: any) => {
|
|
198
|
+
const summaryKey = config.key;
|
|
199
|
+
const hasSummaryValue =
|
|
200
|
+
data?.summary?.[summaryKey]?.[currency.id] && data?.summary?.[summaryKey]?.[currency.id] !== '0';
|
|
201
|
+
|
|
202
|
+
if (type === 'balance') {
|
|
203
|
+
return method?.type === 'arcblock' && (config.alwaysShow || hasSummaryValue);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return config.alwaysShow || hasSummaryValue;
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const getCardVisibility = (currency: any, data: any, method: any) => {
|
|
199
210
|
return Object.entries(CARD_CONFIG).reduce(
|
|
200
211
|
(acc, [type, config]) => {
|
|
201
|
-
|
|
202
|
-
const isVisible =
|
|
203
|
-
config.alwaysShow ||
|
|
204
|
-
(data?.summary?.[summaryKey]?.[currency.id] && data?.summary?.[summaryKey]?.[currency.id] !== '0');
|
|
205
|
-
|
|
206
|
-
if (isVisible) {
|
|
212
|
+
if (isCardVisible(type, config, data, currency, method)) {
|
|
207
213
|
acc.visibleCards.push(type as CardType);
|
|
208
214
|
}
|
|
209
215
|
return acc;
|
|
@@ -213,9 +219,10 @@ const getCardVisibility = (currency: any, data: any) => {
|
|
|
213
219
|
};
|
|
214
220
|
|
|
215
221
|
// 计算最大卡片数量
|
|
216
|
-
const calculateMaxCardCount = (currencies: any[], data: any) => {
|
|
222
|
+
const calculateMaxCardCount = (currencies: any[], data: any, settings: any) => {
|
|
217
223
|
return currencies.reduce((maxCount, currency) => {
|
|
218
|
-
const
|
|
224
|
+
const method = settings?.paymentMethods?.find((m: any) => m.id === currency.payment_method_id);
|
|
225
|
+
const { visibleCards } = getCardVisibility(currency, data, method);
|
|
219
226
|
return Math.max(maxCount, visibleCards.length);
|
|
220
227
|
}, 0);
|
|
221
228
|
};
|
|
@@ -378,7 +385,7 @@ export default function CustomerHome() {
|
|
|
378
385
|
</Box>
|
|
379
386
|
);
|
|
380
387
|
|
|
381
|
-
const maxCardCount = calculateMaxCardCount(currencies, data);
|
|
388
|
+
const maxCardCount = calculateMaxCardCount(currencies, data, settings);
|
|
382
389
|
|
|
383
390
|
const responsiveColumns = {
|
|
384
391
|
xs: Math.min(2, maxCardCount),
|
|
@@ -397,6 +404,10 @@ export default function CustomerHome() {
|
|
|
397
404
|
</Box>
|
|
398
405
|
<Stack gap={2} mt={2}>
|
|
399
406
|
{currencies.map((c) => {
|
|
407
|
+
const method = settings?.paymentMethods?.find((m) => m.id === c.payment_method_id);
|
|
408
|
+
if (method?.type !== 'arcblock') {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
400
411
|
return isSummaryEmpty(data?.summary, c.id) && c.id !== settings.baseCurrency.id ? null : (
|
|
401
412
|
<Stack
|
|
402
413
|
key={c.id}
|
|
@@ -444,12 +455,9 @@ export default function CustomerHome() {
|
|
|
444
455
|
}}>
|
|
445
456
|
{/* 使用配置渲染卡片 */}
|
|
446
457
|
{Object.entries(CARD_CONFIG).map(([type, config]) => {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
(data?.summary?.[summaryKey]?.[c.id] && data?.summary?.[summaryKey]?.[c.id] !== '0');
|
|
451
|
-
|
|
452
|
-
if (!isVisible) return null;
|
|
458
|
+
if (!isCardVisible(type, config, data, c, method)) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
453
461
|
|
|
454
462
|
return (
|
|
455
463
|
<Box
|
|
@@ -467,7 +475,6 @@ export default function CustomerHome() {
|
|
|
467
475
|
backgroundColor: 'var(--stroke-border-base, #EFF1F5)',
|
|
468
476
|
zIndex: 1,
|
|
469
477
|
},
|
|
470
|
-
|
|
471
478
|
'&:has(+ .placeholder)::after': {
|
|
472
479
|
display: 'none',
|
|
473
480
|
},
|
|
@@ -477,7 +484,7 @@ export default function CustomerHome() {
|
|
|
477
484
|
}}>
|
|
478
485
|
<CurrencyCard
|
|
479
486
|
label={t(`admin.customer.summary.${type}`)}
|
|
480
|
-
data={data?.summary?.[
|
|
487
|
+
data={data?.summary?.[config.key] || emptyObject}
|
|
481
488
|
currency={c}
|
|
482
489
|
type={type as CardType}
|
|
483
490
|
icon={getCardIcon(type as CardType)}
|
|
@@ -83,6 +83,15 @@ export default function BalanceRechargePage() {
|
|
|
83
83
|
const [loading, setLoading] = useState(true);
|
|
84
84
|
const [error, setError] = useState('');
|
|
85
85
|
const customInputRef = useRef<HTMLInputElement>(null);
|
|
86
|
+
const [unitCycle, setUnitCycle] = useState<{
|
|
87
|
+
amount: string;
|
|
88
|
+
interval: TimeUnit;
|
|
89
|
+
cycle: number;
|
|
90
|
+
}>({
|
|
91
|
+
amount: '0',
|
|
92
|
+
interval: 'month',
|
|
93
|
+
cycle: 1,
|
|
94
|
+
});
|
|
86
95
|
const [payerValue, setPayerValue] = useState<{
|
|
87
96
|
paymentAddress: string;
|
|
88
97
|
token: string;
|
|
@@ -108,9 +117,14 @@ export default function BalanceRechargePage() {
|
|
|
108
117
|
setCurrency(data.currency);
|
|
109
118
|
setRelatedSubscriptions(data.relatedSubscriptions || []);
|
|
110
119
|
|
|
111
|
-
if (data.recommendedRecharge && data.recommendedRecharge.amount) {
|
|
120
|
+
if (data.recommendedRecharge && data.recommendedRecharge.amount && data.recommendedRecharge.amount !== '0') {
|
|
112
121
|
const baseAmount = data.recommendedRecharge.amount;
|
|
113
122
|
const decimal = data.currency.decimal || 0;
|
|
123
|
+
setUnitCycle({
|
|
124
|
+
amount: parseFloat(formatBNStr(baseAmount, decimal, 6, true)).toString(),
|
|
125
|
+
interval: data.recommendedRecharge.interval as TimeUnit,
|
|
126
|
+
cycle: data.recommendedRecharge.cycle,
|
|
127
|
+
});
|
|
114
128
|
setPresetAmounts([
|
|
115
129
|
{
|
|
116
130
|
amount: Math.ceil(parseFloat(formatBNStr(baseAmount, decimal, 6, true))).toString(),
|
|
@@ -494,6 +508,19 @@ export default function BalanceRechargePage() {
|
|
|
494
508
|
}}
|
|
495
509
|
inputRef={customInputRef}
|
|
496
510
|
/>
|
|
511
|
+
{amount && Number(amount) > 0 && Number(unitCycle.amount) > 0 && !amountError && (
|
|
512
|
+
<Typography variant="body2" sx={{ color: 'text.lighter', mt: 1 }} fontSize={12}>
|
|
513
|
+
{t('common.estimatedDuration', {
|
|
514
|
+
duration: formatSmartDuration(
|
|
515
|
+
Math.floor(Number(amount) / Number(unitCycle.amount)) < 1
|
|
516
|
+
? parseFloat((Number(amount) / Number(unitCycle.amount)).toFixed(1))
|
|
517
|
+
: Math.floor(Number(amount) / Number(unitCycle.amount)),
|
|
518
|
+
unitCycle.interval,
|
|
519
|
+
{ t }
|
|
520
|
+
),
|
|
521
|
+
})}
|
|
522
|
+
</Typography>
|
|
523
|
+
)}
|
|
497
524
|
</Box>
|
|
498
525
|
)}
|
|
499
526
|
|
|
@@ -479,7 +479,11 @@ export default function RechargePage() {
|
|
|
479
479
|
/>
|
|
480
480
|
{amount && Number(amount) > 0 && Number(cycleAmount) > 0 && !amountError && (
|
|
481
481
|
<Typography variant="body2" sx={{ color: 'text.lighter', mt: '8px !important' }} fontSize={12}>
|
|
482
|
-
{formatEstimatedDuration(
|
|
482
|
+
{formatEstimatedDuration(
|
|
483
|
+
Math.floor(Number(amount) / Number(cycleAmount)) < 1
|
|
484
|
+
? parseFloat((Number(amount) / Number(cycleAmount)).toFixed(1))
|
|
485
|
+
: Math.floor(Number(amount) / Number(cycleAmount))
|
|
486
|
+
)}
|
|
483
487
|
</Typography>
|
|
484
488
|
)}
|
|
485
489
|
</Box>
|