@arcblock/did-connect-react 3.1.30 → 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.
- package/lib/Connect/components/login-item/connect-choose-list.js +104 -102
- package/lib/Connect/plugins/email/list-item.js +13 -11
- package/lib/OAuth/context.js +98 -89
- package/lib/OAuth/passport-switcher.js +3 -112
- package/lib/Passkey/context.js +65 -54
- package/lib/Session/handler.js +55 -0
- package/lib/Session/hooks/use-session-token.js +109 -105
- package/lib/Session/index.js +455 -425
- package/lib/Session/libs/constants.js +5 -2
- package/lib/components/PassportSwitcher.js +128 -0
- package/lib/package.json.js +1 -1
- package/package.json +5 -5
- package/src/Connect/components/login-item/connect-choose-list.jsx +6 -0
- package/src/Connect/plugins/email/list-item.jsx +2 -0
- package/src/OAuth/context.jsx +15 -6
- package/src/OAuth/passport-switcher.jsx +2 -133
- package/src/Passkey/context.jsx +13 -5
- package/src/Session/handler.jsx +98 -0
- package/src/Session/hooks/use-session-token.js +12 -0
- package/src/Session/index.jsx +103 -31
- package/src/Session/libs/constants.js +3 -0
- package/src/components/PassportSwitcher.jsx +160 -0
|
@@ -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
|
|
4
|
-
import { LOGIN_PROVIDER as
|
|
5
|
-
import { getWebWalletUrl as
|
|
6
|
-
import
|
|
7
|
-
import { useMemoizedFn as
|
|
8
|
-
import
|
|
9
|
-
import { getCookieOptions as
|
|
10
|
-
import { useRef as
|
|
11
|
-
import { mergeSx as
|
|
12
|
-
import
|
|
13
|
-
import
|
|
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
|
|
16
|
+
import ae from "./login-method-item.js";
|
|
16
17
|
import { useOAuth as ce } from "../../../OAuth/context.js";
|
|
17
|
-
import { useStateContext as
|
|
18
|
-
import { getAppId as
|
|
19
|
-
import
|
|
20
|
-
import { usePasskey as
|
|
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
|
|
23
|
-
function
|
|
24
|
-
onSuccess:
|
|
25
|
-
onError: b =
|
|
26
|
-
size:
|
|
27
|
-
tokenState:
|
|
28
|
-
webWalletUrl:
|
|
29
|
-
tokenKey:
|
|
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:
|
|
32
|
+
onRest: g = d,
|
|
32
33
|
showMobileLogin: j = !0,
|
|
33
34
|
showOAuthLogin: v = !0,
|
|
34
|
-
showPasskeyLogin:
|
|
35
|
-
showWebLogin:
|
|
36
|
-
showEmailLogin:
|
|
35
|
+
showPasskeyLogin: w = !0,
|
|
36
|
+
showWebLogin: G = !0,
|
|
37
|
+
showEmailLogin: m = !0,
|
|
37
38
|
oauthProviderList: q = [],
|
|
38
39
|
slotProps: B = {},
|
|
39
|
-
disableSwitchApp:
|
|
40
|
-
forceUpdate:
|
|
41
|
-
magicToken:
|
|
40
|
+
disableSwitchApp: L = !1,
|
|
41
|
+
forceUpdate: S = d,
|
|
42
|
+
magicToken: M = void 0,
|
|
42
43
|
baseUrl: V = "/",
|
|
43
|
-
customItems:
|
|
44
|
+
customItems: H = []
|
|
44
45
|
}) {
|
|
45
|
-
const
|
|
46
|
-
|
|
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(),
|
|
49
|
-
const
|
|
49
|
+
}), C.reset(), r.chooseMethod = e.provider;
|
|
50
|
+
const a = _?.sourceAppPid;
|
|
50
51
|
try {
|
|
51
52
|
s.loading = !0, s.status = "scanned";
|
|
52
|
-
const
|
|
53
|
-
action:
|
|
54
|
-
...
|
|
55
|
-
}),
|
|
56
|
-
|
|
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
|
-
...
|
|
59
|
+
...c,
|
|
59
60
|
encrypted: !1
|
|
60
61
|
},
|
|
61
62
|
(z) => z,
|
|
62
63
|
{
|
|
63
|
-
sourceAppPid:
|
|
64
|
-
connected_app:
|
|
64
|
+
sourceAppPid: a,
|
|
65
|
+
connected_app: me(t.appInfo, t.memberAppInfo)
|
|
65
66
|
}
|
|
66
67
|
), s.loading = !1, s.status = "succeed");
|
|
67
|
-
} catch (
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
s.loading = !1, s.error =
|
|
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
|
-
}),
|
|
73
|
-
|
|
74
|
-
}), D =
|
|
75
|
-
if (
|
|
76
|
-
const e =
|
|
77
|
-
e.state.status === "idle" && (e.state.reset(), e.state.magicToken =
|
|
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 (
|
|
83
|
-
const
|
|
84
|
-
|
|
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),
|
|
87
|
+
X(e), r.retryConnect = T, setTimeout(() => {
|
|
87
88
|
Z();
|
|
88
89
|
}, 100);
|
|
89
|
-
}, [
|
|
90
|
-
|
|
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
|
-
|
|
99
|
+
u,
|
|
99
100
|
{
|
|
100
101
|
sx: [
|
|
101
102
|
{
|
|
@@ -105,43 +106,43 @@ function he({
|
|
|
105
106
|
}
|
|
106
107
|
],
|
|
107
108
|
children: [
|
|
108
|
-
j &&
|
|
109
|
-
|
|
109
|
+
j && l !== "small" && /* @__PURE__ */ n(
|
|
110
|
+
le,
|
|
110
111
|
{
|
|
111
|
-
ref:
|
|
112
|
-
tokenState:
|
|
113
|
-
sx: [
|
|
112
|
+
ref: A,
|
|
113
|
+
tokenState: t,
|
|
114
|
+
sx: [l === "small" ? { p: 1 } : { p: 2 }],
|
|
114
115
|
locale: Q,
|
|
115
|
-
tokenKey:
|
|
116
|
-
disableSwitchApp:
|
|
116
|
+
tokenKey: N,
|
|
117
|
+
disableSwitchApp: L,
|
|
117
118
|
onClick: async () => {
|
|
118
|
-
|
|
119
|
-
const e =
|
|
120
|
-
|
|
121
|
-
e(
|
|
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
|
-
|
|
127
|
+
G && /* @__PURE__ */ n(
|
|
127
128
|
ie,
|
|
128
129
|
{
|
|
129
130
|
ref: P,
|
|
130
|
-
tokenState:
|
|
131
|
-
webWalletUrl:
|
|
132
|
-
sx: [
|
|
133
|
-
disableSwitchApp:
|
|
131
|
+
tokenState: t,
|
|
132
|
+
webWalletUrl: U,
|
|
133
|
+
sx: [l === "small" ? { p: 1 } : { p: 2 }],
|
|
134
|
+
disableSwitchApp: L,
|
|
134
135
|
onClick: () => {
|
|
135
|
-
|
|
136
|
+
localStorage.setItem(p, "wallet"), t.status = "scanned", r.chooseMethod = "wallet-web";
|
|
136
137
|
const e = P.current.connect;
|
|
137
|
-
|
|
138
|
-
await
|
|
138
|
+
r.retryConnect = async () => {
|
|
139
|
+
await g(), t.error = "", t.status = "scanned", e();
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
),
|
|
143
|
-
v ||
|
|
144
|
-
|
|
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
|
-
|
|
155
|
+
E.map(
|
|
155
156
|
(e) => e.renderListItem({
|
|
156
157
|
key: e.name,
|
|
157
|
-
sx: [
|
|
158
|
+
sx: [l === "small" ? { p: 1 } : { p: 2 }]
|
|
158
159
|
// forceUpdate,
|
|
159
160
|
})
|
|
160
161
|
),
|
|
161
162
|
v ? q.map((e) => /* @__PURE__ */ n(
|
|
162
|
-
|
|
163
|
+
ae,
|
|
163
164
|
{
|
|
164
|
-
title:
|
|
165
|
+
title: ee[e.provider],
|
|
165
166
|
icon: /* @__PURE__ */ n(
|
|
166
|
-
|
|
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
|
-
|
|
179
|
-
|
|
179
|
+
k(e), r.retryConnect = () => {
|
|
180
|
+
k(e);
|
|
180
181
|
};
|
|
181
182
|
},
|
|
182
|
-
sx: [
|
|
183
|
+
sx: [l === "small" ? { p: 1 } : { p: 2 }]
|
|
183
184
|
},
|
|
184
185
|
e.provider
|
|
185
186
|
)) : null,
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
w ? /* @__PURE__ */ n(
|
|
188
|
+
de,
|
|
188
189
|
{
|
|
189
|
-
ref:
|
|
190
|
-
onSuccess:
|
|
190
|
+
ref: O,
|
|
191
|
+
onSuccess: I,
|
|
191
192
|
onError: b,
|
|
192
|
-
tokenState:
|
|
193
|
+
tokenState: t,
|
|
193
194
|
behavior: W,
|
|
194
|
-
sx: [
|
|
195
|
+
sx: [l === "small" ? { p: 1 } : { p: 2 }],
|
|
195
196
|
onClick: () => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
220
|
+
H.map((e) => e || null)
|
|
219
221
|
]
|
|
220
222
|
}
|
|
221
223
|
)
|
|
222
224
|
}
|
|
223
225
|
) });
|
|
224
226
|
}
|
|
225
|
-
|
|
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
|
-
|
|
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
|
|
4
|
-
import
|
|
5
|
-
import { LOGIN_PROVIDER as o, LOGIN_PROVIDER_NAME as
|
|
6
|
-
import
|
|
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
|
|
9
|
-
const { setSelectedPlugin: n, getPlugin: i, connectState: r } = f(), m =
|
|
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
|
-
|
|
16
|
+
I,
|
|
15
17
|
{
|
|
16
18
|
...e,
|
|
17
|
-
title:
|
|
18
|
-
icon:
|
|
19
|
+
title: a[o.EMAIL],
|
|
20
|
+
icon: p,
|
|
19
21
|
onClick: m
|
|
20
22
|
}
|
|
21
23
|
);
|
|
22
24
|
}
|
|
23
|
-
|
|
25
|
+
L.propTypes = {
|
|
24
26
|
onClick: c.func
|
|
25
27
|
};
|
|
26
28
|
export {
|
|
27
|
-
|
|
29
|
+
L as default
|
|
28
30
|
};
|