@blocklet/launcher-workflow 2.1.20 → 2.1.21

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/lib/checkout.js CHANGED
@@ -21,6 +21,8 @@ var _useSetState = _interopRequireDefault(require("react-use/lib/useSetState"));
21
21
  var _dsbridge = _interopRequireDefault(require("dsbridge"));
22
22
  var _urlJoin = _interopRequireDefault(require("url-join"));
23
23
  var _confirm = _interopRequireDefault(require("@arcblock/ux/lib/Dialog/confirm"));
24
+ var _formatError = _interopRequireDefault(require("@blocklet/launcher-util/lib/format-error"));
25
+ var _launchResultMessage = _interopRequireDefault(require("@blocklet/launcher-layout/lib/launch-result-message"));
24
26
  var _agreement = _interopRequireDefault(require("./components/agreement"));
25
27
  var _checkbox = _interopRequireDefault(require("./components/checkbox"));
26
28
  var _layout = _interopRequireDefault(require("./components/layout"));
@@ -92,6 +94,7 @@ function CheckoutPage(_ref) {
92
94
  } = (0, _session.useSessionContext)();
93
95
  const [params] = (0, _reactRouterDom.useSearchParams)();
94
96
  const [state, setState] = (0, _useSetState.default)({
97
+ error: '',
95
98
  showAgreement: false,
96
99
  showPayment: false,
97
100
  showAgreeHint: false,
@@ -132,32 +135,27 @@ function CheckoutPage(_ref) {
132
135
  });
133
136
  const enableBlockletAgreement = !!blocklet;
134
137
  const context = (0, _useAsync.default)(async () => {
135
- try {
136
- const [{
137
- data: {
138
- data: paymentMethods
139
- }
140
- }, {
141
- data: {
142
- data: plan
143
- }
144
- }] = await Promise.all([api.get('/payment-methods'), api.get("/plans/".concat(state.planId))]);
145
- if (paymentMethods.length > 0 && !state.paymentMethod) {
146
- setState({
147
- paymentMethod: paymentMethods[0]._id
148
- });
138
+ const [{
139
+ data: {
140
+ data: paymentMethods
141
+ }
142
+ }, {
143
+ data: {
144
+ data: plan
149
145
  }
150
- return {
151
- paymentMethods,
152
- plan
153
- };
154
- } catch (error) {
155
- console.error('load data failed:', error);
156
- return {
157
- paymentMethods: [],
158
- plan: null
159
- };
146
+ }] = await Promise.all([api.get('/payment-methods'), api.get("/plans/".concat(state.planId))]);
147
+ if (!plan || paymentMethods.length === 0) {
148
+ throw new Error(t('purchase.noProducts'));
160
149
  }
150
+ if (paymentMethods.length > 0 && !state.paymentMethod) {
151
+ setState({
152
+ paymentMethod: paymentMethods[0]._id
153
+ });
154
+ }
155
+ return {
156
+ paymentMethods,
157
+ plan
158
+ };
161
159
  });
162
160
 
163
161
  // 用户退出的时候自动重新创建启动会话
@@ -261,7 +259,7 @@ function CheckoutPage(_ref) {
261
259
  const {
262
260
  paymentMethods,
263
261
  plan
264
- } = context.loading ? {} : context.value;
262
+ } = context.value || {};
265
263
  const paymentMethod = paymentMethods === null || paymentMethods === void 0 ? void 0 : paymentMethods.find(x => x._id === state.paymentMethod);
266
264
  const providerName = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.provider.name;
267
265
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, {
@@ -269,8 +267,14 @@ function CheckoutPage(_ref) {
269
267
  enableBlockletAgreement: enableBlockletAgreement,
270
268
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_header.default, {
271
269
  title: t('checkout.pageTitle')
272
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_body.default, {
273
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
270
+ }), context.error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_body.default, {
271
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_launchResultMessage.default, {
272
+ variant: "error",
273
+ title: t('common.error'),
274
+ subTitle: (0, _formatError.default)(context.error)
275
+ })
276
+ }), !context.error && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
277
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_body.default, {
274
278
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
275
279
  className: "header",
276
280
  children: t('common.details')
@@ -298,106 +302,106 @@ function CheckoutPage(_ref) {
298
302
  className: "price",
299
303
  children: (0, _util2.getPrice)(plan.prices, providerName)
300
304
  })]
301
- })]
302
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
303
- className: "divider"
304
- }), context.loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
305
- className: "skeleton",
306
- sx: {
307
- width: '100%',
308
- height: '100%'
309
- }
310
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
311
- className: "total-order space",
312
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
313
- children: t('checkout.orderTotal')
314
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
315
- children: (0, _util2.getPrice)((plan === null || plan === void 0 ? void 0 : plan.prices) || [], providerName)
316
- })]
317
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
318
- className: "total-payment space",
319
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
320
- children: t('checkout.paymentTotal')
321
305
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
322
- children: calculateTotalPayment((plan === null || plan === void 0 ? void 0 : plan.prices) || [])
323
- })]
324
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
325
- className: "payment-method space",
326
- children: context.loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
306
+ className: "divider"
307
+ }), context.loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
327
308
  className: "skeleton",
