@arcblock/did-connect-react 3.3.0 → 3.3.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/components/did-connect-title.js +5 -4
- package/lib/Connect/components/login-item/connect-choose-list.js +86 -86
- package/lib/Connect/components/login-item/connect-provider-list.js +98 -94
- package/lib/Connect/components/login-item/login-method-item.js +22 -21
- package/lib/Connect/components/login-item/mobile-login-item.js +47 -47
- package/lib/Connect/components/login-item/web-login-item.js +40 -40
- package/lib/Connect/index.js +59 -59
- package/lib/Connect/plugins/email/list-item.js +10 -10
- package/lib/Passkey/context.js +64 -63
- package/lib/package.json.js +1 -1
- package/package.json +5 -5
- package/src/Connect/components/did-connect-title.jsx +1 -0
- package/src/Connect/components/login-item/connect-choose-list.jsx +5 -5
- package/src/Connect/components/login-item/connect-provider-list.jsx +11 -7
- package/src/Connect/components/login-item/login-method-item.jsx +4 -3
- package/src/Connect/components/login-item/mobile-login-item.jsx +5 -5
- package/src/Connect/components/login-item/web-login-item.jsx +6 -6
- package/src/Connect/index.jsx +2 -2
- package/src/Connect/plugins/email/list-item.jsx +2 -2
- package/src/Passkey/context.jsx +3 -0
|
@@ -1,68 +1,68 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
2
|
import r from "prop-types";
|
|
3
3
|
import { CircularProgress as C } from "@mui/material";
|
|
4
|
-
import { useReactive as
|
|
5
|
-
import { detectWalletExtension as
|
|
6
|
-
import { mergeSx as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { useImperativeHandle as
|
|
10
|
-
import
|
|
11
|
-
import { LOGIN_PROVIDER as
|
|
12
|
-
import
|
|
13
|
-
import { useStateContext as
|
|
14
|
-
import { EXT_DOWNLOAD_URL as
|
|
4
|
+
import { useReactive as L, useMemoizedFn as d, useCreation as p } from "ahooks";
|
|
5
|
+
import { detectWalletExtension as _, openWebWallet as w } from "@arcblock/ux/lib/Util";
|
|
6
|
+
import { mergeSx as E } from "@arcblock/ux/lib/Util/style";
|
|
7
|
+
import O from "lodash/noop";
|
|
8
|
+
import P from "lodash/omit";
|
|
9
|
+
import { useImperativeHandle as v } from "react";
|
|
10
|
+
import A from "@arcblock/ux/lib/DIDConnect/provider-icon";
|
|
11
|
+
import { LOGIN_PROVIDER_ICON_SIZE as a, LOGIN_PROVIDER as y } from "@arcblock/ux/lib/Util/constant";
|
|
12
|
+
import T from "./login-method-item.js";
|
|
13
|
+
import { useStateContext as N } from "../../contexts/state.js";
|
|
14
|
+
import { EXT_DOWNLOAD_URL as I } from "../../../constant.js";
|
|
15
15
|
import U from "../../hooks/auth-url.js";
|
|
16
16
|
function j({
|
|
17
|
-
ref:
|
|
17
|
+
ref: g = null,
|
|
18
18
|
tokenState: o,
|
|
19
|
-
locale:
|
|
19
|
+
locale: x = "en",
|
|
20
20
|
webWalletUrl: b,
|
|
21
|
-
onClick:
|
|
21
|
+
onClick: D = O,
|
|
22
22
|
disableSwitchApp: h = !1,
|
|
23
|
-
...
|
|
23
|
+
...f
|
|
24
24
|
}) {
|
|
25
|
-
const { browserBrand: i } =
|
|
25
|
+
const { browserBrand: i } = N(), l = _(), t = L({
|
|
26
26
|
loading: !1
|
|
27
|
-
}),
|
|
28
|
-
t.loading = !0,
|
|
27
|
+
}), W = U({ disableSwitchApp: h, tokenState: o }), u = d(() => {
|
|
28
|
+
t.loading = !0, w({
|
|
29
29
|
webWalletUrl: b,
|
|
30
|
-
url:
|
|
31
|
-
locale:
|
|
30
|
+
url: W,
|
|
31
|
+
locale: x,
|
|
32
32
|
appInfo: o.appInfo,
|
|
33
33
|
memberAppInfo: o.memberAppInfo
|
|
34
34
|
})?.type === "web" ? t.loading = !1 : setTimeout(() => {
|
|
35
35
|
t.loading = !1;
|
|
36
36
|
}, 3e3);
|
|
37
|
-
}), s =
|
|
38
|
-
o.url && (
|
|
37
|
+
}), s = d((e) => {
|
|
38
|
+
o.url && (D(e), e?.preventDefault(), u());
|
|
39
39
|
});
|
|
40
|
-
|
|
41
|
-
connect:
|
|
40
|
+
v(g, () => ({
|
|
41
|
+
connect: u
|
|
42
42
|
}));
|
|
43
|
-
const n = p(() => i === "edge" ?
|
|
43
|
+
const n = p(() => i === "edge" ? I.edge : i === "chrome" ? I.chrome : null, [i]), c = p(() => {
|
|
44
44
|
const e = {};
|
|
45
45
|
return l ? e.onClick = s : n ? (e.component = "a", e.href = n, e.target = "_blank", e.rel = "noopener") : e.onClick = s, o.url || (e.sx = {
|
|
46
46
|
cursor: "not-allowed"
|
|
47
47
|
}), e;
|
|
48
|
-
}, [s, o.url]),
|
|
48
|
+
}, [s, o.url]), R = p(() => l || n ? "DID Wallet (Extension)" : "DID Wallet (Web)", [l, n]);
|
|
49
49
|
return /* @__PURE__ */ m(
|
|
50
|
-
|
|
50
|
+
T,
|
|
51
51
|
{
|
|
52
|
-
...
|
|
53
|
-
sx:
|
|
52
|
+
...f,
|
|
53
|
+
sx: E(
|
|
54
54
|
{
|
|
55
55
|
textDecoration: "none"
|
|
56
56
|
},
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
f?.sx,
|
|
58
|
+
c.sx
|
|
59
59
|
),
|
|
60
|
-
title:
|
|
60
|
+
title: R,
|
|
61
61
|
icon: t.loading || !o.url ? /* @__PURE__ */ m(
|
|
62
62
|
C,
|
|
63
63
|
{
|
|
64
64
|
color: "primary",
|
|
65
|
-
size:
|
|
65
|
+
size: a,
|
|
66
66
|
sx: {
|
|
67
67
|
"& svg": {
|
|
68
68
|
transform: "scale(0.75)"
|
|
@@ -70,17 +70,17 @@ function j({
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
) : /* @__PURE__ */ m(
|
|
73
|
-
|
|
73
|
+
A,
|
|
74
74
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
style: {
|
|
75
|
+
sx: {
|
|
76
|
+
width: a,
|
|
77
|
+
height: a,
|
|
79
78
|
transform: "scale(0.9)"
|
|
80
|
-
}
|
|
79
|
+
},
|
|
80
|
+
provider: y.DID_WALLET
|
|
81
81
|
}
|
|
82
82
|
),
|
|
83
|
-
...
|
|
83
|
+
...P(c, "sx")
|
|
84
84
|
}
|
|
85
85
|
);
|
|
86
86
|
}
|
package/lib/Connect/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import { jsx as t, jsxs as p, Fragment as Le } from "react/jsx-runtime";
|
|
|
2
2
|
import { use as Be, useRef as re, useState as Fe, useEffect as ne } from "react";
|
|
3
3
|
import e from "prop-types";
|
|
4
4
|
import { Box as i, Skeleton as Ne, Divider as je } from "@mui/material";
|
|
5
|
-
import { useUpdate as He, useSize as Ve, useCreation as d, useMount as ie, useMemoizedFn as
|
|
5
|
+
import { useUpdate as He, useSize as Ve, useCreation as d, useMount as ie, useMemoizedFn as U, useDebounceFn as qe, usePrevious as Ye, useUpdateEffect as Ge } from "ahooks";
|
|
6
6
|
import b from "lodash/noop";
|
|
7
7
|
import Ke from "lodash/isUndefined";
|
|
8
8
|
import Qe from "@arcblock/ux/lib/CloseButton";
|
|
9
|
-
import { LOGIN_PROVIDER as Xe, OAUTH_PROVIDER as
|
|
9
|
+
import { LOGIN_PROVIDER as Xe, OAUTH_PROVIDER as M, DID_CONNECT_MEDIUM_WIDTH as z, LOGIN_PROVIDER_NAME as Je, DID_CONNECT_SMALL_WIDTH as Ze } from "@arcblock/ux/lib/Util/constant";
|
|
10
10
|
import $e from "@arcblock/ux/lib/QRCode";
|
|
11
11
|
import { withUxTheme as et, withContainer as tt, DIDConnectFooter as ot } from "@arcblock/ux/lib/DIDConnect";
|
|
12
12
|
import { useTheme as rt } from "@arcblock/ux/lib/Theme";
|
|
@@ -41,31 +41,31 @@ function se({
|
|
|
41
41
|
checkInterval: I = xt,
|
|
42
42
|
checkTimeout: v = gt * 1e3,
|
|
43
43
|
prefix: D = bt,
|
|
44
|
-
tokenKey:
|
|
45
|
-
locale:
|
|
44
|
+
tokenKey: L = "_t_",
|
|
45
|
+
locale: B = "en",
|
|
46
46
|
encKey: ae = "_ek_",
|
|
47
47
|
autoConnect: le = !0,
|
|
48
|
-
forceConnected:
|
|
48
|
+
forceConnected: F = !0,
|
|
49
49
|
saveConnect: ue = !0,
|
|
50
50
|
useSocket: de = !0,
|
|
51
|
-
allowWallet:
|
|
51
|
+
allowWallet: N = !0,
|
|
52
52
|
provider: fe = "",
|
|
53
53
|
messages: u = {},
|
|
54
|
-
passkeyBehavior:
|
|
54
|
+
passkeyBehavior: j = "none",
|
|
55
55
|
webWalletUrl: me = It(),
|
|
56
|
-
enabledConnectTypes: pe = ["web", "mobile", ...Object.keys(
|
|
57
|
-
extraContent:
|
|
56
|
+
enabledConnectTypes: pe = ["web", "mobile", ...Object.keys(M)],
|
|
57
|
+
extraContent: H = null,
|
|
58
58
|
disableSwitchApp: T = !1,
|
|
59
|
-
magicToken:
|
|
59
|
+
magicToken: V = void 0,
|
|
60
60
|
customItems: he = [],
|
|
61
61
|
onClose: P = b,
|
|
62
|
-
onError:
|
|
62
|
+
onError: q = b,
|
|
63
63
|
onSuccess: _ = b,
|
|
64
|
-
onRecreateSession:
|
|
64
|
+
onRecreateSession: Y = b,
|
|
65
65
|
setColor: xe = b
|
|
66
66
|
}) {
|
|
67
|
-
const R = rt(),
|
|
68
|
-
t:
|
|
67
|
+
const R = rt(), G = He(), be = Be(ct), ge = St(be?.session?.user), {
|
|
68
|
+
t: K,
|
|
69
69
|
staticState: Ce,
|
|
70
70
|
connectState: s,
|
|
71
71
|
extraParams: ye,
|
|
@@ -73,9 +73,9 @@ function se({
|
|
|
73
73
|
currentAppColor: O,
|
|
74
74
|
// 插件相关
|
|
75
75
|
selectedPlugin: c,
|
|
76
|
-
blocklet:
|
|
76
|
+
blocklet: Q,
|
|
77
77
|
masterBlocklet: we
|
|
78
|
-
} = lt(), { state: o, generate:
|
|
78
|
+
} = lt(), { state: o, generate: X, cancelWhenScanned: Se } = ft({
|
|
79
79
|
action: w,
|
|
80
80
|
baseUrl: h,
|
|
81
81
|
checkFn: S,
|
|
@@ -83,23 +83,23 @@ function se({
|
|
|
83
83
|
checkTimeout: v,
|
|
84
84
|
extraParams: ye,
|
|
85
85
|
prefix: D,
|
|
86
|
-
onError:
|
|
86
|
+
onError: q,
|
|
87
87
|
onSuccess: _,
|
|
88
|
-
locale:
|
|
89
|
-
tokenKey:
|
|
88
|
+
locale: B,
|
|
89
|
+
tokenKey: L,
|
|
90
90
|
encKey: ae,
|
|
91
91
|
autoConnect: le,
|
|
92
|
-
forceConnected:
|
|
92
|
+
forceConnected: F === !0 ? ge || !0 : F,
|
|
93
93
|
saveConnect: ue,
|
|
94
94
|
useSocket: de,
|
|
95
95
|
provider: fe
|
|
96
|
-
}), A = re(!1),
|
|
96
|
+
}), A = re(!1), J = re(null), x = Ve(J), Z = d(() => x ? x.width < z - 50 : !0, [x, x?.width]), [$, Ie] = Fe(!1);
|
|
97
97
|
ie(() => {
|
|
98
|
-
Ie(x?.width <
|
|
98
|
+
Ie(x?.width < z - 50);
|
|
99
99
|
});
|
|
100
100
|
const { oauthState: a, setBaseUrl: ve } = mt(), { passkeyState: l, setTargetAppPid: De } = ht();
|
|
101
101
|
ie(() => {
|
|
102
|
-
ve(h), De(
|
|
102
|
+
ve(h), De(Q?.appPid), o.reset(), a.reset(), l.reset();
|
|
103
103
|
}), ne(() => {
|
|
104
104
|
xe(O);
|
|
105
105
|
}, [O]);
|
|
@@ -114,12 +114,12 @@ function se({
|
|
|
114
114
|
a.error,
|
|
115
115
|
l.error,
|
|
116
116
|
c?.state?.error
|
|
117
|
-
]), C = d(() => k.includes(l.status) || k.includes(a.status) || k.includes(o.status) || k.includes(c?.state?.computedStatus), [o.status, a.status, l.status, c?.state?.computedStatus]), ee =
|
|
118
|
-
|
|
119
|
-
}), Pe =
|
|
117
|
+
]), C = d(() => k.includes(l.status) || k.includes(a.status) || k.includes(o.status) || k.includes(c?.state?.computedStatus), [o.status, a.status, l.status, c?.state?.computedStatus]), ee = U(async () => {
|
|
118
|
+
Y(), a.reset(), l.reset(), await X(!1);
|
|
119
|
+
}), Pe = U(() => {
|
|
120
120
|
s?.retryConnect();
|
|
121
|
-
}), _e =
|
|
122
|
-
|
|
121
|
+
}), _e = U(() => {
|
|
122
|
+
Y(), a.reset(), l.reset(), c?.state?.reset(), Ce.current.cancelCount++, Se();
|
|
123
123
|
}), { run: Re } = qe(
|
|
124
124
|
() => {
|
|
125
125
|
A.current || o.status === "timeout" && (A.current = !0, o.reset(), ee(), A.current = !1);
|
|
@@ -130,14 +130,14 @@ function se({
|
|
|
130
130
|
const Oe = d(() => Je[s.chooseMethod] || "DID Wallet", [s.chooseMethod]), { providerList: Ae, hideQRCode: m, hideChooseList: n } = kt({
|
|
131
131
|
action: o.action,
|
|
132
132
|
sourceAppPid: s?.sourceAppPid,
|
|
133
|
-
allowWallet:
|
|
134
|
-
passkeyBehavior:
|
|
133
|
+
allowWallet: N,
|
|
134
|
+
passkeyBehavior: j,
|
|
135
135
|
mode: f,
|
|
136
|
-
blocklet: s?.sourceAppPid ? we :
|
|
137
|
-
isSmallView:
|
|
136
|
+
blocklet: s?.sourceAppPid ? we : Q,
|
|
137
|
+
isSmallView: Z
|
|
138
138
|
}), We = Ye(s?.sourceAppPid);
|
|
139
139
|
Ge(() => {
|
|
140
|
-
Ke(We) ||
|
|
140
|
+
Ke(We) || X();
|
|
141
141
|
}, [s?.sourceAppPid]);
|
|
142
142
|
const r = (y) => {
|
|
143
143
|
const Me = R.spacing(y);
|
|
@@ -173,12 +173,12 @@ function se({
|
|
|
173
173
|
onRetry: Pe,
|
|
174
174
|
onClose: P,
|
|
175
175
|
messages: Te,
|
|
176
|
-
locale:
|
|
176
|
+
locale: B,
|
|
177
177
|
className: "did-connect__auth-status auth-status",
|
|
178
178
|
loadingIcon: s.chooseMethod ? /* @__PURE__ */ t(nt, { provider: s.chooseMethod, sx: { color: "text.primary" } }) : null,
|
|
179
179
|
chooseMethod: Oe,
|
|
180
180
|
hideRetry: s.chooseMethod === "email",
|
|
181
|
-
hideBack: !!
|
|
181
|
+
hideBack: !!V
|
|
182
182
|
}
|
|
183
183
|
) })
|
|
184
184
|
}
|
|
@@ -237,7 +237,7 @@ function se({
|
|
|
237
237
|
)
|
|
238
238
|
}
|
|
239
239
|
);
|
|
240
|
-
}, [oe, n]), ze = d(() => n ? "column-reverse" : !m && $ ? "column" : "row", [n, $, m]),
|
|
240
|
+
}, [oe, n]), ze = d(() => n ? "column-reverse" : !m && $ ? "column" : "row", [n, $, m]), W = /* @__PURE__ */ p(
|
|
241
241
|
i,
|
|
242
242
|
{
|
|
243
243
|
className: "did-connect__body",
|
|
@@ -247,7 +247,7 @@ function se({
|
|
|
247
247
|
justifyContent: "center",
|
|
248
248
|
alignItems: "stretch",
|
|
249
249
|
flex: 1,
|
|
250
|
-
gap: !m &&
|
|
250
|
+
gap: !m && Z ? 0 : 1.5,
|
|
251
251
|
overflow: "visible",
|
|
252
252
|
px: n ? 2 : 0
|
|
253
253
|
},
|
|
@@ -288,11 +288,11 @@ function se({
|
|
|
288
288
|
textAlign: "center"
|
|
289
289
|
},
|
|
290
290
|
children: [
|
|
291
|
-
|
|
291
|
+
K("scanWithWallet1"),
|
|
292
292
|
" ",
|
|
293
293
|
/* @__PURE__ */ t(yt, {}),
|
|
294
294
|
" ",
|
|
295
|
-
|
|
295
|
+
K("scanWithWallet2")
|
|
296
296
|
]
|
|
297
297
|
}
|
|
298
298
|
)
|
|
@@ -333,20 +333,20 @@ function se({
|
|
|
333
333
|
sx: [C ? { display: "none" } : {}]
|
|
334
334
|
}
|
|
335
335
|
},
|
|
336
|
-
allowWallet:
|
|
336
|
+
allowWallet: N,
|
|
337
337
|
size: m && f !== "dialog" ? "normal" : "small",
|
|
338
338
|
tokenState: o,
|
|
339
339
|
messages: u,
|
|
340
|
-
tokenKey:
|
|
340
|
+
tokenKey: L,
|
|
341
341
|
onSuccess: _,
|
|
342
|
-
passkeyBehavior:
|
|
342
|
+
passkeyBehavior: j,
|
|
343
343
|
webWalletUrl: me,
|
|
344
|
-
extraContent:
|
|
344
|
+
extraContent: H,
|
|
345
345
|
enabledConnectTypes: pe,
|
|
346
346
|
onReset: ee,
|
|
347
347
|
disableSwitchApp: T,
|
|
348
|
-
forceUpdate:
|
|
349
|
-
magicToken:
|
|
348
|
+
forceUpdate: G,
|
|
349
|
+
magicToken: V,
|
|
350
350
|
baseUrl: h,
|
|
351
351
|
customItems: he,
|
|
352
352
|
providerList: Ae
|
|
@@ -358,16 +358,16 @@ function se({
|
|
|
358
358
|
]
|
|
359
359
|
}
|
|
360
360
|
);
|
|
361
|
-
let
|
|
362
|
-
return c ?
|
|
363
|
-
fallback:
|
|
364
|
-
forceUpdate:
|
|
361
|
+
let E = W;
|
|
362
|
+
return c ? E = c.renderPlaceholder({
|
|
363
|
+
fallback: W,
|
|
364
|
+
forceUpdate: G,
|
|
365
365
|
onSuccess: _,
|
|
366
|
-
onError:
|
|
367
|
-
}) :
|
|
366
|
+
onError: q
|
|
367
|
+
}) : E = W, /* @__PURE__ */ p(
|
|
368
368
|
i,
|
|
369
369
|
{
|
|
370
|
-
ref:
|
|
370
|
+
ref: J,
|
|
371
371
|
className: "did-connect__root",
|
|
372
372
|
sx: {
|
|
373
373
|
backgroundColor: "background.default",
|
|
@@ -378,13 +378,13 @@ function se({
|
|
|
378
378
|
maxWidth: "100%",
|
|
379
379
|
width: (
|
|
380
380
|
// eslint-disable-next-line no-nested-ternary
|
|
381
|
-
f === "drawer" ? "100%" : m || C ? Ze :
|
|
381
|
+
f === "drawer" ? "100%" : m || C ? Ze : z
|
|
382
382
|
),
|
|
383
383
|
transition: "width 0.2s ease-in-out",
|
|
384
384
|
margin: "auto",
|
|
385
|
-
p:
|
|
385
|
+
p: 3,
|
|
386
386
|
pb: 0,
|
|
387
|
-
gap: 2
|
|
387
|
+
gap: 2.5
|
|
388
388
|
},
|
|
389
389
|
children: [
|
|
390
390
|
/* @__PURE__ */ t(i, { "data-did-auth-url": o.url, sx: { display: "none" } }),
|
|
@@ -393,11 +393,11 @@ function se({
|
|
|
393
393
|
{
|
|
394
394
|
title: u.title,
|
|
395
395
|
description: u.scan,
|
|
396
|
-
extraContent:
|
|
396
|
+
extraContent: H,
|
|
397
397
|
disableSwitchApp: T
|
|
398
398
|
}
|
|
399
399
|
),
|
|
400
|
-
/* @__PURE__ */ t(dt, { initHeight: 72, children:
|
|
400
|
+
/* @__PURE__ */ t(dt, { initHeight: 72, children: E }),
|
|
401
401
|
/* @__PURE__ */ t(ot, { currentAppInfo: ke, currentAppColor: O }),
|
|
402
402
|
Ee
|
|
403
403
|
]
|
|
@@ -423,10 +423,10 @@ se.propTypes = {
|
|
|
423
423
|
useSocket: e.bool,
|
|
424
424
|
extraContent: e.any,
|
|
425
425
|
passkeyBehavior: e.oneOf(["none", "both", "only-existing", "only-new"]),
|
|
426
|
-
enabledConnectTypes: e.arrayOf(e.oneOf(["web", "mobile", ...Object.keys(
|
|
426
|
+
enabledConnectTypes: e.arrayOf(e.oneOf(["web", "mobile", ...Object.keys(M)])),
|
|
427
427
|
webWalletUrl: e.string,
|
|
428
428
|
allowWallet: e.bool,
|
|
429
|
-
provider: e.oneOf([Xe.WALLET, ...Object.keys(
|
|
429
|
+
provider: e.oneOf([Xe.WALLET, ...Object.keys(M), ""]),
|
|
430
430
|
hideCloseButton: e.bool,
|
|
431
431
|
disableSwitchApp: e.bool,
|
|
432
432
|
onClose: e.func,
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { jsx as s } from "react/jsx-runtime";
|
|
2
2
|
import c from "prop-types";
|
|
3
3
|
import { useMemoizedFn as l } from "ahooks";
|
|
4
|
-
import p from "@iconify-icons/
|
|
4
|
+
import p from "@iconify-icons/tabler/mail-filled";
|
|
5
5
|
import { LOGIN_PROVIDER as o, LOGIN_PROVIDER_NAME as a } from "@arcblock/ux/lib/Util/constant";
|
|
6
|
-
import { GA_LAST_LOGIN_METHOD as
|
|
7
|
-
import
|
|
8
|
-
import { useStateContext as
|
|
6
|
+
import { GA_LAST_LOGIN_METHOD as I } from "@arcblock/ux/lib/withTracker/constant";
|
|
7
|
+
import f from "../../components/login-item/login-method-item.js";
|
|
8
|
+
import { useStateContext as u } from "../../contexts/state.js";
|
|
9
9
|
function L({ ...e }) {
|
|
10
|
-
const { setSelectedPlugin:
|
|
11
|
-
localStorage.setItem(
|
|
12
|
-
const t =
|
|
13
|
-
t.state.reset(), t.state.status = "creating",
|
|
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);
|
|
14
14
|
});
|
|
15
15
|
return /* @__PURE__ */ s(
|
|
16
|
-
|
|
16
|
+
f,
|
|
17
17
|
{
|
|
18
18
|
...e,
|
|
19
19
|
title: a[o.EMAIL],
|
|
20
20
|
icon: p,
|
|
21
|
-
onClick:
|
|
21
|
+
onClick: n
|
|
22
22
|
}
|
|
23
23
|
);
|
|
24
24
|
}
|
package/lib/Passkey/context.js
CHANGED
|
@@ -12,7 +12,7 @@ import { getBlockletData as H, getFederatedEnabled as X, getMaster as Q } from "
|
|
|
12
12
|
import { startRegistration as Y, startAuthentication as Z } from "@simplewebauthn/browser";
|
|
13
13
|
import { createAxios as $, getWebAuthnErrorMessage as h, logger as U, getApiErrorMessage as A } from "../utils.js";
|
|
14
14
|
import { parseResponse as ee, PassportSwitcher as se } from "../components/PassportSwitcher.js";
|
|
15
|
-
const F = J({}), { Provider: te, Consumer: he } = F,
|
|
15
|
+
const F = J({}), { Provider: te, Consumer: he } = F, re = {
|
|
16
16
|
zh: {
|
|
17
17
|
cancel: "取消",
|
|
18
18
|
usePasskey: "使用 Passkey",
|
|
@@ -76,7 +76,7 @@ const F = J({}), { Provider: te, Consumer: he } = F, ae = {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
|
-
function
|
|
79
|
+
function ae({
|
|
80
80
|
children: m,
|
|
81
81
|
locale: l = "en",
|
|
82
82
|
onAddPasskey: E = w,
|
|
@@ -84,7 +84,7 @@ function re({
|
|
|
84
84
|
onSwitchPassport: I = w,
|
|
85
85
|
session: R = null
|
|
86
86
|
}) {
|
|
87
|
-
const v = S(window.env?.apiPrefix || G, "/api/passkey"),
|
|
87
|
+
const v = S(window.env?.apiPrefix || G, "/api/passkey"), r = g({
|
|
88
88
|
baseUrl: "/",
|
|
89
89
|
session: void 0,
|
|
90
90
|
connecting: !1,
|
|
@@ -117,52 +117,52 @@ function re({
|
|
|
117
117
|
reset() {
|
|
118
118
|
d.creating = !1, d.verifying = !1, d.creatingStatus = "", d.verifyingStatus = "", d.error = "";
|
|
119
119
|
}
|
|
120
|
-
}), n = i((
|
|
121
|
-
if (
|
|
120
|
+
}), n = i((t, e = {}) => q(re, t, l, "en", e)), c = W(() => $({ baseURL: S(r.baseUrl, v), sessionTokenKey: "__sst", timeout: 60 * 1e3 }), [r.baseUrl, v]), x = i(async () => {
|
|
121
|
+
if (r.baseUrl === "/")
|
|
122
122
|
return window.blocklet;
|
|
123
123
|
try {
|
|
124
|
-
if (new URL(
|
|
124
|
+
if (new URL(r.baseUrl).host === window.location.host)
|
|
125
125
|
return window.blocklet;
|
|
126
126
|
} catch {
|
|
127
127
|
}
|
|
128
|
-
return await H(
|
|
129
|
-
}), P = window?.blocklet?.componentId, B = (
|
|
130
|
-
|
|
131
|
-
}, T = (
|
|
132
|
-
|
|
133
|
-
}, b = i(async (
|
|
134
|
-
const { data: e } = await c.get("/register", { params:
|
|
128
|
+
return await H(r.baseUrl);
|
|
129
|
+
}), P = window?.blocklet?.componentId, B = (t) => {
|
|
130
|
+
r.baseUrl = t || "/";
|
|
131
|
+
}, T = (t) => {
|
|
132
|
+
r.targetAppPid = t;
|
|
133
|
+
}, b = i(async (t) => {
|
|
134
|
+
const { data: e } = await c.get("/register", { params: t });
|
|
135
135
|
console.warn("passkey.create.options", e);
|
|
136
136
|
try {
|
|
137
|
-
const
|
|
138
|
-
console.warn("passkey.create.response",
|
|
139
|
-
const { data:
|
|
140
|
-
if (console.warn("passkey.create.result",
|
|
137
|
+
const s = await Y({ optionsJSON: e, useAutoRegister: !1 });
|
|
138
|
+
console.warn("passkey.create.response", s);
|
|
139
|
+
const { data: a } = await c.post("/register", s, { params: { challenge: e.challenge } });
|
|
140
|
+
if (console.warn("passkey.create.result", a), !a.verified)
|
|
141
141
|
throw new Error(n("createPasskeyFailed"));
|
|
142
|
-
return
|
|
143
|
-
} catch (
|
|
144
|
-
throw
|
|
142
|
+
return a;
|
|
143
|
+
} catch (s) {
|
|
144
|
+
throw console.error("passkey.create.error", s), s.name ? new Error(h(s, n("createPasskeyFailed"), n)) : s;
|
|
145
145
|
}
|
|
146
|
-
}), k = i(async (
|
|
147
|
-
const { data: e } = await c.get("/auth", { params:
|
|
146
|
+
}), k = i(async (t) => {
|
|
147
|
+
const { data: e } = await c.get("/auth", { params: t });
|
|
148
148
|
console.warn("passkey.auth.options", e);
|
|
149
149
|
try {
|
|
150
|
-
const
|
|
151
|
-
console.warn("passkey.auth.response",
|
|
152
|
-
const { data:
|
|
153
|
-
params: { challenge: e.challenge, targetAppPid:
|
|
150
|
+
const s = await Z({ optionsJSON: e });
|
|
151
|
+
console.warn("passkey.auth.response", s);
|
|
152
|
+
const { data: a } = await c.post("/auth", s, {
|
|
153
|
+
params: { challenge: e.challenge, targetAppPid: r.targetAppPid }
|
|
154
154
|
});
|
|
155
|
-
if (console.warn("passkey.auth.result",
|
|
155
|
+
if (console.warn("passkey.auth.result", a), !a.verified)
|
|
156
156
|
throw new Error(n("verifyPasskeyFailed"));
|
|
157
|
-
return
|
|
158
|
-
} catch (
|
|
159
|
-
throw
|
|
157
|
+
return a;
|
|
158
|
+
} catch (s) {
|
|
159
|
+
throw console.error("passkey.auth.error", s), s.name ? new Error(h(s, n("verifyPasskeyFailed"), n)) : s;
|
|
160
160
|
}
|
|
161
|
-
}), M = async (
|
|
162
|
-
|
|
161
|
+
}), M = async (t) => {
|
|
162
|
+
r.connecting = !0;
|
|
163
163
|
try {
|
|
164
164
|
const e = await b({
|
|
165
|
-
...
|
|
165
|
+
...t,
|
|
166
166
|
locale: l,
|
|
167
167
|
componentId: P
|
|
168
168
|
});
|
|
@@ -170,54 +170,55 @@ function re({
|
|
|
170
170
|
} catch (e) {
|
|
171
171
|
U.error("Failed to connect passkey", e), u.error(A(e, n("connectPasskeyFailed")));
|
|
172
172
|
} finally {
|
|
173
|
-
|
|
173
|
+
r.connecting = !1;
|
|
174
174
|
}
|
|
175
|
-
}, D = async ({ session:
|
|
176
|
-
|
|
175
|
+
}, D = async ({ session: t, connectedAccount: e }) => {
|
|
176
|
+
r.session = t, r.disconnecting = !0;
|
|
177
177
|
try {
|
|
178
|
-
const
|
|
178
|
+
const s = await k({
|
|
179
179
|
action: "disconnect",
|
|
180
180
|
locale: l,
|
|
181
181
|
componentId: P,
|
|
182
|
-
sourceAppPid:
|
|
182
|
+
sourceAppPid: t?.user?.sourceAppPid,
|
|
183
183
|
credentialId: e.id
|
|
184
184
|
});
|
|
185
|
-
u.success(n("disconnectPasskeySucceed")), C(
|
|
186
|
-
} catch (
|
|
187
|
-
U.error("Failed to disconnect passkey",
|
|
185
|
+
u.success(n("disconnectPasskeySucceed")), C(s);
|
|
186
|
+
} catch (s) {
|
|
187
|
+
U.error("Failed to disconnect passkey", s), u.error(A(s, n("disconnectPasskeyFailed")));
|
|
188
188
|
} finally {
|
|
189
|
-
|
|
189
|
+
r.disconnecting = !1;
|
|
190
190
|
}
|
|
191
|
-
}, N = async (
|
|
191
|
+
}, N = async (t = {}) => {
|
|
192
192
|
try {
|
|
193
193
|
const { data: e } = await c.get("/passports");
|
|
194
|
-
e.length ? (o.open = !0, o.currentUser =
|
|
194
|
+
e.length ? (o.open = !0, o.currentUser = t, o.passports = e || []) : u.error(n("noPassports"));
|
|
195
195
|
} catch (e) {
|
|
196
196
|
u.error(e.message || n("getPassportFailed"));
|
|
197
197
|
}
|
|
198
|
-
}, j = i((...
|
|
199
|
-
o.reset(), I(...
|
|
200
|
-
}), L = i(async ({ action:
|
|
201
|
-
const
|
|
198
|
+
}, j = i((...t) => {
|
|
199
|
+
o.reset(), I(...t);
|
|
200
|
+
}), L = i(async ({ action: t = "login", ...e } = {}) => {
|
|
201
|
+
const s = r.baseUrl;
|
|
202
202
|
if (e?.sourceAppPid === window.blocklet?.appPid)
|
|
203
|
-
|
|
203
|
+
r.baseUrl = window.blocklet?.appUrl || "/";
|
|
204
204
|
else if (e?.sourceAppPid) {
|
|
205
|
-
const
|
|
206
|
-
y && f?.appPid && e?.sourceAppPid === f?.appPid && (
|
|
205
|
+
const a = await x(), y = X(a), f = Q(a);
|
|
206
|
+
y && f?.appPid && e?.sourceAppPid === f?.appPid && (r.baseUrl = f.appUrl);
|
|
207
207
|
}
|
|
208
208
|
try {
|
|
209
|
-
const
|
|
209
|
+
const a = {
|
|
210
210
|
...e,
|
|
211
|
-
action:
|
|
211
|
+
action: t,
|
|
212
212
|
locale: l,
|
|
213
213
|
componentId: P
|
|
214
214
|
};
|
|
215
|
-
z(
|
|
216
|
-
const y = ee(await k(
|
|
215
|
+
z(a.inviter) && window.localStorage.getItem("inviter") && (a.inviter = window.localStorage.getItem("inviter"));
|
|
216
|
+
const y = ee(await k(a));
|
|
217
217
|
return y.provider = "passkey", y;
|
|
218
|
-
} catch (
|
|
219
|
-
|
|
220
|
-
|
|
218
|
+
} catch (a) {
|
|
219
|
+
console.error("passkey.login.error", a);
|
|
220
|
+
const y = h(a, n("verifyPasskeyFailed"), n);
|
|
221
|
+
throw r.baseUrl = s, new Error(y);
|
|
221
222
|
}
|
|
222
223
|
}), _ = i(() => {
|
|
223
224
|
});
|
|
@@ -234,12 +235,12 @@ function re({
|
|
|
234
235
|
loginPasskey: L,
|
|
235
236
|
logoutPasskey: _,
|
|
236
237
|
switchPassport: N,
|
|
237
|
-
baseUrl:
|
|
238
|
+
baseUrl: r.baseUrl,
|
|
238
239
|
setBaseUrl: B,
|
|
239
240
|
setTargetAppPid: T,
|
|
240
241
|
passkeyState: d,
|
|
241
|
-
disconnecting:
|
|
242
|
-
connecting:
|
|
242
|
+
disconnecting: r.disconnecting,
|
|
243
|
+
connecting: r.connecting,
|
|
243
244
|
t: n
|
|
244
245
|
},
|
|
245
246
|
children: [
|
|
@@ -261,7 +262,7 @@ function re({
|
|
|
261
262
|
function me() {
|
|
262
263
|
return K(F);
|
|
263
264
|
}
|
|
264
|
-
|
|
265
|
+
ae.propTypes = {
|
|
265
266
|
children: p.node.isRequired,
|
|
266
267
|
locale: p.string,
|
|
267
268
|
onAddPasskey: p.func,
|
|
@@ -272,6 +273,6 @@ re.propTypes = {
|
|
|
272
273
|
export {
|
|
273
274
|
he as PasskeyConsumer,
|
|
274
275
|
F as PasskeyContext,
|
|
275
|
-
|
|
276
|
+
ae as PasskeyProvider,
|
|
276
277
|
me as usePasskey
|
|
277
278
|
};
|