@blocklet/payment-react 1.14.21 → 1.14.23

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.
Files changed (137) hide show
  1. package/README.md +77 -0
  2. package/es/checkout/donate.d.ts +4 -2
  3. package/es/checkout/donate.js +13 -10
  4. package/es/checkout/form.d.ts +1 -1
  5. package/es/checkout/form.js +50 -4
  6. package/es/checkout/table.d.ts +1 -1
  7. package/es/checkout/table.js +11 -1
  8. package/es/components/blockchain/tx.js +2 -1
  9. package/es/components/country-select.d.ts +16 -0
  10. package/es/components/country-select.js +82 -0
  11. package/es/components/input.d.ts +21 -21
  12. package/es/components/input.js +43 -42
  13. package/es/components/livemode.js +1 -0
  14. package/es/components/pricing-table.js +0 -2
  15. package/es/components/status.js +2 -3
  16. package/es/components/table.d.ts +2 -0
  17. package/es/components/table.js +186 -0
  18. package/es/contexts/payment.d.ts +2 -0
  19. package/es/contexts/payment.js +5 -2
  20. package/es/history/invoice/list.d.ts +3 -1
  21. package/es/history/invoice/list.js +215 -48
  22. package/es/hooks/mobile.d.ts +4 -0
  23. package/es/hooks/mobile.js +10 -0
  24. package/es/index.d.ts +5 -1
  25. package/es/index.js +7 -1
  26. package/es/libs/util.d.ts +21 -8
  27. package/es/libs/util.js +92 -28
  28. package/es/locales/en.js +22 -7
  29. package/es/locales/index.d.ts +0 -1
  30. package/es/locales/index.js +10 -1
  31. package/es/locales/zh.js +21 -6
  32. package/es/payment/error.js +2 -2
  33. package/es/payment/footer.js +1 -1
  34. package/es/payment/form/address.d.ts +9 -2
  35. package/es/payment/form/address.js +69 -69
  36. package/es/payment/form/currency.js +39 -25
  37. package/es/payment/form/index.d.ts +1 -1
  38. package/es/payment/form/index.js +83 -81
  39. package/es/payment/form/phone.js +15 -51
  40. package/es/payment/index.d.ts +3 -10
  41. package/es/payment/index.js +295 -224
  42. package/es/payment/product-card.js +4 -4
  43. package/es/payment/product-donation.js +9 -3
  44. package/es/payment/product-item.d.ts +2 -2
  45. package/es/payment/product-item.js +120 -81
  46. package/es/payment/summary.js +188 -118
  47. package/es/theme/index.css +240 -0
  48. package/es/theme/index.d.ts +14 -0
  49. package/es/theme/index.js +256 -0
  50. package/es/theme/typography.d.ts +2 -0
  51. package/es/theme/typography.js +53 -0
  52. package/es/types/index.d.ts +16 -0
  53. package/lib/checkout/donate.d.ts +4 -2
  54. package/lib/checkout/donate.js +23 -2
  55. package/lib/checkout/form.d.ts +1 -1
  56. package/lib/checkout/form.js +60 -15
  57. package/lib/checkout/table.d.ts +1 -1
  58. package/lib/checkout/table.js +22 -1
  59. package/lib/components/blockchain/tx.js +4 -1
  60. package/lib/components/country-select.d.ts +16 -0
  61. package/lib/components/country-select.js +115 -0
  62. package/lib/components/input.d.ts +21 -21
  63. package/lib/components/input.js +21 -12
  64. package/lib/components/livemode.js +1 -0
  65. package/lib/components/pricing-table.js +0 -2
  66. package/lib/components/status.js +2 -3
  67. package/lib/components/table.d.ts +2 -0
  68. package/lib/components/table.js +220 -0
  69. package/lib/contexts/payment.d.ts +2 -0
  70. package/lib/contexts/payment.js +4 -1
  71. package/lib/history/invoice/list.d.ts +3 -1
  72. package/lib/history/invoice/list.js +290 -62
  73. package/lib/hooks/mobile.d.ts +4 -0
  74. package/lib/hooks/mobile.js +17 -0
  75. package/lib/index.d.ts +5 -1
  76. package/lib/index.js +36 -0
  77. package/lib/libs/util.d.ts +21 -8
  78. package/lib/libs/util.js +115 -37
  79. package/lib/locales/en.js +22 -7
  80. package/lib/locales/index.d.ts +0 -1
  81. package/lib/locales/index.js +14 -3
  82. package/lib/locales/zh.js +21 -6
  83. package/lib/payment/error.js +5 -1
  84. package/lib/payment/footer.js +1 -1
  85. package/lib/payment/form/address.d.ts +9 -2
  86. package/lib/payment/form/address.js +67 -59
  87. package/lib/payment/form/currency.js +31 -24
  88. package/lib/payment/form/index.d.ts +1 -1
  89. package/lib/payment/form/index.js +92 -93
  90. package/lib/payment/form/phone.js +11 -59
  91. package/lib/payment/index.d.ts +3 -10
  92. package/lib/payment/index.js +302 -225
  93. package/lib/payment/product-card.js +5 -4
  94. package/lib/payment/product-donation.js +11 -7
  95. package/lib/payment/product-item.d.ts +2 -2
  96. package/lib/payment/product-item.js +38 -19
  97. package/lib/payment/summary.js +219 -127
  98. package/lib/theme/index.css +240 -0
  99. package/lib/theme/index.d.ts +14 -0
  100. package/lib/theme/index.js +273 -0
  101. package/lib/theme/typography.d.ts +2 -0
  102. package/lib/theme/typography.js +59 -0
  103. package/lib/types/index.d.ts +16 -0
  104. package/package.json +14 -11
  105. package/src/checkout/donate.tsx +25 -11
  106. package/src/checkout/form.tsx +63 -15
  107. package/src/checkout/table.tsx +20 -1
  108. package/src/components/blockchain/tx.tsx +2 -1
  109. package/src/components/country-select.tsx +93 -0
  110. package/src/components/input.tsx +49 -46
  111. package/src/components/livemode.tsx +1 -0
  112. package/src/components/pricing-table.tsx +0 -2
  113. package/src/components/status.tsx +1 -2
  114. package/src/components/table.tsx +200 -0
  115. package/src/contexts/payment.tsx +6 -1
  116. package/src/history/invoice/list.tsx +254 -49
  117. package/src/hooks/mobile.ts +13 -0
  118. package/src/index.ts +7 -0
  119. package/src/libs/util.ts +120 -31
  120. package/src/locales/en.tsx +18 -4
  121. package/src/locales/index.tsx +10 -3
  122. package/src/locales/zh.tsx +17 -3
  123. package/src/payment/error.tsx +2 -2
  124. package/src/payment/footer.tsx +1 -1
  125. package/src/payment/form/address.tsx +56 -47
  126. package/src/payment/form/currency.tsx +29 -23
  127. package/src/payment/form/index.tsx +89 -76
  128. package/src/payment/form/phone.tsx +14 -51
  129. package/src/payment/index.tsx +298 -231
  130. package/src/payment/product-card.tsx +4 -4
  131. package/src/payment/product-donation.tsx +9 -4
  132. package/src/payment/product-item.tsx +49 -20
  133. package/src/payment/summary.tsx +191 -108
  134. package/src/theme/index.css +240 -0
  135. package/src/theme/index.tsx +271 -0
  136. package/src/theme/typography.ts +56 -0
  137. package/src/types/index.ts +17 -0
