@blocklet/launcher-ux 2.2.53 → 2.2.55

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.
@@ -1,8 +1,7 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import Button from '@arcblock/ux/lib/Button';
3
3
  import CircularProgress from '@mui/material/CircularProgress';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- import { jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
5
  export default function WrappedButton({
7
6
  children,
8
7
  loading,
@@ -1,8 +1,7 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import styled from '@emotion/styled';
3
3
  import CheckIcon from '@mui/icons-material/Check';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- import { jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
5
  export default function CheckBox({
7
6
  children,
8
7
  checked,
@@ -0,0 +1,364 @@
1
+ import DidAddress from '@arcblock/ux/lib/DID';
2
+ import formatError from '@blocklet/launcher-util/es/format-error';
3
+ import { getBlockletUrlOnStore } from '@blocklet/launcher-util/lib/util';
4
+ import { CheckoutForm, PaymentProvider, formatPrice, usePaymentContext } from '@blocklet/payment-react';
5
+ import InfoIcon from '@mui/icons-material/InfoOutlined';
6
+ import { Alert, Avatar, List, ListItem, ListItemAvatar, ListItemText, Tooltip, Typography } from '@mui/material';
7
+ import Box from '@mui/material/Box';
8
+ import CircularProgress from '@mui/material/CircularProgress';
9
+ import { useSetState } from 'ahooks';
10
+ import PropTypes from 'prop-types';
11
+ import useAsync from 'react-use/lib/useAsync';
12
+ import useMobile from '../../use-mobile';
13
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ export default function CheckoutOnDemand({
15
+ launchSessionId,
16
+ handlePaid,
17
+ components,
18
+ blockletStoreURL,
19
+ api,
20
+ connectApi,
21
+ checkoutPath,
22
+ session,
23
+ t,
24
+ locale
25
+ }) {
26
+ return /*#__PURE__*/_jsx(Box, {
27
+ sx: {
28
+ display: 'flex',
29
+ justifyContent: 'center'
30
+ },
31
+ children: /*#__PURE__*/_jsx(PaymentProvider, {
32
+ session: session,
33
+ connect: connectApi,
34
+ children: /*#__PURE__*/_jsx(Component, {
35
+ api: api,
36
+ launchSessionId: launchSessionId,
37
+ handlePaid: handlePaid,
38
+ checkoutPath: checkoutPath,
39
+ components: components,
40
+ blockletStoreURL: blockletStoreURL,
41
+ t: t,
42
+ locale: locale
43
+ })
44
+ })
45
+ });
46
+ }
47
+ const propTypes = {
48
+ launchSessionId: PropTypes.string.isRequired,
49
+ handlePaid: PropTypes.func.isRequired,
50
+ components: PropTypes.array.isRequired,
51
+ blockletStoreURL: PropTypes.string.isRequired,
52
+ t: PropTypes.func.isRequired,
53
+ locale: PropTypes.string.isRequired,
54
+ api: PropTypes.object.isRequired,
55
+ checkoutPath: PropTypes.string.isRequired
56
+ };
57
+ CheckoutOnDemand.propTypes = {
58
+ ...propTypes,
59
+ connectApi: PropTypes.func.isRequired,
60
+ session: PropTypes.object.isRequired
61
+ };
62
+ Component.propTypes = propTypes;
63
+ function Component({
64
+ launchSessionId,
65
+ handlePaid,
66
+ components: tempComponents,
67
+ blockletStoreURL,
68
+ api,
69
+ checkoutPath,
70
+ t,
71
+ locale
72
+ }) {
73
+ const {
74
+ getCurrency
75
+ } = usePaymentContext();
76
+ const [state, setState] = useSetState({
77
+ unitPrice: '',
78
+ totalPrice: ''
79
+ });
80
+ const {
81
+ isMobile
82
+ } = useMobile();
83
+ const components = (tempComponents || []).reduce((acc, x) => {
84
+ if (acc.findIndex(y => y.did === x.did) === -1) {
85
+ acc.push(x);
86
+ }
87
+ return acc;
88
+ }, []).sort((x, y) => {
89
+ if (x.title > y.title) {
90
+ return 1;
91
+ }
92
+ if (x.title < y.title) {
93
+ return -1;
94
+ }
95
+ return 0;
96
+ });
97
+ const quantity = components?.length || 1;
98
+ const checkoutState = useAsync(async () => {
99
+ const {
100
+ data
101
+ } = await api.post(checkoutPath, {
102
+ launchSessionId
103
+ });
104
+ return {
105
+ checkoutSessionId: data.checkoutSessionId,
106
+ price: data.price
107
+ };
108
+ });
109
+ if (checkoutState.loading) {
110
+ return /*#__PURE__*/_jsx(CircularProgress, {});
111
+ }
112
+ if (checkoutState.error) {
113
+ return /*#__PURE__*/_jsx(Alert, {
114
+ severity: "error",
115
+ children: formatError(checkoutState.error)
116
+ });
117
+ }
118
+ const {
119
+ checkoutSessionId,
120
+ price
121
+ } = checkoutState.value;
122
+ const handleChange = ({
123
+ payment_currency: currencyId
124
+ } = {}) => {
125
+ try {
126
+ const currency = getCurrency(currencyId);
127
+ const UNIT_LABEL_PLACEHOLDER = 'UNIT_LABEL_TEMPLATES';
128
+ let totalPrice = formatPrice(price, currency, UNIT_LABEL_PLACEHOLDER, quantity, true, locale);
129
+ totalPrice = totalPrice?.replace(new RegExp(`${UNIT_LABEL_PLACEHOLDER}\\s+\\/*`), '');
130
+ let unitPrice = formatPrice(price, currency, UNIT_LABEL_PLACEHOLDER, 1, true, locale);
131
+ unitPrice = unitPrice?.replace(new RegExp(`${UNIT_LABEL_PLACEHOLDER}\\s+\\/*`), '');
132
+ setState({
133
+ unitPrice,
134
+ totalPrice
135
+ });
136
+ } catch (error) {
137
+ console.error('calculate failed error', error);
138
+ }
139
+ };
140
+ return /*#__PURE__*/_jsxs(Box, {
141
+ sx: {
142
+ display: 'flex',
143
+ flexDirection: 'row',
144
+ justifyContent: 'space-between',
145
+ gap: isMobile ? '32px' : '64px',
146
+ height: '100%',
147
+ width: '100%',
148
+ '@media (max-width: 1200px)': {
149
+ flexDirection: 'column',
150
+ justifyContent: 'flex-start'
151
+ }
152
+ },
153
+ children: [/*#__PURE__*/_jsxs(Box, {
154
+ sx: {
155
+ display: 'flex',
156
+ flexDirection: 'column',
157
+ gap: '24px',
158
+ height: '100%',
159
+ width: '100%'
160
+ },
161
+ children: [/*#__PURE__*/_jsxs(Box, {
162
+ sx: {
163
+ display: 'flex',
164
+ flexDirection: 'column',
165
+ gap: '12px'
166
+ },
167
+ children: [/*#__PURE__*/_jsxs(Typography, {
168
+ sx: {
169
+ fontWeight: 'bold'
170
+ },
171
+ children: [components?.length <= 1 && t('purchase.componentCount', {
172
+ count: components?.length
173
+ }), components?.length > 1 && t('purchase.componentsCount', {
174
+ count: components?.length
175
+ })]
176
+ }), /*#__PURE__*/_jsx(List, {
177
+ dense: true,
178
+ disablePadding: true,
179
+ sx: {
180
+ maxHeight: '480px',
181
+ overflowY: 'auto',
182
+ '&::-webkit-scrollbar': {
183
+ width: '6px'
184
+ },
185
+ '&::-webkit-scrollbar-track': {
186
+ backgroundColor: 'transparent'
187
+ },
188
+ '&::-webkit-scrollbar-thumb': {
189
+ backgroundColor: '#ccc',
190
+ borderRadius: '3px'
191
+ },
192
+ '@media (max-width: 1200px)': {
193
+ maxHeight: 'unset'
194
+ }
195
+ },
196
+ children: components.map(({
197
+ did,
198
+ title,
199
+ logo
200
+ }) => {
201
+ let props = {};
202
+ if (blockletStoreURL) {
203
+ props = {
204
+ component: 'a',
205
+ href: getBlockletUrlOnStore({
206
+ did,
207
+ baseUrl: blockletStoreURL
208
+ })
209
+ };
210
+ }
211
+ return /*#__PURE__*/_jsxs(ListItem, {
212
+ sx: {
213
+ cursor: 'pointer',
214
+ paddingRight: '4px',
215
+ '&:hover': {
216
+ backgroundColor: 'secondary.main',
217
+ borderRadius: '4px'
218
+ }
219
+ },
220
+ disablePadding: true,
221
+ disableGutters: true,
222
+ alignItems: "flex-start",
223
+ target: "_blank",
224
+ ...props,
225
+ children: [/*#__PURE__*/_jsx(ListItemAvatar, {
226
+ children: /*#__PURE__*/_jsx(Avatar, {
227
+ alt: title,
228
+ variant: "rounded",
229
+ src: logo
230
+ })
231
+ }), /*#__PURE__*/_jsx(ListItemText, {
232
+ primary: /*#__PURE__*/_jsx(Typography, {
233
+ children: title
234
+ }),
235
+ secondary: /*#__PURE__*/_jsxs(Box, {
236
+ sx: {
237
+ display: 'flex',
238
+ justifyContent: 'space-between'
239
+ },
240
+ children: [/*#__PURE__*/_jsx(DidAddress, {
241
+ copyable: false,
242
+ did: did
243
+ }), /*#__PURE__*/_jsx(Typography, {
244
+ sx: {
245
+ color: 'primary.main'
246
+ },
247
+ children: state.unitPrice
248
+ })]
249
+ })
250
+ })]
251
+ }, did);
252
+ })
253
+ })]
254
+ }), /*#__PURE__*/_jsxs(Box, {
255
+ sx: {
256
+ display: 'flex',
257
+ flexDirection: 'column',
258
+ gap: '12px'
259
+ },
260
+ children: [/*#__PURE__*/_jsx(Typography, {
261
+ sx: {
262
+ fontWeight: 'bold'
263
+ },
264
+ children: t('common.price')
265
+ }), /*#__PURE__*/_jsx(List, {
266
+ dense: true,
267
+ disablePadding: true,
268
+ children: [{
269
+ label: t('checkout.estimatedCost'),
270
+ value: state.totalPrice,
271
+ hint: t('checkout.estimatedCostHint')
272
+ }].map(item => {
273
+ return /*#__PURE__*/_jsx(ListItem, {
274
+ sx: {
275
+ maxHeight: '28px'
276
+ },
277
+ disablePadding: true,
278
+ disableGutters: true,
279
+ secondaryAction: /*#__PURE__*/_jsx(Typography, {
280
+ color: "primary.main",
281
+ sx: {
282
+ paddingRight: '4px'
283
+ },
284
+ children: item.value
285
+ }),
286
+ children: /*#__PURE__*/_jsx(ListItemText, {
287
+ primary: /*#__PURE__*/_jsxs(_Fragment, {
288
+ children: [!item.hint && /*#__PURE__*/_jsx(Typography, {
289
+ children: item.label
290
+ }), item.hint && /*#__PURE__*/_jsx(Box, {
291
+ component: "span",
292
+ sx: {
293
+ display: 'flex',
294
+ alignItems: 'center'
295
+ },
296
+ children: /*#__PURE__*/_jsx(Tooltip, {
297
+ title: item.hint,
298
+ placement: "right",
299
+ children: /*#__PURE__*/_jsxs(Box, {
300
+ component: "span",
301
+ sx: {
302
+ display: 'flex',
303
+ alignItems: 'center',
304
+ cursor: 'pointer'
305
+ },
306
+ children: [/*#__PURE__*/_jsx(Typography, {
307
+ children: item.label
308
+ }), /*#__PURE__*/_jsx(InfoIcon, {
309
+ fontSize: "small",
310
+ sx: {
311
+ marginLeft: '2px'
312
+ }
313
+ })]
314
+ })
315
+ })
316
+ })]
317
+ })
318
+ })
319
+ }, item.label);
320
+ })
321
+ })]
322
+ })]
323
+ }), /*#__PURE__*/_jsx(Box, {
324
+ sx: {
325
+ width: '100%',
326
+ '& .cko-container': {
327
+ minWidth: '100% !important',
328
+ maxWidth: '100% !important'
329
+ },
330
+ '& .cko-payment': {
331
+ gap: '24px'
332
+ },
333
+ '& .cko-payment-contact': {
334
+ gap: '12px',
335
+ '& >div': {
336
+ marginBottom: 0
337
+ }
338
+ },
339
+ '& .cko-payment-form': {
340
+ marginTop: 0
341
+ },
342
+ '& .cko-payment-methods': {
343
+ gap: '12px',
344
+ marginTop: 0,
345
+ '&>p': {
346
+ marginBottom: 0
347
+ }
348
+ },
349
+ '& .cko-payment-submit': {
350
+ marginTop: 0,
351
+ '& button': {
352
+ fontSize: '1rem !important'
353
+ }
354
+ }
355
+ },
356
+ children: /*#__PURE__*/_jsx(CheckoutForm, {
357
+ id: checkoutSessionId,
358
+ mode: "inline-minimal",
359
+ onPaid: handlePaid,
360
+ onChange: handleChange
361
+ })
362
+ })]
363
+ });
364
+ }
@@ -4,8 +4,7 @@ import styled from '@emotion/styled';
4
4
  import SmallCircleProgress from '../small-circle-progress';
5
5
 
6
6
  // autoGrowth 逐渐增长到相应步骤所需的时间
7
- import { jsx as _jsx } from "react/jsx-runtime";
8
- import { jsxs as _jsxs } from "react/jsx-runtime";
7
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
9
8
  export default function ProgressMessage({
10
9
  steps,
11
10
  stepIndex,
@@ -1,8 +1,7 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import styled from '@emotion/styled';
3
3
  import CircularProgress from '@mui/material/CircularProgress';
4
- import { jsx as _jsx } from "react/jsx-runtime";
5
- import { jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
5
  export default function SmallCircleProgress({
7
6
  value,
8
7
  size,
@@ -13,7 +13,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
15
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
17
17
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
18
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
19
19
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -15,7 +15,7 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
15
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
16
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
17
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
19
19
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
20
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
21
21
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = CheckoutOnDemand;
7
+ var _DID = _interopRequireDefault(require("@arcblock/ux/lib/DID"));
8
+ var _formatError = _interopRequireDefault(require("@blocklet/launcher-util/es/format-error"));
9
+ var _util = require("@blocklet/launcher-util/lib/util");
10
+ var _paymentReact = require("@blocklet/payment-react");
11
+ var _InfoOutlined = _interopRequireDefault(require("@mui/icons-material/InfoOutlined"));
12
+ var _material = require("@mui/material");
13
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
14
+ var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
15
+ var _ahooks = require("ahooks");
16
+ var _propTypes = _interopRequireDefault(require("prop-types"));
17
+ var _useAsync = _interopRequireDefault(require("react-use/lib/useAsync"));
18
+ var _useMobile = _interopRequireDefault(require("../../use-mobile"));
19
+ var _jsxRuntime = require("react/jsx-runtime");
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
25
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
+ function CheckoutOnDemand(_ref) {
27
+ let {
28
+ launchSessionId,
29
+ handlePaid,
30
+ components,
31
+ blockletStoreURL,
32
+ api,
33
+ connectApi,
34
+ checkoutPath,
35
+ session,
36
+ t,
37
+ locale
38
+ } = _ref;
39
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
40
+ sx: {
41
+ display: 'flex',
42
+ justifyContent: 'center'
43
+ },
44
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentReact.PaymentProvider, {
45
+ session: session,
46
+ connect: connectApi,
47
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
48
+ api: api,
49
+ launchSessionId: launchSessionId,
50
+ handlePaid: handlePaid,
51
+ checkoutPath: checkoutPath,
52
+ components: components,
53
+ blockletStoreURL: blockletStoreURL,
54
+ t: t,
55
+ locale: locale
56
+ })
57
+ })
58
+ });
59
+ }
60
+ const propTypes = {
61
+ launchSessionId: _propTypes.default.string.isRequired,
62
+ handlePaid: _propTypes.default.func.isRequired,
63
+ components: _propTypes.default.array.isRequired,
64
+ blockletStoreURL: _propTypes.default.string.isRequired,
65
+ t: _propTypes.default.func.isRequired,
66
+ locale: _propTypes.default.string.isRequired,
67
+ api: _propTypes.default.object.isRequired,
68
+ checkoutPath: _propTypes.default.string.isRequired
69
+ };
70
+ CheckoutOnDemand.propTypes = _objectSpread(_objectSpread({}, propTypes), {}, {
71
+ connectApi: _propTypes.default.func.isRequired,
72
+ session: _propTypes.default.object.isRequired
73
+ });
74
+ Component.propTypes = propTypes;
75
+ function Component(_ref2) {
76
+ let {
77
+ launchSessionId,
78
+ handlePaid,
79
+ components: tempComponents,
80
+ blockletStoreURL,
81
+ api,
82
+ checkoutPath,
83
+ t,
84
+ locale
85
+ } = _ref2;
86
+ const {
87
+ getCurrency
88
+ } = (0, _paymentReact.usePaymentContext)();
89
+ const [state, setState] = (0, _ahooks.useSetState)({
90
+ unitPrice: '',
91
+ totalPrice: ''
92
+ });
93
+ const {
94
+ isMobile
95
+ } = (0, _useMobile.default)();
96
+ const components = (tempComponents || []).reduce((acc, x) => {
97
+ if (acc.findIndex(y => y.did === x.did) === -1) {
98
+ acc.push(x);
99
+ }
100
+ return acc;
101
+ }, []).sort((x, y) => {
102
+ if (x.title > y.title) {
103
+ return 1;
104
+ }
105
+ if (x.title < y.title) {
106
+ return -1;
107
+ }
108
+ return 0;
109
+ });
110
+ const quantity = (components === null || components === void 0 ? void 0 : components.length) || 1;
111
+ const checkoutState = (0, _useAsync.default)(async () => {
112
+ const {
113
+ data
114
+ } = await api.post(checkoutPath, {
115
+ launchSessionId
116
+ });
117
+ return {
118
+ checkoutSessionId: data.checkoutSessionId,
119
+ price: data.price
120
+ };
121
+ });
122
+ if (checkoutState.loading) {
123
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {});
124
+ }
125
+ if (checkoutState.error) {
126
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Alert, {
127
+ severity: "error",
128
+ children: (0, _formatError.default)(checkoutState.error)
129
+ });
130
+ }
131
+ const {
132
+ checkoutSessionId,
133
+ price
134
+ } = checkoutState.value;
135
+ const handleChange = function handleChange() {
136
+ let {
137
+ payment_currency: currencyId
138
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
139
+ try {
140
+ var _totalPrice, _unitPrice;
141
+ const currency = getCurrency(currencyId);
142
+ const UNIT_LABEL_PLACEHOLDER = 'UNIT_LABEL_TEMPLATES';
143
+ let totalPrice = (0, _paymentReact.formatPrice)(price, currency, UNIT_LABEL_PLACEHOLDER, quantity, true, locale);
144
+ totalPrice = (_totalPrice = totalPrice) === null || _totalPrice === void 0 ? void 0 : _totalPrice.replace(new RegExp("".concat(UNIT_LABEL_PLACEHOLDER, "\\s+\\/*")), '');
145
+ let unitPrice = (0, _paymentReact.formatPrice)(price, currency, UNIT_LABEL_PLACEHOLDER, 1, true, locale);
146
+ unitPrice = (_unitPrice = unitPrice) === null || _unitPrice === void 0 ? void 0 : _unitPrice.replace(new RegExp("".concat(UNIT_LABEL_PLACEHOLDER, "\\s+\\/*")), '');
147
+ setState({
148
+ unitPrice,
149
+ totalPrice
150
+ });
151
+ } catch (error) {
152
+ console.error('calculate failed error', error);
153
+ }
154
+ };
155
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
156
+ sx: {
157
+ display: 'flex',
158
+ flexDirection: 'row',
159
+ justifyContent: 'space-between',
160
+ gap: isMobile ? '32px' : '64px',
161
+ height: '100%',
162
+ width: '100%',
163
+ '@media (max-width: 1200px)': {
164
+ flexDirection: 'column',
165
+ justifyContent: 'flex-start'
166
+ }
167
+ },
168
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
169
+ sx: {
170
+ display: 'flex',
171
+ flexDirection: 'column',
172
+ gap: '24px',
173
+ height: '100%',
174
+ width: '100%'
175
+ },
176
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
177
+ sx: {
178
+ display: 'flex',
179
+ flexDirection: 'column',
180
+ gap: '12px'
181
+ },
182
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.Typography, {
183
+ sx: {
184
+ fontWeight: 'bold'
185
+ },
186
+ children: [(components === null || components === void 0 ? void 0 : components.length) <= 1 && t('purchase.componentCount', {
187
+ count: components === null || components === void 0 ? void 0 : components.length
188
+ }), (components === null || components === void 0 ? void 0 : components.length) > 1 && t('purchase.componentsCount', {
189
+ count: components === null || components === void 0 ? void 0 : components.length
190
+ })]
191
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.List, {
192
+ dense: true,
193
+ disablePadding: true,
194
+ sx: {
195
+ maxHeight: '480px',
196
+ overflowY: 'auto',
197
+ '&::-webkit-scrollbar': {
198
+ width: '6px'
199
+ },
200
+ '&::-webkit-scrollbar-track': {
201
+ backgroundColor: 'transparent'
202
+ },
203
+ '&::-webkit-scrollbar-thumb': {
204
+ backgroundColor: '#ccc',
205
+ borderRadius: '3px'
206
+ },
207
+ '@media (max-width: 1200px)': {
208
+ maxHeight: 'unset'
209
+ }
210
+ },
211
+ children: components.map(_ref3 => {
212
+ let {
213
+ did,
214
+ title,
215
+ logo
216
+ } = _ref3;
217
+ let props = {};
218
+ if (blockletStoreURL) {
219
+ props = {
220
+ component: 'a',
221
+ href: (0, _util.getBlockletUrlOnStore)({
222
+ did,
223
+ baseUrl: blockletStoreURL
224
+ })
225
+ };
226
+ }
227
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_material.ListItem, _objectSpread(_objectSpread({
228
+ sx: {
229
+ cursor: 'pointer',
230
+ paddingRight: '4px',
231
+ '&:hover': {
232
+ backgroundColor: 'secondary.main',
233
+ borderRadius: '4px'
234
+ }
235
+ },
236
+ disablePadding: true,
237
+ disableGutters: true,
238
+ alignItems: "flex-start",
239
+ target: "_blank"
240
+ }, props), {}, {
241
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItemAvatar, {
242
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Avatar, {
243
+ alt: title,
244
+ variant: "rounded",
245
+ src: logo
246
+ })
247
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItemText, {
248
+ primary: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
249
+ children: title
250
+ }),
251
+ secondary: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
252
+ sx: {
253
+ display: 'flex',
254
+ justifyContent: 'space-between'
255
+ },
256
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_DID.default, {
257
+ copyable: false,
258
+ did: did
259
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
260
+ sx: {
261
+ color: 'primary.main'
262
+ },
263
+ children: state.unitPrice
264
+ })]
265
+ })
266
+ })]
267
+ }), did);
268
+ })
269
+ })]
270
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
271
+ sx: {
272
+ display: 'flex',
273
+ flexDirection: 'column',
274
+ gap: '12px'
275
+ },
276
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
277
+ sx: {
278
+ fontWeight: 'bold'
279
+ },
280
+ children: t('common.price')
281
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.List, {
282
+ dense: true,
283
+ disablePadding: true,
284
+ children: [{
285
+ label: t('checkout.estimatedCost'),
286
+ value: state.totalPrice,
287
+ hint: t('checkout.estimatedCostHint')
288
+ }].map(item => {
289
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItem, {
290
+ sx: {
291
+ maxHeight: '28px'
292
+ },
293
+ disablePadding: true,
294
+ disableGutters: true,
295
+ secondaryAction: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
296
+ color: "primary.main",
297
+ sx: {
298
+ paddingRight: '4px'
299
+ },
300
+ children: item.value
301
+ }),
302
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.ListItemText, {
303
+ primary: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
304
+ children: [!item.hint && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
305
+ children: item.label
306
+ }), item.hint && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
307
+ component: "span",
308
+ sx: {
309
+ display: 'flex',
310
+ alignItems: 'center'
311
+ },
312
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
313
+ title: item.hint,
314
+ placement: "right",
315
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
316
+ component: "span",
317
+ sx: {
318
+ display: 'flex',
319
+ alignItems: 'center',
320
+ cursor: 'pointer'
321
+ },
322
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Typography, {
323
+ children: item.label
324
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_InfoOutlined.default, {
325
+ fontSize: "small",
326
+ sx: {
327
+ marginLeft: '2px'
328
+ }
329
+ })]
330
+ })
331
+ })
332
+ })]
333
+ })
334
+ })
335
+ }, item.label);
336
+ })
337
+ })]
338
+ })]
339
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Box.default, {
340
+ sx: {
341
+ width: '100%',
342
+ '& .cko-container': {
343
+ minWidth: '100% !important',
344
+ maxWidth: '100% !important'
345
+ },
346
+ '& .cko-payment': {
347
+ gap: '24px'
348
+ },
349
+ '& .cko-payment-contact': {
350
+ gap: '12px',
351
+ '& >div': {
352
+ marginBottom: 0
353
+ }
354
+ },
355
+ '& .cko-payment-form': {
356
+ marginTop: 0
357
+ },
358
+ '& .cko-payment-methods': {
359
+ gap: '12px',
360
+ marginTop: 0,
361
+ '&>p': {
362
+ marginBottom: 0
363
+ }
364
+ },
365
+ '& .cko-payment-submit': {
366
+ marginTop: 0,
367
+ '& button': {
368
+ fontSize: '1rem !important'
369
+ }
370
+ }
371
+ },
372
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentReact.CheckoutForm, {
373
+ id: checkoutSessionId,
374
+ mode: "inline-minimal",
375
+ onPaid: handlePaid,
376
+ onChange: handleChange
377
+ })
378
+ })]
379
+ });
380
+ }
@@ -16,7 +16,7 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
16
16
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
17
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
18
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
19
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
20
20
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
21
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
22
22
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -15,7 +15,7 @@ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(
15
15
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
16
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
17
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
19
19
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
20
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
21
21
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-ux",
3
- "version": "2.2.53",
3
+ "version": "2.2.55",
4
4
  "description": "Launcher UX lib",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -44,19 +44,23 @@
44
44
  "react": ">=18.1.0"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.23.9",
48
- "@babel/core": "^7.23.9",
49
- "@babel/preset-env": "^7.23.9",
50
- "@babel/preset-react": "^7.23.3",
47
+ "@babel/cli": "^7.24.1",
48
+ "@babel/core": "^7.24.3",
49
+ "@babel/preset-env": "^7.24.3",
50
+ "@babel/preset-react": "^7.24.1",
51
51
  "@storybook/react": "^6.5.16",
52
52
  "babel-plugin-inline-react-svg": "^2.0.2",
53
53
  "glob": "^10.3.10"
54
54
  },
55
55
  "dependencies": {
56
- "@arcblock/ux": "^2.9.29",
56
+ "@arcblock/ux": "^2.9.57",
57
+ "@blocklet/launcher-util": "2.2.55",
58
+ "@blocklet/payment-react": "^1.13.190",
57
59
  "@emotion/styled": "^11.11.0",
58
- "@mui/icons-material": "^5.15.8",
59
- "@mui/material": "^5.15.7"
60
+ "@mui/icons-material": "^5.15.14",
61
+ "@mui/material": "^5.15.14",
62
+ "ahooks": "^3.7.10",
63
+ "react-use": "^17.5.0"
60
64
  },
61
65
  "exports": {
62
66
  ".": {
@@ -88,5 +92,5 @@
88
92
  "require": "./lib/use-mobile/index.js"
89
93
  }
90
94
  },
91
- "gitHead": "9438d2bb74c7eb19567e0fc86d78f43357287851"
95
+ "gitHead": "83daa20f7a51626f804cc9e4f54cdcd90d51e2d8"
92
96
  }