@arcblock/did-connect-react 3.4.0 → 3.4.2

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 (28) hide show
  1. package/lib/Connect/assets/locale.js +4 -2
  2. package/lib/Connect/components/login-item/connect-choose-list.js +120 -114
  3. package/lib/Connect/components/login-item/connect-provider-list.js +187 -180
  4. package/lib/Connect/components/login-item/login-method-item.js +63 -47
  5. package/lib/Connect/components/login-item/passkey-login-item.js +17 -15
  6. package/lib/Connect/components/login-item/wallet-login-options.js +42 -40
  7. package/lib/Connect/connect.js +116 -117
  8. package/lib/Connect/contexts/state.js +73 -64
  9. package/lib/Connect/hooks/provider-list.js +43 -33
  10. package/lib/Connect/hooks/token.js +121 -122
  11. package/lib/Connect/plugins/email/index.js +15 -12
  12. package/lib/Connect/plugins/email/list-item.js +19 -18
  13. package/lib/Passkey/actions.js +80 -75
  14. package/lib/package.json.js +1 -1
  15. package/package.json +5 -5
  16. package/src/Connect/assets/locale.js +2 -0
  17. package/src/Connect/components/login-item/connect-choose-list.jsx +12 -5
  18. package/src/Connect/components/login-item/connect-provider-list.jsx +11 -4
  19. package/src/Connect/components/login-item/login-method-item.jsx +24 -7
  20. package/src/Connect/components/login-item/passkey-login-item.jsx +3 -1
  21. package/src/Connect/components/login-item/wallet-login-options.jsx +3 -2
  22. package/src/Connect/connect.jsx +36 -35
  23. package/src/Connect/contexts/state.jsx +10 -0
  24. package/src/Connect/hooks/provider-list.js +43 -17
  25. package/src/Connect/hooks/token.js +13 -13
  26. package/src/Connect/plugins/email/index.jsx +3 -0
  27. package/src/Connect/plugins/email/list-item.jsx +3 -2
  28. package/src/Passkey/actions.jsx +5 -0
@@ -1,107 +1,108 @@
1
- import { jsx as t, jsxs as b, Fragment as qe } from "react/jsx-runtime";
2
- import { use as He, useRef as le, useState as Ve, useEffect as ue } from "react";
1
+ import { jsx as t, jsxs as b, Fragment as He } from "react/jsx-runtime";
2
+ import { use as Ve, useRef as ce, useState as Ye, useEffect as le } from "react";
3
3
  import e from "prop-types";
4
- import { Box as i, Skeleton as Ye, Divider as Ge } from "@mui/material";
5
- import { useUpdate as Ke, useSize as Qe, useCreation as u, useMount as de, useMemoizedFn as F, useDebounceFn as Xe, usePrevious as Je, useUpdateEffect as Ze } from "ahooks";
4
+ import { Box as i, Skeleton as Ge, Divider as Ke } from "@mui/material";
5
+ import { useUpdate as Qe, useSize as Xe, useCreation as u, useMount as ue, useMemoizedFn as F, useDebounceFn as Je, usePrevious as Ze, useUpdateEffect as $e } from "ahooks";
6
6
  import C from "lodash/noop";
7
- import $e from "lodash/isUndefined";
8
- import et from "@arcblock/ux/lib/CloseButton";
9
- import { DID_CONNECT_MEDIUM_WIDTH as N, LOGIN_PROVIDER_NAME as tt, DID_CONNECT_SMALL_WIDTH as ot, OAUTH_PROVIDER as j, LOGIN_PROVIDER as rt } from "@arcblock/ux/lib/Util/constant";
10
- import nt from "@arcblock/ux/lib/QRCode";
11
- import { DIDConnectFooter as it } from "@arcblock/ux/lib/DIDConnect";
12
- import { useTheme as st } from "@arcblock/ux/lib/Theme";
13
- import at from "@arcblock/ux/lib/DIDConnect/provider-icon";
7
+ import et from "lodash/isUndefined";
8
+ import tt from "@arcblock/ux/lib/CloseButton";
9
+ import { DID_CONNECT_MEDIUM_WIDTH as N, LOGIN_PROVIDER_NAME as ot, DID_CONNECT_SMALL_WIDTH as rt, OAUTH_PROVIDER as j, LOGIN_PROVIDER as nt } from "@arcblock/ux/lib/Util/constant";
10
+ import it from "@arcblock/ux/lib/QRCode";
11
+ import { DIDConnectFooter as st } from "@arcblock/ux/lib/DIDConnect";
12
+ import { useTheme as at } from "@arcblock/ux/lib/Theme";
13
+ import ct from "@arcblock/ux/lib/DIDConnect/provider-icon";
14
14
  import "@fontsource/lexend/400.css";
