@arcblock/did-connect-react 3.4.13 → 3.4.15

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