@arcblock/did-connect-react 3.4.0 → 3.4.2

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 (28) 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 +116 -117
  8. package/lib/Connect/contexts/state.js +73 -64
  9. package/lib/Connect/hooks/provider-list.js +43 -33
  10. package/lib/Connect/hooks/token.js +121 -122
  11. package/lib/Connect/plugins/email/index.js +15 -12
  12. package/lib/Connect/plugins/email/list-item.js +19 -18
  13. package/lib/Passkey/actions.js +80 -75
  14. package/lib/package.json.js +1 -1
  15. package/package.json +5 -5
  16. package/src/Connect/assets/locale.js +2 -0
  17. package/src/Connect/components/login-item/connect-choose-list.jsx +12 -5
  18. package/src/Connect/components/login-item/connect-provider-list.jsx +11 -4
  19. package/src/Connect/components/login-item/login-method-item.jsx +24 -7
  20. package/src/Connect/components/login-item/passkey-login-item.jsx +3 -1
  21. package/src/Connect/components/login-item/wallet-login-options.jsx +3 -2
  22. package/src/Connect/connect.jsx +36 -35
  23. package/src/Connect/contexts/state.jsx +10 -0
  24. package/src/Connect/hooks/provider-list.js +43 -17
  25. package/src/Connect/hooks/token.js +13 -13
  26. package/src/Connect/plugins/email/index.jsx +3 -0
  27. package/src/Connect/plugins/email/list-item.jsx +3 -2
  28. package/src/Passkey/actions.jsx +5 -0
@@ -1,74 +1,74 @@
1
- import { useRef as I, useEffect as C } from "react";
2
- import T from "lodash/get";
3
- import ue from "js-cookie";
4
- import B from "lodash/omitBy";
5
- import M from "lodash/isNil";
6
- import fe from "lodash/omit";
7
- import de from "lodash/cloneDeep";
8
- import { useReactive as H, useCreation as pe, useMemoizedFn as E } from "ahooks";
1
+ import { useRef as S, useEffect as C } from "react";
2
+ import W from "lodash/get";
3
+ import fe from "js-cookie";
4
+ import M from "lodash/omitBy";
5
+ import H from "lodash/isNil";
6
+ import de from "lodash/omit";
7
+ import pe from "lodash/cloneDeep";
8
+ import { useReactive as Q, useCreation as me, useMemoizedFn as T } from "ahooks";
9
9
  import ke from "@arcblock/react-hooks/lib/useInterval";
