@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,249 @@
1
+ import { jsx as n, jsxs as F } from "react/jsx-runtime";
2
+ import o from "prop-types";
3
+ import { Box as m } from "@mui/material";
4
+ import { LOGIN_PROVIDER as u, LOGIN_PROVIDER_NAME as S } from "@arcblock/ux/lib/Util/constant";
5
+ import { getWebWalletUrl as ee } from "@arcblock/ux/lib/Util/wallet";
6
+ import f from "lodash/noop";
7
+ import { useMemoizedFn as g } from "ahooks";
8
+ import h from "js-cookie";
9
+ import { getCookieOptions as oe } from "@arcblock/ux/lib/Util";
10
+ import { useRef as y, useEffect as re } from "react";
11
+ import { mergeSx as te } from "@arcblock/ux/lib/Util/style";
12
+ import se from "@arcblock/ux/lib/DIDConnect/provider-icon";
13
+ import ne from "./mobile-login-item.js";
14
+ import ie from "./web-login-item.js";
15
+ import le from "./login-method-item.js";
16
+ import { useOAuth as ce } from "../../../OAuth/context.js";
17
+ import { useStateContext as ae } from "../../contexts/state.js";
18
+ import { getAppId as pe, logger as me, getApiErrorMessage as ue } from "../../../utils.js";
19
+ import fe from "./passkey-login-item.js";
20
+ import { usePasskey as de } from "../../../Passkey/context.js";
21
+ import "../../../Passkey/actions.js";
22
+ import ge from "../../plugins/email/index.js";
23
+ function he({
24
+ onSuccess: x = f,
25
+ onError: b = f,
26
+ size: i = "small",
27
+ tokenState: r,
28
+ webWalletUrl: T = ee(),
29
+ tokenKey: U,
30
+ passkeyBehavior: W = "none",
31
+ onRest: d = f,
32
+ showMobileLogin: j = !0,
33
+ showOAuthLogin: v = !0,
34
+ showPasskeyLogin: M = !0,
35
+ showWebLogin: N = !0,
36
+ showEmailLogin: p = !0,
37
+ oauthProviderList: q = [],
38
+ slotProps: B = {},
39
+ disableSwitchApp: w = !1,
40
+ forceUpdate: G = f,
41
+ magicToken: I = void 0,
42
+ baseUrl: V = "/",
43
+ customItems: K = []
44
+ }) {
45
+ const L = y(null), P = y(null), A = y(null), { loginOAuth: $, logoutOAuth: H, t: J, oauthState: s } = ce(), { passkeyState: C } = de(), { extraParams: O, locale: Q, connectState: t, plugins: R, setPlugins: X, setSelectedPlugin: Y, getPlugin: E } = ae(), _ = g(async (e) => {
46
+ r.reset(), s.reset({
47
+ status: "scanned"
48
+ }), C.reset(), t.chooseMethod = e.provider;
49
+ const c = O?.sourceAppPid;
50
+ try {
51
+ s.loading = !0, s.status = "scanned";
52
+ const a = await $(e, {
53
+ action: r.action,
54
+ ...O
55
+ }), l = oe({ returnDomain: !1 });
56
+ h.remove("connected_did", l), h.remove("connected_pk", l), h.remove("connected_wallet_os", l), a?.sessionToken && (await x(
57
+ {
58
+ ...a,
59
+ encrypted: !1
60
+ },
61
+ (z) => z,
62
+ {
63
+ sourceAppPid: c,
64
+ connected_app: pe(r.appInfo, r.memberAppInfo)
65
+ }
66
+ ), s.loading = !1, s.status = "succeed");
67
+ } catch (a) {
68
+ me.error(`Failed login OAuth: ${e.provider}`, a);
69
+ const l = ue(a, J("loginOAuthFailed"));
70
+ s.loading = !1, s.error = l, s.status = "error", await H({ provider: e.provider }), b(new Error(l));
71
+ }
72
+ }), k = g(async () => {
73
+ r.reset(), await d(), r.status = "created", t.chooseMethod = "wallet";
74
+ }), D = ge({ baseUrl: V }), Z = g(() => {
75
+ if (I && p && R.some((e) => e.name === u.EMAIL)) {
76
+ const e = E(u.EMAIL);
77
+ e.state.status === "idle" && (e.state.reset(), e.state.magicToken = I, t.chooseMethod = u.EMAIL, Y(e), G());
78
+ }
79
+ });
80
+ return re(() => {
81
+ const e = [];
82
+ if (p) {
83
+ const c = E(u.EMAIL);
84
+ c && c.baseUrl === D.baseUrl ? e.push(c) : e.push(D);
85
+ }
86
+ X(e), t.retryConnect = k, setTimeout(() => {
87
+ Z();
88
+ }, 100);
89
+ }, [p]), /* @__PURE__ */ n(m, { className: "did-connect__choose", sx: te({ flex: 1 }, B?.root?.sx), children: /* @__PURE__ */ n(
90
+ m,
91
+ {
92
+ sx: {
93
+ display: "flex",
94
+ flexDirection: "column",
95
+ gap: 2
96
+ },
97
+ children: /* @__PURE__ */ F(
98
+ m,
99
+ {
100
+ sx: [
101
+ {
102
+ display: "flex",
103
+ flexDirection: "column",
104
+ gap: 1.5
105
+ }
106
+ ],
107
+ children: [
108
+ j && i !== "small" && /* @__PURE__ */ n(
109
+ ne,
110
+ {
111
+ ref: L,
112
+ tokenState: r,
113
+ sx: [i === "small" ? { p: 1 } : { p: 2 }],
114
+ locale: Q,
115
+ tokenKey: U,
116
+ disableSwitchApp: w,
117
+ onClick: async () => {
118
+ r.reset(), await d(), r.status = "created", t.chooseMethod = "wallet";
119
+ const e = L.current?.connect;
120
+ t.retryConnect = () => {
121
+ e(k);
122
+ };
123
+ }
124
+ }
125
+ ),
126
+ N && /* @__PURE__ */ n(
127
+ ie,
128
+ {
129
+ ref: P,
130
+ tokenState: r,
131
+ webWalletUrl: T,
132
+ sx: [i === "small" ? { p: 1 } : { p: 2 }],
133
+ disableSwitchApp: w,
134
+ onClick: () => {
135
+ r.status = "scanned", t.chooseMethod = "wallet-web";
136
+ const e = P.current.connect;
137
+ t.retryConnect = async () => {
138
+ await d(), r.error = "", r.status = "scanned", e();
139
+ };
140
+ }
141
+ }
142
+ ),
143
+ v || M || p ? /* @__PURE__ */ F(
144
+ m,
145
+ {
146
+ sx: [
147
+ {
148
+ display: "flex",
149
+ flexDirection: "column",
150
+ gap: 1.5
151
+ }
152
+ ],
153
+ children: [
154
+ R.map(
155
+ (e) => e.renderListItem({
156
+ key: e.name,
157
+ sx: [i === "small" ? { p: 1 } : { p: 2 }]
158
+ // forceUpdate,
159
+ })
160
+ ),
161
+ v ? q.map((e) => /* @__PURE__ */ n(
162
+ le,
163
+ {
164
+ title: S[e.provider],
165
+ icon: /* @__PURE__ */ n(
166
+ se,
167
+ {
168
+ provider: e.provider,
169
+ sx: {
170
+ transform: "scale(0.95)",
171
+ width: 24,
172
+ height: 24,
173
+ color: "text.primary"
174
+ }
175
+ }
176
+ ),
177
+ onClick: () => {
178
+ _(e), t.retryConnect = () => {
179
+ _(e);
180
+ };
181
+ },
182
+ sx: [i === "small" ? { p: 1 } : { p: 2 }]
183
+ },
184
+ e.provider
185
+ )) : null,
186
+ M ? /* @__PURE__ */ n(
187
+ fe,
188
+ {
189
+ ref: A,
190
+ onSuccess: x,
191
+ onError: b,
192
+ tokenState: r,
193
+ behavior: W,
194
+ sx: [i === "small" ? { p: 1 } : { p: 2 }],
195
+ onClick: () => {
196
+ const e = A.current.connect;
197
+ t.chooseMethod = "passkey", t.retryConnect = () => {
198
+ C.verifying = !0, t.chooseMethod = "passkey", e();
199
+ };
200
+ },
201
+ slotProps: {
202
+ icon: {
203
+ sx: {
204
+ fontSize: 24,
205
+ "& svg": {
206
+ fontSize: 24,
207
+ width: "1em",
208
+ height: "1em"
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+ ) : null
215
+ ]
216
+ }
217
+ ) : null,
218
+ K.map((e) => e || null)
219
+ ]
220
+ }
221
+ )
222
+ }
223
+ ) });
224
+ }
225
+ he.propTypes = {
226
+ onSuccess: o.func,
227
+ onError: o.func,
228
+ size: o.oneOf(["small", "normal", "large"]),
229
+ tokenState: o.object.isRequired,
230
+ webWalletUrl: o.string,
231
+ tokenKey: o.string.isRequired,
232
+ passkeyBehavior: o.oneOf(["none", "both", "only-existing", "only-new"]),
233
+ onRest: o.func,
234
+ showMobileLogin: o.bool,
235
+ showOAuthLogin: o.bool,
236
+ showPasskeyLogin: o.bool,
237
+ showWebLogin: o.bool,
238
+ showEmailLogin: o.bool,
239
+ oauthProviderList: o.array,
240
+ slotProps: o.object,
241
+ disableSwitchApp: o.bool,
242
+ forceUpdate: o.func,
243
+ magicToken: o.string,
244
+ baseUrl: o.string,
245
+ customItems: o.arrayOf(o.node)
246
+ };
247
+ export {
248
+ he as default
249
+ };
@@ -0,0 +1,129 @@
1
+ import { jsxs as i, jsx as o, Fragment as x } from "react/jsx-runtime";
2
+ import { useTheme as g, Box as r, Typography as l } from "@mui/material";
3
+ import { Icon as s } from "@iconify/react";
4
+ import { isValidElement as y } from "react";
5
+ import e from "prop-types";
6
+ import { mergeSx as c } from "@arcblock/ux/lib/Util/style";
7
+ import u from "@iconify-icons/material-symbols/arrow-right-alt-rounded";
8
+ function b({
9
+ title: m,
10
+ description: n = null,
11
+ icon: t,
12
+ iconScale: p = 0.95,
13
+ slotProps: d = {},
14
+ mode: f = "normal",
15
+ ...a
16
+ }) {
17
+ const h = g();
18
+ return /* @__PURE__ */ i(
19
+ r,
20
+ {
21
+ ...a,
22
+ sx: c(
23
+ {
24
+ display: "flex",
25
+ alignItems: "center",
26
+ gap: 1,
27
+ cursor: "pointer",
28
+ p: 1,
29
+ borderRadius: 1,
30
+ backgroundColor: "grey.50",
31
+ textDecoration: "none",
32
+ transition: "background-color 0.5s",
33
+ "&:hover, &:active, &.did-connect__choose-item__active": {
34
+ backgroundColor: "grey.100"
35
+ },
36
+ "& .other-item-icon": {
37
+ opacity: "0",
38
+ transform: "translateX(-100%)",
39
+ transition: "transform 0.2s ease, opacity 0.1s ease"
40
+ },
41
+ "&:hover": {
42
+ "& .other-item-icon": {
43
+ display: "inline-block",
44
+ transform: "translateX(0)",
45
+ opacity: "1"
46
+ }
47
+ }
48
+ },
49
+ a?.sx
50
+ ),
51
+ children: [
52
+ /* @__PURE__ */ o(
53
+ r,
54
+ {
55
+ className: "arc-login-item__icon",
56
+ sx: c(
57
+ {
58
+ display: "flex",
59
+ justifyContent: "center",
60
+ alignItems: "center",
61
+ color: "text.primary"
62
+ },
63
+ d?.icon?.sx
64
+ ),
65
+ children: y(t) ? t : /* @__PURE__ */ o(
66
+ r,
67
+ {
68
+ component: s,
69
+ icon: t,
70
+ sx: {
71
+ transform: `scale(${p})`,
72
+ width: 24,
73
+ height: 24
74
+ }
75
+ }
76
+ )
77
+ }
78
+ ),
79
+ f === "normal" ? /* @__PURE__ */ i(x, { children: [
80
+ /* @__PURE__ */ i(r, { sx: { display: "flex", flexDirection: "column", flex: 1 }, children: [
81
+ /* @__PURE__ */ o(
82
+ l,
83
+ {
84
+ sx: {
85
+ fontSize: 14,
86
+ fontWeight: "500",
87
+ color: "text.primary",
88
+ whiteSpace: "nowrap"
89
+ },
90
+ children: m
91
+ }
92
+ ),
93
+ n ? /* @__PURE__ */ o(
94
+ l,
95
+ {
96
+ sx: {
97
+ color: "text.secondary",
98
+ fontSize: 12,
99
+ lineHeight: 1
100
+ },
101
+ children: n
102
+ }
103
+ ) : null
104
+ ] }),
105
+ /* @__PURE__ */ o(
106
+ s,
107
+ {
108
+ className: "other-item-icon",
109
+ icon: u,
110
+ fontSize: "1.3rem",
111
+ color: h.palette.primary.main
112
+ }
113
+ )
114
+ ] }) : null
115
+ ]
116
+ }
117
+ );
118
+ }
119
+ b.propTypes = {
120
+ title: e.string.isRequired,
121
+ description: e.string,
122
+ icon: e.any.isRequired,
123
+ iconScale: e.number,
124
+ slotProps: e.object,
125
+ mode: e.oneOf(["simple", "normal"])
126
+ };
127
+ export {
128
+ b as default
129
+ };
@@ -0,0 +1,114 @@
1
+ import { jsx as p } from "react/jsx-runtime";
2
+ import n from "prop-types";
3
+ import { CircularProgress as D } from "@mui/material";
4
+ import { useReactive as T, useCreation as W, useMemoizedFn as a } from "ahooks";
5
+ import O from "@arcblock/bridge";
6
+ import { useBrowser as E } from "@arcblock/react-hooks";
7
+ import q from "lodash/noop";
8
+ import { useImperativeHandle as F } from "react";
9
+ import { mergeSx as M } from "@arcblock/ux/lib/Util/style";
10
+ import N from "@arcblock/ux/lib/DIDConnect/provider-icon";
11
+ import { LOGIN_PROVIDER as _ } from "@arcblock/ux/lib/Util/constant";
12
+ import { useStateContext as j } from "../../contexts/state.js";
13
+ import z from "./login-method-item.js";
14
+ import { logger as I } from "../../../utils.js";
15
+ import J from "../../hooks/auth-url.js";
16
+ function K({
17
+ ref: b = null,
18
+ tokenState: e,
19
+ locale: w,
20
+ tokenKey: y,
21
+ onClick: C = q,
22
+ disableSwitchApp: P = !1,
23
+ ...m
24
+ }) {
25
+ const l = T({
26
+ loading: !1
27
+ }), { isWalletWebview: f } = j(), x = "DID Wallet", c = E(), d = new URL(window.location.href), A = J({ disableSwitchApp: P, tokenState: e }), h = W(() => {
28
+ if (!e.url)
29
+ return "";
30
+ d.searchParams.set("tokenKey", e.token);
31
+ const o = new URL(A);
32
+ c.wallet || (o.searchParams.set("callback", encodeURIComponent(d)), o.searchParams.set("callback_delay", 1500)), o.searchParams.set("locale", w);
33
+ const g = new TextEncoder(), v = o.href.length;
34
+ let r = "", i = "";
35
+ try {
36
+ if (e.appInfo) {
37
+ const t = g.encode(JSON.stringify(e.appInfo));
38
+ r = btoa(String.fromCharCode(...t));
39
+ }
40
+ if (e.memberAppInfo) {
41
+ const t = g.encode(JSON.stringify(e.memberAppInfo));
42
+ i = btoa(String.fromCharCode(...t));
43
+ }
44
+ if (v + 8 + r.length + 14 + i.length > 2e3)
45
+ throw I.warn("URL too long, drop appInfo & memberAppInfo", { appInfo: r, memberAppInfo: i }), new Error("URL too long");
46
+ i ? r && (o.searchParams.set("appInfo", r), o.searchParams.set("memberAppInfo", i)) : r && o.searchParams.set("appInfo", r);
47
+ } catch (t) {
48
+ I.warn("Failed to convert appInfo & memberAppInfo", t);
49
+ }
50
+ return o.href.replace(/^https?:\/\//, "abt://");
51
+ }, [y, e.token, e.appInfo, e.memberAppInfo, e.url]), L = a(() => {
52
+ l.loading = !0, setTimeout(() => {
53
+ O.call("authAction", { action: "auth", deepLink: h });
54
+ }, 600), setTimeout(() => {
55
+ l.loading = !1;
56
+ }, 2e3);
57
+ }), R = a(() => {
58
+ e.checking = !0, e.status = "scanned";
59
+ }), s = {};
60
+ !f && c.mobile.any && (s.component = "a", s.href = h), e.url || (s.sx = {
61
+ cursor: "not-allowed"
62
+ });
63
+ const u = a((o) => {
64
+ e.url && (f ? L() : c.mobile.any ? R() : o());
65
+ }), U = a(() => {
66
+ u(C);
67
+ });
68
+ return F(b, () => ({
69
+ connect: u
70
+ })), /* @__PURE__ */ p(
71
+ z,
72
+ {
73
+ ...m,
74
+ ...s,
75
+ sx: M(m?.sx, s?.sx),
76
+ title: x,
77
+ icon: l.loading || !e.url ? /* @__PURE__ */ p(
78
+ D,
79
+ {
80
+ color: "primary",
81
+ size: 24,
82
+ sx: {
83
+ "& svg": {
84
+ transform: "scale(0.75)"
85
+ }
86
+ }
87
+ }
88
+ ) : /* @__PURE__ */ p(
89
+ N,
90
+ {
91
+ width: "24px",
92
+ height: "24px",
93
+ provider: _.DID_WALLET,
94
+ style: {
95
+ transform: "scale(0.9)"
96
+ }
97
+ }
98
+ ),
99
+ iconScale: 1,
100
+ onClick: U
101
+ }
102
+ );
103
+ }
104
+ K.propTypes = {
105
+ tokenState: n.object.isRequired,
106
+ tokenKey: n.string.isRequired,
107
+ locale: n.string.isRequired,
108
+ onClick: n.func,
109
+ disableSwitchApp: n.bool,
110
+ ref: n.any
111
+ };
112
+ export {
113
+ K as default
114
+ };
@@ -0,0 +1,44 @@
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import e from "prop-types";
3
+ import { useRef as a, useImperativeHandle as l } from "react";
4
+ import { useMemoizedFn as d } from "ahooks";
5
+ import y from "../../../Passkey/actions.js";
6
+ import { getAppId as A } from "../../../utils.js";
7
+ import { useStateContext as P } from "../../contexts/state.js";
8
+ function x({ ref: t = null, onSuccess: p, tokenState: o, behavior: n = "none", ...c }) {
9
+ const { extraParams: r } = P(), s = a(null), i = d(
10
+ (m) => p(
11
+ {
12
+ ...m,
13
+ encrypted: !1
14
+ },
15
+ (u) => u,
16
+ {
17
+ sourceAppPid: r?.sourceAppPid,
18
+ connected_app: A(o.appInfo, o.memberAppInfo)
19
+ }
20
+ )
21
+ );
22
+ return l(t, () => ({
23
+ connect: s.current.click
24
+ })), n === "none" ? null : /* @__PURE__ */ f(
25
+ y,
26
+ {
27
+ ...c,
28
+ ref: s,
29
+ action: o.action,
30
+ behavior: n,
31
+ onSuccess: i,
32
+ extraParams: r
33
+ }
34
+ );
35
+ }
36
+ x.propTypes = {
37
+ onSuccess: e.func.isRequired,
38
+ tokenState: e.object.isRequired,
39
+ behavior: e.oneOf(["none", "both", "only-existing", "only-new"]),
40
+ ref: e.any
41
+ };
42
+ export {
43
+ x as default
44
+ };
@@ -0,0 +1,97 @@
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import r from "prop-types";
3
+ import { CircularProgress as C } from "@mui/material";
4
+ import { useReactive as R, useMemoizedFn as c, useCreation as p } from "ahooks";
5
+ import { detectWalletExtension as w, openWebWallet as L } from "@arcblock/ux/lib/Util";
6
+ import { mergeSx as v } from "@arcblock/ux/lib/Util/style";
7
+ import y from "lodash/noop";
8
+ import A from "lodash/omit";
9
+ import { useImperativeHandle as P } from "react";
10
+ import E from "@arcblock/ux/lib/DIDConnect/provider-icon";
11
+ import { LOGIN_PROVIDER as T } from "@arcblock/ux/lib/Util/constant";
12
+ import _ from "./login-method-item.js";
13
+ import { useStateContext as O } from "../../contexts/state.js";
14
+ import { EXT_DOWNLOAD_URL as d } from "../../../constant.js";
15
+ import U from "../../hooks/auth-url.js";
16
+ function j({
17
+ ref: x = null,
18
+ tokenState: o,
19
+ locale: g = "en",
20
+ webWalletUrl: b,
21
+ onClick: I = y,
22
+ disableSwitchApp: h = !1,
23
+ ...a
24
+ }) {
25
+ const { browserBrand: i } = O(), l = w(), t = R({
26
+ loading: !1
27
+ }), D = U({ disableSwitchApp: h, tokenState: o }), f = c(() => {
28
+ t.loading = !0, L({
29
+ webWalletUrl: b,
30
+ url: D,
31
+ locale: g,
32
+ appInfo: o.appInfo,
33
+ memberAppInfo: o.memberAppInfo
34
+ })?.type === "web" ? t.loading = !1 : setTimeout(() => {
35
+ t.loading = !1;
36
+ }, 3e3);
37
+ }), s = c((e) => {
38
+ o.url && (I(e), e?.preventDefault(), f());
39
+ });
40
+ P(x, () => ({
41
+ connect: f
42
+ }));
43
+ const n = p(() => i === "edge" ? d.edge : i === "chrome" ? d.chrome : null, [i]), u = p(() => {
44
+ const e = {};
45
+ return l ? e.onClick = s : n ? (e.component = "a", e.href = n, e.target = "_blank", e.rel = "noopener") : e.onClick = s, o.url || (e.sx = {
46
+ cursor: "not-allowed"
47
+ }), e;
48
+ }, [s, o.url]), W = p(() => l || n ? "DID Wallet (Extension)" : "DID Wallet (Web)", [l, n]);
49
+ return /* @__PURE__ */ m(
50
+ _,
51
+ {
52
+ ...a,
53
+ sx: v(
54
+ {
55
+ textDecoration: "none"
56
+ },
57
+ a?.sx,
58
+ u.sx
59
+ ),
60
+ title: W,
61
+ icon: t.loading || !o.url ? /* @__PURE__ */ m(
62
+ C,
63
+ {
64
+ color: "primary",
65
+ size: 24,
66
+ sx: {
67
+ "& svg": {
68
+ transform: "scale(0.75)"
69
+ }
70
+ }
71
+ }
72
+ ) : /* @__PURE__ */ m(
73
+ E,
74
+ {
75
+ width: "24px",
76
+ height: "24px",
77
+ provider: T.DID_WALLET,
78
+ style: {
79
+ transform: "scale(0.9)"
80
+ }
81
+ }
82
+ ),
83
+ ...A(u, "sx")
84
+ }
85
+ );
86
+ }
87
+ j.propTypes = {
88
+ tokenState: r.object.isRequired,
89
+ locale: r.string,
90
+ webWalletUrl: r.string.isRequired,
91
+ onClick: r.func,
92
+ disableSwitchApp: r.bool,
93
+ ref: r.any
94
+ };
95
+ export {
96
+ j as default
97
+ };
@@ -0,0 +1,34 @@
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ import p from "prop-types";
3
+ import { Box as i, alpha as a } from "@mui/material";
4
+ import { mergeSx as l } from "@arcblock/ux/lib/Util/style";
5
+ function n({ children: r, ...o }) {
6
+ return /* @__PURE__ */ e(
7
+ i,
8
+ {
9
+ ...o,
10
+ sx: l(
11
+ {
12
+ position: "absolute",
13
+ top: 0,
14
+ bottom: 0,
15
+ left: 0,
16
+ right: 0,
17
+ display: "flex",
18
+ justifyContent: "center",
19
+ alignItems: "center",
20
+ backgroundColor: ({ palette: t }) => a(t.background.default, 0.75),
21
+ backdropFilter: "blur(3px)"
22
+ },
23
+ o?.sx
24
+ ),
25
+ children: r
26
+ }
27
+ );
28
+ }
29
+ n.propTypes = {
30
+ children: p.any.isRequired
31
+ };
32
+ export {
33
+ n as default
34
+ };