@arcblock/did-connect-react 3.1.28 → 3.1.31

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,93 +1,94 @@
1
1
  import { jsx as n, jsxs as F } from "react/jsx-runtime";
2
2
  import o from "prop-types";
3
- import { Box as m } from "@mui/material";
4
- import { LOGIN_PROVIDER as u, LOGIN_PROVIDER_NAME as S } from "@arcblock/ux/lib/Util/constant";
5
- import { getWebWalletUrl as ee } from "@arcblock/ux/lib/Util/wallet";
6
- import f from "lodash/noop";
7
- import { useMemoizedFn as g } from "ahooks";
8
- import h from "js-cookie";
9
- import { getCookieOptions as oe } from "@arcblock/ux/lib/Util";
10
- import { useRef as y, useEffect as re } from "react";
11
- import { mergeSx as te } from "@arcblock/ux/lib/Util/style";
12
- import se from "@arcblock/ux/lib/DIDConnect/provider-icon";
13
- import ne from "./mobile-login-item.js";
3
+ import { Box as u } from "@mui/material";
4
+ import { LOGIN_PROVIDER as f, LOGIN_PROVIDER_NAME as ee } from "@arcblock/ux/lib/Util/constant";
5
+ import { getWebWalletUrl as oe } from "@arcblock/ux/lib/Util/wallet";
6
+ import d from "lodash/noop";
7
+ import { useMemoizedFn as h } from "ahooks";
8
+ import y from "js-cookie";
9
+ import { getCookieOptions as te } from "@arcblock/ux/lib/Util";
10
+ import { useRef as x, useEffect as re } from "react";
11
+ import { mergeSx as se } from "@arcblock/ux/lib/Util/style";
12
+ import ne from "@arcblock/ux/lib/DIDConnect/provider-icon";
13
+ import { GA_LAST_LOGIN_METHOD as p } from "@arcblock/ux/lib/withTracker/constant";
14
+ import le from "./mobile-login-item.js";
14
15
  import ie from "./web-login-item.js";
15
- import le from "./login-method-item.js";
16
+ import ae from "./login-method-item.js";
16
17
  import { useOAuth as ce } from "../../../OAuth/context.js";
17
- import { useStateContext as ae } from "../../contexts/state.js";
18
- import { getAppId as pe, logger as me, getApiErrorMessage as ue } from "../../../utils.js";
19
- import fe from "./passkey-login-item.js";
20
- import { usePasskey as de } from "../../../Passkey/context.js";
18
+ import { useStateContext as pe } from "../../contexts/state.js";
19
+ import { getAppId as me, logger as ue, getApiErrorMessage as fe } from "../../../utils.js";
20
+ import de from "./passkey-login-item.js";
21
+ import { usePasskey as ge } from "../../../Passkey/context.js";
21
22
  import "../../../Passkey/actions.js";
