@blocklet/payment-react 1.15.4 → 1.15.6

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.
@@ -64,6 +64,7 @@ type Props = {
64
64
  target?: string;
65
65
  action?: string;
66
66
  type?: 'list' | 'table';
67
+ onTableDataChange?: Function;
67
68
  };
68
69
 
69
70
  const getInvoiceLink = (invoice: TInvoiceExpanded, action?: string) => {
@@ -97,6 +98,7 @@ const InvoiceTable = React.memo((props: Props & { onPay: (invoiceId: string) =>
97
98
  subscription_id,
98
99
  include_staking,
99
100
  include_recovered_from,
101
+ onTableDataChange,
100
102
  } = props;
101
103
  const listKey = 'invoice-table';
102
104
  const { t, locale } = useLocaleContext();
@@ -105,7 +107,11 @@ const InvoiceTable = React.memo((props: Props & { onPay: (invoiceId: string) =>
105
107
  pageSize: pageSize || 10,
106
108
  page: 1,
107
109
  });
108
- const { loading, data = { list: [], count: 0 } } = useRequest(
110
+ const {
111
+ loading,
112
+ data = { list: [], count: 0 },
113
+ refresh,
114
+ } = useRequest(
109
115
  () =>
110
116
  fetchData({
111
117
  ...search,
@@ -121,6 +127,26 @@ const InvoiceTable = React.memo((props: Props & { onPay: (invoiceId: string) =>
121
127
  refreshDeps: [search],
122
128
  }
123
129
  );
130
+ useEffect(() => {
131
+ if (onTableDataChange) {
132
+ onTableDataChange(data);
133
+ }
134
+ // eslint-disable-next-line react-hooks/exhaustive-deps
135
+ }, [data]);
136
+
137
+ const subscription = useSubscription('events');
138
+
139
+ useEffect(() => {
140
+ if (subscription && customer_id) {
141
+ subscription.on('invoice.paid', ({ response }: { response: TInvoiceExpanded }) => {
142
+ if (response.customer_id === customer_id) {
143
+ Toast.success(t('payment.customer.invoice.paySuccess'));
144
+ refresh();
145
+ }
146
+ });
147
+ }
148
+ // eslint-disable-next-line react-hooks/exhaustive-deps
149
+ }, [subscription]);
124
150
 
125
151
  const columns = [
126
152
  {
@@ -284,6 +310,7 @@ const InvoiceList = React.memo((props: Props & { onPay: (invoiceId: string) => v
284
310
  target,
285
311
  action,
286
312
  onPay,
313
+ onTableDataChange,
287
314
  } = props;
288
315
  const size = pageSize || 10;
289
316
 
@@ -310,11 +337,19 @@ const InvoiceList = React.memo((props: Props & { onPay: (invoiceId: string) => v
310
337
  }
311
338
  );
312
339
 
340
+ useEffect(() => {
341
+ if (onTableDataChange) {
342
+ onTableDataChange(data);
343
+ }
344
+ // eslint-disable-next-line react-hooks/exhaustive-deps
345
+ }, [data]);
346
+
313
347
  // Listen to invoice.paid event and refresh data
314
348
  useEffect(() => {
315
349
  if (subscription && customer_id) {
316
350
  subscription.on('invoice.paid', async ({ response }: { response: TInvoiceExpanded }) => {
317
351
  if (response.customer_id === customer_id) {
352
+ Toast.success(t('payment.customer.invoice.paySuccess'));
318
353
  await reloadAsync();
319
354
  }
320
355
  });
@@ -497,6 +532,7 @@ CustomerInvoiceList.defaultProps = {
497
532
  target: '_self',
498
533
  action: '',
499
534
  type: 'list',
535
+ onTableDataChange: () => {},
500
536
  };
501
537
 
502
538
  const Root = styled(Stack)`
package/src/libs/util.ts CHANGED
@@ -1089,5 +1089,6 @@ export function getCustomerAvatar(
1089
1089
  updated_at: string | number | undefined,
1090
1090
  imageSize: number = 48
1091
1091
  ): string {
1092
- return `/.well-known/service/user/avatar/${did}?imageFilter=resize&w=${imageSize}&h=${imageSize}&updateAt=${updated_at || dayjs().unix()}`;
1092
+ const updated = typeof updated_at === 'number' ? updated_at : dayjs(updated_at).unix();
1093
+ return `/.well-known/service/user/avatar/${did}?imageFilter=resize&w=${imageSize}&h=${imageSize}&updateAt=${updated || dayjs().unix()}`;
1093
1094
  }
@@ -308,9 +308,6 @@ export default function Payment({
308
308
  if (checkoutSession) {
309
309
  if (livemode !== checkoutSession.livemode) {
310
310
  setLivemode(checkoutSession.livemode);
311
- setTimeout(() => {
312
- refresh();
313
- }, 10);
314
311
  }
315
312
  }
316
313
  }, [checkoutSession, livemode, setLivemode, refresh]);
@@ -1,4 +1,4 @@
1
- import { Avatar, Stack, Typography } from '@mui/material';
1
+ import { Avatar, Box, Stack, Typography } from '@mui/material';
2
2
  import type { LiteralUnion } from 'type-fest';
3
3
 
4
4
  type Props = {
@@ -47,9 +47,9 @@ export default function ProductCard({ size, variant, name, logo, description, ex
47
47
  </Typography>
48
48
  )}
49
49
  {extra && (
50
- <Typography variant="body1" sx={{ fontSize: '0.85rem' }} color="text.lighter">
50
+ <Box sx={{ fontSize: '0.85rem' }} color="text.lighter">
51
51
  {extra}
52
- </Typography>
52
+ </Box>
53
53
  )}
54
54
  </Stack>
55
55
  </Stack>