@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 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>
@@ -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 {
@@ -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
- if (!donationCache[settings.target]) {
33
- donationCache[settings.target] = api.post(`/api/donations?livemode=${livemode}`, omit(settings, ["appearance"])).then((res) => res.data).finally(() => {
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[settings.target];
36
+ delete donationCache[donationKey];
36
37
  }, 3e3);
37
38
  });
38
39
  }
39
- return donationCache[settings.target];
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" })
@@ -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 {
@@ -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
- if (!donationCache[settings.target]) {
25
- donationCache[settings.target] = _api.default.post(`/api/donations?livemode=${livemode}`, (0, _omit.default)(settings, ["appearance"])).then(res => res.data).finally(() => {
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[settings.target];
28
+ delete donationCache[donationKey];
28
29
  }, 3e3);
29
30
  });
30
31
  }
31
- return donationCache[settings.target];
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.10",
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.10",
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": "ee0052f6d37257507d69b979ea11ae22ffd622b7"
125
+ "gitHead": "1af1e91e65dfb78b39d65a1d8d3396be83a9c04f"
126
126
  }
@@ -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?: (openDialog: () => void, donateTotalAmount: string, supporters: DonateHistory) => React.ReactNode;
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
- if (!donationCache[settings.target]) {
71
- donationCache[settings.target] = api
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[settings.target];
82
+ delete donationCache[donationKey];
77
83
  }, 3000);
78
84
  });
79
85
  }
80
86
 
81
- return donationCache[settings.target];
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
  ) : (