22
- import ge from "../../plugins/email/index.js";
23
- function he({
24
- onSuccess: x = f,
25
- onError: b = f,
26
- size: i = "small",
27
- tokenState: r,
28
- webWalletUrl: T = ee(),
29
- tokenKey: U,
23
+ import he from "../../plugins/email/index.js";
24
+ function ye({
25
+ onSuccess: I = d,
26
+ onError: b = d,
27
+ size: l = "small",
28
+ tokenState: t,
29
+ webWalletUrl: U = oe(),
30
+ tokenKey: N,
30
31
  passkeyBehavior: W = "none",
31
- onRest: d = f,
32
+ onRest: g = d,
32
33
  showMobileLogin: j = !0,
33
34
  showOAuthLogin: v = !0,
34
- showPasskeyLogin: M = !0,
35
- showWebLogin: N = !0,
36
- showEmailLogin: p = !0,
35
+ showPasskeyLogin: w = !0,
36
+ showWebLogin: G = !0,
37
+ showEmailLogin: m = !0,
37
38
  oauthProviderList: q = [],
38
39
  slotProps: B = {},
39
- disableSwitchApp: w = !1,
40
- forceUpdate: G = f,
41
- magicToken: I = void 0,
40
+ disableSwitchApp: L = !1,
41
+ forceUpdate: S = d,
42
+ magicToken: M = void 0,
42
43
  baseUrl: V = "/",
43
- customItems: K = []
44
+ customItems: H = []
44
45
  }) {
45
- const L = y(null), P = y(null), A = y(null), { loginOAuth: $, logoutOAuth: H, t: J, oauthState: s } = ce(), { passkeyState: C } = de(), { extraParams: O, locale: Q, connectState: t, plugins: R, setPlugins: X, setSelectedPlugin: Y, getPlugin: E } = ae(), _ = g(async (e) => {
46
- r.reset(), s.reset({
46
+ const A = x(null), P = x(null), O = x(null), { loginOAuth: K, logoutOAuth: $, t: J, oauthState: s } = ce(), { passkeyState: C } = ge(), { extraParams: _, locale: Q, connectState: r, plugins: E, setPlugins: X, setSelectedPlugin: Y, getPlugin: R } = pe(), k = h(async (e) => {
47
+ localStorage.setItem(p, e.provider), t.reset(), s.reset({
47
48
  status: "scanned"
48
- }), C.reset(), t.chooseMethod = e.provider;
49
- const c = O?.sourceAppPid;
49
+ }), C.reset(), r.chooseMethod = e.provider;
50
+ const a = _?.sourceAppPid;
50
51
  try {
51
52
  s.loading = !0, s.status = "scanned";
52
- const a = await $(e, {
53
- action: r.action,
54
- ...O
55
- }), l = oe({ returnDomain: !1 });
56
- h.remove("connected_did", l), h.remove("connected_pk", l), h.remove("connected_wallet_os", l), a?.sessionToken && (await x(
53
+ const c = await K(e, {
54
+ action: t.action,
55
+ ..._
56
+ }), i = te({ returnDomain: !1 });
57
+ y.remove("connected_did", i), y.remove("connected_pk", i), y.remove("connected_wallet_os", i), c?.sessionToken && (await I(
57
58
  {
58
- ...a,
59
+ ...c,
59
60
  encrypted: !1
60
61
  },
61
62
  (z) => z,
62
63
  {
63
- sourceAppPid: c,
64
- connected_app: pe(r.appInfo, r.memberAppInfo)
64
+ sourceAppPid: a,
65
+ connected_app: me(t.appInfo, t.memberAppInfo)
65
66
  }
66
67
  ), s.loading = !1, s.status = "succeed");
67
- } catch (a) {
68
- me.error(`Failed login OAuth: ${e.provider}`, a);
69
- const l = ue(a, J("loginOAuthFailed"));
70
- s.loading = !1, s.error = l, s.status = "error", await H({ provider: e.provider }), b(new Error(l));
68
+ } catch (c) {
69
+ ue.error(`Failed login OAuth: ${e.provider}`, c);
70
+ const i = fe(c, J("loginOAuthFailed"));
71
+ s.loading = !1, s.error = i, s.status = "error", await $({ provider: e.provider }), b(new Error(i));
71
72
  }
72
- }), k = g(async () => {
73
- r.reset(), await d(), r.status = "created", t.chooseMethod = "wallet";
74
- }), D = ge({ baseUrl: V }), Z = g(() => {
75
- if (I && p && R.some((e) => e.name === u.EMAIL)) {
76
- const e = E(u.EMAIL);
77
- e.state.status === "idle" && (e.state.reset(), e.state.magicToken = I, t.chooseMethod = u.EMAIL, Y(e), G());
73
+ }), T = h(async () => {
74
+ t.reset(), await g(), t.status = "created", r.chooseMethod = "wallet";
75
+ }), D = he({ baseUrl: V }), Z = h(() => {
76
+ if (M && m && E.some((e) => e.name === f.EMAIL)) {
77
+ const e = R(f.EMAIL);
78
+ e.state.status === "idle" && (localStorage.setItem(p, "email"), e.state.reset(), e.state.magicToken = M, r.chooseMethod = f.EMAIL, Y(e), S());
78
79
  }
79
80
  });
80
81
  return re(() => {
81
82
  const e = [];
82
- if (p) {
83
- const c = E(u.EMAIL);
84
- c && c.baseUrl === D.baseUrl ? e.push(c) : e.push(D);
83
+ if (m) {
84
+ const a = R(f.EMAIL);
85
+ a && a.baseUrl === D.baseUrl ? e.push(a) : e.push(D);
85
86
  }
86
- X(e), t.retryConnect = k, setTimeout(() => {
87
+ X(e), r.retryConnect = T, setTimeout(() => {
87
88
  Z();
88
89
  }, 100);
89
- }, [p]), /* @__PURE__ */ n(m, { className: "did-connect__choose", sx: te({ flex: 1 }, B?.root?.sx), children: /* @__PURE__ */ n(
90
- m,
90
+ }, [m]), /* @__PURE__ */ n(u, { className: "did-connect__choose", sx: se({ flex: 1 }, B?.root?.sx), children: /* @__PURE__ */ n(
91
+ u,
91
92
  {
92
93
  sx: {
93
94
  display: "flex",
@@ -95,7 +96,7 @@ function he({
95
96
  gap: 2
96
97
  },
97
98
  children: /* @__PURE__ */ F(
98
- m,
99
+ u,
99
100
  {
100
101
  sx: [
101
102
  {
@@ -105,43 +106,43 @@ function he({
105
106
  }
106
107
  ],
107
108
  children: [
108
- j && i !== "small" && /* @__PURE__ */ n(
109
- ne,
109
+ j && l !== "small" && /* @__PURE__ */ n(
110
+ le,
110
111
  {
111
- ref: L,
112
- tokenState: r,
113
- sx: [i === "small" ? { p: 1 } : { p: 2 }],
112
+ ref: A,
113
+ tokenState: t,
114
+ sx: [l === "small" ? { p: 1 } : { p: 2 }],
114
115
  locale: Q,
115
- tokenKey: U,
116
- disableSwitchApp: w,
116
+ tokenKey: N,
117
+ disableSwitchApp: L,
117
118
  onClick: async () => {
118
- r.reset(), await d(), r.status = "created", t.chooseMethod = "wallet";
119
- const e = L.current?.connect;
120
- t.retryConnect = () => {
121
- e(k);
119
+ localStorage.setItem(p, "wallet"), t.reset(), await g(), t.status = "created", r.chooseMethod = "wallet";
120
+ const e = A.current?.connect;
121
+ r.retryConnect = () => {
122
+ e(T);
122
123
  };
123
124
  }
124
125
  }
125
126
  ),
126
- N && /* @__PURE__ */ n(
127
+ G && /* @__PURE__ */ n(
127
128
  ie,
128
129
  {
129
130
  ref: P,
130
- tokenState: r,
131
- webWalletUrl: T,
132
- sx: [i === "small" ? { p: 1 } : { p: 2 }],
133
- disableSwitchApp: w,
131
+ tokenState: t,
132
+ webWalletUrl: U,
133
+ sx: [l === "small" ? { p: 1 } : { p: 2 }],
134
+ disableSwitchApp: L,
134
135
  onClick: () => {
135
- r.status = "scanned", t.chooseMethod = "wallet-web";
136
+ localStorage.setItem(p, "wallet"), t.status = "scanned", r.chooseMethod = "wallet-web";
136
137
  const e = P.current.connect;
137
- t.retryConnect = async () => {
138
- await d(), r.error = "", r.status = "scanned", e();
138
+ r.retryConnect = async () => {
139
+ await g(), t.error = "", t.status = "scanned", e();
139
140
  };
140
141
  }
141
142
  }
142
143
  ),
143
- v || M || p ? /* @__PURE__ */ F(
144
- m,
144
+ v || w || m ? /* @__PURE__ */ F(
145
+ u,
145
146
  {
146
147
  sx: [
147
148
  {
@@ -151,19 +152,19 @@ function he({
151
152
  }
152
153
  ],
153
154
  children: [
154
- R.map(
155
+ E.map(
155
156
  (e) => e.renderListItem({
156
157
  key: e.name,
157
- sx: [i === "small" ? { p: 1 } : { p: 2 }]
158
+ sx: [l === "small" ? { p: 1 } : { p: 2 }]
158
159
  // forceUpdate,
159
160
  })
160
161
  ),
161
162
  v ? q.map((e) => /* @__PURE__ */ n(
162
- le,
163
+ ae,
163
164
  {
164
- title: S[e.provider],
165
+ title: ee[e.provider],
165
166
  icon: /* @__PURE__ */ n(
166
- se,
167
+ ne,
167
168
  {
168
169
  provider: e.provider,
169
170
  sx: {
@@ -175,27 +176,28 @@ function he({
175
176
  }
176
177
  ),
177
178
  onClick: () => {
178
- _(e), t.retryConnect = () => {
179
- _(e);
179
+ k(e), r.retryConnect = () => {
180
+ k(e);
180
181
  };
181
182
  },
182
- sx: [i === "small" ? { p: 1 } : { p: 2 }]
183
+ sx: [l === "small" ? { p: 1 } : { p: 2 }]
183
184
  },
184
185
  e.provider
185
186
  )) : null,
186
- M ? /* @__PURE__ */ n(
187
- fe,
187
+ w ? /* @__PURE__ */ n(
188
+ de,
188
189
  {
189
- ref: A,
190
- onSuccess: x,
190
+ ref: O,
191
+ onSuccess: I,
191
192
  onError: b,
192
- tokenState: r,
193
+ tokenState: t,
193
194
  behavior: W,
194
- sx: [i === "small" ? { p: 1 } : { p: 2 }],
195
+ sx: [l === "small" ? { p: 1 } : { p: 2 }],
195
196
  onClick: () => {
196
- const e = A.current.connect;
197
- t.chooseMethod = "passkey", t.retryConnect = () => {
198
- C.verifying = !0, t.chooseMethod = "passkey", e();
197
+ localStorage.setItem(p, "passkey");
198
+ const e = O.current.connect;
199
+ r.chooseMethod = "passkey", r.retryConnect = () => {
200
+ C.verifying = !0, r.chooseMethod = "passkey", e();
199
201
  };
200
202
  },
201
203
  slotProps: {
@@ -215,14 +217,14 @@ function he({
215
217
  ]
216
218
  }
217
219
  ) : null,
218
- K.map((e) => e || null)
220
+ H.map((e) => e || null)
219
221
  ]
220
222
  }
221
223
  )
222
224
  }
223
225
  ) });
224
226
  }
225
- he.propTypes = {
227
+ ye.propTypes = {
226
228
  onSuccess: o.func,
227
229
  onError: o.func,
228
230
  size: o.oneOf(["small", "normal", "large"]),
@@ -245,5 +247,5 @@ he.propTypes = {
245
247
  customItems: o.arrayOf(o.node)
246
248
  };
247
249
  export {
248
- he as default
250
+ ye as default
249
251
  };
@@ -1,28 +1,30 @@
1
1
  import { jsx as s } from "react/jsx-runtime";
2
2
  import c from "prop-types";
3
- import { useMemoizedFn as p } from "ahooks";
4
- import l from "@iconify-icons/material-symbols/mail-outline-rounded";
5
- import { LOGIN_PROVIDER as o, LOGIN_PROVIDER_NAME as u } from "@arcblock/ux/lib/Util/constant";
6
- import a from "../../components/login-item/login-method-item.js";
3
+ import { useMemoizedFn as l } from "ahooks";
4
+ import p from "@iconify-icons/material-symbols/mail-outline-rounded";
5
+ import { LOGIN_PROVIDER as o, LOGIN_PROVIDER_NAME as a } from "@arcblock/ux/lib/Util/constant";
6
+ import { GA_LAST_LOGIN_METHOD as u } from "@arcblock/ux/lib/withTracker/constant";
7
+ import I from "../../components/login-item/login-method-item.js";
7
8
  import { useStateContext as f } from "../../contexts/state.js";
8
- function I({ ...e }) {
9
- const { setSelectedPlugin: n, getPlugin: i, connectState: r } = f(), m = p(() => {
9
+ function L({ ...e }) {
10
+ const { setSelectedPlugin: n, getPlugin: i, connectState: r } = f(), m = l(() => {
11
+ localStorage.setItem(u, "email");
10
12
  const t = i(o.EMAIL);
11
13
  t.state.reset(), t.state.status = "creating", r.chooseMethod = o.EMAIL, n(t);
12
14
  });
13
15
  return /* @__PURE__ */ s(
14
- a,
16
+ I,
15
17
  {
16
18
  ...e,
17
- title: u[o.EMAIL],
18
- icon: l,
19
+ title: a[o.EMAIL],
20
+ icon: p,
19
21
  onClick: m
20
22
  }
21
23
  );
22
24
  }
23
- I.propTypes = {
25
+ L.propTypes = {
24
26
  onClick: c.func
25
27
  };
26
28
  export {
27
- I as default
29
+ L as default
28
30
  };