@blocklet/payment-react 1.15.2 → 1.15.4
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
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/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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.4",
|
|
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.4",
|
|
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": "d1c51f0dffe33e5d42b3dc601a554df6c8f88828"
|
|
126
126
|
}
|
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,
|