@blocklet/launcher-workflow 2.0.10 → 2.0.12

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.
Files changed (2) hide show
  1. package/lib/checkout.js +24 -16
  2. package/package.json +9 -9
package/lib/checkout.js CHANGED
@@ -85,6 +85,7 @@ function CheckoutPage() {
85
85
  } = (0, _session.useSessionContext)();
86
86
  const [showAgreement, setShowAgreement] = (0, _react.useState)(false);
87
87
  const [showPayment, setShowPayment] = (0, _react.useState)(false);
88
+ const [paying, setPaying] = (0, _react.useState)(false);
88
89
  const [agree, setAgree] = (0, _react.useState)(false);
89
90
  const [showPaidDialog, setShowPaidDialog] = (0, _useSetState.default)({
90
91
  open: false,
@@ -139,27 +140,34 @@ function CheckoutPage() {
139
140
  const switchPayment = method => {
140
141
  setPaymentMethod(method);
141
142
  };
143
+ const handleCancelPay = () => {
144
+ setShowPayment(false);
145
+ setPaying(false);
146
+ };
142
147
  const handlePay = async () => {
143
148
  if (session.user) {
144
149
  setShowPayment(true);
150
+ setPaying(true);
145
151
  return;
146
152
  }
147
- if (!(session !== null && session !== void 0 && session.user)) {
148
- const paymentTokenURL = (0, _urlJoin.default)(didPayPrefix, "/did/purchase/token?productId=".concat(planId, "&paymentMethodId=").concat(paymentMethod._id));
149
- const {
150
- data
151
- } = await api.get(paymentTokenURL);
152
- session.login((results, decrypt) => {
153
+ setPaying(true);
154
+ const paymentTokenURL = (0, _urlJoin.default)(didPayPrefix, "/did/purchase/token?productId=".concat(planId, "&paymentMethodId=").concat(paymentMethod._id));
155
+ const {
156
+ data
157
+ } = await api.get(paymentTokenURL);
158
+ session.login({
159
+ onSuccess: (results, decrypt) => {
153
160
  const [, purchaseResult] = results;
154
161
  return handlePaid(purchaseResult, decrypt);
155
- }, {
162
+ },
163
+ onCancel: () => handleCancelPay(),
164
+ extraParams: {
156
165
  nw: data.url,
157
166
  forceConnected: false,
158
167
  saveConnect: false
159
- });
160
- }
168
+ }
169
+ });
161
170
  };
162
- const handleCancelPay = () => setShowPayment(false);
163
171
  const handlePaid = async _ref => {
164
172
  let {
165
173
  nftId
@@ -171,7 +179,7 @@ function CheckoutPage() {
171
179
  open: true,
172
180
  nftId
173
181
  });
174
- setShowPayment(false);
182
+ handleCancelPay();
175
183
  return;
176
184
  }
177
185
  searchParams.set('launchType', 'serverless');
@@ -180,11 +188,11 @@ function CheckoutPage() {
180
188
  pathname: (0, _urlJoin.default)(routerPrefix, "/launch/".concat(nftId)),
181
189
  search: searchParams.toString()
182
190
  });
183
- setShowPayment(false);
191
+ handleCancelPay();
184
192
  };
185
193
  const handlePayFailed = () => {
186
194
  // TODO: Toast 错误
187
- setShowPayment(false);
195
+ handleCancelPay(false);
188
196
  };
189
197
  const calculateTotalPayment = prices => {
190
198
  if (!paymentMethod) {
@@ -310,15 +318,15 @@ function CheckoutPage() {
310
318
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
311
319
  className: "actions",
312
320
  children: [isMobile && /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.default, {
313
- loading: showPayment,
321
+ loading: paying,
314
322
  className: "button-previous",
315
323
  variant: "outlined",
316
324
  onClick: () => navigate(-1),
317
325
  children: t('common.previous')
318
326
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.default, {
319
- loading: showPayment,
327
+ loading: paying,
320
328
  className: "button-pay",
321
- disabled: showPayment || !planId || !paymentMethod || !agree,
329
+ disabled: paying || showPayment || !planId || !paymentMethod || !agree,
322
330
  variant: "contained",
323
331
  onClick: handlePay,
324
332
  children: t('common.pay')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-workflow",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "Purchase components for Launcher UI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -36,13 +36,13 @@
36
36
  "react": ">=18.1.0"
37
37
  },
38
38
  "dependencies": {
39
- "@arcblock/did-connect": "^2.5.16",
40
- "@arcblock/icons": "^2.5.16",
41
- "@arcblock/license": "^2.5.16",
42
- "@arcblock/ux": "^2.5.16",
43
- "@blocklet/launcher-layout": "2.0.10",
44
- "@blocklet/launcher-util": "2.0.10",
45
- "@blocklet/launcher-ux": "2.0.10",
39
+ "@arcblock/did-connect": "^2.5.17",
40
+ "@arcblock/icons": "^2.5.17",
41
+ "@arcblock/license": "^2.5.17",
42
+ "@arcblock/ux": "^2.5.17",
43
+ "@blocklet/launcher-layout": "2.0.12",
44
+ "@blocklet/launcher-util": "2.0.12",
45
+ "@blocklet/launcher-ux": "2.0.12",
46
46
  "@did-pay/react": "^1.9.46",
47
47
  "@emotion/react": "^11.10.6",
48
48
  "@emotion/styled": "^11.10.6",
@@ -72,5 +72,5 @@
72
72
  "@babel/preset-react": "^7.18.6",
73
73
  "babel-plugin-inline-react-svg": "^2.0.2"
74
74
  },
75
- "gitHead": "e9fa27a72da394ca198138b12efc2de73b6393d8"
75
+ "gitHead": "f9cbe9df62edd3bd16799dcea8388a9ca48574ae"
76
76
  }