@arcblock/did-connect-react 3.4.0 → 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.
@@ -1,175 +1,180 @@
1
- import { jsx as l, jsxs as me } from "react/jsx-runtime";
2
- import o from "prop-types";
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";
1
+ import { jsx as l, jsxs as po } from "react/jsx-runtime";
2
+ import n from "prop-types";
3
+ import { Box as A } from "@mui/material";
4
+ import { LOGIN_PROVIDER as e, LOGIN_PROVIDER_ICON_SIZE as E, LOGIN_PROVIDER_NAME as ho } from "@arcblock/ux/lib/Util/constant";
5
+ import { checkSameProtocol as uo, getWebWalletUrl as go } from "@arcblock/ux/lib/Util/wallet";
6
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";
7
+ import { useMemoizedFn as a, useCreation as fo } from "ahooks";
8
+ import O from "js-cookie";
9
+ import { detectWalletExtension as yo, getCookieOptions as Lo } from "@arcblock/ux/lib/Util";
10
+ import { useRef as w, useEffect as J } from "react";
11
+ import { mergeSx as Io } from "@arcblock/ux/lib/Util/style";
12
+ import Ao from "@arcblock/ux/lib/DIDConnect/provider-icon";
13
+ import { GA_LAST_LOGIN_METHOD as f } from "@arcblock/ux/lib/withTracker/constant";
14
+ import { translate as Eo } from "@arcblock/ux/lib/Locale/util";
15
+ import bo from "@arcblock/ux/lib/Empty";
16
+ import { useBrowser as xo } from "@arcblock/react-hooks";
17
+ import Co from "./mobile-login-item.js";
18
+ import Po from "./web-login-item.js";
19
+ import Mo from "./login-method-item.js";
20
+ import vo from "./wallet-login-options.js";
21
+ import { useOAuth as _o } from "../../../OAuth/context.js";
22
+ import { useStateContext as Oo } from "../../contexts/state.js";
23
+ import { getAppId as wo, logger as Wo, getApiErrorMessage as To } from "../../../utils.js";
24
+ import ko from "./passkey-login-item.js";
25
+ import { usePasskey as So } from "../../../Passkey/context.js";
26
26
  import "../../../Passkey/actions.js";
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,
27
+ import Ro from "../../plugins/email/index.js";
28
+ import jo from "../../assets/locale.js";
29
+ function No({
30
+ onSuccess: W = b,
31
+ onError: T = b,
32
32
  size: m = "small",
33
- tokenState: n,
34
- webWalletUrl: x = ue(),
35
- tokenKey: W,
36
- passkeyBehavior: T = "none",
33
+ tokenState: t,
34
+ webWalletUrl: x = go(),
35
+ tokenKey: k,
36
+ passkeyBehavior: S = "none",
37
37
  onReset: C = b,
38
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
39
+ slotProps: X = {},
40
+ disableSwitchApp: P = !1,
41
+ forceUpdate: z = b,
42
+ magicToken: R = void 0,
43
+ baseUrl: Q = "/",
44
+ customItems: oo = [],
45
+ qrcode: eo = null,
46
+ hideQRCode: y = !1
47
47
  }) {
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,
48
+ const M = w(null), v = w(null), j = w(null), no = uo(x), N = yo(), p = xo(), { loginOAuth: to, logoutOAuth: ro, t: io, oauthState: s } = _o(), { passkeyState: D } = So(), {
49
+ extraParams: F,
50
+ locale: B,
51
51
  connectState: i,
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({
52
+ plugins: G,
53
+ setPlugins: lo,
54
+ setSelectedPlugin: so,
55
+ getPlugin: U,
56
+ showWalletOptions: g,
57
+ setShowWalletOptions: L,
58
+ lastLoginMethod: h
59
+ } = Oo(), I = a((o, r = {}) => Eo(jo, o, B, "en", r)), q = a(async (o) => {
60
+ localStorage.setItem(f, o.provider), t.reset(), s.reset({
60
61
  status: "scanned"
61
- }), j.reset(), i.chooseMethod = e.provider;
62
- const t = N?.sourceAppPid;
62
+ }), D.reset(), i.chooseMethod = o.provider;
63
+ const r = F?.sourceAppPid;
63
64
  try {
64
65
  s.loading = !0, s.status = "scanned";
65
- const c = await oe(e, {
66
- action: n.action,
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 _(
66
+ const c = await to(o, {
67
+ action: t.action,
68
+ ...F
69
+ }), u = Lo({ returnDomain: !1 });
70
+ O.remove("connected_did", u), O.remove("connected_pk", u), O.remove("connected_wallet_os", u), c?.sessionToken && (await W(
70
71
  {
71
72
  ...c,
72
73
  encrypted: !1
73
74
  },
74
- (ae) => ae,
75
+ (mo) => mo,
75
76
  {
76
- sourceAppPid: t,
77
- connected_app: we(n.appInfo, n.memberAppInfo)
77
+ sourceAppPid: r,
78
+ connected_app: wo(t.appInfo, t.memberAppInfo)
78
79
  }
79
80
  ), s.loading = !1, s.status = "succeed");
80
81
  } 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));
82
+ Wo.error(`Failed login OAuth: ${o.provider}`, c);
83
+ const u = To(c, io("loginOAuthFailed"));
84
+ s.loading = !1, s.error = u, s.status = "error", await ro({ provider: o.provider }), T(new Error(u));
84
85
  }
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;
86
+ }), K = a(async () => {
87
+ t.reset(), await C(), t.status = "created", i.chooseMethod = "wallet";
88
+ }), V = a(async () => {
89
+ localStorage.setItem(f, e.WALLET), t.reset(), await C(), t.status = "created", i.chooseMethod = "wallet";
90
+ const o = M.current?.connect;
90
91
  i.retryConnect = () => {
91
- e(U);
92
+ o(K);
92
93
  };
93
- }), V = a(() => {
94
- localStorage.setItem(g, "wallet"), n.status = "scanned", i.chooseMethod = "wallet-web";
95
- const e = P.current.connect;
94
+ }), Y = a(() => {
95
+ localStorage.setItem(f, e.WALLET), t.status = "scanned", i.chooseMethod = "wallet-web";
96
+ const o = v.current.connect;
96
97
  i.retryConnect = async () => {
97
- await C(), n.error = "", n.status = "scanned", e();
98
+ await C(), t.error = "", t.status = "scanned", o();
98
99
  };
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());
100
+ }), co = a(() => {
101
+ L(!1);
102
+ }), _ = fo(() => d.length === 1 && d[0].provider === e.WALLET, [d]);
103
+ J(() => {
104
+ _ && !p.mobile.any && !g && L(!0);
105
+ }, [_, p.mobile.any, L, g]);
106
+ const H = d.some((o) => o.provider === e.EMAIL), Z = Ro({ baseUrl: Q }), ao = a(() => {
107
+ if (R && d.some((o) => o.name === e.EMAIL) && G.some((o) => o.name === e.EMAIL)) {
108
+ const o = U(e.EMAIL);
109
+ o.state.status === "idle" && (localStorage.setItem(f, e.EMAIL), o.state.reset(), o.state.magicToken = R, i.chooseMethod = e.EMAIL, so(o), z());
109
110
  }
110
111
  });