328
309
  sx: {
329
310
  width: '100%',
330
311
  height: '100%'
331
312
  }
332
313
  }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
333
- className: "body",
314
+ className: "total-order space",
334
315
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
335
- className: "payment-method__title",
336
- children: t('checkout.paymentMethod.title')
316
+ children: t('checkout.orderTotal')
337
317
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
338
- className: "payment-method__list",
339
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
340
- container: true,
341
- spacing: 3,
342
- justifyContent: "flex-start",
343
- children: paymentMethods.map(method => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
344
- item: true,
345
- xs: 12,
346
- sm: 12,
347
- md: 3,
348
- lg: 2,
349
- xl: 2,
350
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkbox.default, {
351
- label: method.currency.displayName[locale] || method.currency.displayName.en,
352
- checked: state.paymentMethod === method._id,
353
- onClick: () => switchPayment(method._id)
354
- })
355
- }, method._id))
356
- })
318
+ children: (0, _util2.getPrice)((plan === null || plan === void 0 ? void 0 : plan.prices) || [], providerName)
357
319
  })]
358
- })
359
- })]
360
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_footer.default, {
361
- className: "footer",
362
- children: [enableBlockletAgreement && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
363
- className: "agreement",
364
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkbox.default, {
365
- checked: state.agreed,
366
- showHint: state.showAgreeHint,
367
- onClick: () => toggleAgreement(),
368
- label: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
369
- style: {
370
- display: 'flex',
371
- alignItems: 'center'
372
- },
373
- children: [t('common.agreeTo'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
374
- className: "agreement-label",
375
- onClick: e => {
376
- e.stopPropagation();
377
- setState({
378
- showAgreement: true
379
- });
380
- },
381
- children: t('checkout.agreement', {
382
- name: (0, _util.getBlockletDisplayName)(blocklet)
320
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
321
+ className: "total-payment space",
322
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
323
+ children: t('checkout.paymentTotal')
324
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
325
+ children: calculateTotalPayment((plan === null || plan === void 0 ? void 0 : plan.prices) || [])
326
+ })]
327
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
328
+ className: "payment-method space",
329
+ children: context.loading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Skeleton.default, {
330
+ className: "skeleton",
331
+ sx: {
332
+ width: '100%',
333
+ height: '100%'
334
+ }
335
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
336
+ className: "body",
337
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
338
+ className: "payment-method__title",
339
+ children: t('checkout.paymentMethod.title')
340
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
341
+ className: "payment-method__list",
342
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
343
+ container: true,
344
+ spacing: 3,
345
+ justifyContent: "flex-start",
346
+ children: paymentMethods.map(method => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Grid.default, {
347
+ item: true,
348
+ xs: 12,
349
+ sm: 12,
350
+ md: 3,
351
+ lg: 2,
352
+ xl: 2,
353
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkbox.default, {
354
+ label: method.currency.displayName[locale] || method.currency.displayName.en,
355
+ checked: state.paymentMethod === method._id,
356
+ onClick: () => switchPayment(method._id)
357
+ })
358
+ }, method._id))
383
359
  })
384
360
  })]