15
15
  import "@fontsource/lexend/600.css";
16
- import { SessionContext as ct } from "../Session/context.js";
17
- import { StateProvider as lt, useStateContext as ut } from "./contexts/state.js";
18
- import dt from "./components/login-item/connect-provider-list.js";
19
- import ft from "./components/auto-height.js";
20
- import mt from "./hooks/token.js";
21
- import { useOAuth as pt } from "../OAuth/context.js";
22
- import ht from "./components/connect-status.js";
23
- import { usePasskey as bt } from "../Passkey/context.js";
24
- import { CHECK_STATUS_INTERVAL as gt, API_DID_PREFIX as xt, BUSY_STATUS as w, DEFAULT_TIMEOUT as Ct } from "../constant.js";
16
+ import { SessionContext as lt } from "../Session/context.js";
17
+ import { StateProvider as ut, useStateContext as dt } from "./contexts/state.js";
18
+ import ft from "./components/login-item/connect-provider-list.js";
19
+ import mt from "./components/auto-height.js";
20
+ import pt from "./hooks/token.js";
21
+ import { useOAuth as ht } from "../OAuth/context.js";
22
+ import bt from "./components/connect-status.js";
23
+ import { usePasskey as gt } from "../Passkey/context.js";
24
+ import { CHECK_STATUS_INTERVAL as xt, API_DID_PREFIX as Ct, BUSY_STATUS as w, DEFAULT_TIMEOUT as yt } from "../constant.js";
25
25
  import "../utils.js";
