@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,57 +1,64 @@
1
1
  import { jsx as O } from "react/jsx-runtime";
2
2
  import r from "prop-types";
3
- import { useState as S, use as E, useRef as W, useEffect as V, createContext as X } from "react";
3
+ import { useState as S, use as W, useRef as D, useEffect as V, createContext as X } from "react";
4
4
  import Y from "@arcblock/react-hooks/lib/useBrowser";
5
- import { useUpdate as Z, useCreation as i, useMemoizedFn as h, useLatest as _, useReactive as $, useSize as ee } from "ahooks";
6
- import x from "lodash/isUndefined";
7
- import te from "lodash/noop";
8
- import { Box as oe } from "@mui/material";
9
- import { translate as re } from "@arcblock/ux/lib/Locale/util";
10
- import { getMaster as D, getCurrentApp as ne } from "@arcblock/ux/lib/Util/federated";
11
- import { getDIDMotifInfo as se } from "@arcblock/did-motif";
12
- import { isEthereumDid as ie, getDIDColor as pe } from "@arcblock/ux/lib/Util";
13
- import ce from "../hooks/use-apps.js";
14
- import { SessionContext as ue } from "../../Session/context.js";
15
- import de from "../assets/locale.js";
16
- const R = X({
5
+ import { useUpdate as Z, useCreation as n, useMemoizedFn as h, useLatest as $, useReactive as ee, useSize as te } from "ahooks";
6
+ import E from "lodash/isUndefined";
7
+ import oe from "lodash/noop";
8
+ import { Box as re } from "@mui/material";
9
+ import { translate as ne } from "@arcblock/ux/lib/Locale/util";
10
+ import { getMaster as T, getCurrentApp as se } from "@arcblock/ux/lib/Util/federated";
11
+ import { getDIDMotifInfo as ie } from "@arcblock/did-motif";
12
+ import { isEthereumDid as ce, getDIDColor as pe } from "@arcblock/ux/lib/Util";
13
+ import { GA_LAST_LOGIN_METHOD as ue } from "@arcblock/ux/lib/withTracker/constant";
14
+ import ae from "../hooks/use-apps.js";
15
+ import { SessionContext as de } from "../../Session/context.js";
16
+ import le from "../assets/locale.js";
17
+ const x = X({
17
18
  isWalletWebview: !1,
18
19
  isMobile: !1,
19
20
  matchSmallScreen: !1,
20
21
  blocklet: null
21
- }), { Provider: ae, Consumer: We } = R;
22
- function le({
23
- children: T,
24
- blocklet: p,
22
+ }), { Provider: fe, Consumer: We } = x;
23
+ function me({
24
+ children: R,
25
+ blocklet: c,
25
26
  masterBlocklet: P = void 0,
26
- action: d,
27
+ action: a,
27
28
  extraParams: t = {},
28
- locale: a = "en",
29
+ locale: d = "en",
29
30
  testOnlyBorderColor: l = void 0,
30
- ...j
31
+ ...L
31
32
  }) {
32
- const w = Z(), [f, q] = S([]), [z, J] = S(!1), [m, N] = S(""), U = i(() => new Map(f.map((e) => [e.name, e])), [f]), k = h((e) => U.get(e)), B = _(m), L = h((e, s = {}) => re(de, e, a, "en", s)), g = E(ue), o = $({
33
+ const w = Z(), [f, j] = S([]), [N, q] = S(!1), [m, z] = S(""), G = n(() => new Map(f.map((e) => [e.name, e])), [f]), J = h((e) => G.get(e)), U = $(m), _ = h((e, i = {}) => ne(le, e, d, "en", i)), g = W(de), o = ee({
33
34
  sourceAppPid: void 0,
34
35
  status: "created",
35
36
  autoActiveWebview: !0,
36
37
  deeplink: void 0,
37
38
  chooseMethod: "",
38
- retryConnect: te
39
- }), F = W({
39
+ retryConnect: oe
40
+ }), k = D({
40
41
  cancelCount: 0
41
- }), n = Y(), { appInfoList: b, autoGenerateSourceAppPid: A, canSwitchApp: v } = ce({
42
- blocklet: p,
42
+ }), s = Y(), { appInfoList: b, autoGenerateSourceAppPid: A, canSwitchApp: v } = ae({
43
+ blocklet: c,
43
44
  connectState: o,
44
- action: d,
45
+ action: a,
45
46
  sourceAppPid: t?.sourceAppPid,
46
47
  enableSwitchApp: t?.forceSwitch || t?.enableSwitchApp
47
- }), C = W(null), M = ee(C), y = i(() => (M?.width || 0) < 500, [M?.width]), c = i(() => {
48
+ }), B = n(() => {
49
+ try {
50
+ return localStorage.getItem(ue);
51
+ } catch {
52
+ return "";
53
+ }
54
+ }, []), C = D(null), M = te(C), y = n(() => (M?.width || 0) < 500, [M?.width]), p = n(() => {
48
55
  if (v)
49
56
  return {
50
57
  ...t,
51
- sourceAppPid: x(o.sourceAppPid) ? A : o.sourceAppPid
58
+ sourceAppPid: E(o.sourceAppPid) ? A : o.sourceAppPid
52
59
  };
53
- const e = D(p)?.appPid, s = D(globalThis.blocklet)?.appPid;
54
- return g?.session?.user && (e === s || !e) ? x(t?.sourceAppPid) ? {
60
+ const e = T(c)?.appPid, i = T(globalThis.blocklet)?.appPid;
61
+ return g?.session?.user && (e === i || !e) ? E(t?.sourceAppPid) ? {
55
62
  ...t,
56
63
  sourceAppPid: g.session.user?.sourceAppPid
57
64
  } : t : {
@@ -62,70 +69,72 @@ function le({
62
69
  v,
63
70
  t,
64
71
  o.sourceAppPid,
65
- d,
72
+ a,
66
73
  A,
67
74
  g?.session?.user
68
- ]), G = i(() => {
75
+ ]), F = n(() => {
69
76
  const e = window?.navigator?.userAgent;
70
77
  return e.indexOf("Edge") > -1 || e.indexOf("Edg") > -1 ? "edge" : e.indexOf("Chrome") > -1 ? "chrome" : "unknown";
71
78
  }, []);
72
79
  V(() => {
73
- o.sourceAppPid = c.sourceAppPid;
74
- }, [c.sourceAppPid]);
80
+ o.sourceAppPid = p.sourceAppPid;
81
+ }, [p.sourceAppPid]);
75
82
  const H = h((e) => {
76
83
  o.status = e || "created";
77
- }), u = globalThis.blocklet ? ne(p) : globalThis.env, I = i(() => {
84
+ }), u = globalThis.blocklet ? se(c) : globalThis.env, I = n(() => {
78
85
  if (l)
79
86
  return l;
80
- const e = u.appPid, s = ie(e), Q = s ? void 0 : se(e);
81
- return s ? pe(e) : Q.color;
82
- }, [u.appId, l]), K = i(() => ({
83
- isWalletWebview: n.wallet || n.arcSphere,
84
- isMobile: n.mobile.any,
87
+ const e = u.appPid, i = ce(e), Q = i ? void 0 : ie(e);
88
+ return i ? pe(e) : Q.color;
89
+ }, [u.appId, l]), K = n(() => ({
90
+ isWalletWebview: s.wallet || s.arcSphere,
91
+ isMobile: s.mobile.any,
85
92
  matchSmallScreen: y,
86
93
  connectState: o,
87
- staticState: F,
94
+ staticState: k,
88
95
  reactiveState: o,
89
96
  appInfoList: b,
90
- extraParams: c,
91
- blocklet: p,
97
+ extraParams: p,
98
+ blocklet: c,
92
99
  masterBlocklet: P,
93
- browserBrand: G,
100
+ browserBrand: F,
94
101
  currentAppInfo: u,
95
102
  currentAppColor: I,
96
- t: L,
97
- locale: a,
98
- action: d,
103
+ t: _,
104
+ locale: d,
105
+ action: a,
99
106
  changeStatus: H,
100
- getPlugin: k,
101
- latestActivePlugin: B,
107
+ getPlugin: J,
108
+ latestActivePlugin: U,
102
109
  plugins: f,
103
- setPlugins: q,
110
+ setPlugins: j,
104
111
  selectedPlugin: m,
105
- setSelectedPlugin: N,
112
+ setSelectedPlugin: z,
106
113
  forceUpdate: w,
107
114
  // 控制钱包登录的显示
108
- showWalletOptions: z,
109
- setShowWalletOptions: J
115
+ showWalletOptions: N,
116
+ setShowWalletOptions: q,
117
+ // 用于记录上一次登录方式
118
+ lastLoginMethod: B
110
119
  }), [
111
- n.wallet,
112
- n.arcSphere,
113
- n.mobile.any,
120
+ s.wallet,
121
+ s.arcSphere,
122
+ s.mobile.any,
114
123
  y,
115
124
  JSON.stringify(o),
116
125
  JSON.stringify(b),
117
- JSON.stringify(c),
118
- p,
126
+ JSON.stringify(p),
127
+ c,
119
128
  P,
120
- a,
129
+ d,
121
130
  m,
122
131
  w,
123
132
  u,
124
133
  I
125
134
  ]);
126
- return /* @__PURE__ */ O(ae, { value: K, children: /* @__PURE__ */ O(oe, { ...j, ref: C, children: T }) });
135
+ return /* @__PURE__ */ O(fe, { value: K, children: /* @__PURE__ */ O(re, { ...L, ref: C, children: R }) });
127
136
  }
128
- le.propTypes = {
137
+ me.propTypes = {
129
138
  children: r.any.isRequired,
130
139
  blocklet: r.object.isRequired,
131
140
  masterBlocklet: r.object,
@@ -135,11 +144,11 @@ le.propTypes = {
135
144
  testOnlyBorderColor: r.string
136
145
  };
137
146
  function xe() {
138
- return E(R);
147
+ return W(x);
139
148
  }
140
149
  export {
141
150
  We as StateConsumer,
142
- R as StateContext,
143
- le as StateProvider,
151
+ x as StateContext,
152
+ me as StateProvider,
144
153
  xe as useStateContext
145
154
  };
@@ -1,56 +1,66 @@
1
- import { useBrowser as P } from "@arcblock/react-hooks";
2
- import { useRequest as w, useCreation as u } from "ahooks";
3
- import c from "lodash/isNil";
4
- import { LOGIN_PROVIDER as o } from "@arcblock/ux/lib/Util/constant";
5
- import { getFederatedEnabled as E, getMaster as k, getBlockletData as y } from "@arcblock/ux/lib/Util/federated";
6
- import { useState as A } from "react";
7
- const C = async ({ sourceAppPid: n }) => {
1
+ import { useBrowser as k } from "@arcblock/react-hooks";
2
+ import { useRequest as y, useCreation as L } from "ahooks";
3
+ import n from "lodash/isNil";
4
+ import { LOGIN_PROVIDER as s } from "@arcblock/ux/lib/Util/constant";
5
+ import { getFederatedEnabled as A, getMaster as C, getBlockletData as T } from "@arcblock/ux/lib/Util/federated";
6
+ import { useState as I } from "react";
7
+ const S = async ({ sourceAppPid: a }) => {
8
8
  const t = globalThis?.blocklet;
9
9
  if (!t)
10
10
  return {
11
- [o.WALLET]: {
11
+ [s.WALLET]: {
12
12
  order: 0,
13
13
  enabled: !0,
14
14
  showQrcode: !0
15
15
  },
16
- [o.PASSKEY]: {
16
+ [s.PASSKEY]: {
17
17
  order: 1,
18
18
  enabled: !0
19
19
  }
20
20
  };
21
- const a = E(t), e = k(t);
22
- return a && e?.appPid && n === e?.appPid ? (await y(e.appUrl))?.settings?.authentication || {} : t?.settings?.authentication || {};
23
- }, T = async ({ sourceAppPid: n } = {}) => {
24
- const t = await C({ sourceAppPid: n });
25
- return Object.entries(t).map(([e, r]) => ({ ...r, provider: e })).filter((e) => e.enabled).sort((e, r) => !c(e?.order) && !c(r?.order) ? e.order - r.order : c(e?.order) ? 1 : -1);
21
+ const l = A(t), e = C(t);
22
+ return l && e?.appPid && a === e?.appPid ? (await T(e.appUrl))?.settings?.authentication || {} : t?.settings?.authentication || {};
23
+ }, B = async ({ sourceAppPid: a } = {}) => {
24
+ const t = await S({ sourceAppPid: a });
25
+ return Object.entries(t).map(([e, o]) => ({ ...o, provider: e })).filter((e) => e.enabled).sort((e, o) => !n(e?.order) && !n(o?.order) ? e.order - o.order : n(e?.order) ? 1 : -1);
26
26
  };
27
- function W({
28
- allowWallet: n = !0,
27
+ function Y({
28
+ allowWallet: a = !0,
29
29
  passkeyBehavior: t = "none",
30
- action: a,
30
+ action: l,
31
31
  sourceAppPid: e,
32
- mode: r = "dialog",
33
- blocklet: p = globalThis.blocklet,
34
- isSmallView: f = !1
32
+ mode: o = "dialog",
33
+ blocklet: b = globalThis.blocklet,
34
+ isSmallView: p = !1,
35
+ lastLoginMethod: u = ""
35
36
  }) {
36
- const [h, L] = A(!1), m = ["login", "invite", "connect-to-did-space", "connect-to-did-domain", "destroy-self"], l = P(), { data: g = [] } = w(
37
+ const [P, g] = I(!1), w = ["login", "invite", "connect-to-did-space", "connect-to-did-domain", "destroy-self"], c = k(), { data: h = [] } = y(
37
38
  async () => {
38
- L(!0);
39
- const i = await T({ sourceAppPid: e });
40
- return L(!1), i;
39
+ g(!0);
40
+ const d = await B({ sourceAppPid: e });
41
+ return g(!1), d;
41
42
  },
42
43
  { refreshDeps: [e] }
43
- ), d = u(() => g.filter((s) => s.name === o.WALLET ? n : s.name === o.PASSKEY ? t !== "none" && !l.wallet && !l.arcSphere : s.name === o.EMAIL ? p?.settings?.notification?.email?.enabled ?? !1 : !(s.type === "oauth" && !m.includes(a))), [g]), b = u(() => {
44
- const i = r === "drawer" || f && l.mobile.any;
45
- return globalThis?.blocklet ? !!(d.find((v) => v.provider === o.WALLET)?.showQrcode !== !0 || i) : !!i;
46
- }, [r, f, d]);
44
+ ), f = L(() => h.filter((r) => r.name === s.WALLET ? a : r.name === s.PASSKEY ? t !== "none" && !c.wallet && !c.arcSphere : r.name === s.EMAIL ? b?.settings?.notification?.email?.enabled ?? !1 : !(r.type === "oauth" && !w.includes(l))).sort((r, i) => {
45
+ if (u) {
46
+ const m = r.provider === u, v = i.provider === u;
47
+ if (m && !v)
48
+ return -1;
49
+ if (!m && v)
50
+ return 1;
51
+ }
52
+ return !n(r?.order) && !n(i?.order) ? r.order - i.order : n(r?.order) ? n(i?.order) ? 0 : 1 : -1;
53
+ }), [h, u]), E = L(() => {
54
+ const d = o === "drawer" || p && c.mobile.any;
55
+ return globalThis?.blocklet ? !!(f.find((i) => i.provider === s.WALLET)?.showQrcode !== !0 || d) : !!d;
56
+ }, [o, p, f]);
47
57
  return {
48
- hideChooseList: u(() => !1),
49
- hideQRCode: b,
50
- providerList: d,
51
- loadingProviderList: h
58
+ hideChooseList: L(() => !1),
59
+ hideQRCode: E,
60
+ providerList: f,
61
+ loadingProviderList: P
52
62
  };
53
63
  }
54
64
  export {
55
- W as default
65
+ Y as default
56
66
  };