@blocklet/payment-react 1.13.117 → 1.13.119

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/api.js CHANGED
@@ -9,7 +9,7 @@ api.interceptors.request.use(
9
9
  config.baseURL = prefix || "";
10
10
  config.timeout = 8e3;
11
11
  const livemode = localStorage.getItem("livemode");
12
- const locale = getLocale(window.blocklet.languages);
12
+ const locale = getLocale(window.blocklet?.languages);
13
13
  config.params = { ...config.params || {}, livemode: isNull(livemode) ? true : JSON.parse(livemode), locale };
14
14
  return config;
15
15
  },
@@ -1,2 +1,13 @@
1
1
  /// <reference types="react" />
2
- export default function Livemode(): import("react").JSX.Element;
2
+ type Props = {
3
+ color?: string;
4
+ backgroundColor?: string;
5
+ };
6
+ declare function Livemode({ color, backgroundColor }: Props): import("react").JSX.Element;
7
+ declare namespace Livemode {
8
+ var defaultProps: {
9
+ color: string;
10
+ backgroundColor: string;
11
+ };
12
+ }
13
+ export default Livemode;
@@ -1,7 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
3
  import { Chip } from "@mui/material";
4
- export default function Livemode() {
4
+ export default function Livemode({ color, backgroundColor }) {
5
5
  const { t } = useLocaleContext();
6
6
  return /* @__PURE__ */ jsx(
7
7
  Chip,
@@ -16,9 +16,13 @@ export default function Livemode() {
16
16
  fontSize: "0.8rem",
17
17
  fontWeight: "bold",
18
18
  borderRadius: "4px",
19
- backgroundColor: "#ffde92",
20
- color: "#bb5504"
19
+ backgroundColor,
20
+ color
21
21
  }
22
22
  }
23
23
  );
24
24
  }
