@blocklet/payment-react 1.18.0 → 1.18.2
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/donate.js +55 -10
- package/es/checkout/form.d.ts +2 -1
- package/es/checkout/form.js +32 -45
- package/es/components/payment-beneficiaries.d.ts +24 -0
- package/es/components/payment-beneficiaries.js +70 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +3 -1
- package/es/locales/en.js +13 -1
- package/es/locales/zh.js +13 -1
- package/es/payment/donation-form.d.ts +24 -0
- package/es/payment/donation-form.js +604 -0
- package/es/payment/error.d.ts +1 -1
- package/es/payment/error.js +11 -1
- package/es/payment/form/index.d.ts +9 -3
- package/es/payment/form/index.js +60 -12
- package/es/payment/product-donation.js +101 -56
- package/es/payment/skeleton/donation.d.ts +1 -0
- package/es/payment/skeleton/donation.js +30 -0
- package/es/theme/index.js +13 -0
- package/es/types/index.d.ts +2 -0
- package/lib/checkout/donate.js +85 -10
- package/lib/checkout/form.d.ts +2 -1
- package/lib/checkout/form.js +39 -49
- package/lib/components/payment-beneficiaries.d.ts +24 -0
- package/lib/components/payment-beneficiaries.js +113 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +8 -0
- package/lib/locales/en.js +13 -1
- package/lib/locales/zh.js +13 -1
- package/lib/payment/donation-form.d.ts +24 -0
- package/lib/payment/donation-form.js +645 -0
- package/lib/payment/error.d.ts +1 -1
- package/lib/payment/error.js +2 -2
- package/lib/payment/form/index.d.ts +9 -3
- package/lib/payment/form/index.js +60 -8
- package/lib/payment/product-donation.js +143 -72
- package/lib/payment/skeleton/donation.d.ts +1 -0
- package/lib/payment/skeleton/donation.js +66 -0
- package/lib/theme/index.js +13 -0
- package/lib/types/index.d.ts +2 -0
- package/package.json +3 -3
- package/src/checkout/donate.tsx +64 -11
- package/src/checkout/form.tsx +17 -31
- package/src/components/payment-beneficiaries.tsx +97 -0
- package/src/index.ts +2 -0
- package/src/locales/en.tsx +12 -0
- package/src/locales/zh.tsx +12 -0
- package/src/payment/donation-form.tsx +647 -0
- package/src/payment/error.tsx +13 -4
- package/src/payment/form/index.tsx +66 -11
- package/src/payment/product-donation.tsx +94 -39
- package/src/payment/skeleton/donation.tsx +35 -0
- package/src/theme/index.tsx +13 -0
- package/src/types/index.ts +2 -0
package/src/checkout/form.tsx
CHANGED
|
@@ -9,6 +9,7 @@ import { getPrefix, mergeExtraParams } from '../libs/util';
|
|
|
9
9
|
import Payment from '../payment';
|
|
10
10
|
import type { CheckoutContext, CheckoutProps } from '../types';
|
|
11
11
|
import { PaymentThemeProvider } from '../theme';
|
|
12
|
+
import DonationForm from '../payment/donation-form';
|
|
12
13
|
|
|
13
14
|
const promises: { [key: string]: Promise<any> } = {};
|
|
14
15
|
const startFromPaymentLink = (id: string, params?: Record<string, any>): Promise<CheckoutContext> => {
|
|
@@ -41,6 +42,7 @@ export default function CheckoutForm({
|
|
|
41
42
|
extraParams,
|
|
42
43
|
action,
|
|
43
44
|
theme = 'default',
|
|
45
|
+
formType = 'payment',
|
|
44
46
|
...restProps
|
|
45
47
|
}: CheckoutProps) {
|
|
46
48
|
if (!id.startsWith('plink_') && !id.startsWith('cs_')) {
|
|
@@ -76,9 +78,9 @@ export default function CheckoutForm({
|
|
|
76
78
|
onError?.(err);
|
|
77
79
|
};
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
<
|
|
81
|
+
const Checkout =
|
|
82
|
+
formType === 'donation' ? (
|
|
83
|
+
<DonationForm
|
|
82
84
|
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
83
85
|
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
84
86
|
paymentIntent={data?.paymentIntent}
|
|
@@ -92,34 +94,10 @@ export default function CheckoutForm({
|
|
|
92
94
|
goBack={goBack}
|
|
93
95
|
mode={mode as string}
|
|
94
96
|
action={action}
|
|
97
|
+
id={id}
|
|
95
98
|
{...restProps}
|
|
96
99
|
/>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
if (theme && typeof theme === 'object') {
|
|
100
|
-
return (
|
|
101
|
-
<PaymentThemeProvider theme={theme}>
|
|
102
|
-
<Payment
|
|
103
|
-
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
104
|
-
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
105
|
-
paymentIntent={data?.paymentIntent}
|
|
106
|
-
paymentLink={data?.paymentLink}
|
|
107
|
-
customer={data?.customer}
|
|
108
|
-
completed={state.completed}
|
|
109
|
-
error={apiError}
|
|
110
|
-
onPaid={handlePaid}
|
|
111
|
-
onError={handleError}
|
|
112
|
-
onChange={onChange}
|
|
113
|
-
goBack={goBack}
|
|
114
|
-
mode={mode as string}
|
|
115
|
-
action={action}
|
|
116
|
-
{...restProps}
|
|
117
|
-
/>
|
|
118
|
-
</PaymentThemeProvider>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
return (
|
|
122
|
-
<PaymentThemeProvider>
|
|
100
|
+
) : (
|
|
123
101
|
<Payment
|
|
124
102
|
checkoutSession={data?.checkoutSession as TCheckoutSessionExpanded}
|
|
125
103
|
paymentMethods={data?.paymentMethods as TPaymentMethodExpanded[]}
|
|
@@ -136,8 +114,15 @@ export default function CheckoutForm({
|
|
|
136
114
|
action={action}
|
|
137
115
|
{...restProps}
|
|
138
116
|
/>
|
|
139
|
-
|
|
140
|
-
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (theme === 'inherit') {
|
|
120
|
+
return Checkout;
|
|
121
|
+
}
|
|
122
|
+
if (theme && typeof theme === 'object') {
|
|
123
|
+
return <PaymentThemeProvider theme={theme}>{Checkout}</PaymentThemeProvider>;
|
|
124
|
+
}
|
|
125
|
+
return <PaymentThemeProvider>{Checkout}</PaymentThemeProvider>;
|
|
141
126
|
}
|
|
142
127
|
|
|
143
128
|
CheckoutForm.defaultProps = {
|
|
@@ -146,4 +131,5 @@ CheckoutForm.defaultProps = {
|
|
|
146
131
|
mode: 'inline',
|
|
147
132
|
action: '',
|
|
148
133
|
extraParams: {},
|
|
134
|
+
formType: 'payment',
|
|
149
135
|
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/indent */
|
|
2
|
+
import { Avatar, Box, Stack, Typography } from '@mui/material';
|
|
3
|
+
import { BN, fromUnitToToken } from '@ocap/util';
|
|
4
|
+
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
5
|
+
|
|
6
|
+
export interface TBeneficiary {
|
|
7
|
+
name: string;
|
|
8
|
+
address: string;
|
|
9
|
+
avatar?: string;
|
|
10
|
+
percent: number;
|
|
11
|
+
amount?: string;
|
|
12
|
+
url?: string;
|
|
13
|
+
type?: 'user' | 'dapp';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface BenefitsProps {
|
|
17
|
+
data: TBeneficiary[];
|
|
18
|
+
currency: {
|
|
19
|
+
symbol: string;
|
|
20
|
+
decimal: number;
|
|
21
|
+
};
|
|
22
|
+
totalAmount?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
PaymentBeneficiaries.defaultProps = {
|
|
26
|
+
totalAmount: '0',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default function PaymentBeneficiaries({ data, currency, totalAmount }: BenefitsProps) {
|
|
30
|
+
const { t } = useLocaleContext();
|
|
31
|
+
return (
|
|
32
|
+
<Stack spacing={2}>
|
|
33
|
+
<Typography variant="subtitle2" color="text.secondary">
|
|
34
|
+
{t('benefits.title', { count: data.length })}
|
|
35
|
+
</Typography>
|
|
36
|
+
|
|
37
|
+
{data.map((item) => {
|
|
38
|
+
const amount =
|
|
39
|
+
item.amount ||
|
|
40
|
+
(totalAmount
|
|
41
|
+
? new BN(totalAmount)
|
|
42
|
+
.mul(new BN(Number(item.percent)))
|
|
43
|
+
.div(new BN(100))
|
|
44
|
+
.toString()
|
|
45
|
+
: '0');
|
|
46
|
+
return (
|
|
47
|
+
<Stack
|
|
48
|
+
key={item.address}
|
|
49
|
+
direction={{ xs: 'column', sm: 'row' }}
|
|
50
|
+
alignItems="center"
|
|
51
|
+
justifyContent="space-between"
|
|
52
|
+
sx={{
|
|
53
|
+
px: 0.5,
|
|
54
|
+
borderRadius: 1,
|
|
55
|
+
bgcolor: 'background.paper',
|
|
56
|
+
'&:hover': {
|
|
57
|
+
bgcolor: 'action.hover',
|
|
58
|
+
},
|
|
59
|
+
}}>
|
|
60
|
+
<Stack direction="row" spacing={1.5} alignItems="center" sx={{ width: { xs: '100%', sm: 'auto' } }}>
|
|
61
|
+
<Avatar src={item.avatar} alt={item.name} sx={{ width: 32, height: 32 }} variant="square" />
|
|
62
|
+
<Box>
|
|
63
|
+
<Typography
|
|
64
|
+
variant="subtitle2"
|
|
65
|
+
onClick={() => {
|
|
66
|
+
if (item.url) {
|
|
67
|
+
window.open(item.url, '_blank');
|
|
68
|
+
}
|
|
69
|
+
}}
|
|
70
|
+
sx={{
|
|
71
|
+
cursor: item.url ? 'pointer' : 'default',
|
|
72
|
+
'&:hover': {
|
|
73
|
+
color: item.url ? 'text.link' : 'inherit',
|
|
74
|
+
},
|
|
75
|
+
}}>
|
|
76
|
+
{item.name}
|
|
77
|
+
</Typography>
|
|
78
|
+
<Typography variant="caption" color="text.secondary" sx={{ cursor: 'pointer' }}>
|
|
79
|
+
{item.address}
|
|
80
|
+
</Typography>
|
|
81
|
+
</Box>
|
|
82
|
+
</Stack>
|
|
83
|
+
|
|
84
|
+
<Stack alignItems="flex-end" sx={{ width: { xs: '100%', sm: 'auto' }, mt: { xs: 1, sm: 0 } }}>
|
|
85
|
+
<Typography variant="subtitle2">
|
|
86
|
+
{fromUnitToToken(amount, currency.decimal)} {currency.symbol}
|
|
87
|
+
</Typography>
|
|
88
|
+
<Typography variant="caption" color="text.secondary">
|
|
89
|
+
{Number(item.percent)}%
|
|
90
|
+
</Typography>
|
|
91
|
+
</Stack>
|
|
92
|
+
</Stack>
|
|
93
|
+
);
|
|
94
|
+
})}
|
|
95
|
+
</Stack>
|
|
96
|
+
);
|
|
97
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ import TruncatedText from './components/truncated-text';
|
|
|
29
29
|
import Link from './components/link';
|
|
30
30
|
import { createLazyComponent } from './components/lazy-loader';
|
|
31
31
|
import OverdueInvoicePayment from './components/over-due-invoice-payment';
|
|
32
|
+
import PaymentBeneficiaries from './components/payment-beneficiaries';
|
|
32
33
|
|
|
33
34
|
export { PaymentThemeProvider } from './theme';
|
|
34
35
|
|
|
@@ -75,4 +76,5 @@ export {
|
|
|
75
76
|
TruncatedText,
|
|
76
77
|
Link,
|
|
77
78
|
OverdueInvoicePayment,
|
|
79
|
+
PaymentBeneficiaries,
|
|
78
80
|
};
|
package/src/locales/en.tsx
CHANGED
|
@@ -33,6 +33,8 @@ export default flat({
|
|
|
33
33
|
upload: 'Upload',
|
|
34
34
|
change: 'Change',
|
|
35
35
|
cancel: 'Cancel',
|
|
36
|
+
close: 'Close',
|
|
37
|
+
back: 'Back',
|
|
36
38
|
every: 'every',
|
|
37
39
|
per: 'per {interval}',
|
|
38
40
|
slash: '/ {interval}',
|
|
@@ -129,6 +131,13 @@ export default flat({
|
|
|
129
131
|
select: 'Select Amount',
|
|
130
132
|
summary: '{total} supporters {totalAmount} {symbol}',
|
|
131
133
|
empty: 'No supporters yet',
|
|
134
|
+
gaveTips: '{count} people gave tips',
|
|
135
|
+
tipAmount: 'Tip Amount',
|
|
136
|
+
benefits: {
|
|
137
|
+
one: '{name} will receive all tips',
|
|
138
|
+
multiple: 'Tips will be distributed to {count} beneficiaries',
|
|
139
|
+
view: 'Click to view details',
|
|
140
|
+
},
|
|
132
141
|
},
|
|
133
142
|
cardPay: '{action} with card',
|
|
134
143
|
empty: 'No thing to pay',
|
|
@@ -363,4 +372,7 @@ export default flat({
|
|
|
363
372
|
empty: {
|
|
364
373
|
records: 'No matching records found',
|
|
365
374
|
},
|
|
375
|
+
benefits: {
|
|
376
|
+
title: '{count} Beneficiaries',
|
|
377
|
+
},
|
|
366
378
|
});
|
package/src/locales/zh.tsx
CHANGED
|
@@ -33,6 +33,8 @@ export default flat({
|
|
|
33
33
|
change: '更换',
|
|
34
34
|
confirm: '确认',
|
|
35
35
|
cancel: '取消',
|
|
36
|
+
close: '关闭',
|
|
37
|
+
back: '返回',
|
|
36
38
|
every: '每',
|
|
37
39
|
per: '每{interval}',
|
|
38
40
|
slash: '每{interval}',
|
|
@@ -128,6 +130,13 @@ export default flat({
|
|
|
128
130
|
select: '选择金额',
|
|
129
131
|
summary: '共有 {total} 人支持 {totalAmount} {symbol}',
|
|
130
132
|
empty: '❤️ 支持一下',
|
|
133
|
+
gaveTips: '已有 {count} 人打赏',
|
|
134
|
+
tipAmount: '打赏金额',
|
|
135
|
+
benefits: {
|
|
136
|
+
one: '{name} 将获得全部打赏',
|
|
137
|
+
multiple: '打赏将按比例分配给 {count} 位受益人',
|
|
138
|
+
view: '点击查看详情',
|
|
139
|
+
},
|
|
131
140
|
},
|
|
132
141
|
cardPay: '使用卡片{action}',
|
|
133
142
|
empty: '没有可支付的项目',
|
|
@@ -353,4 +362,7 @@ export default flat({
|
|
|
353
362
|
empty: {
|
|
354
363
|
records: '没有找到匹配的记录',
|
|
355
364
|
},
|
|
365
|
+
benefits: {
|
|
366
|
+
title: '{count} 位受益人',
|
|
367
|
+
},
|
|
356
368
|
});
|