@arcblock/did-connect-react 3.3.6 → 3.3.8

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.
@@ -1,170 +1,175 @@
1
- import { jsx as l, jsxs as ie } from "react/jsx-runtime";
1
+ import { jsx as l, jsxs as me } from "react/jsx-runtime";
2
2
  import o from "prop-types";
3
- import { Box as h } from "@mui/material";
4
- import { LOGIN_PROVIDER as r, LOGIN_PROVIDER_ICON_SIZE as g, LOGIN_PROVIDER_NAME as le } from "@arcblock/ux/lib/Util/constant";
5
- import { getWebWalletUrl as se } from "@arcblock/ux/lib/Util/wallet";
6
- import u from "lodash/noop";
7
- import { useMemoizedFn as c } from "ahooks";
8
- import E from "js-cookie";
9
- import { getCookieOptions as ae } from "@arcblock/ux/lib/Util";
10
- import { useRef as b, useEffect as ce } from "react";
11
- import { mergeSx as me } from "@arcblock/ux/lib/Util/style";
12
- import de from "@arcblock/ux/lib/DIDConnect/provider-icon";
13
- import { GA_LAST_LOGIN_METHOD as p } from "@arcblock/ux/lib/withTracker/constant";
14
- import { translate as pe } from "@arcblock/ux/lib/Locale/util";
15
- import he from "@arcblock/ux/lib/Empty";
16
- import { useBrowser as ge } from "@arcblock/react-hooks";
17
- import ue from "./mobile-login-item.js";
18
- import fe from "./web-login-item.js";
19
- import ye from "./login-method-item.js";
20
- import Le from "./wallet-login-options.js";
21
- import { useOAuth as Ie } from "../../../OAuth/context.js";
22
- import { useStateContext as Ce } from "../../contexts/state.js";
23
- import { getAppId as xe, logger as Ae, getApiErrorMessage as Ee } from "../../../utils.js";
24
- import be from "./passkey-login-item.js";
25
- import { usePasskey as Me } from "../../../Passkey/context.js";
3
+ import { Box as L } from "@mui/material";
4
+ import { LOGIN_PROVIDER as r, LOGIN_PROVIDER_ICON_SIZE as I, LOGIN_PROVIDER_NAME as de } from "@arcblock/ux/lib/Util/constant";
5
+ import { checkSameProtocol as pe, getWebWalletUrl as ue } from "@arcblock/ux/lib/Util/wallet";
6
+ import b from "lodash/noop";
7
+ import { useMemoizedFn as a, useCreation as he } from "ahooks";
8
+ import v from "js-cookie";
9
+ import { detectWalletExtension as ge, getCookieOptions as fe } from "@arcblock/ux/lib/Util";
10
+ import { useRef as w, useEffect as Z } from "react";
11
+ import { mergeSx as ye } from "@arcblock/ux/lib/Util/style";
12
+ import Le from "@arcblock/ux/lib/DIDConnect/provider-icon";
13
+ import { GA_LAST_LOGIN_METHOD as g } from "@arcblock/ux/lib/withTracker/constant";
14
+ import { translate as Ie } from "@arcblock/ux/lib/Locale/util";
15
+ import be from "@arcblock/ux/lib/Empty";
16
+ import { useBrowser as xe } from "@arcblock/react-hooks";
17
+ import Ce from "./mobile-login-item.js";
18
+ import Ae from "./web-login-item.js";
19
+ import Ee from "./login-method-item.js";
20
+ import Pe from "./wallet-login-options.js";
21
+ import { useOAuth as Me } from "../../../OAuth/context.js";
22
+ import { useStateContext as ve } from "../../contexts/state.js";
23
+ import { getAppId as we, logger as _e, getApiErrorMessage as Oe } from "../../../utils.js";
24
+ import We from "./passkey-login-item.js";
25
+ import { usePasskey as Te } from "../../../Passkey/context.js";
26
26
  import "../../../Passkey/actions.js";