@@ -0,0 +1,200 @@
1
+ /* eslint-disable @typescript-eslint/indent */
2
+ import React from 'react';
3
+ import Empty from '@arcblock/ux/lib/Empty';
4
+ import Datatable from '@arcblock/ux/lib/Datatable';
5
+ import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
6
+ import { styled } from '@mui/system';
7
+
8
+ import { useMobile } from '../hooks/mobile';
9
+
10
+ function EmptyStub() {
11
+ return null;
12
+ }
13
+
14
+ const Table = React.memo(
15
+ ({ options, columns, toolbar = true, footer = true, hasRowLink = false, emptyNodeText = '', ...rest }: any) => {
16
+ const { locale, t } = useLocaleContext();
17
+ const { isMobile } = useMobile();
18
+
19
+ const defaultOptions = {
20
+ print: false,
21
+ download: false,
22
+ filter: false,
23
+ selectableRows: 'none',
24
+ rowsPerPage: 10,
25
+ rowsPerPageOptions: [10, 20, 50, 100],
26
+ searchDebounceTime: 300,
27
+ tableBodyHeight: '100%',
28
+ loading: true,
29
+ };
30
+
31
+ const components: any = {};
32
+ if (!toolbar) {
33
+ components.TableToolbar = EmptyStub;
34
+ }
35
+ if (!footer) {
36
+ components.TableFooter = EmptyStub;
37
+ }
38
+
39
+ // components.TableHead = EmptyStub2
40
+ return (
41
+ <Wrapped
42
+ locale={locale}
43
+ options={{ ...defaultOptions, ...options }}
44
+ columns={columns.map((x: any) => {
45
+ x.options = x.options || {};
46
+ x.options.filter = x.options.filter || false;
47
+ x.options.sort = x.options.sort || false;
48
+ return x;
49
+ })}
50
+ emptyNode={<Empty>{emptyNodeText || t('empty.records')}</Empty>}
51
+ {...rest}
52
+ components={components}
53
+ hasRowLink={hasRowLink}
54
+ isMobile={isMobile}
55
+ />
56
+ );
57
+ }
58
+ );
59
+
60
+ const Wrapped = styled(Datatable)`
61
+ ${(props) =>
62
+ props.hasRowLink
63
+ ? `.MuiTableCell-root {
64
+ font-size: 1rem !important;
65
+ }`
66
+ : ''}
67
+ .MuiPaper-root {
68
+ border-radius: 8px;
69
+ overflow: hidden;
70
+ }
71
+ table.MuiTable-root {
72
+ outline: 1px solid var(--stroke-border-base, #eff1f5);
73
+ border-radius: var(--radius-m, 8px);
74
+ overflow: hidden;
75
+ }
76
+ [class*='MUIDataTable-responsiveBase'] {
77
+ outline: 1px solid var(--stroke-border-base, #eff1f5);
78
+ border-radius: var(--radius-m, 8px);
79
+ }
80
+
81
+ th.MuiTableCell-head {
82
+ padding: 8px 16px 8px 16px;
83
+ text-transform: inherit;
84
+ background: var(--backgrounds-bg-subtle, #f9fafb);
85
+ border-bottom: none;
86
+ &:first-of-type {
87
+ border-top-left-radius: 8px;
88
+ padding-left: 20px;
89
+ }
90
+ &:last-of-type {
91
+ border-top-right-radius: 8px;
92
+ }
93
+ }
94
+
95
+ tr.MuiTableRow-root:not(.MuiTableRow-footer):hover {
96
+ background: #f5f5f5;
97
+ }
98
+ tr.MuiTableRow-root:last-of-type td:first-of-type {
99
+ border-bottom-left-radius: 8px;
100
+ }
101
+
102
+ tr.MuiTableRow-root:last-of-type td:last-of-type {
103
+ border-bottom-right-radius: 8px;
104
+ }
105
+
106
+ tr.MuiTableRow-root:nth-of-type(even) {
107
+ background: var(--backgrounds-bg-subtle, #f9fafb);
108
+ }
109
+ td.MuiTableCell-root {
110
+ border-bottom: none;
111
+ &:first-of-type {
112
+ padding-left: 20px;
113
+ }
114
+ &.MuiTableCell-footer {
115
+ border: none;
116
+ }
117
+ }
118
+
119
+ .datatable-footer {
120
+ .MuiTableRow-root.MuiTableRow-footer {
121
+ border: none;
122
+ }
123
+ table.MuiTable-root {
124
+ outline: none;
125
+ overflow: hidden;
126
+ }
127
+ .MuiTablePagination-input {
128
+ background: none;
129
+ }
130
+ div.MuiSelect-select {
131
+ padding: 0 24px 0 0;
132
+ }
133
+ }
134
+
135
+ th a,
136
+ td a {
137
+ text-decoration: none;
138
+ display: block;
139
+ color: inherit;
140
+ &:first-of-type {
141
+ padding-left: 0;
142
+ }
143
+ }
144
+
145
+ > div {
146
+ overflow: auto;
147
+ }
148
+ @media (max-width: ${({ theme }) => theme.breakpoints.values.md}px) {
149
+ th a,
150
+ td a {
151
+ text-decoration: none;
152
+ display: block;
153
+ color: inherit;
154
+ padding-top: 0;
155
+ padding-bottom: 0;
156
+ padding-right: 0;
157
+ }
158
+ tr.MuiTableRow-root {
159
+ border: none;
160
+ padding: 20px;
161
+ display: block;
162
+ }
163
+ td.MuiTableCell-root:first-of-type {
164
+ padding-left: 0;
165
+ margin-top: 0;
166
+ }
167
+ td.MuiTableCell-root {
168
+ margin: 0;
169
+ margin-top: 8px;
170
+ align-items: center;
171
+ padding: 0;
172
+ flex-wrap: wrap;
173
+ flex-direction: ${({ mobileTDFlexDirection = 'column' }) => mobileTDFlexDirection || 'row'};
174
+ align-items: ${({ mobileTDFlexDirection = 'column' }) =>
175
+ mobileTDFlexDirection === 'column' ? 'flex-start' : 'center'};
176
+ justify-content: ${({ mobileTDFlexDirection = 'column' }) =>
177
+ mobileTDFlexDirection === 'column' ? 'flex-start' : 'space-between'};
178
+ }
179
+ td.MuiTableCell-root > div {
180
+ margin-bottom: 4px;
181
+ }
182
+ .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > td.MuiTableCell-root {
183
+ display: flex;
184
+ flex-direction: ${({ mobileTDFlexDirection = 'column' }) => mobileTDFlexDirection || 'row'};
185
+ align-items: flex-start;
186
+ justify-content: ${({ mobileTDFlexDirection = 'column' }) =>
187
+ mobileTDFlexDirection === 'row' ? 'space-between' : 'flex-start'};
188
+ flex-wrap: ${({ mobileTDFlexDirection = 'column' }) => (mobileTDFlexDirection === 'row' ? 'nowrap' : 'wrap')};
189
+ word-break: break-all;
190
+ &.datatables-noprint {
191
+ justify-content: center;
192
+ }
193
+ }
194
+ [class*='MUIDataTable-responsiveBase'] tr:not([class*='responsiveSimple']) td.MuiTableCell-body > div {
195
+ width: inherit;
196
+ }
197
+ }
198
+ `;
199
+
200
+ export default Table;
@@ -2,7 +2,7 @@ import type { TPaymentCurrency, TPaymentMethodExpanded } from '@blocklet/payment
2
2
  import { Alert } from '@mui/material';
