@arcblock/did-connect-react 3.5.1 → 4.0.0-beta.1
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/dist/ConnectContext.d.ts +13 -0
- package/dist/ConnectContext.d.ts.map +1 -0
- package/dist/ConnectContext.js +14 -0
- package/dist/ConnectContext.js.map +1 -0
- package/dist/ConnectProvider.d.ts +11 -0
- package/dist/ConnectProvider.d.ts.map +1 -0
- package/dist/ConnectProvider.js +23 -0
- package/dist/ConnectProvider.js.map +1 -0
- package/dist/compat/SessionProvider.d.ts +22 -0
- package/dist/compat/SessionProvider.d.ts.map +1 -0
- package/dist/compat/SessionProvider.js +17 -0
- package/dist/compat/SessionProvider.js.map +1 -0
- package/dist/compat/index.d.ts +4 -0
- package/dist/compat/index.d.ts.map +1 -0
- package/dist/compat/index.js +3 -0
- package/dist/compat/index.js.map +1 -0
- package/dist/compat/useSessionContext.d.ts +14 -0
- package/dist/compat/useSessionContext.d.ts.map +1 -0
- package/dist/compat/useSessionContext.js +20 -0
- package/dist/compat/useSessionContext.js.map +1 -0
- package/dist/components/LoginPage.d.ts +15 -0
- package/dist/components/LoginPage.d.ts.map +1 -0
- package/dist/components/LoginPage.js +33 -0
- package/dist/components/LoginPage.js.map +1 -0
- package/dist/components/UserAvatar.d.ts +19 -0
- package/dist/components/UserAvatar.d.ts.map +1 -0
- package/dist/components/UserAvatar.js +45 -0
- package/dist/components/UserAvatar.js.map +1 -0
- package/dist/hooks/index.d.ts +11 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useConnect.d.ts +15 -0
- package/dist/hooks/useConnect.d.ts.map +1 -0
- package/dist/hooks/useConnect.js +19 -0
- package/dist/hooks/useConnect.js.map +1 -0
- package/dist/hooks/useEmail.d.ts +11 -0
- package/dist/hooks/useEmail.d.ts.map +1 -0
- package/dist/hooks/useEmail.js +47 -0
- package/dist/hooks/useEmail.js.map +1 -0
- package/dist/hooks/useOAuth.d.ts +12 -0
- package/dist/hooks/useOAuth.d.ts.map +1 -0
- package/dist/hooks/useOAuth.js +75 -0
- package/dist/hooks/useOAuth.js.map +1 -0
- package/dist/hooks/usePasskey.d.ts +14 -0
- package/dist/hooks/usePasskey.d.ts.map +1 -0
- package/dist/hooks/usePasskey.js +35 -0
- package/dist/hooks/usePasskey.js.map +1 -0
- package/dist/hooks/useSession.d.ts +12 -0
- package/dist/hooks/useSession.d.ts.map +1 -0
- package/dist/hooks/useSession.js +30 -0
- package/dist/hooks/useSession.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/internals/blocklet-config.d.ts +22 -0
- package/dist/internals/blocklet-config.d.ts.map +1 -0
- package/dist/internals/blocklet-config.js +26 -0
- package/dist/internals/blocklet-config.js.map +1 -0
- package/dist/internals/local-storage-adapter.d.ts +12 -0
- package/dist/internals/local-storage-adapter.d.ts.map +1 -0
- package/dist/internals/local-storage-adapter.js +32 -0
- package/dist/internals/local-storage-adapter.js.map +1 -0
- package/dist/internals/use-sync-state.d.ts +18 -0
- package/dist/internals/use-sync-state.d.ts.map +1 -0
- package/dist/internals/use-sync-state.js +38 -0
- package/dist/internals/use-sync-state.js.map +1 -0
- package/package.json +33 -79
- package/LICENSE +0 -13
- package/README.md +0 -134
- package/dist/standalone/did-connect-react.css +0 -1
- package/dist/standalone/index.js +0 -133700
- package/lib/Address/index.js +0 -4
- package/lib/Avatar/index.js +0 -4
- package/lib/Button/index.js +0 -17
- package/lib/Connect/assets/locale.js +0 -147
- package/lib/Connect/assets/login-bg.png +0 -0
- package/lib/Connect/assets/login-slogan.js +0 -9
- package/lib/Connect/components/action-button.js +0 -26
- package/lib/Connect/components/app-tips.js +0 -132
- package/lib/Connect/components/auto-height.js +0 -31
- package/lib/Connect/components/back-button.js +0 -25
- package/lib/Connect/components/connect-status.js +0 -263
- package/lib/Connect/components/did-connect-title.js +0 -127
- package/lib/Connect/components/download-tips.js +0 -52
- package/lib/Connect/components/loading.js +0 -26
- package/lib/Connect/components/login-item/connect-choose-list.js +0 -257
- package/lib/Connect/components/login-item/connect-provider-list.js +0 -345
- package/lib/Connect/components/login-item/login-method-item.js +0 -147
- package/lib/Connect/components/login-item/mobile-login-item.js +0 -116
- package/lib/Connect/components/login-item/passkey-login-item.js +0 -44
- package/lib/Connect/components/login-item/wallet-login-options.js +0 -114
- package/lib/Connect/components/login-item/web-login-item.js +0 -104
- package/lib/Connect/components/mask-overlay.js +0 -34
- package/lib/Connect/components/refresh-overlay.js +0 -57
- package/lib/Connect/components/switch-app.js +0 -70
- package/lib/Connect/connect.js +0 -505
- package/lib/Connect/contexts/state.js +0 -156
- package/lib/Connect/fallback-connect.js +0 -53
- package/lib/Connect/fullpage.js +0 -5
- package/lib/Connect/hooks/auth-url.js +0 -23
- package/lib/Connect/hooks/method-list.js +0 -46
- package/lib/Connect/hooks/page-show.js +0 -17
- package/lib/Connect/hooks/provider-list.js +0 -69
- package/lib/Connect/hooks/security.js +0 -27
- package/lib/Connect/hooks/token.js +0 -296
- package/lib/Connect/hooks/use-apps.js +0 -19
- package/lib/Connect/hooks/use-quick-connect.js +0 -86
- package/lib/Connect/index.js +0 -16
- package/lib/Connect/landing-page.js +0 -5
- package/lib/Connect/plugins/email/index.js +0 -65
- package/lib/Connect/plugins/email/list-item.js +0 -31
- package/lib/Connect/plugins/email/placeholder.js +0 -284
- package/lib/Connect/plugins/index.js +0 -4
- package/lib/Connect/use-connect.js +0 -164
- package/lib/Connect/with-blocklet.js +0 -15
- package/lib/Connect/with-bridge-call.js +0 -108
- package/lib/Federated/context.js +0 -61
- package/lib/Federated/index.js +0 -7
- package/lib/Logo/index.js +0 -4
- package/lib/OAuth/bind-conflict-alert.js +0 -29
- package/lib/OAuth/context.js +0 -277
- package/lib/OAuth/guest.svg.js +0 -5
- package/lib/OAuth/index.js +0 -7
- package/lib/OAuth/passport-switcher.js +0 -5
- package/lib/Passkey/actions.js +0 -170
- package/lib/Passkey/constants.js +0 -4
- package/lib/Passkey/context.js +0 -281
- package/lib/Passkey/dialog.js +0 -280
- package/lib/Passkey/icon.js +0 -13
- package/lib/Passkey/index.js +0 -9
- package/lib/Service/index.js +0 -62
- package/lib/Session/assets/did-spaces-guide-cover.svg.js +0 -111
- package/lib/Session/assets/did-spaces-guide-icon.svg.js +0 -9
- package/lib/Session/context.js +0 -5
- package/lib/Session/did-spaces-guide.js +0 -136
- package/lib/Session/handler.js +0 -55
- package/lib/Session/hooks/use-federated.js +0 -64
- package/lib/Session/hooks/use-mobile.js +0 -8
- package/lib/Session/hooks/use-protected-routes.js +0 -11
- package/lib/Session/hooks/use-session-token.js +0 -181
- package/lib/Session/hooks/use-verify.js +0 -45
- package/lib/Session/index.js +0 -941
- package/lib/Session/libs/constants.js +0 -18
- package/lib/Session/libs/did-spaces.js +0 -10
- package/lib/Session/libs/federated.js +0 -42
- package/lib/Session/libs/index.js +0 -15
- package/lib/Session/libs/locales.js +0 -161
- package/lib/Session/libs/login-mobile.js +0 -55
- package/lib/Session/window-focus-aware.js +0 -17
- package/lib/SessionManager/index.js +0 -4
- package/lib/Storage/engine/cookie.js +0 -22
- package/lib/Storage/engine/local-storage.js +0 -37
- package/lib/Storage/index.js +0 -23
- package/lib/User/index.js +0 -6
- package/lib/User/use-did.js +0 -59
- package/lib/User/wrap-did.js +0 -13
- package/lib/WebWalletSWKeeper/index.js +0 -5
- package/lib/components/PassportSwitcher.js +0 -128
- package/lib/constant.js +0 -23
- package/lib/error.js +0 -8
- package/lib/hooks/use-locale.js +0 -7
- package/lib/index.js +0 -111
- package/lib/locales/en.js +0 -17
- package/lib/locales/index.js +0 -10
- package/lib/locales/zh.js +0 -17
- package/lib/package.json.js +0 -7
- package/lib/types.d.ts +0 -355
- package/lib/utils.js +0 -225
package/lib/Session/index.js
DELETED
|
@@ -1,941 +0,0 @@
|
|
|
1
|
-
import { jsx as m, jsxs as K, Fragment as Vo } from "react/jsx-runtime";
|
|
2
|
-
import S from "prop-types";
|
|
3
|
-
import jo from "lodash/omit";
|
|
4
|
-
import Ko from "lodash/pick";
|
|
5
|
-
import Te from "lodash/cloneDeep";
|
|
6
|
-
import Z from "lodash/isFunction";
|
|
7
|
-
import u from "lodash/isUndefined";
|
|
8
|
-
import $o from "lodash/defaultsDeep";
|
|
9
|
-
import qo from "js-cookie";
|
|
10
|
-
import Xo from "eventemitter3";
|
|
11
|
-
import Qo from "p-wait-for";
|
|
12
|
-
import { useTheme as Yo, Typography as Jo, Box as $, CircularProgress as Zo } from "@mui/material";
|
|
13
|
-
import { getVisitorId as q, mergeIgnoreEmpty as et, isUrl as ot, ensureVisitorId as tt, setVisitorId as ke } from "@arcblock/ux/lib/Util";
|
|
14
|
-
import ae, { ToastProvider as ye } from "@arcblock/ux/lib/Toast";
|
|
15
|
-
import it from "@arcblock/ux/lib/Center";
|
|
16
|
-
import { useReactive as Ie, useCreation as Le, useMemoizedFn as f, usePrevious as rt, useLatest as De, useUpdateEffect as le, useMount as nt } from "ahooks";
|
|
17
|
-
import { joinURL as H } from "ufo";
|
|
18
|
-
import { Icon as st } from "@iconify/react";
|
|
19
|
-
import ct from "@iconify-icons/material-symbols/keyboard-double-arrow-right-rounded";
|
|
20
|
-
import at from "@arcblock/react-hooks/lib/useBrowser";
|
|
21
|
-
import lt from "@arcblock/ux/lib/Dialog/use-confirm";
|
|
22
|
-
import _e from "@arcblock/ux/lib/DID";
|
|
23
|
-
import Ee from "@arcblock/ux/lib/Avatar";
|
|
24
|
-
import { getCurrentAppPid as dt } from "@arcblock/ux/lib/SessionUser/libs/utils";
|
|
25
|
-
import { translate as pt } from "@arcblock/ux/lib/Locale/util";
|
|
26
|
-
import { getBlockletSDK as ft } from "@blocklet/js-sdk";
|
|
27
|
-
import b from "@arcblock/bridge";
|
|
28
|
-
import { getFederatedEnabled as ut } from "@arcblock/ux/lib/Util/federated";
|
|
29
|
-
import wt from "lodash/noop";
|
|
30
|
-
import ht from "lodash/isNil";
|
|
31
|
-
import { ReactGA as mt } from "@arcblock/ux/lib/withTracker";
|
|
32
|
-
import { useState as gt, useEffect as St } from "react";
|
|
33
|
-
import de from "../Storage/index.js";
|
|
34
|
-
import { formatCacheTtl as Pt, getBrowserLang as At, debug as h, decodeUrlParams as ve, sleep as E, debugTmp as xe, updateConnectedInfo as ee, getAppId as oe, logger as Oe } from "../utils.js";
|
|
35
|
-
import Re from "./window-focus-aware.js";
|
|
36
|
-
import { OAuthContext as bt, OAuthConsumer as Ct, OAuthProvider as Ne, useOAuth as Tt } from "../OAuth/context.js";
|
|
37
|
-
import { PasskeyContext as kt, PasskeyConsumer as yt, PasskeyProvider as We, usePasskey as It } from "../Passkey/context.js";
|
|
38
|
-
import "../Passkey/actions.js";
|
|
39
|
-
import Lt, { getWalletDid as Dt } from "../User/use-did.js";
|
|
40
|
-
import _t from "../User/wrap-did.js";
|
|
41
|
-
import Et from "./hooks/use-federated.js";
|
|
42
|
-
import vt from "./hooks/use-session-token.js";
|
|
43
|
-
import xt from "./hooks/use-protected-routes.js";
|
|
44
|
-
import { SessionContext as qe } from "./context.js";
|
|
45
|
-
import Ot from "../Connect/use-connect.js";
|
|
46
|
-
import { EVENTS as a } from "./libs/constants.js";
|
|
47
|
-
import { translations as B } from "./libs/locales.js";
|
|
48
|
-
import { NotOpenError as Rt } from "../error.js";
|
|
49
|
-
import { SESSION_TOKEN_STORAGE_KEY as Xe, REFRESH_TOKEN_STORAGE_KEY as Qe, CSRF_TOKEN_STORAGE_KEY as Nt, API_DID_PREFIX as Wt, DEFAULT_TIMEOUT as Ft, BLOCKLET_SERVICE_PATH_PREFIX as G, DID_SPACES_BASE_URL as Bt } from "../constant.js";
|
|
50
|
-
import { getMobileVisitorId as Ut, checkEnableAutoLogin as Mt, login as Ht } from "./libs/login-mobile.js";
|
|
51
|
-
import Gt from "../Connect/hooks/use-quick-connect.js";
|
|
52
|
-
import { didSpacesIsRequired as Fe } from "./libs/did-spaces.js";
|
|
53
|
-
import zt from "./did-spaces-guide.js";
|
|
54
|
-
import { FederatedProvider as Vt, useFederatedContext as jt } from "../Federated/context.js";
|
|
55
|
-
import Kt from "./hooks/use-verify.js";
|
|
56
|
-
import { gaLoginSuccessHandler as Be, gaLoginFailedHandler as Ue, gaSwitchPassportSuccessHandler as Me, gaSwitchPassportFailedHandler as He, gaBindWalletSuccessHandler as Ge, gaBindWalletFailedHandler as ze } from "./handler.js";
|
|
57
|
-
import { loginFederatedMaster as Zi, mountFederatedIframe as er } from "./libs/federated.js";
|
|
58
|
-
const { Provider: $t, Consumer: Ve } = qe, je = {
|
|
59
|
-
en: "DID Connect timeout, please reopen DID Connect popup",
|
|
60
|
-
zh: "DID Connect 超时, 请重新打开 DID Connect"
|
|
61
|
-
}, Ke = {
|
|
62
|
-
en: "DID Connect is already opened, please wait for it to complete",
|
|
63
|
-
zh: "DID Connect 已打开,请等待完成"
|
|
64
|
-
};
|
|
65
|
-
function $e(X = Xe, Q = "ls", te = {}, k = {}) {
|
|
66
|
-
let D = "/";
|
|
67
|
-
globalThis?.blocklet?.prefix && (D = globalThis.blocklet.prefix), typeof k == "boolean" && (k = {
|
|
68
|
-
appendAuthServicePrefix: k,
|
|
69
|
-
extraParams: {}
|
|
70
|
-
}), $o(k, {
|
|
71
|
-
rolling: !0,
|
|
72
|
-
appendAuthServicePrefix: !1,
|
|
73
|
-
extraParams: {},
|
|
74
|
-
refreshTokenStorageKey: Qe
|
|
75
|
-
});
|
|
76
|
-
function O(L) {
|
|
77
|
-
if (globalThis.blocklet)
|
|
78
|
-
if (L?.user) {
|
|
79
|
-
const v = {
|
|
80
|
-
did: L.user.did,
|
|
81
|
-
host: window.location.host,
|
|
82
|
-
appPid: globalThis.blocklet.appPid,
|
|
83
|
-
visitorId: q(),
|
|
84
|
-
sourceAppPid: L.user.sourceAppPid,
|
|
85
|
-
fullName: L.user.fullName
|
|
86
|
-
};
|
|
87
|
-
h("bridge callArc: onLogin", v), b.callArc("onLogin", { ...v, user: v });
|
|
88
|
-
} else
|
|
89
|
-
b.callArc("onLogin", { error: "no user", code: 400 }), h("notifyBridge failed", { sessionState: L });
|
|
90
|
-
}
|
|
91
|
-
const Y = de(X, Q, te), z = de(Nt, "cookie", {
|
|
92
|
-
secure: !0,
|
|
93
|
-
sameSite: "strict"
|
|
94
|
-
}), Ye = de(k.refreshTokenStorageKey, "ls");
|
|
95
|
-
function pe({ ...L }) {
|
|
96
|
-
const v = ft(), n = Object.assign({}, L);
|
|
97
|
-
u(n.serviceHost) && (n.serviceHost = D), u(n.locale) && (n.locale = ""), u(n.action) && (n.action = "login"), u(n.prefix) && (n.prefix = Wt), u(n.appendAuthServicePrefix) && (n.appendAuthServicePrefix = !1), u(n.extraParams) && (n.extraParams = {}), u(n.options) && (n.options = {}), u(n.autoConnect) && (n.autoConnect = !1), u(n.autoDisconnect) && (n.autoDisconnect = !0), u(n.useSocket) && (n.useSocket = !0), u(n.timeout) && (n.timeout = Ft * 1e3), u(n.webWalletUrl) && (n.webWalletUrl = void 0), u(n.protectedRoutes) && (n.protectedRoutes = ["*"]), u(n.apiOptions) && (n.apiOptions = {}), u(n.lazyRefreshToken) && (n.lazyRefreshToken = !1);
|
|
98
|
-
const { connectApi: y, connectHolder: Ze } = Ot(), [eo, fe] = gt(0), I = at(), { requestStorageAccess: oo } = jt(), { palette: to } = Yo(), U = new URLSearchParams(window.location.search), c = Ie({
|
|
99
|
-
extraParams: {},
|
|
100
|
-
options: {},
|
|
101
|
-
currentLocale: n.locale,
|
|
102
|
-
allowWallet: void 0,
|
|
103
|
-
openMode: "window",
|
|
104
|
-
get autoConnect() {
|
|
105
|
-
return typeof n.autoConnect == "boolean" ? n.autoConnect : !!n.autoLogin;
|
|
106
|
-
},
|
|
107
|
-
get prefix() {
|
|
108
|
-
return k.appendAuthServicePrefix || n.appendAuthServicePrefix ? H(G, n.prefix) : n.prefix;
|
|
109
|
-
},
|
|
110
|
-
get notificationPrefix() {
|
|
111
|
-
const e = "/api/notifications";
|
|
112
|
-
return k.appendAuthServicePrefix || n.appendAuthServicePrefix ? H(G, e) : e;
|
|
113
|
-
}
|
|
114
|
-
}), i = Ie({
|
|
115
|
-
action: n.action,
|
|
116
|
-
error: "",
|
|
117
|
-
initialized: !1,
|
|
118
|
-
loading: !1,
|
|
119
|
-
open: !1,
|
|
120
|
-
user: null,
|
|
121
|
-
provider: "",
|
|
122
|
-
walletOS: "",
|
|
123
|
-
baseUrl: "",
|
|
124
|
-
unReadCount: 0
|
|
125
|
-
// 不可以直接个性 props.autoConnect (readonly)
|
|
126
|
-
}), P = Le(() => n.locale || c.currentLocale || At(), [n.locale, c.currentLocale]), { confirmApi: io, confirmHolder: ro } = lt(), R = f(() => {
|
|
127
|
-
if (i.open && !I.arcSphere) {
|
|
128
|
-
const e = Ke[P] || Ke.en;
|
|
129
|
-
throw ae.warning(e), new Error(e);
|
|
130
|
-
}
|
|
131
|
-
}), d = Le(() => new Xo(), []);
|
|
132
|
-
St(() => (d.on(a.LOGIN, Be), d.on(a.LOGIN_FAILED, Ue), d.on(a.SWITCH_PASSPORT, Me), d.on(a.SWITCH_PASSPORT_FAILED, He), d.on(a.BIND_WALLET, Ge), d.on(a.BIND_WALLET_FAILED, ze), () => {
|
|
133
|
-
d.off(a.LOGIN, Be), d.off(a.LOGIN_FAILED, Ue), d.off(a.SWITCH_PASSPORT, Me), d.off(a.SWITCH_PASSPORT_FAILED, He), d.off(a.BIND_WALLET, Ge), d.off(a.BIND_WALLET_FAILED, ze);
|
|
134
|
-
}), [d]);
|
|
135
|
-
const M = f((e, o, t) => {
|
|
136
|
-
const s = {
|
|
137
|
-
login: [a.LOGIN, a.CANCEL_LOGIN],
|
|
138
|
-
"bind-wallet": [a.BIND_WALLET, a.CANCEL_BIND_WALLET],
|
|
139
|
-
"switch-passport": [a.SWITCH_PASSPORT, a.CANCEL_SWITCH_PASSPORT],
|
|
140
|
-
"switch-profile": [a.SWITCH_PROFILE, a.CANCEL_SWITCH_PROFILE],
|
|
141
|
-
// HACK: 对于内部来说,switch-did 就是 login,所以内部的监听事件仍然是 login
|
|
142
|
-
"switch-did": [a.LOGIN, a.CANCEL_LOGIN],
|
|
143
|
-
// @FIXME: @zhanghan 整个事件发射的机制需要重构,目前的实现不是很优雅,对于用户来说不是很好用。 https://github.com/ArcBlock/ux/pull/1414#discussion_r1904830954
|
|
144
|
-
"did-space-connected": [a.DID_SPACE_CONNECTED]
|
|
145
|
-
};
|
|
146
|
-
if (!Object.keys(s).includes(e))
|
|
147
|
-
return;
|
|
148
|
-
const l = async (...p) => {
|
|
149
|
-
Z(o) && await o(...p), d.emit(e, ...p);
|
|
150
|
-
};
|
|
151
|
-
d.once(s[e][0], l), d.once(s[e][1], async (...p) => {
|
|
152
|
-
Z(l) && d.off(s[e][0], l), Z(t) && await t(...p), d.emit(`cancel-${e}`, ...p);
|
|
153
|
-
});
|
|
154
|
-
}), no = rt(i.initialized, (e, o) => e !== o || e === !0 && o === !0), {
|
|
155
|
-
syncSessionSate: so,
|
|
156
|
-
handleRefreshUser: C,
|
|
157
|
-
handleRefreshToken: co,
|
|
158
|
-
renewToken: ao,
|
|
159
|
-
clearSession: ue,
|
|
160
|
-
handleLoginResult: x,
|
|
161
|
-
decrypt: _,
|
|
162
|
-
service: lo,
|
|
163
|
-
getSessionToken: po,
|
|
164
|
-
getRefreshToken: fo,
|
|
165
|
-
setRefreshToken: uo,
|
|
166
|
-
setSessionToken: wo
|
|
167
|
-
} = vt({
|
|
168
|
-
state: i,
|
|
169
|
-
pageState: c,
|
|
170
|
-
sessionTokenStorage: Y,
|
|
171
|
-
refreshTokenStorage: Ye,
|
|
172
|
-
csrfTokenStorage: z,
|
|
173
|
-
serviceHost: n.serviceHost,
|
|
174
|
-
apiOptions: n.apiOptions,
|
|
175
|
-
lazyRefreshToken: n.lazyRefreshToken,
|
|
176
|
-
onRefresh({ type: e, sessionToken: o, refreshToken: t, user: s }) {
|
|
177
|
-
if (h("onRefresh", { type: e, user: s }), globalThis.blocklet) {
|
|
178
|
-
const l = {
|
|
179
|
-
did: s.did,
|
|
180
|
-
host: window.location.host,
|
|
181
|
-
appPid: globalThis.blocklet.appPid,
|
|
182
|
-
visitorId: q(),
|
|
183
|
-
sourceAppPid: s.sourceAppPid,
|
|
184
|
-
fullName: s.fullName
|
|
185
|
-
};
|
|
186
|
-
e === "refreshToken" ? (h("bridge callArc: onRefreshToken"), b.callArc("onRefreshToken", {
|
|
187
|
-
sessionToken: o,
|
|
188
|
-
refreshToken: t,
|
|
189
|
-
user: l
|
|
190
|
-
})) : e === "refreshUser" && (h("bridge callArc: onRefreshUser"), b.callArc("onRefreshUser", {
|
|
191
|
-
sessionToken: o,
|
|
192
|
-
refreshToken: t,
|
|
193
|
-
user: l
|
|
194
|
-
}));
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}), ho = Kt({ state: i, connectApi: y }), we = f((e, o = {}, t = {}) => {
|
|
198
|
-
R();
|
|
199
|
-
const s = e;
|
|
200
|
-
typeof s == "object" && (e = s.onSuccess, o = s.extraParams || {}, t = s.options || {}, t.origin = s.origin || ""), (!i.user || t.origin === "switch-did") && (t.origin === "switch-did" ? M("switch-did", e, s?.onCancel) : M("login", e, s?.onCancel), c.extraParams = o, c.options = t, i.action = "login", F());
|
|
201
|
-
}), mo = f((e, o = {}) => {
|
|
202
|
-
const t = e;
|
|
203
|
-
return function(...l) {
|
|
204
|
-
const p = this;
|
|
205
|
-
return (async () => {
|
|
206
|
-
try {
|
|
207
|
-
const g = await ho(o);
|
|
208
|
-
if (!g.sessionId)
|
|
209
|
-
throw new Error("Authentication failed");
|
|
210
|
-
return await t.call(p, g, ...l);
|
|
211
|
-
} catch (g) {
|
|
212
|
-
throw console.error("Authentication failed", g), g;
|
|
213
|
-
}
|
|
214
|
-
})();
|
|
215
|
-
};
|
|
216
|
-
}), ie = f(async (e, o = {}, t = {}) => {
|
|
217
|
-
R();
|
|
218
|
-
const s = e;
|
|
219
|
-
typeof s == "object" && (e = s.onSuccess, o = s.extraParams || {}, t = s.options || {}), u(o?.inviter) && window.localStorage.getItem("inviter") && (o.inviter = window.localStorage.getItem("inviter"));
|
|
220
|
-
const { params: l } = await ve();
|
|
221
|
-
if (u(o?.forceConnected) && l?.forceConnected && (o.forceConnected = l.forceConnected, u(t.showQuickConnect) && (t.showQuickConnect = !1)), u(o?.sourceAppPid) && !u(l?.sourceAppPid) && (o.sourceAppPid = l.sourceAppPid), o?.openMode === "redirect") {
|
|
222
|
-
const w = o?.redirect || "/", T = new URL(`${G}/login`, window.location.origin);
|
|
223
|
-
T.searchParams.set("redirect", w), o?.forceConnected && T.searchParams.set("forceConnected", o?.forceConnected), u(o?.sourceAppPid) || T.searchParams.set("sourceAppPid", o?.sourceAppPid), u(o?.inviter) || T.searchParams.set("inviter", o?.inviter), t?.origin && T.searchParams.set("origin", t.origin), window.location.href = T.href;
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
let p = o?.sourceAppPid;
|
|
227
|
-
u(p) && No && (p = Wo.appPid), await Qo(() => i.initialized), typeof t == "string" && (t = { origin: t });
|
|
228
|
-
const g = Te(o);
|
|
229
|
-
g.passkeyBehavior = "both", c.allowWallet = void 0;
|
|
230
|
-
const r = g?.openMode || n?.extraParams?.openMode;
|
|
231
|
-
u(r) ? p ? p !== globalThis.blocklet.appPid && ut(globalThis.blocklet) && (c.openMode = "window") : c.openMode = "popup" : c.openMode = r, c.openMode === "window" && !I.arcSphere && !I.wallet && await oo() && (c.openMode = "popup"), p ? i.baseUrl = globalThis.blocklet.appUrl : i.baseUrl = "", we(e, g, t);
|
|
232
|
-
}), he = f(async (e) => {
|
|
233
|
-
const o = q();
|
|
234
|
-
if (globalThis.blocklet && (v.user.logout({ visitorId: o }).catch((t) => {
|
|
235
|
-
console.warn("Failed to logout remote", t);
|
|
236
|
-
}), await E(100)), globalThis.blocklet) {
|
|
237
|
-
const t = {
|
|
238
|
-
visitorId: o,
|
|
239
|
-
appPid: globalThis.blocklet.appPid,
|
|
240
|
-
userDid: i.user.did
|
|
241
|
-
};
|
|
242
|
-
h("bridge callArc: onLogout", t), b.callArc("onLogout", t);
|
|
243
|
-
}
|
|
244
|
-
xe("[clearSession] createSessionContext -> logout:"), ue(), j(), i.user = null, i.provider = "", i.walletOS = "", i.error = "", i.loading = !1, d.emit("logout"), mt.set({
|
|
245
|
-
user_id: void 0
|
|
246
|
-
}), typeof e == "function" && e();
|
|
247
|
-
}), {
|
|
248
|
-
userSessions: go,
|
|
249
|
-
refresh: So,
|
|
250
|
-
loaded: Po,
|
|
251
|
-
loginUserSession: re
|
|
252
|
-
} = Gt({
|
|
253
|
-
appPid: dt(i.user),
|
|
254
|
-
loginAppPid: globalThis?.blocklet?.appPid,
|
|
255
|
-
sourceAppPid: i?.user?.sourceAppPid,
|
|
256
|
-
autoFetch: !1,
|
|
257
|
-
fetchAll: !0
|
|
258
|
-
}), Ao = f((e, o) => {
|
|
259
|
-
if (!globalThis.blocklet) return null;
|
|
260
|
-
const t = globalThis.blocklet?.settings?.actionConfig?.[e];
|
|
261
|
-
return t ? t[o] || t.en : null;
|
|
262
|
-
}), N = f(async () => {
|
|
263
|
-
i?.user || await new Promise((e) => {
|
|
264
|
-
ie(() => {
|
|
265
|
-
e();
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
}), ne = f((e, o = {}, t = {}) => {
|
|
269
|
-
R();
|
|
270
|
-
const s = e;
|
|
271
|
-
typeof s == "object" && (e = s.onSuccess, o = s.extraParams || {}, t = s.options || {}), typeof t == "string" && (t = { origin: t }), t?.userSession ? re(t.userSession).then((l) => {
|
|
272
|
-
ee(
|
|
273
|
-
{
|
|
274
|
-
connected_did: t.userSession.user.did,
|
|
275
|
-
connected_pk: t.userSession.user.pk,
|
|
276
|
-
connected_wallet_os: t.userSession.extra.walletOS,
|
|
277
|
-
connected_app: oe()
|
|
278
|
-
},
|
|
279
|
-
!0
|
|
280
|
-
), M("switch-did", e), x({ ...l, encrypted: !1 }), C({ showProgress: !0 }).then(async () => {
|
|
281
|
-
await E(200), d.emit(a.LOGIN, l, _, A.current), O(A.current), await W();
|
|
282
|
-
}).catch((p) => {
|
|
283
|
-
throw d.emit(a.LOGIN_FAILED, p), p;
|
|
284
|
-
});
|
|
285
|
-
}) : (u(o?.forceConnected) && (o.forceConnected = !1), o.passkeyBehavior = "both", ie(e, o, { ...t, origin: "switch-did" }));
|
|
286
|
-
}), bo = f(async () => {
|
|
287
|
-
await v.user.refreshProfile();
|
|
288
|
-
}), Co = f(async (e, o = {}) => {
|
|
289
|
-
await N(), R();
|
|
290
|
-
const t = e;
|
|
291
|
-
typeof t == "object" && (e = t.onSuccess, o = t.extraParams || {}), M("switch-profile", e, t?.onCancel), c.extraParams = o, c.options = {}, i.action = "switch-profile", F();
|
|
292
|
-
}), To = f(async (e, o = {}) => {
|
|
293
|
-
await N(), R();
|
|
294
|
-
const t = e;
|
|
295
|
-
typeof t == "object" && (e = t.onSuccess, o = t.extraParams || {}), M("switch-passport", e, t?.onCancel), c.extraParams = o, c.options = {}, i.action = "switch-passport", F();
|
|
296
|
-
}), ko = f(async ({ extraParams: e = {}, onSuccess: o = () => {
|
|
297
|
-
}, ...t } = {}) => {
|
|
298
|
-
await N(), R(), c.extraParams = {
|
|
299
|
-
referrer: window.location.href,
|
|
300
|
-
purpose: "authorize-for-import",
|
|
301
|
-
...e,
|
|
302
|
-
saveConnect: !1
|
|
303
|
-
// 连接 spaces 不保存连接信息
|
|
304
|
-
}, c.options = {}, i.action = "connect-to-did-spaces-for-user", F({
|
|
305
|
-
hideCloseButton: !0,
|
|
306
|
-
onSuccess: o,
|
|
307
|
-
...t
|
|
308
|
-
});
|
|
309
|
-
}), me = f(async ({ extraParams: e = {}, onSuccess: o = {} } = {}) => {
|
|
310
|
-
await N(), ko({
|
|
311
|
-
extraParams: {
|
|
312
|
-
// service 交互
|
|
313
|
-
purpose: "authorize-for-import",
|
|
314
|
-
...e
|
|
315
|
-
},
|
|
316
|
-
onSuccess: o,
|
|
317
|
-
hideCloseButton: !1
|
|
318
|
-
});
|
|
319
|
-
}), { didSpacesGuideApi: J, DidSpacesGuideView: yo } = zt({
|
|
320
|
-
autoClose: !1
|
|
321
|
-
}), W = async ({ extraParams: e = {}, onSuccess: o = () => {
|
|
322
|
-
} } = {}) => {
|
|
323
|
-
await N(), await Fe(i?.user) && (J.open(), J.onConnect((t = wt) => {
|
|
324
|
-
const s = {
|
|
325
|
-
prefix: "/connect-to-did-space",
|
|
326
|
-
custom: !0,
|
|
327
|
-
extraParams: {
|
|
328
|
-
provider: "wallet",
|
|
329
|
-
appPid: window.blocklet?.appPid,
|
|
330
|
-
appDid: window.blocklet?.appId,
|
|
331
|
-
appName: window.blocklet?.appName,
|
|
332
|
-
appDescription: window.blocklet?.appDescription,
|
|
333
|
-
appUrl: window.blocklet?.appUrl,
|
|
334
|
-
referrer: window.location.href,
|
|
335
|
-
connectScope: "user",
|
|
336
|
-
...e
|
|
337
|
-
},
|
|
338
|
-
onSuccess: async (l, p) => {
|
|
339
|
-
const g = p ? p(l.spaceGateway) : l.spaceGateway;
|
|
340
|
-
await v.user.updateDidSpace({ spaceGateway: g }), await C({ showProgress: !0 }), await o(l, p), await J.close(), d.emit(a.DID_SPACE_CONNECTED, l, p), globalThis.blocklet && (h("bridge callArc: onDidSpaceConnected"), b.callArc("onDidSpaceConnected")), t(!0);
|
|
341
|
-
},
|
|
342
|
-
onError: (l) => {
|
|
343
|
-
console.error(l), ae.error(l.message), J.close(), t(!1);
|
|
344
|
-
},
|
|
345
|
-
onClose: () => {
|
|
346
|
-
t();
|
|
347
|
-
}
|
|
348
|
-
};
|
|
349
|
-
y.openPopup(s, {
|
|
350
|
-
baseUrl: Bt
|
|
351
|
-
});
|
|
352
|
-
}));
|
|
353
|
-
}, ge = f(async (e, o = {}) => {
|
|
354
|
-
if (await N(), Dt(i.user)) {
|
|
355
|
-
e({}, _, A.current);
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
R();
|
|
359
|
-
const t = e;
|
|
360
|
-
typeof t == "object" && (e = t.onSuccess), M("bind-wallet", e, t?.onCancel), c.extraParams = o, c.options = {}, i.action = "bind-wallet", F();
|
|
361
|
-
}), se = f(async (e) => {
|
|
362
|
-
h("onSwitchPassport", { result: e }), c.extraParams = {}, c.options = {}, x(e), i.loading = !1, await C({ showProgress: !0 }), await E(200), d.emit(a.SWITCH_PASSPORT, e, _, A.current), globalThis.blocklet && (h("bridge callArc: onSwitchPassport"), b.callArc("onSwitchPassport"));
|
|
363
|
-
}), Io = f((e) => {
|
|
364
|
-
d.emit(a.SWITCH_PASSPORT_FAILED, e);
|
|
365
|
-
}), V = f(async (e) => {
|
|
366
|
-
if (i.action === "switch-passport") {
|
|
367
|
-
se(e);
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
h("onLogin", { result: e }), c.extraParams = {}, c.options = {}, x(e), i.loading = !1, await C({ showProgress: !0 }), await E(200), i.action === "login" && (h("onLogin: emit LOGIN event", { result: e }), d.emit(a.LOGIN, e, _, A.current), O(A.current), W());
|
|
371
|
-
}), Lo = f((e) => {
|
|
372
|
-
d.emit(a.LOGIN_FAILED, e);
|
|
373
|
-
}), Do = f((e) => {
|
|
374
|
-
c.extraParams = {}, c.options = {}, x(e), i.loading = !1, C({ showProgress: !0 }).then(async () => {
|
|
375
|
-
await E(100), d.emit(a.BIND_WALLET, e, _, A.current), globalThis.blocklet && (h("bridge callArc: onBindWallet"), b.callArc("onBindWallet"));
|
|
376
|
-
});
|
|
377
|
-
}), _o = f((e) => {
|
|
378
|
-
d.emit(a.BIND_WALLET_FAILED, e, A);
|
|
379
|
-
}), Eo = f((e) => {
|
|
380
|
-
h("onSwitchProfile", { result: e }), c.extraParams = {}, c.options = {}, i.loading = !1, C({ showProgress: !0 }).then(async () => {
|
|
381
|
-
await E(100), d.emit(a.SWITCH_PROFILE, e, _, A.current), globalThis.blocklet && (h("bridge callArc: onSwitchProfile"), b.callArc("onSwitchProfile"));
|
|
382
|
-
});
|
|
383
|
-
}), vo = f((e) => {
|
|
384
|
-
c.extraParams = {}, c.options = {}, j();
|
|
385
|
-
const o = {
|
|
386
|
-
login: a.CANCEL_LOGIN,
|
|
387
|
-
"switch-profile": a.CANCEL_SWITCH_PROFILE,
|
|
388
|
-
"switch-passport": a.CANCEL_SWITCH_PASSPORT,
|
|
389
|
-
"bind-wallet": a.CANCEL_BIND_WALLET
|
|
390
|
-
}, t = {
|
|
391
|
-
login: "offLogin",
|
|
392
|
-
"switch-profile": "offSwitchProfile",
|
|
393
|
-
"switch-passport": "offSwitchPassport",
|
|
394
|
-
"bind-wallet": "offBindWallet"
|
|
395
|
-
};
|
|
396
|
-
d.emit(o[e]), globalThis.blocklet && (h(`bridge callArc: ${t[e]}`), b.callArc(`${t[e]}`));
|
|
397
|
-
}), xo = f((e, ...o) => {
|
|
398
|
-
try {
|
|
399
|
-
ce[e](...o);
|
|
400
|
-
} catch (t) {
|
|
401
|
-
Oe.error("Catch error in onSuccess", {
|
|
402
|
-
action: e,
|
|
403
|
-
args: o,
|
|
404
|
-
err: t
|
|
405
|
-
}), ce[`${e}-failed`]?.(t, ...o);
|
|
406
|
-
}
|
|
407
|
-
}), Oo = f((e, o, ...t) => {
|
|
408
|
-
ce[`${e}-failed`]?.(o, ...t);
|
|
409
|
-
}), {
|
|
410
|
-
federatedMaster: Ro,
|
|
411
|
-
federatedEnabled: No,
|
|
412
|
-
master: Wo
|
|
413
|
-
} = Et({
|
|
414
|
-
locale: P,
|
|
415
|
-
decrypt: _,
|
|
416
|
-
login: we,
|
|
417
|
-
handleLoginResult: x,
|
|
418
|
-
handleRefreshUser: C,
|
|
419
|
-
setRefreshToken: uo,
|
|
420
|
-
setSessionToken: wo
|
|
421
|
-
}), { checkMatch: Fo } = xt({ protectedRoutes: n.protectedRoutes || [] }), Bo = De(go), Se = f(async () => (Po || (await So(), await E(100)), Bo.current)), j = f(() => {
|
|
422
|
-
i.open = !1, y.close();
|
|
423
|
-
}), F = async (e = {}) => {
|
|
424
|
-
let o = i.action;
|
|
425
|
-
c?.options?.origin === "switch-did" && (o = c?.options?.origin);
|
|
426
|
-
const t = B[o], s = Ao(o, P), l = et(t[P] || t.en, s || {}), p = {
|
|
427
|
-
...k.extraParams,
|
|
428
|
-
...n.extraParams,
|
|
429
|
-
...c.extraParams,
|
|
430
|
-
previousUserDid: i?.user?.did,
|
|
431
|
-
email: i?.user?.email
|
|
432
|
-
};
|
|
433
|
-
if (o === "switch-did" && p?.forceConnected) {
|
|
434
|
-
const r = (w, T = {}) => pt(B["switch-specified-did"], w, P, "en", T);
|
|
435
|
-
l.title = r("title"), l.scan = r("scan", { did: p.forceConnected }), l.confirm = r("confirm"), l.success = r("success");
|
|
436
|
-
}
|
|
437
|
-
delete p?.openMode;
|
|
438
|
-
const g = {
|
|
439
|
-
action: i.action,
|
|
440
|
-
locale: P,
|
|
441
|
-
hideCloseButton: e?.hideCloseButton,
|
|
442
|
-
extraParams: p,
|
|
443
|
-
options: { ...n.options || {}, ...c.options },
|
|
444
|
-
checkTimeout: n.timeout,
|
|
445
|
-
webWalletUrl: n.webWalletUrl,
|
|
446
|
-
messages: l,
|
|
447
|
-
useSocket: n.useSocket,
|
|
448
|
-
...jo(n, [
|
|
449
|
-
"action",
|
|
450
|
-
"locale",
|
|
451
|
-
// NOTICE: 将 serviceHost 也透传给 DID Connect 组件
|
|
452
|
-
// 'serviceHost',
|
|
453
|
-
"appendAuthServicePrefix",
|
|
454
|
-
"autoDisconnect",
|
|
455
|
-
"children",
|
|
456
|
-
"timeout",
|
|
457
|
-
"extraParams",
|
|
458
|
-
"options",
|
|
459
|
-
"webWalletUrl",
|
|
460
|
-
"messages",
|
|
461
|
-
"useSocket",
|
|
462
|
-
"lazyRefreshToken",
|
|
463
|
-
"apiOptions",
|
|
464
|
-
"protectedRoutes"
|
|
465
|
-
]),
|
|
466
|
-
// 允许 login/switchProfile/switchDid 的时候传入自定义参数
|
|
467
|
-
...Ko(c.extraParams || {}, [
|
|
468
|
-
"autoConnect",
|
|
469
|
-
"forceConnected",
|
|
470
|
-
"saveConnect",
|
|
471
|
-
"useSocket",
|
|
472
|
-
"passkeyBehavior"
|
|
473
|
-
]),
|
|
474
|
-
// baseUrl: state.baseUrl || props.baseUrl || '',
|
|
475
|
-
// 注意 prefix 经过了特殊处理, 优先级高于 "...rest", 所以放在其后
|
|
476
|
-
prefix: c.prefix,
|
|
477
|
-
allowWallet: u(c.allowWallet) ? i.action !== "login" || ["1", "true", void 0, null].includes(globalThis.blocklet?.DID_CONNECT_ALLOW_WALLET) : c.allowWallet,
|
|
478
|
-
onSuccess: async (...r) => {
|
|
479
|
-
xo(i.action, ...r), Z(e?.onSuccess) && await e.onSuccess(...r), i.open = !1;
|
|
480
|
-
},
|
|
481
|
-
onClose(...r) {
|
|
482
|
-
vo(i.action, ...r);
|
|
483
|
-
},
|
|
484
|
-
onError(r) {
|
|
485
|
-
console.error(i.action, r), Oo(i.action, r, A.current);
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
if (i.open = !0, ["login"].includes(i.action) && c.openMode === "window" && !(I.wallet || I.arcSphere))
|
|
489
|
-
try {
|
|
490
|
-
const r = {
|
|
491
|
-
...g,
|
|
492
|
-
baseUrl: window.location.origin
|
|
493
|
-
};
|
|
494
|
-
ot(c.prefix) || (r.prefix = H(window.location.origin, n.serviceHost, c.prefix)), r.extraParams?.provider || (r.extraParams.provider = i?.user?.provider || "wallet"), await y.openPopup(r, { locale: P });
|
|
495
|
-
} catch (r) {
|
|
496
|
-
r instanceof Rt && j(), r.message === "Timeout" ? ae.error(je[P] || je.en) : console.error(r);
|
|
497
|
-
}
|
|
498
|
-
else
|
|
499
|
-
y.open(g);
|
|
500
|
-
}, Pe = f(async () => {
|
|
501
|
-
const { params: e, url: o } = await ve();
|
|
502
|
-
if (e) {
|
|
503
|
-
const { switchBehavior: t, forceConnected: s, sourceAppPid: l, showClose: p } = e;
|
|
504
|
-
s === i.user.did ? window.history.replaceState(null, "trim", o) : t === "required" ? ne(() => {
|
|
505
|
-
}, {
|
|
506
|
-
openMode: "redirect",
|
|
507
|
-
redirect: o,
|
|
508
|
-
sourceAppPid: l,
|
|
509
|
-
forceConnected: s
|
|
510
|
-
}) : t === "disabled" ? window.history.replaceState(null, "trim", o) : io.open({
|
|
511
|
-
title: B.switchAccountDialog[P].title,
|
|
512
|
-
content: /* @__PURE__ */ K(Vo, { children: [
|
|
513
|
-
/* @__PURE__ */ m(Jo, { variant: "body1", sx: { textAlign: "center", mb: 2 }, children: B.switchAccountDialog[P].description }),
|
|
514
|
-
/* @__PURE__ */ K($, { sx: { display: "flex", alignItems: "center", color: "grey.A700" }, children: [
|
|
515
|
-
/* @__PURE__ */ K(
|
|
516
|
-
$,
|
|
517
|
-
{
|
|
518
|
-
sx: {
|
|
519
|
-
display: "flex",
|
|
520
|
-
flexDirection: "column",
|
|
521
|
-
alignItems: "center",
|
|
522
|
-
gap: 1.5,
|
|
523
|
-
lineHeight: 1
|
|
524
|
-
},
|
|
525
|
-
children: [
|
|
526
|
-
/* @__PURE__ */ m(Ee, { did: i.user.did, shape: "circle", variant: "circle", size: 80 }),
|
|
527
|
-
/* @__PURE__ */ m(_e, { did: i.user.did, showAvatar: !1, compact: !0, responsive: !1 }),
|
|
528
|
-
B.switchAccountDialog[P].currentAccount
|
|
529
|
-
]
|
|
530
|
-
}
|
|
531
|
-
),
|
|
532
|
-
/* @__PURE__ */ m($, { sx: { display: "flex", justifyContent: "center", px: 2 }, children: /* @__PURE__ */ m(
|
|
533
|
-
$,
|
|
534
|
-
{
|
|
535
|
-
component: st,
|
|
536
|
-
icon: ct,
|
|
537
|
-
sx: {
|
|
538
|
-
fontSize: 24,
|
|
539
|
-
color: to.grey[400],
|
|
540
|
-
animation: "right 2.5s linear infinite",
|
|
541
|
-
"@keyframes right": {
|
|
542
|
-
"0%": {
|
|
543
|
-
transform: "translateX(-3px)",
|
|
544
|
-
opacity: 0
|
|
545
|
-
},
|
|
546
|
-
"60%": {
|
|
547
|
-
transform: "translateX(3px)",
|
|
548
|
-
opacity: 1
|
|
549
|
-
},
|
|
550
|
-
"100%": {
|
|
551
|
-
transform: "translateX(0px)",
|
|
552
|
-
opacity: 0
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
) }),
|
|
558
|
-
/* @__PURE__ */ K(
|
|
559
|
-
$,
|
|
560
|
-
{
|
|
561
|
-
sx: {
|
|
562
|
-
display: "flex",
|
|
563
|
-
flexDirection: "column",
|
|
564
|
-
alignItems: "center",
|
|
565
|
-
gap: 1.5,
|
|
566
|
-
lineHeight: 1,
|
|
567
|
-
fontWeight: 500
|
|
568
|
-
},
|
|
569
|
-
children: [
|
|
570
|
-
/* @__PURE__ */ m(Ee, { did: s, shape: "circle", variant: "circle", size: 80 }),
|
|
571
|
-
/* @__PURE__ */ m(_e, { did: s, showAvatar: !1, compact: !0, responsive: !1 }),
|
|
572
|
-
B.switchAccountDialog[P].nextAccount
|
|
573
|
-
]
|
|
574
|
-
}
|
|
575
|
-
)
|
|
576
|
-
] })
|
|
577
|
-
] }),
|
|
578
|
-
showCloseButton: p,
|
|
579
|
-
showCancelButton: !1,
|
|
580
|
-
confirmButtonText: B.switchAccountDialog[P].confirm,
|
|
581
|
-
async onConfirm(g) {
|
|
582
|
-
const w = (await Se()).find((T) => T.userDid === s);
|
|
583
|
-
if (w) {
|
|
584
|
-
re(w).then((T) => {
|
|
585
|
-
ee(
|
|
586
|
-
{
|
|
587
|
-
connected_did: w.user.did,
|
|
588
|
-
connected_pk: w.user.pk,
|
|
589
|
-
connected_wallet_os: w.extra.walletOS,
|
|
590
|
-
connected_app: oe()
|
|
591
|
-
},
|
|
592
|
-
!0
|
|
593
|
-
), x({ ...T, encrypted: !1 }), C({ showProgress: !0 }).then(async () => {
|
|
594
|
-
await E(200), d.emit(a.LOGIN, T, _, A.current), O(A.current), await W();
|
|
595
|
-
}).catch((Ce) => {
|
|
596
|
-
throw d.emit(a.LOGIN_FAILED, Ce), Ce;
|
|
597
|
-
});
|
|
598
|
-
}), g();
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
ne(
|
|
602
|
-
() => {
|
|
603
|
-
g(), window.location.replace(o);
|
|
604
|
-
},
|
|
605
|
-
{ sourceAppPid: l, forceConnected: s, enableSwitchApp: !1 },
|
|
606
|
-
{ showQuickConnect: !0 }
|
|
607
|
-
);
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
}), Uo = f(async (e, o) => {
|
|
612
|
-
const t = Object.assign(
|
|
613
|
-
{
|
|
614
|
-
login: !0,
|
|
615
|
-
bindWallet: !0,
|
|
616
|
-
bindDidSpaces: !1
|
|
617
|
-
},
|
|
618
|
-
o?.requirements
|
|
619
|
-
), s = o?.openMode || "popup";
|
|
620
|
-
t.login && await N(), t.bindWallet && await new Promise((l) => {
|
|
621
|
-
ge(() => {
|
|
622
|
-
l();
|
|
623
|
-
});
|
|
624
|
-
}), t.bindDidSpaces && (await Fe(i?.user) || await new Promise((l) => {
|
|
625
|
-
t.bindDidSpaces === "full" ? W({
|
|
626
|
-
onSuccess() {
|
|
627
|
-
l();
|
|
628
|
-
}
|
|
629
|
-
}) : t.bindDidSpaces === "read" && me({
|
|
630
|
-
onSuccess() {
|
|
631
|
-
l();
|
|
632
|
-
}
|
|
633
|
-
});
|
|
634
|
-
})), s === "window" ? y.openPopup(e, o) : s === "popup" && y.open(e);
|
|
635
|
-
});
|
|
636
|
-
le(() => {
|
|
637
|
-
const e = Number(i.unReadCount || 0);
|
|
638
|
-
fe(e);
|
|
639
|
-
}, [i.unReadCount]);
|
|
640
|
-
const Mo = f(() => {
|
|
641
|
-
U.get("magicToken") && U.delete("magicToken"), U.toString() && window.history.replaceState({}, "", `${window.location.pathname}?${U.toString()}`);
|
|
642
|
-
}), Ae = f((e) => new Promise((o, t) => {
|
|
643
|
-
y.open({
|
|
644
|
-
action: "login",
|
|
645
|
-
locale: P,
|
|
646
|
-
prefix: c.prefix,
|
|
647
|
-
useSocket: !1,
|
|
648
|
-
messages: {
|
|
649
|
-
title: P === "zh" ? "验证 MagicLink Token" : "Verify MagicLink Token"
|
|
650
|
-
},
|
|
651
|
-
magicToken: e,
|
|
652
|
-
onSuccess(...s) {
|
|
653
|
-
V(...s), Mo(), o();
|
|
654
|
-
},
|
|
655
|
-
onError(s) {
|
|
656
|
-
d.emit(a.LOGIN_FAILED, s), t(s);
|
|
657
|
-
}
|
|
658
|
-
});
|
|
659
|
-
})), Ho = {
|
|
660
|
-
...i,
|
|
661
|
-
loading: c.autoConnect && !i.user || i.loading,
|
|
662
|
-
openDidConnect: Uo,
|
|
663
|
-
login: ie,
|
|
664
|
-
logout: he,
|
|
665
|
-
switchDid: ne,
|
|
666
|
-
autoSwitchDid: Pe,
|
|
667
|
-
refreshProfile: bo,
|
|
668
|
-
switchProfile: Co,
|
|
669
|
-
switchPassport: To,
|
|
670
|
-
connectToDidSpaceForImport: me,
|
|
671
|
-
connectToDidSpaceForFullAccess: W,
|
|
672
|
-
bindWallet: ge,
|
|
673
|
-
refresh: C,
|
|
674
|
-
updateConnectedInfo: ee,
|
|
675
|
-
// federated relates
|
|
676
|
-
federatedMaster: Ro,
|
|
677
|
-
// oauth relates
|
|
678
|
-
useOAuth: Tt,
|
|
679
|
-
OAuthProvider: Ne,
|
|
680
|
-
OAuthConsumer: Ct,
|
|
681
|
-
OAuthContext: bt,
|
|
682
|
-
// passkey relates
|
|
683
|
-
usePasskey: It,
|
|
684
|
-
PasskeyProvider: We,
|
|
685
|
-
PasskeyConsumer: yt,
|
|
686
|
-
PasskeyContext: kt,
|
|
687
|
-
// user related
|
|
688
|
-
useDid: Lt,
|
|
689
|
-
WrapDid: _t,
|
|
690
|
-
getUserSessions: Se,
|
|
691
|
-
async loginUserSession(e) {
|
|
692
|
-
try {
|
|
693
|
-
const o = await re(e);
|
|
694
|
-
ee(
|
|
695
|
-
{
|
|
696
|
-
connected_did: e.user.did,
|
|
697
|
-
connected_pk: e.user.pk,
|
|
698
|
-
connected_wallet_os: e.extra.walletOS,
|
|
699
|
-
connected_app: oe()
|
|
700
|
-
},
|
|
701
|
-
!0
|
|
702
|
-
), x({ ...o, encrypted: !1 }), await C({ showProgress: !0 }), await E(200), d.emit(a.LOGIN, o, _, A.current), O(A.current), await W();
|
|
703
|
-
} catch (o) {
|
|
704
|
-
throw d.emit(a.LOGIN_FAILED, o), o;
|
|
705
|
-
}
|
|
706
|
-
},
|
|
707
|
-
unReadCount: eo,
|
|
708
|
-
setUnReadCount: fe,
|
|
709
|
-
verifyMagicToken: Ae,
|
|
710
|
-
// 二次认证相关方法
|
|
711
|
-
withSecondaryAuth: mo
|
|
712
|
-
}, A = De(Ho), Go = {
|
|
713
|
-
api: lo,
|
|
714
|
-
events: d,
|
|
715
|
-
storage: Y,
|
|
716
|
-
connectApi: y,
|
|
717
|
-
session: A.current
|
|
718
|
-
}, ce = {
|
|
719
|
-
login: V,
|
|
720
|
-
"switch-profile": Eo,
|
|
721
|
-
"switch-passport": se,
|
|
722
|
-
"switch-passport-failed": Io,
|
|
723
|
-
"bind-wallet": Do,
|
|
724
|
-
"bind-wallet-failed": _o,
|
|
725
|
-
"login-failed": Lo
|
|
726
|
-
};
|
|
727
|
-
le(() => {
|
|
728
|
-
if (i.initialized) {
|
|
729
|
-
const e = !no;
|
|
730
|
-
if (d.emit("change", { user: Te(i.user), isFirst: e }), i.user && globalThis.blocklet) {
|
|
731
|
-
const o = {
|
|
732
|
-
did: i.user.did,
|
|
733
|
-
host: window.location.host,
|
|
734
|
-
appPid: globalThis.blocklet.appPid,
|
|
735
|
-
visitorId: q(),
|
|
736
|
-
sourceAppPid: i.user.sourceAppPid,
|
|
737
|
-
fullName: i.user.fullName
|
|
738
|
-
};
|
|
739
|
-
h("bridge callArc: onChange", {
|
|
740
|
-
isFirst: e,
|
|
741
|
-
user: o
|
|
742
|
-
}), b.callArc("onChange", {
|
|
743
|
-
...o,
|
|
744
|
-
user: o,
|
|
745
|
-
isFirst: e
|
|
746
|
-
});
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}, [i.user, i.initialized, d]), le(() => {
|
|
750
|
-
i.initialized && i.user && Pe();
|
|
751
|
-
}, [i.initialized]), nt(async () => {
|
|
752
|
-
const e = (r) => {
|
|
753
|
-
ht(r.encrypted) && (r.encrypted = !1), window.temporaryDIDConnectOnSuccess instanceof Function ? (h("bridgeOnLogin: temporaryDIDConnectOnSuccess", { result: r }), window.temporaryDIDConnectOnSuccess(r, (w) => w)) : (h("bridgeOnLogin: onLogin", { result: r }), V(r));
|
|
754
|
-
};
|
|
755
|
-
if (b.registerBlocklet("callLoginOAuth", (r) => {
|
|
756
|
-
h("bridge registerBlocklet: callLoginOAuth", r), y.loginOAuth({
|
|
757
|
-
...r,
|
|
758
|
-
onLogin: e
|
|
759
|
-
});
|
|
760
|
-
}), b.registerBlocklet("logout", he), b.registerBlocklet("login", (r) => {
|
|
761
|
-
h("bridge registerBlocklet: login", r), e(r);
|
|
762
|
-
}), tt(), !q()) {
|
|
763
|
-
if (I.arcSphere) {
|
|
764
|
-
h("bridge callArc: getVisitorId");
|
|
765
|
-
const r = await b.callArc("getVisitorId");
|
|
766
|
-
h("bridge callArc: getVisitorId result", { walletVisitorId: r }), ke(r);
|
|
767
|
-
} else if (I.wallet) {
|
|
768
|
-
const r = await Ut();
|
|
769
|
-
ke(r);
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
const t = qo.get("connected_app"), s = oe();
|
|
773
|
-
if (n.autoDisconnect && t && s && t !== s) {
|
|
774
|
-
xe("[clearSession] createSessionContext -> SessionProvider -> useMount: autoDisconnect", {
|
|
775
|
-
autoDisconnect: n.autoDisconnect,
|
|
776
|
-
connectedApp: t,
|
|
777
|
-
actualApp: s
|
|
778
|
-
}), ue(), i.initialized = !0, c.autoConnect ? F() : j();
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
const l = po();
|
|
782
|
-
if (window?.self === window?.parent) {
|
|
783
|
-
let r = "web";
|
|
784
|
-
if (I.mobile.apple.device ? r = "ios" : I.mobile.android.device && (r = "android"), I.wallet && Mt({ version: I.walletVersion, platform: r }) && !l)
|
|
785
|
-
try {
|
|
786
|
-
i.loading = !0;
|
|
787
|
-
const w = await Ht();
|
|
788
|
-
if (w) {
|
|
789
|
-
await V({
|
|
790
|
-
sessionToken: w.sessionToken,
|
|
791
|
-
refreshToken: w.refreshToken,
|
|
792
|
-
csrfToken: w.csrfToken,
|
|
793
|
-
visitorId: w.visitorId,
|
|
794
|
-
encrypted: !1
|
|
795
|
-
}), i.initialized = !0;
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
} catch (w) {
|
|
799
|
-
throw d.emit(a.LOGIN_FAILED, w), w;
|
|
800
|
-
} finally {
|
|
801
|
-
i.loading = !1;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
const p = U.get("magicToken");
|
|
805
|
-
if (p)
|
|
806
|
-
try {
|
|
807
|
-
i.initialized = !0, await Ae(p);
|
|
808
|
-
} catch (r) {
|
|
809
|
-
console.error("verifyMagicToken failed", r);
|
|
810
|
-
}
|
|
811
|
-
if (l) {
|
|
812
|
-
await C({ showProgress: !0 }), i.initialized = !0, i.user && await W();
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
if (typeof window < "u") {
|
|
816
|
-
const r = new URL(window.location.href), w = r.searchParams.get("loginToken");
|
|
817
|
-
if (w) {
|
|
818
|
-
x({ loginToken: w, encrypted: !1 }), r.searchParams.delete("loginToken"), window.history.replaceState({}, window.title, r.href);
|
|
819
|
-
return;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
if (fo()) {
|
|
823
|
-
await co(!0), i.initialized = !0;
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
if (i.initialized = !0, c.autoConnect ? F() : j(), I.arcSphere && ![
|
|
827
|
-
// 不应该唤起自动登录的路由
|
|
828
|
-
H(G, "login"),
|
|
829
|
-
H(G, "connect"),
|
|
830
|
-
H(G, "lost-passport")
|
|
831
|
-
].includes(window.location.pathname) && !l)
|
|
832
|
-
try {
|
|
833
|
-
h("bridge callArc: autoLogin");
|
|
834
|
-
const r = await b.callArc("autoLogin");
|
|
835
|
-
h("bridgecallArc: autoLogin result", r), r && await V({
|
|
836
|
-
sessionToken: r.sessionToken,
|
|
837
|
-
refreshToken: r.refreshToken,
|
|
838
|
-
csrfToken: r.csrfToken,
|
|
839
|
-
visitorId: r.visitorId,
|
|
840
|
-
encrypted: !1
|
|
841
|
-
});
|
|
842
|
-
} catch (r) {
|
|
843
|
-
d.emit(a.LOGIN_FAILED, r), Oe.error("Failed to autoLogin ArcSphere", r);
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
const zo = U.has("popup");
|
|
847
|
-
if (Fo() && !i.initialized)
|
|
848
|
-
return /* @__PURE__ */ m(it, { children: zo ? null : /* @__PURE__ */ m(Zo, {}) });
|
|
849
|
-
const be = {
|
|
850
|
-
locale: P,
|
|
851
|
-
onSwitchPassport: ({ sessionToken: e, refreshToken: o, csrfToken: t }) => se({ sessionToken: e, refreshToken: o, csrfToken: t, encrypted: !1 }),
|
|
852
|
-
onUnbindOAuth: () => C(),
|
|
853
|
-
onBindOAuth: () => C(),
|
|
854
|
-
onAddPasskey: () => C(),
|
|
855
|
-
onRemovePasskey: () => C(),
|
|
856
|
-
session: A.current
|
|
857
|
-
};
|
|
858
|
-
return /* @__PURE__ */ m($t, { value: Go, children: /* @__PURE__ */ m(We, { ...be, children: /* @__PURE__ */ K(Ne, { ...be, children: [
|
|
859
|
-
!i.open && typeof n.children == "function" ? n.children(i) : n.children,
|
|
860
|
-
Ze,
|
|
861
|
-
ro,
|
|
862
|
-
yo,
|
|
863
|
-
k.rolling && /* @__PURE__ */ m(Re, { callback: () => ao() }),
|
|
864
|
-
/* @__PURE__ */ m(Re, { callback: so })
|
|
865
|
-
] }) }) });
|
|
866
|
-
}
|
|
867
|
-
pe.propTypes = {
|
|
868
|
-
children: S.any.isRequired,
|
|
869
|
-
serviceHost: S.string,
|
|
870
|
-
action: S.string,
|
|
871
|
-
prefix: S.string,
|
|
872
|
-
appendAuthServicePrefix: S.bool,
|
|
873
|
-
locale: S.string,
|
|
874
|
-
timeout: S.number,
|
|
875
|
-
autoConnect: S.bool,
|
|
876
|
-
// should we open connect dialog when session not found
|
|
877
|
-
autoDisconnect: S.bool,
|
|
878
|
-
// should we auto disconnect on appId mismatch
|
|
879
|
-
useSocket: S.bool,
|
|
880
|
-
// should we auto disconnect on appId mismatch
|
|
881
|
-
extraParams: S.object,
|
|
882
|
-
options: S.object,
|
|
883
|
-
webWalletUrl: S.string,
|
|
884
|
-
protectedRoutes: S.arrayOf(S.string),
|
|
885
|
-
apiOptions: S.object,
|
|
886
|
-
lazyRefreshToken: S.bool
|
|
887
|
-
};
|
|
888
|
-
function Je(L) {
|
|
889
|
-
return function(n) {
|
|
890
|
-
return /* @__PURE__ */ m(ye, { children: /* @__PURE__ */ m(Ve, { children: (y) => /* @__PURE__ */ m(L, { ...n, ...y }) }) });
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
|
-
return {
|
|
894
|
-
SessionProvider: (L) => /* @__PURE__ */ m(ye, { children: /* @__PURE__ */ m(Vt, { children: /* @__PURE__ */ m(pe, { ...L }) }) }),
|
|
895
|
-
SessionConsumer: Ve,
|
|
896
|
-
SessionContext: qe,
|
|
897
|
-
withSession: Je
|
|
898
|
-
};
|
|
899
|
-
}
|
|
900
|
-
function Qi({ storageEngine: X = "cookie" } = {}) {
|
|
901
|
-
const Q = Xe, te = Qe;
|
|
902
|
-
let k = null;
|
|
903
|
-
if (typeof window < "u" && (k = (globalThis.blocklet || {}).componentId), X === "cookie") {
|
|
904
|
-
let D = "/", O = 1;
|
|
905
|
-
if (typeof window < "u") {
|
|
906
|
-
const Y = window.env || {}, z = window.blocklet || {};
|
|
907
|
-
D = Y.groupPathPrefix || z.groupPrefix || z.prefix || "", D = D.replace(/\/+$/, ""), D = D || "/", z.serverVersion && (O = Pt(window.blocklet?.settings?.session?.cacheTtl, 1 / 24));
|
|
908
|
-
}
|
|
909
|
-
return $e(
|
|
910
|
-
Q,
|
|
911
|
-
"cookie",
|
|
912
|
-
{
|
|
913
|
-
path: D,
|
|
914
|
-
returnDomain: !1,
|
|
915
|
-
expireInDays: O
|
|
916
|
-
},
|
|
917
|
-
{
|
|
918
|
-
appendAuthServicePrefix: !0,
|
|
919
|
-
extraParams: { componentId: k },
|
|
920
|
-
refreshTokenStorageKey: te
|
|
921
|
-
}
|
|
922
|
-
);
|
|
923
|
-
}
|
|
924
|
-
if (X === "localStorage")
|
|
925
|
-
return $e(Q, "ls", {}, !0);
|
|
926
|
-
throw new Error("storageEngine must be cookie or localStorage");
|
|
927
|
-
}
|
|
928
|
-
export {
|
|
929
|
-
a as EVENTS,
|
|
930
|
-
qe as SessionContext,
|
|
931
|
-
Mt as checkEnableAutoLogin,
|
|
932
|
-
Qi as createAuthServiceSessionContext,
|
|
933
|
-
$e as createSessionContext,
|
|
934
|
-
$e as default,
|
|
935
|
-
Fe as didSpacesIsRequired,
|
|
936
|
-
Ut as getMobileVisitorId,
|
|
937
|
-
Ht as login,
|
|
938
|
-
Zi as loginFederatedMaster,
|
|
939
|
-
er as mountFederatedIframe,
|
|
940
|
-
B as translations
|
|
941
|
-
};
|