@arcblock/did-connect-react 3.1.0

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.
Files changed (183) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +134 -0
  3. package/lib/Address/index.js +4 -0
  4. package/lib/Avatar/index.js +4 -0
  5. package/lib/Button/index.js +17 -0
  6. package/lib/Connect/assets/locale.js +143 -0
  7. package/lib/Connect/assets/login-bg.png +0 -0
  8. package/lib/Connect/assets/login-slogan.js +9 -0
  9. package/lib/Connect/components/action-button.js +26 -0
  10. package/lib/Connect/components/app-tips.js +132 -0
  11. package/lib/Connect/components/auto-height.js +31 -0
  12. package/lib/Connect/components/back-button.js +24 -0
  13. package/lib/Connect/components/connect-status.js +263 -0
  14. package/lib/Connect/components/did-connect-title.js +126 -0
  15. package/lib/Connect/components/download-tips.js +52 -0
  16. package/lib/Connect/components/loading.js +26 -0
  17. package/lib/Connect/components/login-item/connect-choose-list.js +249 -0
  18. package/lib/Connect/components/login-item/login-method-item.js +129 -0
  19. package/lib/Connect/components/login-item/mobile-login-item.js +114 -0
  20. package/lib/Connect/components/login-item/passkey-login-item.js +44 -0
  21. package/lib/Connect/components/login-item/web-login-item.js +97 -0
  22. package/lib/Connect/components/mask-overlay.js +34 -0
  23. package/lib/Connect/components/refresh-overlay.js +57 -0
  24. package/lib/Connect/components/switch-app.js +70 -0
  25. package/lib/Connect/contexts/state.js +142 -0
  26. package/lib/Connect/fullpage.js +5 -0
  27. package/lib/Connect/hooks/auth-url.js +23 -0
  28. package/lib/Connect/hooks/method-list.js +46 -0
  29. package/lib/Connect/hooks/page-show.js +17 -0
  30. package/lib/Connect/hooks/security.js +27 -0
  31. package/lib/Connect/hooks/token.js +305 -0
  32. package/lib/Connect/hooks/use-apps.js +19 -0
  33. package/lib/Connect/hooks/use-quick-connect.js +97 -0
  34. package/lib/Connect/index.js +498 -0
  35. package/lib/Connect/landing-page.js +5 -0
  36. package/lib/Connect/plugins/email/index.js +62 -0
  37. package/lib/Connect/plugins/email/list-item.js +28 -0
  38. package/lib/Connect/plugins/email/placeholder.js +283 -0
  39. package/lib/Connect/plugins/index.js +4 -0
  40. package/lib/Connect/use-connect.js +164 -0
  41. package/lib/Connect/with-blocklet.js +15 -0
  42. package/lib/Connect/with-bridge-call.js +108 -0
  43. package/lib/Federated/context.js +61 -0
  44. package/lib/Federated/index.js +7 -0
  45. package/lib/Logo/index.js +4 -0
  46. package/lib/OAuth/context.js +234 -0
  47. package/lib/OAuth/guest.svg.js +5 -0
  48. package/lib/OAuth/index.js +7 -0
  49. package/lib/OAuth/passport-switcher.js +114 -0
  50. package/lib/Passkey/actions.js +165 -0
  51. package/lib/Passkey/constants.js +4 -0
  52. package/lib/Passkey/context.js +266 -0
  53. package/lib/Passkey/dialog.js +277 -0
  54. package/lib/Passkey/icon.js +13 -0
  55. package/lib/Passkey/index.js +9 -0
  56. package/lib/Service/index.js +62 -0
  57. package/lib/Session/assets/did-spaces-guide-cover.svg.js +135 -0
  58. package/lib/Session/assets/did-spaces-guide-icon.svg.js +9 -0
  59. package/lib/Session/context.js +5 -0
  60. package/lib/Session/did-spaces-guide.js +136 -0
  61. package/lib/Session/hooks/use-federated.js +64 -0
  62. package/lib/Session/hooks/use-mobile.js +8 -0
  63. package/lib/Session/hooks/use-protected-routes.js +11 -0
  64. package/lib/Session/hooks/use-session-token.js +169 -0
  65. package/lib/Session/hooks/use-verify.js +45 -0
  66. package/lib/Session/index.js +896 -0
  67. package/lib/Session/libs/constants.js +15 -0
  68. package/lib/Session/libs/did-spaces.js +10 -0
  69. package/lib/Session/libs/federated.js +42 -0
  70. package/lib/Session/libs/index.js +15 -0
  71. package/lib/Session/libs/locales.js +161 -0
  72. package/lib/Session/libs/login-mobile.js +55 -0
  73. package/lib/Session/window-focus-aware.js +17 -0
  74. package/lib/SessionManager/index.js +4 -0
  75. package/lib/Storage/engine/cookie.js +21 -0
  76. package/lib/Storage/engine/local-storage.js +36 -0
  77. package/lib/Storage/index.js +23 -0
  78. package/lib/User/index.js +6 -0
  79. package/lib/User/use-did.js +59 -0
  80. package/lib/User/wrap-did.js +13 -0
  81. package/lib/WebWalletSWKeeper/index.js +5 -0
  82. package/lib/constant.js +22 -0
  83. package/lib/error.js +8 -0
  84. package/lib/hooks/use-locale.js +7 -0
  85. package/lib/index.js +33 -0
  86. package/lib/locales/en.js +17 -0
  87. package/lib/locales/index.js +10 -0
  88. package/lib/locales/zh.js +17 -0
  89. package/lib/package.json.js +7 -0
  90. package/lib/types.d.ts +355 -0
  91. package/lib/utils.js +214 -0
  92. package/package.json +84 -0
  93. package/src/Address/index.jsx +2 -0
  94. package/src/Avatar/index.jsx +2 -0
  95. package/src/Button/Button.stories.jsx +7 -0
  96. package/src/Button/index.jsx +21 -0
  97. package/src/Connect/Connect.stories.jsx +34 -0
  98. package/src/Connect/assets/locale.js +145 -0
  99. package/src/Connect/assets/login-bg.png +0 -0
  100. package/src/Connect/assets/login-slogan.js +7 -0
  101. package/src/Connect/components/action-button.jsx +22 -0
  102. package/src/Connect/components/app-tips.jsx +156 -0
  103. package/src/Connect/components/auto-height.jsx +38 -0
  104. package/src/Connect/components/back-button.jsx +23 -0
  105. package/src/Connect/components/connect-status.jsx +259 -0
  106. package/src/Connect/components/did-connect-title.jsx +106 -0
  107. package/src/Connect/components/download-tips.jsx +55 -0
  108. package/src/Connect/components/loading.jsx +25 -0
  109. package/src/Connect/components/login-item/connect-choose-list.jsx +304 -0
  110. package/src/Connect/components/login-item/login-method-item.jsx +118 -0
  111. package/src/Connect/components/login-item/mobile-login-item.jsx +179 -0
  112. package/src/Connect/components/login-item/passkey-login-item.jsx +52 -0
  113. package/src/Connect/components/login-item/web-login-item.jsx +149 -0
  114. package/src/Connect/components/mask-overlay.jsx +32 -0
  115. package/src/Connect/components/refresh-overlay.jsx +52 -0
  116. package/src/Connect/components/switch-app.jsx +69 -0
  117. package/src/Connect/contexts/state.jsx +219 -0
  118. package/src/Connect/fullpage.jsx +3 -0
  119. package/src/Connect/hooks/auth-url.js +31 -0
  120. package/src/Connect/hooks/method-list.js +121 -0
  121. package/src/Connect/hooks/page-show.js +24 -0
  122. package/src/Connect/hooks/security.js +40 -0
  123. package/src/Connect/hooks/token.js +639 -0
  124. package/src/Connect/hooks/use-apps.js +69 -0
  125. package/src/Connect/hooks/use-quick-connect.js +130 -0
  126. package/src/Connect/index.jsx +600 -0
  127. package/src/Connect/landing-page.jsx +3 -0
  128. package/src/Connect/plugins/email/index.jsx +82 -0
  129. package/src/Connect/plugins/email/list-item.jsx +31 -0
  130. package/src/Connect/plugins/email/placeholder.jsx +365 -0
  131. package/src/Connect/plugins/index.js +2 -0
  132. package/src/Connect/use-connect.jsx +321 -0
  133. package/src/Connect/with-blocklet.jsx +26 -0
  134. package/src/Connect/with-bridge-call.jsx +138 -0
  135. package/src/Federated/context.jsx +93 -0
  136. package/src/Federated/index.jsx +1 -0
  137. package/src/Logo/index.jsx +2 -0
  138. package/src/OAuth/context.jsx +346 -0
  139. package/src/OAuth/guest.svg +20 -0
  140. package/src/OAuth/index.jsx +1 -0
  141. package/src/OAuth/passport-switcher.jsx +133 -0
  142. package/src/Passkey/actions.jsx +212 -0
  143. package/src/Passkey/constants.js +2 -0
  144. package/src/Passkey/context.jsx +381 -0
  145. package/src/Passkey/dialog.jsx +391 -0
  146. package/src/Passkey/icon.jsx +10 -0
  147. package/src/Passkey/index.jsx +2 -0
  148. package/src/Service/index.jsx +96 -0
  149. package/src/Session/assets/did-spaces-guide-cover.svg +128 -0
  150. package/src/Session/assets/did-spaces-guide-icon.svg +7 -0
  151. package/src/Session/context.jsx +7 -0
  152. package/src/Session/did-spaces-guide.jsx +173 -0
  153. package/src/Session/hooks/use-federated.js +88 -0
  154. package/src/Session/hooks/use-mobile.jsx +6 -0
  155. package/src/Session/hooks/use-protected-routes.js +16 -0
  156. package/src/Session/hooks/use-session-token.js +365 -0
  157. package/src/Session/hooks/use-verify.jsx +76 -0
  158. package/src/Session/index.jsx +1687 -0
  159. package/src/Session/libs/constants.js +14 -0
  160. package/src/Session/libs/did-spaces.js +38 -0
  161. package/src/Session/libs/federated.js +79 -0
  162. package/src/Session/libs/index.js +5 -0
  163. package/src/Session/libs/locales.js +160 -0
  164. package/src/Session/libs/login-mobile.js +80 -0
  165. package/src/Session/window-focus-aware.jsx +28 -0
  166. package/src/SessionManager/index.jsx +2 -0
  167. package/src/Storage/engine/cookie.js +23 -0
  168. package/src/Storage/engine/local-storage.js +55 -0
  169. package/src/Storage/index.js +25 -0
  170. package/src/User/index.js +4 -0
  171. package/src/User/use-did.js +80 -0
  172. package/src/User/wrap-did.jsx +18 -0
  173. package/src/WebWalletSWKeeper/index.jsx +3 -0
  174. package/src/constant.js +26 -0
  175. package/src/error.js +6 -0
  176. package/src/hooks/use-locale.jsx +6 -0
  177. package/src/index.js +43 -0
  178. package/src/locales/en.jsx +15 -0
  179. package/src/locales/index.jsx +13 -0
  180. package/src/locales/zh.jsx +15 -0
  181. package/src/types.d.ts +355 -0
  182. package/src/utils.js +395 -0
  183. package/vite.config.mjs +29 -0
