@coinbase/cdp-react 0.0.49 → 0.0.51

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 (34) hide show
  1. package/README.md +15 -0
  2. package/dist/chunks/lite.1fxw3LjI.js +7 -0
  3. package/dist/components/AuthButton/index.d.ts +16 -3
  4. package/dist/components/AuthButton/index.js +51 -39
  5. package/dist/components/CDPReactProvider/index.d.ts +1 -1
  6. package/dist/components/CDPReactProvider/index.js +59 -52
  7. package/dist/components/Fund/index.d.ts +1 -1
  8. package/dist/components/Fund/index.js +9 -1
  9. package/dist/components/Fund/types.d.ts +2 -1
  10. package/dist/components/FundModal/index.d.ts +13 -3
  11. package/dist/components/FundModal/index.js +93 -83
  12. package/dist/components/OAuthStatusModal/index.js +39 -37
  13. package/dist/components/SendEvmTransactionButton/index.d.ts +3 -6
  14. package/dist/components/SendEvmTransactionButton/index.js +32 -34
  15. package/dist/components/SendSolanaTransactionButton/index.d.ts +3 -6
  16. package/dist/components/SendSolanaTransactionButton/index.js +28 -30
  17. package/dist/components/SignIn/SignInAuthMethodButtons.js +30 -25
  18. package/dist/components/SignIn/hooks/useSignInWithOAuth.js +12 -12
  19. package/dist/components/SignIn/index.d.ts +2 -3
  20. package/dist/components/SignIn/index.js +32 -32
  21. package/dist/components/SignInModal/index.d.ts +11 -0
  22. package/dist/components/SignInModal/index.js +73 -51
  23. package/dist/components/SignOutButton/index.d.ts +4 -5
  24. package/dist/components/SignOutButton/index.js +23 -10
  25. package/dist/components/ui/Button/index.js +20 -18
  26. package/dist/components/ui/ButtonBase/index.d.ts +1 -0
  27. package/dist/components/ui/ButtonBase/index.js +31 -28
  28. package/dist/components/ui/Modal/index.d.ts +4 -3
  29. package/dist/components/ui/Modal/index.js +26 -22
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.js +105 -92
  32. package/dist/utils/childrenHasComponent.d.ts +2 -0
  33. package/dist/utils/childrenHasComponent.js +13 -0
  34. package/package.json +7 -5
package/README.md CHANGED
@@ -81,6 +81,21 @@ ReactDOM.createRoot(document.getElementById('root')!).render(
81
81
  );
