@blocklet/launcher-workflow 1.8.13 → 1.8.16

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.
@@ -47,7 +47,7 @@ function PaymentMethod(_ref) {
47
47
  t
48
48
  } = (0, _locale.useLocaleContext)();
49
49
 
50
- if (type === _constant.CURRENCY_TYPE.crypto) {
50
+ if (type === _constant.PAYMENT_METHODS.crypto) {
51
51
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, _objectSpread(_objectSpread({}, props), {}, {
52
52
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_MonetizationOn.default, {
53
53
  className: "payment-icon"
@@ -65,5 +65,5 @@ function PaymentMethod(_ref) {
65
65
  const Container = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n justify-content: center;\n align-items: center;\n\n .payment-icon {\n margin-right: 4px;\n }\n"])));
66
66
 
67
67
  PaymentMethod.propTypes = {
68
- type: _propTypes.default.oneOf([_constant.CURRENCY_TYPE.crypto, _constant.CURRENCY_TYPE.fiat]).isRequired
68
+ type: _propTypes.default.oneOf([_constant.PAYMENT_METHODS.crypto, _constant.PAYMENT_METHODS.stripe, _constant.PAYMENT_METHODS.fiat]).isRequired
69
69
  };
package/lib/locales/en.js CHANGED
@@ -20,7 +20,8 @@ module.exports = {
20
20
  redirecting: 'Redirecting',
21
21
  cancel: 'Cancel',
22
22
  confirm: 'Confirm',
23
- launching: 'Launching'
23
+ launching: 'Launching',
24
+ loadFailed: 'Failed to load the resource, please refresh the page and try again.'
24
25
  },
25
26
  plan: {
26
27
  title: 'Select Blocklet Server Plan',
package/lib/locales/zh.js CHANGED
@@ -20,7 +20,8 @@ module.exports = {
20
20
  redirecting: '跳转中',
21
21
  cancel: '取消',
22
22
  confirm: '同意',
23
- launching: '启动中'
23
+ launching: '启动中',
24
+ loadFailed: '加载资源失败, 请刷新页面重试。'
24
25
  },
25
26
  plan: {
26
27
  title: '选择节点类型',
package/lib/purchase.js CHANGED
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _react = require("react");
9
9
 
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+
10
12
  var _reactRouterDom = require("react-router-dom");
11
13
 
12
14
  var _reactUse = require("react-use");
@@ -81,6 +83,91 @@ const formatTokenPrice = token => "".concat((0, _util.fromUnitToToken)(token.val
81
83
 
82
84
  const formatFiatPrice = price => "".concat(price.symbol || price.unit).concat(price.value);
83
85
 
86
+ function PlanList(_ref) {
87
+ let {
88
+ paymentMethod,
89
+ onSelect,
90
+ onLoaded
91
+ } = _ref;
92
+ const {
93
+ api
94
+ } = (0, _request.default)();
95
+ const [plan, setPlan] = (0, _react.useState)(null);
96
+ const {
97
+ t
98
+ } = (0, _locale.useLocaleContext)();
99
+ const selectPlan = (0, _react.useCallback)(value => {
100
+ setPlan(value);
101
+ onSelect(value); // eslint-disable-next-line react-hooks/exhaustive-deps
102
+ }, []);
103
+ const plansState = (0, _reactUse.useAsync)(async () => {
104
+ const {
105
+ data
106
+ } = await api.get("/plans?paymentMethod=".concat(paymentMethod._id));
107
+ const plans = (data || []).map(item => {
108
+ item.prices = {
109
+ crypto: formatTokenPrice(item.prices.crypto),
110
+ fiat: formatFiatPrice(item.prices.fiat)
111
+ };
112
+ return item;
113
+ }).sort((itemX, itemY) => itemX.weight - itemY.weight);
114
+ onLoaded();
115
+ return {
116
+ plans
117
+ };
118
+ }, [paymentMethod]);
119
+ (0, _react.useEffect)(() => {
120
+ if (plansState.loading === false && plansState.value) {
121
+ const {
122
+ plans
123
+ } = plansState.value;
124
+
125
+ if (plans.length > 0) {
126
+ selectPlan(plans[0]);
127
+ }
128
+ }
129
+ }, [plansState, selectPlan]);
130
+
131
+ if (plansState.loading) {
132
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Center.default, {
133
+ relative: "parent",
134
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {})
135
+ });
136
+ }
137
+
138
+ if (plansState.error) {
139
+ console.error('load plans error', plansState.error);
140
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
141
+ type: "error",
142
+ children: t('plan.loadListFailed')
143
+ });
144
+ }
145
+
146
+ const {
147
+ plans
148
+ } = plansState.value;
149
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Container, {
150
+ className: "select-plan small-select-plan-".concat(plans.length),
151
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
152
+ className: "selector-container container-padding",
153
+ children: plans.length ? plans.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_plan.default, {
154
+ paymentMethod: paymentMethod.type,
155
+ onClick: () => selectPlan(item),
156
+ selected: plan && plan._id === item._id,
157
+ data: item
158
+ }, item._id)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Empty.default, {
159
+ children: t('plan.noPlan')
160
+ })
161
+ })
162
+ });
163
+ }
164
+
165
+ PlanList.propTypes = {
166
+ paymentMethod: _propTypes.default.any.isRequired,
167
+ onSelect: _propTypes.default.func.isRequired,
168
+ onLoaded: _propTypes.default.func.isRequired
169
+ };
170
+
84
171
  function PurchasePage() {
85
172
  const {
86
173
  api,
@@ -100,83 +187,59 @@ function PurchasePage() {
100
187
  const [paying, setPaying] = (0, _react.useState)(false);
101
188
  const [paymentInfo, setPaymentInfo] = (0, _react.useState)(null);
102
189
  const [buttonInFix, setButtonInFix] = (0, _react.useState)(false);
103
- const [paymentMethod, setPaymentType] = (0, _react.useState)(_constant.CURRENCY_TYPE.crypto);
190
+ const [paymentMethod, setPaymentMethod] = (0, _react.useState)(null);
104
191
  const routerPrefix = (0, _router.usePrefix)();
192
+ const [planLoaded, setPlanLoaded] = (0, _react.useState)(false);
105
193
  const isMobile = (0, _useMediaQuery.default)(theme => theme.breakpoints.down('md'));
106
194
  const userDid = query.get('userDid') || (0, _lodash.default)(session, 'user.did');
107
195
  const isEmbed = !!query.get('blocklet_meta_url');
108
196
  (0, _react.useEffect)(() => {
109
- if (!session.loading && paymentMethod === _constant.CURRENCY_TYPE.fiat && !userDid) {
197
+ if (!session.loading && paymentMethod && paymentMethod === _constant.CURRENCY_TYPE.fiat && !userDid) {
110
198
  session.login();
111
199
  } // eslint-disable-next-line
112
200
 
113
201
  }, [paymentMethod, userDid]);
114
- const paymentTypes = [{
115
- label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentMethod.default, {
116
- type: _constant.CURRENCY_TYPE.crypto
117
- }),
118
- value: _constant.CURRENCY_TYPE.crypto
119
- }, {
120
- label: /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentMethod.default, {
121
- type: _constant.CURRENCY_TYPE.fiat
122
- }),
123
- value: _constant.CURRENCY_TYPE.fiat
124
- }];
125
- const plansState = (0, _reactUse.useAsync)(async () => {
202
+ const paymentMethodsState = (0, _reactUse.useAsync)(async () => {
126
203
  const {
127
204
  data
128
- } = await api.get('/plans');
129
- const plans = (data || []).map(item => {
130
- item.prices = {
131
- crypto: formatTokenPrice(item.prices.crypto),
132
- fiat: formatFiatPrice(item.prices.fiat)
133
- };
205
+ } = await api.get('/payment-methods');
206
+ const methods = (data || []).map(item => {
207
+ item.label = /*#__PURE__*/(0, _jsxRuntime.jsx)(_paymentMethod.default, {
208
+ type: item.type
209
+ });
210
+ item.value = item.type;
134
211
  return item;
135
- }).sort((itemX, itemY) => itemX.weight - itemY.weight);
136
- return {
137
- plans
138
- };
139
- });
140
- (0, _react.useEffect)(() => {
141
- if (plansState.loading === false) {
142
- setPaymentType(_constant.CURRENCY_TYPE.crypto);
143
-
144
- if (plansState.value) {
145
- const {
146
- plans
147
- } = plansState.value;
148
-
149
- if (plans.length > 0) {
150
- selectPlan(plans[0]);
151
- }
212
+ }).sort(itemX => {
213
+ if (itemX.type === _constant.PAYMENT_METHODS.crypto) {
214
+ return -1;
152
215
  }
153
- }
154
- }, [plansState.loading, plansState.value]);
155
216
 
156
- if (plansState.loading) {
217
+ return 1;
218
+ });
219
+ setPaymentMethod(methods[0]);
220
+ return methods;
221
+ });
222
+
223
+ if (paymentMethodsState.loading) {
157
224
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Center.default, {
158
225
  relative: "parent",
159
226
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Spinner.default, {})
160
227
  });
161
228
  }
162
229
 
163
- if (plansState.error) {
164
- console.error('load plans error', plansState.error);
230
+ if (paymentMethodsState.error) {
231
+ console.error('load plans error', paymentMethodsState.error);
165
232
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Alert.default, {
166
233
  type: "error",
167
234
  children: t('plan.loadListFailed')
168
235
  });
169
236
  }
170
237
 
171
- const {
172
- plans
173
- } = plansState.value;
174
-
175
- const handlePaid = (_ref, decrypt) => {
238
+ const handlePaid = (_ref2, decrypt) => {
176
239
  let {
177
240
  nftId,
178
241
  launchToken
179
- } = _ref;
242
+ } = _ref2;
180
243
 
181
244
  if (launchToken) {
182
245
  _jsCookie.default.set('launch-token', decrypt(launchToken));
@@ -190,10 +253,6 @@ function PurchasePage() {
190
253
  setPaying(false);
191
254
  };
192
255
 
193
- const selectPlan = value => {
194
- setPlan(value);
195
- };
196
-
197
256
  const getPurchaseParams = () => {
198
257
  const obj = {
199
258
  productId: plan ? plan._id : null,
@@ -227,11 +286,11 @@ function PurchasePage() {
227
286
 
228
287
  setPaying(true);
229
288
 
230
- if (payment === _constant.CURRENCY_TYPE.crypto) {
289
+ if (payment === _constant.PAYMENT_METHODS.crypto) {
231
290
  return;
232
291
  }
233
292
 
234
- if (payment === _constant.CURRENCY_TYPE.fiat) {
293
+ if (payment === _constant.PAYMENT_METHODS.fiat) {
235
294
  try {
236
295
  const {
237
296
  data
@@ -260,6 +319,12 @@ function PurchasePage() {
260
319
  navigate(-1);
261
320
  };
262
321
 
322
+ const handleSelectPaymenMethod = value => {
323
+ setPlanLoaded(false);
324
+ const method = paymentMethodsState.value.find(item => item.type === value);
325
+ setPaymentMethod(method);
326
+ };
327
+
263
328
  return (
264
329
  /*#__PURE__*/
265
330
  // layout-fix-container for compatibility with lower versions of safari, do not remove this className
@@ -275,10 +340,10 @@ function PurchasePage() {
275
340
  className: "page-body-article",
276
341
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_submit.default, {
277
342
  disabled: paying,
278
- onConfirm: () => handlePay(paymentMethod),
343
+ onConfirm: () => handlePay(paymentMethod.type),
279
344
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_compactLayout.default, {
280
345
  onBottomFix: type => setButtonInFix(type === 'fix'),
281
- bottom: plans.length ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
346
+ bottom: planLoaded ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
282
347
  className: "button-container container-padding ".concat(buttonInFix ? 'has-shadow' : ''),
283
348
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.default, {
284
349
  onClick: () => handleRedeem(),
@@ -289,7 +354,7 @@ function PurchasePage() {
289
354
  },
290
355
  children: t('common.redeem')
291
356
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Button.default, {
292
- onClick: () => handlePay(paymentMethod),
357
+ onClick: () => handlePay(paymentMethod.type),
293
358
  disabled: paying,
294
359
  variant: "contained",
295
360
  color: "primary",
@@ -302,32 +367,23 @@ function PurchasePage() {
302
367
  title: t('plan.title'),
303
368
  subTitle: t('plan.subTitle'),
304
369
  onClickBack: disabledBack.includes('purchase') ? '' : clickBack
305
- }), plans.length ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
370
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
306
371
  className: "select-payment",
307
372
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Tabs.default, {
308
- tabs: paymentTypes,
309
- current: paymentMethod,
310
- onChange: e => setPaymentType(e)
311
- })
312
- }) : '', /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
313
- className: "select-plan small-select-plan-".concat(plans.length),
314
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
315
- className: "selector-container container-padding",
316
- children: plans.length ? plans.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_plan.default, {
317
- paymentMethod: paymentMethod,
318
- onClick: () => selectPlan(item),
319
- selected: plan && plan._id === item._id,
320
- data: item
321
- }, item._id)) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Empty.default, {
322
- children: t('plan.noPlan')
323
- })
373
+ tabs: paymentMethodsState.value,
374
+ current: paymentMethod.type,
375
+ onChange: e => handleSelectPaymenMethod(e)
324
376
  })
377
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PlanList, {
378
+ paymentMethod: paymentMethod,
379
+ onSelect: v => setPlan(v),
380
+ onLoaded: () => setPlanLoaded(true)
325
381
  })]
326
382
  })
327
383
  })
328
384
  })
329
385
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Connect.default, {
330
- open: paying && paymentMethod === _constant.CURRENCY_TYPE.crypto,
386
+ open: paying && paymentMethod.type === _constant.PAYMENT_METHODS.crypto,
331
387
  popup: true,
332
388
  action: "purchase",
333
389
  checkFn: createRequest().get,
@@ -355,7 +411,7 @@ function PurchasePage() {
355
411
  );
356
412
  }
357
413
 
358
- const Container = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n\n .select-payment {\n display: flex;\n justify-content: center;\n align-items: center;\n padding-top: 30px;\n }\n\n .select-plan {\n margin: 48px auto 33px;\n\n ", " {\n margin: 30px auto;\n }\n &.small-select-plan-2 {\n max-width: 780px;\n }\n &.small-select-plan-0,\n &.small-select-plan-1 {\n max-width: 460px;\n }\n }\n\n .page-body {\n position: relative;\n flex: 1;\n margin-top: 0;\n }\n\n .page-body-article {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n overflow-y: auto;\n }\n\n .selector-container {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));\n gap: 24px;\n margin-top: 18px;\n }\n\n .button-container {\n display: flex;\n justify-content: center;\n align-items: center;\n padding-bottom: 15px;\n padding-top: 15px;\n > button {\n width: 200px;\n }\n &.has-shadow {\n box-shadow: 0px -1px 1px 0px rgba(168, 180, 197, 0.12);\n }\n }\n\n .container-padding {\n padding-left: 24px;\n padding-right: 24px;\n }\n"])), props => props.theme.breakpoints.down('md'));
414
+ const Container = _styled.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n .select-payment {\n display: flex;\n justify-content: center;\n align-items: center;\n padding-top: 30px;\n }\n .select-plan {\n margin: 48px auto 33px;\n ", " {\n margin: 30px auto;\n }\n &.small-select-plan-2 {\n max-width: 780px;\n }\n &.small-select-plan-0,\n &.small-select-plan-1 {\n max-width: 460px;\n }\n }\n .page-body {\n position: relative;\n flex: 1;\n margin-top: 0;\n }\n .page-body-article {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n overflow-y: auto;\n }\n .selector-container {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));\n gap: 24px;\n margin-top: 18px;\n }\n .button-container {\n display: flex;\n justify-content: center;\n align-items: center;\n padding-bottom: 15px;\n padding-top: 15px;\n > button {\n width: 200px;\n }\n &.has-shadow {\n box-shadow: 0px -1px 1px 0px rgba(168, 180, 197, 0.12);\n }\n }\n .container-padding {\n padding-left: 24px;\n padding-right: 24px;\n }\n"])), props => props.theme.breakpoints.down('md'));
359
415
 
