@arcblock/did-connect-react 3.3.4 → 3.3.5

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.
@@ -0,0 +1,109 @@
1
+ import { jsxs as c, Fragment as f, jsx as e } from "react/jsx-runtime";
2
+ import o from "prop-types";
3
+ import { Box as t, Divider as R } from "@mui/material";
4
+ import { LOGIN_PROVIDER as d } from "@arcblock/ux/lib/Util/constant";
5
+ import { checkSameProtocol as k, getWebWalletUrl as C } from "@arcblock/ux/lib/Util/wallet";
6
+ import { detectWalletExtension as W } from "@arcblock/ux/lib/Util";
7
+ import { useCreation as q } from "ahooks";
8
+ import { useBrowser as j } from "@arcblock/react-hooks";
9
+ import T from "./mobile-login-item.js";
10
+ import B from "./web-login-item.js";
11
+ import P from "../back-button.js";
12
+ import { useStateContext as v } from "../../contexts/state.js";
13
+ function E({
14
+ qrcode: p,
15
+ tokenState: r,
16
+ webWalletUrl: n = C(),
17
+ size: l = "small",
18
+ disableSwitchApp: m = !1,
19
+ tokenKey: u,
20
+ walletLoginRef: b = null,
21
+ webLoginRef: x = null,
22
+ onMobileLoginClick: g,
23
+ onWebLoginClick: h,
24
+ onBack: L
25
+ }) {
26
+ const { locale: w } = v(), i = j(), y = k(n), s = W(), a = q(() => i.mobile.tablet || !i.mobile.any && window?.navigator?.maxTouchPoints > 0, [i.mobile.tablet, i.mobile.any]);
27
+ return /* @__PURE__ */ c(f, { children: [
28
+ p,
29
+ /* @__PURE__ */ c(t, { sx: { width: "100%", display: "flex", flexDirection: "column", gap: 1.5 }, children: [
30
+ /* @__PURE__ */ e(t, { sx: { width: "100%" }, children: /* @__PURE__ */ e(
31
+ R,
32
+ {
33
+ orientation: "horizontal",
34
+ sx: {
35
+ fontSize: 12,
36
+ color: "text.hint",
37
+ "&::before, &::after": {
38
+ borderColor: "divider"
39
+ }
40
+ },
41
+ children: "or"
42
+ }
43
+ ) }),
44
+ /* @__PURE__ */ e(
45
+ t,
46
+ {
47
+ sx: {
48
+ width: "100%",
49
+ ".arc-login-item": {
50
+ width: "100%",
51
+ justifyContent: "center",
52
+ "& > .arc-login-item__body": {
53
+ flex: "unset"
54
+ },
55
+ "& > .other-item-icon": {
56
+ display: "none !important"
57
+ }
58
+ }
59
+ },
60
+ children: a ? /* @__PURE__ */ e(
61
+ T,
62
+ {
63
+ ref: b,
64
+ tokenState: r,
65
+ isTablet: a,
66
+ sx: [l === "small" ? { p: 1 } : { p: 2 }],
67
+ locale: w,
68
+ tokenKey: u,
69
+ disableSwitchApp: m,
70
+ onClick: g
71
+ },
72
+ d.WALLET
73
+ ) : (
74
+ // eslint-disable-next-line react/jsx-no-useless-fragment
75
+ /* @__PURE__ */ e(f, { children: (y || s) && (!i.mobile.any || s) ? /* @__PURE__ */ e(
76
+ B,
77
+ {
78
+ ref: x,
79
+ tokenState: r,
80
+ webWalletUrl: n,
81
+ sx: [l === "small" ? { p: 1 } : { p: 2 }],
82
+ disableSwitchApp: m,
83
+ onClick: h
84
+ },
85
+ d.WALLET
86
+ ) : null })
87
+ )
88
+ }
89
+ ),
90
+ /* @__PURE__ */ e(P, { variant: "text", onClick: L })
91
+ ] })
92
+ ] });
93
+ }
94
+ E.propTypes = {
95
+ qrcode: o.node.isRequired,
96
+ tokenState: o.object.isRequired,
97
+ webWalletUrl: o.string,
98
+ size: o.oneOf(["small", "normal", "large"]),
99
+ disableSwitchApp: o.bool,
100
+ tokenKey: o.string.isRequired,
101
+ walletLoginRef: o.object,
102
+ webLoginRef: o.object,
103
+ onMobileLoginClick: o.func.isRequired,
104
+ onWebLoginClick: o.func.isRequired,
105
+ onBack: o.func.isRequired
106
+ };
107
+ export {
108
+ E as default
109
+ };
@@ -1,65 +1,68 @@
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 L, useMemoizedFn as d, useCreation as p } from "ahooks";
5
- import { detectWalletExtension as _, openWebWallet as w } from "@arcblock/ux/lib/Util";
6
- import { mergeSx as E } from "@arcblock/ux/lib/Util/style";
7
- import O from "lodash/noop";
8
- import P from "lodash/omit";
9
- import { useImperativeHandle as v } from "react";
10
- import A from "@arcblock/ux/lib/DIDConnect/provider-icon";
11
- import { LOGIN_PROVIDER_ICON_SIZE as a, LOGIN_PROVIDER as y } from "@arcblock/ux/lib/Util/constant";
12
- import T from "./login-method-item.js";
13
- import { useStateContext as N } from "../../contexts/state.js";
14
- import { EXT_DOWNLOAD_URL as I } from "../../../constant.js";
15
- import U from "../../hooks/auth-url.js";
16
- function j({
17
- ref: g = null,
18
- tokenState: o,
19
- locale: x = "en",
1
+ import { jsx as p } from "react/jsx-runtime";
2
+ import o from "prop-types";
3
+ import { CircularProgress as _ } from "@mui/material";
4
+ import { useReactive as w, useMemoizedFn as I, useCreation as f } from "ahooks";
5
+ import { detectWalletExtension as C, openWebWallet as E } from "@arcblock/ux/lib/Util";
6
+ import { mergeSx as O } from "@arcblock/ux/lib/Util/style";
7
+ import P from "lodash/noop";
8
+ import v from "lodash/omit";
9
+ import { useImperativeHandle as A } from "react";
10
+ import y from "@arcblock/ux/lib/DIDConnect/provider-icon";
11
+ import { LOGIN_PROVIDER_ICON_SIZE as a, LOGIN_PROVIDER as T } from "@arcblock/ux/lib/Util/constant";
12
+ import N from "./login-method-item.js";
13
+ import { useStateContext as U } from "../../contexts/state.js";
14
+ import { EXT_DOWNLOAD_URL as g } from "../../../constant.js";
15
+ import j from "../../hooks/auth-url.js";
16
+ function q({
17
+ ref: x = null,
18
+ tokenState: r,
19
+ locale: D = "en",
20
20
  webWalletUrl: b,
21
- onClick: D = O,
22
- disableSwitchApp: h = !1,
23
- ...f
21
+ onClick: h = P,
22
+ disableSwitchApp: W = !1,
23
+ autoConnect: t = !0,
24
+ ...u
24
25
  }) {
25
- const { browserBrand: i } = N(), l = _(), t = L({
26
+ const { browserBrand: l } = U(), s = C(), n = w({
26
27
  loading: !1
27
- }), W = U({ disableSwitchApp: h, tokenState: o }), u = d(() => {
28
- t.loading = !0, w({
28
+ }), R = j({ disableSwitchApp: W, tokenState: r }), c = I(() => {
29
+ if (!t)
30
+ return;
31
+ n.loading = !0, E({
29
32
  webWalletUrl: b,
30
- url: W,
31
- locale: x,
32
- appInfo: o.appInfo,
33
- memberAppInfo: o.memberAppInfo
34
- })?.type === "web" ? t.loading = !1 : setTimeout(() => {
35
- t.loading = !1;
33
+ url: R,
34
+ locale: D,
35
+ appInfo: r.appInfo,
36
+ memberAppInfo: r.memberAppInfo
37
+ })?.type === "web" ? n.loading = !1 : setTimeout(() => {
38
+ n.loading = !1;
36
39
  }, 3e3);
37
- }), s = d((e) => {
38
- o.url && (D(e), e?.preventDefault(), u());
40
+ }), m = I((e) => {
41
+ r.url && (h(e), e?.preventDefault(), c());
39
42
  });
40
- v(g, () => ({
41
- connect: u
43
+ A(x, () => ({
44
+ connect: c
42
45
  }));
43
- const n = p(() => i === "edge" ? I.edge : i === "chrome" ? I.chrome : null, [i]), c = p(() => {
46
+ const i = f(() => l === "edge" ? g.edge : l === "chrome" ? g.chrome : null, [l]), d = f(() => {
44
47
  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 = {
48
+ return s || !t ? e.onClick = m : i && t ? (e.component = "a", e.href = i, e.target = "_blank", e.rel = "noopener") : e.onClick = m, r.url || (e.sx = {
46
49
  cursor: "not-allowed"
47
50
  }), e;
48
- }, [s, o.url]), R = p(() => l || n ? "DID Wallet (Extension)" : "DID Wallet (Web)", [l, n]);
49
- return /* @__PURE__ */ m(
50
- T,
51
+ }, [m, r.url]), L = f(() => t ? s || i ? "DID Wallet (Extension)" : "DID Wallet (Web)" : "DID Wallet", [s, i]);
52
+ return /* @__PURE__ */ p(
53
+ N,
51
54
  {
52
- ...f,
53
- sx: E(
55
+ ...u,
56
+ sx: O(
54
57
  {
55
58
  textDecoration: "none"
56
59
  },
57
- f?.sx,
58
- c.sx
60
+ u?.sx,
61
+ d.sx
59
62
  ),
60
- title: R,
61
- icon: t.loading || !o.url ? /* @__PURE__ */ m(
62
- C,
63
+ title: L,
64
+ icon: n.loading || !r.url ? /* @__PURE__ */ p(
65
+ _,
63
66
  {
64
67
  color: "primary",
65
68
  size: a,
@@ -69,29 +72,31 @@ function j({
69
72
  }
70
73
  }
71
74
  }
72
- ) : /* @__PURE__ */ m(
73
- A,
75
+ ) : /* @__PURE__ */ p(
76
+ y,
74
77
  {
75
78
  sx: {
76
79
  width: a,
77
80
  height: a,
78
81
  transform: "scale(0.9)"
79
82
  },
80
- provider: y.DID_WALLET
83
+ provider: T.DID_WALLET
81
84
  }
82
85
  ),
83
- ...P(c, "sx")
86
+ ...v(d, "sx")
84
87
  }
85
88
  );
86
89
  }
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
90
+ q.propTypes = {
91
+ tokenState: o.object.isRequired,
92
+ locale: o.string,
93
+ webWalletUrl: o.string.isRequired,
94
+ onClick: o.func,
95
+ disableSwitchApp: o.bool,
96
+ autoConnect: o.bool,
97
+ // 点击后是否自动连接,默认true
98
+ ref: o.any
94
99
  };
95
100
  export {
96
- j as default
101
+ q as default
97
102
  };
@@ -1,57 +1,57 @@
1
- import { jsx as I } from "react/jsx-runtime";
1
+ import { jsx as O } from "react/jsx-runtime";
2
2
  import r from "prop-types";
3
- import { createContext as K, useState as x, use as O, useRef as D, useEffect as Q } from "react";
4
- import V from "@arcblock/react-hooks/lib/useBrowser";
5
- import { useUpdate as X, useCreation as s, useMemoizedFn as S, useLatest as Y, useReactive as Z, useSize as _ } from "ahooks";
6
- import E from "lodash/isUndefined";
7
- import $ from "lodash/noop";
8
- import { Box as ee } from "@mui/material";
9
- import { translate as te } from "@arcblock/ux/lib/Locale/util";
10
- import { getMaster as R, getCurrentApp as oe } from "@arcblock/ux/lib/Util/federated";
11
- import { getDIDMotifInfo as re } from "@arcblock/did-motif";
12
- import { isEthereumDid as ne, getDIDColor as ie } from "@arcblock/ux/lib/Util";
13
- import se from "../hooks/use-apps.js";
14
- import { SessionContext as pe } from "../../Session/context.js";
15
- import ce from "../assets/locale.js";
16
- const T = K({
3
+ import { createContext as V, useState as S, use as E, useRef as W, useEffect as X } from "react";
4
+ import Y from "@arcblock/react-hooks/lib/useBrowser";
5
+ import { useUpdate as Z, useCreation as i, useMemoizedFn as h, useLatest as _, useReactive as $, useSize as ee } from "ahooks";
6
+ import x from "lodash/isUndefined";
7
+ import te from "lodash/noop";
8
+ import { Box as oe } from "@mui/material";
9
+ import { translate as re } from "@arcblock/ux/lib/Locale/util";
10
+ import { getMaster as D, getCurrentApp as ne } from "@arcblock/ux/lib/Util/federated";
11
+ import { getDIDMotifInfo as se } from "@arcblock/did-motif";
12
+ import { isEthereumDid as ie, getDIDColor as pe } from "@arcblock/ux/lib/Util";
13
+ import ce from "../hooks/use-apps.js";
14
+ import { SessionContext as ue } from "../../Session/context.js";
15
+ import de from "../assets/locale.js";
16
+ const R = V({
17
17
  isWalletWebview: !1,
18
18
  isMobile: !1,
19
19
  matchSmallScreen: !1,
20
20
  blocklet: null
21
- }), { Provider: ue, Consumer: Ie } = T;
22
- function de({
23
- children: W,
21
+ }), { Provider: ae, Consumer: We } = R;
22
+ function le({
23
+ children: T,
24
24
  blocklet: p,
25
- masterBlocklet: h = void 0,
25
+ masterBlocklet: P = void 0,
26
26
  action: d,
27
27
  extraParams: t = {},
28
28
  locale: a = "en",
29
- testOnlyBorderColor: f = void 0,
29
+ testOnlyBorderColor: l = void 0,
30
30
  ...j
31
31
  }) {
32
- const P = X(), [l, q] = x([]), [m, z] = x(""), J = s(() => new Map(l.map((e) => [e.name, e])), [l]), N = S((e) => J.get(e)), U = Y(m), k = S((e, i = {}) => te(ce, e, a, "en", i)), g = O(pe), o = Z({
32
+ const w = Z(), [f, q] = S([]), [z, J] = S(!1), [m, N] = S(""), U = i(() => new Map(f.map((e) => [e.name, e])), [f]), k = h((e) => U.get(e)), B = _(m), L = h((e, s = {}) => re(de, e, a, "en", s)), g = E(ue), o = $({
33
33
  sourceAppPid: void 0,
34
34
  status: "created",
35
35
  autoActiveWebview: !0,
36
36
  deeplink: void 0,
37
37
  chooseMethod: "",
38
- retryConnect: $
39
- }), B = D({
38
+ retryConnect: te
39
+ }), F = W({
40
40
  cancelCount: 0
41
- }), n = V(), { appInfoList: w, autoGenerateSourceAppPid: A, canSwitchApp: b } = se({
41
+ }), n = Y(), { appInfoList: b, autoGenerateSourceAppPid: A, canSwitchApp: v } = ce({
42
42
  blocklet: p,
43
43
  connectState: o,
44
44
  action: d,
45
45
  sourceAppPid: t?.sourceAppPid,
46
46
  enableSwitchApp: t?.forceSwitch || t?.enableSwitchApp
47
- }), v = D(null), C = _(v), M = s(() => (C?.width || 0) < 500, [C?.width]), c = s(() => {
48
- if (b)
47
+ }), C = W(null), M = ee(C), y = i(() => (M?.width || 0) < 500, [M?.width]), c = i(() => {
48
+ if (v)
49
49
  return {
50
50
  ...t,
51
- sourceAppPid: E(o.sourceAppPid) ? A : o.sourceAppPid
51
+ sourceAppPid: x(o.sourceAppPid) ? A : o.sourceAppPid
52
52
  };
53
- const e = R(p)?.appPid, i = R(globalThis.blocklet)?.appPid;
54
- return g?.session?.user && (e === i || !e) ? E(t?.sourceAppPid) ? {
53
+ const e = D(p)?.appPid, s = D(globalThis.blocklet)?.appPid;
54
+ return g?.session?.user && (e === s || !e) ? x(t?.sourceAppPid) ? {
55
55
  ...t,
56
56
  sourceAppPid: g.session.user?.sourceAppPid
57
57
  } : t : {
@@ -59,70 +59,73 @@ function de({
59
59
  sourceAppPid: A
60
60
  };
61
61
  }, [
62
- b,
62
+ v,
63
63
  t,
64
64
  o.sourceAppPid,
65
65
  d,
66
66
  A,
67
67
  g?.session?.user
68
- ]), L = s(() => {
68
+ ]), G = i(() => {
69
69
  const e = window?.navigator?.userAgent;
70
70
  return e.indexOf("Edge") > -1 || e.indexOf("Edg") > -1 ? "edge" : e.indexOf("Chrome") > -1 ? "chrome" : "unknown";
71
71
  }, []);
72
- Q(() => {
72
+ X(() => {
73
73
  o.sourceAppPid = c.sourceAppPid;
74
74
  }, [c.sourceAppPid]);
75
- const F = S((e) => {
75
+ const H = h((e) => {
76
76
  o.status = e || "created";
77
- }), u = globalThis.blocklet ? oe(p) : globalThis.env, y = s(() => {
78
- if (f)
79
- return f;
80
- const e = u.appPid, i = ne(e), H = i ? void 0 : re(e);
81
- return i ? ie(e) : H.color;
82
- }, [u.appId, f]), G = s(() => ({
77
+ }), u = globalThis.blocklet ? ne(p) : globalThis.env, I = i(() => {
78
+ if (l)
79
+ return l;
80
+ const e = u.appPid, s = ie(e), Q = s ? void 0 : se(e);
81
+ return s ? pe(e) : Q.color;
82
+ }, [u.appId, l]), K = i(() => ({
83
83
  isWalletWebview: n.wallet || n.arcSphere,
84
84
  isMobile: n.mobile.any,
85
- matchSmallScreen: M,
85
+ matchSmallScreen: y,
86
86
  connectState: o,
87
- staticState: B,
87
+ staticState: F,
88
88
  reactiveState: o,
89
- appInfoList: w,
89
+ appInfoList: b,
90
90
  extraParams: c,
91
91
  blocklet: p,
92
- masterBlocklet: h,
93
- browserBrand: L,
92
+ masterBlocklet: P,
93
+ browserBrand: G,
94
94
  currentAppInfo: u,
95
- currentAppColor: y,
96
- t: k,
95
+ currentAppColor: I,
96
+ t: L,
97
97
  locale: a,
98
98
  action: d,
99
- changeStatus: F,
100
- getPlugin: N,
101
- latestActivePlugin: U,
102
- plugins: l,
99
+ changeStatus: H,
100
+ getPlugin: k,
101
+ latestActivePlugin: B,
102
+ plugins: f,
103
103
  setPlugins: q,
104
104
  selectedPlugin: m,
105
- setSelectedPlugin: z,
106
- forceUpdate: P
105
+ setSelectedPlugin: N,
106
+ forceUpdate: w,
107
+ // 控制钱包登录的显示
108
+ showWalletOptions: z,
109
+ setShowWalletOptions: J
107
110
  }), [
108
111
  n.wallet,
109
112
  n.arcSphere,
110
113
  n.mobile.any,
111
- M,
114
+ y,
112
115
  JSON.stringify(o),
113
- JSON.stringify(w),
116
+ JSON.stringify(b),
114
117
  JSON.stringify(c),
115
118
  p,
116
- h,
119
+ P,
117
120
  a,
118
121
  m,
119
- P,
122
+ w,
120
123
  u,
121
- y
124
+ I
122
125
  ]);
123
- return /* @__PURE__ */ I(ue, { value: G, children: /* @__PURE__ */ I(ee, { ...j, ref: v, children: W }) });
126
+ return /* @__PURE__ */ O(ae, { value: K, children: /* @__PURE__ */ O(oe, { ...j, ref: C, children: T }) });
124
127
  }
125
- de.propTypes = {
128
+ le.propTypes = {
126
129
  children: r.any.isRequired,
127
130
  blocklet: r.object.isRequired,
128
131
  masterBlocklet: r.object,
@@ -132,11 +135,11 @@ de.propTypes = {
132
135
  testOnlyBorderColor: r.string
133
136
  };
134
137
  function xe() {
135
- return O(T);
138
+ return E(R);
136
139
  }
137
140
  export {
138
- Ie as StateConsumer,
139
- T as StateContext,
140
- de as StateProvider,
141
+ We as StateConsumer,
142
+ R as StateContext,
143
+ le as StateProvider,
141
144
  xe as useStateContext
142
145
  };