@arcblock/did-connect-react 3.3.10 → 3.4.1

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 (39) 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 +503 -0
  8. package/lib/Connect/contexts/state.js +74 -65
  9. package/lib/Connect/fallback-connect.js +53 -0
  10. package/lib/Connect/hooks/provider-list.js +45 -29
  11. package/lib/Connect/index.js +13 -502
  12. package/lib/Connect/plugins/email/list-item.js +19 -18
  13. package/lib/Connect/use-connect.js +10 -10
  14. package/lib/OAuth/context.js +3 -3
  15. package/lib/Passkey/actions.js +80 -75
  16. package/lib/Passkey/context.js +3 -3
  17. package/lib/Passkey/dialog.js +7 -7
  18. package/lib/Session/assets/did-spaces-guide-cover.svg.js +74 -98
  19. package/lib/Session/index.js +189 -189
  20. package/lib/package.json.js +1 -1
  21. package/lib/utils.js +2 -2
  22. package/package.json +8 -8
  23. package/src/Connect/assets/locale.js +2 -0
  24. package/src/Connect/components/login-item/connect-choose-list.jsx +12 -5
  25. package/src/Connect/components/login-item/connect-provider-list.jsx +11 -4
  26. package/src/Connect/components/login-item/login-method-item.jsx +24 -7
  27. package/src/Connect/components/login-item/passkey-login-item.jsx +3 -1
  28. package/src/Connect/components/login-item/wallet-login-options.jsx +3 -2
  29. package/src/Connect/connect.jsx +618 -0
  30. package/src/Connect/contexts/state.jsx +10 -0
  31. package/src/Connect/fallback-connect.jsx +47 -0
  32. package/src/Connect/hooks/provider-list.js +48 -17
  33. package/src/Connect/index.jsx +8 -605
  34. package/src/Connect/plugins/email/list-item.jsx +3 -2
  35. package/src/Connect/use-connect.jsx +1 -1
  36. package/src/Passkey/actions.jsx +5 -0
  37. package/src/Session/assets/did-spaces-guide-cover.svg +1 -128
  38. package/src/Session/index.jsx +3 -4
  39. package/src/utils.js +2 -2
@@ -67,7 +67,8 @@ const e = {
67
67
  passkeyPreviewDescription: "Sign in with Passkey - More secure and convenient authentication. No passwords to remember, easily access apps and websites.",
68
68
  didConnectTitle: "DID Connect",
69
69
  didConnectDescription: "Decentralized identities and apps, W3C DID-based, future-ready.",
70
- noAuthenticationProvider: "No authentication provider configured"
70
+ noAuthenticationProvider: "No authentication provider configured",
71
+ lastUsed: "Last Used"
71
72
  },
72
73
  zh: {
73
74
  generateError: "二维码生成失败",
@@ -137,7 +138,8 @@ const e = {
137
138
  passkeyPreviewDescription: "使用 Passkey 账户登录 - 更安全、更便捷的身份验证方式。无需记忆密码,轻松登录各类应用和网站",
138
139
  didConnectTitle: "DID Connect",
139
140
  didConnectDescription: "面向未来的基于 W3C DID 去中心化身份和应用",
140
- noAuthenticationProvider: "未配置任何身份验证提供者"
141
+ noAuthenticationProvider: "未配置任何身份验证提供者",
142
+ lastUsed: "上次使用"
141
143
  }
142
144
  };