25
+ Livemode.defaultProps = {
26
+ color: "#bb5504",
27
+ backgroundColor: "#ffde92"
28
+ };
@@ -20,7 +20,7 @@ export default styled(Switch)(({ variant = "success", theme }) => ({
20
20
  color: "#fff",
21
21
  "& + .MuiSwitch-track": {
22
22
  opacity: 1,
23
- backgroundColor: theme.palette[variant].light
23
+ backgroundColor: theme.palette[variant]?.light
24
24
  }
25
25
  }
26
26
  },
@@ -29,7 +29,7 @@ export default styled(Switch)(({ variant = "success", theme }) => ({
29
29
  width: 12,
30
30
  height: 12,
31
31
  borderRadius: 6,
32
- transition: theme.transitions.create(["width"], {
32
+ transition: theme.transitions?.create(["width"], {
33
33
  duration: 200
34
34
  })
35
35
  },
package/es/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import FormInput from './components/input';
5
5
  import Livemode from './components/livemode';
6
6
  import PricingTable from './components/pricing-table';
7
7
  import Status from './components/status';
8
- import Switch from './components/switch';
8
+ import Switch from './components/switch-button';
9
9
  import dayjs from './dayjs';
10
10
  import Amount from './payment/amount';
11
11
  import PhoneInput from './payment/form/phone';
package/es/index.js CHANGED
@@ -5,7 +5,7 @@ import FormInput from "./components/input.js";
5
5
  import Livemode from "./components/livemode.js";
6
6
  import PricingTable from "./components/pricing-table.js";
7
7
  import Status from "./components/status.js";
8
- import Switch from "./components/switch.js";
8
+ import Switch from "./components/switch-button.js";
9
9
  import dayjs from "./dayjs.js";
10
10
  import Amount from "./payment/amount.js";
11
11
  import PhoneInput from "./payment/form/phone.js";
@@ -4,7 +4,7 @@ export default function PaymentError({ title, description, button }) {
4
4
  return /* @__PURE__ */ jsx(Stack, { sx: { height: "100vh" }, alignItems: "center", justifyContent: "center", children: /* @__PURE__ */ jsxs(Stack, { sx: { width: "280px" }, direction: "column", alignItems: "center", justifyContent: "center", children: [
5
5
  /* @__PURE__ */ jsx(Typography, { variant: "h5", sx: { mb: 2 }, children: title }),
6
6
  /* @__PURE__ */ jsx(Typography, { variant: "body1", sx: { mb: 2, textAlign: "center" }, children: description }),
7
- /* @__PURE__ */ jsx(Button, { variant: "text", size: "small", component: Link, href: window.blocklet.appUrl, children: button })
7
+ /* @__PURE__ */ jsx(Button, { variant: "text", size: "small", component: Link, href: window.blocklet?.appUrl, children: button })
8
8
  ] }) });
9
9
  }
10
10
  PaymentError.defaultProps = {
@@ -2,7 +2,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useLocaleContext } from "@arcblock/ux/lib/Locale/context";
3
3
  import { Stack, Typography } from "@mui/material";
4
4
  import Status from "../components/status.js";
5
- import Switch from "../components/switch.js";
5
+ import Switch from "../components/switch-button.js";
6
6
  import { formatLineItemPricing, formatPrice, formatRecurring, formatUpsellSaving } from "../util.js";
7
7
  import ProductCard from "./product-card.js";
8
8
  ProductItem.defaultProps = {
package/es/util.js CHANGED
@@ -4,15 +4,15 @@ import dayjs from "./dayjs.js";
4
4
  import { t } from "./locales/index.js";
5
5
  export const PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
6
6
  export const getPrefix = () => {
7
- const componentId = (window.blocklet.componentId || "").split("/").pop();
7
+ const componentId = (window?.blocklet?.componentId || "").split("/").pop();
8
8
  if (componentId === PAYMENT_KIT_DID) {
9
- return window.blocklet.prefix;
9
+ return window.blocklet?.prefix;
10
10
  }
11
- const component = (window.blocklet.componentMountPoints || []).find((x) => x.did === PAYMENT_KIT_DID);
11
+ const component = (window.blocklet?.componentMountPoints || []).find((x) => x.did === PAYMENT_KIT_DID);
12
12
  if (component) {
13
13
  return component.mountPoint;
14
14
  }
15
- return window.blocklet.prefix;
15
+ return window.blocklet?.prefix;
16
16
  };
17
17
  export function formatToDate(date, locale = "en") {
18
18
  if (!date) {
@@ -95,7 +95,7 @@ export function getStatementDescriptor(items) {
95
95
  return item.price?.product?.statement_descriptor;
96
96
  }
97
97
  }
98
- return window.blocklet.appName;
98
+ return window.blocklet?.appName;
99
99
  }
100
100
  export function formatRecurring(recurring, translate = true, separator = "per", locale = "en") {
101
101
  const intervals = {
package/lib/api.js CHANGED
@@ -15,7 +15,7 @@ api.interceptors.request.use(config => {
15
15
  config.baseURL = prefix || "";
16
16
  config.timeout = 8e3;
17
17
  const livemode = localStorage.getItem("livemode");
18
- const locale = (0, _context.getLocale)(window.blocklet.languages);
18
+ const locale = (0, _context.getLocale)(window.blocklet?.languages);
19
19
  config.params = {
20
20
  ...(config.params || {}),
21
21
  livemode: (0, _isNull.default)(livemode) ? true : JSON.parse(livemode),
@@ -1,2 +1,13 @@
1
1
  /// <reference types="react" />
2
- export default function Livemode(): import("react").JSX.Element;
2
+ type Props = {
3
+ color?: string;
4
+ backgroundColor?: string;
5
+ };
6
+ declare function Livemode({ color, backgroundColor }: Props): import("react").JSX.Element;
7
+ declare namespace Livemode {
8
+ var defaultProps: {
9
+ color: string;
10
+ backgroundColor: string;
11
+ };
12
+ }
13
+ export default Livemode;
@@ -7,7 +7,10 @@ module.exports = Livemode;
7
7
  var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _context = require("@arcblock/ux/lib/Locale/context");
9
9
  var _material = require("@mui/material");
10
- function Livemode() {
10
+ function Livemode({
11
+ color,
12
+ backgroundColor
13
+ }) {
11
14
  const {
12
15
  t
13
16
  } = (0, _context.useLocaleContext)();
@@ -22,8 +25,12 @@ function Livemode() {
22
25
  fontSize: "0.8rem",
23
26
  fontWeight: "bold",
24
27
  borderRadius: "4px",
25
- backgroundColor: "#ffde92",
26
- color: "#bb5504"
28
+ backgroundColor,
29
+ color
27
30
  }
28
31
  });
29
- }
32
+ }
33
+ Livemode.defaultProps = {
34
+ color: "#bb5504",
35
+ backgroundColor: "#ffde92"
36
+ };
@@ -29,7 +29,7 @@ module.exports = (0, _system.styled)(_material.Switch)(({
29
29
  color: "#fff",
30
30
  "& + .MuiSwitch-track": {
31
31
  opacity: 1,
32
- backgroundColor: theme.palette[variant].light
32
+ backgroundColor: theme.palette[variant]?.light
33
33
  }
34
34
  }
35
35
  },
@@ -38,7 +38,7 @@ module.exports = (0, _system.styled)(_material.Switch)(({
38
38
  width: 12,
39
39
  height: 12,
40
40
  borderRadius: 6,
41
- transition: theme.transitions.create(["width"], {
41
+ transition: theme.transitions?.create(["width"], {
42
42
  duration: 200
43
43
  })
44
44
  },
package/lib/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import FormInput from './components/input';
5
5
  import Livemode from './components/livemode';
6
6
  import PricingTable from './components/pricing-table';
7
7
  import Status from './components/status';
8
- import Switch from './components/switch';
8
+ import Switch from './components/switch-button';
9
9
  import dayjs from './dayjs';
10
10
  import Amount from './payment/amount';
11
11
  import PhoneInput from './payment/form/phone';
package/lib/index.js CHANGED
@@ -83,7 +83,7 @@ Object.defineProperty(exports, "Status", {
83
83
  Object.defineProperty(exports, "Switch", {
84
84
  enumerable: true,
85
85
  get: function () {
86
- return _switch.default;
86
+ return _switchButton.default;
87
87
  }
88
88
  });
89
89
  Object.defineProperty(exports, "api", {
@@ -117,7 +117,7 @@ var _input = _interopRequireDefault(require("./components/input"));
117
117
  var _livemode = _interopRequireDefault(require("./components/livemode"));
118
118
  var _pricingTable = _interopRequireDefault(require("./components/pricing-table"));
119
119
  var _status = _interopRequireDefault(require("./components/status"));
120
- var _switch = _interopRequireDefault(require("./components/switch"));
120
+ var _switchButton = _interopRequireDefault(require("./components/switch-button"));
121
121
  var _dayjs = _interopRequireDefault(require("./dayjs"));
122
122
  var _amount = _interopRequireDefault(require("./payment/amount"));
123
123
  var _phone = _interopRequireDefault(require("./payment/form/phone"));
@@ -41,7 +41,7 @@ function PaymentError({
41
41
  variant: "text",
42
42
  size: "small",
43
43
  component: _material.Link,
44
- href: window.blocklet.appUrl,
44
+ href: window.blocklet?.appUrl,
45
45
  children: button
46
46
  })]
47
47
  })
@@ -8,7 +8,7 @@ var _jsxRuntime = require("react/jsx-runtime");
8
8
  var _context = require("@arcblock/ux/lib/Locale/context");
9
9
  var _material = require("@mui/material");
10
10
  var _status = _interopRequireDefault(require("../components/status"));
11
- var _switch = _interopRequireDefault(require("../components/switch"));
11
+ var _switchButton = _interopRequireDefault(require("../components/switch-button"));
12
12
  var _util = require("../util");
13
13
  var _productCard = _interopRequireDefault(require("./product-card"));
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -95,7 +95,7 @@ function ProductItem({
95
95
  cursor: "pointer",
96
96
  color: "text.primary"
97
97
  },
98
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_switch.default, {
98
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_switchButton.default, {
99
99
  id: "upsell-switch",
100
100
  sx: {
101
101
  mr: 1
@@ -137,7 +137,7 @@ function ProductItem({
137
137
  cursor: "pointer",
138
138
  color: "text.secondary"
139
139
  },
140
- children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_switch.default, {
140
+ children: [/* @__PURE__ */(0, _jsxRuntime.jsx)(_switchButton.default, {
141
141
  id: "upsell-switch",
142
142
  sx: {
143
143
  mr: 1
package/lib/util.js CHANGED
@@ -30,19 +30,19 @@ exports.stopEvent = stopEvent;
30
30
  var _util = require("@ocap/util");
31
31
  var _reactInternationalPhone = require("react-international-phone");
32
32
  var _dayjs = _interopRequireDefault(require("./dayjs"));
33
- var _index = require("./locales/index");
33
+ var _locales = require("./locales");
34
34
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
35
  const PAYMENT_KIT_DID = exports.PAYMENT_KIT_DID = "z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk";
36
36
  const getPrefix = () => {
37
- const componentId = (window.blocklet.componentId || "").split("/").pop();
37
+ const componentId = (window?.blocklet?.componentId || "").split("/").pop();
38
38
  if (componentId === PAYMENT_KIT_DID) {
39
- return window.blocklet.prefix;
39
+ return window.blocklet?.prefix;
40
40
  }
41
- const component = (window.blocklet.componentMountPoints || []).find(x => x.did === PAYMENT_KIT_DID);
41
+ const component = (window.blocklet?.componentMountPoints || []).find(x => x.did === PAYMENT_KIT_DID);
42
42
  if (component) {
43
43
  return component.mountPoint;
44
44
  }
45
- return window.blocklet.prefix;
45
+ return window.blocklet?.prefix;
46
46
  };
47
47
  exports.getPrefix = getPrefix;
48
48
  function formatToDate(date, locale = "en") {
@@ -135,7 +135,7 @@ function getStatementDescriptor(items) {
135
135
  return item.price?.product?.statement_descriptor;
136
136
  }
137
137
  }
138
- return window.blocklet.appName;
138
+ return window.blocklet?.appName;
139
139
  }
140
140
  function formatRecurring(recurring, translate = true, separator = "per", locale = "en") {
141
141
  const intervals = {
@@ -146,14 +146,14 @@ function formatRecurring(recurring, translate = true, separator = "per", locale
146
146
  year: "yearly"
147
147
  };
148
148
  if (+recurring.interval_count === 1) {
149
- const interval = (0, _index.t)(`common.${recurring.interval}`, locale);
150
- return translate ? (0, _index.t)(`common.${intervals[recurring.interval]}`, locale) : separator ? (0, _index.t)(`common.${separator}`, locale, {
149
+ const interval = (0, _locales.t)(`common.${recurring.interval}`, locale);
150
+ return translate ? (0, _locales.t)(`common.${intervals[recurring.interval]}`, locale) : separator ? (0, _locales.t)(`common.${separator}`, locale, {
151
151
  interval
152
152
  }) : interval;
153
153
  }
154
- return (0, _index.t)("common.recurring", locale, {
154
+ return (0, _locales.t)("common.recurring", locale, {
155
155
  count: recurring.interval_count,
156
- interval: (0, _index.t)(`common.${recurring.interval}s`, locale)
156
+ interval: (0, _locales.t)(`common.${recurring.interval}s`, locale)
157
157
  });
158
158
  }
159
159
  function getPriceUintAmountByCurrency(price, currency) {
@@ -177,7 +177,7 @@ function getPriceCurrencyOptions(price) {
177
177
  }
178
178
  function formatLineItemPricing(item, currency, trial, locale = "en") {
179
179
  const price = item.upsell_price || item.price;
180
- let quantity = (0, _index.t)("common.qty", locale, {
180
+ let quantity = (0, _locales.t)("common.qty", locale, {
181
181
  count: item.quantity
182
182
  });
183
183
  if (price.recurring?.usage_type === "metered" || +item.quantity === 1) {
@@ -192,14 +192,14 @@ function formatLineItemPricing(item, currency, trial, locale = "en") {
192
192
  if (price.recurring?.usage_type === "metered" || item.quantity === 1) {
193
193
  return alt;
194
194
  }
195
- return quantity ? (0, _index.t)("common.each", locale, {
195
+ return quantity ? (0, _locales.t)("common.each", locale, {
196
196
  unit
197
197
  }) : "";
198
198
  };
199
199
  if (price.type === "recurring" && price.recurring) {
200
200
  if (trial > 0) {
201
201
  return {
202
- primary: (0, _index.t)("common.trial", locale, {
202
+ primary: (0, _locales.t)("common.trial", locale, {
203
203
  count: trial
204
204
  }),
205
205
  secondary: `${appendUnit(total, total)} ${formatRecurring(price.recurring, false, "slash", locale)}`,
@@ -297,7 +297,7 @@ function formatCheckoutHeadlines(session, currency, locale = "en") {
297
297
  const amount = `${(0, _util.fromUnitToToken)(total, currency.decimal)} ${currency.symbol}`;
298
298
  if (items.length === 0) {
299
299
  return {
300
- action: (0, _index.t)("payment.checkout.empty", locale),
300
+ action: (0, _locales.t)("payment.checkout.empty", locale),
301
301
  amount: "0",
302
302
  then: ""
303
303
  };
@@ -308,7 +308,7 @@ function formatCheckoutHeadlines(session, currency, locale = "en") {
308
308
  name: ""
309
309
  };
310
310
  if (items.every(x => x.price.type === "one_time")) {
311
- const action = (0, _index.t)("payment.checkout.pay", locale, {
311
+ const action = (0, _locales.t)("payment.checkout.pay", locale, {
312
312
  payee: brand
313
313
  });
314
314
  if (items.length > 1) {
@@ -327,7 +327,7 @@ function formatCheckoutHeadlines(session, currency, locale = "en") {
327
327
  const recurring = formatRecurring((item?.upsell_price || item?.price)?.recurring, false, "per", locale);
328
328
  if (items.every(x => x.price.type === "recurring")) {
329
329
  const hasMetered = items.some(x => x.price.type === "recurring" && x.price.recurring?.usage_type === "metered");
330
- const subscription2 = [hasMetered ? (0, _index.t)("payment.checkout.least", locale) : "", (0, _util.fromUnitToToken)(items.reduce((acc, x) => {
330
+ const subscription2 = [hasMetered ? (0, _locales.t)("payment.checkout.least", locale) : "", (0, _util.fromUnitToToken)(items.reduce((acc, x) => {
331
331
  if (x.price.recurring?.usage_type === "metered") {
332
332
  return acc;
333
333
  }
@@ -336,21 +336,21 @@ function formatCheckoutHeadlines(session, currency, locale = "en") {
336
336
  if (items.length > 1) {
337
337
  if (trial > 0) {
338
338
  return {
339
- action: (0, _index.t)("payment.checkout.try2", locale, {
339
+ action: (0, _locales.t)("payment.checkout.try2", locale, {
340
340
  name,
341
341
  count: items.length - 1
342
342
  }),
343
- amount: (0, _index.t)("payment.checkout.free", locale, {
343
+ amount: (0, _locales.t)("payment.checkout.free", locale, {
344
344
  count: trial
345
345
  }),
346
- then: (0, _index.t)("payment.checkout.then", locale, {
346
+ then: (0, _locales.t)("payment.checkout.then", locale, {
347
347
  subscription: subscription2,
348
348
  recurring
349
349
  })
350
350
  };
351
351
  }
352
352
  return {
353
- action: (0, _index.t)("payment.checkout.sub2", locale, {
353
+ action: (0, _locales.t)("payment.checkout.sub2", locale, {
354
354
  name,
355
355
  count: items.length - 1
356
356
  }),
@@ -360,20 +360,20 @@ function formatCheckoutHeadlines(session, currency, locale = "en") {
360
360
  }
361
361
  if (trial > 0) {
362
362
  return {
363
- action: (0, _index.t)("payment.checkout.try1", locale, {
363
+ action: (0, _locales.t)("payment.checkout.try1", locale, {
364
364
  name
365
365
  }),
366
- amount: (0, _index.t)("payment.checkout.free", locale, {
366
+ amount: (0, _locales.t)("payment.checkout.free", locale, {
367
367
  count: trial
368
368
  }),
369
- then: (0, _index.t)("payment.checkout.then", locale, {
369
+ then: (0, _locales.t)("payment.checkout.then", locale, {
370
370
  subscription: subscription2,
371
371
  recurring
372
372
  })
373
373
  };
374
374
  }
375
375
  return {
376
- action: (0, _index.t)("payment.checkout.sub1", locale, {
376
+ action: (0, _locales.t)("payment.checkout.sub1", locale, {
377
377
  name
378
378
  }),
379
379
  amount,
@@ -387,11 +387,11 @@ function formatCheckoutHeadlines(session, currency, locale = "en") {
387
387
  return acc.add(new _util.BN(getPriceUintAmountByCurrency(x.price, currency)).mul(new _util.BN(x.quantity)));
388
388
  }, new _util.BN(0)), currency.decimal);
389
389
  return {
390
- action: (0, _index.t)("payment.checkout.pay", locale, {
390
+ action: (0, _locales.t)("payment.checkout.pay", locale, {
391
391
  payee: brand
392
392
  }),
393
393
  amount,
394
- then: (0, _index.t)("payment.checkout.then", locale, {
394
+ then: (0, _locales.t)("payment.checkout.then", locale, {
395
395
  subscription: `${subscription} ${currency.symbol}`,
396
396
  recurring
397
397
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/payment-react",
3
- "version": "1.13.117",
3
+ "version": "1.13.119",
4
4
  "description": "Reusable react components for payment kit v2",
5
5
  "keywords": [
6
6
  "react",
@@ -24,7 +24,9 @@
24
24
  "prepush": "CI=1 npm run lint",
25
25
  "prepublish": "npm run build",
26
26
  "test": "node tools/jest.js",
27
- "coverage": "npm run test -- --coverage"
27
+ "coverage": "npm run test -- --coverage",
28
+ "storybook": "storybook dev -p 6006",
29
+ "build-storybook": "storybook build"
28
30
  },
29
31
  "bugs": {
30
32
  "url": "https://github.com/blocklet/payment-kit/issues"
@@ -60,6 +62,7 @@
60
62
  "@ocap/util": "^1.18.108",
61
63
  "@stripe/react-stripe-js": "^2.4.0",
62
64
  "@stripe/stripe-js": "^2.2.0",
65
+ "@vitejs/plugin-legacy": "^5.3.0",
63
66
  "ahooks": "^3.7.8",
64
67
  "axios": "^0.27.2",
65
68
  "dayjs": "^1.11.10",
@@ -86,19 +89,34 @@
86
89
  "@babel/core": "^7.19.3",
87
90
  "@babel/preset-env": "^7.19.3",
88
91
  "@babel/preset-react": "^7.18.6",
89
- "@blocklet/payment-types": "1.13.117",
92
+ "@blocklet/payment-types": "1.13.119",
93
+ "@storybook/addon-essentials": "^7.6.10",
94
+ "@storybook/addon-interactions": "^7.6.10",
95
+ "@storybook/addon-links": "^7.6.10",
96
+ "@storybook/addon-onboarding": "^1.0.11",
97
+ "@storybook/blocks": "^7.6.10",
98
+ "@storybook/react": "^7.6.10",
99
+ "@storybook/react-vite": "^7.6.10",
100
+ "@storybook/test": "^7.6.10",
90
101
  "@types/react": "^18.2.42",
91
102
  "@types/react-dom": "^18.2.17",
103
+ "@vitejs/plugin-legacy": "^5.3.0",
92
104
  "eslint": "^8.56.0",
93
105
  "glob": "^10.3.3",
94
106
  "import-sort-style-module": "^6.0.0",
95
107
  "jest": "^29.7.0",
96
108
  "prettier": "^2.8.8",
97
109
  "prettier-plugin-import-sort": "^0.0.7",
110
+ "react": "^18.2.0",
111
+ "react-dom": "^18.2.0",
112
+ "rollup-plugin-node-builtins": "^2.1.2",
113
+ "storybook": "^7.6.10",
98
114
  "ts-jest": "^29.1.2",
99
115
  "type-fest": "^4.8.3",
100
116
  "typescript": "^4.9.5",
101
- "unbuild": "^2.0.0"
117
+ "unbuild": "^2.0.0",
118
+ "vite-plugin-babel": "^1.2.0",
119
+ "vite-plugin-node-polyfills": "^0.19.0"
102
120
  },
103
- "gitHead": "8cb6598da65c927de5beaf94f59b1884ba95162b"
121
+ "gitHead": "476ee7af8213287b3953330a4ad179f4d29d4902"
104
122
  }
package/src/api.ts CHANGED
@@ -13,7 +13,7 @@ api.interceptors.request.use(
13
13
  config.timeout = 8000;
14
14
 
15
15
  const livemode = localStorage.getItem('livemode');
16
- const locale = getLocale(window.blocklet.languages);
16
+ const locale = getLocale(window.blocklet?.languages);
17
17
  config.params = { ...(config.params || {}), livemode: isNull(livemode) ? true : JSON.parse(livemode), locale };
18
18
 
19
19
  return config;
@@ -1,7 +1,12 @@
1
1
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
2
2
  import { Chip } from '@mui/material';
3
3
 
4
- export default function Livemode() {
4
+ type Props = {
5
+ color?: string;
6
+ backgroundColor?: string;
7
+ };
8
+
9
+ export default function Livemode({ color, backgroundColor }: Props) {
5
10
  const { t } = useLocaleContext();
6
11
  return (
7
12
  <Chip
@@ -15,9 +20,14 @@ export default function Livemode() {
15
20
  fontSize: '0.8rem',
16
21
  fontWeight: 'bold',
17
22
  borderRadius: '4px',
18
- backgroundColor: '#ffde92',
19
- color: '#bb5504',
23
+ backgroundColor,
24
+ color,
20
25
  }}
21
26
  />
22
27
  );
23
28
  }
29
+
30
+ Livemode.defaultProps = {
31
+ color: '#bb5504',
32
+ backgroundColor: '#ffde92',
33
+ };
@@ -26,7 +26,7 @@ export default styled(Switch)<SwitchProps>(({ variant = 'success', theme }) => (
26
26
  color: '#fff',
27
27
  '& + .MuiSwitch-track': {
28
28
  opacity: 1,
29
- backgroundColor: theme.palette[variant].light,
29
+ backgroundColor: theme.palette[variant]?.light,
30
30
  },
31
31
  },
32
32
  },
@@ -35,7 +35,7 @@ export default styled(Switch)<SwitchProps>(({ variant = 'success', theme }) => (
35
35
  width: 12,
36
36
  height: 12,
37
37
  borderRadius: 6,
38
- transition: (theme.transitions as any).create(['width'], {
38
+ transition: (theme.transitions as any)?.create(['width'], {
39
39
  duration: 200,
40
40
  }),
41
41
  },
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import FormInput from './components/input';
5
5
  import Livemode from './components/livemode';
6
6
  import PricingTable from './components/pricing-table';
7
7
  import Status from './components/status';
8
- import Switch from './components/switch';
8
+ import Switch from './components/switch-button';
9
9
  import dayjs from './dayjs';
10
10
  import Amount from './payment/amount';
11
11
  import PhoneInput from './payment/form/phone';
@@ -16,7 +16,7 @@ export default function PaymentError({ title, description, button }: Props) {
16
16
  <Typography variant="body1" sx={{ mb: 2, textAlign: 'center' }}>
17
17
  {description}
18
18
  </Typography>
19
- <Button variant="text" size="small" component={Link} href={window.blocklet.appUrl}>
19
+ <Button variant="text" size="small" component={Link} href={window.blocklet?.appUrl}>
20
20
  {button}
21
21
  </Button>
22
22
  </Stack>
@@ -8,7 +8,7 @@ import type {
8
8
  import { Stack, Typography } from '@mui/material';
9
9
 
10
10
  import Status from '../components/status';
11
- import Switch from '../components/switch';
11
+ import Switch from '../components/switch-button';
12
12
  import { formatLineItemPricing, formatPrice, formatRecurring, formatUpsellSaving } from '../util';
13
13
  import ProductCard from './product-card';
14
14
 
package/src/util.ts CHANGED
@@ -14,21 +14,21 @@ import { BN, fromUnitToToken } from '@ocap/util';
14
14
  import { defaultCountries } from 'react-international-phone';
15
15
 
16
16
  import dayjs from './dayjs';
17
- import { t } from './locales/index';
17
+ import { t } from './locales';
18
18
 
19
19
  export const PAYMENT_KIT_DID = 'z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk';
20
20
 
21
21
  export const getPrefix = () => {
22
- const componentId = (window.blocklet.componentId || '').split('/').pop();
22
+ const componentId = (window?.blocklet?.componentId || '').split('/').pop();
23
23
  if (componentId === PAYMENT_KIT_DID) {
24
- return window.blocklet.prefix;
24
+ return window.blocklet?.prefix;
25
25
  }
26
- const component = (window.blocklet.componentMountPoints || []).find((x: any) => x.did === PAYMENT_KIT_DID);
26
+ const component = (window.blocklet?.componentMountPoints || []).find((x: any) => x.did === PAYMENT_KIT_DID);
27
27
  if (component) {
28
28
  return component.mountPoint;
29
29
  }
30
30
 
31
- return window.blocklet.prefix;
31
+ return window.blocklet?.prefix;
32
32
  };
33
33
 
34
34
  export function formatToDate(date: Date | string | number, locale = 'en') {
@@ -156,7 +156,7 @@ export function getStatementDescriptor(items: any[]) {
156
156
  }
157
157
  }
158
158
 
159
- return window.blocklet.appName;
159
+ return window.blocklet?.appName;
160
160
  }
161
161
 
162
162
  export function formatRecurring(
package/vite.config.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from 'vite';
2
+ import { nodePolyfills } from 'vite-plugin-node-polyfills';
3
+
4
+ export default defineConfig({
5
+ plugins: [ nodePolyfills({ protocolImports: true })]
6
+ });