@blocklet/payment-react 1.13.213 → 1.13.215

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.
@@ -37,7 +37,7 @@ const createOrUpdateDonation = (settings, livemode = true) => {
37
37
  const supporterCache = {};
38
38
  const fetchSupporters = (target) => {
39
39
  if (!supporterCache[target]) {
40
- supporterCache[target] = api.get(`/api/donations?&target=${target}`).then((res) => res.data).finally(() => {
40
+ supporterCache[target] = api.get("/api/donations", { params: { target } }).then((res) => res.data).finally(() => {
41
41
  setTimeout(() => {
42
42
  delete supporterCache[target];
43
43
  }, 3e3);
@@ -45,7 +45,7 @@ const fetchSupporters = (target) => {
45
45
  }
46
46
  return supporterCache[target];
47
47
  };
48
- function SupporterAvatar({ supporters = [], total, currency, method }) {
48
+ function SupporterAvatar({ supporters = [], total = 0, currency, method }) {
49
49
  const { t } = useLocaleContext();
50
50
  const customers = uniqBy(supporters, "customer_did");
51
51
  return /* @__PURE__ */ jsxs(
@@ -80,7 +80,7 @@ function SupporterAvatar({ supporters = [], total, currency, method }) {
80
80
  }
81
81
  );
82
82
  }
83
- function SupporterTable({ supporters = [], total, currency, method }) {
83
+ function SupporterTable({ supporters = [], total = 0, currency, method }) {
84
84
  const { t } = useLocaleContext();
85
85
  return /* @__PURE__ */ jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", sx: { width: "100%" }, gap: { xs: 0.5, sm: 1 }, children: [
86
86
  /* @__PURE__ */ jsx(Typography, { component: "p", color: "text.secondary", children: t("payment.checkout.donation.summary", { total }) }),
package/es/util.d.ts CHANGED
@@ -10,8 +10,8 @@ export declare function formatDateTime(date: Date | string | number, locale?: st
10
10
  export declare const formatLocale: (locale?: string) => string;
11
11
  export declare const formatPrettyMsLocale: (locale: string) => "zh_CN" | "en_US";
12
12
  export declare const formatError: (err: any) => any;
13
- export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): any;
14
- export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): any;
13
+ export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): string;
14
+ export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): string;
15
15
  export declare const formatPrice: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean, locale?: string) => string;
16
16
  export declare const formatPriceAmount: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean) => string;
17
17
  export declare function getStatementDescriptor(items: any[]): any;
package/es/util.js CHANGED
@@ -78,7 +78,12 @@ export function formatNumber(n, precision = 6, trim = true) {
78
78
  thousandSeparated: true,
79
79
  ...(precision || precision === 0) && { mantissa: precision }
80
80
  };
81
- return trim ? trimEnd(num.format(options), "0.") : num.format(options);
81
+ const result = num.format(options);
82
+ if (!trim) {
83
+ return result;
84
+ }
85
+ const [left, right] = result.split(".");
86
+ return right ? [left, trimEnd(right, "0")].filter(Boolean).join(".") : left;
82
87
  }
83
88
  export const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
84
89
  if (price.custom_unit_amount) {
@@ -31,7 +31,11 @@ const createOrUpdateDonation = (settings, livemode = true) => {
31
31
  const supporterCache = {};
32
32
  const fetchSupporters = target => {
33
33
  if (!supporterCache[target]) {
34
- supporterCache[target] = _api.default.get(`/api/donations?&target=${target}`).then(res => res.data).finally(() => {
34
+ supporterCache[target] = _api.default.get("/api/donations", {
35
+ params: {
36
+ target
37
+ }
38
+ }).then(res => res.data).finally(() => {
35
39
  setTimeout(() => {
36
40
  delete supporterCache[target];
37
41
  }, 3e3);
@@ -41,7 +45,7 @@ const fetchSupporters = target => {
41
45
  };
42
46
  function SupporterAvatar({
43
47
  supporters = [],
44
- total,
48
+ total = 0,
45
49
  currency,
46
50
  method
47
51
  }) {
@@ -86,7 +90,7 @@ function SupporterAvatar({
86
90
  }
87
91
  function SupporterTable({
88
92
  supporters = [],
89
- total,
93
+ total = 0,
90
94
  currency,
91
95
  method
92
96
  }) {
package/lib/util.d.ts CHANGED
@@ -10,8 +10,8 @@ export declare function formatDateTime(date: Date | string | number, locale?: st
10
10
  export declare const formatLocale: (locale?: string) => string;
11
11
  export declare const formatPrettyMsLocale: (locale: string) => "zh_CN" | "en_US";
12
12
  export declare const formatError: (err: any) => any;
13
- export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): any;
14
- export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): any;
13
+ export declare function formatBNStr(str?: string, decimals?: number, precision?: number, trim?: boolean): string;
14
+ export declare function formatNumber(n: number | string, precision?: number, trim?: boolean): string;
15
15
  export declare const formatPrice: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean, locale?: string) => string;
16
16
  export declare const formatPriceAmount: (price: TPrice, currency: TPaymentCurrency, unit_label?: string, quantity?: number, bn?: boolean) => string;
17
17
  export declare function getStatementDescriptor(items: any[]): any;
package/lib/util.js CHANGED
@@ -132,7 +132,12 @@ function formatNumber(n, precision = 6, trim = true) {
132
132
  mantissa: precision
133
133
  })
134
134
  };
135
- return trim ? (0, _trimEnd.default)(num.format(options), "0.") : num.format(options);
135
+ const result = num.format(options);
136
+ if (!trim) {
137
+ return result;
138
+ }
139
+ const [left, right] = result.split(".");
140
+ return right ? [left, (0, _trimEnd.default)(right, "0")].filter(Boolean).join(".") : left;
136
141
  }
137
142
  const formatPrice = (price, currency, unit_label, quantity = 1, bn = true, locale = "en") => {
138
143
  if (price.custom_unit_amount) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.213",
3
+ "version": "1.13.215",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -90,7 +90,7 @@
90
90
  "@babel/core": "^7.23.9",
91
91
  "@babel/preset-env": "^7.23.9",
92
92
  "@babel/preset-react": "^7.23.3",
93
- "@blocklet/payment-types": "1.13.213",
93
+ "@blocklet/payment-types": "1.13.215",
94
94
  "@storybook/addon-essentials": "^7.6.13",
95
95
  "@storybook/addon-interactions": "^7.6.13",
96
96
  "@storybook/addon-links": "^7.6.13",
@@ -119,5 +119,5 @@
119
119
  "vite-plugin-babel": "^1.2.0",
120
120
  "vite-plugin-node-polyfills": "^0.21.0"
121
121
  },
122
- "gitHead": "209467c5da3ab2fa17f5ce802bcd8b086e7c08e5"
122
+ "gitHead": "cb347916f1833065915dc149f2557944393f83d2"
123
123
  }
@@ -64,7 +64,7 @@ const supporterCache: { [key: string]: Promise<DonateHistory> } = {};
64
64
  const fetchSupporters = (target: string): Promise<DonateHistory> => {
65
65
  if (!supporterCache[target]) {
66
66
  supporterCache[target] = api
67
- .get(`/api/donations?&target=${target}`)
67
+ .get('/api/donations', { params: { target } })
68
68
  .then((res) => res.data)
69
69
  .finally(() => {
70
70
  setTimeout(() => {
@@ -77,7 +77,7 @@ const fetchSupporters = (target: string): Promise<DonateHistory> => {
77
77
  };
78
78
 
79
79
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
80
- function SupporterAvatar({ supporters = [], total, currency, method }: DonateHistory) {
80
+ function SupporterAvatar({ supporters = [], total = 0, currency, method }: DonateHistory) {
81
81
  const { t } = useLocaleContext();
82
82
  const customers = uniqBy(supporters, 'customer_did');
83
83
  return (
@@ -114,7 +114,7 @@ function SupporterAvatar({ supporters = [], total, currency, method }: DonateHis
114
114
  }
115
115
 
116
116
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
117
- function SupporterTable({ supporters = [], total, currency, method }: DonateHistory) {
117
+ function SupporterTable({ supporters = [], total = 0, currency, method }: DonateHistory) {
118
118
  const { t } = useLocaleContext();
119
119
  return (
120
120
  <Box display="flex" flexDirection="column" alignItems="center" sx={{ width: '100%' }} gap={{ xs: 0.5, sm: 1 }}>
package/src/util.ts CHANGED
@@ -118,7 +118,12 @@ export function formatNumber(n: number | string, precision: number = 6, trim: bo
118
118
  thousandSeparated: true,
119
119
  ...((precision || precision === 0) && { mantissa: precision }),
120
120
  };
121
- return trim ? trimEnd(num.format(options), '0.') : num.format(options);
121
+ const result = num.format(options);
122
+ if (!trim) {
123
+ return result;
124
+ }
125
+ const [left, right] = result.split('.');
126
+ return right ? [left, trimEnd(right, '0')].filter(Boolean).join('.') : left;
122
127
  }
123
128
 
124
129
  export const formatPrice = (