385
361
  })
386
- })
387
- }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
388
- className: "actions",
389
- children: [isMobile && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.default, {
390
- className: "button-previous",
391
- variant: "outlined",
392
- onClick: () => navigate(-1),
393
- children: t('common.previous')
394
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.default, {
395
- loading: state.paying,
396
- className: "button-pay",
397
- disabled: state.paying || state.showPayment || !state.planId || !state.paymentMethod,
398
- variant: "contained",
399
- onClick: handlePay,
400
- children: t('common.pay')
362
+ })]
363
+ }), !context.loading && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_footer.default, {
364
+ className: "footer",
365
+ children: [enableBlockletAgreement && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
366
+ className: "agreement",
367
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_checkbox.default, {
368
+ checked: state.agreed,
369
+ showHint: state.showAgreeHint,
370
+ onClick: () => toggleAgreement(),
371
+ label: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
372
+ style: {
373
+ display: 'flex',
374
+ alignItems: 'center'
375
+ },
376
+ children: [t('common.agreeTo'), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
377
+ className: "agreement-label",
378
+ onClick: e => {
379
+ e.stopPropagation();
380
+ setState({
381
+ showAgreement: true
382
+ });
383
+ },
384
+ children: t('checkout.agreement', {
385
+ name: (0, _util.getBlockletDisplayName)(blocklet)
386
+ })
387
+ })]
388
+ })
389
+ })
390
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
391
+ className: "actions",
392
+ children: [isMobile && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.default, {
393
+ className: "button-previous",
394
+ variant: "outlined",
395
+ onClick: () => navigate(-1),
396
+ children: t('common.previous')
397
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.default, {
398
+ loading: state.paying,
399
+ className: "button-pay",
400
+ disabled: state.paying || state.showPayment || !state.planId || !state.paymentMethod,
401
+ variant: "contained",
402
+ onClick: handlePay,
403
+ children: t('common.pay')
404
+ })]
401
405
  })]
402
406
  })]
