payment-kit 1.19.0 → 1.19.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/api/src/crons/index.ts +8 -0
- package/api/src/index.ts +4 -0
- package/api/src/libs/credit-grant.ts +146 -0
- package/api/src/libs/env.ts +1 -0
- package/api/src/libs/invoice.ts +4 -3
- package/api/src/libs/notification/template/base.ts +388 -2
- package/api/src/libs/notification/template/customer-credit-grant-granted.ts +149 -0
- package/api/src/libs/notification/template/customer-credit-grant-low-balance.ts +151 -0
- package/api/src/libs/notification/template/customer-credit-insufficient.ts +254 -0
- package/api/src/libs/notification/template/subscription-canceled.ts +193 -202
- package/api/src/libs/notification/template/subscription-refund-succeeded.ts +215 -237
- package/api/src/libs/notification/template/subscription-renewed.ts +130 -200
- package/api/src/libs/notification/template/subscription-succeeded.ts +100 -202
- package/api/src/libs/notification/template/subscription-trial-start.ts +142 -188
- package/api/src/libs/notification/template/subscription-trial-will-end.ts +146 -174
- package/api/src/libs/notification/template/subscription-upgraded.ts +96 -192
- package/api/src/libs/notification/template/subscription-will-canceled.ts +94 -135
- package/api/src/libs/notification/template/subscription-will-renew.ts +220 -245
- package/api/src/libs/payment.ts +69 -0
- package/api/src/libs/queue/index.ts +3 -2
- package/api/src/libs/session.ts +8 -0
- package/api/src/libs/subscription.ts +74 -3
- package/api/src/libs/util.ts +3 -1
- package/api/src/libs/ws.ts +23 -1
- package/api/src/locales/en.ts +33 -0
- package/api/src/locales/zh.ts +31 -0
- package/api/src/queues/credit-consume.ts +728 -0
- package/api/src/queues/credit-grant.ts +572 -0
- package/api/src/queues/notification.ts +173 -128
- package/api/src/queues/payment.ts +210 -122
- package/api/src/queues/subscription.ts +179 -0
- package/api/src/routes/checkout-sessions.ts +157 -9
- package/api/src/routes/connect/shared.ts +3 -2
- package/api/src/routes/credit-grants.ts +241 -0
- package/api/src/routes/credit-transactions.ts +208 -0
- package/api/src/routes/customers.ts +34 -5
- package/api/src/routes/index.ts +8 -0
- package/api/src/routes/meter-events.ts +347 -0
- package/api/src/routes/meters.ts +219 -0
- package/api/src/routes/payment-currencies.ts +20 -2
- package/api/src/routes/payment-links.ts +1 -1
- package/api/src/routes/payment-methods.ts +14 -2
- package/api/src/routes/prices.ts +43 -0
- package/api/src/routes/pricing-table.ts +13 -7
- package/api/src/routes/products.ts +63 -4
- package/api/src/routes/settings.ts +1 -1
- package/api/src/routes/subscriptions.ts +4 -0
- package/api/src/routes/webhook-endpoints.ts +0 -3
- package/api/src/store/migrations/20250610-billing-credit.ts +43 -0
- package/api/src/store/models/credit-grant.ts +486 -0
- package/api/src/store/models/credit-transaction.ts +268 -0
- package/api/src/store/models/customer.ts +8 -0
- package/api/src/store/models/index.ts +52 -1
- package/api/src/store/models/meter-event.ts +423 -0
- package/api/src/store/models/meter.ts +176 -0
- package/api/src/store/models/payment-currency.ts +66 -14
- package/api/src/store/models/price.ts +6 -0
- package/api/src/store/models/product.ts +2 -2
- package/api/src/store/models/subscription.ts +24 -0
- package/api/src/store/models/types.ts +28 -2
- package/api/tests/libs/subscription.spec.ts +53 -0
- package/blocklet.yml +9 -1
- package/package.json +4 -4
- package/scripts/sdk.js +233 -1
- package/src/app.tsx +10 -0
- package/src/components/collapse.tsx +11 -1
- package/src/components/conditional-section.tsx +87 -0
- package/src/components/customer/credit-grant-item-list.tsx +99 -0
- package/src/components/customer/credit-overview.tsx +246 -0
- package/src/components/customer/form.tsx +7 -3
- package/src/components/invoice/list.tsx +19 -1
- package/src/components/metadata/form.tsx +287 -91
- package/src/components/meter/actions.tsx +101 -0
- package/src/components/meter/add-usage-dialog.tsx +239 -0
- package/src/components/meter/events-list.tsx +657 -0
- package/src/components/meter/form.tsx +245 -0
- package/src/components/meter/products.tsx +264 -0
- package/src/components/meter/usage-guide.tsx +174 -0
- package/src/components/payment-currency/form.tsx +2 -0
- package/src/components/payment-intent/list.tsx +19 -1
- package/src/components/payment-link/item.tsx +2 -2
- package/src/components/payment-link/preview.tsx +1 -1
- package/src/components/payment-link/product-select.tsx +52 -12
- package/src/components/payment-method/arcblock.tsx +2 -0
- package/src/components/payment-method/base.tsx +2 -0
- package/src/components/payment-method/bitcoin.tsx +2 -0
- package/src/components/payment-method/ethereum.tsx +2 -0
- package/src/components/payment-method/stripe.tsx +2 -0
- package/src/components/payouts/list.tsx +19 -1
- package/src/components/payouts/portal/list.tsx +6 -11
- package/src/components/price/currency-select.tsx +56 -32
- package/src/components/price/form.tsx +912 -407
- package/src/components/pricing-table/preview.tsx +1 -1
- package/src/components/product/add-price.tsx +9 -7
- package/src/components/product/create.tsx +7 -4
- package/src/components/product/edit-price.tsx +21 -12
- package/src/components/product/features.tsx +17 -7
- package/src/components/product/form.tsx +100 -90
- package/src/components/refund/list.tsx +19 -1
- package/src/components/section/header.tsx +5 -18
- package/src/components/subscription/items/index.tsx +1 -1
- package/src/components/subscription/metrics.tsx +37 -5
- package/src/components/subscription/portal/actions.tsx +2 -1
- package/src/contexts/products.tsx +26 -9
- package/src/hooks/subscription.ts +34 -0
- package/src/libs/meter-utils.ts +196 -0
- package/src/libs/util.ts +4 -0
- package/src/locales/en.tsx +389 -5
- package/src/locales/zh.tsx +368 -1
- package/src/pages/admin/billing/index.tsx +61 -33
- package/src/pages/admin/billing/invoices/detail.tsx +1 -1
- package/src/pages/admin/billing/meters/create.tsx +60 -0
- package/src/pages/admin/billing/meters/detail.tsx +435 -0
- package/src/pages/admin/billing/meters/index.tsx +210 -0
- package/src/pages/admin/billing/meters/meter-event.tsx +346 -0
- package/src/pages/admin/billing/subscriptions/detail.tsx +47 -14
- package/src/pages/admin/customers/customers/credit-grant/detail.tsx +391 -0
- package/src/pages/admin/customers/customers/detail.tsx +14 -10
- package/src/pages/admin/customers/index.tsx +5 -0
- package/src/pages/admin/developers/events/detail.tsx +1 -1
- package/src/pages/admin/developers/index.tsx +1 -1
- package/src/pages/admin/payments/intents/detail.tsx +1 -1
- package/src/pages/admin/payments/payouts/detail.tsx +1 -1
- package/src/pages/admin/payments/refunds/detail.tsx +1 -1
- package/src/pages/admin/products/index.tsx +3 -2
- package/src/pages/admin/products/links/detail.tsx +1 -1
- package/src/pages/admin/products/prices/actions.tsx +16 -4
- package/src/pages/admin/products/prices/detail.tsx +30 -3
- package/src/pages/admin/products/prices/list.tsx +8 -1
- package/src/pages/admin/products/pricing-tables/detail.tsx +1 -1
- package/src/pages/admin/products/products/create.tsx +233 -57
- package/src/pages/admin/products/products/detail.tsx +2 -1
- package/src/pages/admin/settings/payment-methods/index.tsx +3 -0
- package/src/pages/customer/credit-grant/detail.tsx +308 -0
- package/src/pages/customer/index.tsx +44 -9
- package/src/pages/customer/recharge/account.tsx +5 -5
- package/src/pages/customer/subscription/change-payment.tsx +4 -2
- package/src/pages/customer/subscription/detail.tsx +48 -14
- package/src/pages/customer/subscription/embed.tsx +1 -1
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
useDefaultPageSize,
|
|
11
11
|
} from '@blocklet/payment-react';
|
|
12
12
|
import type { TPaymentIntentExpanded } from '@blocklet/payment-types';
|
|
13
|
-
import { CircularProgress, Typography } from '@mui/material';
|
|
13
|
+
import { Avatar, CircularProgress, Typography } from '@mui/material';
|
|
14
14
|
import { useLocalStorageState } from 'ahooks';
|
|
15
15
|
import { useEffect, useState } from 'react';
|
|
16
16
|
import { Link } from 'react-router-dom';
|
|
@@ -136,6 +136,24 @@ export default function PaymentList({
|
|
|
136
136
|
},
|
|
137
137
|
},
|
|
138
138
|
},
|
|
139
|
+
{
|
|
140
|
+
label: t('common.paymentMethod'),
|
|
141
|
+
name: 'paymentMethod',
|
|
142
|
+
width: 120,
|
|
143
|
+
options: {
|
|
144
|
+
customBodyRenderLite: (_: string, index: number) => {
|
|
145
|
+
const item = data.list[index] as TPaymentIntentExpanded;
|
|
146
|
+
return (
|
|
147
|
+
<Link to={`/admin/payments/${item.id}`}>
|
|
148
|
+
<Typography sx={{ display: 'flex', alignItems: 'center', whiteSpace: 'nowrap' }}>
|
|
149
|
+
<Avatar src={item.paymentMethod.logo} sx={{ width: 18, height: 18, mr: 1 }} />
|
|
150
|
+
{item.paymentMethod.name}
|
|
151
|
+
</Typography>
|
|
152
|
+
</Link>
|
|
153
|
+
);
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
139
157
|
{
|
|
140
158
|
label: t('common.status'),
|
|
141
159
|
name: 'status',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
2
2
|
import Toast from '@arcblock/ux/lib/Toast';
|
|
3
|
-
import { api, findCurrency, formatError, formatPrice, usePaymentContext } from '@blocklet/payment-react';
|
|
3
|
+
import { api, findCurrency, formatError, formatPrice, usePaymentContext, FormLabel } from '@blocklet/payment-react';
|
|
4
4
|
import type { TPrice, TProduct, TProductExpanded } from '@blocklet/payment-types';
|
|
5
|
-
import { Box, Checkbox, FormControlLabel,
|
|
5
|
+
import { Box, Checkbox, FormControlLabel, Stack, TextField, Typography } from '@mui/material';
|
|
6
6
|
import { useSetState } from 'ahooks';
|
|
7
7
|
import { Controller, useFormContext, useWatch } from 'react-hook-form';
|
|
8
8
|
|
|
@@ -7,38 +7,68 @@ import cloneDeep from 'lodash/cloneDeep';
|
|
|
7
7
|
import { useState } from 'react';
|
|
8
8
|
import type { LiteralUnion } from 'type-fest';
|
|
9
9
|
|
|
10
|
+
import Empty from '@arcblock/ux/lib/Empty';
|
|
10
11
|
import { useProductsContext } from '../../contexts/products';
|
|
11
12
|
|
|
12
13
|
type Props = {
|
|
13
14
|
mode: LiteralUnion<'waiting' | 'selecting' | 'inline', string>;
|
|
14
15
|
hasSelected: (price: any) => boolean;
|
|
15
16
|
onSelect: (priceId: string) => void;
|
|
17
|
+
addProduct?: boolean;
|
|
18
|
+
filterPrice?: (price: any) => boolean;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
|
-
const filterPrices = (
|
|
19
|
-
product
|
|
21
|
+
const filterPrices = (
|
|
22
|
+
product: TProductExpanded,
|
|
23
|
+
hasSelected: (price: any) => boolean,
|
|
24
|
+
filterPrice?: (price: any) => boolean
|
|
25
|
+
) => {
|
|
26
|
+
product.prices = product.prices.filter((x) => {
|
|
27
|
+
const isActive = x.active;
|
|
28
|
+
const notSelected = !hasSelected(x);
|
|
29
|
+
const customFilter = filterPrice ? filterPrice(x) : true;
|
|
30
|
+
return isActive && notSelected && customFilter;
|
|
31
|
+
});
|
|
20
32
|
return product;
|
|
21
33
|
};
|
|
22
34
|
|
|
23
|
-
const filterProducts = (
|
|
24
|
-
|
|
35
|
+
const filterProducts = (
|
|
36
|
+
products: TProductExpanded[],
|
|
37
|
+
hasSelected: (price: any) => boolean,
|
|
38
|
+
filterPrice?: (price: any) => boolean
|
|
39
|
+
) => {
|
|
40
|
+
const filtered = cloneDeep(products).map((x) => filterPrices(x, hasSelected, filterPrice));
|
|
25
41
|
return filtered.filter((x) => x.prices.length);
|
|
26
42
|
};
|
|
27
43
|
|
|
28
|
-
export default function ProductSelect({
|
|
44
|
+
export default function ProductSelect({
|
|
45
|
+
mode: initialMode,
|
|
46
|
+
hasSelected,
|
|
47
|
+
onSelect,
|
|
48
|
+
addProduct = true,
|
|
49
|
+
filterPrice = () => true,
|
|
50
|
+
}: Props) {
|
|
29
51
|
const { t } = useLocaleContext();
|
|
30
52
|
const [mode, setMode] = useState(initialMode);
|
|
31
53
|
const { products } = useProductsContext();
|
|
32
54
|
const { settings } = usePaymentContext();
|
|
55
|
+
const [value, setValue] = useState('');
|
|
33
56
|
const size = { width: 16, height: 16 };
|
|
34
57
|
|
|
35
58
|
const handleSelect = (e: any) => {
|
|
59
|
+
setValue(e.target.value);
|
|
36
60
|
setMode('waiting');
|
|
37
61
|
onSelect(e.target.value);
|
|
38
62
|
};
|
|
39
63
|
|
|
40
|
-
const items = (callback?: any) =>
|
|
41
|
-
filterProducts(products, hasSelected)
|
|
64
|
+
const items = (callback?: any) => {
|
|
65
|
+
const filteredProducts = filterProducts(products, hasSelected, filterPrice);
|
|
66
|
+
|
|
67
|
+
if (filteredProducts.length === 0) {
|
|
68
|
+
return <Empty>{t('admin.product.empty')}</Empty>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return filteredProducts.map((product) => [
|
|
42
72
|
<ListSubheader key={product.id} sx={{ fontSize: '0.875rem', color: 'text.secondary', lineHeight: '2.1875rem' }}>
|
|
43
73
|
<Stack
|
|
44
74
|
direction="row"
|
|
@@ -89,6 +119,7 @@ export default function ProductSelect({ mode: initialMode, hasSelected, onSelect
|
|
|
89
119
|
);
|
|
90
120
|
}),
|
|
91
121
|
]);
|
|
122
|
+
};
|
|
92
123
|
|
|
93
124
|
if (mode === 'inline') {
|
|
94
125
|
return <>{items(onSelect)}</>;
|
|
@@ -96,11 +127,20 @@ export default function ProductSelect({ mode: initialMode, hasSelected, onSelect
|
|
|
96
127
|
|
|
97
128
|
if (mode === 'selecting') {
|
|
98
129
|
return (
|
|
99
|
-
<Select
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
130
|
+
<Select
|
|
131
|
+
fullWidth
|
|
132
|
+
size="small"
|
|
133
|
+
onChange={handleSelect}
|
|
134
|
+
value={value}
|
|
135
|
+
MenuProps={{
|
|
136
|
+
style: { maxHeight: 480 },
|
|
137
|
+
}}>
|
|
138
|
+
{addProduct && (
|
|
139
|
+
<MenuItem value="add">
|
|
140
|
+
<AddOutlined />
|
|
141
|
+
{t('admin.product.add')}
|
|
142
|
+
</MenuItem>
|
|
143
|
+
)}
|
|
104
144
|
{items()}
|
|
105
145
|
</Select>
|
|
106
146
|
);
|
|
@@ -30,6 +30,7 @@ export default function ArcBlockMethodForm({ checkDisabled }: { checkDisabled: (
|
|
|
30
30
|
label={t('admin.paymentMethod.name.label')}
|
|
31
31
|
placeholder={t('admin.paymentMethod.name.tip')}
|
|
32
32
|
disabled={checkDisabled('name')}
|
|
33
|
+
inputProps={{ maxLength: 32 }}
|
|
33
34
|
/>
|
|
34
35
|
<FormInput
|
|
35
36
|
key="description"
|
|
@@ -39,6 +40,7 @@ export default function ArcBlockMethodForm({ checkDisabled }: { checkDisabled: (
|
|
|
39
40
|
label={t('admin.paymentMethod.description.label')}
|
|
40
41
|
placeholder={t('admin.paymentMethod.description.tip')}
|
|
41
42
|
disabled={checkDisabled('description')}
|
|
43
|
+
inputProps={{ maxLength: 255 }}
|
|
42
44
|
/>
|
|
43
45
|
<FormInput
|
|
44
46
|
key="secret_key"
|
|
@@ -31,6 +31,7 @@ export default function BaseMethodForm({ checkDisabled }: { checkDisabled: (key:
|
|
|
31
31
|
label={t('admin.paymentMethod.name.label')}
|
|
32
32
|
placeholder={t('admin.paymentMethod.name.tip')}
|
|
33
33
|
disabled={checkDisabled('name')}
|
|
34
|
+
inputProps={{ maxLength: 32 }}
|
|
34
35
|
/>
|
|
35
36
|
<FormInput
|
|
36
37
|
key="description"
|
|
@@ -40,6 +41,7 @@ export default function BaseMethodForm({ checkDisabled }: { checkDisabled: (key:
|
|
|
40
41
|
label={t('admin.paymentMethod.description.label')}
|
|
41
42
|
placeholder={t('admin.paymentMethod.description.tip')}
|
|
42
43
|
disabled={checkDisabled('description')}
|
|
44
|
+
inputProps={{ maxLength: 255 }}
|
|
43
45
|
/>
|
|
44
46
|
<EvmRpcInput
|
|
45
47
|
name="settings.base.api_host"
|
|
@@ -30,6 +30,7 @@ export default function BitcoinMethodForm({ checkDisabled }: { checkDisabled: (k
|
|
|
30
30
|
label={t('admin.paymentMethod.name.label')}
|
|
31
31
|
placeholder={t('admin.paymentMethod.name.tip')}
|
|
32
32
|
disabled={checkDisabled('name')}
|
|
33
|
+
inputProps={{ maxLength: 32 }}
|
|
33
34
|
/>
|
|
34
35
|
<FormInput
|
|
35
36
|
key="description"
|
|
@@ -39,6 +40,7 @@ export default function BitcoinMethodForm({ checkDisabled }: { checkDisabled: (k
|
|
|
39
40
|
label={t('admin.paymentMethod.description.label')}
|
|
40
41
|
placeholder={t('admin.paymentMethod.description.tip')}
|
|
41
42
|
disabled={checkDisabled('description')}
|
|
43
|
+
inputProps={{ maxLength: 255 }}
|
|
42
44
|
/>
|
|
43
45
|
<FormInput
|
|
44
46
|
key="chain_id"
|
|
@@ -31,6 +31,7 @@ export default function EthereumMethodForm({ checkDisabled }: { checkDisabled: (
|
|
|
31
31
|
label={t('admin.paymentMethod.name.label')}
|
|
32
32
|
placeholder={t('admin.paymentMethod.name.tip')}
|
|
33
33
|
disabled={checkDisabled('name')}
|
|
34
|
+
inputProps={{ maxLength: 32 }}
|
|
34
35
|
/>
|
|
35
36
|
<FormInput
|
|
36
37
|
key="description"
|
|
@@ -40,6 +41,7 @@ export default function EthereumMethodForm({ checkDisabled }: { checkDisabled: (
|
|
|
40
41
|
label={t('admin.paymentMethod.description.label')}
|
|
41
42
|
placeholder={t('admin.paymentMethod.description.tip')}
|
|
42
43
|
disabled={checkDisabled('description')}
|
|
44
|
+
inputProps={{ maxLength: 255 }}
|
|
43
45
|
/>
|
|
44
46
|
<EvmRpcInput
|
|
45
47
|
name="settings.ethereum.api_host"
|
|
@@ -14,6 +14,7 @@ export default function StripeMethodForm({ checkDisabled }: { checkDisabled: (ke
|
|
|
14
14
|
label={t('admin.paymentMethod.name.label')}
|
|
15
15
|
placeholder={t('admin.paymentMethod.name.tip')}
|
|
16
16
|
disabled={checkDisabled('name')}
|
|
17
|
+
inputProps={{ maxLength: 32 }}
|
|
17
18
|
/>
|
|
18
19
|
<FormInput
|
|
19
20
|
name="description"
|
|
@@ -21,6 +22,7 @@ export default function StripeMethodForm({ checkDisabled }: { checkDisabled: (ke
|
|
|
21
22
|
rules={{ required: true }}
|
|
22
23
|
label={t('admin.paymentMethod.description.label')}
|
|
23
24
|
placeholder={t('admin.paymentMethod.description.tip')}
|
|
25
|
+
inputProps={{ maxLength: 255 }}
|
|
24
26
|
/>
|
|
25
27
|
<FormInput
|
|
26
28
|
name="settings.stripe.dashboard"
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
useDefaultPageSize,
|
|
11
11
|
} from '@blocklet/payment-react';
|
|
12
12
|
import type { TPayoutExpanded } from '@blocklet/payment-types';
|
|
13
|
-
import { CircularProgress, Typography } from '@mui/material';
|
|
13
|
+
import { Avatar, CircularProgress, Typography } from '@mui/material';
|
|
14
14
|
import { useLocalStorageState } from 'ahooks';
|
|
15
15
|
import { useEffect, useState } from 'react';
|
|
16
16
|
import { Link } from 'react-router-dom';
|
|
@@ -132,6 +132,24 @@ export default function PayoutList({
|
|
|
132
132
|
},
|
|
133
133
|
},
|
|
134
134
|
},
|
|
135
|
+
{
|
|
136
|
+
label: t('common.paymentMethod'),
|
|
137
|
+
name: 'paymentMethod',
|
|
138
|
+
width: 120,
|
|
139
|
+
options: {
|
|
140
|
+
customBodyRenderLite: (_: string, index: number) => {
|
|
141
|
+
const item = data.list[index] as TPayoutExpanded;
|
|
142
|
+
return (
|
|
143
|
+
<Link to={`/admin/payments/${item.id}`}>
|
|
144
|
+
<Typography sx={{ display: 'flex', alignItems: 'center', whiteSpace: 'nowrap' }}>
|
|
145
|
+
<Avatar src={item.paymentMethod.logo} sx={{ width: 18, height: 18, mr: 1 }} />
|
|
146
|
+
{item.paymentMethod.name}
|
|
147
|
+
</Typography>
|
|
148
|
+
</Link>
|
|
149
|
+
);
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
135
153
|
{
|
|
136
154
|
label: t('common.status'),
|
|
137
155
|
name: 'status',
|
|
@@ -10,6 +10,7 @@ import { Link } from 'react-router-dom';
|
|
|
10
10
|
import { styled } from '@mui/system';
|
|
11
11
|
import { debounce } from '../../../libs/util';
|
|
12
12
|
import CustomerLink from '../../customer/link';
|
|
13
|
+
import { useConditionalSection } from '../../conditional-section';
|
|
13
14
|
|
|
14
15
|
const fetchData = (
|
|
15
16
|
params: Record<string, any> = {}
|
|
@@ -47,7 +48,6 @@ type ListProps = {
|
|
|
47
48
|
status?: string;
|
|
48
49
|
customer_id?: string;
|
|
49
50
|
currency_id?: string;
|
|
50
|
-
setHasRevenues?: (hasRevenues: boolean) => void;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const getListKey = (props: ListProps) => {
|
|
@@ -57,14 +57,10 @@ const getListKey = (props: ListProps) => {
|
|
|
57
57
|
return 'payouts-mine';
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
export default function CustomerRevenueList({
|
|
61
|
-
currency_id = '',
|
|
62
|
-
status = '',
|
|
63
|
-
customer_id = '',
|
|
64
|
-
setHasRevenues = () => {},
|
|
65
|
-
}: ListProps) {
|
|
60
|
+
export default function CustomerRevenueList({ currency_id = '', status = '', customer_id = '' }: ListProps) {
|
|
66
61
|
const { t } = useLocaleContext();
|
|
67
62
|
const { isMobile } = useMobile('sm');
|
|
63
|
+
const conditionalSection = useConditionalSection();
|
|
68
64
|
|
|
69
65
|
const listKey = getListKey({ customer_id });
|
|
70
66
|
const defaultPageSize = useDefaultPageSize(10);
|
|
@@ -87,12 +83,11 @@ export default function CustomerRevenueList({
|
|
|
87
83
|
debounce(() => {
|
|
88
84
|
fetchData(search).then((res: any) => {
|
|
89
85
|
setData(res);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
86
|
+
const hasData = res.count > 0;
|
|
87
|
+
conditionalSection?.hideRender(!hasData);
|
|
93
88
|
});
|
|
94
89
|
}, 300)();
|
|
95
|
-
}, [search]);
|
|
90
|
+
}, [search, conditionalSection]);
|
|
96
91
|
|
|
97
92
|
const columns = [
|
|
98
93
|
{
|
|
@@ -2,7 +2,7 @@ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
|
|
|
2
2
|
import { usePaymentContext } from '@blocklet/payment-react';
|
|
3
3
|
import { AddOutlined, ArrowDropDown } from '@mui/icons-material';
|
|
4
4
|
import { ListSubheader, MenuItem, Select, Stack, SxProps, Typography } from '@mui/material';
|
|
5
|
-
import { useState } from 'react';
|
|
5
|
+
import { useState, useEffect } from 'react';
|
|
6
6
|
import type { LiteralUnion } from 'type-fest';
|
|
7
7
|
|
|
8
8
|
import { flatten } from 'lodash';
|
|
@@ -17,6 +17,8 @@ type Props = {
|
|
|
17
17
|
width?: string;
|
|
18
18
|
disabled?: boolean;
|
|
19
19
|
selectSX?: SxProps;
|
|
20
|
+
currencyFilter?: (currency: any) => boolean;
|
|
21
|
+
hideMethod?: boolean;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export default function CurrencySelect({
|
|
@@ -27,11 +29,28 @@ export default function CurrencySelect({
|
|
|
27
29
|
width = '100%',
|
|
28
30
|
disabled = false,
|
|
29
31
|
selectSX = {},
|
|
32
|
+
currencyFilter = () => true,
|
|
33
|
+
hideMethod = false,
|
|
30
34
|
}: Props) {
|
|
31
35
|
const { t } = useLocaleContext();
|
|
32
36
|
const { settings } = usePaymentContext();
|
|
33
37
|
const [mode, setMode] = useState(initialMode);
|
|
34
38
|
|
|
39
|
+
const currencies = flatten(settings.paymentMethods.map((method) => method.payment_currencies));
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (value && initialMode === 'selected' && currencies.length > 0) {
|
|
43
|
+
const currency = currencies.find((c) => c.id === value);
|
|
44
|
+
if (currency && !hasSelected(currency)) {
|
|
45
|
+
const timer = setTimeout(() => {
|
|
46
|
+
onSelect(value);
|
|
47
|
+
}, 0);
|
|
48
|
+
return () => clearTimeout(timer);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}, [value, initialMode]);
|
|
53
|
+
|
|
35
54
|
const handleSelect = (e: any) => {
|
|
36
55
|
if (disabled) {
|
|
37
56
|
return;
|
|
@@ -40,8 +59,6 @@ export default function CurrencySelect({
|
|
|
40
59
|
onSelect(e.target.value);
|
|
41
60
|
};
|
|
42
61
|
|
|
43
|
-
const currencies = flatten(settings.paymentMethods.map((method) => method.payment_currencies));
|
|
44
|
-
|
|
45
62
|
const selectedCurrency = currencies.find((x) => x.id === value);
|
|
46
63
|
|
|
47
64
|
const selectedPaymentMethod = settings.paymentMethods.find((x) => x.payment_currencies.some((c) => c.id === value));
|
|
@@ -59,11 +76,13 @@ export default function CurrencySelect({
|
|
|
59
76
|
}
|
|
60
77
|
}}
|
|
61
78
|
sx={{
|
|
62
|
-
fontSize: '12px',
|
|
63
79
|
cursor: canSelect ? 'pointer' : 'default',
|
|
64
80
|
display: 'inline-flex',
|
|
81
|
+
minWidth: '120px',
|
|
82
|
+
justifyContent: 'flex-end',
|
|
83
|
+
textAlign: 'right',
|
|
65
84
|
}}>
|
|
66
|
-
{selectedCurrency?.symbol}({selectedPaymentMethod?.name})
|
|
85
|
+
{selectedCurrency?.symbol} {hideMethod ? '' : `(${selectedPaymentMethod?.name})`}
|
|
67
86
|
{canSelect && <ArrowDropDown sx={{ color: 'text.secondary', fontSize: 21 }} />}
|
|
68
87
|
</Typography>
|
|
69
88
|
);
|
|
@@ -80,7 +99,7 @@ export default function CurrencySelect({
|
|
|
80
99
|
value={value}
|
|
81
100
|
renderValue={() => (
|
|
82
101
|
<Typography variant="body1" sx={{ display: 'inline-flex', fontSize: '12px', color: 'text.secondary' }}>
|
|
83
|
-
{selectedCurrency?.symbol} ({selectedPaymentMethod?.name})
|
|
102
|
+
{selectedCurrency?.symbol} {hideMethod ? '' : `(${selectedPaymentMethod?.name})`}
|
|
84
103
|
</Typography>
|
|
85
104
|
)}
|
|
86
105
|
onChange={handleSelect}
|
|
@@ -88,32 +107,37 @@ export default function CurrencySelect({
|
|
|
88
107
|
sx={{ width, ...selectSX }}
|
|
89
108
|
disabled={disabled}
|
|
90
109
|
onClose={() => setMode(initialMode)}>
|
|
91
|
-
{extraCurrencies
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
<
|
|
108
|
-
sx={{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
{extraCurrencies
|
|
111
|
+
.map((method) => {
|
|
112
|
+
const filteredCurrencies = method.payment_currencies.filter(currencyFilter);
|
|
113
|
+
if (filteredCurrencies.length === 0) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return [
|
|
118
|
+
hideMethod ? null : (
|
|
119
|
+
<ListSubheader
|
|
120
|
+
key={method.id}
|
|
121
|
+
sx={{ fontSize: '0.875rem', color: 'text.secondary', lineHeight: '2.1875rem' }}>
|
|
122
|
+
{method.name}
|
|
123
|
+
</ListSubheader>
|
|
124
|
+
),
|
|
125
|
+
...filteredCurrencies.map((currency) => (
|
|
126
|
+
<MenuItem key={currency.id} sx={{ pl: 3 }} value={currency.id}>
|
|
127
|
+
<Stack direction="row" sx={{ width: '100%', justifyContent: 'space-between', gap: 2 }}>
|
|
128
|
+
{hideMethod ? null : <Currency logo={currency.logo} name={currency.name} />}
|
|
129
|
+
<Typography
|
|
130
|
+
sx={{
|
|
131
|
+
fontWeight: hideMethod ? 'normal' : 'bold',
|
|
132
|
+
}}>
|
|
133
|
+
{currency.symbol}
|
|
134
|
+
</Typography>
|
|
135
|
+
</Stack>
|
|
136
|
+
</MenuItem>
|
|
137
|
+
)),
|
|
138
|
+
];
|
|
139
|
+
})
|
|
140
|
+
.filter(Boolean)}
|
|
117
141
|
</Select>
|
|
118
142
|
);
|
|
119
143
|
}
|