@coinbase/cdp-react 0.0.86 → 0.0.88

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 (113) hide show
  1. package/dist/assets/CDPReactProvider.css +1 -1
  2. package/dist/assets/EnrollMfaFlow.css +1 -1
  3. package/dist/assets/VerifyMfaFlow.css +1 -1
  4. package/dist/assets/VerifyMfaFlowBackButton.css +1 -0
  5. package/dist/assets/VerifyMfaInline.css +1 -1
  6. package/dist/assets/VerifyMfaItem.css +1 -0
  7. package/dist/assets/VerifyMfaItems.css +1 -0
  8. package/dist/assets/sms.css +1 -0
  9. package/dist/chunks/CDPReactProvider.BkmtXUv1.js +337 -0
  10. package/dist/chunks/{LinkAuthFlow.BaUSMzGH.js → LinkAuthFlow.B4FAtf4V.js} +13 -13
  11. package/dist/chunks/index.BX4k-ruQ.js +12 -0
  12. package/dist/chunks/index.Bgx0-QLY.js +12 -0
  13. package/dist/chunks/{index.C_DV0Ud7.js → index.DgrgIsTX.js} +1 -1
  14. package/dist/chunks/useSendComponentCallOnce.DGjALrnZ.js +278 -0
  15. package/dist/components/AuthButton/index.js +1 -1
  16. package/dist/components/CDPReactProvider/index.js +1 -1
  17. package/dist/components/CopyEvmKeyButton/index.js +1 -1
  18. package/dist/components/CopySolanaKeyButton/index.js +1 -1
  19. package/dist/components/EnrollMfa/EnrollMfaDescription.js +4 -3
  20. package/dist/components/EnrollMfa/EnrollMfaFlow.js +27 -26
  21. package/dist/components/EnrollMfa/EnrollMfaFlowBackButton.js +7 -6
  22. package/dist/components/EnrollMfa/EnrollMfaFlowProvider.d.ts +1 -1
  23. package/dist/components/EnrollMfa/EnrollMfaFlowProvider.js +5 -4
  24. package/dist/components/EnrollMfa/EnrollMfaImage.js +7 -6
  25. package/dist/components/EnrollMfa/EnrollMfaItem.js +7 -6
  26. package/dist/components/EnrollMfa/EnrollMfaItems.js +28 -25
  27. package/dist/components/EnrollMfa/EnrollMfaProvider.js +22 -17
  28. package/dist/components/EnrollMfa/EnrollMfaTitle.js +8 -7
  29. package/dist/components/EnrollMfa/index.js +134 -128
  30. package/dist/components/EnrollMfa/methods/sms.d.ts +6 -0
  31. package/dist/components/EnrollMfa/methods/sms.js +148 -0
  32. package/dist/components/EnrollMfa/methods/totp.js +24 -19
  33. package/dist/components/EnrollMfa/types.d.ts +17 -5
  34. package/dist/components/EnrollMfa/types.js +1 -0
  35. package/dist/components/EnrollMfa/useEnrollMfaReducer.js +51 -38
  36. package/dist/components/EnrollMfaModal/index.js +2 -2
  37. package/dist/components/ExportWallet/index.js +109 -101
  38. package/dist/components/ExportWalletModal/index.js +2 -2
  39. package/dist/components/Fund/index.js +2 -2
  40. package/dist/components/FundModal/index.js +2 -2
  41. package/dist/components/LinkAuth/LinkAuthFlow.js +2 -2
  42. package/dist/components/LinkAuth/LinkAuthFlowBackButton.js +2 -2
  43. package/dist/components/LinkAuth/LinkAuthFlowProvider.js +2 -2
  44. package/dist/components/LinkAuth/LinkAuthItem.js +1 -1
  45. package/dist/components/LinkAuth/LinkAuthItems.js +1 -1
  46. package/dist/components/LinkAuth/LinkAuthProvider.js +1 -1
  47. package/dist/components/LinkAuth/index.js +4 -4
  48. package/dist/components/LinkAuth/types.js +1 -1
  49. package/dist/components/LinkAuth/utils.js +1 -1
  50. package/dist/components/LinkAuthModal/index.js +3 -3
  51. package/dist/components/OAuthStatusModal/index.js +2 -2
  52. package/dist/components/SendEvmTransactionButton/index.js +1 -1
  53. package/dist/components/SendSolanaTransactionButton/index.js +1 -1
  54. package/dist/components/SignIn/SignInAuthMethodButtons.js +1 -1
  55. package/dist/components/SignIn/SignInBackButton.js +12 -12
  56. package/dist/components/SignIn/SignInDescription.js +2 -2
  57. package/dist/components/SignIn/SignInForm.js +2 -2
  58. package/dist/components/SignIn/SignInImage.js +1 -1
  59. package/dist/components/SignIn/SignInProvider.js +1 -1
  60. package/dist/components/SignIn/SignInTitle.js +2 -2
  61. package/dist/components/SignIn/flows/SignInWithEmail.js +1 -1
  62. package/dist/components/SignIn/flows/SignInWithOAuth.js +1 -1
  63. package/dist/components/SignIn/flows/SignInWithSms.js +74 -84
  64. package/dist/components/SignIn/index.js +2 -2
  65. package/dist/components/SignIn/types.d.ts +2 -0
  66. package/dist/components/SignIn/types.js +1 -1
  67. package/dist/components/SignIn/useSignInReducer.js +20 -6
  68. package/dist/components/SignInModal/index.js +2 -2
  69. package/dist/components/SignOutButton/index.js +1 -1
  70. package/dist/components/VerifyMfa/VerifyMfaDescription.d.ts +1 -1
  71. package/dist/components/VerifyMfa/VerifyMfaDescription.js +24 -14
  72. package/dist/components/VerifyMfa/VerifyMfaFlow.d.ts +5 -4
  73. package/dist/components/VerifyMfa/VerifyMfaFlow.js +52 -13
  74. package/dist/components/VerifyMfa/VerifyMfaFlowBackButton.d.ts +9 -0
  75. package/dist/components/VerifyMfa/VerifyMfaFlowBackButton.js +40 -0
  76. package/dist/components/VerifyMfa/VerifyMfaFlowProvider.d.ts +23 -0
  77. package/dist/components/VerifyMfa/VerifyMfaFlowProvider.js +37 -0
  78. package/dist/components/VerifyMfa/VerifyMfaImage.d.ts +1 -1
  79. package/dist/components/VerifyMfa/VerifyMfaImage.js +25 -13
  80. package/dist/components/VerifyMfa/VerifyMfaItem.d.ts +10 -0
  81. package/dist/components/VerifyMfa/VerifyMfaItem.js +27 -0
  82. package/dist/components/VerifyMfa/VerifyMfaItems.d.ts +9 -0
  83. package/dist/components/VerifyMfa/VerifyMfaItems.js +31 -0
  84. package/dist/components/VerifyMfa/VerifyMfaProvider.js +27 -14
  85. package/dist/components/VerifyMfa/VerifyMfaTitle.d.ts +1 -1
  86. package/dist/components/VerifyMfa/VerifyMfaTitle.js +23 -13
  87. package/dist/components/VerifyMfa/index.d.ts +6 -2
  88. package/dist/components/VerifyMfa/index.js +24 -15
  89. package/dist/components/VerifyMfa/methods/sms.d.ts +6 -0
  90. package/dist/components/VerifyMfa/methods/sms.js +90 -0
  91. package/dist/components/VerifyMfa/methods/totp.js +40 -39
  92. package/dist/components/VerifyMfa/types.d.ts +21 -2
  93. package/dist/components/VerifyMfa/types.js +1 -0
  94. package/dist/components/VerifyMfa/useVerifyMfaReducer.d.ts +2 -1
  95. package/dist/components/VerifyMfa/useVerifyMfaReducer.js +29 -4
  96. package/dist/components/VerifyMfaInline/index.d.ts +1 -1
  97. package/dist/components/VerifyMfaInline/index.js +133 -116
  98. package/dist/components/VerifyMfaModal/index.js +8 -6
  99. package/dist/components/ui/SwitchTransition/index.js +3 -3
  100. package/dist/hooks/usePhoneNumberState.d.ts +15 -0
  101. package/dist/hooks/usePhoneNumberState.js +39 -0
  102. package/dist/hooks/useTransitionMap.js +24 -22
  103. package/dist/hooks/useVerifyMfaModal.js +2 -2
  104. package/dist/index.js +60 -52
  105. package/dist/utils/transition.d.ts +3 -3
  106. package/dist/utils/transition.js +21 -20
  107. package/dist/version.d.ts +1 -1
  108. package/dist/version.js +1 -1
  109. package/package.json +6 -6
  110. package/dist/chunks/CDPReactProvider.CIQm4C4z.js +0 -299
  111. package/dist/chunks/index.CKQKBoX2.js +0 -9
  112. package/dist/chunks/index.Dp-lIxM1.js +0 -9
  113. package/dist/chunks/useSendComponentCallOnce.BHZMuo6E.js +0 -273