27
- import ve from "../../plugins/email/index.js";
28
- import Pe from "../../assets/locale.js";
29
- function _e({
30
- onSuccess: M = u,
31
- onError: v = u,
27
+ import ke from "../../plugins/email/index.js";
28
+ import Re from "../../assets/locale.js";
29
+ function Se({
30
+ onSuccess: _ = b,
31
+ onError: O = b,
32
32
  size: m = "small",
33
33
  tokenState: n,
34
- webWalletUrl: P = se(),
35
- tokenKey: _,
36
- passkeyBehavior: w = "none",
37
- onReset: f = u,
38
- providerList: y = [],
39
- slotProps: V = {},
40
- disableSwitchApp: L = !1,
41
- forceUpdate: K = u,
42
- magicToken: O = void 0,
43
- baseUrl: Y = "/",
44
- customItems: H = [],
45
- qrcode: Z = null
34
+ webWalletUrl: x = ue(),
35
+ tokenKey: W,
36
+ passkeyBehavior: T = "none",
37
+ onReset: C = b,
38
+ providerList: d = [],
39
+ slotProps: $ = {},
40
+ disableSwitchApp: A = !1,
41
+ forceUpdate: J = b,
42
+ magicToken: k = void 0,
43
+ baseUrl: X = "/",
44
+ customItems: z = [],
45
+ qrcode: Q = null,
46
+ hideQRCode: f = !1
46
47
  }) {
47
- const I = b(null), C = b(null), R = b(null), x = ge(), { loginOAuth: $, logoutOAuth: J, t: Q, oauthState: s } = Ie(), { passkeyState: T } = Me(), {
48
- extraParams: k,
49
- locale: W,
48
+ const E = w(null), P = w(null), R = w(null), ee = pe(x), S = ge(), p = xe(), { loginOAuth: oe, logoutOAuth: ne, t: te, oauthState: s } = Me(), { passkeyState: j } = Te(), {
49
+ extraParams: N,
50
+ locale: D,
50
51
  connectState: i,
51
- plugins: j,
52
- setPlugins: X,
53
- setSelectedPlugin: z,
54
- getPlugin: N,
55
- showWalletOptions: A,
56
- setShowWalletOptions: D
57
- } = Ce(), ee = c((e, t = {}) => pe(Pe, e, W, "en", t)), F = c(async (e) => {
58
- localStorage.setItem(p, e.provider), n.reset(), s.reset({
52
+ plugins: F,
53
+ setPlugins: re,
54
+ setSelectedPlugin: ie,
55
+ getPlugin: B,
56
+ showWalletOptions: h,
57
+ setShowWalletOptions: y
58
+ } = ve(), le = a((e, t = {}) => Ie(Re, e, D, "en", t)), G = a(async (e) => {
59
+ localStorage.setItem(g, e.provider), n.reset(), s.reset({
59
60
  status: "scanned"
60
- }), T.reset(), i.chooseMethod = e.provider;
61
- const t = k?.sourceAppPid;
61
+ }), j.reset(), i.chooseMethod = e.provider;
62
+ const t = N?.sourceAppPid;
62
63
  try {
63
64
  s.loading = !0, s.status = "scanned";
64
- const a = await $(e, {
65
+ const c = await oe(e, {
65
66
  action: n.action,
66
- ...k
67
- }), d = ae({ returnDomain: !1 });
68
- E.remove("connected_did", d), E.remove("connected_pk", d), E.remove("connected_wallet_os", d), a?.sessionToken && (await M(
67
+ ...N
68
+ }), u = fe({ returnDomain: !1 });
69
+ v.remove("connected_did", u), v.remove("connected_pk", u), v.remove("connected_wallet_os", u), c?.sessionToken && (await _(
69
70
  {
70
- ...a,
71
+ ...c,
71
72
  encrypted: !1
72
73
  },
73
- (re) => re,
74
+ (ae) => ae,
74
75
  {
75
76
  sourceAppPid: t,
76
- connected_app: xe(n.appInfo, n.memberAppInfo)
77
+ connected_app: we(n.appInfo, n.memberAppInfo)
77
78
  }
78
79
  ), s.loading = !1, s.status = "succeed");
79
- } catch (a) {
80
- Ae.error(`Failed login OAuth: ${e.provider}`, a);
81
- const d = Ee(a, Q("loginOAuthFailed"));
82
- s.loading = !1, s.error = d, s.status = "error", await J({ provider: e.provider }), v(new Error(d));
80
+ } catch (c) {
81
+ _e.error(`Failed login OAuth: ${e.provider}`, c);
82
+ const u = Oe(c, te("loginOAuthFailed"));
83
+ s.loading = !1, s.error = u, s.status = "error", await ne({ provider: e.provider }), O(new Error(u));
83
84
  }
84
- }), S = c(async () => {
85
- n.reset(), await f(), n.status = "created", i.chooseMethod = "wallet";
86
- }), B = c(async () => {
87
- localStorage.setItem(p, "wallet"), n.reset(), await f(), n.status = "created", i.chooseMethod = "wallet";
88
- const e = I.current?.connect;
85
+ }), U = a(async () => {
86
+ n.reset(), await C(), n.status = "created", i.chooseMethod = "wallet";
87
+ }), q = a(async () => {
88
+ localStorage.setItem(g, "wallet"), n.reset(), await C(), n.status = "created", i.chooseMethod = "wallet";
89
+ const e = E.current?.connect;
89
90
  i.retryConnect = () => {
90
- e(S);
91
+ e(U);
91
92
  };
92
- }), oe = c(() => {
93
- localStorage.setItem(p, "wallet"), n.status = "scanned", i.chooseMethod = "wallet-web";
94
- const e = C.current.connect;
93
+ }), V = a(() => {
94
+ localStorage.setItem(g, "wallet"), n.status = "scanned", i.chooseMethod = "wallet-web";
95
+ const e = P.current.connect;
95
96
  i.retryConnect = async () => {
96
- await f(), n.error = "", n.status = "scanned", e();
97
+ await C(), n.error = "", n.status = "scanned", e();
97
98
  };
98
- }), ne = c(() => {
99
- D(!1);
100
- }), G = y.some((e) => e.provider === r.EMAIL), U = ve({ baseUrl: Y }), te = c(() => {
101
- if (O && y.some((e) => e.name === r.EMAIL) && j.some((e) => e.name === r.EMAIL)) {
102
- const e = N(r.EMAIL);
103
- e.state.status === "idle" && (localStorage.setItem(p, "email"), e.state.reset(), e.state.magicToken = O, i.chooseMethod = r.EMAIL, z(e), K());
99
+ }), se = a(() => {
100
+ y(!1);
101
+ }), M = he(() => d.length === 1 && d[0].provider === r.WALLET, [d]);
102
+ Z(() => {
103
+ M && !p.mobile.any && !h && y(!0);
104
+ }, [M, p.mobile.any, y, h]);
105
+ const K = d.some((e) => e.provider === r.EMAIL), Y = ke({ baseUrl: X }), ce = a(() => {
106
+ if (k && d.some((e) => e.name === r.EMAIL) && F.some((e) => e.name === r.EMAIL)) {
107
+ const e = B(r.EMAIL);
108
+ e.state.status === "idle" && (localStorage.setItem(g, "email"), e.state.reset(), e.state.magicToken = k, i.chooseMethod = r.EMAIL, ie(e), J());
104
109
  }
105
110
  });
106
- ce(() => {
111
+ Z(() => {
107
112
  const e = [];
108
- if (G) {
109
- const t = N(r.EMAIL);
110
- t && t.baseUrl === U.baseUrl ? e.push(t) : e.push(U);
113
+ if (K) {
114
+ const t = B(r.EMAIL);
115
+ t && t.baseUrl === Y.baseUrl ? e.push(t) : e.push(Y);
111
116
  }
112
- X(e), i.retryConnect = S, setTimeout(() => {
113
- te();
117
+ re(e), i.retryConnect = U, setTimeout(() => {
118
+ ce();
114
119
  }, 100);
115
- }, [G]);
116
- const q = y.map((e) => {
120
+ }, [K]);
121
+ const H = d.map((e) => {
117
122
  if (e.provider === r.WALLET)
118
- return x.mobile.any && !A ? /* @__PURE__ */ l(
119
- ue,
123
+ return p.mobile.any && !h ? /* @__PURE__ */ l(
124
+ Ce,
120
125
  {
121
- ref: I,
126
+ ref: E,
122
127
  tokenState: n,
123
128
  sx: [m === "small" ? { p: 1 } : { p: 2 }],
124
- locale: W,
125
- tokenKey: _,
126
- disableSwitchApp: L,
127
- onClick: B
129
+ locale: D,
130
+ tokenKey: W,
131
+ disableSwitchApp: A,
132
+ onClick: q
128
133
  },
129
134
  r.WALLET
130
- ) : /* @__PURE__ */ l(
131
- fe,
135
+ ) : f || !f && (ee || S) && (!p.mobile.any || S) ? /* @__PURE__ */ l(
136
+ Ae,
132
137
  {
133
- ref: C,
138
+ ref: P,
134
139
  tokenState: n,
135
- webWalletUrl: P,
140
+ webWalletUrl: x,
136
141
  sx: [m === "small" ? { p: 1 } : { p: 2 }],
137
- disableSwitchApp: L,
138
- autoConnect: !1,
142
+ disableSwitchApp: A,
143
+ autoConnect: !f,
139
144
  onClick: () => {
140
- D(!0);
145
+ f ? y(!0) : V();
141
146
  }
142
147
  },
143
148
  r.WALLET
144
- );
149
+ ) : null;
145
150
  if (e.provider === r.PASSKEY)
146
- return w === "none" ? null : /* @__PURE__ */ l(
147
- be,
151
+ return T === "none" ? null : /* @__PURE__ */ l(
152
+ We,
148
153
  {
149
154
  ref: R,
150
- onSuccess: M,
151
- onError: v,
155
+ onSuccess: _,
156
+ onError: O,
152
157
  tokenState: n,
153
- behavior: w,
158
+ behavior: T,
154
159
  sx: [m === "small" ? { p: 1 } : { p: 2 }],
155
160
  onClick: () => {
156
- localStorage.setItem(p, "passkey");
161
+ localStorage.setItem(g, "passkey");
157
162
  const t = R.current.connect;
158
163
  i.chooseMethod = "passkey", i.retryConnect = () => {
159
- T.verifying = !0, i.chooseMethod = "passkey", t();
164
+ j.verifying = !0, i.chooseMethod = "passkey", t();
160
165
  };
161
166
  },
162
167
  slotProps: {
163
168
  icon: {
164
169
  sx: {
165
- fontSize: g,
170
+ fontSize: I,
166
171
  "& svg": {
167
- fontSize: g,
172
+ fontSize: I,
168
173
  width: "1em",
169
174
  height: "1em"
170
175
  }
@@ -175,7 +180,7 @@ function _e({
175
180
  r.PASSKEY
176
181
  );
177
182
  if (e.provider === r.EMAIL) {
178
- const t = j.find((a) => a.name === r.EMAIL);
183
+ const t = F.find((c) => c.name === r.EMAIL);
179
184
  return t ? t?.renderListItem({
180
185
  key: t.name,
181
186
  sx: [m === "small" ? { p: 1 } : { p: 2 }]
@@ -183,24 +188,24 @@ function _e({
183
188
  }) : null;
184
189
  }
185
190
  return e.type === "oauth" ? /* @__PURE__ */ l(
186
- ye,
191
+ Ee,
187
192
  {
188
- title: le[e.provider],
193
+ title: de[e.provider],
189
194
  icon: /* @__PURE__ */ l(
190
- de,
195
+ Le,
191
196
  {
192
197
  provider: e.provider,
193
198
  sx: {
194
199
  transform: "scale(0.95)",
195
- width: g,
196
- height: g,
200
+ width: I,
201
+ height: I,
197
202
  color: "text.primary"
198
203
  }
199
204
  }
200
205
  ),
201
206
  onClick: () => {
202
- F(e), i.retryConnect = () => {
203
- F(e);
207
+ G(e), i.retryConnect = () => {
208
+ G(e);
204
209
  };
205
210
  },
206
211
  sx: [m === "small" ? { p: 1.2 } : { p: 2 }]
@@ -208,42 +213,42 @@ function _e({
208
213
  e.provider
209
214
  ) : null;
210
215
  }).filter(Boolean);
211
- return /* @__PURE__ */ l(h, { className: "did-connect__choose", sx: me({ flex: 1 }, V?.root?.sx), children: /* @__PURE__ */ l(
212
- h,
216
+ return /* @__PURE__ */ l(L, { className: "did-connect__choose", sx: ye({ flex: 1 }, $?.root?.sx), children: /* @__PURE__ */ l(
217
+ L,
213
218
  {
214
219
  sx: {
215
220
  display: "flex",
216
221
  flexDirection: "column",
217
222
  gap: 2
218
223
  },
219
- children: /* @__PURE__ */ ie(
220
- h,
224
+ children: /* @__PURE__ */ me(
225
+ L,
221
226
  {
222
227
  sx: [
223
228
  {
224
229
  display: "flex",
225
230
  flexDirection: "column",
226
- ...A && !x.mobile.any ? { alignItems: "center", gap: 0 } : { gap: 1.5 }
231
+ ...h && !p.mobile.any ? { alignItems: "center", gap: 0 } : { gap: 1.5 }
227
232
  }
228
233
  ],
229
234
  children: [
230
- A && !x.mobile.any ? /* @__PURE__ */ l(
231
- Le,
235
+ h && !p.mobile.any ? /* @__PURE__ */ l(
236
+ Pe,
232
237
  {
233
- qrcode: Z,
238
+ qrcode: Q,
234
239
  tokenState: n,
235
- webWalletUrl: P,
240
+ webWalletUrl: x,
236
241
  size: m,
237
- disableSwitchApp: L,
238
- tokenKey: _,
239
- walletLoginRef: I,
240
- webLoginRef: C,
241
- onMobileLoginClick: B,
242
- onWebLoginClick: oe,
243
- onBack: ne
242
+ disableSwitchApp: A,
243
+ tokenKey: W,
244
+ walletLoginRef: E,
245
+ webLoginRef: P,
246
+ onMobileLoginClick: q,
247
+ onWebLoginClick: V,
248
+ onBack: M ? void 0 : se
244
249
  }
245
250
  ) : /* @__PURE__ */ l(
246
- h,
251
+ L,
247
252
  {
248
253
  sx: {
249
254
  display: "grid",
@@ -288,8 +293,8 @@ function _e({
288
293
  }
289
294
  }
290
295
  },
291
- children: q.length > 0 ? q : /* @__PURE__ */ l(
292
- he,
296
+ children: H.length > 0 ? H : /* @__PURE__ */ l(
297
+ be,
293
298
  {
294
299
  className: "arc-login-item",
295
300
  sx: {
@@ -297,19 +302,19 @@ function _e({
297
302
  textAlign: "center"
298
303
  }
299
304
  },
300
- children: ee("noAuthenticationProvider")
305
+ children: le("noAuthenticationProvider")
301
306
  }
302
307
  )
303
308
  }
304
309
  ),
305
- H.map((e) => e || null)
310
+ z.map((e) => e || null)
306
311
  ]
307
312
  }
308
313
  )
309
314
  }
310
315
  ) });
311
316
  }
312
- _e.propTypes = {
317
+ Se.propTypes = {
313
318
  onSuccess: o.func,
314
319
  onError: o.func,
315
320
  size: o.oneOf(["small", "normal", "large"]),
@@ -325,8 +330,9 @@ _e.propTypes = {
325
330
  magicToken: o.string,
326
331
  baseUrl: o.string,
327
332
  customItems: o.arrayOf(o.node),
328
- qrcode: o.node
333
+ qrcode: o.node,
334
+ hideQRCode: o.bool
329
335
  };
330
336
  export {
331
- _e as default
337
+ Se as default
332
338
  };
@@ -1,32 +1,32 @@
1
- import { jsxs as c, Fragment as f, jsx as e } from "react/jsx-runtime";
1
+ import { jsxs as f, Fragment as d, jsx as e } from "react/jsx-runtime";
2
2
  import o from "prop-types";
3
3
  import { Box as t, Divider as R } from "@mui/material";
4
- import { LOGIN_PROVIDER as d } from "@arcblock/ux/lib/Util/constant";
5
- import { checkSameProtocol as k, getWebWalletUrl as C } from "@arcblock/ux/lib/Util/wallet";
4
+ import { LOGIN_PROVIDER as p } from "@arcblock/ux/lib/Util/constant";
5
+ import { checkSameProtocol as C, getWebWalletUrl as k } from "@arcblock/ux/lib/Util/wallet";
6
6
  import { detectWalletExtension as W } from "@arcblock/ux/lib/Util";
7
7
  import { useCreation as q } from "ahooks";
8
8
  import { useBrowser as j } from "@arcblock/react-hooks";
9
9
  import T from "./mobile-login-item.js";
10
- import B from "./web-login-item.js";
11
- import P from "../back-button.js";
12
- import { useStateContext as v } from "../../contexts/state.js";
10
+ import P from "./web-login-item.js";
11
+ import v from "../back-button.js";
12
+ import { useStateContext as B } from "../../contexts/state.js";
13
13
  function E({
14
- qrcode: p,
14
+ qrcode: u,
15
15
  tokenState: r,
16
- webWalletUrl: n = C(),
16
+ webWalletUrl: n = k(),
17
17
  size: l = "small",
18
18
  disableSwitchApp: m = !1,
19
- tokenKey: u,
20
- walletLoginRef: b = null,
21
- webLoginRef: x = null,
22
- onMobileLoginClick: g,
23
- onWebLoginClick: h,
24
- onBack: L
19
+ tokenKey: b,
20
+ walletLoginRef: x = null,
21
+ webLoginRef: g = null,
22
+ onMobileLoginClick: h,
23
+ onWebLoginClick: L,
24
+ onBack: s
25
25
  }) {
26
- const { locale: w } = v(), i = j(), y = k(n), s = W(), a = q(() => i.mobile.tablet || !i.mobile.any && window?.navigator?.maxTouchPoints > 0, [i.mobile.tablet, i.mobile.any]);
27
- return /* @__PURE__ */ c(f, { children: [
28
- p,
29
- /* @__PURE__ */ c(t, { sx: { width: "100%", display: "flex", flexDirection: "column", gap: 1.5 }, children: [
26
+ const { locale: w } = B(), i = j(), y = C(n), a = W(), c = q(() => i.mobile.tablet || !i.mobile.any && window?.navigator?.maxTouchPoints > 0, [i.mobile.tablet, i.mobile.any]);
27
+ return /* @__PURE__ */ f(d, { children: [
28
+ u,
29
+ /* @__PURE__ */ f(t, { sx: { width: "100%", display: "flex", flexDirection: "column", gap: 1.5 }, children: [
30
30
  /* @__PURE__ */ e(t, { sx: { width: "100%" }, children: /* @__PURE__ */ e(
31
31
  R,
32
32
  {
@@ -57,37 +57,37 @@ function E({
57
57
  }
58
58
  }
59
59
  },
60
- children: a ? /* @__PURE__ */ e(
60
+ children: c ? /* @__PURE__ */ e(
61
61
  T,
62
62
  {
63
- ref: b,
63
+ ref: x,
64
64
  tokenState: r,
65
- isTablet: a,
65
+ isTablet: c,
66
66
  sx: [l === "small" ? { p: 1 } : { p: 2 }],
67
67
  locale: w,
68
- tokenKey: u,
68
+ tokenKey: b,
69
69
  disableSwitchApp: m,
70
- onClick: g
70
+ onClick: h
71
71
  },
72
- d.WALLET
72
+ p.WALLET
73
73
  ) : (
74
74
  // eslint-disable-next-line react/jsx-no-useless-fragment
75
- /* @__PURE__ */ e(f, { children: (y || s) && (!i.mobile.any || s) ? /* @__PURE__ */ e(
76
- B,
75
+ /* @__PURE__ */ e(d, { children: (y || a) && (!i.mobile.any || a) ? /* @__PURE__ */ e(
76
+ P,
77
77
  {
78
- ref: x,
78
+ ref: g,
79
79
  tokenState: r,
80
80
  webWalletUrl: n,
81
81
  sx: [l === "small" ? { p: 1 } : { p: 2 }],
82
82
  disableSwitchApp: m,
83
- onClick: h
83
+ onClick: L
84
84
  },
85
- d.WALLET
85
+ p.WALLET
86
86
  ) : null })
87
87
  )
88
88
  }
89
89
  ),
90
- /* @__PURE__ */ e(P, { variant: "text", onClick: L })
90
+ s && /* @__PURE__ */ e(v, { variant: "text", onClick: s })
91
91
  ] })
92
92
  ] });
93
93
  }
@@ -34,7 +34,7 @@ import { getWalletDid as _t } from "../User/use-did.js";
34
34
  import { getWebWalletUrl as Pt } from "@arcblock/ux/lib/Util/wallet";
35
35
  function fe({
36
36
  hideCloseButton: w = !1,
37
- mode: m = "dialog",
37
+ mode: p = "dialog",
38
38
  action: I,
39
39
  baseUrl: b = "",
40
40
  checkFn: v,
@@ -129,12 +129,12 @@ function fe({
129
129
  { leading: !0, trailing: !1 }
130
130
  );
131
131
  ue(Me, [o.status]);
132
- const Be = u(() => ot[s.chooseMethod] || "DID Wallet", [s.chooseMethod]), { providerList: Le, hideQRCode: p, hideChooseList: r } = Dt({
132
+ const Be = u(() => ot[s.chooseMethod] || "DID Wallet", [s.chooseMethod]), { providerList: Le, hideQRCode: m, hideChooseList: r } = Dt({
133
133
  action: o.action,
134
134
  sourceAppPid: s?.sourceAppPid,
135
135
  allowWallet: V,
136
136
  passkeyBehavior: Y,
137
- mode: m,
137
+ mode: p,
138
138
  blocklet: s?.sourceAppPid ? _e : $,
139
139
  isSmallView: oe
140
140
  }), Ne = Je(s?.sourceAppPid);
@@ -241,7 +241,7 @@ function fe({
241
241
  )
242
242
  }
243
243
  );
244
- }, [se, r, f]), je = u(() => r ? "column-reverse" : !p && re ? "column" : "row", [r, re, p]), ce = u(() => E ? /* @__PURE__ */ t(
244
+ }, [se, r, f]), je = u(() => r ? "column-reverse" : !m && re ? "column" : "row", [r, re, m]), ce = u(() => E ? /* @__PURE__ */ t(
245
245
  i,
246
246
  {
247
247
  sx: {
@@ -311,12 +311,12 @@ function fe({
311
311
  justifyContent: "center",
312
312
  alignItems: "stretch",
313
313
  flex: 1,
314
- gap: !p && oe ? 0 : 1.5,
314
+ gap: !m && oe ? 0 : 1.5,
315
315
  overflow: "visible",
316
316
  px: r ? 2 : 0
317
317
  },
318
318
  children: [
319
- !y && !p ? /* @__PURE__ */ x(qe, { children: [
319
+ !y && !m ? /* @__PURE__ */ x(qe, { children: [
320
320
  ce,
321
321
  r ? null : /* @__PURE__ */ t(i, { children: /* @__PURE__ */ t(
322
322
  Ge,
@@ -351,8 +351,9 @@ function fe({
351
351
  }
352
352
  },
353
353
  allowWallet: V,
354
- size: p && m !== "dialog" ? "normal" : "small",
354
+ size: m && p !== "dialog" ? "normal" : "small",
355
355
  tokenState: o,
356
+ hideQRCode: m,
356
357
  messages: d,
357
358
  tokenKey: j,
358
359
  onSuccess: R,
@@ -383,7 +384,7 @@ function fe({
383
384
  onSuccess: R,
384
385
  onError: Q
385
386
  }) : M = U;
386
- const ae = p || y ? rt : N;
387
+ const ae = m || y ? rt : N;
387
388
  return /* @__PURE__ */ x(
388
389
  i,
389
390
  {
@@ -398,7 +399,7 @@ function fe({
398
399
  maxWidth: "100%",
399
400
  width: (
400
401
  // eslint-disable-next-line no-nested-ternary
401
- m === "drawer" ? "100%" : f ? ae - 20 : ae
402
+ p === "drawer" ? "100%" : f ? ae - 20 : ae
402
403
  ),
403
404
  transition: "width 0.2s ease-in-out",
404
405
  margin: "auto",
@@ -459,8 +460,8 @@ fe.propTypes = {
459
460
  magicToken: e.string,
460
461
  customItems: e.arrayOf(e.node)
461
462
  };
462
- function me({ testOnlyBorderColor: w = void 0, ...m }) {
463
- const { checkFn: I, extraParams: b = {}, blocklet: v, masterBlocklet: D, action: T, locale: _ = "en" } = m;
463
+ function me({ testOnlyBorderColor: w = void 0, ...p }) {
464
+ const { checkFn: I, extraParams: b = {}, blocklet: v, masterBlocklet: D, action: T, locale: _ = "en" } = p;
464
465
  if (typeof I != "function")
465
466
  throw new Error("Cannot initialize did connect component without a fetchFn");
466
467
  return /* @__PURE__ */ t(
@@ -484,7 +485,7 @@ function me({ testOnlyBorderColor: w = void 0, ...m }) {
484
485
  boxSizing: "border-box"
485
486
  }
486
487
  },
487
- children: /* @__PURE__ */ t(fe, { ...m })
488
+ children: /* @__PURE__ */ t(fe, { ...p })
488
489
  }
489
490
  );
490
491
  }
@@ -1,4 +1,4 @@
1
- const o = "3.3.6", s = {
1
+ const o = "3.3.8", s = {
2
2
  version: o
3
3
  };
4
4
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/did-connect-react",
3
- "version": "3.3.6",
3
+ "version": "3.3.8",
4
4
  "description": "Client side library to work with DID Connect by ArcBlock.",
5
5
  "keywords": [
6
6
  "react",
@@ -32,10 +32,10 @@
32
32
  "url": "https://github.com/ArcBlock/ux/issues"
33
33
  },
34
34
  "dependencies": {
35
- "@arcblock/bridge": "3.3.6",
35
+ "@arcblock/bridge": "3.3.8",
36
36
  "@arcblock/did": "^1.27.16",
37
- "@arcblock/icons": "3.3.6",
38
- "@arcblock/react-hooks": "3.3.6",
37
+ "@arcblock/icons": "3.3.8",
38
+ "@arcblock/react-hooks": "3.3.8",
39
39
  "@arcblock/ws": "^1.27.16",
40
40
  "@blocklet/constant": "^1.17.6",
41
41
  "@fontsource/lexend": "^5.2.9",
@@ -81,5 +81,5 @@
81
81
  "eslint-plugin-react-hooks": "^4.6.2",
82
82
  "jest": "^29.7.0"
83
83
  },
84
- "gitHead": "ee100e9010a13a124962ce7ef38c8378c6deca9b"
84
+ "gitHead": "b4c40eaa794d708a6d21b721306b8e1cf6fb00ce"
85
85
  }
@@ -1,11 +1,11 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import { Box } from '@mui/material';
3
3
  import { LOGIN_PROVIDER, LOGIN_PROVIDER_NAME, LOGIN_PROVIDER_ICON_SIZE } from '@arcblock/ux/lib/Util/constant';
4
- import { getWebWalletUrl } from '@arcblock/ux/lib/Util/wallet';
4
+ import { checkSameProtocol, getWebWalletUrl } from '@arcblock/ux/lib/Util/wallet';
5
5
  import noop from 'lodash/noop';
6
- import { useMemoizedFn } from 'ahooks';
6
+ import { useMemoizedFn, useCreation } from 'ahooks';
7
7
  import Cookie from 'js-cookie';
8
- import { getCookieOptions } from '@arcblock/ux/lib/Util';
8
+ import { detectWalletExtension, getCookieOptions } from '@arcblock/ux/lib/Util';
9
9
  import { useEffect, useRef } from 'react';
10
10
  import { mergeSx } from '@arcblock/ux/lib/Util/style';
11
11
  import ProviderIcon from '@arcblock/ux/lib/DIDConnect/provider-icon';
@@ -43,10 +43,13 @@ export default function ConnectProviderList({
43
43
  baseUrl = '/',
44
44
  customItems = [],
45
45
  qrcode = null,
46
+ hideQRCode = false,
46
47
  }) {
47
48
  const walletLoginRef = useRef(null);
48
49
  const webLoginRef = useRef(null);
49
50
  const passkeyLoginRef = useRef(null);
51
+ const isSameProtocol = checkSameProtocol(webWalletUrl);
52
+ const extension = detectWalletExtension();
50
53
 
51
54
  const browser = useBrowser();
52
55
 
@@ -153,6 +156,16 @@ export default function ConnectProviderList({
153
156
  setShowWalletOptions(false);
154
157
  });
155
158
 
159
+ const onlyWalletProvider = useCreation(() => {
160
+ return providerList.length === 1 && providerList[0].provider === LOGIN_PROVIDER.WALLET;
161
+ }, [providerList]);
162
+
163
+ useEffect(() => {
164
+ if (onlyWalletProvider && !browser.mobile.any && !showWalletOptions) {
165
+ setShowWalletOptions(true);
166
+ }
167
+ }, [onlyWalletProvider, browser.mobile.any, setShowWalletOptions, showWalletOptions]);
168
+
156
169
  const showEmailLogin = providerList.some((p) => p.provider === LOGIN_PROVIDER.EMAIL);
157
170
 
158
171
  const emailPlugin = useEmailPlugin({ baseUrl });
@@ -213,7 +226,12 @@ export default function ConnectProviderList({
213
226
  />
214
227
  );
215
228
  }
216
- return (
229
+ // 是否显示 web 登录项
230
+ // 1. 如果隐藏了二维码,会在新页面显示 wallet 登录项
231
+ // 2. 如果显示了二维码,不需要在新页面显示 wallet 登录项,根据是否是同一协议、是否安装了钱包扩展、是否是移动端来判断是否显示
232
+ const shouldShowWebLoginItem =
233
+ hideQRCode || (!hideQRCode && (isSameProtocol || extension) && (!browser.mobile.any || extension));
234
+ return shouldShowWebLoginItem ? (
217
235
  <WebLoginItem
218
236
  key={LOGIN_PROVIDER.WALLET}
219
237
  ref={webLoginRef}
@@ -221,12 +239,16 @@ export default function ConnectProviderList({
221
239
  webWalletUrl={webWalletUrl}
222
240
  sx={[size === 'small' ? { p: 1 } : { p: 2 }]}
223
241
  disableSwitchApp={disableSwitchApp}
224
- autoConnect={false}
242
+ autoConnect={!hideQRCode}
225
243
  onClick={() => {
226
- setShowWalletOptions(true);
244
+ if (!hideQRCode) {
245
+ handleWebLoginClick();
246
+ } else {
247
+ setShowWalletOptions(true);
248
+ }
227
249
  }}
228
250
  />
229
- );
251
+ ) : null;
230
252
  }
231
253
 
232
254
  if (item.provider === LOGIN_PROVIDER.PASSKEY) {
@@ -339,7 +361,7 @@ export default function ConnectProviderList({
339
361
  webLoginRef={webLoginRef}
340
362
  onMobileLoginClick={handleMobileLoginClick}
341
363
  onWebLoginClick={handleWebLoginClick}
342
- onBack={handleWalletLoginBack}
364
+ onBack={onlyWalletProvider ? undefined : handleWalletLoginBack}
343
365
  />
344
366
  ) : (
345
367
  <Box
@@ -429,4 +451,5 @@ ConnectProviderList.propTypes = {
429
451
  baseUrl: PropTypes.string,
430
452
  customItems: PropTypes.arrayOf(PropTypes.node),
431
453
  qrcode: PropTypes.node,
454
+ hideQRCode: PropTypes.bool,
432
455
  };
@@ -95,7 +95,7 @@ export default function WalletLoginOptions({
95
95
  )}
96
96
  </Box>
97
97
 
98
- <BackButton variant="text" onClick={onBack} />
98
+ {onBack && <BackButton variant="text" onClick={onBack} />}
99
99
  </Box>
100
100
  </>
101
101
  );
@@ -467,6 +467,7 @@ function Connect({
467
467
  allowWallet={allowWallet}
468
468
  size={hideQRCode && mode !== 'dialog' ? 'normal' : 'small'}
469
469
  tokenState={state}
470
+ hideQRCode={hideQRCode}
470
471
  messages={messages}
471
472
  tokenKey={tokenKey}
472
473
  onSuccess={onSuccess}