@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,57 +1,64 @@
|
|
|
1
1
|
import { jsx as O } from "react/jsx-runtime";
|
|
2
2
|
import r from "prop-types";
|
|
3
|
-
import { useState as S, use as
|
|
3
|
+
import { useState as S, use as W, useRef as D, useEffect as V, createContext as X } from "react";
|
|
4
4
|
import Y from "@arcblock/react-hooks/lib/useBrowser";
|
|
5
|
-
import { useUpdate as Z, useCreation as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { Box as
|
|
9
|
-
import { translate as
|
|
10
|
-
import { getMaster as
|
|
11
|
-
import { getDIDMotifInfo as
|
|
12
|
-
import { isEthereumDid as
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import de from "
|
|
16
|
-
|
|
5
|
+
import { useUpdate as Z, useCreation as n, useMemoizedFn as h, useLatest as $, useReactive as ee, useSize as te } from "ahooks";
|
|
6
|
+
import E from "lodash/isUndefined";
|
|
7
|
+
import oe from "lodash/noop";
|
|
8
|
+
import { Box as re } from "@mui/material";
|
|
9
|
+
import { translate as ne } from "@arcblock/ux/lib/Locale/util";
|
|
10
|
+
import { getMaster as T, getCurrentApp as se } from "@arcblock/ux/lib/Util/federated";
|
|
11
|
+
import { getDIDMotifInfo as ie } from "@arcblock/did-motif";
|
|
12
|
+
import { isEthereumDid as ce, getDIDColor as pe } from "@arcblock/ux/lib/Util";
|
|
13
|
+
import { GA_LAST_LOGIN_METHOD as ue } from "@arcblock/ux/lib/withTracker/constant";
|
|
14
|
+
import ae from "../hooks/use-apps.js";
|
|
15
|
+
import { SessionContext as de } from "../../Session/context.js";
|
|
16
|
+
import le from "../assets/locale.js";
|
|
17
|
+
const x = X({
|
|
17
18
|
isWalletWebview: !1,
|
|
18
19
|
isMobile: !1,
|
|
19
20
|
matchSmallScreen: !1,
|
|
20
21
|
blocklet: null
|
|
21
|
-
}), { Provider:
|
|
22
|
-
function
|
|
23
|
-
children:
|
|
24
|
-
blocklet:
|
|
22
|
+
}), { Provider: fe, Consumer: We } = x;
|
|
23
|
+
function me({
|
|
24
|
+
children: R,
|
|
25
|
+
blocklet: c,
|
|
25
26
|
masterBlocklet: P = void 0,
|
|
26
|
-
action:
|
|
27
|
+
action: a,
|
|
27
28
|
extraParams: t = {},
|
|
28
|
-
locale:
|
|
29
|
+
locale: d = "en",
|
|
29
30
|
testOnlyBorderColor: l = void 0,
|
|
30
|
-
...
|
|
31
|
+
...L
|
|
31
32
|
}) {
|
|
32
|
-
const w = Z(), [f,
|
|
33
|
+
const w = Z(), [f, j] = S([]), [N, q] = S(!1), [m, z] = S(""), G = n(() => new Map(f.map((e) => [e.name, e])), [f]), J = h((e) => G.get(e)), U = $(m), _ = h((e, i = {}) => ne(le, e, d, "en", i)), g = W(de), o = ee({
|
|
33
34
|
sourceAppPid: void 0,
|
|
34
35
|
status: "created",
|
|
35
36
|
autoActiveWebview: !0,
|
|
36
37
|
deeplink: void 0,
|
|
37
38
|
chooseMethod: "",
|
|
38
|
-
retryConnect:
|
|
39
|
-
}),
|
|
39
|
+
retryConnect: oe
|
|
40
|
+
}), k = D({
|
|
40
41
|
cancelCount: 0
|
|
41
|
-
}),
|
|
42
|
-
blocklet:
|
|
42
|
+
}), s = Y(), { appInfoList: b, autoGenerateSourceAppPid: A, canSwitchApp: v } = ae({
|
|
43
|
+
blocklet: c,
|
|
43
44
|
connectState: o,
|
|
44
|
-
action:
|
|
45
|
+
action: a,
|
|
45
46
|
sourceAppPid: t?.sourceAppPid,
|
|
46
47
|
enableSwitchApp: t?.forceSwitch || t?.enableSwitchApp
|
|
47
|
-
}),
|
|
48
|
+
}), B = n(() => {
|
|
49
|
+
try {
|
|
50
|
+
return localStorage.getItem(ue);
|
|
51
|
+
} catch {
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
}, []), C = D(null), M = te(C), y = n(() => (M?.width || 0) < 500, [M?.width]), p = n(() => {
|
|
48
55
|
if (v)
|
|
49
56
|
return {
|
|
50
57
|
...t,
|
|
51
|
-
sourceAppPid:
|
|
58
|
+
sourceAppPid: E(o.sourceAppPid) ? A : o.sourceAppPid
|
|
52
59
|
};
|
|
53
|
-
const e =
|
|
54
|
-
return g?.session?.user && (e ===
|
|
60
|
+
const e = T(c)?.appPid, i = T(globalThis.blocklet)?.appPid;
|
|
61
|
+
return g?.session?.user && (e === i || !e) ? E(t?.sourceAppPid) ? {
|
|
55
62
|
...t,
|
|
56
63
|
sourceAppPid: g.session.user?.sourceAppPid
|
|
57
64
|
} : t : {
|
|
@@ -62,70 +69,72 @@ function le({
|
|
|
62
69
|
v,
|
|
63
70
|
t,
|
|
64
71
|
o.sourceAppPid,
|
|
65
|
-
|
|
72
|
+
a,
|
|
66
73
|
A,
|
|
67
74
|
g?.session?.user
|
|
68
|
-
]),
|
|
75
|
+
]), F = n(() => {
|
|
69
76
|
const e = window?.navigator?.userAgent;
|
|
70
77
|
return e.indexOf("Edge") > -1 || e.indexOf("Edg") > -1 ? "edge" : e.indexOf("Chrome") > -1 ? "chrome" : "unknown";
|
|
71
78
|
}, []);
|
|
72
79
|
V(() => {
|
|
73
|
-
o.sourceAppPid =
|
|
74
|
-
}, [
|
|
80
|
+
o.sourceAppPid = p.sourceAppPid;
|
|
81
|
+
}, [p.sourceAppPid]);
|
|
75
82
|
const H = h((e) => {
|
|
76
83
|
o.status = e || "created";
|
|
77
|
-
}), u = globalThis.blocklet ?
|
|
84
|
+
}), u = globalThis.blocklet ? se(c) : globalThis.env, I = n(() => {
|
|
78
85
|
if (l)
|
|
79
86
|
return l;
|
|
80
|
-
const e = u.appPid,
|
|
81
|
-
return
|
|
82
|
-
}, [u.appId, l]), K =
|
|
83
|
-
isWalletWebview:
|
|
84
|
-
isMobile:
|
|
87
|
+
const e = u.appPid, i = ce(e), Q = i ? void 0 : ie(e);
|
|
88
|
+
return i ? pe(e) : Q.color;
|
|
89
|
+
}, [u.appId, l]), K = n(() => ({
|
|
90
|
+
isWalletWebview: s.wallet || s.arcSphere,
|
|
91
|
+
isMobile: s.mobile.any,
|
|
85
92
|
matchSmallScreen: y,
|
|
86
93
|
connectState: o,
|
|
87
|
-
staticState:
|
|
94
|
+
staticState: k,
|
|
88
95
|
reactiveState: o,
|
|
89
96
|
appInfoList: b,
|
|
90
|
-
extraParams:
|
|
91
|
-
blocklet:
|
|
97
|
+
extraParams: p,
|
|
98
|
+
blocklet: c,
|
|
92
99
|
masterBlocklet: P,
|
|
93
|
-
browserBrand:
|
|
100
|
+
browserBrand: F,
|
|
94
101
|
currentAppInfo: u,
|
|
95
102
|
currentAppColor: I,
|
|
96
|
-
t:
|
|
97
|
-
locale:
|
|
98
|
-
action:
|
|
103
|
+
t: _,
|
|
104
|
+
locale: d,
|
|
105
|
+
action: a,
|
|
99
106
|
changeStatus: H,
|
|
100
|
-
getPlugin:
|
|
101
|
-
latestActivePlugin:
|
|
107
|
+
getPlugin: J,
|
|
108
|
+
latestActivePlugin: U,
|
|
102
109
|
plugins: f,
|
|
103
|
-
setPlugins:
|
|
110
|
+
setPlugins: j,
|
|
104
111
|
selectedPlugin: m,
|
|
105
|
-
setSelectedPlugin:
|
|
112
|
+
setSelectedPlugin: z,
|
|
106
113
|
forceUpdate: w,
|
|
107
114
|
// 控制钱包登录的显示
|
|
108
|
-
showWalletOptions:
|
|
109
|
-
setShowWalletOptions:
|
|
115
|
+
showWalletOptions: N,
|
|
116
|
+
setShowWalletOptions: q,
|
|
117
|
+
// 用于记录上一次登录方式
|
|
118
|
+
lastLoginMethod: B
|
|
110
119
|
}), [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
s.wallet,
|
|
121
|
+
s.arcSphere,
|
|
122
|
+
s.mobile.any,
|
|
114
123
|
y,
|
|
115
124
|
JSON.stringify(o),
|
|
116
125
|
JSON.stringify(b),
|
|
117
|
-
JSON.stringify(
|
|
118
|
-
|
|
126
|
+
JSON.stringify(p),
|
|
127
|
+
c,
|
|
119
128
|
P,
|
|
120
|
-
|
|
129
|
+
d,
|
|
121
130
|
m,
|
|
122
131
|
w,
|
|
123
132
|
u,
|
|
124
133
|
I
|
|
125
134
|
]);
|
|
126
|
-
return /* @__PURE__ */ O(
|
|
135
|
+
return /* @__PURE__ */ O(fe, { value: K, children: /* @__PURE__ */ O(re, { ...L, ref: C, children: R }) });
|
|
127
136
|
}
|
|
128
|
-
|
|
137
|
+
me.propTypes = {
|
|
129
138
|
children: r.any.isRequired,
|
|
130
139
|
blocklet: r.object.isRequired,
|
|
131
140
|
masterBlocklet: r.object,
|
|
@@ -135,11 +144,11 @@ le.propTypes = {
|
|
|
135
144
|
testOnlyBorderColor: r.string
|
|
136
145
|
};
|
|
137
146
|
function xe() {
|
|
138
|
-
return
|
|
147
|
+
return W(x);
|
|
139
148
|
}
|
|
140
149
|
export {
|
|
141
150
|
We as StateConsumer,
|
|
142
|
-
|
|
143
|
-
|
|
151
|
+
x as StateContext,
|
|
152
|
+
me as StateProvider,
|
|
144
153
|
xe as useStateContext
|
|
145
154
|
};
|
|
@@ -1,56 +1,66 @@
|
|
|
1
|
-
import { useBrowser as
|
|
2
|
-
import { useRequest as
|
|
3
|
-
import
|
|
4
|
-
import { LOGIN_PROVIDER as
|
|
5
|
-
import { getFederatedEnabled as
|
|
6
|
-
import { useState as
|
|
7
|
-
const
|
|
1
|
+
import { useBrowser as k } from "@arcblock/react-hooks";
|
|
2
|
+
import { useRequest as y, useCreation as L } from "ahooks";
|
|
3
|
+
import n from "lodash/isNil";
|
|
4
|
+
import { LOGIN_PROVIDER as s } from "@arcblock/ux/lib/Util/constant";
|
|
5
|
+
import { getFederatedEnabled as A, getMaster as C, getBlockletData as T } from "@arcblock/ux/lib/Util/federated";
|
|
6
|
+
import { useState as I } from "react";
|
|
7
|
+
const S = async ({ sourceAppPid: a }) => {
|
|
8
8
|
const t = globalThis?.blocklet;
|
|
9
9
|
if (!t)
|
|
10
10
|
return {
|
|
11
|
-
[
|
|
11
|
+
[s.WALLET]: {
|
|
12
12
|
order: 0,
|
|
13
13
|
enabled: !0,
|
|
14
14
|
showQrcode: !0
|
|
15
15
|
},
|
|
16
|
-
[
|
|
16
|
+
[s.PASSKEY]: {
|
|
17
17
|
order: 1,
|
|
18
18
|
enabled: !0
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
const
|
|
22
|
-
return
|
|
23
|
-
},
|
|
24
|
-
const t = await
|
|
25
|
-
return Object.entries(t).map(([e,
|
|
21
|
+
const l = A(t), e = C(t);
|
|
22
|
+
return l && e?.appPid && a === e?.appPid ? (await T(e.appUrl))?.settings?.authentication || {} : t?.settings?.authentication || {};
|
|
23
|
+
}, B = async ({ sourceAppPid: a } = {}) => {
|
|
24
|
+
const t = await S({ sourceAppPid: a });
|
|
25
|
+
return Object.entries(t).map(([e, o]) => ({ ...o, provider: e })).filter((e) => e.enabled).sort((e, o) => !n(e?.order) && !n(o?.order) ? e.order - o.order : n(e?.order) ? 1 : -1);
|
|
26
26
|
};
|
|
27
|
-
function
|
|
28
|
-
allowWallet:
|
|
27
|
+
function Y({
|
|
28
|
+
allowWallet: a = !0,
|
|
29
29
|
passkeyBehavior: t = "none",
|
|
30
|
-
action:
|
|
30
|
+
action: l,
|
|
31
31
|
sourceAppPid: e,
|
|
32
|
-
mode:
|
|
33
|
-
blocklet:
|
|
34
|
-
isSmallView:
|
|
32
|
+
mode: o = "dialog",
|
|
33
|
+
blocklet: b = globalThis.blocklet,
|
|
34
|
+
isSmallView: p = !1,
|
|
35
|
+
lastLoginMethod: u = ""
|
|
35
36
|
}) {
|
|
36
|
-
const [
|
|
37
|
+
const [P, g] = I(!1), w = ["login", "invite", "connect-to-did-space", "connect-to-did-domain", "destroy-self"], c = k(), { data: h = [] } = y(
|
|
37
38
|
async () => {
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
return
|
|
39
|
+
g(!0);
|
|
40
|
+
const d = await B({ sourceAppPid: e });
|
|
41
|
+
return g(!1), d;
|
|
41
42
|
},
|
|
42
43
|
{ refreshDeps: [e] }
|
|
43
|
-
),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
), f = L(() => h.filter((r) => r.name === s.WALLET ? a : r.name === s.PASSKEY ? t !== "none" && !c.wallet && !c.arcSphere : r.name === s.EMAIL ? b?.settings?.notification?.email?.enabled ?? !1 : !(r.type === "oauth" && !w.includes(l))).sort((r, i) => {
|
|
45
|
+
if (u) {
|
|
46
|
+
const m = r.provider === u, v = i.provider === u;
|
|
47
|
+
if (m && !v)
|
|
48
|
+
return -1;
|
|
49
|
+
if (!m && v)
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
return !n(r?.order) && !n(i?.order) ? r.order - i.order : n(r?.order) ? n(i?.order) ? 0 : 1 : -1;
|
|
53
|
+
}), [h, u]), E = L(() => {
|
|
54
|
+
const d = o === "drawer" || p && c.mobile.any;
|
|
55
|
+
return globalThis?.blocklet ? !!(f.find((i) => i.provider === s.WALLET)?.showQrcode !== !0 || d) : !!d;
|
|
56
|
+
}, [o, p, f]);
|
|
47
57
|
return {
|
|
48
|
-
hideChooseList:
|
|
49
|
-
hideQRCode:
|
|
50
|
-
providerList:
|
|
51
|
-
loadingProviderList:
|
|
58
|
+
hideChooseList: L(() => !1),
|
|
59
|
+
hideQRCode: E,
|
|
60
|
+
providerList: f,
|
|
61
|
+
loadingProviderList: P
|
|
52
62
|
};
|
|
53
63
|
}
|
|
54
64
|
export {
|
|
55
|
-
|
|
65
|
+
Y as default
|
|
56
66
|
};
|