@@ -1,24 +1,29 @@
1
- import { jsx as i } from "react/jsx-runtime";
2
- import { createContext as u, useContext as a, useMemo as f } from "react";
1
+ import { jsx as f } from "react/jsx-runtime";
2
+ import { createContext as s, useContext as a, useEffect as u, useMemo as c } from "react";
3
+ import "@coinbase/cdp-core";
3
4
  import "@coinbase/cdp-hooks";
4
- import { useEnrollMfaReducer as m } from "./useEnrollMfaReducer.js";
5
- const n = u(null), p = () => {
6
- const t = a(n);
7
- if (!t)
5
+ import { useEnrollMfaReducer as p } from "./useEnrollMfaReducer.js";
6
+ const i = s(null), C = () => {
7
+ const o = a(i);
8
+ if (!o)
8
9
  throw new Error("useEnrollMfaContext must be used within EnrollMfaProvider");
9
- return t;
10
- }, E = ({
11
- children: t,
12
- onEnrollSuccess: o,
13
- methods: s
10
+ return o;
11
+ }, v = ({
12
+ children: o,
13
+ onEnrollSuccess: n,
14
+ methods: t
14
15
  }) => {
15
- const [r, e] = m(s), l = f(
16
- () => ({ state: r, dispatch: e, onEnrollSuccess: o }),
17
- [r, e, o]
16
+ const [r, e] = p(t);
17
+ u(() => {
18
+ t && t.join(",") !== r.methods.join(",") && e({ type: "SET_METHODS", payload: { methods: t } });
19
+ }, [t, e, r.methods]);
20
+ const l = c(
21
+ () => ({ state: r, dispatch: e, onEnrollSuccess: n }),
22
+ [r, e, n]
18
23
  );
19
- return /* @__PURE__ */ i(n.Provider, { value: l, children: t });
24
+ return /* @__PURE__ */ f(i.Provider, { value: l, children: o });
20
25
  };
21
26
  export {
22
- E as EnrollMfaProvider,
23
- p as useEnrollMfaContext
27
+ v as EnrollMfaProvider,
28
+ C as useEnrollMfaContext
24
29
  };
@@ -1,21 +1,22 @@
1
1
  import { jsx as t, Fragment as h } from "react/jsx-runtime";
2
2
  import "react";
3
3
  import { useEnrollMfaContext as p } from "./EnrollMfaProvider.js";
4
- import { m as f } from "../../chunks/index.CKQKBoX2.js";
4
+ import { m as f } from "../../chunks/index.Bgx0-QLY.js";
5
+ import "@coinbase/cdp-core";
5
6
  import "@coinbase/cdp-hooks";
6
7
  import '../../assets/EnrollMfaTitle.css';const g = "EnrollMfaTitle-module__heading___ogrZZ", u = {
7
8
  heading: g
8
- }, y = ({
9
- as: s = "h2",
10
- children: i,
11
- className: r = "",
9
+ }, C = ({
10
+ as: i = "h2",
11
+ children: r,
12
+ className: s = "",
12
13
  method: l,
13
14
  step: m,
14
15
  ...a
15
16
  }) => {
16
17
  const { state: o } = p(), e = m || o.step, n = l || o.method, c = f[n].title, d = e === "list" ? /* @__PURE__ */ t(h, { children: "Add multi-factor authentication" }) : /* @__PURE__ */ t(c, { step: e, method: n });
17
- return /* @__PURE__ */ t(s, { className: `${u.heading} ${r}`, ...a, children: i ?? d });
18
+ return /* @__PURE__ */ t(i, { className: `${u.heading} ${s}`, ...a, children: r ?? d });
18
19
  };
19
20
  export {
20
- y as EnrollMfaTitle
21
+ C as EnrollMfaTitle
21
22
  };
@@ -1,180 +1,186 @@
1
- import { jsx as o, jsxs as a, Fragment as E } from "react/jsx-runtime";
2
- import { useIsInitialized as B, useCurrentUser as P, useInitiateMfaEnrollment as b, useSubmitMfaEnrollment as D, useRecordMfaEnrollmentPrompted as $ } from "@coinbase/cdp-hooks";
3
- import { u as k } from "../../chunks/useSendComponentCallOnce.BHZMuo6E.js";
4
- import { useMemo as V, useRef as p, useEffect as R, useCallback as d, useLayoutEffect as j } from "react";
5
- import { c as z } from "../../chunks/lite.1fxw3LjI.js";
6
- import { u as J } from "../../chunks/CDPReactProvider.CIQm4C4z.js";
7
- import { useTimeout as K } from "../../hooks/useTimeout.js";
8
- import { isApiError as q } from "../../utils/isApiError.js";
1
+ import { jsx as r, jsxs as s, Fragment as u } from "react/jsx-runtime";
2
+ import { getEnabledMfaMethods as $, getEnrolledMfaMethods as k } from "@coinbase/cdp-core";
3
+ import { useCurrentUser as w, useIsInitialized as V, useInitiateMfaEnrollment as j, useSubmitMfaEnrollment as z, useRecordMfaEnrollmentPrompted as q } from "@coinbase/cdp-hooks";
4
+ import { u as J } from "../../chunks/useSendComponentCallOnce.DGjALrnZ.js";
5
+ import { useMemo as C, useRef as _, useEffect as v, useCallback as p, useLayoutEffect as K } from "react";
6
+ import { c as G } from "../../chunks/lite.1fxw3LjI.js";
7
+ import { u as X } from "../../chunks/CDPReactProvider.BkmtXUv1.js";
8
+ import { useTimeout as Y } from "../../hooks/useTimeout.js";
9
+ import { isApiError as Z } from "../../utils/isApiError.js";
9
10
  import "libphonenumber-js";
10
- import { EnrollMfaDescription as x } from "./EnrollMfaDescription.js";
11
- import { EnrollMfaFlow as G } from "./EnrollMfaFlow.js";
12
- import { EnrollMfaFlowBackButton as X } from "./EnrollMfaFlowBackButton.js";
13
- import { EnrollMfaFlowProvider as Y } from "./EnrollMfaFlowProvider.js";
14
- import { useEnrollMfaFlow as xe } from "./EnrollMfaFlowProvider.js";
15
- import { EnrollMfaFooter as Z } from "./EnrollMfaFooter.js";
16
- import { EnrollMfaImage as H } from "./EnrollMfaImage.js";
17
- import { EnrollMfaItem as Ue } from "./EnrollMfaItem.js";
18
- import { EnrollMfaItems as Fe } from "./EnrollMfaItems.js";
19
- import { EnrollMfaProvider as Q, useEnrollMfaContext as U } from "./EnrollMfaProvider.js";
20
- import { EnrollMfaTitle as C } from "./EnrollMfaTitle.js";
21
- import { Banner as W } from "../ui/Banner/index.js";
22
- import '../../assets/EnrollMfa.css';const ee = "EnrollMfa-module__img___JmjV1", te = "EnrollMfa-module__centered___YxB8I", re = "EnrollMfa-module__footer___Zro3u", l = {
11
+ import { EnrollMfaDescription as O } from "./EnrollMfaDescription.js";
12
+ import { EnrollMfaFlow as H } from "./EnrollMfaFlow.js";
13
+ import { EnrollMfaFlowBackButton as Q } from "./EnrollMfaFlowBackButton.js";
14
+ import { EnrollMfaFlowProvider as W } from "./EnrollMfaFlowProvider.js";
15
+ import { useEnrollMfaFlow as Fe } from "./EnrollMfaFlowProvider.js";
16
+ import { EnrollMfaFooter as ee } from "./EnrollMfaFooter.js";
17
+ import { EnrollMfaImage as te } from "./EnrollMfaImage.js";
18
+ import { EnrollMfaItem as Pe } from "./EnrollMfaItem.js";
19
+ import { EnrollMfaItems as De } from "./EnrollMfaItems.js";
20
+ import { EnrollMfaProvider as oe, useEnrollMfaContext as A } from "./EnrollMfaProvider.js";
21
+ import { EnrollMfaTitle as U } from "./EnrollMfaTitle.js";
22
+ import { m as re } from "../../chunks/index.Bgx0-QLY.js";
23
+ import { Banner as ne } from "../ui/Banner/index.js";
24
+ import '../../assets/EnrollMfa.css';const le = "EnrollMfa-module__img___JmjV1", ae = "EnrollMfa-module__centered___YxB8I", ie = "EnrollMfa-module__footer___Zro3u", a = {
23
25
  "mfa-enrollment": "EnrollMfa-module__mfa-enrollment___80xnL",
24
- img: ee,
26
+ img: le,
25
27
  "flex-container": "EnrollMfa-module__flex-container___9Dazs",
26
28
  "gap-2": "EnrollMfa-module__gap-2___BKEqR",
27
29
  "gap-3": "EnrollMfa-module__gap-3___JKVyF",
28
- centered: te,
29
- footer: re
30
- }, oe = 5 * 60 * 1e3, ne = ({ role: c = "alert", ...i }) => {
31
- const { state: s } = U(), { error: m } = s;
32
- return m ? /* @__PURE__ */ o(W, { variant: "error", role: c, ...i, children: q(m) ? m.message : m }) : null;
33
- }, le = ({
34
- className: c = "",
35
- children: i,
36
- resetOnSuccess: s = !0,
37
- ...m
30
+ centered: ae,
31
+ footer: ie
32
+ }, se = 5 * 60 * 1e3, me = ({ role: d = "alert", ...m }) => {
33
+ const { state: i } = A(), { error: l } = i;
34
+ return l ? /* @__PURE__ */ r(ne, { variant: "error", role: d, ...m, children: Z(l) ? l.message : l }) : null;
35
+ }, ce = ({
36
+ className: d = "",
37
+ children: m,
38
+ resetOnSuccess: i = !0,
39
+ ...l
38
40
  }) => {
39
- const { isInitialized: f } = B(), { currentUser: u } = P(), { state: e, dispatch: n, onEnrollSuccess: _ } = U(), { initiateMfaEnrollment: M } = b(), { submitMfaEnrollment: h } = D(), { recordMfaEnrollmentPrompted: I } = $(), { showCoinbaseFooter: v } = J(), N = p(!1);
40
- R(() => {
41
- !f || !u || N.current || (I(), N.current = !0);
42
- }, [I, f, u]), R(() => {
41
+ const { isInitialized: c } = V(), { currentUser: E } = w(), { state: e, dispatch: o, onEnrollSuccess: M } = A(), { initiateMfaEnrollment: h } = j(), { submitMfaEnrollment: I } = z(), { recordMfaEnrollmentPrompted: S } = q(), { showCoinbaseFooter: F } = X(), g = _(!1), y = !!E;
42
+ v(() => {
43
+ !c || !y || g.current || (S(), g.current = !0);
44
+ }, [S, c, y]), v(() => {
43
45
  if (!e.initiatedAt) return;
44
46
  const t = () => {
45
- e.initiatedAt && Date.now() - e.initiatedAt >= oe && n({ type: "ENROLLMENT_SESSION_EXPIRED" });
47
+ e.initiatedAt && Date.now() - e.initiatedAt >= se && o({ type: "ENROLLMENT_SESSION_EXPIRED" });
46
48
  };
47
49
  t();
48
- const r = setInterval(t, 1e3);
49
- return () => clearInterval(r);
50
- }, [e.initiatedAt, n]);
51
- const S = p(e.step), T = p(null), { schedule: y } = K(), g = d((t) => {
52
- S.current !== t && (S.current = t, T.current?.transition.toggle(t));
53
- }, []), F = d(() => {
54
- n({ type: "GO_TO_PREVIOUS_STEP" });
55
- }, [n]), w = d(
50
+ const n = setInterval(t, 1e3);
51
+ return () => clearInterval(n);
52
+ }, [e.initiatedAt, o]);
53
+ const T = _(e.step), N = _(null), { schedule: L } = Y(), R = p((t) => {
54
+ T.current !== t && (T.current = t, N.current?.transition.toggle(t));
55
+ }, []), B = p(() => {
56
+ o({ type: "GO_TO_PREVIOUS_STEP" });
57
+ }, [o]), P = p(
56
58
  async (t) => {
57
- if (f) {
58
- n({ type: "INITIATE_ENROLLMENT", payload: { method: t } });
59
- try {
60
- const r = await M({ mfaMethod: t });
61
- if ("authUrl" in r && "secret" in r)
62
- n({
63
- type: "INITIATE_ENROLLMENT_SUCCESS",
64
- payload: { authUrl: r.authUrl, secret: r.secret }
65
- });
66
- else
67
- throw new Error("Failed to initiate enrollment");
68
- } catch (r) {
69
- n({
70
- type: "INITIATE_ENROLLMENT_FAILURE",
71
- payload: {
72
- error: r instanceof Error ? r.message : "Failed to initiate enrollment"
73
- }
74
- });
75
- }
59
+ if (!c) return;
60
+ const n = re[t];
61
+ if (n.requiresInput && e.step !== "setup") {
62
+ o({
63
+ type: "SET_STEP",
64
+ payload: { step: "setup", flowDirection: "left", method: t }
65
+ });
66
+ return;
67
+ }
68
+ o({ type: "INITIATE_ENROLLMENT", payload: { method: t } });
69
+ try {
70
+ const f = n.getInitiateOptions(e), D = await h(f);
71
+ o({ type: "INITIATE_ENROLLMENT_SUCCESS", payload: D });
72
+ } catch (f) {
73
+ o({
74
+ type: "INITIATE_ENROLLMENT_FAILURE",
75
+ payload: {
76
+ error: f instanceof Error ? f.message : "Failed to initiate enrollment"
77
+ }
78
+ });
76
79
  }
77
80
  },
78
- [n, M, f]
79
- ), A = d(
81
+ [o, h, c, e]
82
+ ), b = p(
80
83
  async (t) => {
81
- t.preventDefault(), n({ type: "SUBMIT_ENROLLMENT" });
84
+ t.preventDefault(), o({ type: "SUBMIT_ENROLLMENT" });
82
85
  try {
83
- await h({
86
+ await I({
84
87
  mfaMethod: e.method,
85
88
  mfaCode: e.mfaCode
86
- }), n({ type: "SUBMIT_ENROLLMENT_SUCCESS" }), _?.(), s && y(() => {
87
- n({ type: "SET_STEP", payload: { step: "list", flowDirection: "left" } });
89
+ }), o({ type: "SUBMIT_ENROLLMENT_SUCCESS" }), M?.(), i && L(() => {
90
+ o({ type: "SET_STEP", payload: { step: "list", flowDirection: "left" } });
88
91
  }, 800);
89
- } catch (r) {
90
- n({
92
+ } catch (n) {
93
+ o({
91
94
  type: "SUBMIT_ENROLLMENT_FAILURE",
92
95
  payload: {
93
- error: r instanceof Error ? r.message : "Verification failed"
96
+ error: n instanceof Error ? n.message : "Verification failed"
94
97
  }
95
98
  });
96
99
  }
97
100
  },
98
101
  [
99
- n,
102
+ o,
100
103
  e.method,
101
104
  e.mfaCode,
102
- h,
103
- _,
104
- s,
105
- y
105
+ I,
106
+ M,
107
+ i,
108
+ L
106
109
  ]
107
110
  );
108
- j(() => {
109
- g(e.step);
110
- }, [e.step, g]);
111
- const L = typeof i == "function" ? i(e) : i;
112
- return /* @__PURE__ */ o(
113
- Y,
111
+ K(() => {
112
+ R(e.step);
113
+ }, [e.step, R]);
114
+ const x = typeof m == "function" ? m(e) : m;
115
+ return /* @__PURE__ */ r(
116
+ W,
114
117
  {
115
- onBack: F,
116
- onStartEnrollment: w,
117
- onSubmit: A,
118
- transitionRef: T,
119
- children: /* @__PURE__ */ a("div", { className: `${l["mfa-enrollment"]} ${c}`, ...m, children: [
120
- L,
121
- !L && /* @__PURE__ */ a(E, { children: [
122
- /* @__PURE__ */ a(
118
+ onBack: B,
119
+ onStartEnrollment: P,
120
+ onSubmit: b,
121
+ transitionRef: N,
122
+ children: /* @__PURE__ */ s("div", { className: `${a["mfa-enrollment"]} ${d}`, ...l, children: [
123
+ x,
124
+ !x && /* @__PURE__ */ s(u, { children: [
125
+ /* @__PURE__ */ s(
123
126
  "div",
124
127
  {
125
- className: z(
126
- l["flex-container"],
127
- e.step === "list" ? l["gap-3"] : ""
128
+ className: G(
129
+ a["flex-container"],
130
+ e.step === "list" ? a["gap-3"] : ""
128
131
  ),
129
132
  children: [
130
- e.step === "list" ? /* @__PURE__ */ a(E, { children: [
131
- /* @__PURE__ */ a("div", { children: [
132
- /* @__PURE__ */ o(C, { step: "list", method: e.method }),
133
- /* @__PURE__ */ o(x, { step: "list", method: e.method })
133
+ e.step === "list" ? /* @__PURE__ */ s(u, { children: [
134
+ /* @__PURE__ */ s("div", { children: [
135
+ /* @__PURE__ */ r(U, { step: "list", method: e.method }),
136
+ /* @__PURE__ */ r(O, { step: "list", method: e.method })
134
137
  ] }),
135
- /* @__PURE__ */ o(ne, {})
136
- ] }) : /* @__PURE__ */ o("div", { children: /* @__PURE__ */ o(X, { step: e.step }) }),
137
- /* @__PURE__ */ o(G, { children: ({ step: t, method: r, Content: O }) => /* @__PURE__ */ a("div", { className: `${l["flex-container"]} ${l["gap-2"]}`, children: [
138
- t !== "list" && /* @__PURE__ */ a(E, { children: [
139
- /* @__PURE__ */ o(
140
- H,
138
+ /* @__PURE__ */ r(me, {})
139
+ ] }) : /* @__PURE__ */ r("div", { children: /* @__PURE__ */ r(Q, { step: e.step }) }),
140
+ /* @__PURE__ */ r(H, { children: ({ step: t, method: n, Content: f }) => /* @__PURE__ */ s("div", { className: `${a["flex-container"]} ${a["gap-2"]}`, children: [
141
+ t !== "list" && /* @__PURE__ */ s(u, { children: [
142
+ /* @__PURE__ */ r(
143
+ te,
141
144
  {
142
- className: `${l.img} ${l.centered}`,
145
+ className: `${a.img} ${a.centered}`,
143
146
  step: t,
144
- method: r
147
+ method: n
145
148
  }
146
149
  ),
147
- /* @__PURE__ */ a("div", { className: l.centered, children: [
148
- /* @__PURE__ */ o(C, { step: t, method: r }),
149
- /* @__PURE__ */ o(x, { step: t, method: r })
150
+ /* @__PURE__ */ s("div", { className: a.centered, children: [
151
+ /* @__PURE__ */ r(U, { step: t, method: n }),
152
+ /* @__PURE__ */ r(O, { step: t, method: n })
150
153
  ] })
151
154
  ] }),
152
- O
155
+ f
153
156
  ] }) })
154
157
  ]
155
158
  }
156
159
  ),
157
- v && /* @__PURE__ */ o(Z, { className: l.footer })
160
+ F && /* @__PURE__ */ r(ee, { className: a.footer })
158
161
  ] })
159
162
  ] })
160
163
  }
161
164
  );
162
- }, ge = ({ onEnrollSuccess: c, ...i }) => {
163
- k("enroll_mfa");
164
- const s = V(() => ["totp"], []);
165
- return /* @__PURE__ */ o(Q, { methods: s, onEnrollSuccess: c, children: /* @__PURE__ */ o(le, { ...i }) });
165
+ }, Ue = ({ onEnrollSuccess: d, ...m }) => {
166
+ J("enroll_mfa");
167
+ const { currentUser: i } = w(), l = $(), c = C(
168
+ () => i ? k(i) : [],
169
+ [i]
170
+ ), E = C(() => [.../* @__PURE__ */ new Set([...l, ...c])], [l, c]);
171
+ return /* @__PURE__ */ r(oe, { methods: E, onEnrollSuccess: d, children: /* @__PURE__ */ r(ce, { ...m }) });
166
172
  };
167
173
  export {
168
- ge as EnrollMfa,
169
- x as EnrollMfaDescription,
170
- ne as EnrollMfaError,
171
- G as EnrollMfaFlow,
172
- X as EnrollMfaFlowBackButton,
173
- Z as EnrollMfaFooter,
174
- H as EnrollMfaImage,
175
- Ue as EnrollMfaItem,
176
- Fe as EnrollMfaItems,
177
- C as EnrollMfaTitle,
178
- U as useEnrollMfaContext,
179
- xe as useEnrollMfaFlow
174
+ Ue as EnrollMfa,
175
+ O as EnrollMfaDescription,
176
+ me as EnrollMfaError,
177
+ H as EnrollMfaFlow,
178
+ Q as EnrollMfaFlowBackButton,
179
+ ee as EnrollMfaFooter,
180
+ te as EnrollMfaImage,
181
+ Pe as EnrollMfaItem,
182
+ De as EnrollMfaItems,
183
+ U as EnrollMfaTitle,
184
+ A as useEnrollMfaContext,
185
+ Fe as useEnrollMfaFlow
180
186
  };
@@ -0,0 +1,6 @@
1
+ import { EnrollMfaMethodConfig, EnrollMfaMethodContentProps, EnrollMfaMethodComponentProps } from '../types';
2
+ export declare const SmsContent: ({ autoFocus, step, onSubmit, children, }: EnrollMfaMethodContentProps) => import("react/jsx-runtime").JSX.Element;
3
+ export declare const SmsTitle: ({ step }: EnrollMfaMethodComponentProps) => import("react/jsx-runtime").JSX.Element | null;
4
+ export declare const SmsDescription: ({ step }: EnrollMfaMethodComponentProps) => import("react/jsx-runtime").JSX.Element | null;
5
+ export declare const SmsImage: ({ step }: EnrollMfaMethodComponentProps) => import("react/jsx-runtime").JSX.Element | null;
6
+ export declare const smsMethodConfig: EnrollMfaMethodConfig;
@@ -0,0 +1,148 @@
1
+ import { jsx as t, Fragment as a, jsxs as D } from "react/jsx-runtime";
2
+ import { useState as M, useCallback as i, useEffect as E, useMemo as w } from "react";
3
+ import { OTPForm as x } from "../../forms/OTPForm/index.js";
4
+ import { PhoneNumberForm as F } from "../../forms/PhoneNumberForm/index.js";
5
+ import { Badge as U } from "../../ui/Badge/index.js";
6
+ import { usePhoneNumberState as j } from "../../../hooks/usePhoneNumberState.js";
7
+ import { useTimer as I } from "../../../hooks/useTimer.js";
8
+ import { IconPhone as W } from "../../../icons/IconPhone.js";
9
+ import { formatPhoneNumber as k } from "../../../utils/formatPhoneNumber.js";
10
+ import { useEnrollMfaFlow as A } from "../EnrollMfaFlowProvider.js";
11
+ import { useEnrollMfaContext as _ } from "../EnrollMfaProvider.js";
12
+ import "@coinbase/cdp-core";
13
+ import "@coinbase/cdp-hooks";
14
+ import '../../../assets/sms.css';const L = "sms-module__form___G393d", B = "sms-module__credentials___jMUzc", f = {
15
+ form: L,
16
+ "otp-form": "sms-module__otp-form___yNrQa",
17
+ credentials: B
18
+ }, q = ({
19
+ autoFocus: e = !0,
20
+ step: o,
21
+ onSubmit: m,
22
+ children: h
23
+ }) => {
24
+ const { state: r, dispatch: n } = _(), { startEnrollment: c } = A(), {
25
+ timeRemaining: l,
26
+ start: u,
27
+ reset: N
28
+ } = I(), [p, C] = M(!1), b = i(
29
+ (s) => {
30
+ n({ type: "SET_PHONE_NUMBER", payload: { phoneNumber: s } });
31
+ },
32
+ [n]
33
+ ), { phoneNumberObject: S, countryCode: g, handlePhoneNumberChange: O, handleCountryCodeChange: P } = j({
34
+ phoneNumber: r.phoneNumber,
35
+ onPhoneNumberChange: b
36
+ }), v = i(
37
+ (s) => {
38
+ n({ type: "SET_MFA_CODE", payload: { mfaCode: s } });
39
+ },
40
+ [n]
41
+ ), y = i(() => {
42
+ n({ type: "CLEAR_ERROR" });
43
+ }, [n]), R = i(
44
+ (s) => {
45
+ s.preventDefault(), c("sms");
46
+ },
47
+ [c]
48
+ ), T = i(async () => {
49
+ n({ type: "SET_MFA_CODE", payload: { mfaCode: "" } }), C(!1), u(60), c("sms");
50
+ }, [n, c, u]);
51
+ E(() => {
52
+ o === "setup-verification" && u(60);
53
+ }, [o, u]), E(() => {
54
+ l === 0 && !p && (C(!0), N());
55
+ }, [l, p, N]);
56
+ let d;
57
+ switch (o) {
58
+ case "setup":
59
+ d = /* @__PURE__ */ t(
60
+ F,
61
+ {
62
+ className: f.form,
63
+ autoFocus: e,
64
+ phoneNumber: S,
65
+ countryCode: g,
66
+ onPhoneNumberChange: O,
67
+ onCountryCodeChange: P,
68
+ error: r.error && r.step === "setup" ? r.error : void 0,
69
+ isPending: r.isPending,
70
+ onClearServerErrors: y,
71
+ onSubmit: R,
72
+ submitLabel: "Continue"
73
+ }
74
+ );
75
+ break;
76
+ case "setup-verification":
77
+ d = /* @__PURE__ */ t(
78
+ x,
79
+ {
80
+ className: f["otp-form"],
81
+ autoFocus: e,
82
+ otp: r.mfaCode,
83
+ error: r.error && r.step === "setup-verification" ? r.error : void 0,
84
+ isPending: r.isPending,
85
+ onOTPChange: v,
86
+ onResendOTP: T,
87
+ onSubmit: m,
88
+ passwordLength: 6,
89
+ canResetOTP: p,
90
+ resendCountdown: l,
91
+ successMessage: r.isSuccess ? "Enrolled!" : void 0
92
+ }
93
+ );
94
+ break;
95
+ }
96
+ return h ? /* @__PURE__ */ t(a, { children: h({ step: o, Content: d }) }) : d;
97
+ }, z = ({ step: e }) => {
98
+ switch (e) {
99
+ case "setup":
100
+ return /* @__PURE__ */ t(a, { children: "Enter phone number" });
101
+ case "setup-verification":
102
+ return /* @__PURE__ */ t(a, { children: "Enter verification code" });
103
+ default:
104
+ return null;
105
+ }
106
+ }, G = ({ step: e }) => {
107
+ const { state: o } = _(), m = w(
108
+ () => e === "setup-verification" ? k(o.phoneNumber) : "",
109
+ [o.phoneNumber, e]
110
+ );
111
+ switch (e) {
112
+ case "setup":
113
+ return /* @__PURE__ */ t(a, { children: "We'll send you a verification code via text." });
114
+ case "setup-verification":
115
+ return /* @__PURE__ */ D(a, { children: [
116
+ "Enter the 6 digit code sent to",
117
+ " ",
118
+ m ? /* @__PURE__ */ t("span", { className: f.credentials, children: m }) : "your phone number"
119
+ ] });
120
+ default:
121
+ return null;
122
+ }
123
+ }, H = ({ step: e }) => {
124
+ switch (e) {
125
+ case "setup":
126
+ case "setup-verification":
127
+ return /* @__PURE__ */ t(U, { variant: "secondary", children: /* @__PURE__ */ t(W, {}) });
128
+ default:
129
+ return null;
130
+ }
131
+ }, ie = {
132
+ content: q,
133
+ description: G,
134
+ getInitiateOptions: (e) => ({
135
+ mfaMethod: "sms",
136
+ phoneNumber: e.phoneNumber
137
+ }),
138
+ image: H,
139
+ requiresInput: !0,
140
+ title: z
141
+ };
142
+ export {
143
+ q as SmsContent,
144
+ G as SmsDescription,
145
+ H as SmsImage,
146
+ z as SmsTitle,
147
+ ie as smsMethodConfig
148
+ };
@@ -1,6 +1,6 @@
1
1
  import { jsx as t, jsxs as l, Fragment as i } from "react/jsx-runtime";
2
2
  import { c as u } from "../../../chunks/lite.1fxw3LjI.js";
3
- import { useCallback as a } from "react";
3
+ import { useCallback as c } from "react";
4
4
  import { OTPForm as E } from "../../forms/OTPForm/index.js";
5
5
  import { Badge as C } from "../../ui/Badge/index.js";
6
6
  import { Button as m } from "../../ui/Button/index.js";
@@ -8,8 +8,10 @@ import { CopyTextField as T } from "../../ui/CopyTextField/index.js";
8
8
  import { Error as f } from "../../ui/Error/index.js";
9
9
  import { QRCode as v } from "../../ui/QRCode/index.js";
10
10
  import { IconSmartPhone as k } from "../../../icons/IconSmartPhone.js";
11
- import { useEnrollMfaFlow as S } from "../EnrollMfaFlowProvider.js";
12
- import { useEnrollMfaContext as w } from "../EnrollMfaProvider.js";
11
+ import { isApiError as S } from "../../../utils/isApiError.js";
12
+ import { useEnrollMfaFlow as w } from "../EnrollMfaFlowProvider.js";
13
+ import { useEnrollMfaContext as M } from "../EnrollMfaProvider.js";
14
+ import "@coinbase/cdp-core";
13
15
  import "@coinbase/cdp-hooks";
14
16
  import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F = "totp-module__container___1aL5H", o = {
15
17
  "qr-code": "totp-module__qr-code___qyK1k",
@@ -17,24 +19,24 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
17
19
  container: F,
18
20
  "copy-key": "totp-module__copy-key___iwzZf",
19
21
  "otp-form": "totp-module__otp-form___OzooV"
20
- }, M = ({
22
+ }, b = ({
21
23
  autoFocus: r = !0,
22
- step: c,
24
+ step: a,
23
25
  onSubmit: h,
24
26
  children: p
25
27
  }) => {
26
- const { state: e, dispatch: n } = w(), { startEnrollment: d } = S(), _ = a(() => {
28
+ const { state: e, dispatch: n } = M(), { startEnrollment: d } = w(), _ = c(() => {
27
29
  d(e.method);
28
- }, [d, e.method]), y = a(() => {
30
+ }, [d, e.method]), y = c(() => {
29
31
  n({ type: "SET_STEP", payload: { step: "setup-verification", flowDirection: "left" } });
30
- }, [n]), g = a(
32
+ }, [n]), g = c(
31
33
  (x) => {
32
34
  n({ type: "SET_MFA_CODE", payload: { mfaCode: x } });
33
35
  },
34
36
  [n]
35
37
  );
36
38
  let s;
37
- switch (c) {
39
+ switch (a) {
38
40
  case "setup":
39
41
  s = /* @__PURE__ */ l("div", { className: o.container, children: [
40
42
  /* @__PURE__ */ t("div", { className: u(o["qr-code"], e.isExpired ? o.expired : ""), children: /* @__PURE__ */ t(v, { value: e.authUrl || "", size: 128, ecl: "L" }) }),
@@ -48,7 +50,7 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
48
50
  }
49
51
  ),
50
52
  e.isExpired && /* @__PURE__ */ t(f, { children: "Verification timed out. For your security, try again." }),
51
- !e.isExpired && !!e.error && e.step === "setup" && /* @__PURE__ */ t(f, { children: "isApiError(state.error) ? state.error.message : state.error" })
53
+ !e.isExpired && !!e.error && e.step === "setup" && /* @__PURE__ */ t(f, { children: S(e.error) ? e.error.message : e.error })
52
54
  ] }),
53
55
  e.isExpired ? /* @__PURE__ */ t(
54
56
  m,
@@ -79,8 +81,8 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
79
81
  );
80
82
  break;
81
83
  }
82
- return p ? /* @__PURE__ */ t(i, { children: p({ step: c, Content: s }) }) : s;
83
- }, b = ({ step: r }) => {
84
+ return p ? /* @__PURE__ */ t(i, { children: p({ step: a, Content: s }) }) : s;
85
+ }, O = ({ step: r }) => {
84
86
  switch (r) {
85
87
  case "setup":
86
88
  return /* @__PURE__ */ t(i, { children: "Set up authenticator" });
@@ -105,16 +107,19 @@ import '../../../assets/totp.css';const P = "totp-module__expired___SKiyj", F =
105
107
  default:
106
108
  return null;
107
109
  }
108
- }, H = {
109
- content: M,
110
- title: b,
110
+ }, G = {
111
+ content: b,
112
+ title: O,
111
113
  description: q,
112
- image: A
114
+ image: A,
115
+ getInitiateOptions: () => ({
116
+ mfaMethod: "totp"
117
+ })
113
118
  };
114
119
  export {
115
- M as TotpContent,
120
+ b as TotpContent,
116
121
  q as TotpDescription,
117
122
  A as TotpImage,
118
- b as TotpTitle,
119
- H as totpMethodConfig
123
+ O as TotpTitle,
124
+ G as totpMethodConfig
120
125
  };