26
- import yt from "./components/did-connect-title.js";
27
- import St from "./components/download-tips.js";
28
- import kt from "./hooks/provider-list.js";
29
- import wt from "./hooks/auth-url.js";
30
- import { getWalletDid as It } from "../User/use-did.js";
31
- import vt from "./fallback-connect.js";
32
- import { getWebWalletUrl as Pt } from "@arcblock/ux/lib/Util/wallet";
33
- function fe({
26
+ import St from "./components/did-connect-title.js";
27
+ import kt from "./components/download-tips.js";
28
+ import wt from "./hooks/provider-list.js";
29
+ import It from "./hooks/auth-url.js";
30
+ import { getWalletDid as vt } from "../User/use-did.js";
31
+ import Pt from "./fallback-connect.js";
32
+ import { getWebWalletUrl as _t } from "@arcblock/ux/lib/Util/wallet";
33
+ function de({
34
34
  hideCloseButton: y = !1,
35
35
  mode: p = "dialog",
36
36
  action: I,
37
37
  baseUrl: g = "",
38
38
  checkFn: v,
39
- checkInterval: P = gt,
40
- checkTimeout: _ = Ct * 1e3,
41
- prefix: D = xt,
39
+ checkInterval: P = xt,
40
+ checkTimeout: _ = yt * 1e3,
41
+ prefix: D = Ct,
42
42
  tokenKey: B = "_t_",
43
43
  locale: q = "en",
44
- encKey: me = "_ek_",
45
- autoConnect: pe = !0,
44
+ encKey: fe = "_ek_",
45
+ autoConnect: me = !0,
46
46
  forceConnected: H = !0,
47
- saveConnect: he = !0,
48
- useSocket: be = !0,
47
+ saveConnect: pe = !0,
48
+ useSocket: he = !0,
49
49
  allowWallet: V = !0,
50
- provider: ge = "",
50
+ provider: be = "",
51
51
  messages: d = {},
52
52
  passkeyBehavior: Y = "none",
53
- webWalletUrl: xe = Pt(),
54
- enabledConnectTypes: Ce = ["web", "mobile", ...Object.keys(j)],
53
+ webWalletUrl: ge = _t(),
54
+ enabledConnectTypes: xe = ["web", "mobile", ...Object.keys(j)],
55
55
  extraContent: G = null,
56
56
  disableSwitchApp: T = !1,
57
57
  magicToken: K = void 0,
58
- customItems: ye = [],
58
+ customItems: Ce = [],
59
59
  onClose: O = C,
60
60
  onError: Q = C,
61
61
  onSuccess: R = C,
62
62
  onRecreateSession: X = C,
63
- setColor: Se = C
63
+ setColor: ye = C
64
64
  }) {
65
- const A = st(), J = Ke(), ke = He(ct), we = It(ke?.session?.user), {
65
+ const A = at(), J = Qe(), Se = Ve(lt), ke = vt(Se?.session?.user), {
66
66
  t: Z,
67
- staticState: Ie,
67
+ staticState: we,
68
68
  connectState: s,
69
- extraParams: ve,
70
- currentAppInfo: Pe,
69
+ extraParams: Ie,
70
+ currentAppInfo: ve,
71
71
  currentAppColor: W,
72
72
  // 插件相关
73
73
  selectedPlugin: a,
74
74
  blocklet: $,
75
- masterBlocklet: _e,
75
+ masterBlocklet: Pe,
76
76
  showWalletOptions: f,
77
- setShowWalletOptions: De
78
- } = ut(), { state: o, generate: ee, cancelWhenScanned: Te } = mt({
77
+ setShowWalletOptions: _e,
78
+ lastLoginMethod: De
79
+ } = dt(), { state: o, generate: ee, cancelWhenScanned: Te } = pt({
79
80
  action: I,
80
81
  baseUrl: g,
81
82
  checkFn: v,
82
83
  checkInterval: P,
83
84
  checkTimeout: _,
84
- extraParams: ve,
85
+ extraParams: Ie,
85
86
  prefix: D,
86
87
  onError: Q,
87
88
  onSuccess: R,
88
89
  locale: q,
89
90
  tokenKey: B,
90
- encKey: me,
91
- autoConnect: pe,
92
- forceConnected: H === !0 ? we || !0 : H,
93
- saveConnect: he,
94
- useSocket: be,
95
- provider: ge
96
- }), z = le(!1), te = le(null), x = Qe(te), oe = u(() => x ? x.width < N - 50 : !0, [x, x?.width]), [re, Oe] = Ve(!1);
97
- de(() => {
91
+ encKey: fe,
92
+ autoConnect: me,
93
+ forceConnected: H === !0 ? ke || !0 : H,
94
+ saveConnect: pe,
95
+ useSocket: he,
96
+ provider: be
97
+ }), z = ce(!1), te = ce(null), x = Xe(te), oe = u(() => x ? x.width < N - 50 : !0, [x, x?.width]), [re, Oe] = Ye(!1);
98
+ ue(() => {
98
99
  Oe(x?.width < N - 50);
99
100
  });
100
- const { oauthState: c, setBaseUrl: Re } = pt(), { passkeyState: l, setTargetAppPid: Ae } = bt();
101
- de(() => {
101
+ const { oauthState: c, setBaseUrl: Re } = ht(), { passkeyState: l, setTargetAppPid: Ae } = gt();
102
+ ue(() => {
102
103
  Re(g), Ae($?.appPid), o.reset(), c.reset(), l.reset();
103
- }), ue(() => {
104
- Se(W);
104
+ }), le(() => {
105
+ ye(W);
105
106
  }, [W]);
106
107
  const We = u(() => ({
107
108
  confirm: d.confirm,
@@ -119,31 +120,32 @@ function fe({
119
120
  }), ze = F(() => {
120
121
  s?.retryConnect();
121
122
  }), Ee = F(() => {
122
- X(), c.reset(), l.reset(), a?.state?.reset(), Ie.current.cancelCount++, Te();
123
- }), { run: Ue } = Xe(
123
+ X(), c.reset(), l.reset(), a?.state?.reset(), we.current.cancelCount++, Te();
124
+ }), { run: Le } = Je(
124
125
  () => {
125
126
  z.current || o.status === "timeout" && (z.current = !0, o.reset(), ne(), z.current = !1);
126
127
  },
127
128
  { leading: !0, trailing: !1 }
128
129
  );
129
- ue(Ue, [o.status]);
130
- const Le = u(() => tt[s.chooseMethod] || "DID Wallet", [s.chooseMethod]), { providerList: Me, hideQRCode: m, hideChooseList: r, loadingProviderList: Fe } = kt({
130
+ le(Le, [o.status]);
131
+ const Me = u(() => ot[s.chooseMethod] || "DID Wallet", [s.chooseMethod]), { providerList: Ue, hideQRCode: m, hideChooseList: r, loadingProviderList: Fe } = wt({
131
132
  action: o.action,
132
133
  sourceAppPid: s?.sourceAppPid,
133
134
  allowWallet: V,
134
135
  passkeyBehavior: Y,
135
136
  mode: p,
136
- blocklet: s?.sourceAppPid ? _e : $,
137
- isSmallView: oe
138
- }), Ne = Je(s?.sourceAppPid);
139
- Ze(() => {
140
- $e(Ne) || ee();
137
+ blocklet: s?.sourceAppPid ? Pe : $,
138
+ isSmallView: oe,
139
+ lastLoginMethod: De
140
+ }), Ne = Ze(s?.sourceAppPid);
141
+ $e(() => {
142
+ et(Ne) || ee();
141
143
  }, [s?.sourceAppPid]);
142
144
  const n = (k) => {
143
145
  const h = A.spacing(k);
144
146
  return parseInt(h, 10);
145
147
  }, je = u(() => y ? null : /* @__PURE__ */ t(
146
- et,
148
+ tt,
147
149
  {
148
150
  onClose: O,
149
151
  sx: {
@@ -152,19 +154,17 @@ function fe({
152
154
  top: 14
153
155
  }
154
156
  }
155
- ), [y, O]);
156
- let ie = null;
157
- S && (ie = /* @__PURE__ */ t(
157
+ ), [y, O]), Be = /* @__PURE__ */ t(
158
158
  i,
159
159
  {
160
160
  sx: {
161
161
  flex: 1,
162
- display: "flex",
162
+ display: S ? "flex" : "none",
163
163
  alignItems: "center",
164
164
  justifyContent: "center"
165
165
  },
166
166
  children: /* @__PURE__ */ t(i, { children: /* @__PURE__ */ t(
167
- ht,
167
+ bt,
168
168
  {
169
169
  status: a?.state?.computedStatus || c.status || l.status || o.status,
170
170
  nextWorkflow: o.nextWorkflow,
@@ -175,30 +175,29 @@ function fe({
175
175
  messages: We,
176
176
  locale: q,
177
177
  className: "did-connect__auth-status auth-status",
178
- loadingIcon: s.chooseMethod ? /* @__PURE__ */ t(at, { provider: s.chooseMethod, sx: { color: "text.primary" } }) : null,
179
- chooseMethod: Le,
178
+ loadingIcon: s.chooseMethod ? /* @__PURE__ */ t(ct, { provider: s.chooseMethod, sx: { color: "text.primary" } }) : null,
179
+ chooseMethod: Me,
180
180
  hideRetry: s.chooseMethod === "email",
181
181
  hideBack: !!K
182
182
  }
183
183
  ) })
184
184
  }
185
- ));
186
- const se = wt({ disableSwitchApp: T, tokenState: o }), E = u(() => {
185
+ ), ie = It({ disableSwitchApp: T, tokenState: o }), E = u(() => {
187
186
  const k = A.mode === "dark" ? A.palette.grey[600] : "white";
188
- let h = r ? 240 - n(3) * 2 : 196 - n(2) * 2, M = r ? 3 : 2;
189
- return f && (M = 1, h += n(M) * 2), /* @__PURE__ */ t(
187
+ let h = r ? 240 - n(3) * 2 : 196 - n(2) * 2, U = r ? 3 : 2;
188
+ return f && (U = 1, h += n(U) * 2), /* @__PURE__ */ t(
190
189
  i,
191
190
  {
192
191
  className: "did-connect__qrcode",
193
192
  sx: {
194
- p: M,
193
+ p: U,
195
194
  width: (r ? 240 : 196) + n(1) * 2,
196
195
  height: (r ? 240 : 196) + n(1) * 2
197
196
  },
198
197
  children: o.url ? /* @__PURE__ */ t(
199
- nt,
198
+ it,
200
199
  {
201
- data: se,
200
+ data: ie,
202
201
  size: h,
203
202
  sx: {
204
203
  width: h + n(1) * 2,
@@ -220,7 +219,7 @@ function fe({
220
219
  }
221
220
  }
222
221
  ) : /* @__PURE__ */ t(
223
- Ye,
222
+ Ge,
224
223
  {
225
224
  animation: "wave",
226
225
  variant: "rectangular",
@@ -239,7 +238,7 @@ function fe({
239
238
  )
240
239
  }
241
240
  );
242
- }, [se, r, f]), Be = u(() => r ? "column-reverse" : !m && re ? "column" : "row", [r, re, m]), ae = u(() => E ? /* @__PURE__ */ t(
241
+ }, [ie, r, f]), qe = u(() => r ? "column-reverse" : !m && re ? "column" : "row", [r, re, m]), se = u(() => E ? /* @__PURE__ */ t(
243
242
  i,
244
243
  {
245
244
  sx: {
@@ -289,7 +288,7 @@ function fe({
289
288
  children: [
290
289
  Z("scanWithWallet1"),
291
290
  " ",
292
- /* @__PURE__ */ t(St, {}),
291
+ /* @__PURE__ */ t(kt, {}),
293
292
  " ",
294
293
  Z("scanWithWallet2")
295
294
  ]
@@ -299,13 +298,13 @@ function fe({
299
298
  }
300
299
  )
301
300
  }
302
- ) : null, [E, r, f]), U = /* @__PURE__ */ b(
301
+ ) : null, [E, r, f]), L = /* @__PURE__ */ b(
303
302
  i,
304
303
  {
305
304
  className: "did-connect__body",
306
305
  sx: {
307
306
  display: "flex",
308
- flexDirection: Be,
307
+ flexDirection: qe,
309
308
  justifyContent: "center",
310
309
  alignItems: "stretch",
311
310
  flex: 1,
@@ -314,10 +313,10 @@ function fe({
314
313
  px: r ? 2 : 0
315
314
  },
316
315
  children: [
317
- !S && !m ? /* @__PURE__ */ b(qe, { children: [
318
- ae,
316
+ !S && !m ? /* @__PURE__ */ b(He, { children: [
317
+ se,
319
318
  r ? null : /* @__PURE__ */ t(i, { children: /* @__PURE__ */ t(
320
- Ge,
319
+ Ke,
321
320
  {
322
321
  orientation: "vertical",
323
322
  sx: {
@@ -339,9 +338,9 @@ function fe({
339
338
  flex: 1
340
339
  },
341
340
  children: [
342
- ie,
341
+ Be,
343
342
  /* @__PURE__ */ t(
344
- dt,
343
+ ft,
345
344
  {
346
345
  slotProps: {
347
346
  root: {
@@ -356,17 +355,17 @@ function fe({
356
355
  tokenKey: B,
357
356
  onSuccess: R,
358
357
  passkeyBehavior: Y,
359
- webWalletUrl: xe,
358
+ webWalletUrl: ge,
360
359
  extraContent: G,
361
- enabledConnectTypes: Ce,
360
+ enabledConnectTypes: xe,
362
361
  onReset: ne,
363
362
  disableSwitchApp: T,
364
363
  forceUpdate: J,
365
364
  magicToken: K,
366
365
  baseUrl: g,
367
- customItems: ye,
368
- providerList: Me,
369
- qrcode: ae
366
+ customItems: Ce,
367
+ providerList: Ue,
368
+ qrcode: se
370
369
  }
371
370
  )
372
371
  ]
@@ -375,15 +374,15 @@ function fe({
375
374
  ]
376
375
  }
377
376
  );
378
- let L = U;
379
- a ? L = a.renderPlaceholder({
380
- fallback: U,
377
+ let M = L;
378
+ a ? M = a.renderPlaceholder({
379
+ fallback: L,
381
380
  forceUpdate: J,
382
381
  onSuccess: R,
383
382
  onError: Q
384
- }) : L = U;
385
- const ce = m || S ? ot : N;
386
- return Fe ? /* @__PURE__ */ t(vt, {}) : /* @__PURE__ */ b(
383
+ }) : M = L;
384
+ const ae = m || S ? rt : N;
385
+ return Fe ? /* @__PURE__ */ t(Pt, {}) : /* @__PURE__ */ b(
387
386
  i,
388
387
  {
389
388
  ref: te,
@@ -397,7 +396,7 @@ function fe({
397
396
  maxWidth: "100%",
398
397
  width: (
399
398
  // eslint-disable-next-line no-nested-ternary
400
- p === "drawer" ? "100%" : f ? ce - 20 : ce
399
+ p === "drawer" ? "100%" : f ? ae - 20 : ae
401
400
  ),
402
401
  transition: "width 0.2s ease-in-out",
403
402
  margin: "auto",
@@ -408,24 +407,24 @@ function fe({
408
407
  children: [
409
408
  /* @__PURE__ */ t(i, { "data-did-auth-url": o.url, sx: { display: "none" } }),
410
409
  /* @__PURE__ */ t(
411
- yt,
410
+ St,
412
411
  {
413
412
  title: d.title,
414
413
  description: d.scan,
415
414
  extraContent: G,
416
415
  disableSwitchApp: T,
417
416
  showWalletOptions: f,
418
- onBack: () => De(!1)
417
+ onBack: () => _e(!1)
419
418
  }
420
419
  ),
421
- /* @__PURE__ */ t(ft, { initHeight: 72, children: L }),
422
- /* @__PURE__ */ t(it, { currentAppInfo: Pe, currentAppColor: W }),
420
+ /* @__PURE__ */ t(mt, { initHeight: 72, children: M }),
421
+ /* @__PURE__ */ t(st, { currentAppInfo: ve, currentAppColor: W }),
423
422
  je
424
423
  ]
425
424
  }
426
425
  );
427
426
  }
428
- fe.propTypes = {
427
+ de.propTypes = {
429
428
  mode: e.oneOf(["dialog", "drawer", "page"]),
430
429
  action: e.string.isRequired,
431
430
  baseUrl: e.string,
@@ -447,7 +446,7 @@ fe.propTypes = {
447
446
  enabledConnectTypes: e.arrayOf(e.oneOf(["web", "mobile", ...Object.keys(j)])),
448
447
  webWalletUrl: e.string,
449
448
  allowWallet: e.bool,
450
- provider: e.oneOf([rt.WALLET, ...Object.keys(j), ""]),
449
+ provider: e.oneOf([nt.WALLET, ...Object.keys(j), ""]),
451
450
  hideCloseButton: e.bool,
452
451
  disableSwitchApp: e.bool,
453
452
  onClose: e.func,
@@ -458,12 +457,12 @@ fe.propTypes = {
458
457
  magicToken: e.string,
459
458
  customItems: e.arrayOf(e.node)
460
459
  };
461
- function _t({ testOnlyBorderColor: y = void 0, ...p }) {
460
+ function Dt({ testOnlyBorderColor: y = void 0, ...p }) {
462
461
  const { checkFn: I, extraParams: g = {}, blocklet: v, masterBlocklet: P, action: _, locale: D = "en" } = p;
463
462
  if (typeof I != "function")
464
463
  throw new Error("Cannot initialize did connect component without a fetchFn");
465
464
  return /* @__PURE__ */ t(
466
- lt,
465
+ ut,
467
466
  {
468
467
  blocklet: v,
469
468
  masterBlocklet: P,
@@ -483,11 +482,11 @@ function _t({ testOnlyBorderColor: y = void 0, ...p }) {
483
482
  boxSizing: "border-box"
484
483
  }
485
484
  },
486
- children: /* @__PURE__ */ t(fe, { ...p })
485
+ children: /* @__PURE__ */ t(de, { ...p })
487
486
  }
488
487
  );
489
488
  }
490
- _t.propTypes = {
489
+ Dt.propTypes = {
491
490
  checkFn: e.func.isRequired,
492
491
  extraParams: e.object,
493
492
  blocklet: e.object.isRequired,
@@ -497,5 +496,5 @@ _t.propTypes = {
497
496
  testOnlyBorderColor: e.string
498
497
  };
499
498
  export {
500
- _t as default
499
+ Dt as default
501
500
  };