@coinbase/cdp-react 0.0.23 → 0.0.25

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 (107) hide show
  1. package/README.md +2 -2
  2. package/dist/assets/AmountInput.css +1 -1
  3. package/dist/assets/AuthButton.css +1 -1
  4. package/dist/assets/Button.css +1 -1
  5. package/dist/assets/ButtonBase.css +1 -0
  6. package/dist/assets/CoinbaseFooter.css +1 -0
  7. package/dist/assets/ExchangeAmountInput.css +1 -1
  8. package/dist/assets/Fund.css +1 -0
  9. package/dist/assets/FundAmountInput.css +1 -0
  10. package/dist/assets/FundErrorScreen.css +1 -0
  11. package/dist/assets/FundForm.css +1 -0
  12. package/dist/assets/FundModal.css +1 -0
  13. package/dist/assets/FundPaymentMethods.css +1 -0
  14. package/dist/assets/FundPresetAmountInputs.css +1 -0
  15. package/dist/assets/FundTitle.css +1 -0
  16. package/dist/assets/FundTransactionStatus.css +1 -0
  17. package/dist/assets/Input.css +1 -1
  18. package/dist/assets/Modal.css +1 -1
  19. package/dist/assets/Select.css +1 -0
  20. package/dist/assets/ThemeProvider.css +1 -1
  21. package/dist/components/Fund/FundForm.d.ts +18 -0
  22. package/dist/components/Fund/FundForm.js +156 -0
  23. package/dist/components/Fund/FundProvider.d.ts +6 -0
  24. package/dist/components/Fund/FundProvider.js +128 -0
  25. package/dist/components/Fund/FundTitle.d.ts +5 -0
  26. package/dist/components/Fund/FundTitle.js +17 -0
  27. package/dist/components/Fund/components/FundAmountInput.d.ts +5 -0
  28. package/dist/components/Fund/components/FundAmountInput.js +58 -0
  29. package/dist/components/Fund/components/FundErrorScreen.d.ts +6 -0
  30. package/dist/components/Fund/components/FundErrorScreen.js +118 -0
  31. package/dist/components/Fund/components/FundPaymentMethods.d.ts +6 -0
  32. package/dist/components/Fund/components/FundPaymentMethods.js +55 -0
  33. package/dist/components/Fund/components/FundPresetAmountInputs.d.ts +6 -0
  34. package/dist/components/Fund/components/FundPresetAmountInputs.js +41 -0
  35. package/dist/components/Fund/components/FundTransactionStatus.d.ts +8 -0
  36. package/dist/components/Fund/components/FundTransactionStatus.js +106 -0
  37. package/dist/components/Fund/hooks/useBuyUrl.d.ts +14 -0
  38. package/dist/components/Fund/hooks/useBuyUrl.js +65 -0
  39. package/dist/components/Fund/hooks/useEmitLifecycleStatus.d.ts +5 -0
  40. package/dist/components/Fund/hooks/useEmitLifecycleStatus.js +14 -0
  41. package/dist/components/Fund/hooks/useExchangeRate.d.ts +11 -0
  42. package/dist/components/Fund/hooks/useExchangeRate.js +62 -0
  43. package/dist/components/Fund/hooks/usePaymentMethods.d.ts +11 -0
  44. package/dist/components/Fund/hooks/usePaymentMethods.js +112 -0
  45. package/dist/components/Fund/hooks/usePopupMonitor.d.ts +3 -0
  46. package/dist/components/Fund/hooks/usePopupMonitor.js +17 -0
  47. package/dist/components/Fund/hooks/useSetupOnrampEventListeners.d.ts +1 -0
  48. package/dist/components/Fund/hooks/useSetupOnrampEventListeners.js +56 -0
  49. package/dist/components/Fund/index.d.ts +10 -0
  50. package/dist/components/Fund/index.js +30 -0
  51. package/dist/components/Fund/types.d.ts +218 -0
  52. package/dist/components/Fund/types.js +1 -0
  53. package/dist/components/Fund/useFundReducer.d.ts +9 -0
  54. package/dist/components/Fund/useFundReducer.js +104 -0
  55. package/dist/components/Fund/utils/buildPaymentMethods.d.ts +5 -0
  56. package/dist/components/Fund/utils/buildPaymentMethods.js +57 -0
  57. package/dist/components/Fund/utils/setupOnrampEventListeners.d.ts +9 -0
  58. package/dist/components/Fund/utils/setupOnrampEventListeners.js +19 -0
  59. package/dist/components/Fund/utils/subscribeToWindowMessage.d.ts +14 -0
  60. package/dist/components/Fund/utils/subscribeToWindowMessage.js +24 -0
  61. package/dist/components/FundModal/index.d.ts +9 -0
  62. package/dist/components/FundModal/index.js +92 -0
  63. package/dist/components/SignIn/SignInFooter.d.ts +1 -1
  64. package/dist/components/SignIn/SignInFooter.js +4 -15
  65. package/dist/components/forms/ExchangeAmountInput/index.js +93 -65
  66. package/dist/components/forms/ExchangeAmountInput/types.d.ts +2 -1
  67. package/dist/components/forms/ExchangeAmountInput/useExchangeAmountInput.js +42 -38
  68. package/dist/components/forms/Input/index.d.ts +6 -2
  69. package/dist/components/forms/Input/index.js +27 -12
  70. package/dist/components/forms/PhoneNumberInput/index.d.ts +2 -2
  71. package/dist/components/forms/Select/index.d.ts +21 -0
  72. package/dist/components/forms/Select/index.js +74 -0
  73. package/dist/components/ui/Button/index.d.ts +4 -5
  74. package/dist/components/ui/Button/index.js +35 -56
  75. package/dist/components/ui/ButtonBase/index.d.ts +8 -0
  76. package/dist/components/ui/ButtonBase/index.js +45 -0
  77. package/dist/components/ui/CoinbaseFooter/index.d.ts +2 -0
  78. package/dist/components/ui/CoinbaseFooter/index.js +19 -0
  79. package/dist/components/ui/LoadingSkeleton/index.d.ts +3 -2
  80. package/dist/components/ui/LoadingSkeleton/index.js +9 -15
  81. package/dist/components/ui/LoadingSpinner/index.d.ts +9 -2
  82. package/dist/components/ui/LoadingSpinner/index.js +39 -17
  83. package/dist/icons/IconAppleLogo.d.ts +2 -0
  84. package/dist/icons/IconAppleLogo.js +10 -0
  85. package/dist/icons/IconCheck.d.ts +2 -0
  86. package/dist/icons/IconCheck.js +14 -0
  87. package/dist/icons/IconChevronDown.d.ts +2 -0
  88. package/dist/icons/IconChevronDown.js +14 -0
  89. package/dist/icons/IconCoinbaseMark.d.ts +2 -0
  90. package/dist/icons/IconCoinbaseMark.js +13 -0
  91. package/dist/icons/IconCreditCard.d.ts +2 -0
  92. package/dist/icons/IconCreditCard.js +10 -0
  93. package/dist/icons/IconExclamationTriangle.d.ts +2 -0
  94. package/dist/icons/IconExclamationTriangle.js +14 -0
  95. package/dist/icons/index.d.ts +3 -0
  96. package/dist/icons/index.js +20 -14
  97. package/dist/index.d.ts +2 -0
  98. package/dist/index.js +86 -69
  99. package/dist/theme/theme.d.ts +120 -2
  100. package/dist/theme/tokens.d.ts +346 -0
  101. package/dist/theme/tokens.js +76 -8
  102. package/dist/utils/formatFiat.d.ts +1 -0
  103. package/dist/utils/formatFiat.js +13 -0
  104. package/dist/utils/openPopup.d.ts +7 -0
  105. package/dist/utils/openPopup.js +15 -0
  106. package/package.json +7 -6
  107. package/dist/assets/SignInFooter.css +0 -1