@@ -0,0 +1,283 @@
1
+ import { jsxs as l, Fragment as s, jsx as a } from "react/jsx-runtime";
2
+ import j from "@arcblock/ux/lib/LoadingMask";
3
+ import { Typography as T, TextField as B, Box as p, CircularProgress as R } from "@mui/material";
4
+ import { useMemoizedFn as d, useCreation as F, useReactive as D, useInterval as H } from "ahooks";
5
+ import c from "prop-types";
6
+ import { joinURL as K, withQuery as k } from "ufo";
7
+ import O from "@arcblock/ux/lib/Toast";
8
+ import q from "@arcblock/ux/lib/VerificationCode";
9
+ import { useEffect as N } from "react";
10
+ import v from "lodash/noop";
11
+ import U from "@arcblock/ux/lib/DIDConnect/provider-icon";
12
+ import V from "../../components/back-button.js";
13
+ import S from "../../components/action-button.js";
14
+ import { useStateContext as W } from "../../contexts/state.js";
15
+ import { BLOCKLET_SERVICE_PATH_PREFIX as G, VERIFY_CODE_LENGTH as Q, CHECK_STATUS_INTERVAL as X } from "../../../constant.js";
16
+ import { createAxios as Y, debug as y } from "../../../utils.js";
17
+ function $({
18
+ fallback: A = null,
19
+ state: o,
20
+ forceUpdate: t = v,
21
+ onSuccess: h = v,
22
+ t: L = v
23
+ }) {
24
+ const { setSelectedPlugin: w, locale: m, connectState: u, action: f, extraParams: P } = W(), n = d((r, i = {}) => L(r, i, m)), g = F(() => Y({
25
+ baseURL: K(o.baseUrl, G, "/api/user")
26
+ }), [o.baseUrl]), e = D({
27
+ email: "",
28
+ code: "",
29
+ codeId: "",
30
+ defaultVerifyMode: "magicLink",
31
+ verifyMode: "magicLink",
32
+ // magicLink, code
33
+ loadingSendCode: !1,
34
+ loadingVerifyCode: !1,
35
+ error: ""
36
+ }), b = d(() => {
37
+ e.email = "", e.code = "", e.codeId = "", e.verifyMode = e.defaultVerifyMode, e.loadingSendCode = !1, e.loadingVerifyCode = !1, e.error = "";
38
+ }), E = d(async () => {
39
+ if (!e.email || !e.email.trim()) {
40
+ e.error = n("emailRequired");
41
+ return;
42
+ }
43
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.email)) {
44
+ e.error = n("emailInvalid");
45
+ return;
46
+ }
47
+ e.error = "";
48
+ try {
49
+ e.loadingSendCode = !0;
50
+ let i = !1;
51
+ ["login"].includes(f) && (u.sourceAppPid || (i = !0));
52
+ const { data: x } = await g.post(k("/email/sendCode", { locale: m }), {
53
+ email: e.email,
54
+ sourceAppPid: u.sourceAppPid,
55
+ useMagicLink: i
56
+ });
57
+ e.verifyMode = e.defaultVerifyMode, e.codeId = x.id, o.status = "sending";
58
+ } catch (i) {
59
+ const x = i?.response?.data?.error || i?.message;
60
+ o.status = "error", o.error = x;
61
+ } finally {
62
+ e.loadingSendCode = !1, t();
63
+ }
64
+ }), I = d(async () => {
65
+ if (e.code.length === Q)
66
+ try {
67
+ e.loadingVerifyCode = !0;
68
+ const { data: r } = await g.post(k("/email/login", { locale: m }), {
69
+ ...P,
70
+ action: f,
71
+ code: e.code,
72
+ sourceAppPid: u.sourceAppPid
73
+ });
74
+ y("Email login succeed (use code)", { loginResult: r }), await h(
75
+ {
76
+ ...r,
77
+ encrypted: !1
78
+ },
79
+ (i) => i
80
+ ), o.status = "succeed";
81
+ } catch (r) {
82
+ const i = r?.response?.data || r?.message;
83
+ O.error(i), y("Email login failed (use code)", { error: r });
84
+ } finally {
85
+ e.loadingVerifyCode = !1, t();
86
+ }
87
+ }), _ = d(async () => {
88
+ o.status = "verifying", t();
89
+ try {
90
+ const { data: r } = await g.post(k("/email/login", { locale: m }), {
91
+ ...P,
92
+ action: f,
93
+ magicToken: o.magicToken
94
+ });
95
+ y("Email login succeed (use magic link)", { loginResult: r }), await h(
96
+ {
97
+ ...r,
98
+ encrypted: !1
99
+ },
100
+ (i) => i
101
+ ), o.status = "succeed";
102
+ } catch (r) {
103
+ const i = r?.response?.data || r?.message;
104
+ o.status = "error", o.error = i, y("Email login failed (use magic link)", { error: r });
105
+ }
106
+ t();
107
+ }), M = e.verifyMode === "magicLink" && o.status === "sending" && // 如果正在校验验证码,则不轮询状态
108
+ !e.loadingVerifyCode && e.codeId, z = d(async () => {
109
+ if (M) {
110
+ try {
111
+ const { data: r } = await g.get("/email/status", {
112
+ params: {
113
+ codeId: e.codeId
114
+ }
115
+ });
116
+ r.verified && (o.status = "succeed", b(), await h({ encrypted: !1 }, (i) => i));
117
+ } catch (r) {
118
+ console.error("check status error", r);
119
+ }
120
+ t();
121
+ }
122
+ });
123
+ H(z, M ? X : void 0), N(() => {
124
+ b(), (u.sourceAppPid || !["login"].includes(f)) && (e.defaultVerifyMode = "code"), o.magicToken && _();
125
+ }, [o]);
126
+ let C = null;
127
+ if (o.status === "creating")
128
+ C = /* @__PURE__ */ l(s, { children: [
129
+ /* @__PURE__ */ a(
130
+ T,
131
+ {
132
+ variant: "body2",
133
+ sx: {
134
+ textAlign: "center",
135
+ color: "text.secondary"
136
+ },
137
+ children: n("emailPlaceholder")
138
+ }
139
+ ),
140
+ /* @__PURE__ */ a(
141
+ B,
142
+ {
143
+ name: "email",
144
+ fullWidth: !0,
145
+ type: "email",
146
+ variant: "outlined",
147
+ label: n("email"),
148
+ placeholder: n("emailPlaceholder"),
149
+ size: "small",
150
+ value: e.email,
151
+ onChange: (r) => {
152
+ e.email = r.target.value;
153
+ },
154
+ onKeyDown: (r) => {
155
+ r.key === "Enter" && E(e.email);
156
+ },
157
+ sx: {
158
+ maxWidth: 320,
159
+ "& .MuiOutlinedInput-root": {
160
+ borderRadius: 1
161
+ }
162
+ },
163
+ error: !!e.error,
164
+ helperText: e.error,
165
+ slotProps: {
166
+ htmlInput: {
167
+ sx: {
168
+ boxSizing: "content-box !important"
169
+ }
170
+ }
171
+ }
172
+ }
173
+ ),
174
+ /* @__PURE__ */ l(p, { sx: { display: "flex", gap: 1 }, children: [
175
+ /* @__PURE__ */ a(
176
+ V,
177
+ {
178
+ onClick: () => {
179
+ o.reset(), w();
180
+ }
181
+ }
182
+ ),
183
+ /* @__PURE__ */ l(
184
+ S,
185
+ {
186
+ sx: {
187
+ color: "primary.main",
188
+ borderColor: "primary.light"
189
+ },
190
+ disabled: e.loadingSendCode,
191
+ onClick: () => {
192
+ E(e.email);
193
+ },
194
+ children: [
195
+ e.loadingSendCode ? /* @__PURE__ */ a(R, { color: "inherit", size: 14, sx: { mr: 1 } }) : null,
196
+ n("sendCode")
197
+ ]
198
+ }
199
+ )
200
+ ] })
201
+ ] });
202
+ else if (o.status === "sending")
203
+ C = /* @__PURE__ */ l(s, { children: [
204
+ /* @__PURE__ */ l(p, { sx: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
205
+ /* @__PURE__ */ a(T, { variant: "body2", sx: { textAlign: "center", color: "text.secondary" }, children: e.verifyMode === "magicLink" ? /* @__PURE__ */ l(s, { children: [
206
+ n("verifyEmail"),
207
+ /* @__PURE__ */ a("br", {}),
208
+ n("orUseCodePlaceholder")
209
+ ] }) : n("codePlaceholder") }),
210
+ /* @__PURE__ */ a(s, {})
211
+ ] }),
212
+ /* @__PURE__ */ l(s, { children: [
213
+ /* @__PURE__ */ a(
214
+ q,
215
+ {
216
+ code: e.code,
217
+ onChange: (r) => {
218
+ e.code = r;
219
+ },
220
+ onComplete: () => {
221
+ I();
222
+ }
223
+ }
224
+ ),
225
+ /* @__PURE__ */ l(p, { sx: { display: "flex", gap: 1 }, children: [
226
+ /* @__PURE__ */ a(
227
+ V,
228
+ {
229
+ onClick: () => {
230
+ e.code = "", o.status = "creating", t();
231
+ }
232
+ }
233
+ ),
234
+ /* @__PURE__ */ l(
235
+ S,
236
+ {
237
+ sx: {
238
+ color: "primary.main",
239
+ borderColor: "primary.light"
240
+ },
241
+ disabled: e.loadingVerifyCode,
242
+ onClick: () => {
243
+ I();
244
+ },
245
+ children: [
246
+ e.loadingVerifyCode ? /* @__PURE__ */ a(R, { color: "inherit", size: 14, sx: { mr: 1 } }) : null,
247
+ n("confirm")
248
+ ]
249
+ }
250
+ )
251
+ ] })
252
+ ] })
253
+ ] });
254
+ else
255
+ return A;
256
+ return /* @__PURE__ */ l(
257
+ p,
258
+ {
259
+ sx: {
260
+ display: "flex",
261
+ flexDirection: "column",
262
+ alignItems: "center",
263
+ justifyContent: "center",
264
+ gap: 2,
265
+ pb: 1
266
+ },
267
+ children: [
268
+ /* @__PURE__ */ a(j, { size: 52, borderRadius: 12, children: /* @__PURE__ */ a(U, { provider: "email" }) }),
269
+ C
270
+ ]
271
+ }
272
+ );
273
+ }
274
+ $.propTypes = {
275
+ fallback: c.any,
276
+ state: c.object.isRequired,
277
+ forceUpdate: c.func,
278
+ onSuccess: c.func,
279
+ t: c.func
280
+ };
281
+ export {
282
+ $ as default
283
+ };
@@ -0,0 +1,4 @@
1
+ import { default as l } from "./email/index.js";
2
+ export {
3
+ l as useEmailPlugin
4
+ };
@@ -0,0 +1,164 @@
1
+ import { jsx as H } from "react/jsx-runtime";
2
+ import { createPortal as j } from "react-dom";
3
+ import { useCreation as R, useMemoizedFn as g, useReactive as V, useDebounce as q } from "ahooks";
4
+ import { useRef as B, use as Q, useState as v, useImperativeHandle as X } from "react";
5
+ import z from "lodash/noop";
6
+ import T from "lodash/cloneDeep";
7
+ import S from "lodash/isFunction";
8
+ import J from "lodash/isUndefined";
9
+ import { joinURL as k, withQuery as M } from "ufo";
10
+ import { getFederatedEnabled as K, getMaster as N } from "@arcblock/ux/lib/Util/federated";
11
+ import G from "p-queue";
12
+ import { useTheme as W } from "@arcblock/ux/lib/Theme";
13
+ import { getCookieOptions as Y } from "@arcblock/ux/lib/Util";
14
+ import A from "js-cookie";
15
+ import { useBrowser as Z } from "@arcblock/react-hooks";
16
+ import { SessionContext as $ } from "../Session/context.js";
17
+ import { openPopup as ee, runPopup as oe, updateConnectedInfo as ne, getAppId as te } from "../utils.js";
18
+ import { API_DID_PREFIX as re, BLOCKLET_SERVICE_PATH_PREFIX as se } from "../constant.js";
19
+ import ce from "./index.js";
20
+ const b = 2e3;
21
+ function ie({ ref: P }) {
22
+ const { api: _, session: s } = Q($), [c, I] = v({
23
+ title: "DID Connect",
24
+ scan: "Use follwing methods to complete this action",
25
+ confirm: "Confirm in your account",
26
+ success: "Success!"
27
+ }), x = W(), F = {
28
+ containerEl: null,
29
+ popup: !0,
30
+ checkFn: _?.get || z
31
+ }, C = x?.transitions?.duration?.leavingScreen || 500, e = V({
32
+ show: !1,
33
+ ...T(F)
34
+ }), o = q(e.show, {
35
+ wait: C
36
+ }), [i, O] = v({}), l = g(() => {
37
+ const n = T(F);
38
+ Object.keys(n).forEach((m) => {
39
+ e[m] = n[m];
40
+ });
41
+ }), t = g(() => {
42
+ e.show = !1, setTimeout(() => {
43
+ l();
44
+ }, C);
45
+ }), E = g((n) => {
46
+ const { containerEl: m, checkFn: a, popup: d, messages: f, ...h } = T(n);
47
+ typeof a == "function" && (e.checkFn = a), d !== void 0 && (e.popup = d), f !== void 0 && I(f), m !== void 0 && (e.containerEl = m), O(h), e.show = !0;
48
+ }), y = s.useOAuth(), p = g(async ({ provider: n, action: m, extraParams: a, onLogin: d }) => {
49
+ const f = await y.loginOAuth(
50
+ { provider: n },
51
+ {
52
+ action: m,
53
+ ...a
54
+ }
55
+ ), h = Y({ returnDomain: !1 });
56
+ A.remove("connected_did", h), A.remove("connected_pk", h), A.remove("connected_wallet_os", h), d(
57
+ {
58
+ ...f,
59
+ encrypted: !1
60
+ },
61
+ (w) => w
62
+ );
63
+ });
64
+ X(P, () => ({
65
+ open: E,
66
+ loginOAuth: p,
67
+ close: t
68
+ }), [E, t, p]);
69
+ const u = /* @__PURE__ */ H(
70
+ ce,
71
+ {
72
+ open: e.show,
73
+ popup: e.popup,
74
+ messages: c,
75
+ checkFn: e.checkFn,
76
+ ...i
77
+ }
78
+ );
79
+ return e.containerEl ? j(u, e.containerEl) : e.show || o ? u : null;
80
+ }
81
+ function xe() {
82
+ const P = B(null), _ = Z(), s = R(() => {
83
+ const o = { concurrency: 1 };
84
+ return _.arcSphere && delete o.concurrency, new G(o);
85
+ }), c = g((...o) => {
86
+ P.current?.close(...o);
87
+ }), I = g(
88
+ ({ onSuccess: o, onClose: i, onEnd: O, closeTimeout: l = b, ...t }, ...E) => {
89
+ const y = () => new Promise((p) => {
90
+ typeof o == "function" ? t.onSuccess = (...u) => {
91
+ o(...u), setTimeout(() => {
92
+ c(), p();
93
+ }, l);
94
+ } : t.onSuccess = () => {
95
+ setTimeout(() => {
96
+ c(), p();
97
+ }, l);
98
+ }, typeof i == "function" ? t.onClose = (...u) => {
99
+ i(...u), c(), p(), s.clear();
100
+ } : t.onClose = () => {
101
+ c(), p(), s.clear();
102
+ }, setTimeout(() => {
103
+ P.current?.open(t, ...E);
104
+ }, 300);
105
+ });
106
+ s.add(y);
107
+ }
108
+ ), x = g(
109
+ (o = {}, { baseUrl: i, locale: O = "en", blocklet: l = globalThis?.blocklet, closeTimeout: t = b, popupOptions: E } = {}) => new Promise((y, p) => {
110
+ const u = () => new Promise((n) => {
111
+ (async () => {
112
+ if (J(i)) {
113
+ const r = K(), U = N();
114
+ i = r ? U.appUrl : window.location.origin;
115
+ }
116
+ const { onSuccess: a, onClose: d, onError: f, custom: h = !1, ...w } = o;
117
+ if (!w?.extraParams?.provider)
118
+ throw S(f) && f("Must have extraParams.provider"), new Error("Must have extraParams.provider");
119
+ w?.prefix || (w.prefix = window.location.origin + k(l?.prefix, re));
120
+ const D = {
121
+ params: btoa(encodeURIComponent(JSON.stringify(w))),
122
+ appPid: l?.appPid,
123
+ locale: O,
124
+ disableClose: !0
125
+ // 弹窗模式默认不允许关闭 DID Connect
126
+ }, L = ee(
127
+ h ? M(k(i, w.prefix), D) : M(k(i || "/", se, "/connect"), D),
128
+ E
129
+ );
130
+ try {
131
+ const r = await oe({ popup: L, closeTimeout: t });
132
+ ne(
133
+ {
134
+ connected_app: te(),
135
+ ...r?.options
136
+ },
137
+ !0
138
+ ), S(a) ? (a({ ...r.response, encrypted: !1 }), c(), n()) : (c(), n()), y({ ...r.response, encrypted: !1 });
139
+ } catch (r) {
140
+ throw console.error(r), r.message === "Popup closed" ? S(d) ? (d(), n(), s.clear()) : (n(), s.clear()) : S(f) && f(r), r;
141
+ }
142
+ })().catch((a) => {
143
+ n(), p(a);
144
+ });
145
+ });
146
+ s.add(u);
147
+ })
148
+ ), F = (o) => {
149
+ P.current.loginOAuth(o);
150
+ }, C = R(() => /* @__PURE__ */ H(ie, { ref: P })), e = R(() => ({
151
+ open: I,
152
+ close: c,
153
+ loginOAuth: F,
154
+ openPopup: x,
155
+ queue: s
156
+ }));
157
+ return {
158
+ connectHolder: C,
159
+ connectApi: e
160
+ };
161
+ }
162
+ export {
163
+ xe as default
164
+ };
@@ -0,0 +1,15 @@
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ import { BlockletProvider as i, useBlockletContext as u } from "@arcblock/ux/lib/BlockletContext";
3
+ function p(r) {
4
+ function n({ ...t }) {
5
+ const { blocklet: o, masterBlocklet: c } = u();
6
+ return /* @__PURE__ */ e(r, { ...t, blocklet: o, masterBlocklet: c });
7
+ }
8
+ function l({ baseUrl: t, ...o }) {
9
+ return /* @__PURE__ */ e(i, { baseUrl: t, children: /* @__PURE__ */ e(n, { baseUrl: t, ...o }) });
10
+ }
11
+ return l;
12
+ }
13
+ export {
14
+ p as default
15
+ };
@@ -0,0 +1,108 @@
1
+ import { jsx as b } from "react/jsx-runtime";
2
+ import { use as h, useEffect as y } from "react";
3
+ import g from "prop-types";
4
+ import w from "@arcblock/bridge";
5
+ import { useDebounceFn as x, useMemoizedFn as T } from "ahooks";
6
+ import D from "lodash/pick";
7
+ import P from "@arcblock/react-hooks/lib/useBrowser";
8
+ import { isUrl as _ } from "@arcblock/ux/lib/Util";
9
+ import { joinURL as k } from "ufo";
10
+ import { debug as n } from "../utils.js";
11
+ import { API_DID_PREFIX as A, BLOCKLET_SERVICE_PATH_PREFIX as E, DEFAULT_TIMEOUT as I } from "../constant.js";
12
+ import S from "./hooks/security.js";
13
+ import { SessionContext as K } from "../Session/context.js";
14
+ import { getWalletDid as U } from "../User/use-did.js";
15
+ function G(a) {
16
+ const l = {
17
+ prefix: A,
18
+ checkInterval: 2e3,
19
+ checkTimeout: I * 1e3,
20
+ locale: "en",
21
+ tokenKey: "_t_",
22
+ encKey: "_ek_",
23
+ baseUrl: "",
24
+ messages: {},
25
+ extraParams: {},
26
+ forceConnected: !0,
27
+ enabledConnectTypes: [],
28
+ // 所有的
29
+ disableSwitchApp: !1,
30
+ hideCloseButton: !1,
31
+ qrcodeSize: 160,
32
+ options: {}
33
+ };
34
+ function c(r) {
35
+ const { encryptKey: d, decrypt: f } = S(), m = P(), p = h(K), u = U(p?.session?.user), i = D(r, [
36
+ //
37
+ "action",
38
+ "checkTimeout",
39
+ "locale",
40
+ "messages",
41
+ // 'webWalletUrl', arcSphere 中不需要通过 web 登录,不需要此参数
42
+ //
43
+ "baseUrl",
44
+ // 要写清楚 baseUrl 和 prefix 的处理逻辑
45
+ "prefix",
46
+ "checkInterval",
47
+ "closeTimeout",
48
+ "extraParams",
49
+ "tokenKey",
50
+ "encKey",
51
+ "forceConnected",
52
+ "provider",
53
+ "enabledConnectTypes",
54
+ "disableSwitchApp",
55
+ "hideCloseButton",
56
+ // 不允许用户关闭这个 connect
57
+ // 'qrcodeSize', // 不应该允许配置?
58
+ "options"
59
+ // FIXME: @zhanghan 弄清楚参数的字段
60
+ //
61
+ // 'autoConnect',
62
+ // 'saveConnect',
63
+ // 'useSocket', // 后期再考虑实现
64
+ // 'allowWallet',
65
+ // 'showDownload',
66
+ // 函数,需要在这一层进行处理
67
+ // 'onError',
68
+ // 'onSuccess',
69
+ // 'onRecreateSession', // 貌似没有地方用,直接去掉?
70
+ // 'onClose',
71
+ ]), e = Object.assign({}, l, i);
72
+ e.forceConnected === !0 && (e.forceConnected = u || !0);
73
+ const C = r.serviceHost || window?.env?.apiPrefix || window?.blocklet?.prefix || "/";
74
+ !_(e.prefix) && !e.prefix?.startsWith(E) && (e.prefix = k(C, e.prefix));
75
+ const t = m.arcSphere && r.open && !window.forceOpenConnect, { run: s } = x(
76
+ T(async () => {
77
+ n("bridge call arcDidConnect", r, i, e);
78
+ try {
79
+ const o = await w.callArc("didConnect", { ...e, [e.encKey]: d });
80
+ if (n("bridge callArc didConnect: result", o), o.action === "error") {
81
+ r.onError(o.data);
82
+ return;
83
+ }
84
+ if (o.action === "success") {
85
+ r.onSuccess(o.data, f);
86
+ return;
87
+ }
88
+ r.onClose(o.data);
89
+ } catch (o) {
90
+ logger.error("Failed to callArc didConnect", o);
91
+ }
92
+ }),
93
+ {
94
+ leading: !0,
95
+ wait: 300
96
+ }
97
+ );
98
+ return y(() => {
99
+ t && (n("WrapConnect call"), s());
100
+ }, [s, t]), t ? null : /* @__PURE__ */ b(a, { ...r });
101
+ }
102
+ return c.propTypes = {
103
+ open: g.bool
104
+ }, c;
105
+ }
106
+ export {
107
+ G as default
108
+ };
@@ -0,0 +1,61 @@
1
+ import { jsx as S, jsxs as L } from "react/jsx-runtime";
2
+ import { createContext as R, useRef as b, useState as h, use as w } from "react";
3
+ import l from "prop-types";
4
+ import x from "lodash/omit";
5
+ import { RequestStorageAccessApiDialog as F } from "@arcblock/ux/lib/DIDConnect";
6
+ import { joinURL as U } from "ufo";
7
+ import { getFederatedEnabled as _, getMaster as v } from "@arcblock/ux/lib/Util/federated";
8
+ import { useLocalStorageState as I, useMemoizedFn as p, useCreation as T, useInterval as k } from "ahooks";
9
+ import { BLOCKLET_SERVICE_PATH_PREFIX as q } from "@arcblock/ux/lib/Util/constant";
10
+ import P from "js-cookie";
11
+ import { getBrowserLang as D } from "../utils.js";
12
+ import { LANG_COOKIE_NAME as M, CHECK_INTERVAL_TIME as j } from "../constant.js";
13
+ const m = R({}), { Provider: y, Consumer: Z } = m;
14
+ function K({ children: o, locale: d = "en" }) {
15
+ const c = window?.blocklet, n = _(c), r = v(c), i = b(null), [e, u] = I("storage-access", {
16
+ defaultValue: {
17
+ appUrl: r?.appUrl,
18
+ iat: Date.now(),
19
+ state: void 0
20
+ }
21
+ }), [s, f] = h(d), g = p(() => {
22
+ const t = P.get(M) || D();
23
+ t !== s && f(t);
24
+ }), A = p(async () => {
25
+ const { value: t, origin: E } = await i.current.requestStorageAccess();
26
+ let a = e.state || "prompt";
27
+ return E === "broswer" && e.state && (a = t ? "granted" : "denied"), a !== e.state && u({
28
+ ...e,
29
+ iat: Date.now(),
30
+ state: a
31
+ }), t;
32
+ }), C = T(() => r?.appUrl && n ? /* @__PURE__ */ S(
33
+ F,
34
+ {
35
+ ref: i,
36
+ locale: s,
37
+ src: U(r.appUrl, q, "/share/shared-bridge.html"),
38
+ storageAccessState: e.state
39
+ }
40
+ ) : null, [s, r?.appUrl, n, e.appUrl, e.iat, e.state]);
41
+ return k(() => {
42
+ g();
43
+ }, j), /* @__PURE__ */ L(y, { value: { requestStorageAccess: A }, children: [
44
+ o,
45
+ C
46
+ ] });
47
+ }
48
+ K.propTypes = {
49
+ children: l.node.isRequired,
50
+ locale: l.string
51
+ };
52
+ function $() {
53
+ const o = w(m);
54
+ return x(o, ["locale"]);
55
+ }
56
+ export {
57
+ Z as FederatedConsumer,
58
+ m as FederatedContext,
59
+ K as FederatedProvider,
60
+ $ as useFederatedContext
61
+ };
@@ -0,0 +1,7 @@
1
+ import { FederatedConsumer as r, FederatedContext as t, FederatedProvider as o, useFederatedContext as a } from "./context.js";
2
+ export {
3
+ r as FederatedConsumer,
4
+ t as FederatedContext,
5
+ o as FederatedProvider,
6
+ a as useFederatedContext
7
+ };
@@ -0,0 +1,4 @@
1
+ import { default as o } from "@arcblock/ux/lib/DIDLogo";
2
+ export {
3
+ o as default
4
+ };