10
- import me from "@arcblock/react-hooks/lib/useBrowser";
11
- import { getVisitorId as he, stringifyQuery as $, isUrl as ge } from "@arcblock/ux/lib/Util";
12
- import { WsClient as be } from "@arcblock/ws";
13
- import { sleep as q, getExtraHeaders as x, getConnectedInfo as we, updateConnectedInfo as Ce, parseNextWorkflow as Q, createAxios as z, decodeConnectUrl as Se, parseTokenFromConnectUrl as Ie } from "../../utils.js";
14
- import V from "../assets/locale.js";
15
- import $e from "./security.js";
16
- import xe from "./page-show.js";
17
- import { RELAY_SOCKET_PREFIX as G } from "../../constant.js";
18
- function ve(o) {
10
+ import ge from "@arcblock/react-hooks/lib/useBrowser";
11
+ import { getVisitorId as he, stringifyQuery as x, isUrl as be } from "@arcblock/ux/lib/Util";
12
+ import { WsClient as we } from "@arcblock/ws";
13
+ import { sleep as G, getExtraHeaders as v, getConnectedInfo as Se, updateConnectedInfo as Ce, parseNextWorkflow as z, createAxios as V, decodeConnectUrl as Ie, parseTokenFromConnectUrl as $e } from "../../utils.js";
14
+ import X from "../assets/locale.js";
15
+ import xe from "./security.js";
16
+ import ve from "./page-show.js";
17
+ import { RELAY_SOCKET_PREFIX as J } from "../../constant.js";
18
+ function Ue(o) {
19
19
  const l = o || window.location.href;
20
20
  return new URL(l).host;
21
21
  }
22
22
  const P = {};
23
- function Ue({ action: o, prefix: l, checkFn: k, extraParams: v, baseUrl: m }) {
24
- const d = `${l}/token?${$(v)}`;
23
+ function Ae({ action: o, prefix: l, checkFn: m, extraParams: U, baseUrl: k }) {
24
+ const d = `${l}/token?${x(U)}`;
25
25
  return P[d] || (P[d] = async function() {
26
- const f = +/* @__PURE__ */ new Date(), h = await k(d, { headers: x(m) }), g = +/* @__PURE__ */ new Date();
27
- if (g - f < 500 && await q(500 - (g - f)), h?.data?.token)
28
- return h.data;
29
- if (h?.data?.error)
30
- throw new Error(h.data.error);
31
- const U = ge(l) ? l : `${m}${l}`;
32
- throw new Error(`Error generating ${o} QR Code from: ${U}`);
26
+ const f = +/* @__PURE__ */ new Date(), g = await m(d, { headers: v(k) }), h = +/* @__PURE__ */ new Date();
27
+ if (h - f < 500 && await G(500 - (h - f)), g?.data?.token)
28
+ return g.data;
29
+ if (g?.data?.error)
30
+ throw new Error(g.data.error);
31
+ const A = be(l) ? l : `${k}${l}`;
32
+ throw new Error(`Error generating ${o} QR Code from: ${A}`);
33
33
  }), P[d];
34
34
  }
35
- const Ae = () => {
35
+ const ye = () => {
36
36
  try {
37
37
  const l = new URL(window.location.href).searchParams.get("__connect_url__");
38
38
  if (!l)
39
39
  return null;
40
- const k = Se(l);
40
+ const m = Ie(l);
41
41
  return {
42
- token: Ie(k),
43
- url: k
42
+ token: $e(m),
43
+ url: m
44
44
  };
45
45
  } catch (o) {
46
46
  return {
47
47
  error: o
48
48
  };
49
49
  }
50
- }, J = () => T(globalThis, "blocklet.appPid") || T(globalThis, "blocklet.appId") || T(globalThis, "env.appId") || "", ye = () => (T(globalThis, "env.apiPrefix") || "/").replace(/\/$/, "").replace(G, ""), R = (o) => `relay:${J()}:${o}`, Ee = () => window.location.protocol === "https:" ? "wss:" : "ws:", X = (o) => !o || new URL(o).origin === window.location.origin, Y = (o) => ["succeed", "error", "timeout", "busy"].includes(o);
51
- function Xe({
50
+ }, Z = () => W(globalThis, "blocklet.appPid") || W(globalThis, "blocklet.appId") || W(globalThis, "env.appId") || "", Ee = () => (W(globalThis, "env.apiPrefix") || "/").replace(/\/$/, "").replace(J, ""), _ = (o) => `relay:${Z()}:${o}`, Te = () => window.location.protocol === "https:" ? "wss:" : "ws:", Y = (o) => !o || new URL(o).origin === window.location.origin, q = (o) => ["succeed", "error", "timeout", "busy"].includes(o);
51
+ function Ye({
52
52
  action: o,
53
53
  checkFn: l,
54
- checkInterval: k,
55
- checkTimeout: v,
56
- extraParams: m,
54
+ checkInterval: m,
55
+ checkTimeout: U,
56
+ extraParams: k,
57
57
  locale: d,
58
- prefix: _,
58
+ prefix: F,
59
59
  tokenKey: f,
60
- encKey: h,
61
- onError: g,
62
- onSuccess: U,
63
- baseUrl: Z,
64
- autoConnect: K = !0,
65
- forceConnected: ee = !0,
66
- saveConnect: re = !0,
60
+ encKey: g,
61
+ onError: h,
62
+ onSuccess: A,
63
+ baseUrl: K,
64
+ autoConnect: ee = !0,
65
+ forceConnected: re = !0,
66
+ saveConnect: te = !0,
67
67
  // FIXME: @zhanghan 将来需要设置为默认 false,仅在需要的时候进行保存 login, switch/role/profile
68
- useSocket: te = !0,
69
- provider: ne = "wallet"
68
+ useSocket: ne = !0,
69
+ provider: oe = "wallet"
70
70
  }) {
71
- const e = H({
71
+ const e = Q({
72
72
  checking: !1,
73
73
  loading: !1,
74
74
  token: "",
@@ -76,7 +76,6 @@ function Xe({
76
76
  store: null,
77
77
  status: "created",
78
78
  error: "",
79
- checkCount: 0,
80
79
  mfaCode: 0,
81
80
  appInfo: null,
82
81
  memberAppInfo: null,
@@ -84,80 +83,80 @@ function Xe({
84
83
  saveConnect: !1,
85
84
  inExistingSession: !1,
86
85
  nextWorkflow: "",
87
- baseUrl: Z,
88
- prefix: `${_}/${o}`,
89
- extraParams: B(m, M),
86
+ baseUrl: K,
87
+ prefix: `${F}/${o}`,
88
+ extraParams: M(k, H),
90
89
  checkFn: l,
91
90
  results: {},
92
91
  action: o,
93
- provider: ne,
92
+ provider: oe,
94
93
  reset() {
95
94
  this.error = "", this.status = "created";
96
95
  }
97
- }), F = I(null), S = V[d] || V.en, u = pe(() => Ae(), []), oe = Math.ceil(v / k), c = H({
96
+ }), I = S(0), D = S(null), $ = X[d] || X.en, u = me(() => ye(), []), se = Math.ceil(U / m), c = Q({
98
97
  onSuccessCalled: !1,
99
98
  cancelWhenScannedCounter: 0,
100
99
  isSocketAvailable: !1
101
- }), { encryptKey: se, decrypt: A } = $e(), D = me(), O = he(), a = I(null), p = I(null), b = {
100
+ }), { encryptKey: ae, decrypt: y } = xe(), O = ge(), L = he(), a = S(null), p = S(null), b = {
102
101
  ...e.extraParams,
103
102
  locale: d,
104
103
  [f]: e.token || u?.token,
105
104
  provider: e.provider
106
- }, L = async () => {
105
+ }, j = async () => {
107
106
  if (!(u?.token && u?.token === e.token)) {
108
107
  try {
109
- b[f] && e.status === "created" && await e.checkFn(`${e.prefix}/timeout?${$(b)}`, {
110
- headers: x(e.baseUrl)
108
+ b[f] && e.status === "created" && await e.checkFn(`${e.prefix}/timeout?${x(b)}`, {
109
+ headers: v(e.baseUrl)
111
110
  });
112
111
  } catch {
113
112
  }
114
113
  try {
115
- e.token && p.current && (await a.current.unsubscribe(R(e.token)), p.current = null);
114
+ e.token && p.current && (await a.current.unsubscribe(_(e.token)), p.current = null);
116
115
  } catch {
117
116
  }
118
117
  }
119
- }, ae = E((...t) => {
118
+ }, ce = T((...t) => {
120
119
  const r = {
121
- [h]: se,
120
+ [g]: ae,
122
121
  ...e.extraParams,
123
122
  locale: d,
124
- forceConnected: ee,
123
+ forceConnected: re,
125
124
  // - autoConnect 请求参数用于控制服务端是否给钱包应用发送自动连接通知
126
125
  // - 使用 connect 组件时明确传入了 autoConnect = false, 则 autoConnect 请求参数 为 false
127
126
  // - 如果 cancelWhenScannedCounter > 0, 说明用户进行过 cancel 操作, 则临时禁用自动连接, autoConnect 请求参数 为 false
128
127
  // (避免 "无限自动连接问题")
129
128
  // - 如果上次连接设备 (connected_wallet_os) 不是 ios/android, 则禁用自动连接
130
- autoConnect: K && // 如果是 wallet webview 环境, 不发送通知, 避免 wallet 连续弹出 auth 窗口 2 次 (#341)
131
- !(D.wallet || D.arcSphere) && !c.cancelWhenScannedCounter && ["ios", "android"].includes(ue.get("connected_wallet_os")),
129
+ autoConnect: ee && // 如果是 wallet webview 环境, 不发送通知, 避免 wallet 连续弹出 auth 窗口 2 次 (#341)
130
+ !(O.wallet || O.arcSphere) && !c.cancelWhenScannedCounter && ["ios", "android"].includes(fe.get("connected_wallet_os")),
132
131
  provider: e.provider
133
132
  };
134
- O && (r.visitorId = O);
135
- const n = fe(F.current || {}, ["sourceAppPid", "verbose"]);
133
+ L && (r.visitorId = L);
134
+ const n = de(D.current || {}, ["sourceAppPid", "verbose"]);
136
135
  return Object.keys(n).forEach((s) => {
137
- (!r[s] || s === h && n[s]) && (r[s] = n[s]);
138
- }), u?.token && !r.sourceToken && (r.sourceToken = u?.token), Ue({
136
+ (!r[s] || s === g && n[s]) && (r[s] = n[s]);
137
+ }), u?.token && !r.sourceToken && (r.sourceToken = u?.token), Ae({
139
138
  action: o,
140
139
  prefix: e.prefix,
141
140
  baseUrl: e.baseUrl,
142
141
  checkFn: e.checkFn,
143
142
  extraParams: r
144
143
  })(...t);
145
- }), y = E(async (t = !0) => {
146
- t && L();
144
+ }), E = T(async (t = !0) => {
145
+ t && j();
147
146
  try {
148
- e.loading = !0, e.token = "", e.url = "", e.store = null, e.extraParams = B(m, M), await q();
149
- const r = await ae(), n = r.extra || {};
150
- e.loading = !1, e.token = r.token, e.url = r.url, e.status = "created", e.error = "", e.checkCount = 0, e.appInfo = r.appInfo, e.memberAppInfo = r.memberAppInfo, e.connectedDid = n.connectedDid, e.saveConnect = n.saveConnect;
147
+ e.loading = !0, e.token = "", e.url = "", e.store = null, e.extraParams = M(k, H), await G();
148
+ const r = await ce(), n = r.extra || {};
149
+ e.loading = !1, e.token = r.token, e.url = r.url, e.status = "created", e.error = "", I.current = 0, e.appInfo = r.appInfo, e.memberAppInfo = r.memberAppInfo, e.connectedDid = n.connectedDid, e.saveConnect = n.saveConnect;
151
150
  } catch (r) {
152
- e.loading = !1, e.status = "error", e.error = `${S.generateError}: ${r.message}`;
151
+ e.loading = !1, e.status = "error", e.error = `${$.generateError}: ${r.message}`;
153
152
  }
154
- }), ce = E(() => {
153
+ }), ie = T(() => {
155
154
  c.cancelWhenScannedCounter++;
156
155
  });
157
156
  C(() => {
158
- c.cancelWhenScannedCounter > 0 && (m.nw ? g(new Error(S.retryForbidden)) : y());
159
- }, [c.cancelWhenScannedCounter]), C(() => (!(/^((?!chrome|android).)*safari/i.test(globalThis.navigator.userAgent) || Object.hasOwn(globalThis?.blocklet || {}, "DID_CONNECT_DISABLE_SOCKET")) && te && X(e.baseUrl) && J() ? (!a.current || a.current.isConnected() === !1 || a.current.baseUrl !== e.baseUrl) && (a.current = new be(
160
- `${Ee()}//${ve(e.baseUrl)}${ye()}${G}/relay`,
157
+ c.cancelWhenScannedCounter > 0 && (k.nw ? h(new Error($.retryForbidden)) : E());
158
+ }, [c.cancelWhenScannedCounter]), C(() => (!(/^((?!chrome|android).)*safari/i.test(globalThis.navigator.userAgent) || Object.hasOwn(globalThis?.blocklet || {}, "DID_CONNECT_DISABLE_SOCKET")) && ne && Y(e.baseUrl) && Z() ? (!a.current || a.current.isConnected() === !1 || a.current.baseUrl !== e.baseUrl) && (a.current = new we(
159
+ `${Te()}//${Ue(e.baseUrl)}${Ee()}${J}/relay`,
161
160
  {
162
161
  longpollerTimeout: 5e3,
163
162
  // connection timeout
@@ -168,50 +167,54 @@ function Xe({
168
167
  }), a.current.connect()) : c.isSocketAvailable && (c.isSocketAvailable = !1), () => {
169
168
  a.current && (a.current.disconnect(), a.current = null);
170
169
  }), [e.baseUrl]);
171
- const ie = () => !e.token || e.loading || Y(e.status) ? null : k, j = I(null);
170
+ const le = () => !e.token || e.loading || q(e.status) ? null : m, N = S(null);
172
171
  C(() => {
173
- j.current = { state: e, params: b };
172
+ N.current = { state: e, params: b };
174
173
  }), C(() => () => {
175
- const { state: t, params: r } = j.current;
176
- t.status === "created" && r[f] && t.checkFn(`${t.prefix}/timeout?${$(r)}`, {
177
- headers: x(t.baseUrl)
174
+ const { state: t, params: r } = N.current;
175
+ t.status === "created" && r[f] && t.checkFn(`${t.prefix}/timeout?${x(r)}`, {
176
+ headers: v(t.baseUrl)
178
177
  });
179
178
  }, []);
180
- const w = E(async (t = !1) => {
181
- if ((e.checking || document.hidden) && !t || (e.status === "created" && e.checkCount++, c.isSocketAvailable && !t))
179
+ const w = T(async (t = !1) => {
180
+ if ((e.checking || document.hidden) && !t)
181
+ return null;
182
+ if (e.status === "created" && (I.current++, e.status !== "timeout" && I.current > se))
183
+ return e.status = "timeout", j(), null;
184
+ if (c.isSocketAvailable && !t)
182
185
  return null;
183
186
  try {
184
187
  e.checking = !0;
185
- const r = await e.checkFn(`${e.prefix}/status?${$(b)}`, {
186
- headers: x(e.baseUrl)
188
+ const r = await e.checkFn(`${e.prefix}/status?${x(b)}`, {
189
+ headers: v(e.baseUrl)
187
190
  }), { status: n, error: i, mfaCode: s = 0 } = r.data;
188
191
  if (e.store = r.data, e.mfaCode = s, e.checking = !1, e.status === "scanned" && n === "created" || (e.status = n), n === "error" && i) {
189
- const N = new Error(i);
190
- throw N.response = r, N;
192
+ const B = new Error(i);
193
+ throw B.response = r, B;
191
194
  }
192
195
  return r.data;
193
196
  } catch (r) {
194
197
  const { response: n } = r;
195
198
  if (n?.status) {
196
- b[f] && e.checkFn(`${e.prefix}/timeout?${$(b)}`, {
197
- headers: x(e.baseUrl)
199
+ b[f] && e.checkFn(`${e.prefix}/timeout?${x(b)}`, {
200
+ headers: v(e.baseUrl)
198
201
  });
199
202
  const i = n?.data?.error ? n.data.error : r.message, s = new Error(i);
200
- s.code = n.status, e.status = "error", e.checking = !1, e.error = i, g(s, e?.store, A);
203
+ s.code = n.status, e.status = "error", e.checking = !1, e.error = i, h(s, e?.store, y);
201
204
  } else
202
- e.status = "error", e.checking = !1, e.error = S.generateError;
205
+ e.status = "error", e.checking = !1, e.error = $.generateError;
203
206
  }
204
207
  return null;
205
- }), le = async () => {
208
+ }), ue = async () => {
206
209
  try {
207
210
  if (u.error)
208
211
  throw u.error;
209
212
  e.loading = !0, e.token = u.token, e.url = u.url, e.inExistingSession = !0;
210
213
  let t = await w();
211
- if ((["scanned"].includes(t?.status) || t?.sourceToken === u?.token) && (await y(!1), t = await w()), F.current = t?.extraParams || null, t?.status && !["created"].includes(t?.status))
212
- throw new Error(`${S.invalidSessionStatus} [${t.status}]`);
214
+ if ((["scanned"].includes(t?.status) || t?.sourceToken === u?.token) && (await E(!1), t = await w()), D.current = t?.extraParams || null, t?.status && !["created"].includes(t?.status))
215
+ throw new Error(`${$.invalidSessionStatus} [${t.status}]`);
213
216
  } catch (t) {
214
- e.status = "error", e.error = t.message, g(t, e?.store, A);
217
+ e.status = "error", e.error = t.message, h(t, e?.store, y);
215
218
  } finally {
216
219
  e.loading = !1;
217
220
  }
@@ -219,39 +222,35 @@ function Xe({
219
222
  C(() => {
220
223
  if (!e.token && !e.store && !e.loading && !e.error)
221
224
  if (u)
222
- le();
225
+ ue();
223
226
  else {
224
- y(!1);
227
+ E(!1);
225
228
  return;
226
229
  }
227
- if (e.status !== "timeout" && e.checkCount > oe) {
228
- e.status = "timeout", L();
229
- return;
230
- }
231
230
  if (e.status === "succeed" && !c.onSuccessCalled) {
232
- const t = we({
231
+ const t = Se({
233
232
  ...e.store,
234
233
  appInfo: e.appInfo,
235
234
  memberAppInfo: e.memberAppInfo
236
235
  });
237
- if (X(e.baseUrl) && re && e.saveConnect && e.store.did && Ce(t, !0), e.store) {
236
+ if (Y(e.baseUrl) && te && e.saveConnect && e.store.did && Ce(t, !0), e.store) {
238
237
  const { nextWorkflow: r } = e.store;
239
238
  if (r)
240
239
  try {
241
- const n = Q(r, f);
242
- e.nextWorkflow = n?.nextWorkflow || r, Object.assign(e, n), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, e.checkCount = 0, e.status = "scanned", e.results = {
240
+ const n = z(r, f);
241
+ e.nextWorkflow = n?.nextWorkflow || r, Object.assign(e, n), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, I.current = 0, e.status = "scanned", e.results = {
243
242
  ...e.results,
244
243
  [e.token]: e.store
245
- }, e.checkFn = z({ baseURL: n.baseUrl, timeout: 8e3 }).get, w();
244
+ }, e.checkFn = V({ baseURL: n.baseUrl, timeout: 8e3 }).get, w();
246
245
  } catch (n) {
247
246
  console.error(`Invalid nextWorkflow: ${r}`, n), e.status = "error", e.error = `Invalid nextWorkflow: ${r}: ${n.message}`;
248
247
  }
249
- else if (e.nextWorkflow && (e.nextWorkflow = "", e.url = ""), typeof U == "function") {
248
+ else if (e.nextWorkflow && (e.nextWorkflow = "", e.url = ""), typeof A == "function") {
250
249
  const n = Object.values({ ...e.results, [e.token]: e.store });
251
250
  c.onSuccessCalled = !0;
252
- const i = n.length > 1 ? n : n[0], s = de(i);
253
- U(s, A, {
254
- sourceAppPid: m?.sourceAppPid,
251
+ const i = n.length > 1 ? n : n[0], s = pe(i);
252
+ A(s, y, {
253
+ sourceAppPid: k?.sourceAppPid,
255
254
  ...t
256
255
  });
257
256
  }
@@ -261,37 +260,37 @@ function Xe({
261
260
  if (e.store?.nextWorkflow) {
262
261
  const { nextWorkflow: t } = e.store;
263
262
  try {
264
- const r = Q(t, f);
265
- e.nextWorkflow = r?.nextWorkflow || t, Object.assign(e, r), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, e.checkCount = 0, e.status = "scanned", e.results = {
263
+ const r = z(t, f);
264
+ e.nextWorkflow = r?.nextWorkflow || t, Object.assign(e, r), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null, I.current = 0, e.status = "scanned", e.results = {
266
265
  ...e.results,
267
266
  [e.token]: e.store
268
- }, e.checkFn = z({ baseURL: r.baseUrl, timeout: 8e3 }).get, w();
267
+ }, e.checkFn = V({ baseURL: r.baseUrl, timeout: 8e3 }).get, w();
269
268
  } catch (r) {
270
269
  console.error(`Invalid nextWorkflow: ${t}`, r), e.status = "error", e.error = `Invalid nextWorkflow: ${t}: ${r.message}`;
271
270
  }
272
271
  }
273
272
  });
274
- const W = I(0);
273
+ const R = S(0);
275
274
  return C(() => {
276
275
  if (e.token && c.isSocketAvailable && a.current) {
277
276
  let t = !1;
278
- p.current ? p.current.token !== e.token && (a.current.unsubscribe(R(p.current.token)), t = !0) : t = !0, t && (p.current = a.current.subscribe(R(e.token)), W.current = 0, p.current.token = e.token, p.current.on("updated", ({ response: r }) => {
277
+ p.current ? p.current.token !== e.token && (a.current.unsubscribe(_(p.current.token)), t = !0) : t = !0, t && (p.current = a.current.subscribe(_(e.token)), R.current = 0, p.current.token = e.token, p.current.on("updated", ({ response: r }) => {
279
278
  const n = +new Date(r.updatedAt);
280
- if (n <= W.current) {
279
+ if (n <= R.current) {
281
280
  console.warn("Ignore outdated message", r);
282
281
  return;
283
282
  }
284
- W.current = n;
283
+ R.current = n;
285
284
  let { status: i, error: s } = r;
286
- i === "forbidden" && (s = S.forbidden, i = "error"), e.status = i, e.mfaCode = r.mfaCode || 0, e.store = r, e.error = s, s && g(new Error(s), e?.store, A);
285
+ i === "forbidden" && (s = $.forbidden, i = "error"), e.status = i, e.mfaCode = r.mfaCode || 0, e.store = r, e.error = s, s && h(new Error(s), e?.store, y);
287
286
  }));
288
287
  }
289
- }, [e.token, c.isSocketAvailable, a.current]), ke(w, ie()), xe(() => {
290
- e.token && Y(e.status) === !1 && (e.checking = !1, setTimeout(() => {
288
+ }, [e.token, c.isSocketAvailable, a.current]), ke(w, le()), ve(() => {
289
+ e.token && q(e.status) === !1 && (e.checking = !1, setTimeout(() => {
291
290
  w(!0);
292
291
  }, 100));
293
- }), { state: e, generate: y, cancelWhenScanned: ce };
292
+ }), { state: e, generate: E, cancelWhenScanned: ie };
294
293
  }
295
294
  export {
296
- Xe as default
295
+ Ye as default
297
296
  };
@@ -1,13 +1,14 @@
1
1
  import { jsx as a } from "react/jsx-runtime";
2
- import { useReactive as c, useMemoizedFn as u } from "ahooks";
3
- import f from "@iconify-icons/material-symbols/mail-outline-rounded";
4
- import { LOGIN_PROVIDER as h } from "@arcblock/ux/lib/Util/constant";
5
- import { translate as E } from "@arcblock/ux/lib/Locale/util";
6
- import P from "./list-item.js";
2
+ import { useReactive as u, useMemoizedFn as f } from "ahooks";
3
+ import h from "@iconify-icons/material-symbols/mail-outline-rounded";
4
+ import { LOGIN_PROVIDER as E } from "@arcblock/ux/lib/Util/constant";
5
+ import { translate as P } from "@arcblock/ux/lib/Locale/util";
6
+ import p from "./list-item.js";
7
7
  import g from "./placeholder.js";
8
- function k({ baseUrl: s }) {
9
- const i = c({
10
- baseUrl: s,
8
+ import s from "../../assets/locale.js";
9
+ function q({ baseUrl: l }) {
10
+ const i = u({
11
+ baseUrl: l,
11
12
  status: "idle",
12
13
  get computedStatus() {
13
14
  return this.status === "idle" ? "creating" : this.status === "creating" || this.status === "sending" || this.status === "verifying" ? "scanned" : this.status;
@@ -17,8 +18,9 @@ function k({ baseUrl: s }) {
17
18
  reset() {
18
19
  this.status = "idle", this.error = "", this.magicToken = "";
19
20
  }
20
- }), r = h.EMAIL, t = "Email", o = f, l = {
21
+ }), r = E.EMAIL, t = "Email", o = h, m = {
21
22
  zh: {
23
+ ...s.zh,
22
24
  email: "邮箱地址",
23
25
  emailPlaceholder: "请输入邮箱地址",
24
26
  sendCode: "发送验证邮件",
@@ -31,6 +33,7 @@ function k({ baseUrl: s }) {
31
33
  emailRequired: "邮箱地址不能为空"
32
34
  },
33
35
  en: {
36
+ ...s.en,
34
37
  email: "Email",
35
38
  emailPlaceholder: "Enter your email address",
36
39
  sendCode: "Send Verification Email",
@@ -42,13 +45,13 @@ function k({ baseUrl: s }) {
42
45
  emailInvalid: "Email format is incorrect",
43
46
  emailRequired: "Email is required"
44
47
  }
45
- }, n = u((e, m = {}, d = "en") => E(l, e, d, "en", m));
48
+ }, n = f((e, d = {}, c = "en") => P(m, e, c, "en", d));
46
49
  return {
47
50
  name: r,
48
51
  title: t,
49
52
  icon: o,
50
53
  renderListItem(e) {
51
- return /* @__PURE__ */ a(P, { ...e, state: i, name: r, title: t, icon: o, t: n });
54
+ return /* @__PURE__ */ a(p, { ...e, state: i, name: r, title: t, icon: o, t: n });
52
55
  },
53
56
  renderPlaceholder(e) {
54
57
  return /* @__PURE__ */ a(g, { ...e, state: i, name: r, title: t, icon: o, t: n });
@@ -58,5 +61,5 @@ function k({ baseUrl: s }) {
58
61
  };
59
62
  }
60
63
  export {
61
- k as default
64
+ q as default
62
65
  };
@@ -1,30 +1,31 @@
1
- import { jsx as s } from "react/jsx-runtime";
2
- import c from "prop-types";
3
- import { useMemoizedFn as l } from "ahooks";
1
+ import { jsx as c } from "react/jsx-runtime";
2
+ import l from "prop-types";
3
+ import { useMemoizedFn as a } from "ahooks";
4
4
  import p from "@iconify-icons/tabler/mail-filled";
5
- import { LOGIN_PROVIDER as o, LOGIN_PROVIDER_NAME as a } from "@arcblock/ux/lib/Util/constant";
6
- import { GA_LAST_LOGIN_METHOD as I } from "@arcblock/ux/lib/withTracker/constant";
5
+ import { LOGIN_PROVIDER as t, LOGIN_PROVIDER_NAME as I } from "@arcblock/ux/lib/Util/constant";
6
+ import { GA_LAST_LOGIN_METHOD as L } from "@arcblock/ux/lib/withTracker/constant";
7
7
  import f from "../../components/login-item/login-method-item.js";
8
- import { useStateContext as u } from "../../contexts/state.js";
9
- function L({ ...e }) {
10
- const { setSelectedPlugin: i, getPlugin: r, connectState: m } = u(), n = l(() => {
11
- localStorage.setItem(I, "email");
12
- const t = r(o.EMAIL);
13
- t.state.reset(), t.state.status = "creating", m.chooseMethod = o.EMAIL, i(t);
8
+ import { useStateContext as M } from "../../contexts/state.js";
9
+ function u({ ...i }) {
10
+ const { setSelectedPlugin: n, getPlugin: r, connectState: m, lastLoginMethod: e } = M(), s = a(() => {
11
+ localStorage.setItem(L, t.EMAIL);
12
+ const o = r(t.EMAIL);
13
+ o.state.reset(), o.state.status = "creating", m.chooseMethod = t.EMAIL, n(o);
14
14
  });
15
- return /* @__PURE__ */ s(
15
+ return /* @__PURE__ */ c(
16
16
  f,
17
17
  {
18
- ...e,
19
- title: a[o.EMAIL],
18
+ ...i,
19
+ isLatest: e && e === t.EMAIL,
20
+ title: I[t.EMAIL],
20
21
  icon: p,
21
- onClick: n
22
+ onClick: s
22
23
  }
23
24
  );
24
25
  }
25
- L.propTypes = {
26
- onClick: c.func
26
+ u.propTypes = {
27
+ onClick: l.func
27
28
  };
28
29
  export {
29
- L as default
30
+ u as default
30
31
  };