@blocklet/launcher-workflow 2.0.3 → 2.0.4

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 +22 -12
  2. package/package.json +21 -21
package/lib/checkout.js CHANGED
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _jsCookie = _interopRequireDefault(require("js-cookie"));
9
8
  var _urlJoin = _interopRequireDefault(require("url-join"));
10
9
  var _reactRouterDom = require("react-router-dom");
11
10
  var _styled = _interopRequireDefault(require("@emotion/styled"));
@@ -84,6 +83,7 @@ function CheckoutPage() {
84
83
  } = (0, _session.useSessionContext)();
85
84
  const [paying, setPaying] = (0, _react.useState)(false);
86
85
  const [showAgreement, setShowAgreement] = (0, _react.useState)(false);
86
+ const [showPayment, setShowPayment] = (0, _react.useState)(false);
87
87
  const [agree, setAgree] = (0, _react.useState)(false);
88
88
  const navigate = (0, _reactRouterDom.useNavigate)();
89
89
  const {
@@ -132,22 +132,32 @@ function CheckoutPage() {
132
132
  const switchPayment = method => {
133
133
  setPaymentMethod(method);
134
134
  };
135
- const handlePay = () => {
136
- if (!(session !== null && session !== void 0 && session.user)) {
137
- session.login(() => setPaying(true));
135
+ const handlePay = async () => {
136
+ if (session.user) {
137
+ setShowPayment(true);
138
138
  return;
139
139
  }
140
140
  setPaying(true);
141
+ if (!(session !== null && session !== void 0 && session.user)) {
142
+ const paymentTokenURL = (0, _urlJoin.default)(didPayPrefix, "/did/purchase/token?productId=".concat(planId, "&paymentMethodId=").concat(paymentMethod._id));
143
+ const {
144
+ data
145
+ } = await api.get(paymentTokenURL);
146
+ session.login((results, decrypt) => {
147
+ const [, purchaseResult] = results;
148
+ return handlePaid(purchaseResult, decrypt);
149
+ }, {
150
+ nw: data.url,
151
+ forceConnected: false,
152
+ saveConnect: false
153
+ });
154
+ }
141
155
  };
142
156
  const handleCancelPay = () => setPaying(false);
143
- const handlePaid = async (_ref, decrypt) => {
157
+ const handlePaid = async _ref => {
144
158
  let {
145
- nftId,
146
- launchToken
159
+ nftId
147
160
  } = _ref;
148
- if (launchToken) {
149
- _jsCookie.default.set('launch-token', decrypt(launchToken));
150
- }
151
161
  const nftState = await (0, _util.getAsset)(window.blocklet.CHAIN_HOST, nftId);
152
162
  if ((nftState.tags || []).includes(_constant.NFT_TYPE_SERVERLESS)) {
153
163
  searchParams.set('launchType', 'serverless');
@@ -285,13 +295,13 @@ function CheckoutPage() {
285
295
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.default, {
286
296
  loading: paying,
287
297
  className: "button-pay",
288
- disabled: paying || !planId || !paymentMethod || !agree,
298
+ disabled: paying || showPayment || !planId || !paymentMethod || !agree,
289
299
  variant: "contained",
290
300
  onClick: handlePay,
291
301
  children: t('common.pay')
292
302
  })
293
303
  })]
294
- }), paying && /*#__PURE__*/(0, _jsxRuntime.jsx)(_payment.default, {
304
+ }), showPayment && /*#__PURE__*/(0, _jsxRuntime.jsx)(_payment.default, {
295
305
  baseURL: didPayPrefix,
296
306
  method: paymentMethod,
297
307
  userDid: session === null || session === void 0 ? void 0 : (_session$user = session.user) === null || _session$user === void 0 ? void 0 : _session$user.did,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/launcher-workflow",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Purchase components for Launcher UI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -36,24 +36,24 @@
36
36
  "react": ">=18.1.0"
37
37
  },
38
38
  "dependencies": {
39
- "@arcblock/did-connect": "^2.4.68",
40
- "@arcblock/icons": "^2.4.68",
41
- "@arcblock/license": "^2.4.68",
42
- "@arcblock/ux": "^2.4.68",
43
- "@blocklet/launcher-layout": "2.0.3",
44
- "@blocklet/launcher-util": "2.0.3",
45
- "@blocklet/launcher-ux": "2.0.3",
46
- "@did-pay/react": "^1.9.38",
47
- "@emotion/react": "^11.10.5",
48
- "@emotion/styled": "^11.10.5",
49
- "@mui/icons-material": "^5.11.0",
50
- "@mui/material": "^5.11.8",
51
- "@ocap/util": "^1.18.39",
39
+ "@arcblock/did-connect": "^2.5.10",
40
+ "@arcblock/icons": "^2.5.10",
41
+ "@arcblock/license": "^2.5.10",
42
+ "@arcblock/ux": "^2.5.10",
43
+ "@blocklet/launcher-layout": "2.0.4",
44
+ "@blocklet/launcher-util": "2.0.4",
45
+ "@blocklet/launcher-ux": "2.0.4",
46
+ "@did-pay/react": "^1.9.41",
47
+ "@emotion/react": "^11.10.6",
48
+ "@emotion/styled": "^11.10.6",
49
+ "@mui/icons-material": "^5.11.11",
50
+ "@mui/material": "^5.11.13",
51
+ "@ocap/util": "^1.18.58",
52
52
  "@splidejs/react-splide": "^0.7.12",
53
53
  "@splidejs/splide": "^4.1.4",
54
54
  "@splidejs/splide-extension-grid": "^0.4.1",
55
- "@stripe/react-stripe-js": "^1.16.4",
56
- "@stripe/stripe-js": "^1.46.0",
55
+ "@stripe/react-stripe-js": "^1.16.5",
56
+ "@stripe/stripe-js": "^1.49.0",
57
57
  "axios": "^0.26.1",
58
58
  "flat": "^5.0.2",
59
59
  "js-cookie": "^3.0.1",
@@ -61,16 +61,16 @@
61
61
  "lodash.throttle": "^4.1.1",
62
62
  "prop-types": "^15.8.1",
63
63
  "react-lottie-player": "^1.5.4",
64
- "react-router-dom": "^6.8.1",
64
+ "react-router-dom": "^6.9.0",
65
65
  "react-use": "^17.4.0",
66
66
  "url-join": "^4.0.1"
67
67
  },
68
68
  "devDependencies": {
69
- "@babel/cli": "^7.20.7",
70
- "@babel/core": "^7.20.12",
69
+ "@babel/cli": "^7.21.0",
70
+ "@babel/core": "^7.21.3",
71
71
  "@babel/preset-env": "^7.20.2",
72
72
  "@babel/preset-react": "^7.18.6",
73
- "babel-plugin-inline-react-svg": "^2.0.1"
73
+ "babel-plugin-inline-react-svg": "^2.0.2"
74
74
  },
75
- "gitHead": "a296cb39be055fc2797a360505bfc7b662b09b92"
75
+ "gitHead": "201f0d84547fb0c09c3cc2484d72bb0f84b5842b"
76
76
  }