@arcblock/did-connect-react 3.3.1 → 3.3.3
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/OAuth/context.js +1 -1
- package/lib/package.json.js +1 -1
- package/lib/utils.js +2 -2
- 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/OAuth/context.jsx +1 -1
- package/src/utils.js +2 -2
|
@@ -1,128 +1,128 @@
|
|
|
1
|
-
import { jsx as s, jsxs as
|
|
1
|
+
import { jsx as s, jsxs as oe } from "react/jsx-runtime";
|
|
2
2
|
import t from "prop-types";
|
|
3
|
-
import { Box as
|
|
4
|
-
import { LOGIN_PROVIDER as r, LOGIN_PROVIDER_NAME as
|
|
5
|
-
import { checkSameProtocol as
|
|
3
|
+
import { Box as p } from "@mui/material";
|
|
4
|
+
import { LOGIN_PROVIDER as r, LOGIN_PROVIDER_ICON_SIZE as h, LOGIN_PROVIDER_NAME as te } from "@arcblock/ux/lib/Util/constant";
|
|
5
|
+
import { checkSameProtocol as ne, getWebWalletUrl as re } from "@arcblock/ux/lib/Util/wallet";
|
|
6
6
|
import u from "lodash/noop";
|
|
7
|
-
import { useMemoizedFn as
|
|
8
|
-
import
|
|
9
|
-
import { detectWalletExtension as
|
|
10
|
-
import { useRef as
|
|
11
|
-
import { mergeSx as
|
|
12
|
-
import
|
|
13
|
-
import { GA_LAST_LOGIN_METHOD as
|
|
14
|
-
import { translate as
|
|
15
|
-
import
|
|
7
|
+
import { useMemoizedFn as g } from "ahooks";
|
|
8
|
+
import I from "js-cookie";
|
|
9
|
+
import { detectWalletExtension as ie, getCookieOptions as se } from "@arcblock/ux/lib/Util";
|
|
10
|
+
import { useRef as L, useEffect as le } from "react";
|
|
11
|
+
import { mergeSx as ce } from "@arcblock/ux/lib/Util/style";
|
|
12
|
+
import ae from "@arcblock/ux/lib/DIDConnect/provider-icon";
|
|
13
|
+
import { GA_LAST_LOGIN_METHOD as d } from "@arcblock/ux/lib/withTracker/constant";
|
|
14
|
+
import { translate as me } from "@arcblock/ux/lib/Locale/util";
|
|
15
|
+
import de from "@arcblock/ux/lib/Empty";
|
|
16
16
|
import { useBrowser as pe } from "@arcblock/react-hooks";
|
|
17
|
-
import
|
|
17
|
+
import he from "./mobile-login-item.js";
|
|
18
18
|
import ue from "./web-login-item.js";
|
|
19
|
-
import
|
|
20
|
-
import { useOAuth as
|
|
21
|
-
import { useStateContext as
|
|
22
|
-
import { getAppId as
|
|
19
|
+
import ge from "./login-method-item.js";
|
|
20
|
+
import { useOAuth as fe } from "../../../OAuth/context.js";
|
|
21
|
+
import { useStateContext as ye } from "../../contexts/state.js";
|
|
22
|
+
import { getAppId as Ie, logger as Le, getApiErrorMessage as xe } from "../../../utils.js";
|
|
23
23
|
import Ae from "./passkey-login-item.js";
|
|
24
|
-
import { usePasskey as
|
|
24
|
+
import { usePasskey as Ee } from "../../../Passkey/context.js";
|
|
25
25
|
import "../../../Passkey/actions.js";
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
function
|
|
29
|
-
onSuccess:
|
|
26
|
+
import Ce from "../../plugins/email/index.js";
|
|
27
|
+
import Pe from "../../assets/locale.js";
|
|
28
|
+
function ve({
|
|
29
|
+
onSuccess: x = u,
|
|
30
30
|
onError: A = u,
|
|
31
31
|
size: m = "small",
|
|
32
32
|
tokenState: n,
|
|
33
|
-
webWalletUrl:
|
|
33
|
+
webWalletUrl: E = re(),
|
|
34
34
|
tokenKey: U,
|
|
35
|
-
passkeyBehavior:
|
|
36
|
-
onReset:
|
|
37
|
-
providerList:
|
|
38
|
-
slotProps:
|
|
39
|
-
disableSwitchApp:
|
|
40
|
-
forceUpdate:
|
|
41
|
-
magicToken:
|
|
42
|
-
baseUrl:
|
|
35
|
+
passkeyBehavior: C = "none",
|
|
36
|
+
onReset: f = u,
|
|
37
|
+
providerList: y = [],
|
|
38
|
+
slotProps: B = {},
|
|
39
|
+
disableSwitchApp: P = !1,
|
|
40
|
+
forceUpdate: K = u,
|
|
41
|
+
magicToken: v = void 0,
|
|
42
|
+
baseUrl: V = "/",
|
|
43
43
|
customItems: q = []
|
|
44
44
|
}) {
|
|
45
|
-
const
|
|
46
|
-
localStorage.setItem(
|
|
45
|
+
const _ = L(null), M = L(null), b = L(null), w = pe(), Y = ne(E), O = ie(), { loginOAuth: H, logoutOAuth: Z, t: $, oauthState: l } = fe(), { passkeyState: R } = Ee(), { extraParams: T, locale: k, connectState: i, plugins: S, setPlugins: z, setSelectedPlugin: J, getPlugin: j } = ye(), Q = g((e, o = {}) => me(Pe, e, k, "en", o)), N = g(async (e) => {
|
|
46
|
+
localStorage.setItem(d, e.provider), n.reset(), l.reset({
|
|
47
47
|
status: "scanned"
|
|
48
|
-
}),
|
|
48
|
+
}), R.reset(), i.chooseMethod = e.provider;
|
|
49
49
|
const o = T?.sourceAppPid;
|
|
50
50
|
try {
|
|
51
51
|
l.loading = !0, l.status = "scanned";
|
|
52
|
-
const c = await
|
|
52
|
+
const c = await H(e, {
|
|
53
53
|
action: n.action,
|
|
54
54
|
...T
|
|
55
|
-
}), a =
|
|
56
|
-
|
|
55
|
+
}), a = se({ returnDomain: !1 });
|
|
56
|
+
I.remove("connected_did", a), I.remove("connected_pk", a), I.remove("connected_wallet_os", a), c?.sessionToken && (await x(
|
|
57
57
|
{
|
|
58
58
|
...c,
|
|
59
59
|
encrypted: !1
|
|
60
60
|
},
|
|
61
|
-
(
|
|
61
|
+
(ee) => ee,
|
|
62
62
|
{
|
|
63
63
|
sourceAppPid: o,
|
|
64
|
-
connected_app:
|
|
64
|
+
connected_app: Ie(n.appInfo, n.memberAppInfo)
|
|
65
65
|
}
|
|
66
66
|
), l.loading = !1, l.status = "succeed");
|
|
67
67
|
} catch (c) {
|
|
68
|
-
|
|
69
|
-
const a =
|
|
70
|
-
l.loading = !1, l.error = a, l.status = "error", await
|
|
68
|
+
Le.error(`Failed login OAuth: ${e.provider}`, c);
|
|
69
|
+
const a = xe(c, $("loginOAuthFailed"));
|
|
70
|
+
l.loading = !1, l.error = a, l.status = "error", await Z({ provider: e.provider }), A(new Error(a));
|
|
71
71
|
}
|
|
72
|
-
}),
|
|
73
|
-
n.reset(), await
|
|
74
|
-
}),
|
|
75
|
-
if (
|
|
72
|
+
}), D = g(async () => {
|
|
73
|
+
n.reset(), await f(), n.status = "created", i.chooseMethod = "wallet";
|
|
74
|
+
}), W = y.some((e) => e.provider === r.EMAIL), F = Ce({ baseUrl: V }), X = g(() => {
|
|
75
|
+
if (v && y.some((e) => e.name === r.EMAIL) && S.some((e) => e.name === r.EMAIL)) {
|
|
76
76
|
const e = j(r.EMAIL);
|
|
77
|
-
e.state.status === "idle" && (localStorage.setItem(
|
|
77
|
+
e.state.status === "idle" && (localStorage.setItem(d, "email"), e.state.reset(), e.state.magicToken = v, i.chooseMethod = r.EMAIL, J(e), K());
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
|
|
80
|
+
le(() => {
|
|
81
81
|
const e = [];
|
|
82
|
-
if (
|
|
82
|
+
if (W) {
|
|
83
83
|
const o = j(r.EMAIL);
|
|
84
84
|
o && o.baseUrl === F.baseUrl ? e.push(o) : e.push(F);
|
|
85
85
|
}
|
|
86
|
-
z(e), i.retryConnect =
|
|
86
|
+
z(e), i.retryConnect = D, setTimeout(() => {
|
|
87
87
|
X();
|
|
88
88
|
}, 100);
|
|
89
|
-
}, [
|
|
90
|
-
const
|
|
89
|
+
}, [W]);
|
|
90
|
+
const G = y.map((e) => {
|
|
91
91
|
if (e.provider === r.WALLET) {
|
|
92
|
-
if (
|
|
92
|
+
if (w.mobile.any)
|
|
93
93
|
return /* @__PURE__ */ s(
|
|
94
|
-
|
|
94
|
+
he,
|
|
95
95
|
{
|
|
96
|
-
ref:
|
|
96
|
+
ref: _,
|
|
97
97
|
tokenState: n,
|
|
98
98
|
sx: [m === "small" ? { p: 1 } : { p: 2 }],
|
|
99
|
-
locale:
|
|
99
|
+
locale: k,
|
|
100
100
|
tokenKey: U,
|
|
101
|
-
disableSwitchApp:
|
|
101
|
+
disableSwitchApp: P,
|
|
102
102
|
onClick: async () => {
|
|
103
|
-
localStorage.setItem(
|
|
104
|
-
const o =
|
|
103
|
+
localStorage.setItem(d, "wallet"), n.reset(), await f(), n.status = "created", i.chooseMethod = "wallet";
|
|
104
|
+
const o = _.current?.connect;
|
|
105
105
|
i.retryConnect = () => {
|
|
106
|
-
o(
|
|
106
|
+
o(D);
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
r.WALLET
|
|
111
111
|
);
|
|
112
|
-
if ((
|
|
112
|
+
if ((Y || O) && (!w.mobile.any || O))
|
|
113
113
|
return /* @__PURE__ */ s(
|
|
114
114
|
ue,
|
|
115
115
|
{
|
|
116
116
|
ref: M,
|
|
117
117
|
tokenState: n,
|
|
118
|
-
webWalletUrl:
|
|
118
|
+
webWalletUrl: E,
|
|
119
119
|
sx: [m === "small" ? { p: 1 } : { p: 2 }],
|
|
120
|
-
disableSwitchApp:
|
|
120
|
+
disableSwitchApp: P,
|
|
121
121
|
onClick: () => {
|
|
122
|
-
localStorage.setItem(
|
|
122
|
+
localStorage.setItem(d, "wallet"), n.status = "scanned", i.chooseMethod = "wallet-web";
|
|
123
123
|
const o = M.current.connect;
|
|
124
124
|
i.retryConnect = async () => {
|
|
125
|
-
await
|
|
125
|
+
await f(), n.error = "", n.status = "scanned", o();
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
},
|
|
@@ -130,28 +130,28 @@ function Pe({
|
|
|
130
130
|
);
|
|
131
131
|
}
|
|
132
132
|
if (e.provider === r.PASSKEY)
|
|
133
|
-
return
|
|
133
|
+
return C === "none" ? null : /* @__PURE__ */ s(
|
|
134
134
|
Ae,
|
|
135
135
|
{
|
|
136
|
-
ref:
|
|
137
|
-
onSuccess:
|
|
136
|
+
ref: b,
|
|
137
|
+
onSuccess: x,
|
|
138
138
|
onError: A,
|
|
139
139
|
tokenState: n,
|
|
140
|
-
behavior:
|
|
140
|
+
behavior: C,
|
|
141
141
|
sx: [m === "small" ? { p: 1 } : { p: 2 }],
|
|
142
142
|
onClick: () => {
|
|
143
|
-
localStorage.setItem(
|
|
144
|
-
const o =
|
|
143
|
+
localStorage.setItem(d, "passkey");
|
|
144
|
+
const o = b.current.connect;
|
|
145
145
|
i.chooseMethod = "passkey", i.retryConnect = () => {
|
|
146
|
-
|
|
146
|
+
R.verifying = !0, i.chooseMethod = "passkey", o();
|
|
147
147
|
};
|
|
148
148
|
},
|
|
149
149
|
slotProps: {
|
|
150
150
|
icon: {
|
|
151
151
|
sx: {
|
|
152
|
-
fontSize:
|
|
152
|
+
fontSize: h,
|
|
153
153
|
"& svg": {
|
|
154
|
-
fontSize:
|
|
154
|
+
fontSize: h,
|
|
155
155
|
width: "1em",
|
|
156
156
|
height: "1em"
|
|
157
157
|
}
|
|
@@ -162,7 +162,7 @@ function Pe({
|
|
|
162
162
|
r.PASSKEY
|
|
163
163
|
);
|
|
164
164
|
if (e.provider === r.EMAIL) {
|
|
165
|
-
const o =
|
|
165
|
+
const o = S.find((c) => c.name === r.EMAIL);
|
|
166
166
|
return o ? o?.renderListItem({
|
|
167
167
|
key: o.name,
|
|
168
168
|
sx: [m === "small" ? { p: 1 } : { p: 2 }]
|
|
@@ -170,41 +170,41 @@ function Pe({
|
|
|
170
170
|
}) : null;
|
|
171
171
|
}
|
|
172
172
|
return e.type === "oauth" ? /* @__PURE__ */ s(
|
|
173
|
-
|
|
173
|
+
ge,
|
|
174
174
|
{
|
|
175
|
-
title:
|
|
175
|
+
title: te[e.provider],
|
|
176
176
|
icon: /* @__PURE__ */ s(
|
|
177
|
-
|
|
177
|
+
ae,
|
|
178
178
|
{
|
|
179
179
|
provider: e.provider,
|
|
180
180
|
sx: {
|
|
181
181
|
transform: "scale(0.95)",
|
|
182
|
-
width:
|
|
183
|
-
height:
|
|
182
|
+
width: h,
|
|
183
|
+
height: h,
|
|
184
184
|
color: "text.primary"
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
),
|
|
188
188
|
onClick: () => {
|
|
189
|
-
|
|
190
|
-
|
|
189
|
+
N(e), i.retryConnect = () => {
|
|
190
|
+
N(e);
|
|
191
191
|
};
|
|
192
192
|
},
|
|
193
|
-
sx: [m === "small" ? { p: 1 } : { p: 2 }]
|
|
193
|
+
sx: [m === "small" ? { p: 1.2 } : { p: 2 }]
|
|
194
194
|
},
|
|
195
195
|
e.provider
|
|
196
196
|
) : null;
|
|
197
197
|
}).filter(Boolean);
|
|
198
|
-
return /* @__PURE__ */ s(
|
|
199
|
-
|
|
198
|
+
return /* @__PURE__ */ s(p, { className: "did-connect__choose", sx: ce({ flex: 1 }, B?.root?.sx), children: /* @__PURE__ */ s(
|
|
199
|
+
p,
|
|
200
200
|
{
|
|
201
201
|
sx: {
|
|
202
202
|
display: "flex",
|
|
203
203
|
flexDirection: "column",
|
|
204
204
|
gap: 2
|
|
205
205
|
},
|
|
206
|
-
children: /* @__PURE__ */
|
|
207
|
-
|
|
206
|
+
children: /* @__PURE__ */ oe(
|
|
207
|
+
p,
|
|
208
208
|
{
|
|
209
209
|
sx: [
|
|
210
210
|
{
|
|
@@ -215,15 +215,19 @@ function Pe({
|
|
|
215
215
|
],
|
|
216
216
|
children: [
|
|
217
217
|
/* @__PURE__ */ s(
|
|
218
|
-
|
|
218
|
+
p,
|
|
219
219
|
{
|
|
220
220
|
sx: {
|
|
221
221
|
display: "grid",
|
|
222
222
|
gridTemplateColumns: "repeat(12, 1fr)",
|
|
223
|
-
gap: 1.
|
|
223
|
+
gap: 1.5,
|
|
224
224
|
".arc-login-item:nth-child(-n+3)": {
|
|
225
225
|
gridColumn: "span 12"
|
|
226
226
|
},
|
|
227
|
+
// 当登录项大于等于 5 时,第三个登录项增加一个 marginBottom,用于分割独占一行的和一行多个的登录项
|
|
228
|
+
".arc-login-item:nth-child(3):nth-last-child(n+3)": {
|
|
229
|
+
mb: 1
|
|
230
|
+
},
|
|
227
231
|
".arc-login-item:nth-child(4):last-child": {
|
|
228
232
|
gridColumn: "span 12"
|
|
229
233
|
},
|
|
@@ -256,8 +260,8 @@ function Pe({
|
|
|
256
260
|
}
|
|
257
261
|
}
|
|
258
262
|
},
|
|
259
|
-
children:
|
|
260
|
-
|
|
263
|
+
children: G.length > 0 ? G : /* @__PURE__ */ s(
|
|
264
|
+
de,
|
|
261
265
|
{
|
|
262
266
|
className: "arc-login-item",
|
|
263
267
|
sx: {
|
|
@@ -277,7 +281,7 @@ function Pe({
|
|
|
277
281
|
}
|
|
278
282
|
) });
|
|
279
283
|
}
|
|
280
|
-
|
|
284
|
+
ve.propTypes = {
|
|
281
285
|
onSuccess: t.func,
|
|
282
286
|
onError: t.func,
|
|
283
287
|
size: t.oneOf(["small", "normal", "large"]),
|
|
@@ -295,5 +299,5 @@ Pe.propTypes = {
|
|
|
295
299
|
customItems: t.arrayOf(t.node)
|
|
296
300
|
};
|
|
297
301
|
export {
|
|
298
|
-
|
|
302
|
+
ve as default
|
|
299
303
|
};
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { jsxs as t, jsx as e, Fragment as
|
|
2
|
-
import { useTheme as
|
|
1
|
+
import { jsxs as t, jsx as e, Fragment as g } from "react/jsx-runtime";
|
|
2
|
+
import { useTheme as y, Box as r, Tooltip as u, Typography as s } from "@mui/material";
|
|
3
3
|
import { Icon as c } from "@iconify/react";
|
|
4
|
-
import { isValidElement as
|
|
4
|
+
import { isValidElement as _ } from "react";
|
|
5
5
|
import o from "prop-types";
|
|
6
6
|
import { mergeSx as m } from "@arcblock/ux/lib/Util/style";
|
|
7
|
-
import
|
|
8
|
-
|
|
7
|
+
import { LOGIN_PROVIDER_ICON_SIZE as p } from "@arcblock/ux/lib/Util/constant";
|
|
8
|
+
import I from "@iconify-icons/material-symbols/arrow-right-alt-rounded";
|
|
9
|
+
function b({
|
|
9
10
|
title: n,
|
|
10
11
|
description: a = null,
|
|
11
12
|
icon: i,
|
|
12
|
-
iconScale:
|
|
13
|
-
slotProps:
|
|
14
|
-
mode:
|
|
13
|
+
iconScale: d = 0.95,
|
|
14
|
+
slotProps: f = {},
|
|
15
|
+
mode: h = "normal",
|
|
15
16
|
...l
|
|
16
17
|
}) {
|
|
17
|
-
const
|
|
18
|
+
const x = y();
|
|
18
19
|
return /* @__PURE__ */ t(
|
|
19
20
|
r,
|
|
20
21
|
{
|
|
@@ -26,7 +27,7 @@ function _({
|
|
|
26
27
|
alignItems: "center",
|
|
27
28
|
gap: 1,
|
|
28
29
|
cursor: "pointer",
|
|
29
|
-
p: 1,
|
|
30
|
+
p: 1.2,
|
|
30
31
|
borderRadius: 1,
|
|
31
32
|
backgroundColor: "grey.50",
|
|
32
33
|
textDecoration: "none",
|
|
@@ -50,7 +51,7 @@ function _({
|
|
|
50
51
|
l?.sx
|
|
51
52
|
),
|
|
52
53
|
children: [
|
|
53
|
-
/* @__PURE__ */ e(
|
|
54
|
+
/* @__PURE__ */ e(u, { title: n, children: /* @__PURE__ */ e(
|
|
54
55
|
r,
|
|
55
56
|
{
|
|
56
57
|
className: "arc-login-item__icon",
|
|
@@ -61,23 +62,23 @@ function _({
|
|
|
61
62
|
alignItems: "center",
|
|
62
63
|
color: "text.primary"
|
|
63
64
|
},
|
|
64
|
-
|
|
65
|
+
f?.icon?.sx
|
|
65
66
|
),
|
|
66
|
-
children:
|
|
67
|
+
children: _(i) ? i : /* @__PURE__ */ e(
|
|
67
68
|
r,
|
|
68
69
|
{
|
|
69
70
|
component: c,
|
|
70
71
|
icon: i,
|
|
71
72
|
sx: {
|
|
72
|
-
transform: `scale(${
|
|
73
|
-
width:
|
|
74
|
-
height:
|
|
73
|
+
transform: `scale(${d})`,
|
|
74
|
+
width: p,
|
|
75
|
+
height: p
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
)
|
|
78
79
|
}
|
|
79
80
|
) }),
|
|
80
|
-
|
|
81
|
+
h === "normal" ? /* @__PURE__ */ t(g, { children: [
|
|
81
82
|
/* @__PURE__ */ t(r, { className: "arc-login-item__body", sx: { display: "flex", flexDirection: "column", flex: 1 }, children: [
|
|
82
83
|
/* @__PURE__ */ e(
|
|
83
84
|
s,
|
|
@@ -107,9 +108,9 @@ function _({
|
|
|
107
108
|
c,
|
|
108
109
|
{
|
|
109
110
|
className: "other-item-icon",
|
|
110
|
-
icon:
|
|
111
|
+
icon: I,
|
|
111
112
|
fontSize: "1.3rem",
|
|
112
|
-
color:
|
|
113
|
+
color: x.palette.primary.main
|
|
113
114
|
}
|
|
114
115
|
)
|
|
115
116
|
] }) : null
|
|
@@ -117,7 +118,7 @@ function _({
|
|
|
117
118
|
}
|
|
118
119
|
);
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
+
b.propTypes = {
|
|
121
122
|
title: o.string.isRequired,
|
|
122
123
|
description: o.string,
|
|
123
124
|
icon: o.any.isRequired,
|
|
@@ -126,5 +127,5 @@ _.propTypes = {
|
|
|
126
127
|
mode: o.oneOf(["mini", "simple", "normal"])
|
|
127
128
|
};
|
|
128
129
|
export {
|
|
129
|
-
|
|
130
|
+
b as default
|
|
130
131
|
};
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as m } from "react/jsx-runtime";
|
|
2
2
|
import n from "prop-types";
|
|
3
3
|
import { CircularProgress as D } from "@mui/material";
|
|
4
|
-
import { useReactive as
|
|
5
|
-
import
|
|
6
|
-
import { useBrowser as
|
|
7
|
-
import
|
|
8
|
-
import { useImperativeHandle as
|
|
9
|
-
import { mergeSx as
|
|
10
|
-
import
|
|
11
|
-
import { LOGIN_PROVIDER as
|
|
12
|
-
import { useStateContext as
|
|
13
|
-
import
|
|
14
|
-
import { logger as
|
|
4
|
+
import { useReactive as E, useCreation as T, useMemoizedFn as a } from "ahooks";
|
|
5
|
+
import W from "@arcblock/bridge";
|
|
6
|
+
import { useBrowser as _ } from "@arcblock/react-hooks";
|
|
7
|
+
import N from "lodash/noop";
|
|
8
|
+
import { useImperativeHandle as q } from "react";
|
|
9
|
+
import { mergeSx as F } from "@arcblock/ux/lib/Util/style";
|
|
10
|
+
import M from "@arcblock/ux/lib/DIDConnect/provider-icon";
|
|
11
|
+
import { LOGIN_PROVIDER_ICON_SIZE as p, LOGIN_PROVIDER as j } from "@arcblock/ux/lib/Util/constant";
|
|
12
|
+
import { useStateContext as z } from "../../contexts/state.js";
|
|
13
|
+
import G from "./login-method-item.js";
|
|
14
|
+
import { logger as b } from "../../../utils.js";
|
|
15
15
|
import J from "../../hooks/auth-url.js";
|
|
16
16
|
function K({
|
|
17
|
-
ref:
|
|
17
|
+
ref: w = null,
|
|
18
18
|
tokenState: e,
|
|
19
|
-
locale:
|
|
20
|
-
tokenKey:
|
|
21
|
-
onClick:
|
|
22
|
-
disableSwitchApp:
|
|
23
|
-
...
|
|
19
|
+
locale: C,
|
|
20
|
+
tokenKey: P,
|
|
21
|
+
onClick: y = N,
|
|
22
|
+
disableSwitchApp: R = !1,
|
|
23
|
+
...f
|
|
24
24
|
}) {
|
|
25
|
-
const l =
|
|
25
|
+
const l = E({
|
|
26
26
|
loading: !1
|
|
27
|
-
}), { isWalletWebview:
|
|
27
|
+
}), { isWalletWebview: d } = z(), A = "DID Wallet", c = _(), h = new URL(window.location.href), L = J({ disableSwitchApp: R, tokenState: e }), u = T(() => {
|
|
28
28
|
if (!e.url)
|
|
29
29
|
return "";
|
|
30
|
-
|
|
31
|
-
const o = new URL(
|
|
32
|
-
c.wallet || (o.searchParams.set("callback", encodeURIComponent(
|
|
30
|
+
h.searchParams.set("tokenKey", e.token);
|
|
31
|
+
const o = new URL(L);
|
|
32
|
+
c.wallet || (o.searchParams.set("callback", encodeURIComponent(h)), o.searchParams.set("callback_delay", 1500)), o.searchParams.set("locale", C);
|
|
33
33
|
const g = new TextEncoder(), v = o.href.length;
|
|
34
34
|
let r = "", i = "";
|
|
35
35
|
try {
|
|
@@ -42,56 +42,56 @@ function K({
|
|
|
42
42
|
i = btoa(String.fromCharCode(...t));
|
|
43
43
|
}
|
|
44
44
|
if (v + 8 + r.length + 14 + i.length > 2e3)
|
|
45
|
-
throw
|
|
45
|
+
throw b.warn("URL too long, drop appInfo & memberAppInfo", { appInfo: r, memberAppInfo: i }), new Error("URL too long");
|
|
46
46
|
i ? r && (o.searchParams.set("appInfo", r), o.searchParams.set("memberAppInfo", i)) : r && o.searchParams.set("appInfo", r);
|
|
47
47
|
} catch (t) {
|
|
48
|
-
|
|
48
|
+
b.warn("Failed to convert appInfo & memberAppInfo", t);
|
|
49
49
|
}
|
|
50
50
|
return o.href.replace(/^https?:\/\//, "abt://");
|
|
51
|
-
}, [
|
|
51
|
+
}, [P, e.token, e.appInfo, e.memberAppInfo, e.url]), x = a(() => {
|
|
52
52
|
l.loading = !0, setTimeout(() => {
|
|
53
|
-
|
|
53
|
+
W.call("authAction", { action: "auth", deepLink: u });
|
|
54
54
|
}, 600), setTimeout(() => {
|
|
55
55
|
l.loading = !1;
|
|
56
56
|
}, 2e3);
|
|
57
|
-
}),
|
|
57
|
+
}), O = a(() => {
|
|
58
58
|
e.checking = !0, e.status = "scanned";
|
|
59
59
|
}), s = {};
|
|
60
|
-
!
|
|
60
|
+
!d && c.mobile.any && (s.component = "a", s.href = u), e.url || (s.sx = {
|
|
61
61
|
cursor: "not-allowed"
|
|
62
62
|
});
|
|
63
|
-
const
|
|
64
|
-
e.url && (
|
|
63
|
+
const I = a((o) => {
|
|
64
|
+
e.url && (d ? x() : c.mobile.any ? O() : o());
|
|
65
65
|
}), U = a(() => {
|
|
66
|
-
|
|
66
|
+
I(y);
|
|
67
67
|
});
|
|
68
|
-
return
|
|
69
|
-
connect:
|
|
70
|
-
})), /* @__PURE__ */
|
|
71
|
-
|
|
68
|
+
return q(w, () => ({
|
|
69
|
+
connect: I
|
|
70
|
+
})), /* @__PURE__ */ m(
|
|
71
|
+
G,
|
|
72
72
|
{
|
|
73
|
-
...
|
|
73
|
+
...f,
|
|
74
74
|
...s,
|
|
75
|
-
sx:
|
|
76
|
-
title:
|
|
77
|
-
icon: l.loading || !e.url ? /* @__PURE__ */
|
|
75
|
+
sx: F(f?.sx, s?.sx),
|
|
76
|
+
title: A,
|
|
77
|
+
icon: l.loading || !e.url ? /* @__PURE__ */ m(
|
|
78
78
|
D,
|
|
79
79
|
{
|
|
80
80
|
color: "primary",
|
|
81
|
-
size:
|
|
81
|
+
size: p,
|
|
82
82
|
sx: {
|
|
83
83
|
"& svg": {
|
|
84
84
|
transform: "scale(0.75)"
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
) : /* @__PURE__ */
|
|
89
|
-
|
|
88
|
+
) : /* @__PURE__ */ m(
|
|
89
|
+
M,
|
|
90
90
|
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
provider: j.DID_WALLET,
|
|
92
|
+
sx: {
|
|
93
|
+
width: p,
|
|
94
|
+
height: p,
|
|
95
95
|
transform: "scale(0.9)"
|
|
96
96
|
}
|
|
97
97
|
}
|