@blocklet/payment-react 1.15.1 → 1.15.3

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.
@@ -6,9 +6,24 @@ import api from "../libs/api.js";
6
6
  import { getPrefix } from "../libs/util.js";
7
7
  const PaymentContext = createContext({ api });
8
8
  const { Provider, Consumer } = PaymentContext;
9
- const getSettings = async () => {
10
- const { data } = await api.get("/api/settings");
11
- return data;
9
+ let settingsPromise = null;
10
+ const getSettings = () => {
11
+ const cacheKey = `payment-settings-${window.location.pathname}`;
12
+ const cachedData = sessionStorage.getItem(cacheKey);
13
+ if (cachedData) {
14
+ return JSON.parse(cachedData);
15
+ }
16
+ if (!settingsPromise) {
17
+ settingsPromise = api.get("/api/settings").then(({ data }) => {
18
+ sessionStorage.setItem(cacheKey, JSON.stringify(data));
19
+ return data;
20
+ }).catch((error) => {
21
+ throw error;
22
+ }).finally(() => {
23
+ settingsPromise = null;
24
+ });
25
+ }
26
+ return settingsPromise;
12
27
  };
13
28
  const getCurrency = (currencyId, methods) => {
14
29
  const currencies = methods.reduce((acc, x) => acc.concat(x.payment_currencies), []);
@@ -40,8 +55,8 @@ function PaymentProvider({ session, connect, children, baseUrl }) {
40
55
  prefix,
41
56
  livemode: !!livemode,
42
57
  settings: data,
43
- getCurrency: (currencyId) => getCurrency(currencyId, data.paymentMethods),
44
- getMethod: (methodId) => getMethod(methodId, data.paymentMethods),
58
+ getCurrency: (currencyId) => getCurrency(currencyId, data?.paymentMethods || []),
59
+ getMethod: (methodId) => getMethod(methodId, data?.paymentMethods || []),
45
60
  refresh: run,
46
61
  setLivemode,
47
62
  api,
@@ -1 +1 @@
1
- export default function create(settings?: any): any;
1
+ export default function create(settings?: any): import("@mui/material").Theme;
@@ -117,7 +117,10 @@ export default function ProductDonation({
117
117
  margin: "none",
118
118
  fullWidth: true,
119
119
  error: !!state.error,
120
- helperText: state.error
120
+ helperText: state.error,
121
+ sx: {
122
+ mt: preset !== "0" ? 0 : 1
123
+ }
121
124
  }
122
125
  )
123
126
  ] });
@@ -22,11 +22,26 @@ const {
22
22
  Consumer
23
23
  } = PaymentContext;
24
24
  exports.SettingsConsumer = Consumer;
25
- const getSettings = async () => {
26
- const {
27
- data
28
- } = await _api.default.get("/api/settings");
29
- return data;
25
+ let settingsPromise = null;
26
+ const getSettings = () => {
27
+ const cacheKey = `payment-settings-${window.location.pathname}`;
28
+ const cachedData = sessionStorage.getItem(cacheKey);
29
+ if (cachedData) {
30
+ return JSON.parse(cachedData);
31
+ }
32
+ if (!settingsPromise) {
33
+ settingsPromise = _api.default.get("/api/settings").then(({
34
+ data
35
+ }) => {
36
+ sessionStorage.setItem(cacheKey, JSON.stringify(data));
37
+ return data;
38
+ }).catch(error => {
39
+ throw error;
40
+ }).finally(() => {
41
+ settingsPromise = null;
42
+ });
43
+ }
44
+ return settingsPromise;
30
45
  };
31
46
  const getCurrency = (currencyId, methods) => {
32
47
  const currencies = methods.reduce((acc, x) => acc.concat(x.payment_currencies), []);
@@ -71,8 +86,8 @@ function PaymentProvider({
71
86
  prefix,
72
87
  livemode: !!livemode,
73
88
  settings: data,
74
- getCurrency: currencyId => getCurrency(currencyId, data.paymentMethods),
75
- getMethod: methodId => getMethod(methodId, data.paymentMethods),
89
+ getCurrency: currencyId => getCurrency(currencyId, data?.paymentMethods || []),
90
+ getMethod: methodId => getMethod(methodId, data?.paymentMethods || []),
76
91
  refresh: run,
77
92
  setLivemode,
78
93
  api: _api.default,
@@ -1 +1 @@
1
- export default function create(settings?: any): any;
1
+ export default function create(settings?: any): import("@mui/material").Theme;
@@ -187,7 +187,10 @@ function ProductDonation({
187
187
  margin: "none",
188
188
  fullWidth: true,
189
189
  error: !!state.error,
190
- helperText: state.error
190
+ helperText: state.error,
191
+ sx: {
192
+ mt: preset !== "0" ? 0 : 1
193
+ }
191
194
  })]
192
195
  });
193
196
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.15.1",
3
+ "version": "1.15.3",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -53,10 +53,10 @@
53
53
  }
54
54
  },