3
3
  import { useLocalStorageState, useRequest } from 'ahooks';
4
4
  import type { Axios } from 'axios';
5
- import { createContext, useContext } from 'react';
5
+ import { createContext, useContext, useState } from 'react';
6
6
 
7
7
  import api from '../libs/api';
8
8
  import { getPrefix } from '../libs/util';
@@ -23,6 +23,8 @@ export type PaymentContextType = {
23
23
  getMethod: (methodId: string) => TPaymentMethodExpanded | undefined;
24
24
  setLivemode: (livemode: boolean) => void;
25
25
  api: Axios;
26
+ payable: boolean;
27
+ setPayable: (status: boolean) => void;
26
28
  };
27
29
 
28
30
  export type PaymentContextProps = {
@@ -60,6 +62,7 @@ function PaymentProvider({ session, connect, children, baseUrl }: PaymentContext
60
62
  const { data, error, run, loading } = useRequest(getSettings);
61
63
  const [livemode, setLivemode] = useLocalStorageState('livemode', { defaultValue: true });
62
64
  const prefix = getPrefix();
65
+ const [payable, setPayable] = useState(true);
63
66
 
64
67
  if (error) {
65
68
  return <Alert severity="error">{error.message}</Alert>;
@@ -82,6 +85,8 @@ function PaymentProvider({ session, connect, children, baseUrl }: PaymentContext
82
85
  refresh: run,
83
86
  setLivemode,
84
87
  api,
88
+ payable,
89
+ setPayable,
85
90
  }}>
86
91
  {children}
87
92
  </Provider>
@@ -1,3 +1,7 @@
1
+ /* eslint-disable @typescript-eslint/indent */
2
+ /* eslint-disable react/require-default-props */
3
+ /* eslint-disable react/no-unused-prop-types */
4
+ /* eslint-disable @typescript-eslint/naming-convention */
1
5
  /* eslint-disable no-nested-ternary */
2
6
  /* eslint-disable react/no-unstable-nested-components */
3
7
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
@@ -6,8 +10,8 @@ import type { Paginated, TInvoiceExpanded, TSubscription } from '@blocklet/payme
6
10
  import { OpenInNewOutlined } from '@mui/icons-material';
7
11
  import { Box, Button, CircularProgress, Hidden, Stack, Typography } from '@mui/material';
8
12
  import { styled } from '@mui/system';
9
- import { useInfiniteScroll, useSetState } from 'ahooks';
10
- import { useEffect } from 'react';
13
+ import { useInfiniteScroll, useRequest, useSetState } from 'ahooks';
14
+ import React, { useEffect, useState } from 'react';
11
15
  import { joinURL } from 'ufo';
12
16
 
13
17
  import Status from '../../components/status';
@@ -23,6 +27,7 @@ import {
23
27
  getPrefix,
24
28
  getTxLink,
25
29
  } from '../../libs/util';
30
+ import Table from '../../components/table';
26
31
 
27
32
  type Result = Paginated<TInvoiceExpanded> & { subscription: TSubscription };
28
33
 
@@ -58,6 +63,7 @@ type Props = {
58
63
  pageSize?: number;
59
64
  target?: string;
60
65
  action?: string;
66
+ type?: 'list' | 'table';
61
67
  };
62
68
 
63
69
  const getInvoiceLink = (invoice: TInvoiceExpanded, action?: string) => {
@@ -79,23 +85,210 @@ const getInvoiceLink = (invoice: TInvoiceExpanded, action?: string) => {
79
85
  };
80
86
  };
81
87
 
82
- export default function CustomerInvoiceList({
83
- customer_id,
84
- subscription_id,
85
- currency_id,
86
- include_staking,
87
- include_recovered_from,
88
- status,
89
- pageSize,
90
- target,
91
- action,
92
- }: Props) {
88
+ const InvoiceTable = React.memo((props: Props & { onPay: (invoiceId: string) => void }) => {
89
+ const {
90
+ pageSize,
91
+ target,
92
+ action,
93
+ onPay,
94
+ status,
95
+ customer_id,
96
+ currency_id,
97
+ subscription_id,
98
+ include_staking,
99
+ include_recovered_from,
100
+ } = props;
101
+ const listKey = 'invoice-table';
102
+ const { t, locale } = useLocaleContext();
103
+
104
+ const [search, setSearch] = useState<{ pageSize: number; page: number }>({
105
+ pageSize: pageSize || 10,
106
+ page: 1,
107
+ });
108
+ const { loading, data = { list: [], count: 0 } } = useRequest(
109
+ () =>
110
+ fetchData({
111
+ ...search,
112
+ status,
113
+ customer_id,
114
+ currency_id,
115
+ subscription_id,
116
+ include_staking,
117
+ include_recovered_from,
118
+ ignore_zero: true,
119
+ }),
120
+ {
121
+ refreshDeps: [search],
122
+ }
123
+ );
124
+
125
+ const columns = [
126
+ {
127
+ label: t('payment.customer.invoice.invoiceNumber'),
128
+ name: 'number',
129
+ options: {
130
+ customBodyRenderLite: (_: string, index: number) => {
131
+ const invoice = data?.list[index] as TInvoiceExpanded;
132
+ const link = getInvoiceLink(invoice, action);
133
+ return (
134
+ <a href={link.url} target={link.external ? '_blank' : target} rel="noreferrer">
135
+ {invoice?.number}
136
+ </a>
137
+ );
138
+ },
139
+ },
140
+ },
141
+ {
142
+ label: t('common.amount'),
143
+ name: 'total',
144
+ options: {
145
+ customBodyRenderLite: (_: string, index: number) => {
146
+ const invoice = data?.list[index] as TInvoiceExpanded;
147
+ const link = getInvoiceLink(invoice, action);
148
+ return (
149
+ <a href={link.url} target={link.external ? '_blank' : target} rel="noreferrer">
150
+ <Typography>
151
+ {formatBNStr(invoice.total, invoice.paymentCurrency.decimal)}&nbsp;
152
+ {invoice.paymentCurrency.symbol}
153
+ </Typography>
154
+ </a>
155
+ );
156
+ },
157
+ },
158
+ },
159
+
160
+ {
161
+ label: t('common.updatedAt'),
162
+ name: 'name',
163
+ options: {
164
+ customBodyRenderLite: (val: string, index: number) => {
165
+ const invoice = data?.list[index] as TInvoiceExpanded;
166
+ const link = getInvoiceLink(invoice, action);
167
+ return (
168
+ <a href={link.url} target={link.external ? '_blank' : target} rel="noreferrer">
169
+ {formatToDate(invoice.created_at, locale, 'YYYY-MM-DD HH:mm:ss')}
170
+ </a>
171
+ );
172
+ },
173
+ },
174
+ },
175
+ {
176
+ label: t('common.description'),
177
+ name: '',
178
+ options: {
179
+ sort: false,
180
+ customBodyRenderLite: (val: string, index: number) => {
181
+ const invoice = data?.list[index] as TInvoiceExpanded;
182
+ const link = getInvoiceLink(invoice, action);
183
+ return (
184
+ <a href={link.url} target={link.external ? '_blank' : target} rel="noreferrer">
185
+ {invoice.description || invoice.id}
186
+ </a>
187
+ );
188
+ },
189
+ },
190
+ },
191
+ {
192
+ label: t('common.status'),
193
+ name: 'created_at',
194
+ options: {
195
+ sort: true,
196
+ customBodyRenderLite: (val: string, index: number) => {
197
+ const invoice = data?.list[index] as TInvoiceExpanded;
198
+ const link = getInvoiceLink(invoice, action);
199
+ if (action) {
200
+ return link.connect ? (
201
+ <Button variant="text" size="small" onClick={() => onPay(invoice.id)} sx={{ color: 'text.link' }}>
202
+ {t('payment.customer.invoice.pay')}
203
+ </Button>
204
+ ) : (
205
+ <Button
206
+ component="a"
207
+ variant="text"
208
+ size="small"
209
+ href={link.url}
210
+ target={link.external ? '_blank' : target}
211
+ sx={{ color: 'var(--foregrounds-fg-interactive, #0086FF) !important' }}
212
+ rel="noreferrer">
213
+ {t('payment.customer.invoice.pay')}
214
+ </Button>
215
+ );
216
+ }
217
+ return (
218
+ <a href={link.url} target={link.external ? '_blank' : target} rel="noreferrer">
219
+ <Status label={invoice.status} color={getInvoiceStatusColor(invoice.status)} />
220
+ </a>
221
+ );
222
+ },
223
+ },
224
+ },
225
+ ];
226
+
227
+ const onTableChange = ({ page, rowsPerPage }: any) => {
228
+ if (search.pageSize !== rowsPerPage) {
229
+ setSearch((x) => ({ ...x, pageSize: rowsPerPage, page: 1 }));
230
+ } else if (search.page !== page + 1) {
231
+ setSearch((x) => ({ ...x, page: page + 1 }));
232
+ }
233
+ };
234
+
235
+ return (
236
+ <InvoiceTableRoot>
237
+ <Table
238
+ hasRowLink
239
+ durable={`__${listKey}__`}
240
+ durableKeys={['page', 'rowsPerPage', 'searchText']}
241
+ data={data.list}
242
+ columns={columns}
243
+ options={{
244
+ count: data.count,
245
+ page: search.page - 1,
246
+ rowsPerPage: search.pageSize,
247
+ }}
248
+ loading={loading}
249
+ onChange={onTableChange}
250
+ toolbar={false}
251
+ sx={{ mt: 2 }}
252
+ showMobile={false}
253
+ mobileTDFlexDirection="row"
254
+ emptyNodeText={t('payment.customer.invoice.emptyList')}
255
+ />
256
+ </InvoiceTableRoot>
257
+ );
258
+ });
259
+
260
+ const InvoiceTableRoot = styled(Box)`
261
+ @media (max-width: ${({ theme }) => theme.breakpoints.values.md}px) {
262
+ .MuiTable-root > .MuiTableBody-root > .MuiTableRow-root > td.MuiTableCell-root {
263
+ > div {
264
+ width: fit-content;
265
+ flex: inherit;
266
+ font-size: 14px;
267
+ }
268
+ }
269
+ .invoice-summary {
270
+ padding-right: 20px;
271
+ }
272
+ }
273
+ `;
274
+
275
+ const InvoiceList = React.memo((props: Props & { onPay: (invoiceId: string) => void }) => {
276
+ const {
277
+ customer_id,
278
+ subscription_id,
279
+ include_recovered_from,
280
+ currency_id,
281
+ include_staking,
282
+ status,
283
+ pageSize,
284
+ target,
285
+ action,
286
+ onPay,
287
+ } = props;
93
288
  const size = pageSize || 10;
94
289
 
95
290
  const subscription = useSubscription('events');
96
291
  const { t, locale } = useLocaleContext();
97
- const { connect } = usePaymentContext();
98
- const [state, setState] = useSetState({ paying: '' });
99
292
 
100
293
  const { data, loadMore, loadingMore, loading, reloadAsync } = useInfiniteScroll<Result>(
101
294
  (d) => {
@@ -128,38 +321,6 @@ export default function CustomerInvoiceList({
128
321
  }
129
322
  }, [subscription]); // eslint-disable-line react-hooks/exhaustive-deps
130
323
 
131
- const onPay = (invoiceId: string) => {
132
- if (state.paying) {
133
- return;
134
- }
135
-
136
- setState({ paying: invoiceId });
137
- connect.open({
138
- action: 'collect',
139
- saveConnect: false,
140
- messages: {
141
- scan: '',
142
- title: t(`payment.customer.invoice.${action || 'pay'}`),
143
- success: t(`payment.customer.invoice.${action || 'pay'}Success`),
144
- error: t(`payment.customer.invoice.${action || 'pay'}Error`),
145
- confirm: '',
146
- } as any,
147
- extraParams: { invoiceId, action },
148
- onSuccess: () => {
149
- connect.close();
150
- setState({ paying: '' });
151
- },
152
- onClose: () => {
153
- connect.close();
154
- setState({ paying: '' });
155
- },
156
- onError: (err: any) => {
157
- setState({ paying: '' });
158
- Toast.error(formatError(err));
159
- },
160
- });
161
- };
162
-
163
324
  if (loading || !data) {
164
325
  return <CircularProgress />;
165
326
  }
@@ -241,7 +402,6 @@ export default function CustomerInvoiceList({
241
402
  <Button
242
403
  component="a"
243
404
  variant="contained"
244
- color="primary"
245
405
  size="small"
246
406
  href={link.url}
247
407
  target={link.external ? '_blank' : target}
@@ -274,6 +434,50 @@ export default function CustomerInvoiceList({
274
434
  </Box>
275
435
  </Root>
276
436
  );
437
+ });
438
+
439
+ export default function CustomerInvoiceList(props: Props) {
440
+ const { action, type } = props;
441
+ const { t } = useLocaleContext();
442
+ const { connect } = usePaymentContext();
443
+ const [state, setState] = useSetState({ paying: '' });
444
+
445
+ const onPay = (invoiceId: string) => {
446
+ if (state.paying) {
447
+ return;
448
+ }
449
+
450
+ setState({ paying: invoiceId });
451
+ connect.open({
452
+ action: 'collect',
453
+ saveConnect: false,
454
+ messages: {
455
+ scan: '',
456
+ title: t(`payment.customer.invoice.${action || 'pay'}`),
457
+ success: t(`payment.customer.invoice.${action || 'pay'}Success`),
458
+ error: t(`payment.customer.invoice.${action || 'pay'}Error`),
459
+ confirm: '',
460
+ } as any,
461
+ extraParams: { invoiceId, action },
462
+ onSuccess: () => {
463
+ connect.close();
464
+ setState({ paying: '' });
465
+ },
466
+ onClose: () => {
467
+ connect.close();
468
+ setState({ paying: '' });
469
+ },
470
+ onError: (err: any) => {
471
+ setState({ paying: '' });
472
+ Toast.error(formatError(err));
473
+ },
474
+ });
475
+ };
476
+
477
+ if (type === 'table') {
478
+ return <InvoiceTable {...props} onPay={onPay} />;
479
+ }
480
+ return <InvoiceList {...props} onPay={onPay} />;
277
481
  }
278
482
 
279
483
  CustomerInvoiceList.defaultProps = {
@@ -286,10 +490,11 @@ CustomerInvoiceList.defaultProps = {
286
490
  pageSize: 10,
287
491
  target: '_self',
288
492
  action: '',
493
+ type: 'list',
289
494
  };
290
495
 
291
496
  const Root = styled(Stack)`
292
- @media (max-width: 600px) {
497
+ @media (max-width: ${({ theme }) => theme.breakpoints.values.md}px) {
293
498
  .invoice-description {
294
499
  display: none !important;
295
500
  }
@@ -0,0 +1,13 @@
1
+ import { useTheme } from '@mui/material/styles';
2
+ import useMediaQuery from '@mui/material/useMediaQuery';
3
+
4
+ const MOBILE_POINT = 'md';
5
+
6
+ export function useMobile(mobilePoint: 'md' | 'sm' | 'lg' | 'xl' | 'xs' = MOBILE_POINT) {
7
+ const theme = useTheme();
8
+
9
+ return {
10
+ isMobile: useMediaQuery(theme.breakpoints.down(mobilePoint)),
11
+ mobileSize: `${theme.breakpoints.values[mobilePoint]}px`,
12
+ };
13
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import ConfirmDialog from './components/confirm';
7
7
  import FormInput from './components/input';
8
8
  import Livemode from './components/livemode';
9
9
  import PricingTable from './components/pricing-table';
10
+ import Table from './components/table';
10
11
  import SafeGuard from './components/safe-guard';
11
12
  import Status from './components/status';
12
13
  import Switch from './components/switch-button';
@@ -23,11 +24,15 @@ import Payment from './payment/index';
23
24
  import ProductSkeleton from './payment/product-skeleton';
24
25
  import PaymentSummary from './payment/summary';
25
26
  import PricingItem from './components/pricing-item';
27
+ import CountrySelect from './components/country-select';
28
+
29
+ export { PaymentThemeProvider } from './theme';
26
30
 
27
31
  export * from './libs/util';
28
32
  export * from './libs/connect';
29
33
  export * from './contexts/payment';
30
34
  export * from './hooks/subscription';
35
+ export * from './hooks/mobile';
31
36
 
32
37
  export { translations, createTranslator } from './locales';
33
38
 
@@ -57,4 +62,6 @@ export {
57
62
  TxGas,
58
63
  SafeGuard,
59
64
  PricingItem,
65
+ CountrySelect,
66
+ Table,
60
67
  };