@@ -0,0 +1,118 @@
1
+ import { jsxs as d, jsx as o, Fragment as y } from "react/jsx-runtime";
2
+ import { useMemo as i, Fragment as E } from "react";
3
+ import { IconExclamationTriangle as m } from "../../../icons/IconExclamationTriangle.js";
4
+ import { useFundContext as h } from "../FundProvider.js";
5
+ import '../../../assets/FundErrorScreen.css';const f = "FundErrorScreen-module__icon___Mf6ck", O = "FundErrorScreen-module__title___8Qv6o", g = "FundErrorScreen-module__body___-p-r9", U = "FundErrorScreen-module__keywords___u85Do", c = {
6
+ icon: f,
7
+ title: O,
8
+ body: g,
9
+ "docs-link": "FundErrorScreen-module__docs-link___mzeH8",
10
+ keywords: U
11
+ }, C = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), b = ({
12
+ message: s,
13
+ keywords: e,
14
+ className: t = ""
15
+ }) => {
16
+ if (!s || !e?.length)
17
+ return /* @__PURE__ */ o(y, { children: s });
18
+ const a = new RegExp(`(${e.map(C).join("|")})\\b`, "g"), r = s.split(a);
19
+ return /* @__PURE__ */ o(y, { children: r.map((n, u) => n ? e.includes(n) ? /* @__PURE__ */ o("span", { className: t, "data-part": "keyword", children: n }, u) : /* @__PURE__ */ o(E, { children: n }, u) : null) });
20
+ }, T = ({ error: s }) => {
21
+ const { state: e } = h(), { code: t, message: a } = s || {}, r = process.env.NODE_ENV === "development", n = e.network.charAt(0).toUpperCase() + e.network.slice(1), u = i(() => {
22
+ switch (t) {
23
+ case "NO_ONRAMP_URL":
24
+ case "BUY_URL_ERROR":
25
+ case "UNKNOWN_BUY_URL_ERROR":
26
+ return "https://docs.cdp.coinbase.com/onramp-&-offramp/onramp-apis/generating-quotes#example-request%2Fresponse-with-one-click-buy-url";
27
+ case "EXCHANGE_RATE_ERROR":
28
+ case "UNKNOWN_EXCHANGE_RATE_ERROR":
29
+ return "https://docs.cdp.coinbase.com/onramp-&-offramp/onramp-apis/generating-quotes#onramp-quote";
30
+ default:
31
+ return "https://docs.cdp.coinbase.com/onramp-&-offramp/onramp-apis/countries-&-currencies#fiat-currencies-and-crypto-assets-supported";
32
+ }
33
+ }, [t]), l = i(() => {
34
+ if (!r || !t)
35
+ return "";
36
+ switch (t) {
37
+ case "NO_ONRAMP_URL":
38
+ case "BUY_URL_ERROR":
39
+ case "UNKNOWN_BUY_URL_ERROR":
40
+ return "Use the Onramp Quote API with a destination address to get a one-click-buy URL.";
41
+ case "EXCHANGE_RATE_ERROR":
42
+ case "UNKNOWN_EXCHANGE_RATE_ERROR":
43
+ return "Use the Onramp Quote API to calculate the exchange rate.";
44
+ default:
45
+ return "Use the Buy Options API to see the full list of crypto assets that can be bought for each region your app supports.";
46
+ }
47
+ }, [t, r]), R = i(() => {
48
+ switch (t) {
49
+ case "INVALID_PURCHASE_CURRENCY":
50
+ return r ? "Invalid parameters" : `${e.cryptoCurrency} is not available`;
51
+ case "INVALID_NETWORK":
52
+ return r ? "Invalid parameters" : `${n} network is not available`;
53
+ case "NO_ONRAMP_URL":
54
+ case "BUY_URL_ERROR":
55
+ case "UNKNOWN_BUY_URL_ERROR":
56
+ return r ? "Onramp URL error" : "Something went wrong";
57
+ case "EXCHANGE_RATE_ERROR":
58
+ case "UNKNOWN_EXCHANGE_RATE_ERROR":
59
+ return "No exchange rate";
60
+ default:
61
+ return "No payment methods";
62
+ }
63
+ }, [t, e.cryptoCurrency, n, r]), _ = i(() => {
64
+ switch (t) {
65
+ case "PAYMENT_METHODS_ERROR":
66
+ case "UNKNOWN_PAYMENT_METHODS_ERROR":
67
+ return r ? a || "There was an error fetching the payment methods." : `Unfortunately there's no available payment method to purchase ${e.cryptoCurrency} with ${e.fiatCurrency} on ${n} in your region. Please select a different asset to buy.`;
68
+ case "INVALID_PURCHASE_CURRENCY":
69
+ return r ? `${e.cryptoCurrency} crypto asset is not available.` : "Please select a different asset to buy.";
70
+ case "INVALID_NETWORK":
71
+ return r ? `${e.network} is not available for buying ${e.cryptoCurrency} in your region.` : `Coinbase doesn’t support buying ${e.cryptoCurrency} on ${n} in your region. Please select a different network to buy ${e.cryptoCurrency} on.`;
72
+ case "NO_ONRAMP_URL":
73
+ return r ? "An onramp url was unable to be created" : "We’re running into some issues. Please try again later.";
74
+ case "BUY_URL_ERROR":
75
+ case "UNKNOWN_BUY_URL_ERROR":
76
+ return r ? a || "There was an error creating the onramp url." : "We’re running into some issues. Please try again later.";
77
+ case "EXCHANGE_RATE_ERROR":
78
+ case "UNKNOWN_EXCHANGE_RATE_ERROR":
79
+ return r ? a || "There was an error fetching the exchange rate." : `No exchange rate found for ${e.fiatCurrency}<>${e.cryptoCurrency} on ${n} in your region.`;
80
+ default:
81
+ return r ? `There's no available payment method to purchase ${e.cryptoCurrency} with ${e.fiatCurrency} on ${e.network} in your region.` : `Unfortunately there's no available payment method to purchase ${e.cryptoCurrency} with ${e.fiatCurrency} on ${n} in your region. Please select a different asset to buy.`;
82
+ }
83
+ }, [
84
+ t,
85
+ a,
86
+ e.cryptoCurrency,
87
+ e.network,
88
+ n,
89
+ r,
90
+ e.fiatCurrency
91
+ ]), N = i(() => {
92
+ const p = [e.cryptoCurrency, e.network, e.country, e.fiatCurrency];
93
+ return e.subdivision && p.push(e.subdivision), p;
94
+ }, [e.cryptoCurrency, e.network, e.country, e.fiatCurrency, e.subdivision]);
95
+ return !R || !_ ? null : /* @__PURE__ */ d("div", { children: [
96
+ /* @__PURE__ */ o(m, { className: c.icon }),
97
+ /* @__PURE__ */ o("p", { className: `${c.title}`, children: R }),
98
+ /* @__PURE__ */ o("p", { className: `${c.body} ${r ? c.keywords : ""}`, children: /* @__PURE__ */ o(b, { message: _, keywords: N }) }),
99
+ l && /* @__PURE__ */ d("p", { className: `${c.body}`, children: [
100
+ " ",
101
+ l,
102
+ " ",
103
+ /* @__PURE__ */ o(
104
+ "a",
105
+ {
106
+ className: c["docs-link"],
107
+ href: u,
108
+ target: "_blank",
109
+ rel: "noopener noreferrer",
110
+ children: "View docs"
111
+ }
112
+ )
113
+ ] })
114
+ ] });
115
+ };
116
+ export {
117
+ T as FundErrorScreen
118
+ };
@@ -0,0 +1,6 @@
1
+ import { ElementType, HTMLAttributes } from 'react';
2
+ interface FundPaymentMethodsProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
3
+ as?: ElementType;
4
+ }
5
+ export declare const FundPaymentMethods: ({ as: Component, ...props }: FundPaymentMethodsProps) => import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,55 @@
1
+ import { jsxs as l, jsx as n } from "react/jsx-runtime";
2
+ import { useCallback as r } from "react";
3
+ import { Select as _, SelectTrigger as h, SelectContent as p, SelectItem as u } from "../../forms/Select/index.js";
4
+ import { LoadingSkeleton as y } from "../../ui/LoadingSkeleton/index.js";
5
+ import { useFundContext as g } from "../FundProvider.js";
6
+ import { createSetFieldAction as P } from "../useFundReducer.js";
7
+ import '../../../assets/FundPaymentMethods.css';const s = {
8
+ "select-loading-skeleton": "FundPaymentMethods-module__select-loading-skeleton___ZuD3n",
9
+ "select-item": "FundPaymentMethods-module__select-item___9VyxH",
10
+ "select-item-icon": "FundPaymentMethods-module__select-item-icon___28unQ",
11
+ "select-item-name": "FundPaymentMethods-module__select-item-name___5vLc0",
12
+ "select-item-description": "FundPaymentMethods-module__select-item-description___C5mTB",
13
+ "select-trigger": "FundPaymentMethods-module__select-trigger___ypebl"
14
+ }, k = ({
15
+ as: a = "div",
16
+ ...c
17
+ }) => {
18
+ const { state: e, dispatch: i } = g(), m = r(
19
+ (t) => {
20
+ const d = e.paymentMethods?.find((o) => o.id === t);
21
+ d && i(P("selectedPaymentMethod", d));
22
+ },
23
+ [i, e.paymentMethods]
24
+ );
25
+ return /* @__PURE__ */ l(a, { ...c, children: [
26
+ e.isPaymentMethodsPending && /* @__PURE__ */ n(y, { className: s["select-loading-skeleton"] }),
27
+ !e.isPaymentMethodsPending && /* @__PURE__ */ l(
28
+ _,
29
+ {
30
+ defaultValue: e.selectedPaymentMethod?.id || e.paymentMethods?.[0]?.id,
31
+ onValueChange: m,
32
+ children: [
33
+ /* @__PURE__ */ n(
34
+ h,
35
+ {
36
+ "aria-label": "Select a payment method",
37
+ placeholder: "Select a payment method",
38
+ className: s["select-trigger"]
39
+ }
40
+ ),
41
+ /* @__PURE__ */ n(p, { children: e.paymentMethods?.map((t) => /* @__PURE__ */ n(u, { value: t.id, children: /* @__PURE__ */ l("span", { className: s["select-item"], children: [
42
+ /* @__PURE__ */ n("span", { className: s["select-item-icon"], children: t.icon }),
43
+ /* @__PURE__ */ l("span", { children: [
44
+ /* @__PURE__ */ n("span", { className: s["select-item-name"], children: t.name }),
45
+ /* @__PURE__ */ n("span", { className: s["select-item-description"], children: t.description })
46
+ ] })
47
+ ] }) }, t.id)) })
48
+ ]
49
+ }
50
+ )
51
+ ] });
52
+ };
53
+ export {
54
+ k as FundPaymentMethods
55
+ };
@@ -0,0 +1,6 @@
1
+ import { ElementType, HTMLAttributes } from 'react';
2
+ interface FundPresetAmountInputsProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
3
+ as?: ElementType;
4
+ }
5
+ export declare const FundPresetAmountInputs: ({ as: Component, className, ...props }: FundPresetAmountInputsProps) => import("react/jsx-runtime").JSX.Element | null;
6
+ export {};
@@ -0,0 +1,41 @@
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { Big as c } from "big.js";
3
+ import { useCallback as l } from "react";
4
+ import { Button as d } from "../../ui/Button/index.js";
5
+ import { formatFiat as f } from "../../../utils/formatFiat.js";
6
+ import { useFundContext as y } from "../FundProvider.js";
7
+ import '../../../assets/FundPresetAmountInputs.css';const a = {
8
+ "preset-amount-inputs": "FundPresetAmountInputs-module__preset-amount-inputs___Skjnm",
9
+ "preset-amount-input": "FundPresetAmountInputs-module__preset-amount-input___eyNqU"
10
+ }, P = ({
11
+ as: r = "div",
12
+ className: m = "",
13
+ ...u
14
+ }) => {
15
+ const { state: t, dispatch: o } = y(), i = l(
16
+ (e) => {
17
+ const n = c(e).times(t.exchangeRate ?? 0), p = n.eq(0) ? 0 : +n.toFixed(t.cryptoDecimalPlaces);
18
+ o({
19
+ type: "SET_AMOUNTS",
20
+ payload: { cryptoAmount: p, fiatAmount: e }
21
+ });
22
+ },
23
+ [o, t.exchangeRate, t.cryptoDecimalPlaces]
24
+ );
25
+ return t.presetAmountInputs?.length ? /* @__PURE__ */ s(r, { className: `${a["preset-amount-inputs"]} ${m}`, ...u, children: t.presetAmountInputs.map((e) => /* @__PURE__ */ s(
26
+ d,
27
+ {
28
+ size: "xs",
29
+ variant: "control",
30
+ "aria-label": `Deposit ${e}`,
31
+ className: a["preset-amount-input"],
32
+ onClick: () => i(e),
33
+ type: "button",
34
+ children: f(e, t.fiatCurrency, t.fiatDecimalPlaces, t.locale)
35
+ },
36
+ e
37
+ )) }) : null;
38
+ };
39
+ export {
40
+ P as FundPresetAmountInputs
41
+ };
@@ -0,0 +1,8 @@
1
+ type StatusComponentProps = {
2
+ reset?: () => void;
3
+ timeRemaining?: number | null;
4
+ unmountOnSuccess?: boolean;
5
+ unmountOnError?: boolean;
6
+ };
7
+ export declare const FundTransactionStatus: (props: StatusComponentProps) => import("react/jsx-runtime").JSX.Element;
8
+ export {};
@@ -0,0 +1,106 @@
1
+ import { jsx as s, jsxs as r, Fragment as i } from "react/jsx-runtime";
2
+ import { useRef as d, useCallback as h, useEffect as S, useMemo as g } from "react";
3
+ import { Button as l } from "../../ui/Button/index.js";
4
+ import { LoadingSpinner as T } from "../../ui/LoadingSpinner/index.js";
5
+ import { SwitchFadeTransition as N } from "../../ui/SwitchFadeTransition/index.js";
6
+ import { IconCheck as f } from "../../../icons/IconCheck.js";
7
+ import { IconXMark as F } from "../../../icons/IconXMark.js";
8
+ import { useFundContext as m } from "../FundProvider.js";
9
+ import '../../../assets/FundTransactionStatus.css';const y = "FundTransactionStatus-module__graphic___cam38", $ = "FundTransactionStatus-module__status___2zKJu", k = "FundTransactionStatus-module__pad___-9rGO", w = "FundTransactionStatus-module__spinner___94rMk", C = "FundTransactionStatus-module__icon___0hBQO", b = "FundTransactionStatus-module__subhead___0sHIM", M = "FundTransactionStatus-module__description___W7kK2", v = "FundTransactionStatus-module__ring___1vnCu", t = {
10
+ graphic: y,
11
+ status: $,
12
+ pad: k,
13
+ spinner: w,
14
+ icon: C,
15
+ "icon-success": "FundTransactionStatus-module__icon-success___893VG",
16
+ "icon-error": "FundTransactionStatus-module__icon-error___-aQvD",
17
+ subhead: b,
18
+ description: M,
19
+ ring: v,
20
+ "ring-success": "FundTransactionStatus-module__ring-success___Bxudq",
21
+ "ring-error": "FundTransactionStatus-module__ring-error___WmTaE"
22
+ }, W = ["waiting", "transactionSuccess", "error"], q = (a) => {
23
+ const { state: n } = m(), e = d(null), o = d(null), u = h((c) => {
24
+ o.current !== c && (o.current = c, e.current?.transition.toggle(c));
25
+ }, []);
26
+ return S(() => {
27
+ (n.transactionStatus.statusName === "transactionSuccess" || n.transactionStatus.statusName === "error") && u(n.transactionStatus.statusName);
28
+ }, [n.transactionStatus.statusName, u]), /* @__PURE__ */ s(
29
+ N,
30
+ {
31
+ animateHeight: !1,
32
+ timeout: 250,
33
+ items: W,
34
+ initialEntered: !0,
35
+ transitionRef: e,
36
+ children: ({ itemKey: c, ..._ }) => {
37
+ const p = E[c];
38
+ return /* @__PURE__ */ s("div", { ..._, className: t.status, children: /* @__PURE__ */ s(p, { ...a }) });
39
+ }
40
+ }
41
+ );
42
+ }, x = () => {
43
+ const { state: a } = m(), n = g(
44
+ () => a.paymentMethods?.find((e) => e.id === a.selectedPaymentMethod?.id),
45
+ [a.paymentMethods, a.selectedPaymentMethod?.id]
46
+ );
47
+ return /* @__PURE__ */ r(i, { children: [
48
+ /* @__PURE__ */ r("div", { className: t.graphic, children: [
49
+ /* @__PURE__ */ s(
50
+ T,
51
+ {
52
+ strokeWidth: "5%",
53
+ staticStroke: !0,
54
+ staticStrokeColor: "var(--cdp-web-colors-line-default)",
55
+ className: t.spinner
56
+ }
57
+ ),
58
+ n && /* @__PURE__ */ s("span", { className: t.icon, children: n.icon })
59
+ ] }),
60
+ /* @__PURE__ */ s("p", { className: t.subhead, children: "Waiting" }),
61
+ /* @__PURE__ */ r("p", { className: t.description, children: [
62
+ "Deposit ",
63
+ a.cryptoAmount,
64
+ " ",
65
+ a.cryptoCurrency,
66
+ n ? ` via ${n.name}` : ""
67
+ ] })
68
+ ] });
69
+ }, P = ({
70
+ reset: a,
71
+ timeRemaining: n,
72
+ unmountOnSuccess: e
73
+ }) => /* @__PURE__ */ r(i, { children: [
74
+ /* @__PURE__ */ r("div", { className: `${t.graphic} ${t.pad}`, children: [
75
+ /* @__PURE__ */ s("span", { className: `${t.ring} ${t["ring-success"]}` }),
76
+ /* @__PURE__ */ s("span", { className: `${t.icon} ${t["icon-success"]}`, children: /* @__PURE__ */ s(f, {}) })
77
+ ] }),
78
+ /* @__PURE__ */ s("p", { className: t.subhead, children: "Success" }),
79
+ e && /* @__PURE__ */ r("p", { className: t.description, children: [
80
+ "This window will automatically close",
81
+ " ",
82
+ n === null ? "soon" : `in ${n}`
83
+ ] }),
84
+ !e && /* @__PURE__ */ s("p", { className: t.description, children: "Your transaction was successful." }),
85
+ !e && a !== void 0 && /* @__PURE__ */ s(l, { fullWidth: !0, onClick: a, children: "Go back" })
86
+ ] }), B = ({ reset: a, timeRemaining: n, unmountOnError: e }) => /* @__PURE__ */ r(i, { children: [
87
+ /* @__PURE__ */ r("div", { className: `${t.graphic} ${t.pad}`, children: [
88
+ /* @__PURE__ */ s("span", { className: `${t.ring} ${t["ring-error"]}` }),
89
+ /* @__PURE__ */ s("span", { className: `${t.icon} ${t["icon-error"]}`, children: /* @__PURE__ */ s(F, {}) })
90
+ ] }),
91
+ /* @__PURE__ */ s("p", { className: t.subhead, children: "Payment failed" }),
92
+ e && /* @__PURE__ */ r("p", { className: t.description, children: [
93
+ "This window will automatically close",
94
+ " ",
95
+ n === null ? "soon" : `in ${n}`
96
+ ] }),
97
+ !e && /* @__PURE__ */ s("p", { className: t.description, children: "Something went wrong. Please try again." }),
98
+ !e && a !== void 0 && /* @__PURE__ */ s(l, { fullWidth: !0, onClick: a, children: "Try again" })
99
+ ] }), E = {
100
+ waiting: x,
101
+ transactionSuccess: P,
102
+ error: B
103
+ };
104
+ export {
105
+ q as FundTransactionStatus
106
+ };
@@ -0,0 +1,14 @@
1
+ import { OnrampError, FundProps, FundState } from '../types';
2
+ export type UseBuyUrlParams = Pick<FundState, "country" | "cryptoCurrency" | "fiatCurrency" | "network" | "subdivision"> & {
3
+ fetchBuyQuote: FundProps["fetchBuyQuote"];
4
+ onError?: (e: OnrampError | undefined) => void;
5
+ destinationAddress?: string;
6
+ };
7
+ export interface FetchBuyUrlParams {
8
+ paymentMethod: NonNullable<FundState["selectedPaymentMethod"]>["id"];
9
+ paymentAmount: number;
10
+ }
11
+ export type UseBuyUrlReturn = {
12
+ fetchBuyUrl: (params: FetchBuyUrlParams) => Promise<string>;
13
+ };
14
+ export declare const useBuyUrl: ({ country, cryptoCurrency, destinationAddress, fetchBuyQuote, fiatCurrency, network, onError: onErrorProp, subdivision, }: UseBuyUrlParams) => UseBuyUrlReturn;
@@ -0,0 +1,65 @@
1
+ import { useCallback as f, useMemo as y } from "react";
2
+ const R = ({
3
+ country: a,
4
+ cryptoCurrency: n,
5
+ destinationAddress: o,
6
+ fetchBuyQuote: s,
7
+ fiatCurrency: t,
8
+ network: u,
9
+ onError: c,
10
+ subdivision: d
11
+ }) => {
12
+ const l = f(
13
+ async ({ paymentMethod: m, paymentAmount: p }, U) => {
14
+ if (isNaN(p) || !o || !m)
15
+ return "";
16
+ try {
17
+ const e = (await s({
18
+ purchaseCurrency: n,
19
+ purchaseNetwork: u,
20
+ paymentCurrency: t,
21
+ paymentAmount: p.toFixed(),
22
+ paymentMethod: m.replace("_GUEST", ""),
23
+ // remove "_GUEST" from the payment method since it is not valid in the Buy Quote API
24
+ country: a,
25
+ subdivision: d,
26
+ destinationAddress: o
27
+ })).onrampUrl;
28
+ if (!e) {
29
+ const _ = {
30
+ errorType: "handled_error",
31
+ code: "NO_ONRAMP_URL",
32
+ debugMessage: "No payment methods found for the selected country and currency. See docs for more information: https://docs.cdp.coinbase.com/onramp/docs/api-configurations"
33
+ };
34
+ return U?.(_), c?.(_), "";
35
+ }
36
+ return e;
37
+ } catch (r) {
38
+ let e;
39
+ return r instanceof Error ? e = {
40
+ errorType: "handled_error",
41
+ code: "BUY_URL_ERROR",
42
+ debugMessage: r.message
43
+ } : e = {
44
+ errorType: "unknown_error",
45
+ code: "UNKNOWN_BUY_URL_ERROR",
46
+ debugMessage: JSON.stringify(r)
47
+ }, U?.(e), c?.(e), "";
48
+ }
49
+ },
50
+ [
51
+ a,
52
+ n,
53
+ o,
54
+ s,
55
+ t,
56
+ u,
57
+ c,
58
+ d
59
+ ]
60
+ );
61
+ return y(() => ({ fetchBuyUrl: l }), [l]);
62
+ };
63
+ export {
64
+ R as useBuyUrl
65
+ };
@@ -0,0 +1,5 @@
1
+ import { FundLifecycleEvents, FundLifecycleStatus } from '../types';
2
+ export type UseEmitLifecycleStatusProps = FundLifecycleEvents & {
3
+ lifecycleStatus: FundLifecycleStatus;
4
+ };
5
+ export declare const useEmitLifecycleStatus: ({ lifecycleStatus, onError, onSuccess, onStatus, }: UseEmitLifecycleStatusProps) => void;
@@ -0,0 +1,14 @@
1
+ import { useEffect as r } from "react";
2
+ const i = ({
3
+ lifecycleStatus: a,
4
+ onError: s,
5
+ onSuccess: t,
6
+ onStatus: m
7
+ }) => {
8
+ r(() => {
9
+ a.statusName === "error" && s?.(a.statusData), a.statusName === "transactionSuccess" && t?.(a.statusData || void 0), m?.(a);
10
+ }, [s, m, t, a]);
11
+ };
12
+ export {
13
+ i as useEmitLifecycleStatus
14
+ };
@@ -0,0 +1,11 @@
1
+ import { Dispatch } from 'react';
2
+ import { OnrampError, FundAction, FundProps } from '../types';
3
+ type UseExchangeRateParams = Pick<FundProps, "country" | "fetchBuyQuote" | "cryptoCurrency" | "fiatCurrency" | "subdivision" | "network"> & {
4
+ dispatch: Dispatch<FundAction>;
5
+ onError?: (e: OnrampError | undefined) => void;
6
+ };
7
+ type UseExchangeRateReturn = {
8
+ fetchExchangeRate: () => Promise<void>;
9
+ };
10
+ export declare const useExchangeRate: ({ country, cryptoCurrency, fetchBuyQuote, fiatCurrency, network, onError, dispatch, subdivision, }: UseExchangeRateParams) => UseExchangeRateReturn;
11
+ export {};
@@ -0,0 +1,62 @@
1
+ import { Big as _ } from "big.js";
2
+ import { useCallback as m, useMemo as i } from "react";
3
+ const N = ({
4
+ country: t,
5
+ cryptoCurrency: a,
6
+ fetchBuyQuote: s,
7
+ fiatCurrency: n,
8
+ network: p,
9
+ onError: c,
10
+ dispatch: o,
11
+ subdivision: u
12
+ }) => {
13
+ const E = m(async () => {
14
+ const C = a.toUpperCase(), R = n.toUpperCase(), d = p.toLowerCase(), g = t.toUpperCase(), y = u?.toUpperCase();
15
+ o({ type: "FETCH_EXCHANGE_RATE" });
16
+ try {
17
+ const r = await s({
18
+ purchaseCurrency: C,
19
+ paymentCurrency: R,
20
+ paymentAmount: "100",
21
+ paymentMethod: "CARD",
22
+ country: g,
23
+ subdivision: y,
24
+ purchaseNetwork: d,
25
+ destinationAddress: ""
26
+ }), e = _(r.purchaseAmount.value).div(r.paymentSubtotal.value).toNumber();
27
+ o({ type: "SET_EXCHANGE_RATE_SUCCESS", payload: { exchangeRate: e } });
28
+ } catch (r) {
29
+ let e;
30
+ r instanceof Error ? e = {
31
+ errorType: "handled_error",
32
+ code: "EXCHANGE_RATE_ERROR",
33
+ debugMessage: r.message
34
+ } : e = {
35
+ errorType: "unknown_error",
36
+ code: "UNKNOWN_EXCHANGE_RATE_ERROR",
37
+ debugMessage: JSON.stringify(r)
38
+ }, c?.(e), o({
39
+ type: "SET_EXCHANGE_RATE_ERROR",
40
+ payload: {
41
+ error: {
42
+ code: e?.code,
43
+ message: e.errorType === "handled_error" ? e?.debugMessage : "Something went wrong fetching the exchange rate"
44
+ }
45
+ }
46
+ });
47
+ }
48
+ }, [
49
+ t,
50
+ a,
51
+ o,
52
+ s,
53
+ n,
54
+ p,
55
+ c,
56
+ u
57
+ ]);
58
+ return i(() => ({ fetchExchangeRate: E }), [E]);
59
+ };
60
+ export {
61
+ N as useExchangeRate
62
+ };
@@ -0,0 +1,11 @@
1
+ import { Dispatch } from 'react';
2
+ import { OnrampError, FundAction, FundProps } from '../types';
3
+ type UsePaymentMethodsParams = Pick<FundProps, "country" | "cryptoCurrency" | "fetchBuyOptions" | "fiatCurrency" | "subdivision" | "network"> & {
4
+ dispatch: Dispatch<FundAction>;
5
+ onError?: (e: OnrampError | undefined) => void;
6
+ };
7
+ type UsePaymentMethodsReturn = {
8
+ fetchPaymentMethods: () => Promise<void>;
9
+ };
10
+ export declare const usePaymentMethods: ({ country, cryptoCurrency, fetchBuyOptions, fiatCurrency, network, subdivision, dispatch, onError, }: UsePaymentMethodsParams) => UsePaymentMethodsReturn;
11
+ export {};
@@ -0,0 +1,112 @@
1
+ import { useCallback as m, useMemo as N } from "react";
2
+ import { buildPaymentMethods as R } from "../utils/buildPaymentMethods.js";
3
+ const h = ({
4
+ country: a,
5
+ cryptoCurrency: c,
6
+ fetchBuyOptions: p,
7
+ fiatCurrency: _,
8
+ network: n,
9
+ subdivision: u,
10
+ dispatch: o,
11
+ onError: t
12
+ }) => {
13
+ const M = m(async () => {
14
+ const d = c.toUpperCase(), T = n.toLowerCase(), g = a.toUpperCase(), y = u?.toUpperCase();
15
+ o({ type: "FETCH_PAYMENT_METHODS" });
16
+ try {
17
+ const s = await p({
18
+ country: g,
19
+ subdivision: y
20
+ }), r = s.purchaseCurrencies.find(
21
+ (e) => e.symbol.toUpperCase() === d
22
+ );
23
+ if (!r) {
24
+ const e = {
25
+ errorType: "handled_error",
26
+ code: "INVALID_PURCHASE_CURRENCY",
27
+ debugMessage: `You cannot purchase ${d} in your region.`
28
+ };
29
+ t?.(e), o({
30
+ type: "SET_PAYMENT_METHODS_ERROR",
31
+ payload: {
32
+ error: {
33
+ code: e?.code,
34
+ message: e?.debugMessage
35
+ }
36
+ }
37
+ });
38
+ return;
39
+ }
40
+ if (!r.networks.find(
41
+ (e) => e.name.toLowerCase() === T
42
+ )) {
43
+ const e = {
44
+ errorType: "handled_error",
45
+ code: "INVALID_NETWORK",
46
+ debugMessage: `You cannot purchase ${d} on ${n} in your region.`
47
+ };
48
+ t?.(e), o({
49
+ type: "SET_PAYMENT_METHODS_ERROR",
50
+ payload: {
51
+ error: {
52
+ code: e?.code,
53
+ message: e?.debugMessage
54
+ }
55
+ }
56
+ });
57
+ return;
58
+ }
59
+ const E = R(s, _, a);
60
+ if (E.length === 0) {
61
+ const e = {
62
+ errorType: "handled_error",
63
+ code: "NO_PAYMENT_METHODS",
64
+ debugMessage: "No payment methods found for the selected country and currency."
65
+ };
66
+ t?.(e), o({
67
+ type: "SET_PAYMENT_METHODS_ERROR",
68
+ payload: {
69
+ error: {
70
+ code: e?.code,
71
+ message: e?.debugMessage
72
+ }
73
+ }
74
+ });
75
+ return;
76
+ }
77
+ o({ type: "SET_PAYMENT_METHODS_SUCCESS", payload: { paymentMethods: E } });
78
+ } catch (s) {
79
+ let r;
80
+ s instanceof Error ? r = {
81
+ errorType: "handled_error",
82
+ code: "PAYMENT_METHODS_ERROR",
83
+ debugMessage: s.message
84
+ } : r = {
85
+ errorType: "unknown_error",
86
+ code: "UNKNOWN_PAYMENT_METHODS_ERROR",
87
+ debugMessage: JSON.stringify(s)
88
+ }, t?.(r), o({
89
+ type: "SET_PAYMENT_METHODS_ERROR",
90
+ payload: {
91
+ error: {
92
+ code: r?.code,
93
+ message: r.errorType === "handled_error" ? r?.debugMessage : "Something went wrong fetching the payment methods"
94
+ }
95
+ }
96
+ });
97
+ }
98
+ }, [
99
+ a,
100
+ c,
101
+ o,
102
+ p,
103
+ _,
104
+ n,
105
+ t,
106
+ u
107
+ ]);
108
+ return N(() => ({ fetchPaymentMethods: M }), [M]);
109
+ };
110
+ export {
111
+ h as usePaymentMethods
112
+ };
@@ -0,0 +1,3 @@
1
+ export declare const usePopupMonitor: (onClose?: () => void) => {
2
+ startPopupMonitor: (popupWindow: Window) => void;
3
+ };