55
55
  "dependencies": {
56
- "@arcblock/did-connect": "^2.10.25",
57
- "@arcblock/ux": "2.10.24",
56
+ "@arcblock/did-connect": "^2.10.30",
57
+ "@arcblock/ux": "^2.10.30",
58
58
  "@arcblock/ws": "^1.18.135",
59
- "@blocklet/ui-react": "^2.10.25",
59
+ "@blocklet/ui-react": "^2.10.30",
60
60
  "@mui/icons-material": "^5.16.6",
61
61
  "@mui/lab": "^5.0.0-alpha.173",
62
62
  "@mui/material": "^5.16.6",
@@ -92,7 +92,7 @@
92
92
  "@babel/core": "^7.25.2",
93
93
  "@babel/preset-env": "^7.25.2",
94
94
  "@babel/preset-react": "^7.24.7",
95
- "@blocklet/payment-types": "1.15.1",
95
+ "@blocklet/payment-types": "1.15.3",
96
96
  "@storybook/addon-essentials": "^7.6.20",
97
97
  "@storybook/addon-interactions": "^7.6.20",
98
98
  "@storybook/addon-links": "^7.6.20",
@@ -122,5 +122,5 @@
122
122
  "vite-plugin-babel": "^1.2.0",
123
123
  "vite-plugin-node-polyfills": "^0.21.0"
124
124
  },
125
- "gitHead": "ff06b03c0e25d6c4d9ea8f5495592c4f5c20829b"
125
+ "gitHead": "e9841f27db3993526f7871e2a0118d89c6958470"
126
126
  }
@@ -32,7 +32,7 @@ export default function ConfirmDialog({
32
32
  onCancel={onCancel}
33
33
  confirmButton={{
34
34
  text: confirm || t('common.confirm'),
35
- props: { color, size: 'small', variant: 'contained', disabled: !!loading },
35
+ props: { color: color as any, size: 'small', variant: 'contained', disabled: !!loading },
36
36
  }}
37
37
  cancelButton={{ text: cancel || t('common.cancel'), props: { color: 'inherit', size: 'small' } }}
38
38
  showCancelButton={typeof cancel !== 'boolean' || !!cancel}>
@@ -39,9 +39,28 @@ export type PaymentContextProps = {
39
39
  const PaymentContext = createContext<PaymentContextType>({ api });
40
40
  const { Provider, Consumer } = PaymentContext;
41
41
 
42
- const getSettings = async () => {
43
- const { data } = await api.get('/api/settings');
44
- return data;
42
+ let settingsPromise: Promise<any> | null = null;
43
+ const getSettings = () => {
44
+ const cacheKey = `payment-settings-${window.location.pathname}`;
45
+ const cachedData = sessionStorage.getItem(cacheKey);
46
+ if (cachedData) {
47
+ return JSON.parse(cachedData);
48
+ }
49
+ if (!settingsPromise) {
50
+ settingsPromise = api
51
+ .get('/api/settings')
52
+ .then(({ data }) => {
53
+ sessionStorage.setItem(cacheKey, JSON.stringify(data));
54
+ return data;
55
+ })
56
+ .catch((error) => {
57
+ throw error;
58
+ })
59
+ .finally(() => {
60
+ settingsPromise = null;
61
+ });
62
+ }
63
+ return settingsPromise;
45
64
  };
46
65
 
47
66
  const getCurrency = (currencyId: string, methods: TPaymentMethodExpanded[]) => {
@@ -79,9 +98,9 @@ function PaymentProvider({ session, connect, children, baseUrl }: PaymentContext
79
98
  connect,
80
99
  prefix,
81
100
  livemode: !!livemode,
82
- settings: data,
83
- getCurrency: (currencyId: string) => getCurrency(currencyId, data.paymentMethods),
84
- getMethod: (methodId: string) => getMethod(methodId, data.paymentMethods),
101
+ settings: data as Settings,
102
+ getCurrency: (currencyId: string) => getCurrency(currencyId, (data as Settings)?.paymentMethods || []),
103
+ getMethod: (methodId: string) => getMethod(methodId, (data as Settings)?.paymentMethods || []),
85
104
  refresh: run,
86
105
  setLivemode,
87
106
  api,
@@ -132,6 +132,9 @@ export default function ProductDonation({
132
132
  fullWidth
133
133
  error={!!state.error}
134
134
  helperText={state.error}
135
+ sx={{
136
+ mt: preset !== '0' ? 0 : 1,
137
+ }}
135
138
  />
136
139
  )}
137
140
  </Box>
@@ -1,4 +1,4 @@
1
- import { type ThemeOptions, ThemeProvider, useTheme } from '@mui/material/styles';
1
+ import { type Theme, ThemeProvider, useTheme } from '@mui/material/styles';
2
2
  import { create } from '@arcblock/ux/lib/Theme';
3
3
  import { cloneDeep, merge } from 'lodash';
4
4
  import { Box, CssBaseline } from '@mui/material';
@@ -26,7 +26,7 @@ export function PaymentThemeProvider({
26
26
  const parentTheme = useTheme();
27
27
  const rootStyle = getComputedStyle(document.documentElement);
28
28
 
29
- const themeOverrides: Partial<ThemeOptions> = {
29
+ const themeOverrides: Partial<Theme> = {
30
30
  shape: {
31
31
  borderRadius: 8,
32
32
  },
@@ -242,6 +242,7 @@ export function PaymentThemeProvider({
242
242
  },
243
243
  },
244
244
  };
245
+
245
246
  const mergeTheme = create(
246
247
  merge(
247
248
  cloneDeep({