@blocklet/payment-react 1.16.10 → 1.16.12
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/README.md +2 -1
- package/es/checkout/donate.d.ts +1 -1
- package/es/checkout/donate.js +7 -5
- package/lib/checkout/donate.d.ts +1 -1
- package/lib/checkout/donate.js +6 -5
- package/package.json +3 -3
- package/src/checkout/donate.tsx +13 -6
package/README.md
CHANGED
|
@@ -213,8 +213,9 @@ import { CheckoutDonate } from '@blocklet/payment-react';
|
|
|
213
213
|
// ... other settings
|
|
214
214
|
}}
|
|
215
215
|
>
|
|
216
|
-
{(openDonate, totalAmount, supporters) => (
|
|
216
|
+
{(openDonate, totalAmount, supporters, loading) => (
|
|
217
217
|
<div>
|
|
218
|
+
{loading && <div>Loading...</div>}
|
|
218
219
|
<button onClick={openDonate}>
|
|
219
220
|
Support Us
|
|
220
221
|
</button>
|
package/es/checkout/donate.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
|
21
21
|
button?: ButtonType;
|
|
22
22
|
};
|
|
23
23
|
theme?: 'default' | 'inherit' | PaymentThemeOptions;
|
|
24
|
-
children?: (openDialog: () => void, donateTotalAmount: string, supporters: DonateHistory) => React.ReactNode;
|
|
24
|
+
children?: (openDialog: () => void, donateTotalAmount: string, supporters: DonateHistory, loading?: boolean) => React.ReactNode;
|
|
25
25
|
};
|
|
26
26
|
declare function CheckoutDonate(props: DonateProps): import("react").JSX.Element;
|
|
27
27
|
declare namespace CheckoutDonate {
|
package/es/checkout/donate.js
CHANGED
|
@@ -29,14 +29,15 @@ import { PaymentThemeProvider } from "../theme/index.js";
|
|
|
29
29
|
import { usePaymentContext } from "../contexts/payment.js";
|
|
30
30
|
const donationCache = {};
|
|
31
31
|
const createOrUpdateDonation = (settings, livemode = true) => {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const donationKey = `${settings.target}-${livemode}`;
|
|
33
|
+
if (!donationCache[donationKey]) {
|
|
34
|
+
donationCache[donationKey] = api.post(`/api/donations?livemode=${livemode}`, omit(settings, ["appearance"])).then((res) => res.data).finally(() => {
|
|
34
35
|
setTimeout(() => {
|
|
35
|
-
delete donationCache[
|
|
36
|
+
delete donationCache[donationKey];
|
|
36
37
|
}, 3e3);
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
|
-
return donationCache[
|
|
40
|
+
return donationCache[donationKey];
|
|
40
41
|
};
|
|
41
42
|
const supporterCache = {};
|
|
42
43
|
const fetchSupporters = (target, livemode = true) => {
|
|
@@ -361,7 +362,8 @@ function CheckoutDonateInner({
|
|
|
361
362
|
supporters.data?.totalAmount || "0",
|
|
362
363
|
supporters.data?.currency?.decimal
|
|
363
364
|
)} ${supporters.data?.currency?.symbol}`,
|
|
364
|
-
supporters.data || {}
|
|
365
|
+
supporters.data || {},
|
|
366
|
+
!!supporters.loading
|
|
365
367
|
) }) : /* @__PURE__ */ jsxs(Typography, { children: [
|
|
366
368
|
"Please provide a valid render function ",
|
|
367
369
|
/* @__PURE__ */ jsx("pre", { children: "(openDonate, donateTotalAmount, supporters) => ReactNode" })
|
package/lib/checkout/donate.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
|
21
21
|
button?: ButtonType;
|
|
22
22
|
};
|
|
23
23
|
theme?: 'default' | 'inherit' | PaymentThemeOptions;
|
|
24
|
-
children?: (openDialog: () => void, donateTotalAmount: string, supporters: DonateHistory) => React.ReactNode;
|
|
24
|
+
children?: (openDialog: () => void, donateTotalAmount: string, supporters: DonateHistory, loading?: boolean) => React.ReactNode;
|
|
25
25
|
};
|
|
26
26
|
declare function CheckoutDonate(props: DonateProps): import("react").JSX.Element;
|
|
27
27
|
declare namespace CheckoutDonate {
|
package/lib/checkout/donate.js
CHANGED
|
@@ -21,14 +21,15 @@ var _payment = require("../contexts/payment");
|
|
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
22
|
const donationCache = {};
|
|
23
23
|
const createOrUpdateDonation = (settings, livemode = true) => {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const donationKey = `${settings.target}-${livemode}`;
|
|
25
|
+
if (!donationCache[donationKey]) {
|
|
26
|
+
donationCache[donationKey] = _api.default.post(`/api/donations?livemode=${livemode}`, (0, _omit.default)(settings, ["appearance"])).then(res => res.data).finally(() => {
|
|
26
27
|
setTimeout(() => {
|
|
27
|
-
delete donationCache[
|
|
28
|
+
delete donationCache[donationKey];
|
|
28
29
|
}, 3e3);
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
|
-
return donationCache[
|
|
32
|
+
return donationCache[donationKey];
|
|
32
33
|
};
|
|
33
34
|
const supporterCache = {};
|
|
34
35
|
const fetchSupporters = (target, livemode = true) => {
|
|
@@ -451,7 +452,7 @@ function CheckoutDonateInner({
|
|
|
451
452
|
}
|
|
452
453
|
if (mode === "custom") {
|
|
453
454
|
return children && typeof children === "function" ? /* @__PURE__ */(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
454
|
-
children: children(startDonate, `${(0, _util.formatAmount)(supporters.data?.totalAmount || "0", supporters.data?.currency?.decimal)} ${supporters.data?.currency?.symbol}`, supporters.data || {})
|
|
455
|
+
children: children(startDonate, `${(0, _util.formatAmount)(supporters.data?.totalAmount || "0", supporters.data?.currency?.decimal)} ${supporters.data?.currency?.symbol}`, supporters.data || {}, !!supporters.loading)
|
|
455
456
|
}) : /* @__PURE__ */(0, _jsxRuntime.jsxs)(_material.Typography, {
|
|
456
457
|
children: ["Please provide a valid render function ", /* @__PURE__ */(0, _jsxRuntime.jsx)("pre", {
|
|
457
458
|
children: "(openDonate, donateTotalAmount, supporters) => ReactNode"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/payment-react",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.12",
|
|
4
4
|
"description": "Reusable react components for payment kit v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -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.16.
|
|
95
|
+
"@blocklet/payment-types": "1.16.12",
|
|
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": "1af1e91e65dfb78b39d65a1d8d3396be83a9c04f"
|
|
126
126
|
}
|
package/src/checkout/donate.tsx
CHANGED
|
@@ -62,23 +62,29 @@ export type DonateProps = Pick<CheckoutProps, 'onPaid' | 'onError'> & {
|
|
|
62
62
|
button?: ButtonType;
|
|
63
63
|
};
|
|
64
64
|
theme?: 'default' | 'inherit' | PaymentThemeOptions;
|
|
65
|
-
children?: (
|
|
65
|
+
children?: (
|
|
66
|
+
openDialog: () => void,
|
|
67
|
+
donateTotalAmount: string,
|
|
68
|
+
supporters: DonateHistory,
|
|
69
|
+
loading?: boolean
|
|
70
|
+
) => React.ReactNode;
|
|
66
71
|
};
|
|
67
72
|
|
|
68
73
|
const donationCache: { [key: string]: Promise<TPaymentLink> } = {};
|
|
69
74
|
const createOrUpdateDonation = (settings: DonationSettings, livemode: boolean = true): Promise<TPaymentLink> => {
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
const donationKey = `${settings.target}-${livemode}`;
|
|
76
|
+
if (!donationCache[donationKey]) {
|
|
77
|
+
donationCache[donationKey] = api
|
|
72
78
|
.post(`/api/donations?livemode=${livemode}`, omit(settings, ['appearance']))
|
|
73
79
|
.then((res) => res.data)
|
|
74
80
|
.finally(() => {
|
|
75
81
|
setTimeout(() => {
|
|
76
|
-
delete donationCache[
|
|
82
|
+
delete donationCache[donationKey];
|
|
77
83
|
}, 3000);
|
|
78
84
|
});
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
return donationCache[
|
|
87
|
+
return donationCache[donationKey];
|
|
82
88
|
};
|
|
83
89
|
|
|
84
90
|
const supporterCache: { [key: string]: Promise<DonateHistory> } = {};
|
|
@@ -467,7 +473,8 @@ function CheckoutDonateInner({
|
|
|
467
473
|
(supporters.data as DonateHistory)?.totalAmount || '0',
|
|
468
474
|
(supporters.data as DonateHistory)?.currency?.decimal
|
|
469
475
|
)} ${(supporters.data as DonateHistory)?.currency?.symbol}`,
|
|
470
|
-
(supporters.data as DonateHistory) || {}
|
|
476
|
+
(supporters.data as DonateHistory) || {},
|
|
477
|
+
!!supporters.loading
|
|
471
478
|
)}
|
|
472
479
|
</>
|
|
473
480
|
) : (
|