@arcblock/did-connect-react 3.3.4 → 3.3.6
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/back-button.js +13 -12
- package/lib/Connect/components/login-item/connect-provider-list.js +187 -158
- package/lib/Connect/components/login-item/mobile-login-item.js +42 -40
- package/lib/Connect/components/login-item/wallet-login-options.js +109 -0
- package/lib/Connect/components/login-item/web-login-item.js +64 -59
- package/lib/Connect/contexts/state.js +66 -63
- package/lib/Connect/index.js +286 -264
- package/lib/package.json.js +1 -1
- package/package.json +5 -5
- package/src/Connect/components/back-button.jsx +3 -2
- package/src/Connect/components/login-item/connect-provider-list.jsx +133 -97
- package/src/Connect/components/login-item/mobile-login-item.jsx +3 -1
- package/src/Connect/components/login-item/wallet-login-options.jsx +116 -0
- package/src/Connect/components/login-item/web-login-item.jsx +10 -2
- package/src/Connect/contexts/state.jsx +5 -0
- package/src/Connect/index.jsx +77 -41
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import s from "prop-types";
|
|
3
3
|
import o from "../assets/locale.js";
|
|
4
|
-
import { useStateContext as
|
|
5
|
-
import
|
|
6
|
-
function
|
|
7
|
-
const { locale:
|
|
8
|
-
return /* @__PURE__ */
|
|
9
|
-
|
|
4
|
+
import { useStateContext as c } from "../contexts/state.js";
|
|
5
|
+
import a from "./action-button.js";
|
|
6
|
+
function p({ onClick: t, ...r }) {
|
|
7
|
+
const { locale: n } = c(), e = o[n] || o.en;
|
|
8
|
+
return /* @__PURE__ */ i(
|
|
9
|
+
a,
|
|
10
10
|
{
|
|
11
11
|
onClick: t,
|
|
12
12
|
sx: {
|
|
13
13
|
color: "text.secondary"
|
|
14
14
|
},
|
|
15
|
-
|
|
15
|
+
...r,
|
|
16
|
+
children: e.back
|
|
16
17
|
}
|
|
17
18
|
);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
onClick:
|
|
20
|
+
p.propTypes = {
|
|
21
|
+
onClick: s.func.isRequired
|
|
21
22
|
};
|
|
22
23
|
export {
|
|
23
|
-
|
|
24
|
+
p as default
|
|
24
25
|
};
|
|
@@ -1,157 +1,170 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { Box as
|
|
4
|
-
import { LOGIN_PROVIDER as r, LOGIN_PROVIDER_ICON_SIZE as
|
|
5
|
-
import {
|
|
1
|
+
import { jsx as l, jsxs as ie } from "react/jsx-runtime";
|
|
2
|
+
import o from "prop-types";
|
|
3
|
+
import { Box as h } from "@mui/material";
|
|
4
|
+
import { LOGIN_PROVIDER as r, LOGIN_PROVIDER_ICON_SIZE as g, LOGIN_PROVIDER_NAME as le } from "@arcblock/ux/lib/Util/constant";
|
|
5
|
+
import { getWebWalletUrl as se } from "@arcblock/ux/lib/Util/wallet";
|
|
6
6
|
import u from "lodash/noop";
|
|
7
|
-
import { useMemoizedFn as
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import { useRef as
|
|
11
|
-
import { mergeSx as
|
|
12
|
-
import
|
|
13
|
-
import { GA_LAST_LOGIN_METHOD as
|
|
14
|
-
import { translate as
|
|
15
|
-
import
|
|
16
|
-
import { useBrowser as
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import Ae from "
|
|
24
|
-
import
|
|
7
|
+
import { useMemoizedFn as c } from "ahooks";
|
|
8
|
+
import E from "js-cookie";
|
|
9
|
+
import { getCookieOptions as ae } from "@arcblock/ux/lib/Util";
|
|
10
|
+
import { useRef as b, useEffect as ce } from "react";
|
|
11
|
+
import { mergeSx as me } from "@arcblock/ux/lib/Util/style";
|
|
12
|
+
import de from "@arcblock/ux/lib/DIDConnect/provider-icon";
|
|
13
|
+
import { GA_LAST_LOGIN_METHOD as p } from "@arcblock/ux/lib/withTracker/constant";
|
|
14
|
+
import { translate as pe } from "@arcblock/ux/lib/Locale/util";
|
|
15
|
+
import he from "@arcblock/ux/lib/Empty";
|
|
16
|
+
import { useBrowser as ge } from "@arcblock/react-hooks";
|
|
17
|
+
import ue from "./mobile-login-item.js";
|
|
18
|
+
import fe from "./web-login-item.js";
|
|
19
|
+
import ye from "./login-method-item.js";
|
|
20
|
+
import Le from "./wallet-login-options.js";
|
|
21
|
+
import { useOAuth as Ie } from "../../../OAuth/context.js";
|
|
22
|
+
import { useStateContext as Ce } from "../../contexts/state.js";
|
|
23
|
+
import { getAppId as xe, logger as Ae, getApiErrorMessage as Ee } from "../../../utils.js";
|
|
24
|
+
import be from "./passkey-login-item.js";
|
|
25
|
+
import { usePasskey as Me } from "../../../Passkey/context.js";
|
|
25
26
|
import "../../../Passkey/actions.js";
|
|
26
|
-
import
|
|
27
|
+
import ve from "../../plugins/email/index.js";
|
|
27
28
|
import Pe from "../../assets/locale.js";
|
|
28
|
-
function
|
|
29
|
-
onSuccess:
|
|
30
|
-
onError:
|
|
29
|
+
function _e({
|
|
30
|
+
onSuccess: M = u,
|
|
31
|
+
onError: v = u,
|
|
31
32
|
size: m = "small",
|
|
32
33
|
tokenState: n,
|
|
33
|
-
webWalletUrl:
|
|
34
|
-
tokenKey:
|
|
35
|
-
passkeyBehavior:
|
|
34
|
+
webWalletUrl: P = se(),
|
|
35
|
+
tokenKey: _,
|
|
36
|
+
passkeyBehavior: w = "none",
|
|
36
37
|
onReset: f = u,
|
|
37
38
|
providerList: y = [],
|
|
38
|
-
slotProps:
|
|
39
|
-
disableSwitchApp:
|
|
39
|
+
slotProps: V = {},
|
|
40
|
+
disableSwitchApp: L = !1,
|
|
40
41
|
forceUpdate: K = u,
|
|
41
|
-
magicToken:
|
|
42
|
-
baseUrl:
|
|
43
|
-
customItems:
|
|
42
|
+
magicToken: O = void 0,
|
|
43
|
+
baseUrl: Y = "/",
|
|
44
|
+
customItems: H = [],
|
|
45
|
+
qrcode: Z = null
|
|
44
46
|
}) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
+
const I = b(null), C = b(null), R = b(null), x = ge(), { loginOAuth: $, logoutOAuth: J, t: Q, oauthState: s } = Ie(), { passkeyState: T } = Me(), {
|
|
48
|
+
extraParams: k,
|
|
49
|
+
locale: W,
|
|
50
|
+
connectState: i,
|
|
51
|
+
plugins: j,
|
|
52
|
+
setPlugins: X,
|
|
53
|
+
setSelectedPlugin: z,
|
|
54
|
+
getPlugin: N,
|
|
55
|
+
showWalletOptions: A,
|
|
56
|
+
setShowWalletOptions: D
|
|
57
|
+
} = Ce(), ee = c((e, t = {}) => pe(Pe, e, W, "en", t)), F = c(async (e) => {
|
|
58
|
+
localStorage.setItem(p, e.provider), n.reset(), s.reset({
|
|
47
59
|
status: "scanned"
|
|
48
|
-
}),
|
|
49
|
-
const
|
|
60
|
+
}), T.reset(), i.chooseMethod = e.provider;
|
|
61
|
+
const t = k?.sourceAppPid;
|
|
50
62
|
try {
|
|
51
|
-
|
|
52
|
-
const
|
|
63
|
+
s.loading = !0, s.status = "scanned";
|
|
64
|
+
const a = await $(e, {
|
|
53
65
|
action: n.action,
|
|
54
|
-
...
|
|
55
|
-
}),
|
|
56
|
-
|
|
66
|
+
...k
|
|
67
|
+
}), d = ae({ returnDomain: !1 });
|
|
68
|
+
E.remove("connected_did", d), E.remove("connected_pk", d), E.remove("connected_wallet_os", d), a?.sessionToken && (await M(
|
|
57
69
|
{
|
|
58
|
-
...
|
|
70
|
+
...a,
|
|
59
71
|
encrypted: !1
|
|
60
72
|
},
|
|
61
|
-
(
|
|
73
|
+
(re) => re,
|
|
62
74
|
{
|
|
63
|
-
sourceAppPid:
|
|
64
|
-
connected_app:
|
|
75
|
+
sourceAppPid: t,
|
|
76
|
+
connected_app: xe(n.appInfo, n.memberAppInfo)
|
|
65
77
|
}
|
|
66
|
-
),
|
|
67
|
-
} catch (
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
78
|
+
), s.loading = !1, s.status = "succeed");
|
|
79
|
+
} catch (a) {
|
|
80
|
+
Ae.error(`Failed login OAuth: ${e.provider}`, a);
|
|
81
|
+
const d = Ee(a, Q("loginOAuthFailed"));
|
|
82
|
+
s.loading = !1, s.error = d, s.status = "error", await J({ provider: e.provider }), v(new Error(d));
|
|
71
83
|
}
|
|
72
|
-
}),
|
|
84
|
+
}), S = c(async () => {
|
|
73
85
|
n.reset(), await f(), n.status = "created", i.chooseMethod = "wallet";
|
|
74
|
-
}),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
}), B = c(async () => {
|
|
87
|
+
localStorage.setItem(p, "wallet"), n.reset(), await f(), n.status = "created", i.chooseMethod = "wallet";
|
|
88
|
+
const e = I.current?.connect;
|
|
89
|
+
i.retryConnect = () => {
|
|
90
|
+
e(S);
|
|
91
|
+
};
|
|
92
|
+
}), oe = c(() => {
|
|
93
|
+
localStorage.setItem(p, "wallet"), n.status = "scanned", i.chooseMethod = "wallet-web";
|
|
94
|
+
const e = C.current.connect;
|
|
95
|
+
i.retryConnect = async () => {
|
|
96
|
+
await f(), n.error = "", n.status = "scanned", e();
|
|
97
|
+
};
|
|
98
|
+
}), ne = c(() => {
|
|
99
|
+
D(!1);
|
|
100
|
+
}), G = y.some((e) => e.provider === r.EMAIL), U = ve({ baseUrl: Y }), te = c(() => {
|
|
101
|
+
if (O && y.some((e) => e.name === r.EMAIL) && j.some((e) => e.name === r.EMAIL)) {
|
|
102
|
+
const e = N(r.EMAIL);
|
|
103
|
+
e.state.status === "idle" && (localStorage.setItem(p, "email"), e.state.reset(), e.state.magicToken = O, i.chooseMethod = r.EMAIL, z(e), K());
|
|
78
104
|
}
|
|
79
105
|
});
|
|
80
|
-
|
|
106
|
+
ce(() => {
|
|
81
107
|
const e = [];
|
|
82
|
-
if (
|
|
83
|
-
const
|
|
84
|
-
|
|
108
|
+
if (G) {
|
|
109
|
+
const t = N(r.EMAIL);
|
|
110
|
+
t && t.baseUrl === U.baseUrl ? e.push(t) : e.push(U);
|
|
85
111
|
}
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
X(e), i.retryConnect = S, setTimeout(() => {
|
|
113
|
+
te();
|
|
88
114
|
}, 100);
|
|
89
|
-
}, [
|
|
90
|
-
const
|
|
91
|
-
if (e.provider === r.WALLET)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
sx: [m === "small" ? { p: 1 } : { p: 2 }],
|
|
120
|
-
disableSwitchApp: P,
|
|
121
|
-
onClick: () => {
|
|
122
|
-
localStorage.setItem(d, "wallet"), n.status = "scanned", i.chooseMethod = "wallet-web";
|
|
123
|
-
const o = M.current.connect;
|
|
124
|
-
i.retryConnect = async () => {
|
|
125
|
-
await f(), n.error = "", n.status = "scanned", o();
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
r.WALLET
|
|
130
|
-
);
|
|
131
|
-
}
|
|
115
|
+
}, [G]);
|
|
116
|
+
const q = y.map((e) => {
|
|
117
|
+
if (e.provider === r.WALLET)
|
|
118
|
+
return x.mobile.any && !A ? /* @__PURE__ */ l(
|
|
119
|
+
ue,
|
|
120
|
+
{
|
|
121
|
+
ref: I,
|
|
122
|
+
tokenState: n,
|
|
123
|
+
sx: [m === "small" ? { p: 1 } : { p: 2 }],
|
|
124
|
+
locale: W,
|
|
125
|
+
tokenKey: _,
|
|
126
|
+
disableSwitchApp: L,
|
|
127
|
+
onClick: B
|
|
128
|
+
},
|
|
129
|
+
r.WALLET
|
|
130
|
+
) : /* @__PURE__ */ l(
|
|
131
|
+
fe,
|
|
132
|
+
{
|
|
133
|
+
ref: C,
|
|
134
|
+
tokenState: n,
|
|
135
|
+
webWalletUrl: P,
|
|
136
|
+
sx: [m === "small" ? { p: 1 } : { p: 2 }],
|
|
137
|
+
disableSwitchApp: L,
|
|
138
|
+
autoConnect: !1,
|
|
139
|
+
onClick: () => {
|
|
140
|
+
D(!0);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
r.WALLET
|
|
144
|
+
);
|
|
132
145
|
if (e.provider === r.PASSKEY)
|
|
133
|
-
return
|
|
134
|
-
|
|
146
|
+
return w === "none" ? null : /* @__PURE__ */ l(
|
|
147
|
+
be,
|
|
135
148
|
{
|
|
136
|
-
ref:
|
|
137
|
-
onSuccess:
|
|
138
|
-
onError:
|
|
149
|
+
ref: R,
|
|
150
|
+
onSuccess: M,
|
|
151
|
+
onError: v,
|
|
139
152
|
tokenState: n,
|
|
140
|
-
behavior:
|
|
153
|
+
behavior: w,
|
|
141
154
|
sx: [m === "small" ? { p: 1 } : { p: 2 }],
|
|
142
155
|
onClick: () => {
|
|
143
|
-
localStorage.setItem(
|
|
144
|
-
const
|
|
156
|
+
localStorage.setItem(p, "passkey");
|
|
157
|
+
const t = R.current.connect;
|
|
145
158
|
i.chooseMethod = "passkey", i.retryConnect = () => {
|
|
146
|
-
|
|
159
|
+
T.verifying = !0, i.chooseMethod = "passkey", t();
|
|
147
160
|
};
|
|
148
161
|
},
|
|
149
162
|
slotProps: {
|
|
150
163
|
icon: {
|
|
151
164
|
sx: {
|
|
152
|
-
fontSize:
|
|
165
|
+
fontSize: g,
|
|
153
166
|
"& svg": {
|
|
154
|
-
fontSize:
|
|
167
|
+
fontSize: g,
|
|
155
168
|
width: "1em",
|
|
156
169
|
height: "1em"
|
|
157
170
|
}
|
|
@@ -162,32 +175,32 @@ function ve({
|
|
|
162
175
|
r.PASSKEY
|
|
163
176
|
);
|
|
164
177
|
if (e.provider === r.EMAIL) {
|
|
165
|
-
const
|
|
166
|
-
return
|
|
167
|
-
key:
|
|
178
|
+
const t = j.find((a) => a.name === r.EMAIL);
|
|
179
|
+
return t ? t?.renderListItem({
|
|
180
|
+
key: t.name,
|
|
168
181
|
sx: [m === "small" ? { p: 1 } : { p: 2 }]
|
|
169
182
|
// forceUpdate,
|
|
170
183
|
}) : null;
|
|
171
184
|
}
|
|
172
|
-
return e.type === "oauth" ? /* @__PURE__ */
|
|
173
|
-
|
|
185
|
+
return e.type === "oauth" ? /* @__PURE__ */ l(
|
|
186
|
+
ye,
|
|
174
187
|
{
|
|
175
|
-
title:
|
|
176
|
-
icon: /* @__PURE__ */
|
|
177
|
-
|
|
188
|
+
title: le[e.provider],
|
|
189
|
+
icon: /* @__PURE__ */ l(
|
|
190
|
+
de,
|
|
178
191
|
{
|
|
179
192
|
provider: e.provider,
|
|
180
193
|
sx: {
|
|
181
194
|
transform: "scale(0.95)",
|
|
182
|
-
width:
|
|
183
|
-
height:
|
|
195
|
+
width: g,
|
|
196
|
+
height: g,
|
|
184
197
|
color: "text.primary"
|
|
185
198
|
}
|
|
186
199
|
}
|
|
187
200
|
),
|
|
188
201
|
onClick: () => {
|
|
189
|
-
|
|
190
|
-
|
|
202
|
+
F(e), i.retryConnect = () => {
|
|
203
|
+
F(e);
|
|
191
204
|
};
|
|
192
205
|
},
|
|
193
206
|
sx: [m === "small" ? { p: 1.2 } : { p: 2 }]
|
|
@@ -195,27 +208,42 @@ function ve({
|
|
|
195
208
|
e.provider
|
|
196
209
|
) : null;
|
|
197
210
|
}).filter(Boolean);
|
|
198
|
-
return /* @__PURE__ */
|
|
199
|
-
|
|
211
|
+
return /* @__PURE__ */ l(h, { className: "did-connect__choose", sx: me({ flex: 1 }, V?.root?.sx), children: /* @__PURE__ */ l(
|
|
212
|
+
h,
|
|
200
213
|
{
|
|
201
214
|
sx: {
|
|
202
215
|
display: "flex",
|
|
203
216
|
flexDirection: "column",
|
|
204
217
|
gap: 2
|
|
205
218
|
},
|
|
206
|
-
children: /* @__PURE__ */
|
|
207
|
-
|
|
219
|
+
children: /* @__PURE__ */ ie(
|
|
220
|
+
h,
|
|
208
221
|
{
|
|
209
222
|
sx: [
|
|
210
223
|
{
|
|
211
224
|
display: "flex",
|
|
212
225
|
flexDirection: "column",
|
|
213
|
-
gap: 1.5
|
|
226
|
+
...A && !x.mobile.any ? { alignItems: "center", gap: 0 } : { gap: 1.5 }
|
|
214
227
|
}
|
|
215
228
|
],
|
|
216
229
|
children: [
|
|
217
|
-
/* @__PURE__ */
|
|
218
|
-
|
|
230
|
+
A && !x.mobile.any ? /* @__PURE__ */ l(
|
|
231
|
+
Le,
|
|
232
|
+
{
|
|
233
|
+
qrcode: Z,
|
|
234
|
+
tokenState: n,
|
|
235
|
+
webWalletUrl: P,
|
|
236
|
+
size: m,
|
|
237
|
+
disableSwitchApp: L,
|
|
238
|
+
tokenKey: _,
|
|
239
|
+
walletLoginRef: I,
|
|
240
|
+
webLoginRef: C,
|
|
241
|
+
onMobileLoginClick: B,
|
|
242
|
+
onWebLoginClick: oe,
|
|
243
|
+
onBack: ne
|
|
244
|
+
}
|
|
245
|
+
) : /* @__PURE__ */ l(
|
|
246
|
+
h,
|
|
219
247
|
{
|
|
220
248
|
sx: {
|
|
221
249
|
display: "grid",
|
|
@@ -260,8 +288,8 @@ function ve({
|
|
|
260
288
|
}
|
|
261
289
|
}
|
|
262
290
|
},
|
|
263
|
-
children:
|
|
264
|
-
|
|
291
|
+
children: q.length > 0 ? q : /* @__PURE__ */ l(
|
|
292
|
+
he,
|
|
265
293
|
{
|
|
266
294
|
className: "arc-login-item",
|
|
267
295
|
sx: {
|
|
@@ -269,35 +297,36 @@ function ve({
|
|
|
269
297
|
textAlign: "center"
|
|
270
298
|
}
|
|
271
299
|
},
|
|
272
|
-
children:
|
|
300
|
+
children: ee("noAuthenticationProvider")
|
|
273
301
|
}
|
|
274
302
|
)
|
|
275
303
|
}
|
|
276
304
|
),
|
|
277
|
-
|
|
305
|
+
H.map((e) => e || null)
|
|
278
306
|
]
|
|
279
307
|
}
|
|
280
308
|
)
|
|
281
309
|
}
|
|
282
310
|
) });
|
|
283
311
|
}
|
|
284
|
-
|
|
285
|
-
onSuccess:
|
|
286
|
-
onError:
|
|
287
|
-
size:
|
|
288
|
-
tokenState:
|
|
289
|
-
webWalletUrl:
|
|
290
|
-
tokenKey:
|
|
291
|
-
passkeyBehavior:
|
|
292
|
-
onReset:
|
|
293
|
-
providerList:
|
|
294
|
-
slotProps:
|
|
295
|
-
disableSwitchApp:
|
|
296
|
-
forceUpdate:
|
|
297
|
-
magicToken:
|
|
298
|
-
baseUrl:
|
|
299
|
-
customItems:
|
|
312
|
+
_e.propTypes = {
|
|
313
|
+
onSuccess: o.func,
|
|
314
|
+
onError: o.func,
|
|
315
|
+
size: o.oneOf(["small", "normal", "large"]),
|
|
316
|
+
tokenState: o.object.isRequired,
|
|
317
|
+
webWalletUrl: o.string,
|
|
318
|
+
tokenKey: o.string.isRequired,
|
|
319
|
+
passkeyBehavior: o.oneOf(["none", "both", "only-existing", "only-new"]),
|
|
320
|
+
onReset: o.func,
|
|
321
|
+
providerList: o.array,
|
|
322
|
+
slotProps: o.object,
|
|
323
|
+
disableSwitchApp: o.bool,
|
|
324
|
+
forceUpdate: o.func,
|
|
325
|
+
magicToken: o.string,
|
|
326
|
+
baseUrl: o.string,
|
|
327
|
+
customItems: o.arrayOf(o.node),
|
|
328
|
+
qrcode: o.node
|
|
300
329
|
};
|
|
301
330
|
export {
|
|
302
|
-
|
|
331
|
+
_e as default
|
|
303
332
|
};
|
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
2
|
import n from "prop-types";
|
|
3
|
-
import { CircularProgress as
|
|
4
|
-
import { useReactive as E, useCreation as
|
|
5
|
-
import
|
|
6
|
-
import { useBrowser as
|
|
7
|
-
import
|
|
8
|
-
import { useImperativeHandle as
|
|
9
|
-
import { mergeSx as
|
|
10
|
-
import
|
|
11
|
-
import { LOGIN_PROVIDER_ICON_SIZE as p, LOGIN_PROVIDER as
|
|
12
|
-
import { useStateContext as
|
|
13
|
-
import
|
|
3
|
+
import { CircularProgress as T } from "@mui/material";
|
|
4
|
+
import { useReactive as E, useCreation as W, useMemoizedFn as a } from "ahooks";
|
|
5
|
+
import _ from "@arcblock/bridge";
|
|
6
|
+
import { useBrowser as N } from "@arcblock/react-hooks";
|
|
7
|
+
import q from "lodash/noop";
|
|
8
|
+
import { useImperativeHandle as F } from "react";
|
|
9
|
+
import { mergeSx as M } from "@arcblock/ux/lib/Util/style";
|
|
10
|
+
import j from "@arcblock/ux/lib/DIDConnect/provider-icon";
|
|
11
|
+
import { LOGIN_PROVIDER_ICON_SIZE as p, LOGIN_PROVIDER as z } from "@arcblock/ux/lib/Util/constant";
|
|
12
|
+
import { useStateContext as G } from "../../contexts/state.js";
|
|
13
|
+
import J from "./login-method-item.js";
|
|
14
14
|
import { logger as b } from "../../../utils.js";
|
|
15
|
-
import
|
|
16
|
-
function
|
|
17
|
-
|
|
15
|
+
import K from "../../hooks/auth-url.js";
|
|
16
|
+
function V({
|
|
17
|
+
isTablet: w = !1,
|
|
18
|
+
ref: C = null,
|
|
18
19
|
tokenState: e,
|
|
19
|
-
locale:
|
|
20
|
-
tokenKey:
|
|
21
|
-
onClick:
|
|
22
|
-
disableSwitchApp:
|
|
20
|
+
locale: P,
|
|
21
|
+
tokenKey: y,
|
|
22
|
+
onClick: R = q,
|
|
23
|
+
disableSwitchApp: A = !1,
|
|
23
24
|
...f
|
|
24
25
|
}) {
|
|
25
26
|
const l = E({
|
|
26
27
|
loading: !1
|
|
27
|
-
}), { isWalletWebview: d } =
|
|
28
|
+
}), { isWalletWebview: d } = G(), L = "DID Wallet", c = N(), h = new URL(window.location.href), x = K({ disableSwitchApp: A, tokenState: e }), u = W(() => {
|
|
28
29
|
if (!e.url)
|
|
29
30
|
return "";
|
|
30
31
|
h.searchParams.set("tokenKey", e.token);
|
|
31
|
-
const o = new URL(
|
|
32
|
-
c.wallet || (o.searchParams.set("callback", encodeURIComponent(h)), o.searchParams.set("callback_delay", 1500)), o.searchParams.set("locale",
|
|
33
|
-
const g = new TextEncoder(),
|
|
32
|
+
const o = new URL(x);
|
|
33
|
+
c.wallet || (o.searchParams.set("callback", encodeURIComponent(h)), o.searchParams.set("callback_delay", 1500)), o.searchParams.set("locale", P);
|
|
34
|
+
const g = new TextEncoder(), D = o.href.length;
|
|
34
35
|
let r = "", i = "";
|
|
35
36
|
try {
|
|
36
37
|
if (e.appInfo) {
|
|
@@ -41,41 +42,41 @@ function K({
|
|
|
41
42
|
const t = g.encode(JSON.stringify(e.memberAppInfo));
|
|
42
43
|
i = btoa(String.fromCharCode(...t));
|
|
43
44
|
}
|
|
44
|
-
if (
|
|
45
|
+
if (D + 8 + r.length + 14 + i.length > 2e3)
|
|
45
46
|
throw b.warn("URL too long, drop appInfo & memberAppInfo", { appInfo: r, memberAppInfo: i }), new Error("URL too long");
|
|
46
47
|
i ? r && (o.searchParams.set("appInfo", r), o.searchParams.set("memberAppInfo", i)) : r && o.searchParams.set("appInfo", r);
|
|
47
48
|
} catch (t) {
|
|
48
49
|
b.warn("Failed to convert appInfo & memberAppInfo", t);
|
|
49
50
|
}
|
|
50
51
|
return o.href.replace(/^https?:\/\//, "abt://");
|
|
51
|
-
}, [
|
|
52
|
+
}, [y, e.token, e.appInfo, e.memberAppInfo, e.url]), O = a(() => {
|
|
52
53
|
l.loading = !0, setTimeout(() => {
|
|
53
|
-
|
|
54
|
+
_.call("authAction", { action: "auth", deepLink: u });
|
|
54
55
|
}, 600), setTimeout(() => {
|
|
55
56
|
l.loading = !1;
|
|
56
57
|
}, 2e3);
|
|
57
|
-
}),
|
|
58
|
+
}), U = a(() => {
|
|
58
59
|
e.checking = !0, e.status = "scanned";
|
|
59
60
|
}), s = {};
|
|
60
61
|
!d && c.mobile.any && (s.component = "a", s.href = u), e.url || (s.sx = {
|
|
61
62
|
cursor: "not-allowed"
|
|
62
63
|
});
|
|
63
64
|
const I = a((o) => {
|
|
64
|
-
e.url && (d ?
|
|
65
|
-
}),
|
|
66
|
-
I(
|
|
65
|
+
e.url && (d ? O() : c.mobile.any || w ? U() : o());
|
|
66
|
+
}), v = a(() => {
|
|
67
|
+
I(R);
|
|
67
68
|
});
|
|
68
|
-
return
|
|
69
|
+
return F(C, () => ({
|
|
69
70
|
connect: I
|
|
70
71
|
})), /* @__PURE__ */ m(
|
|
71
|
-
|
|
72
|
+
J,
|
|
72
73
|
{
|
|
73
74
|
...f,
|
|
74
75
|
...s,
|
|
75
|
-
sx:
|
|
76
|
-
title:
|
|
76
|
+
sx: M(f?.sx, s?.sx),
|
|
77
|
+
title: L,
|
|
77
78
|
icon: l.loading || !e.url ? /* @__PURE__ */ m(
|
|
78
|
-
|
|
79
|
+
T,
|
|
79
80
|
{
|
|
80
81
|
color: "primary",
|
|
81
82
|
size: p,
|
|
@@ -86,9 +87,9 @@ function K({
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
) : /* @__PURE__ */ m(
|
|
89
|
-
|
|
90
|
+
j,
|
|
90
91
|
{
|
|
91
|
-
provider:
|
|
92
|
+
provider: z.DID_WALLET,
|
|
92
93
|
sx: {
|
|
93
94
|
width: p,
|
|
94
95
|
height: p,
|
|
@@ -97,18 +98,19 @@ function K({
|
|
|
97
98
|
}
|
|
98
99
|
),
|
|
99
100
|
iconScale: 1,
|
|
100
|
-
onClick:
|
|
101
|
+
onClick: v
|
|
101
102
|
}
|
|
102
103
|
);
|
|
103
104
|
}
|
|
104
|
-
|
|
105
|
+
V.propTypes = {
|
|
105
106
|
tokenState: n.object.isRequired,
|
|
106
107
|
tokenKey: n.string.isRequired,
|
|
107
108
|
locale: n.string.isRequired,
|
|
108
109
|
onClick: n.func,
|
|
109
110
|
disableSwitchApp: n.bool,
|
|
110
|
-
ref: n.any
|
|
111
|
+
ref: n.any,
|
|
112
|
+
isTablet: n.bool
|
|
111
113
|
};
|
|
112
114
|
export {
|
|
113
|
-
|
|
115
|
+
V as default
|
|
114
116
|
};
|