143
145
  export {
@@ -1,102 +1,102 @@
1
- import { jsx as n, jsxs as F } from "react/jsx-runtime";
1
+ import { jsx as i, jsxs as U } from "react/jsx-runtime";
2
2
  import o from "prop-types";
3
- import { Box as u } from "@mui/material";
4
- import { LOGIN_PROVIDER as f, LOGIN_PROVIDER_NAME as oe, LOGIN_PROVIDER_ICON_SIZE as d } from "@arcblock/ux/lib/Util/constant";
5
- import { getWebWalletUrl as te } from "@arcblock/ux/lib/Util/wallet";
6
- import g from "lodash/noop";
7
- import { useMemoizedFn as y } from "ahooks";
3
+ import { Box as g } from "@mui/material";
4
+ import { LOGIN_PROVIDER as s, LOGIN_PROVIDER_NAME as te, LOGIN_PROVIDER_ICON_SIZE as h } from "@arcblock/ux/lib/Util/constant";
5
+ import { getWebWalletUrl as re } from "@arcblock/ux/lib/Util/wallet";
6
+ import L from "lodash/noop";
7
+ import { useMemoizedFn as I } from "ahooks";
8
8
  import x from "js-cookie";
9
- import { getCookieOptions as re } from "@arcblock/ux/lib/Util";
10
- import { useRef as I, useEffect as se } from "react";
11
- import { mergeSx as ne } from "@arcblock/ux/lib/Util/style";
9
+ import { getCookieOptions as se } from "@arcblock/ux/lib/Util";
10
+ import { useRef as A, useEffect as ne } from "react";
11
+ import { mergeSx as ie } from "@arcblock/ux/lib/Util/style";
12
12
  import le from "@arcblock/ux/lib/DIDConnect/provider-icon";
13
- import { GA_LAST_LOGIN_METHOD as p } from "@arcblock/ux/lib/withTracker/constant";
14
- import ie from "./mobile-login-item.js";
15
- import ae from "./web-login-item.js";
16
- import ce from "./login-method-item.js";
17
- import { useOAuth as pe } from "../../../OAuth/context.js";
18
- import { useStateContext as me } from "../../contexts/state.js";
19
- import { getAppId as ue, logger as fe, getApiErrorMessage as de } from "../../../utils.js";
20
- import ge from "./passkey-login-item.js";
21
- import { usePasskey as he } from "../../../Passkey/context.js";
13
+ import { GA_LAST_LOGIN_METHOD as u } from "@arcblock/ux/lib/withTracker/constant";
14
+ import ae from "./mobile-login-item.js";
15
+ import ce from "./web-login-item.js";
16
+ import pe from "./login-method-item.js";
17
+ import { useOAuth as me } from "../../../OAuth/context.js";
18
+ import { useStateContext as ue } from "../../contexts/state.js";
19
+ import { getAppId as de, logger as fe, getApiErrorMessage as ge } from "../../../utils.js";
20
+ import he from "./passkey-login-item.js";
21
+ import { usePasskey as Le } from "../../../Passkey/context.js";
22
22
  import "../../../Passkey/actions.js";
23
23
  import ye from "../../plugins/email/index.js";
24
- function xe({
25
- onSuccess: b = g,
26
- onError: L = g,
27
- size: i = "small",
24
+ function Ie({
25
+ onSuccess: b = L,
26
+ onError: M = L,
27
+ size: c = "small",
28
28
  tokenState: t,
29
- webWalletUrl: U = te(),
30
- tokenKey: G,
31
- passkeyBehavior: W = "none",
32
- onReset: h = g,
33
- showMobileLogin: j = !0,
29
+ webWalletUrl: G = re(),
30
+ tokenKey: S,
31
+ passkeyBehavior: j = "none",
32
+ onReset: y = L,
33
+ showMobileLogin: V = !0,
34
34
  showOAuthLogin: v = !0,
35
- showPasskeyLogin: w = !0,
36
- showWebLogin: S = !0,
37
- showEmailLogin: m = !0,
38
- oauthProviderList: V = [],
39
- slotProps: q = {},
40
- disableSwitchApp: M = !1,
41
- forceUpdate: B = g,
42
- magicToken: O = void 0,
43
- baseUrl: H = "/",
44
- customItems: K = []
35
+ showPasskeyLogin: O = !0,
36
+ showWebLogin: q = !0,
37
+ showEmailLogin: d = !0,
38
+ oauthProviderList: B = [],
39
+ slotProps: K = {},
40
+ disableSwitchApp: P = !1,
41
+ forceUpdate: H = L,
42
+ magicToken: E = void 0,
43
+ baseUrl: Y = "/",
44
+ customItems: Z = []
45
45
  }) {
46
- const P = I(null), A = I(null), C = I(null), { loginOAuth: Z, logoutOAuth: $, t: z, oauthState: s } = pe(), { passkeyState: _ } = he(), { extraParams: E, locale: J, connectState: r, plugins: R, setPlugins: Q, setSelectedPlugin: X, getPlugin: k } = me(), D = y(async (e) => {
47
- localStorage.setItem(p, e.provider), t.reset(), s.reset({
46
+ const w = A(null), C = A(null), _ = A(null), { loginOAuth: $, logoutOAuth: z, t: f, oauthState: n } = me(), { passkeyState: R } = Le(), { extraParams: T, locale: J, connectState: r, plugins: W, setPlugins: Q, setSelectedPlugin: X, getPlugin: k, lastLoginMethod: l } = ue(), D = I(async (e) => {
47
+ localStorage.setItem(u, e.provider), t.reset(), n.reset({
48
48
  status: "scanned"
49
- }), _.reset(), r.chooseMethod = e.provider;
50
- const a = E?.sourceAppPid;
49
+ }), R.reset(), r.chooseMethod = e.provider;
50
+ const p = T?.sourceAppPid;
51
51
  try {
52
- s.loading = !0, s.status = "scanned";
53
- const c = await Z(e, {
52
+ n.loading = !0, n.status = "scanned";
53
+ const m = await $(e, {
54
54
  action: t.action,
55
- ...E
56
- }), l = re({ returnDomain: !1 });
57
- x.remove("connected_did", l), x.remove("connected_pk", l), x.remove("connected_wallet_os", l), c?.sessionToken && (await b(
55
+ ...T
56
+ }), a = se({ returnDomain: !1 });
57
+ x.remove("connected_did", a), x.remove("connected_pk", a), x.remove("connected_wallet_os", a), m?.sessionToken && (await b(
58
58
  {
59
- ...c,
59
+ ...m,
60
60
  encrypted: !1
61
61
  },
62
- (ee) => ee,
62
+ (oe) => oe,
63
63
  {
64
- sourceAppPid: a,
65
- connected_app: ue(t.appInfo, t.memberAppInfo)
64
+ sourceAppPid: p,
65
+ connected_app: de(t.appInfo, t.memberAppInfo)
66
66
  }
67
- ), s.loading = !1, s.status = "succeed");
68
- } catch (c) {
69
- fe.error(`Failed login OAuth: ${e.provider}`, c);
70
- const l = de(c, z("loginOAuthFailed"));
71
- s.loading = !1, s.error = l, s.status = "error", await $({ provider: e.provider }), L(new Error(l));
67
+ ), n.loading = !1, n.status = "succeed");
68
+ } catch (m) {
69
+ fe.error(`Failed login OAuth: ${e.provider}`, m);
70
+ const a = ge(m, f("loginOAuthFailed"));
71
+ n.loading = !1, n.error = a, n.status = "error", await z({ provider: e.provider }), M(new Error(a));
72
72
  }
73
- }), T = y(async () => {
74
- t.reset(), await h(), t.status = "created", r.chooseMethod = "wallet";
75
- }), N = ye({ baseUrl: H }), Y = y(() => {
76
- if (O && m && R.some((e) => e.name === f.EMAIL)) {
77
- const e = k(f.EMAIL);
78
- e.state.status === "idle" && (localStorage.setItem(p, "email"), e.state.reset(), e.state.magicToken = O, r.chooseMethod = f.EMAIL, X(e), B());
73
+ }), N = I(async () => {
74
+ t.reset(), await y(), t.status = "created", r.chooseMethod = "wallet";
75
+ }), F = ye({ baseUrl: Y }), ee = I(() => {
76
+ if (E && d && W.some((e) => e.name === s.EMAIL)) {
77
+ const e = k(s.EMAIL);
78
+ e.state.status === "idle" && (localStorage.setItem(u, s.EMAIL), e.state.reset(), e.state.magicToken = E, r.chooseMethod = s.EMAIL, X(e), H());
79
79
  }
80
80
  });
81
- return se(() => {
81
+ return ne(() => {
82
82
  const e = [];
83
- if (m) {
84
- const a = k(f.EMAIL);
85
- a && a.baseUrl === N.baseUrl ? e.push(a) : e.push(N);
83
+ if (d) {
84
+ const p = k(s.EMAIL);
85
+ p && p.baseUrl === F.baseUrl ? e.push(p) : e.push(F);
86
86
  }
87
- Q(e), r.retryConnect = T, setTimeout(() => {
88
- Y();
87
+ Q(e), r.retryConnect = N, setTimeout(() => {
88
+ ee();
89
89
  }, 100);
90
- }, [m]), /* @__PURE__ */ n(u, { className: "did-connect__choose", sx: ne({ flex: 1 }, q?.root?.sx), children: /* @__PURE__ */ n(
91
- u,
90
+ }, [d]), /* @__PURE__ */ i(g, { className: "did-connect__choose", sx: ie({ flex: 1 }, K?.root?.sx), children: /* @__PURE__ */ i(
91
+ g,
92
92
  {
93
93
  sx: {
94
94
  display: "flex",
95
95
  flexDirection: "column",
96
96
  gap: 2
97
97
  },
98
- children: /* @__PURE__ */ F(
99
- u,
98
+ children: /* @__PURE__ */ U(
99
+ g,
100
100
  {
101
101
  sx: [
102
102
  {
@@ -106,43 +106,47 @@ function xe({
106
106
  }
107
107
  ],
108
108
  children: [
109
- j && /* @__PURE__ */ n(
110
- ie,
109
+ V && /* @__PURE__ */ i(
110
+ ae,
111
111
  {
112
- ref: P,
112
+ t: f,
113
+ isLatest: l && l === s.WALLET,
114
+ ref: w,
113
115
  tokenState: t,
114
- sx: [i === "small" ? { p: 1 } : { p: 2 }],
116
+ sx: [c === "small" ? { p: 1 } : { p: 2 }],
115
117
  locale: J,
116
- tokenKey: G,
117
- disableSwitchApp: M,
118
+ tokenKey: S,
119
+ disableSwitchApp: P,
118
120
  onClick: async () => {
119
- localStorage.setItem(p, "wallet"), t.reset(), await h(), t.status = "created", r.chooseMethod = "wallet";
120
- const e = P.current?.connect;
121
+ localStorage.setItem(u, s.WALLET), t.reset(), await y(), t.status = "created", r.chooseMethod = "wallet";
122
+ const e = w.current?.connect;
121
123
  r.retryConnect = () => {
122
- e(T);
124
+ e(N);
123
125
  };
124
126
  }
125
127
  }
126
128
  ),
127
- S && /* @__PURE__ */ n(
128
- ae,
129
+ q && /* @__PURE__ */ i(
130
+ ce,
129
131
  {
130
- ref: A,
132
+ isLatest: l && l === s.WALLET,
133
+ ref: C,
131
134
  tokenState: t,
132
- webWalletUrl: U,
133
- sx: [i === "small" ? { p: 1 } : { p: 2 }],
134
- disableSwitchApp: M,
135
+ webWalletUrl: G,
136
+ t: f,
137
+ sx: [c === "small" ? { p: 1 } : { p: 2 }],
138
+ disableSwitchApp: P,
135
139
  onClick: () => {
136
- localStorage.setItem(p, "wallet"), t.status = "scanned", r.chooseMethod = "wallet-web";
137
- const e = A.current.connect;
140
+ localStorage.setItem(u, s.WALLET), t.status = "scanned", r.chooseMethod = "wallet-web";
141
+ const e = C.current.connect;
138
142
  r.retryConnect = async () => {
139
- await h(), t.error = "", t.status = "scanned", e();
143
+ await y(), t.error = "", t.status = "scanned", e();
140
144
  };
141
145
  }
142
146
  }
143
147
  ),
144
- v || w || m ? /* @__PURE__ */ F(
145
- u,
148
+ v || O || d ? /* @__PURE__ */ U(
149
+ g,
146
150
  {
147
151
  sx: [
148
152
  {
@@ -152,25 +156,27 @@ function xe({
152
156
  }
153
157
  ],
154
158
  children: [
155
- R.map(
159
+ W.map(
156
160
  (e) => e.renderListItem({
157
161
  key: e.name,
158
- sx: [i === "small" ? { p: 1 } : { p: 2 }]
162
+ sx: [c === "small" ? { p: 1 } : { p: 2 }]
159
163
  // forceUpdate,
160
164
  })
161
165
  ),
162
- v ? V.map((e) => /* @__PURE__ */ n(
163
- ce,
166
+ v ? B.map((e) => /* @__PURE__ */ i(
167
+ pe,
164
168
  {
165
- title: oe[e.provider],
166
- icon: /* @__PURE__ */ n(
169
+ t: f,
170
+ isLatest: l && l === e.provider,
171
+ title: te[e.provider],
172
+ icon: /* @__PURE__ */ i(
167
173
  le,
168
174
  {
169
175
  provider: e.provider,
170
176
  sx: {
171
177
  transform: "scale(0.95)",
172
- width: d,
173
- height: d,
178
+ width: h,
179
+ height: h,
174
180
  color: "text.primary"
175
181
  }
176
182
  }
@@ -180,32 +186,32 @@ function xe({
180
186
  D(e);
181
187
  };
182
188
  },
183
- sx: [i === "small" ? { p: 1 } : { p: 2 }]
189
+ sx: [c === "small" ? { p: 1 } : { p: 2 }]
184
190
  },
185
191
  e.provider
186
192
  )) : null,
187
- w ? /* @__PURE__ */ n(
188
- ge,
193
+ O ? /* @__PURE__ */ i(
194
+ he,
189
195
  {
190
- ref: C,
196
+ ref: _,
191
197
  onSuccess: b,
192
- onError: L,
198
+ onError: M,
193
199
  tokenState: t,
194
- behavior: W,
195
- sx: [i === "small" ? { p: 1 } : { p: 2 }],
200
+ behavior: j,
201
+ sx: [c === "small" ? { p: 1 } : { p: 2 }],
196
202
  onClick: () => {
197
- localStorage.setItem(p, "passkey");
198
- const e = C.current.connect;
203
+ localStorage.setItem(u, s.PASSKEY);
204
+ const e = _.current.connect;
199
205
  r.chooseMethod = "passkey", r.retryConnect = () => {
200
- _.verifying = !0, r.chooseMethod = "passkey", e();
206
+ R.verifying = !0, r.chooseMethod = "passkey", e();
201
207
  };
202
208
  },
203
209
  slotProps: {
204
210
  icon: {
205
211
  sx: {
206
- fontSize: d,
212
+ fontSize: h,
207
213
  "& svg": {
208
- fontSize: d,
214
+ fontSize: h,
209
215
  width: "1em",
210
216
  height: "1em"
211
217
  }
@@ -217,14 +223,14 @@ function xe({
217
223
  ]
218
224
  }
219
225
  ) : null,
220
- K.map((e) => e || null)
226
+ Z.map((e) => e || null)
221
227
  ]
222
228
  }
223
229
  )
224
230
  }
225
231
  ) });
226
232
  }
227
- xe.propTypes = {
233
+ Ie.propTypes = {
228
234
  onSuccess: o.func,
229
235
  onError: o.func,
230
236
  size: o.oneOf(["small", "normal", "large"]),
@@ -247,5 +253,5 @@ xe.propTypes = {
247
253
  customItems: o.arrayOf(o.node)
248
254
  };
249
255
  export {
250
- xe as default
256
+ Ie as default
251
257
  };