@coinbase/cdp-react 0.0.24 → 0.0.26
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.
- package/README.md +2 -2
- package/dist/assets/AmountInput.css +1 -1
- package/dist/assets/AuthButton.css +1 -1
- package/dist/assets/ExchangeAmountInput.css +1 -1
- package/dist/assets/Fund.css +1 -0
- package/dist/assets/FundAmountInput.css +1 -0
- package/dist/assets/FundErrorScreen.css +1 -0
- package/dist/assets/FundForm.css +1 -0
- package/dist/assets/FundModal.css +1 -0
- package/dist/assets/FundPaymentMethods.css +1 -0
- package/dist/assets/FundPresetAmountInputs.css +1 -0
- package/dist/assets/FundTitle.css +1 -0
- package/dist/assets/FundTransactionStatus.css +1 -0
- package/dist/assets/Input.css +1 -1
- package/dist/assets/Modal.css +1 -1
- package/dist/assets/ThemeProvider.css +1 -1
- package/dist/components/Fund/FundForm.d.ts +18 -0
- package/dist/components/Fund/FundForm.js +156 -0
- package/dist/components/Fund/FundProvider.d.ts +6 -0
- package/dist/components/Fund/FundProvider.js +128 -0
- package/dist/components/Fund/FundTitle.d.ts +5 -0
- package/dist/components/Fund/FundTitle.js +17 -0
- package/dist/components/Fund/components/FundAmountInput.d.ts +5 -0
- package/dist/components/Fund/components/FundAmountInput.js +58 -0
- package/dist/components/Fund/components/FundErrorScreen.d.ts +6 -0
- package/dist/components/Fund/components/FundErrorScreen.js +118 -0
- package/dist/components/Fund/components/FundPaymentMethods.d.ts +6 -0
- package/dist/components/Fund/components/FundPaymentMethods.js +55 -0
- package/dist/components/Fund/components/FundPresetAmountInputs.d.ts +6 -0
- package/dist/components/Fund/components/FundPresetAmountInputs.js +41 -0
- package/dist/components/Fund/components/FundTransactionStatus.d.ts +8 -0
- package/dist/components/Fund/components/FundTransactionStatus.js +106 -0
- package/dist/components/Fund/hooks/useBuyUrl.d.ts +14 -0
- package/dist/components/Fund/hooks/useBuyUrl.js +65 -0
- package/dist/components/Fund/hooks/useEmitLifecycleStatus.d.ts +5 -0
- package/dist/components/Fund/hooks/useEmitLifecycleStatus.js +14 -0
- package/dist/components/Fund/hooks/useExchangeRate.d.ts +11 -0
- package/dist/components/Fund/hooks/useExchangeRate.js +62 -0
- package/dist/components/Fund/hooks/usePaymentMethods.d.ts +11 -0
- package/dist/components/Fund/hooks/usePaymentMethods.js +112 -0
- package/dist/components/Fund/hooks/usePopupMonitor.d.ts +3 -0
- package/dist/components/Fund/hooks/usePopupMonitor.js +17 -0
- package/dist/components/Fund/hooks/useSetupOnrampEventListeners.d.ts +1 -0
- package/dist/components/Fund/hooks/useSetupOnrampEventListeners.js +56 -0
- package/dist/components/Fund/index.d.ts +10 -0
- package/dist/components/Fund/index.js +30 -0
- package/dist/components/Fund/types.d.ts +218 -0
- package/dist/components/Fund/types.js +1 -0
- package/dist/components/Fund/useFundReducer.d.ts +9 -0
- package/dist/components/Fund/useFundReducer.js +104 -0
- package/dist/components/Fund/utils/buildPaymentMethods.d.ts +5 -0
- package/dist/components/Fund/utils/buildPaymentMethods.js +57 -0
- package/dist/components/Fund/utils/setupOnrampEventListeners.d.ts +9 -0
- package/dist/components/Fund/utils/setupOnrampEventListeners.js +19 -0
- package/dist/components/Fund/utils/subscribeToWindowMessage.d.ts +14 -0
- package/dist/components/Fund/utils/subscribeToWindowMessage.js +24 -0
- package/dist/components/FundModal/index.d.ts +9 -0
- package/dist/components/FundModal/index.js +92 -0
- package/dist/components/forms/ExchangeAmountInput/index.js +93 -65
- package/dist/components/forms/ExchangeAmountInput/types.d.ts +2 -1
- package/dist/components/forms/ExchangeAmountInput/useExchangeAmountInput.js +42 -38
- package/dist/components/forms/Input/index.d.ts +6 -2
- package/dist/components/forms/Input/index.js +27 -12
- package/dist/components/forms/PhoneNumberInput/index.d.ts +2 -2
- package/dist/components/ui/Button/index.js +7 -7
- package/dist/components/ui/ButtonBase/index.js +19 -19
- package/dist/components/ui/LoadingSpinner/index.d.ts +9 -2
- package/dist/components/ui/LoadingSpinner/index.js +39 -17
- package/dist/icons/IconAppleLogo.d.ts +2 -0
- package/dist/icons/IconAppleLogo.js +10 -0
- package/dist/icons/IconCoinbaseMark.d.ts +2 -0
- package/dist/icons/IconCoinbaseMark.js +13 -0
- package/dist/icons/IconCreditCard.d.ts +2 -0
- package/dist/icons/IconCreditCard.js +10 -0
- package/dist/icons/IconExclamationTriangle.d.ts +2 -0
- package/dist/icons/IconExclamationTriangle.js +14 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +18 -16
- package/dist/index.d.ts +2 -0
- package/dist/index.js +86 -73
- package/dist/theme/theme.d.ts +23 -0
- package/dist/theme/tokens.d.ts +67 -0
- package/dist/theme/tokens.js +19 -2
- package/dist/utils/formatFiat.d.ts +1 -0
- package/dist/utils/formatFiat.js +13 -0
- package/dist/utils/openPopup.d.ts +7 -0
- package/dist/utils/openPopup.js +15 -0
- package/package.json +6 -6
|
@@ -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,17 @@
|
|
|
1
|
+
import { useRef as u, useCallback as c, useEffect as l } from "react";
|
|
2
|
+
const a = (e) => {
|
|
3
|
+
const r = u(null), t = c(
|
|
4
|
+
(n) => {
|
|
5
|
+
r.current && clearInterval(r.current), r.current = window.setInterval(() => {
|
|
6
|
+
n.closed && (r.current && (clearInterval(r.current), r.current = null), e?.());
|
|
7
|
+
}, 500);
|
|
8
|
+
},
|
|
9
|
+
[e]
|
|
10
|
+
);
|
|
11
|
+
return l(() => () => {
|
|
12
|
+
r.current && clearInterval(r.current);
|
|
13
|
+
}, []), { startPopupMonitor: t };
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
a as usePopupMonitor
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSetupOnrampEventListeners: () => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useCallback as n, useEffect as u } from "react";
|
|
2
|
+
import { useFundContext as c } from "../FundProvider.js";
|
|
3
|
+
import { setupOnrampEventListeners as i } from "../utils/setupOnrampEventListeners.js";
|
|
4
|
+
const e = (t) => ({
|
|
5
|
+
type: "SET_TRANSACTION_STATUS",
|
|
6
|
+
payload: {
|
|
7
|
+
transactionStatus: t
|
|
8
|
+
}
|
|
9
|
+
}), S = () => {
|
|
10
|
+
const { dispatch: t } = c(), a = n(
|
|
11
|
+
(s) => {
|
|
12
|
+
s.eventName === "transition_view" ? t(
|
|
13
|
+
e({
|
|
14
|
+
statusName: "transactionPending",
|
|
15
|
+
statusData: null
|
|
16
|
+
})
|
|
17
|
+
) : s.eventName === "error" && t(
|
|
18
|
+
e({
|
|
19
|
+
statusName: "error",
|
|
20
|
+
statusData: s.error
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
[t]
|
|
25
|
+
), r = n(
|
|
26
|
+
(s) => {
|
|
27
|
+
t(
|
|
28
|
+
e({
|
|
29
|
+
statusName: "transactionSuccess",
|
|
30
|
+
statusData: s || null
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
[t]
|
|
35
|
+
), o = n(() => {
|
|
36
|
+
t(
|
|
37
|
+
e({
|
|
38
|
+
statusName: "exit",
|
|
39
|
+
statusData: null
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}, [t]);
|
|
43
|
+
u(() => {
|
|
44
|
+
const s = i({
|
|
45
|
+
onEvent: a,
|
|
46
|
+
onExit: o,
|
|
47
|
+
onSuccess: r
|
|
48
|
+
});
|
|
49
|
+
return () => {
|
|
50
|
+
s();
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
S as useSetupOnrampEventListeners
|
|
56
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HTMLAttributes } from 'react';
|
|
2
|
+
import { InputType } from '../forms/ExchangeAmountInput/types';
|
|
3
|
+
import { FundForm, FundFormProps } from './FundForm';
|
|
4
|
+
import { useFundContext } from './FundProvider';
|
|
5
|
+
import { FundTitle, FundTitleProps } from './FundTitle';
|
|
6
|
+
import { FetchBuyUrlParams } from './hooks/useBuyUrl';
|
|
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;
|
|
9
|
+
declare const FundFooter: (props: HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export { Fund as unstable_Fund, FundFooter as unstable_FundFooter, FundForm as unstable_FundForm, FundTitle as unstable_FundTitle, useFundContext as unstable_useFundContext, type CamelToSnakeCase as unstable_CamelToSnakeCase, type CamelToSnakeCaseNested as unstable_CamelToSnakeCaseNested, type FundAction as unstable_FundAction, type FetchBuyOptions as unstable_FetchBuyOptions, type FetchBuyQuote as unstable_FetchBuyQuote, type FetchBuyUrlParams as unstable_FetchBuyUrlParams, type FundContextType as unstable_FundContextType, type FundFormProps as unstable_FundFormProps, type FundLifecycleStatus as unstable_FundLifecycleStatus, type FundPaymentMethod as unstable_FundPaymentMethod, type FundPresetAmountInputs as unstable_FundPresetAmountInputs, type FundProps as unstable_FundProps, type FundState as unstable_FundState, type FundStateError as unstable_FundStateError, type FundStateProps as unstable_FundStateProps, type FundTitleProps as unstable_FundTitleProps, type InputType as unstable_InputType, type OnrampAmount as unstable_OnrampAmount, type OnrampBuyQuoteResponse as unstable_OnrampBuyQuoteResponse, type OnrampBuyOptionsResponse as unstable_OnrampBuyOptionsResponse, type OnrampBuyOptionsSnakeCaseResponse as unstable_OnrampBuyOptionsSnakeCaseResponse, type OnrampBuyQuoteSnakeCaseResponse as unstable_OnrampBuyQuoteSnakeCaseResponse, type OnrampError as unstable_OnrampError, type OnrampNetwork as unstable_OnrampNetwork, type OnrampPaymentCurrency as unstable_OnrampPaymentCurrency, type OnrampPaymentMethodLimit as unstable_OnrampPaymentMethodLimit, type OnrampPurchaseCurrency as unstable_OnrampPurchaseCurrency, type OnrampSuccessEventData as unstable_OnrampSuccessEventData, };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as t, jsxs as m, Fragment as a } from "react/jsx-runtime";
|
|
2
|
+
import { useId as F } from "react";
|
|
3
|
+
import { useAppConfig as f } from "../CDPReactProvider/index.js";
|
|
4
|
+
import { CoinbaseFooter as l } from "../ui/CoinbaseFooter/index.js";
|
|
5
|
+
import { FundForm as p } from "./FundForm.js";
|
|
6
|
+
import { FundProvider as c, useFundContext as _ } from "./FundProvider.js";
|
|
7
|
+
import { FundTitle as b } from "./FundTitle.js";
|
|
8
|
+
import { useSetupOnrampEventListeners as C } from "./hooks/useSetupOnrampEventListeners.js";
|
|
9
|
+
import '../../assets/Fund.css';const x = "Fund-module__fund___6j-Og", g = {
|
|
10
|
+
fund: x
|
|
11
|
+
}, E = ({ className: n = "", children: e, openIn: r, submitLabel: s, title: u, ...o }) => /* @__PURE__ */ t(c, { ...o, children: /* @__PURE__ */ t("div", { className: `${g.fund} ${n}`, children: /* @__PURE__ */ t(h, { openIn: r, submitLabel: s, title: u, children: e }) }) }), h = ({
|
|
12
|
+
children: n,
|
|
13
|
+
openIn: e,
|
|
14
|
+
submitLabel: r,
|
|
15
|
+
title: s
|
|
16
|
+
}) => {
|
|
17
|
+
const { state: u } = _(), o = F(), { showCoinbaseFooter: d } = f();
|
|
18
|
+
return C(), n ? typeof n == "function" ? n(u) : n : /* @__PURE__ */ t(p, { "aria-labelledby": o, openIn: e, submitLabel: r, children: ({ Content: i }) => /* @__PURE__ */ m(a, { children: [
|
|
19
|
+
/* @__PURE__ */ t(b, { id: o, children: s }),
|
|
20
|
+
i,
|
|
21
|
+
d && /* @__PURE__ */ t(j, {})
|
|
22
|
+
] }) });
|
|
23
|
+
}, j = (n) => /* @__PURE__ */ t(l, { ...n });
|
|
24
|
+
export {
|
|
25
|
+
E as unstable_Fund,
|
|
26
|
+
j as unstable_FundFooter,
|
|
27
|
+
p as unstable_FundForm,
|
|
28
|
+
b as unstable_FundTitle,
|
|
29
|
+
_ as unstable_useFundContext
|
|
30
|
+
};
|