403
407
  }), state.showPayment && /*#__PURE__*/(0, _jsxRuntime.jsx)(_payment.default, {
package/lib/locales/en.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module.exports = {
4
4
  common: {
5
+ error: 'Oops',
5
6
  agreeTo: 'Agree to the',
6
7
  agreement: 'Agreement',
7
8
  paymentMethod: 'Payment Method',
@@ -75,7 +76,7 @@ module.exports = {
75
76
  title: 'Starting Space',
76
77
  error: {
77
78
  launchFailed: 'Start Space Failed',
78
- notFound: 'No Spacebeing started'
79
+ notFound: 'No Space being started'
79
80
  }
80
81
  },
81
82
  redeem: {
@@ -102,6 +103,7 @@ module.exports = {
102
103
  selectSpaceHint: 'Already have dedicated space? Click here to select >',
103
104
  morePlanPrompt: 'Flip the page to see more plans',
104
105
  redeem: 'Select purchased space',
106
+ noProducts: 'No products available for purchase, please check your payment-kit config',
105
107
  dialog: {
106
108
  title: 'Purchase Blocklet Space NFT',
107
109
  scan: 'Scan the QR code below with your DID wallet to complete purchase',
package/lib/locales/zh.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module.exports = {
4
4
  common: {
5
+ error: '哎呀',
5
6
  agreeTo: '同意',
6
7
  agreement: '用户协议',
7
8
  agreementHint: '请勾选同意用户协议后继续',
@@ -101,6 +102,7 @@ module.exports = {
101
102
  selectSpaceHint: '已有专用空间?点击这里选择 >',
102
103
  morePlanPrompt: '翻页看更多方案',
103
104
  redeem: '我已购买空间',
105
+ noProducts: '没有可购买的商品,请检查 PaymentKit 的配置',
104
106
  dialog: {
105
107
  title: '购买 Blocklet Server NFT',
106
108
  scan: '用您的 DID 钱包扫描下面的二维码完成购买',
package/lib/purchase.js CHANGED
@@ -22,6 +22,7 @@ var _useMeasure = _interopRequireDefault(require("react-use/lib/useMeasure"));
22
22
  var _useSetState = _interopRequireDefault(require("react-use/lib/useSetState"));
23
23
  var _urlJoin = _interopRequireDefault(require("url-join"));
24
24
  require("@splidejs/splide/dist/css/splide.min.css");
25
+ var _launchResultMessage = _interopRequireDefault(require("@blocklet/launcher-layout/lib/launch-result-message"));
25
26
  var _formatError = _interopRequireDefault(require("@blocklet/launcher-util/lib/format-error"));
26
27
  var _layout = _interopRequireDefault(require("./components/layout"));
27
28
  var _body = _interopRequireDefault(require("./components/layout/body"));
@@ -179,6 +180,13 @@ function PurchasePage(_ref) {
179
180
  data: paymentMethods
180
181
  }
181
182
  }] = _ref2;
183
+ if (data.length === 0 || paymentMethods.length === 0) {
184
+ setState({
185
+ loading: false,
186
+ error: t('purchase.noProducts')
187
+ });
188
+ return;
189
+ }
182
190
  const plans = (data || []).sort((a, b) => b.weight - a.weight);
183
191
  setState({
184
192
  plans,
@@ -340,12 +348,16 @@ function PurchasePage(_ref) {
340
348
  style: {
341
349
  justifyContent: 'center'
342
350
  },
343
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
351
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
344
352
  style: {
345
353
  flex: 1,
346
354
  position: 'relative'
347
355
  },
348
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
356
+ children: [state.error && /*#__PURE__*/(0, _jsxRuntime.jsx)(_launchResultMessage.default, {
357
+ variant: "error",
358
+ title: t('common.error'),
359
+ subTitle: state.error
360
+ }), !state.error && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
349
361
  className: "container-inner",
350
362
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_compactLayout.default, {
351
363
  bottom: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_footer.default, {
@@ -387,7 +399,7 @@ function PurchasePage(_ref) {
387
399
  paymentMethod
388
400
  }),
389
401
  className: "toc"
390
- }), state.plans.length > 0 && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactSplide.Splide, {
402
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactSplide.Splide, {
391
403
  extensions: {
392
404
  Grid: _splideExtensionGrid.Grid
393
405
  },
@@ -463,7 +475,7 @@ function PurchasePage(_ref) {
463
475
  })
464
476
  })
465
477
  })
466
- })
478
+ })]
467
479
  })
468
480
  }), state.showRedeem && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
469
481
  open: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-workflow",
3
- "version": "2.1.20",
3
+ "version": "2.1.21",
4
4
  "description": "Purchase components for Launcher UI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -40,9 +40,9 @@
40
40
  "@arcblock/license": "^2.5.50",
41
41
  "@arcblock/react-hooks": "^2.5.50",
42
42
  "@arcblock/ux": "^2.5.50",
43
- "@blocklet/launcher-layout": "2.1.20",
44
- "@blocklet/launcher-util": "2.1.20",
45
- "@blocklet/launcher-ux": "2.1.20",
43
+ "@blocklet/launcher-layout": "2.1.21",
44
+ "@blocklet/launcher-util": "2.1.21",
45
+ "@blocklet/launcher-ux": "2.1.21",
46
46
  "@blocklet/payment": "^1.12.9",
47
47
  "@emotion/react": "^11.11.0",
48
48
  "@emotion/styled": "^11.11.0",
@@ -75,5 +75,5 @@
75
75
  "babel-plugin-inline-react-svg": "^2.0.2",
76
76
  "jest": "^27.5.1"
77
77
  },
78
- "gitHead": "6570634a807d34d81addfaf7485e8ca6dd7e6fac"
78
+ "gitHead": "4e839ce423d8960a67bcebe701fdf5b555b0ee88"
79
79
  }