@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.
- package/es/contexts/payment.js +20 -5
- package/es/libs/theme.d.ts +1 -1
- package/es/payment/product-donation.js +4 -1
- package/lib/contexts/payment.js +22 -7
- package/lib/libs/theme.d.ts +1 -1
- package/lib/payment/product-donation.js +4 -1
- package/package.json +6 -6
- package/src/components/confirm.tsx +1 -1
- package/src/contexts/payment.tsx +25 -6
- package/src/payment/product-donation.tsx +3 -0
- package/src/theme/index.tsx +3 -2
package/es/contexts/payment.js
CHANGED
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
|
44
|
-
getMethod: (methodId) => getMethod(methodId, data
|
|
58
|
+
getCurrency: (currencyId) => getCurrency(currencyId, data?.paymentMethods || []),
|
|
59
|
+
getMethod: (methodId) => getMethod(methodId, data?.paymentMethods || []),
|
|
45
60
|
refresh: run,
|
|
46
61
|
setLivemode,
|
|
47
62
|
api,
|
package/es/libs/theme.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function create(settings?: any):
|
|
1
|
+
export default function create(settings?: any): import("@mui/material").Theme;
|
package/lib/contexts/payment.js
CHANGED
|
@@ -22,11 +22,26 @@ const {
|
|
|
22
22
|
Consumer
|
|
23
23
|
} = PaymentContext;
|
|
24
24
|
exports.SettingsConsumer = Consumer;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
75
|
-
getMethod: methodId => getMethod(methodId, data
|
|
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,
|
package/lib/libs/theme.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function create(settings?: any):
|
|
1
|
+
export default function create(settings?: any): import("@mui/material").Theme;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.15.
|
|
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.
|
|
57
|
-
"@arcblock/ux": "2.10.
|
|
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.
|
|
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.
|
|
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": "
|
|
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}>
|
package/src/contexts/payment.tsx
CHANGED
|
@@ -39,9 +39,28 @@ export type PaymentContextProps = {
|
|
|
39
39
|
const PaymentContext = createContext<PaymentContextType>({ api });
|
|
40
40
|
const { Provider, Consumer } = PaymentContext;
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
|
84
|
-
getMethod: (methodId: string) => getMethod(methodId, data
|
|
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,
|
package/src/theme/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
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<
|
|
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({
|