@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.
- package/lib/Connect/assets/locale.js +4 -2
- package/lib/Connect/components/login-item/connect-choose-list.js +120 -114
- package/lib/Connect/components/login-item/connect-provider-list.js +187 -180
- package/lib/Connect/components/login-item/login-method-item.js +63 -47
- package/lib/Connect/components/login-item/passkey-login-item.js +17 -15
- package/lib/Connect/components/login-item/wallet-login-options.js +42 -40
- package/lib/Connect/connect.js +116 -117
- package/lib/Connect/contexts/state.js +73 -64
- package/lib/Connect/hooks/provider-list.js +43 -33
- package/lib/Connect/hooks/token.js +121 -122
- package/lib/Connect/plugins/email/index.js +15 -12
- package/lib/Connect/plugins/email/list-item.js +19 -18
- package/lib/Passkey/actions.js +80 -75
- package/lib/package.json.js +1 -1
- package/package.json +5 -5
- package/src/Connect/assets/locale.js +2 -0
- package/src/Connect/components/login-item/connect-choose-list.jsx +12 -5
- package/src/Connect/components/login-item/connect-provider-list.jsx +11 -4
- package/src/Connect/components/login-item/login-method-item.jsx +24 -7
- package/src/Connect/components/login-item/passkey-login-item.jsx +3 -1
- package/src/Connect/components/login-item/wallet-login-options.jsx +3 -2
- package/src/Connect/connect.jsx +36 -35
- package/src/Connect/contexts/state.jsx +10 -0
- package/src/Connect/hooks/provider-list.js +43 -17
- package/src/Connect/hooks/token.js +13 -13
- package/src/Connect/plugins/email/index.jsx +3 -0
- package/src/Connect/plugins/email/list-item.jsx +3 -2
- package/src/Passkey/actions.jsx +5 -0
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { useReactive as
|
|
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
|
|
11
|
-
import { getVisitorId as he, stringifyQuery as
|
|
12
|
-
import { WsClient as
|
|
13
|
-
import { sleep as
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import { RELAY_SOCKET_PREFIX as
|
|
18
|
-
function
|
|
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
|
|
24
|
-
const d = `${l}/token?${
|
|
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(),
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
29
|
-
if (
|
|
30
|
-
throw new Error(
|
|
31
|
-
const
|
|
32
|
-
throw new Error(`Error generating ${o} QR Code from: ${
|
|
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
|
|
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
|
|
40
|
+
const m = Ie(l);
|
|
41
41
|
return {
|
|
42
|
-
token:
|
|
43
|
-
url:
|
|
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
|
-
},
|
|
51
|
-
function
|
|
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:
|
|
55
|
-
checkTimeout:
|
|
56
|
-
extraParams:
|
|
54
|
+
checkInterval: m,
|
|
55
|
+
checkTimeout: U,
|
|
56
|
+
extraParams: k,
|
|
57
57
|
locale: d,
|
|
58
|
-
prefix:
|
|
58
|
+
prefix: F,
|
|
59
59
|
tokenKey: f,
|
|
60
|
-
encKey:
|
|
61
|
-
onError:
|
|
62
|
-
onSuccess:
|
|
63
|
-
baseUrl:
|
|
64
|
-
autoConnect:
|
|
65
|
-
forceConnected:
|
|
66
|
-
saveConnect:
|
|
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:
|
|
69
|
-
provider:
|
|
68
|
+
useSocket: ne = !0,
|
|
69
|
+
provider: oe = "wallet"
|
|
70
70
|
}) {
|
|
71
|
-
const e =
|
|
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:
|
|
88
|
-
prefix: `${
|
|
89
|
-
extraParams:
|
|
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:
|
|
92
|
+
provider: oe,
|
|
94
93
|
reset() {
|
|
95
94
|
this.error = "", this.status = "created";
|
|
96
95
|
}
|
|
97
|
-
}),
|
|
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:
|
|
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
|
-
},
|
|
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?${
|
|
110
|
-
headers:
|
|
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(
|
|
114
|
+
e.token && p.current && (await a.current.unsubscribe(_(e.token)), p.current = null);
|
|
116
115
|
} catch {
|
|
117
116
|
}
|
|
118
117
|
}
|
|
119
|
-
},
|
|
118
|
+
}, ce = T((...t) => {
|
|
120
119
|
const r = {
|
|
121
|
-
[
|
|
120
|
+
[g]: ae,
|
|
122
121
|
...e.extraParams,
|
|
123
122
|
locale: d,
|
|
124
|
-
forceConnected:
|
|
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:
|
|
131
|
-
!(
|
|
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
|
-
|
|
135
|
-
const n =
|
|
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 ===
|
|
138
|
-
}), u?.token && !r.sourceToken && (r.sourceToken = u?.token),
|
|
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
|
-
}),
|
|
146
|
-
t &&
|
|
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 =
|
|
149
|
-
const r = await
|
|
150
|
-
e.loading = !1, e.token = r.token, e.url = r.url, e.status = "created", e.error = "",
|
|
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 = `${
|
|
151
|
+
e.loading = !1, e.status = "error", e.error = `${$.generateError}: ${r.message}`;
|
|
153
152
|
}
|
|
154
|
-
}),
|
|
153
|
+
}), ie = T(() => {
|
|
155
154
|
c.cancelWhenScannedCounter++;
|
|
156
155
|
});
|
|
157
156
|
C(() => {
|
|
158
|
-
c.cancelWhenScannedCounter > 0 && (
|
|
159
|
-
}, [c.cancelWhenScannedCounter]), C(() => (!(/^((?!chrome|android).)*safari/i.test(globalThis.navigator.userAgent) || Object.hasOwn(globalThis?.blocklet || {}, "DID_CONNECT_DISABLE_SOCKET")) &&
|
|
160
|
-
`${
|
|
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
|
|
170
|
+
const le = () => !e.token || e.loading || q(e.status) ? null : m, N = S(null);
|
|
172
171
|
C(() => {
|
|
173
|
-
|
|
172
|
+
N.current = { state: e, params: b };
|
|
174
173
|
}), C(() => () => {
|
|
175
|
-
const { state: t, params: r } =
|
|
176
|
-
t.status === "created" && r[f] && t.checkFn(`${t.prefix}/timeout?${
|
|
177
|
-
headers:
|
|
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 =
|
|
181
|
-
if ((e.checking || document.hidden) && !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?${
|
|
186
|
-
headers:
|
|
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
|
|
190
|
-
throw
|
|
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?${
|
|
197
|
-
headers:
|
|
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,
|
|
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 =
|
|
205
|
+
e.status = "error", e.checking = !1, e.error = $.generateError;
|
|
203
206
|
}
|
|
204
207
|
return null;
|
|
205
|
-
}),
|
|
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
|
|
212
|
-
throw new Error(`${
|
|
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,
|
|
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
|
-
|
|
225
|
+
ue();
|
|
223
226
|
else {
|
|
224
|
-
|
|
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 =
|
|
231
|
+
const t = Se({
|
|
233
232
|
...e.store,
|
|
234
233
|
appInfo: e.appInfo,
|
|
235
234
|
memberAppInfo: e.memberAppInfo
|
|
236
235
|
});
|
|
237
|
-
if (
|
|
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 =
|
|
242
|
-
e.nextWorkflow = n?.nextWorkflow || r, Object.assign(e, n), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null,
|
|
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 =
|
|
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
|
|
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 =
|
|
253
|
-
|
|
254
|
-
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 =
|
|
265
|
-
e.nextWorkflow = r?.nextWorkflow || t, Object.assign(e, r), e.store = null, e.error = "", e.url = "", e.appInfo = null, e.memberAppInfo = null,
|
|
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 =
|
|
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
|
|
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(
|
|
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 <=
|
|
279
|
+
if (n <= R.current) {
|
|
281
280
|
console.warn("Ignore outdated message", r);
|
|
282
281
|
return;
|
|
283
282
|
}
|
|
284
|
-
|
|
283
|
+
R.current = n;
|
|
285
284
|
let { status: i, error: s } = r;
|
|
286
|
-
i === "forbidden" && (s =
|
|
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,
|
|
290
|
-
e.token &&
|
|
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:
|
|
292
|
+
}), { state: e, generate: E, cancelWhenScanned: ie };
|
|
294
293
|
}
|
|
295
294
|
export {
|
|
296
|
-
|
|
295
|
+
Ye as default
|
|
297
296
|
};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { useReactive as
|
|
3
|
-
import
|
|
4
|
-
import { LOGIN_PROVIDER as
|
|
5
|
-
import { translate as
|
|
6
|
-
import
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 =
|
|
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 =
|
|
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(
|
|
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
|
-
|
|
64
|
+
q as default
|
|
62
65
|
};
|
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { useMemoizedFn as
|
|
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
|
|
6
|
-
import { GA_LAST_LOGIN_METHOD as
|
|
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
|
|
9
|
-
function
|
|
10
|
-
const { setSelectedPlugin:
|
|
11
|
-
localStorage.setItem(
|
|
12
|
-
const
|
|
13
|
-
|
|
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__ */
|
|
15
|
+
return /* @__PURE__ */ c(
|
|
16
16
|
f,
|
|
17
17
|
{
|
|
18
|
-
...
|
|
19
|
-
|
|
18
|
+
...i,
|
|
19
|
+
isLatest: e && e === t.EMAIL,
|
|
20
|
+
title: I[t.EMAIL],
|
|
20
21
|
icon: p,
|
|
21
|
-
onClick:
|
|
22
|
+
onClick: s
|
|
22
23
|
}
|
|
23
24
|
);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
onClick:
|
|
26
|
+
u.propTypes = {
|
|
27
|
+
onClick: l.func
|
|
27
28
|
};
|
|
28
29
|
export {
|
|
29
|
-
|
|
30
|
+
u as default
|
|
30
31
|
};
|