111
- Z(() => {
112
- const e = [];
113
- if (K) {
114
- const t = B(r.EMAIL);
115
- t && t.baseUrl === Y.baseUrl ? e.push(t) : e.push(Y);
112
+ J(() => {
113
+ const o = [];
114
+ if (H) {
115
+ const r = U(e.EMAIL);
116
+ r && r.baseUrl === Z.baseUrl ? o.push(r) : o.push(Z);
116
117
  }
117
- re(e), i.retryConnect = U, setTimeout(() => {
118
- ce();
118
+ lo(o), i.retryConnect = K, setTimeout(() => {
119
+ ao();
119
120
  }, 100);
120
- }, [K]);
121
- const H = d.map((e) => {
122
- if (e.provider === r.WALLET)
123
- return p.mobile.any && !h ? /* @__PURE__ */ l(
124
- Ce,
121
+ }, [H]);
122
+ const $ = d.map((o) => {
123
+ if (o.provider === e.WALLET)
124
+ return p.mobile.any && !g ? /* @__PURE__ */ l(
125
+ Co,
125
126
  {
126
- ref: E,
127
- tokenState: n,
127
+ t: I,
128
+ isLatest: h && h === e.WALLET,
129
+ ref: M,
130
+ tokenState: t,
128
131
  sx: [m === "small" ? { p: 1 } : { p: 2 }],
129
- locale: D,
130
- tokenKey: W,
131
- disableSwitchApp: A,
132
- onClick: q
132
+ locale: B,
133
+ tokenKey: k,
134
+ disableSwitchApp: P,
135
+ onClick: V
133
136
  },
134
- r.WALLET
135
- ) : f || !f && (ee || S) && (!p.mobile.any || S) ? /* @__PURE__ */ l(
136
- Ae,
137
+ e.WALLET
138
+ ) : y || !y && (no || N) && (!p.mobile.any || N) ? /* @__PURE__ */ l(
139
+ Po,
137
140
  {
138
- ref: P,
139
- tokenState: n,
141
+ t: I,
142
+ isLatest: h && h === e.WALLET,
143
+ ref: v,
144
+ tokenState: t,
140
145
  webWalletUrl: x,
141
146
  sx: [m === "small" ? { p: 1 } : { p: 2 }],
142
- disableSwitchApp: A,
143
- autoConnect: !f,
147
+ disableSwitchApp: P,
148
+ autoConnect: !y,
144
149
  onClick: () => {
145
- f ? y(!0) : V();
150
+ y ? L(!0) : Y();
146
151
  }
147
152
  },
148
- r.WALLET
153
+ e.WALLET
149
154
  ) : null;
150
- if (e.provider === r.PASSKEY)
151
- return T === "none" ? null : /* @__PURE__ */ l(
152
- We,
155
+ if (o.provider === e.PASSKEY)
156
+ return S === "none" ? null : /* @__PURE__ */ l(
157
+ ko,
153
158
  {
154
- ref: R,
155
- onSuccess: _,
156
- onError: O,
157
- tokenState: n,
158
- behavior: T,
159
+ ref: j,
160
+ onSuccess: W,
161
+ onError: T,
162
+ tokenState: t,
163
+ behavior: S,
159
164
  sx: [m === "small" ? { p: 1 } : { p: 2 }],
160
165
  onClick: () => {
161
- localStorage.setItem(g, "passkey");
162
- const t = R.current.connect;
166
+ localStorage.setItem(f, e.PASSKEY);
167
+ const r = j.current.connect;
163
168
  i.chooseMethod = "passkey", i.retryConnect = () => {
164
- j.verifying = !0, i.chooseMethod = "passkey", t();
169
+ D.verifying = !0, i.chooseMethod = "passkey", r();
165
170
  };
166
171
  },
167
172
  slotProps: {
168
173
  icon: {
169
174
  sx: {
170
- fontSize: I,
175
+ fontSize: E,
171
176
  "& svg": {
172
- fontSize: I,
177
+ fontSize: E,
173
178
  width: "1em",
174
179
  height: "1em"
175
180
  }
@@ -177,78 +182,80 @@ function Se({
177
182
  }
178
183
  }
179
184
  },
180
- r.PASSKEY
185
+ e.PASSKEY
181
186
  );
182
- if (e.provider === r.EMAIL) {
183
- const t = F.find((c) => c.name === r.EMAIL);
184
- return t ? t?.renderListItem({
185
- key: t.name,
187
+ if (o.provider === e.EMAIL) {
188
+ const r = G.find((c) => c.name === e.EMAIL);
189
+ return r ? r?.renderListItem({
190
+ key: r.name,
186
191
  sx: [m === "small" ? { p: 1 } : { p: 2 }]
187
192
  // forceUpdate,
188
193
  }) : null;
189
194
  }
190
- return e.type === "oauth" ? /* @__PURE__ */ l(
191
- Ee,
195
+ return o.type === "oauth" ? /* @__PURE__ */ l(
196
+ Mo,
192
197
  {
193
- title: de[e.provider],
198
+ t: I,
199
+ isLatest: h && h === o.provider,
200
+ title: ho[o.provider],
194
201
  icon: /* @__PURE__ */ l(
195
- Le,
202
+ Ao,
196
203
  {
197
- provider: e.provider,
204
+ provider: o.provider,
198
205
  sx: {
199
206
  transform: "scale(0.95)",
200
- width: I,
201
- height: I,
207
+ width: E,
208
+ height: E,
202
209
  color: "text.primary"
203
210
  }
204
211
  }
205
212
  ),
206
213
  onClick: () => {
207
- G(e), i.retryConnect = () => {
208
- G(e);
214
+ q(o), i.retryConnect = () => {
215
+ q(o);
209
216
  };
210
217
  },
211
218
  sx: [m === "small" ? { p: 1.2 } : { p: 2 }]
212
219
  },
213
- e.provider
220
+ o.provider
214
221
  ) : null;
215
222
  }).filter(Boolean);
216
- return /* @__PURE__ */ l(L, { className: "did-connect__choose", sx: ye({ flex: 1 }, $?.root?.sx), children: /* @__PURE__ */ l(
217
- L,
223
+ return /* @__PURE__ */ l(A, { className: "did-connect__choose", sx: Io({ flex: 1 }, X?.root?.sx), children: /* @__PURE__ */ l(
224
+ A,
218
225
  {
219
226
  sx: {
220
227
  display: "flex",
221
228
  flexDirection: "column",
222
229
  gap: 2
223
230
  },
224
- children: /* @__PURE__ */ me(
225
- L,
231
+ children: /* @__PURE__ */ po(
232
+ A,
226
233
  {
227
234
  sx: [
228
235
  {
229
236
  display: "flex",
230
237
  flexDirection: "column",
231
- ...h && !p.mobile.any ? { alignItems: "center", gap: 0 } : { gap: 1.5 }
238
+ ...g && !p.mobile.any ? { alignItems: "center", gap: 0 } : { gap: 1.5 }
232
239
  }
233
240
  ],
234
241
  children: [
235
- h && !p.mobile.any ? /* @__PURE__ */ l(
236
- Pe,
242
+ g && !p.mobile.any ? /* @__PURE__ */ l(
243
+ vo,
237
244
  {
238
- qrcode: Q,
239
- tokenState: n,
245
+ qrcode: eo,
246
+ tokenState: t,
240
247
  webWalletUrl: x,
241
248
  size: m,
242
- disableSwitchApp: A,
243
- tokenKey: W,
244
- walletLoginRef: E,
245
- webLoginRef: P,
246
- onMobileLoginClick: q,
247
- onWebLoginClick: V,
248
- onBack: M ? void 0 : se
249
+ disableSwitchApp: P,
250
+ tokenKey: k,
251
+ walletLoginRef: M,
252
+ webLoginRef: v,
253
+ onMobileLoginClick: V,
254
+ onWebLoginClick: Y,
255
+ onBack: _ ? void 0 : co
249
256
  }
250
257
  ) : /* @__PURE__ */ l(
251
- L,
258
+ A,
252
259
  {
253
260
  sx: {
254
261
  display: "grid",
@@ -293,8 +300,8 @@ function Se({
293
300
  }
294
301
  }
295
302
  },
296
- children: H.length > 0 ? H : /* @__PURE__ */ l(
297
- be,
303
+ children: $.length > 0 ? $ : /* @__PURE__ */ l(
304
+ bo,
298
305
  {
299
306
  className: "arc-login-item",
300
307
  sx: {
@@ -302,37 +309,37 @@ function Se({
302
309
  textAlign: "center"
303
310
  }
304
311
  },
305
- children: le("noAuthenticationProvider")
312
+ children: I("noAuthenticationProvider")
306
313
  }
307
314
  )
308
315
  }
309
316
  ),
310
- z.map((e) => e || null)
317
+ oo.map((o) => o || null)
311
318
  ]
312
319
  }
313
320
  )
314
321
  }
315
322
  ) });
316
323
  }
317
- Se.propTypes = {
318
- onSuccess: o.func,
319
- onError: o.func,
320
- size: o.oneOf(["small", "normal", "large"]),
321
- tokenState: o.object.isRequired,
322
- webWalletUrl: o.string,
323
- tokenKey: o.string.isRequired,
324
- passkeyBehavior: o.oneOf(["none", "both", "only-existing", "only-new"]),
325
- onReset: o.func,
326
- providerList: o.array,
327
- slotProps: o.object,
328
- disableSwitchApp: o.bool,
329
- forceUpdate: o.func,
330
- magicToken: o.string,
331
- baseUrl: o.string,
332
- customItems: o.arrayOf(o.node),
333
- qrcode: o.node,
334
- hideQRCode: o.bool
324
+ No.propTypes = {
325
+ onSuccess: n.func,
326
+ onError: n.func,
327
+ size: n.oneOf(["small", "normal", "large"]),
328
+ tokenState: n.object.isRequired,
329
+ webWalletUrl: n.string,
330
+ tokenKey: n.string.isRequired,
331
+ passkeyBehavior: n.oneOf(["none", "both", "only-existing", "only-new"]),
332
+ onReset: n.func,
333
+ providerList: n.array,
334
+ slotProps: n.object,
335
+ disableSwitchApp: n.bool,
336
+ forceUpdate: n.func,
337
+ magicToken: n.string,
338
+ baseUrl: n.string,
339
+ customItems: n.arrayOf(n.node),
340
+ qrcode: n.node,
341
+ hideQRCode: n.bool
335
342
  };
336
343
  export {
337
- Se as default
344
+ No as default
338
345
  };