82
82
  ```
83
83
 
84
+ #### Analytics Opt-Out
85
+
86
+ By default the SDK will emit usage analytics to help us improve the SDK. If you would like to opt-out, you can do so by setting the `disableAnalytics` configuration option to `true`.
87
+
88
+ ```tsx lines
89
+ <CDPReactProvider
90
+ config={{
91
+ projectId: "your-project-id",
92
+ disableAnalytics: true,
93
+ }}
94
+ >
95
+ <App />
96
+ </CDPReactProvider>
97
+ ```
98
+
84
99
  ### Render a Component
85
100
 
86
101
  Now you can use the components from the library. Let's add the `AuthButton` component to your application. This component handles both sign-in and sign-out functionality.
@@ -0,0 +1,7 @@
1
+ function a() {
2
+ for (var n, r = 0, t = "", s = arguments.length; r < s; r++) (n = arguments[r]) && typeof n == "string" && (t += (t && " ") + n);
3
+ return t;
4
+ }
5
+ export {
6
+ a as c
7
+ };
@@ -1,8 +1,21 @@
1
- import { HTMLAttributes } from 'react';
2
- export interface AuthButtonProps {
1
+ import { HTMLAttributes, ReactNode } from 'react';
2
+ import { SignInModalProps } from '../SignInModal';
3
+ import { SignOutButtonProps } from '../SignOutButton';
4
+ export type AuthButtonSlots = {
5
+ placeholder?: (props: Pick<HTMLAttributes<HTMLDivElement>, "className">) => ReactNode;
6
+ signOutButton?: (props: Pick<SignOutButtonProps, "onSuccess">) => ReactNode;
7
+ signInModal?: (props: Pick<SignInModalProps, "open" | "setIsOpen" | "onSuccess">) => ReactNode;
8
+ };
9
+ export interface AuthButtonProps extends AuthButtonSlots {
10
+ children?: (props: {
11
+ [key in keyof AuthButtonSlots as Capitalize<key>]: ReactNode;
12
+ } & {
13
+ isInitialized: boolean;
14
+ isSignedIn: boolean;
15
+ }) => ReactNode;
3
16
  closeOnSuccessDelay?: null | number;
4
17
  onSignInSuccess?: () => void;
5
18
  onSignInSuccessTransitionEnd?: () => void;
6
19
  onSignOutSuccess?: () => void;
7
20
  }
8
- export declare const AuthButton: ({ closeOnSuccessDelay, onSignInSuccess, onSignInSuccessTransitionEnd, onSignOutSuccess, ...props }: AuthButtonProps & HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
21
+ export declare const AuthButton: ({ children, closeOnSuccessDelay, onSignInSuccess, onSignInSuccessTransitionEnd, onSignOutSuccess, placeholder, signInModal, signOutButton, ...props }: AuthButtonProps & Omit<HTMLAttributes<HTMLDivElement>, "children">) => import("react/jsx-runtime").JSX.Element;
@@ -1,58 +1,70 @@
1
- import { jsxs as T, jsx as l } from "react/jsx-runtime";
2
- import { useIsInitialized as _, useIsSignedIn as v } from "@coinbase/cdp-hooks";
3
- import { useState as c, useRef as w, useEffect as f } from "react";
4
- import { SignInModal as x } from "../SignInModal/index.js";
5
- import { SignOutButton as y } from "../SignOutButton/index.js";
6
- import { LoadingSkeleton as A } from "../ui/LoadingSkeleton/index.js";
7
- import '../../assets/AuthButton.css';const B = "AuthButton-module__loading___JpDqi", D = {
8
- loading: B
9
- }, L = ({
1
+ import { jsx as u, jsxs as k, Fragment as y } from "react/jsx-runtime";
2
+ import { useIsInitialized as z, useIsSignedIn as D } from "@coinbase/cdp-hooks";
3
+ import { useState as f, useRef as M, useCallback as A, useEffect as m } from "react";
4
+ import { SignInModal as N } from "../SignInModal/index.js";
5
+ import { SignOutButton as $ } from "../SignOutButton/index.js";
6
+ import { LoadingSkeleton as b } from "../ui/LoadingSkeleton/index.js";
7
+ import '../../assets/AuthButton.css';const q = "AuthButton-module__loading___JpDqi", C = {
8
+ loading: q
9
+ }, G = ({
10
+ children: d,
10
11
  closeOnSuccessDelay: S = 800,
11
12
  onSignInSuccess: g,
12
- onSignInSuccessTransitionEnd: a,
13
- onSignOutSuccess: h,
14
- ...p
13
+ onSignInSuccessTransitionEnd: h,
14
+ onSignOutSuccess: p,
15
+ placeholder: I,
16
+ signInModal: O,
17
+ signOutButton: T,
18
+ ...j
15
19
  }) => {
16
- const { isInitialized: i } = _(), { isSignedIn: u } = v(), [m, s] = c(u), [t, d] = c(!1), [n, r] = c(void 0), o = w(!1), I = () => {
17
- g?.(), r(S);
18
- }, O = () => {
19
- h?.(), s(!1);
20
- };
21
- return f(() => {
22
- if (n === void 0)
20
+ const { isInitialized: n } = z(), { isSignedIn: r } = D(), [l, s] = f(r), [e, c] = f(!1), [i, a] = f(void 0), o = M(!1), _ = A(() => {
21
+ g?.(), a(S);
22
+ }, [S, g]), v = A(() => {
23
+ p?.(), s(!1);
24
+ }, [p]);
25
+ m(() => {
26
+ if (i === void 0)
23
27
  return;
24
- if (n === null) {
28
+ if (i === null) {
25
29
  o.current = !0;
26
30
  return;
27
31
  }
28
- const e = setTimeout(() => {
29
- o.current = !0, d(!1), r(void 0);
30
- }, n);
32
+ const t = setTimeout(() => {
33
+ o.current = !0, c(!1), a(void 0);
34
+ }, i);
31
35
  return () => {
32
- e && clearTimeout(e);
36
+ t && clearTimeout(t);
33
37
  };
34
- }, [n]), f(() => {
35
- if (t)
38
+ }, [i]), m(() => {
39
+ if (e)
36
40
  return;
37
- let e = null;
38
- return o.current && (e = setTimeout(() => {
39
- a?.(), o.current = !1, s(!0);
41
+ let t = null;
42
+ return o.current && (t = setTimeout(() => {
43
+ h?.(), o.current = !1, s(!0);
40
44
  }, 200)), () => {
41
- e && clearTimeout(e);
45
+ t && clearTimeout(t);
42
46
  };
43
- }, [t, a]), f(() => {
44
- if (u) {
47
+ }, [e, h]), m(() => {
48
+ if (r) {
45
49
  if (o.current)
46
50
  return;
47
- t ? r((e) => e === void 0 ? 0 : e) : s(!0);
51
+ e ? a((t) => t === void 0 ? 0 : t) : s(!0);
48
52
  } else
49
53
  s(!1);
50
- }, [u, t]), /* @__PURE__ */ T("div", { ...p, children: [
51
- !i && /* @__PURE__ */ l(A, { className: D.loading }),
52
- i && m && /* @__PURE__ */ l(y, { onSuccess: O }),
53
- i && !m && /* @__PURE__ */ l(x, { open: t, setIsOpen: d, onSuccess: I })
54
- ] });
54
+ }, [r, e]);
55
+ const B = I ? I({ className: C.loading }) : /* @__PURE__ */ u(b, { className: C.loading }), w = T ? T({ onSuccess: v }) : /* @__PURE__ */ u($, { onSuccess: v }), x = O ? O({ open: e, setIsOpen: c, onSuccess: _ }) : /* @__PURE__ */ u(N, { open: e, setIsOpen: c, onSuccess: _ });
56
+ return /* @__PURE__ */ u("div", { ...j, children: d ? d({
57
+ isInitialized: n,
58
+ isSignedIn: l,
59
+ Placeholder: B,
60
+ SignOutButton: w,
61
+ SignInModal: x
62
+ }) : /* @__PURE__ */ k(y, { children: [
63
+ !n && B,
64
+ n && l && w,
65
+ n && !l && x
66
+ ] }) });
55
67
  };
56
68
  export {
57
- L as AuthButton
69
+ G as AuthButton
58
70
  };
@@ -15,6 +15,6 @@ export type CDPReactProviderProps = {
15
15
  config: Config;
16
16
  name?: string;
17
17
  } & ThemeProviderProps;
18
- export declare const CDPReactProvider: ({ children, config, name, theme }: CDPReactProviderProps) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const CDPReactProvider: ({ children, className, config, name, style, theme, }: CDPReactProviderProps) => import("react/jsx-runtime").JSX.Element;
19
19
  export declare const useAppConfig: () => Required<AppConfig>;
20
20
  export declare const useProviderName: () => string;
@@ -1,95 +1,102 @@
1
- import { jsx as h, jsxs as y } from "react/jsx-runtime";
2
- import { OAuth2ProviderType as b, CDPContext as N, CDPHooksProvider as T } from "@coinbase/cdp-hooks";
3
- import { lazy as D, createContext as H, useContext as m, useMemo as O } from "react";
4
- import { ThemeProvider as S } from "../ThemeProvider/index.js";
5
- const U = D(() => import("../OAuthStatusModal/index.js")), _ = (o) => {
1
+ import { jsx as c, jsxs as N } from "react/jsx-runtime";
2
+ import { OAuth2ProviderType as T, CDPContext as D, CDPHooksProvider as H } from "@coinbase/cdp-hooks";
3
+ import { lazy as S, createContext as U, useContext as m, useMemo as P } from "react";
4
+ import { ThemeProvider as _ } from "../ThemeProvider/index.js";
5
+ const E = S(() => import("../OAuthStatusModal/index.js")), j = (o) => {
6
6
  try {
7
7
  return JSON.stringify(o);
8
8
  } catch {
9
9
  }
10
10
  return "";
11
- }, E = Object.keys(b).map((o) => `oauth:${o}`), j = [
11
+ }, F = Object.keys(T).map((o) => `oauth:${o}`), k = [
12
12
  /** Email OTP method */
13
13
  "email",
14
14
  /** SMS OTP method */
15
15
  "sms"
16
- ], R = [...j, ...E], W = ({ children: o, config: n, name: s, theme: a }) => {
16
+ ], $ = [...k, ...F], q = ({
17
+ children: o,
18
+ className: r = "",
19
+ config: n,
20
+ name: s,
21
+ style: a,
22
+ theme: i
23
+ }) => {
17
24
  const {
18
- appName: i,
25
+ appName: h,
19
26
  appLogoUrl: p,
20
27
  showCoinbaseFooter: u,
21
- authMethods: e,
22
- projectId: c,
23
- useMock: t,
24
- debugging: d,
25
- basePath: C,
26
- ethereum: M,
27
- solana: P
28
- } = n, { createOnLogin: l } = M ?? {}, { createOnLogin: f } = P ?? {}, v = O(
28
+ authMethods: t,
29
+ projectId: d,
30
+ useMock: C,
31
+ debugging: l,
32
+ basePath: f,
33
+ ethereum: v,
34
+ solana: x
35
+ } = n, { createOnLogin: A } = v ?? {}, { createOnLogin: O } = x ?? {}, L = P(
29
36
  () => ({
30
- projectId: c,
31
- useMock: t,
32
- debugging: d,
33
- basePath: C,
34
- ethereum: { createOnLogin: l },
35
- solana: { createOnLogin: f }
37
+ projectId: d,
38
+ useMock: C,
39
+ debugging: l,
40
+ basePath: f,
41
+ ethereum: { createOnLogin: A },
42
+ solana: { createOnLogin: O }
36
43
  }),
37
- [c, t, d, C, l, f]
38
- ), x = { appName: i, appLogoUrl: p, showCoinbaseFooter: u, authMethods: e }, L = e?.some((w) => w.startsWith("oauth:")), A = /* @__PURE__ */ h(F, { name: s, config: x, children: /* @__PURE__ */ y(S, { theme: a, children: [
44
+ [d, C, l, f, A, O]
45
+ ), w = { appName: h, appLogoUrl: p, showCoinbaseFooter: u, authMethods: t }, y = t?.some((b) => b.startsWith("oauth:")), M = /* @__PURE__ */ c(J, { name: s, config: w, children: /* @__PURE__ */ N(_, { className: r, style: a, theme: i, children: [
39
46
  o,
40
- L && /* @__PURE__ */ h(U, {})
47
+ y && /* @__PURE__ */ c(E, {})
41
48
  ] }) });
42
- return m(N) ? A : /* @__PURE__ */ h(T, { config: v, children: A });
43
- }, g = H(
49
+ return m(D) ? M : /* @__PURE__ */ c(H, { config: L, children: M });
50
+ }, g = U(
44
51
  void 0
45
- ), r = {
52
+ ), e = {
46
53
  appName: "",
47
54
  appLogoUrl: "",
48
55
  showCoinbaseFooter: !0,
49
56
  authMethods: ["email"]
50
- }, F = ({
57
+ }, J = ({
51
58
  children: o,
52
- config: n,
53
- name: s
59
+ config: r,
60
+ name: n
54
61
  }) => {
55
62
  const {
56
- appName: a = r.appName,
57
- appLogoUrl: i = r.appLogoUrl,
58
- showCoinbaseFooter: p = r.showCoinbaseFooter,
59
- authMethods: u = r.authMethods
60
- } = n ?? {}, e = _(u), c = O(() => {
63
+ appName: s = e.appName,
64
+ appLogoUrl: a = e.appLogoUrl,
65
+ showCoinbaseFooter: i = e.showCoinbaseFooter,
66
+ authMethods: h = e.authMethods
67
+ } = r ?? {}, p = j(h), u = P(() => {
61
68
  let t = ["email"];
62
69
  try {
63
- t = JSON.parse(e);
70
+ t = JSON.parse(p);
64
71
  } catch {
65
72
  }
66
73
  return {
67
74
  app: {
68
- appName: a,
69
- appLogoUrl: i,
70
- showCoinbaseFooter: p,
71
- authMethods: Array.isArray(t) && t?.length ? t : r.authMethods
75
+ appName: s,
76
+ appLogoUrl: a,
77
+ showCoinbaseFooter: i,
78
+ authMethods: Array.isArray(t) && t?.length ? t : e.authMethods
72
79
  },
73
- name: s
80
+ name: n
74
81
  };
75
- }, [a, i, p, e, s]);
76
- return /* @__PURE__ */ h(g.Provider, { value: c, children: o });
77
- }, $ = () => {
82
+ }, [s, a, i, p, n]);
83
+ return /* @__PURE__ */ c(g.Provider, { value: u, children: o });
84
+ }, B = () => {
78
85
  const o = m(g);
79
86
  if (!o)
80
87
  throw new Error("useAppConfig must be used within an AppConfigProvider");
81
88
  return o.app;
82
- }, q = () => {
89
+ }, G = () => {
83
90
  const o = m(g);
84
91
  if (!o)
85
92
  throw new Error("useProviderName must be used within an AppConfigProvider");
86
93
  return o.name ?? "";
87
94
  };
88
95
  export {
89
- R as ALL_AUTH_METHODS,
90
- j as AUTH_METHODS,
91
- W as CDPReactProvider,
92
- E as OAUTH_METHODS,
93
- $ as useAppConfig,
94
- q as useProviderName
96
+ $ as ALL_AUTH_METHODS,
97
+ k as AUTH_METHODS,
98
+ q as CDPReactProvider,
99
+ F as OAUTH_METHODS,
100
+ B as useAppConfig,
101
+ G as useProviderName
95
102
  };
@@ -5,6 +5,6 @@ import { useFundContext } from './FundProvider';
5
5
  import { FundTitle, FundTitleProps } from './FundTitle';
6
6
  import { FetchBuyUrlParams } from './hooks/useBuyUrl';
7
7
  import { CamelToSnakeCase, CamelToSnakeCaseNested, FundAction, FetchBuyOptions, FetchBuyQuote, FundPaymentMethod, FundPresetAmountInputs, FundProps, FundState, FundStateError, FundStateProps, FundContextType, FundLifecycleStatus, OnrampAmount, OnrampBuyQuoteResponse, OnrampBuyOptionsResponse, OnrampBuyOptionsSnakeCaseResponse, OnrampBuyQuoteSnakeCaseResponse, OnrampError, OnrampNetwork, OnrampPaymentCurrency, OnrampPaymentMethodLimit, OnrampPurchaseCurrency, OnrampSuccessEventData } from './types';
8
- declare const Fund: ({ className, children, openIn, submitLabel, title, ...props }: FundProps) => import("react/jsx-runtime").JSX.Element;
8
+ declare const Fund: ({ className, children, openIn, style, submitLabel, title, ...props }: FundProps) => import("react/jsx-runtime").JSX.Element;
9
9
  declare const FundFooter: (props: HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
10
10
  export { Fund, FundFooter, FundForm, FundTitle, useFundContext, type CamelToSnakeCase, type CamelToSnakeCaseNested, type FundAction, type FetchBuyOptions, type FetchBuyQuote, type FetchBuyUrlParams, type FundContextType, type FundFormProps, type FundLifecycleStatus, type FundPaymentMethod, type FundPresetAmountInputs, type FundProps, type FundState, type FundStateError, type FundStateProps, type FundTitleProps, type InputType, type OnrampAmount, type OnrampBuyQuoteResponse, type OnrampBuyOptionsResponse, type OnrampBuyOptionsSnakeCaseResponse, type OnrampBuyQuoteSnakeCaseResponse, type OnrampError, type OnrampNetwork, type OnrampPaymentCurrency, type OnrampPaymentMethodLimit, type OnrampPurchaseCurrency, type OnrampSuccessEventData, };
@@ -8,7 +8,15 @@ import { FundTitle as _ } from "./FundTitle.js";
8
8
  import { useSetupOnrampEventListeners as b } from "./hooks/useSetupOnrampEventListeners.js";
9
9
  import '../../assets/Fund.css';const x = "Fund-module__fund___6j-Og", g = {
10
10
  fund: x
11
- }, L = ({ className: o = "", children: r, openIn: e, submitLabel: s, title: u, ...n }) => /* @__PURE__ */ t(l, { ...n, children: /* @__PURE__ */ t("div", { className: `${g.fund} ${o}`, children: /* @__PURE__ */ t(h, { openIn: e, submitLabel: s, title: u, children: r }) }) }), h = ({
11
+ }, L = ({
12
+ className: o = "",
13
+ children: r,
14
+ openIn: e,
15
+ style: s,
16
+ submitLabel: u,
17
+ title: n,
18
+ ...i
19
+ }) => /* @__PURE__ */ t(l, { ...i, children: /* @__PURE__ */ t("div", { className: `${g.fund} ${o}`, style: s, children: /* @__PURE__ */ t(h, { openIn: e, submitLabel: u, title: n, children: r }) }) }), h = ({
12
20
  children: o,
13
21
  openIn: r,
14
22
  submitLabel: e,
@@ -1,4 +1,4 @@
1
- import { Dispatch, ReactNode } from 'react';
1
+ import { CSSProperties, Dispatch, ReactNode } from 'react';
2
2
  import { InputType } from '../forms/ExchangeAmountInput/types';
3
3
  import { FetchBuyUrlParams } from './hooks/useBuyUrl';
4
4
  export type CamelToSnakeCase<T extends string> = T extends `${infer A}${infer B}` ? B extends Uncapitalize<B> ? `${A}${CamelToSnakeCase<B>}` : `${Uncapitalize<A>}_${CamelToSnakeCase<Uncapitalize<B>>}` : T;
@@ -111,6 +111,7 @@ export interface FundProps extends FundStateProps, FundLifecycleEvents {
111
111
  inputType?: InputType;
112
112
  openIn?: "popup" | "tab";
113
113
  redirectUrl?: string;
114
+ style?: CSSProperties;
114
115
  submitLabel?: ReactNode;
115
116
  title?: ReactNode;
116
117
  }
@@ -1,9 +1,19 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { FundProps } from '../Fund';
3
- interface FundModalProps extends FundProps {
3
+ import { ButtonProps } from '../ui/Button';
4
+ import { ModalContentProps } from '../ui/Modal';
5
+ interface FundModalTriggerProps extends Partial<Pick<ButtonProps, "className" | "fullWidth" | "size" | "style" | "variant">> {
6
+ children?: ReactNode;
7
+ label?: ReactNode;
8
+ }
9
+ interface FundModalContentProps extends ModalContentProps {
10
+ }
11
+ interface FundModalProps extends Omit<FundProps, "children"> {
4
12
  children?: ReactNode;
5
13
  open?: boolean;
6
14
  setIsOpen?: (value: boolean) => void;
7
15
  }
8
- declare const FundModal: ({ children, open, setIsOpen, openIn, submitLabel, title, ...fundProps }: FundModalProps) => import("react/jsx-runtime").JSX.Element;
9
- export { FundModal, type FundModalProps };
16
+ declare const FundModalTrigger: ({ children, className, label, ...props }: FundModalTriggerProps) => import("react/jsx-runtime").JSX.Element;
17
+ declare const FundModalContent: (props: FundModalContentProps) => import("react/jsx-runtime").JSX.Element;
18
+ declare const FundModal: ({ children, open, setIsOpen, ...fundProps }: FundModalProps) => import("react/jsx-runtime").JSX.Element;
19
+ export { FundModal, FundModalContent, FundModalTrigger, type FundModalProps, type FundModalContentProps, type FundModalTriggerProps, };
@@ -1,93 +1,103 @@
1
- import { jsxs as t, jsx as o, Fragment as v } from "react/jsx-runtime";
2
- import { useId as x, useState as O, useCallback as p } from "react";
3
- import { useAppConfig as T } from "../CDPReactProvider/index.js";
4
- import { Fund as $, FundFooter as j } from "../Fund/index.js";
5
- import { Button as F } from "../ui/Button/index.js";
6
- import { Modal as A, ModalTrigger as I, ModalContent as z, ModalTitle as S, ModalClose as k } from "../ui/Modal/index.js";
7
- import { VisuallyHidden as M } from "../ui/VisuallyHidden/index.js";
8
- import { IconXMark as w } from "../../icons/IconXMark.js";
9
- import { FundTitle as a } from "../Fund/FundTitle.js";
10
- import { FundForm as U } from "../Fund/FundForm.js";
11
- import '../../assets/FundModal.css';const V = "FundModal-module__trigger___2IuXj", W = "FundModal-module__fund___1AmQa", X = "FundModal-module__title___lNsoT", q = "FundModal-module__content___9f3ze", e = {
12
- trigger: V,
13
- fund: W,
1
+ import { jsx as o, jsxs as i, Fragment as M } from "react/jsx-runtime";
2
+ import { c as x } from "../../chunks/lite.1fxw3LjI.js";
3
+ import { createContext as w, useState as j, useCallback as F, useMemo as A, useId as $, useContext as z } from "react";
4
+ import { useAppConfig as S } from "../CDPReactProvider/index.js";
5
+ import { Fund as V, FundFooter as k } from "../Fund/index.js";
6
+ import { Button as v } from "../ui/Button/index.js";
7
+ import { Modal as D, ModalContent as H, ModalTitle as L, ModalClose as R, ModalTrigger as U } from "../ui/Modal/index.js";
8
+ import { VisuallyHidden as C } from "../ui/VisuallyHidden/index.js";
9
+ import { IconXMark as W } from "../../icons/IconXMark.js";
10
+ import { childrenHasComponent as g } from "../../utils/childrenHasComponent.js";
11
+ import { FundTitle as _ } from "../Fund/FundTitle.js";
12
+ import { FundForm as X } from "../Fund/FundForm.js";
13
+ import '../../assets/FundModal.css';const q = "FundModal-module__trigger___2IuXj", B = "FundModal-module__fund___1AmQa", E = "FundModal-module__title___lNsoT", K = "FundModal-module__content___9f3ze", t = {
14
+ trigger: q,
15
+ fund: B,
14
16
  "no-footer": "FundModal-module__no-footer___WKV78",
15
17
  "title-buttons": "FundModal-module__title-buttons___Lctf7",
16
18
  "close-button": "FundModal-module__close-button___jzdFM",
17
19
  "close-icon": "FundModal-module__close-icon___WoA4a",
18
20
  "fund-inner": "FundModal-module__fund-inner___UuOq3",
19
21
  "tx-status": "FundModal-module__tx-status___fc-3f",
20
- title: X,
21
- content: q,
22
+ title: E,
23
+ content: K,
22
24
  "error-view": "FundModal-module__error-view___hR1A0"
23
- }, Y = ({
24
- children: g,
25
- open: i,
26
- setIsOpen: c,
27
- openIn: u,
28
- submitLabel: _,
29
- title: r,
30
- ...m
31
- }) => {
32
- const { showCoinbaseFooter: f } = T(), d = x(), l = i !== void 0, [C, h] = O(!1), b = l ? i : C, s = p(
33
- (n) => l ? c?.(n) : h(n),
34
- [l, c, h]
35
- ), N = p(() => {
36
- s(!1);
37
- }, [s]);
38
- return /* @__PURE__ */ t(A, { open: b, onOpenChange: s, children: [
39
- /* @__PURE__ */ o(I, { asChild: !0, children: g || /* @__PURE__ */ t(F, { variant: "primary", className: e.trigger, children: [
40
- "Deposit ",
41
- m.cryptoCurrency.toUpperCase()
42
- ] }) }),
43
- /* @__PURE__ */ o(z, { "aria-describedby": void 0, children: /* @__PURE__ */ o(
44
- $,
45
- {
46
- className: `${e.fund} ${f ? "" : e["no-footer"]}`,
47
- openIn: u,
48
- submitLabel: _,
49
- title: r,
50
- ...m,
51
- children: /* @__PURE__ */ t(v, { children: [
52
- /* @__PURE__ */ o(M, { children: /* @__PURE__ */ o(S, { asChild: !0, children: /* @__PURE__ */ o(a, { as: "span", children: r }) }) }),
53
- /* @__PURE__ */ o(
54
- U,
55
- {
56
- "aria-labelledby": d,
57
- openIn: u,
58
- unmountOnTransactionSuccess: !0,
59
- unmount: N,
60
- submitLabel: _,
61
- children: ({ view: n, Content: y }) => /* @__PURE__ */ t(
62
- "div",
63
- {
64
- className: `${e["fund-inner"]} ${n === "transaction-status" ? e["tx-status"] : ""} ${n === "error" ? e["error-view"] : ""}`,
65
- children: [
66
- /* @__PURE__ */ t("div", { className: e["title-buttons"], children: [
67
- n === "error" ? /* @__PURE__ */ o(M, { children: /* @__PURE__ */ o(a, { id: d, children: r }) }) : /* @__PURE__ */ o(a, { className: e.title, id: d, children: r }),
68
- /* @__PURE__ */ o(k, { asChild: !0, children: /* @__PURE__ */ o(
69
- F,
70
- {
71
- className: e["close-button"],
72
- "aria-label": "Close",
73
- size: "md",
74
- variant: "transparentSecondary",
75
- children: /* @__PURE__ */ o(w, { className: e["close-icon"] })
76
- }
77
- ) })
78
- ] }),
79
- /* @__PURE__ */ o("div", { className: e.content, children: y })
80
- ]
81
- }
82
- )
83
- }
84
- ),
85
- f && /* @__PURE__ */ o(j, {})
86
- ] })
87
- }
88
- ) })
89
- ] });
25
+ }, N = w(null), y = () => {
26
+ const n = z(N);
27
+ if (!n)
28
+ throw new Error("useFundModalContext must be used within a FundModal");
29
+ return n;
30
+ }, b = ({ children: n, className: l = "", label: e, ...s }) => {
31
+ const { cryptoCurrency: r } = y();
32
+ return /* @__PURE__ */ o(U, { asChild: !0, children: n || /* @__PURE__ */ o(v, { variant: "primary", className: x(t.trigger, l), ...s, children: e || `Deposit ${r.toUpperCase()}` }) });
33
+ }, f = (n) => {
34
+ const { showCoinbaseFooter: l } = S(), e = $(), { unmount: s, ...r } = y(), { openIn: m, submitLabel: u, title: a } = r;
35
+ return /* @__PURE__ */ o(H, { "aria-describedby": void 0, ...n, children: /* @__PURE__ */ o(
36
+ V,
37
+ {
38
+ className: x(t.fund, l ? "" : t["no-footer"]),
39
+ ...r,
40
+ children: /* @__PURE__ */ i(M, { children: [
41
+ /* @__PURE__ */ o(C, { children: /* @__PURE__ */ o(L, { asChild: !0, children: /* @__PURE__ */ o(_, { as: "span", children: a }) }) }),
42
+ /* @__PURE__ */ o(
43
+ X,
44
+ {
45
+ "aria-labelledby": e,
46
+ openIn: m,
47
+ unmountOnTransactionSuccess: !0,
48
+ unmount: s,
49
+ submitLabel: u,
50
+ children: ({ view: d, Content: c }) => /* @__PURE__ */ i(
51
+ "div",
52
+ {
53
+ className: `${t["fund-inner"]} ${d === "transaction-status" ? t["tx-status"] : ""} ${d === "error" ? t["error-view"] : ""}`,
54
+ children: [
55
+ /* @__PURE__ */ i("div", { className: t["title-buttons"], children: [
56
+ d === "error" ? /* @__PURE__ */ o(C, { children: /* @__PURE__ */ o(_, { id: e, children: a }) }) : /* @__PURE__ */ o(_, { className: t.title, id: e, children: a }),
57
+ /* @__PURE__ */ o(R, { asChild: !0, children: /* @__PURE__ */ o(
58
+ v,
59
+ {
60
+ className: t["close-button"],
61
+ "aria-label": "Close",
62
+ size: "md",
63
+ variant: "transparentSecondary",
64
+ children: /* @__PURE__ */ o(W, { className: t["close-icon"] })
65
+ }
66
+ ) })
67
+ ] }),
68
+ /* @__PURE__ */ o("div", { className: t.content, children: c })
69
+ ]
70
+ }
71
+ )
72
+ }
73
+ ),
74
+ l && /* @__PURE__ */ o(k, {})
75
+ ] })
76
+ }
77
+ ) });
78
+ }, so = ({ children: n, open: l, setIsOpen: e, ...s }) => {
79
+ const r = l !== void 0, [m, u] = j(!1), a = r ? l : m, d = F(
80
+ (p) => r ? e?.(p) : u(p),
81
+ [r, e, u]
82
+ ), c = F(() => {
83
+ d(!1);
84
+ }, [d]), T = A(
85
+ () => ({
86
+ unmount: c,
87
+ ...s
88
+ }),
89
+ [c, s]
90
+ ), I = n ? g(n, b) : !1, h = n ? g(n, f) : !1, O = !I && !h;
91
+ return /* @__PURE__ */ o(N.Provider, { value: T, children: /* @__PURE__ */ o(D, { open: a, onOpenChange: d, children: O ? /* @__PURE__ */ i(M, { children: [
92
+ /* @__PURE__ */ o(b, { children: n }),
93
+ /* @__PURE__ */ o(f, {})
94
+ ] }) : /* @__PURE__ */ i(M, { children: [
95
+ n,
96
+ !h && /* @__PURE__ */ o(f, {})
97
+ ] }) }) });
90
98
  };
91
99
  export {
92
- Y as FundModal
100
+ so as FundModal,
101
+ f as FundModalContent,
102
+ b as FundModalTrigger
93
103
  };