360
416
  var _default = PurchasePage;
361
417
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-workflow",
3
- "version": "1.8.13",
3
+ "version": "1.8.16",
4
4
  "description": "Purchase components for Launcher UI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -37,13 +37,13 @@
37
37
  "react": ">=18.1.0"
38
38
  },
39
39
  "dependencies": {
40
- "@arcblock/did-connect": "^2.4.11",
41
- "@arcblock/icons": "^2.4.11",
42
- "@arcblock/license": "^2.4.11",
43
- "@arcblock/ux": "^2.4.11",
44
- "@blocklet/launcher-layout": "1.8.13",
45
- "@blocklet/launcher-util": "1.8.13",
46
- "@blocklet/launcher-ux": "1.8.13",
40
+ "@arcblock/did-connect": "^2.4.13",
41
+ "@arcblock/icons": "^2.4.13",
42
+ "@arcblock/license": "^2.4.13",
43
+ "@arcblock/ux": "^2.4.13",
44
+ "@blocklet/launcher-layout": "1.8.16",
45
+ "@blocklet/launcher-util": "1.8.16",
46
+ "@blocklet/launcher-ux": "1.8.16",
47
47
  "@emotion/react": "^11.10.0",
48
48
  "@emotion/styled": "^11.10.0",
49
49
  "@mui/icons-material": "^5.8.4",
@@ -65,10 +65,10 @@
65
65
  },
66
66
  "devDependencies": {
67
67
  "@babel/cli": "^7.18.10",
68
- "@babel/core": "^7.18.10",
68
+ "@babel/core": "^7.18.13",
69
69
  "@babel/preset-env": "^7.18.10",
70
70
  "@babel/preset-react": "^7.18.6",
71
71
  "babel-plugin-inline-react-svg": "^2.0.1"
72
72
  },
73
- "gitHead": "1c94f8c40e780b3a11d0c340f539f2a755a17c31"
73
+ "gitHead": "816f92ecb17b0b34c1990844df338197817d0e18"
74
74
  }