@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.
- package/README.md +2 -2
- package/dist/assets/AmountInput.css +1 -1
- package/dist/assets/AuthButton.css +1 -1
- package/dist/assets/Button.css +1 -1
- package/dist/assets/ButtonBase.css +1 -0
- package/dist/assets/CoinbaseFooter.css +1 -0
- 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/Select.css +1 -0
- 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/SignIn/SignInFooter.d.ts +1 -1
- package/dist/components/SignIn/SignInFooter.js +4 -15
- 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/forms/Select/index.d.ts +21 -0
- package/dist/components/forms/Select/index.js +74 -0
- package/dist/components/ui/Button/index.d.ts +4 -5
- package/dist/components/ui/Button/index.js +35 -56
- package/dist/components/ui/ButtonBase/index.d.ts +8 -0
- package/dist/components/ui/ButtonBase/index.js +45 -0
- package/dist/components/ui/CoinbaseFooter/index.d.ts +2 -0
- package/dist/components/ui/CoinbaseFooter/index.js +19 -0
- package/dist/components/ui/LoadingSkeleton/index.d.ts +3 -2
- package/dist/components/ui/LoadingSkeleton/index.js +9 -15
- 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/IconCheck.d.ts +2 -0
- package/dist/icons/IconCheck.js +14 -0
- package/dist/icons/IconChevronDown.d.ts +2 -0
- package/dist/icons/IconChevronDown.js +14 -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 +3 -0
- package/dist/icons/index.js +20 -14
- package/dist/index.d.ts +2 -0
- package/dist/index.js +86 -69
- package/dist/theme/theme.d.ts +120 -2
- package/dist/theme/tokens.d.ts +346 -0
- package/dist/theme/tokens.js +76 -8
- 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 +7 -6
- package/dist/assets/SignInFooter.css +0 -1
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Dispatch, ReactNode } from 'react';
|
|
2
|
+
import { InputType } from '../forms/ExchangeAmountInput/types';
|
|
3
|
+
import { FetchBuyUrlParams } from './hooks/useBuyUrl';
|
|
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;
|
|
5
|
+
export type CamelToSnakeCaseNested<T> = T extends readonly any[] ? T : T extends object ? {
|
|
6
|
+
[K in keyof T as K extends string ? CamelToSnakeCase<K> : K]: CamelToSnakeCaseNested<T[K]>;
|
|
7
|
+
} : T;
|
|
8
|
+
export type FundPresetAmountInputs = readonly [number, number, number];
|
|
9
|
+
export interface FundPaymentMethod {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
icon: ReactNode;
|
|
14
|
+
minAmount?: number;
|
|
15
|
+
maxAmount?: number;
|
|
16
|
+
}
|
|
17
|
+
export type OnrampOpenEvent = {
|
|
18
|
+
eventName: "open";
|
|
19
|
+
widgetName: string;
|
|
20
|
+
};
|
|
21
|
+
export type OnrampTransitionViewEvent = {
|
|
22
|
+
eventName: "transition_view";
|
|
23
|
+
pageRoute: string;
|
|
24
|
+
};
|
|
25
|
+
export type OnrampPublicErrorEvent = {
|
|
26
|
+
eventName: "error";
|
|
27
|
+
error: OnrampError;
|
|
28
|
+
};
|
|
29
|
+
export type OnrampExitEvent = {
|
|
30
|
+
eventName: "exit";
|
|
31
|
+
error?: OnrampError;
|
|
32
|
+
};
|
|
33
|
+
export type OnrampSuccessEvent = {
|
|
34
|
+
eventName: "success";
|
|
35
|
+
data?: OnrampSuccessEventData;
|
|
36
|
+
};
|
|
37
|
+
export type OnrampSuccessEventData = {
|
|
38
|
+
assetImageUrl: string;
|
|
39
|
+
assetName: string;
|
|
40
|
+
assetSymbol: string;
|
|
41
|
+
chainId: string;
|
|
42
|
+
};
|
|
43
|
+
export type RequestOpenUrlEvent = {
|
|
44
|
+
eventName: "request_open_url";
|
|
45
|
+
url: string;
|
|
46
|
+
};
|
|
47
|
+
export type EventMetadata = OnrampOpenEvent | OnrampTransitionViewEvent | OnrampPublicErrorEvent | OnrampExitEvent | OnrampSuccessEvent | RequestOpenUrlEvent;
|
|
48
|
+
export interface OnrampError {
|
|
49
|
+
errorType: "internal_error" | "handled_error" | "network_error" | "unknown_error";
|
|
50
|
+
code?: string;
|
|
51
|
+
debugMessage?: string;
|
|
52
|
+
}
|
|
53
|
+
export type FundLifecycleStatus = {
|
|
54
|
+
statusName: "init";
|
|
55
|
+
statusData: null;
|
|
56
|
+
} | {
|
|
57
|
+
statusName: "exit";
|
|
58
|
+
statusData: null;
|
|
59
|
+
} | {
|
|
60
|
+
statusName: "error";
|
|
61
|
+
statusData: OnrampError;
|
|
62
|
+
} | {
|
|
63
|
+
statusName: "transactionSuccess";
|
|
64
|
+
statusData: OnrampSuccessEventData | null;
|
|
65
|
+
} | {
|
|
66
|
+
statusName: "transactionPending";
|
|
67
|
+
statusData: null;
|
|
68
|
+
};
|
|
69
|
+
export type FundLifecycleEvents = {
|
|
70
|
+
onError?: (e: OnrampError | undefined) => void;
|
|
71
|
+
onStatus?: (lifecycleStatus: FundLifecycleStatus) => void;
|
|
72
|
+
onSuccess?: (result?: OnrampSuccessEventData) => void;
|
|
73
|
+
};
|
|
74
|
+
export type FundStateError = {
|
|
75
|
+
code: string;
|
|
76
|
+
message: string;
|
|
77
|
+
};
|
|
78
|
+
export interface FundState {
|
|
79
|
+
country: string;
|
|
80
|
+
cryptoAmount?: number;
|
|
81
|
+
cryptoCurrency: string;
|
|
82
|
+
cryptoDecimalPlaces?: number;
|
|
83
|
+
exchangeRate?: number;
|
|
84
|
+
exchangeRateError?: FundStateError | null;
|
|
85
|
+
isExchangeRatePending?: boolean;
|
|
86
|
+
isPaymentMethodsPending?: boolean;
|
|
87
|
+
fiatAmount?: number;
|
|
88
|
+
fiatCurrency: string;
|
|
89
|
+
fiatDecimalPlaces?: number;
|
|
90
|
+
locale?: string;
|
|
91
|
+
network: string;
|
|
92
|
+
paymentMethods?: FundPaymentMethod[];
|
|
93
|
+
paymentMethodsError?: FundStateError | null;
|
|
94
|
+
presetAmountInputs?: FundPresetAmountInputs;
|
|
95
|
+
selectedInputType: InputType;
|
|
96
|
+
selectedPaymentMethod?: FundPaymentMethod;
|
|
97
|
+
subdivision?: string;
|
|
98
|
+
transactionStatus: FundLifecycleStatus;
|
|
99
|
+
}
|
|
100
|
+
export type FundStateProps = Pick<FundState, "country" | "cryptoCurrency" | "cryptoDecimalPlaces" | "fiatCurrency" | "fiatDecimalPlaces" | "locale" | "network" | "presetAmountInputs" | "subdivision">;
|
|
101
|
+
export interface FundProps extends FundStateProps, FundLifecycleEvents {
|
|
102
|
+
children?: ReactNode | ((state: FundState) => ReactNode);
|
|
103
|
+
className?: string;
|
|
104
|
+
fetchBuyOptions: FetchBuyOptions;
|
|
105
|
+
fetchBuyQuote: FetchBuyQuote;
|
|
106
|
+
inputType?: InputType;
|
|
107
|
+
openIn?: "popup" | "tab";
|
|
108
|
+
submitLabel?: ReactNode;
|
|
109
|
+
title?: ReactNode;
|
|
110
|
+
}
|
|
111
|
+
export type FundAction = {
|
|
112
|
+
type: "SET_FIELD";
|
|
113
|
+
payload: {
|
|
114
|
+
[K in keyof FundState]: {
|
|
115
|
+
field: K;
|
|
116
|
+
value: FundState[K];
|
|
117
|
+
};
|
|
118
|
+
}[keyof FundState];
|
|
119
|
+
} | {
|
|
120
|
+
type: "SET_AMOUNTS";
|
|
121
|
+
payload: {
|
|
122
|
+
cryptoAmount: number;
|
|
123
|
+
fiatAmount: number;
|
|
124
|
+
};
|
|
125
|
+
} | {
|
|
126
|
+
type: "FETCH_EXCHANGE_RATE";
|
|
127
|
+
} | {
|
|
128
|
+
type: "SET_EXCHANGE_RATE_SUCCESS";
|
|
129
|
+
payload: {
|
|
130
|
+
exchangeRate: number | undefined;
|
|
131
|
+
};
|
|
132
|
+
} | {
|
|
133
|
+
type: "SET_EXCHANGE_RATE_ERROR";
|
|
134
|
+
payload: {
|
|
135
|
+
error: Partial<NonNullable<FundState["exchangeRateError"]>>;
|
|
136
|
+
};
|
|
137
|
+
} | {
|
|
138
|
+
type: "FETCH_PAYMENT_METHODS";
|
|
139
|
+
} | {
|
|
140
|
+
type: "SET_PAYMENT_METHODS_SUCCESS";
|
|
141
|
+
payload: {
|
|
142
|
+
paymentMethods: FundPaymentMethod[];
|
|
143
|
+
};
|
|
144
|
+
} | {
|
|
145
|
+
type: "SET_PAYMENT_METHODS_ERROR";
|
|
146
|
+
payload: {
|
|
147
|
+
error: Partial<NonNullable<FundState["paymentMethodsError"]>>;
|
|
148
|
+
};
|
|
149
|
+
} | {
|
|
150
|
+
type: "SET_TRANSACTION_STATUS";
|
|
151
|
+
payload: {
|
|
152
|
+
transactionStatus: FundLifecycleStatus;
|
|
153
|
+
};
|
|
154
|
+
} | {
|
|
155
|
+
type: "SYNC_WITH_PROPS";
|
|
156
|
+
payload: FundStateProps;
|
|
157
|
+
};
|
|
158
|
+
export type FundContextType = {
|
|
159
|
+
state: FundState;
|
|
160
|
+
dispatch: Dispatch<FundAction>;
|
|
161
|
+
fetchBuyUrl: (params: FetchBuyUrlParams, onError?: (e: OnrampError | undefined) => void) => Promise<string>;
|
|
162
|
+
};
|
|
163
|
+
export type OnrampPaymentMethodLimit = {
|
|
164
|
+
id: string;
|
|
165
|
+
min: string;
|
|
166
|
+
max: string;
|
|
167
|
+
};
|
|
168
|
+
export type OnrampPaymentCurrency = {
|
|
169
|
+
id: string;
|
|
170
|
+
limits: OnrampPaymentMethodLimit[];
|
|
171
|
+
};
|
|
172
|
+
export type OnrampNetwork = {
|
|
173
|
+
name: string;
|
|
174
|
+
displayName: string;
|
|
175
|
+
chainId: string;
|
|
176
|
+
contractAddress: string;
|
|
177
|
+
iconUrl: string;
|
|
178
|
+
};
|
|
179
|
+
export type OnrampPurchaseCurrency = {
|
|
180
|
+
id: string;
|
|
181
|
+
name: string;
|
|
182
|
+
symbol: string;
|
|
183
|
+
iconUrl: string;
|
|
184
|
+
networks: OnrampNetwork[];
|
|
185
|
+
};
|
|
186
|
+
export type OnrampAmount = {
|
|
187
|
+
value: string;
|
|
188
|
+
currency: string;
|
|
189
|
+
};
|
|
190
|
+
export type OnrampBuyOptionsResponse = {
|
|
191
|
+
paymentCurrencies: OnrampPaymentCurrency[];
|
|
192
|
+
purchaseCurrencies: OnrampPurchaseCurrency[];
|
|
193
|
+
};
|
|
194
|
+
export type OnrampBuyOptionsSnakeCaseResponse = CamelToSnakeCaseNested<OnrampBuyOptionsResponse>;
|
|
195
|
+
export type OnrampBuyQuoteResponse = {
|
|
196
|
+
paymentTotal: OnrampAmount;
|
|
197
|
+
paymentSubtotal: OnrampAmount;
|
|
198
|
+
purchaseAmount: OnrampAmount;
|
|
199
|
+
coinbaseFee: OnrampAmount;
|
|
200
|
+
networkFee: OnrampAmount;
|
|
201
|
+
quoteId: string;
|
|
202
|
+
onrampUrl?: string;
|
|
203
|
+
};
|
|
204
|
+
export type OnrampBuyQuoteSnakeCaseResponse = CamelToSnakeCaseNested<OnrampBuyQuoteResponse>;
|
|
205
|
+
export type FetchBuyOptions = (params: {
|
|
206
|
+
country: string;
|
|
207
|
+
subdivision?: string;
|
|
208
|
+
}) => Promise<OnrampBuyOptionsResponse>;
|
|
209
|
+
export type FetchBuyQuote = (params: {
|
|
210
|
+
destinationAddress: string;
|
|
211
|
+
purchaseCurrency: string;
|
|
212
|
+
purchaseNetwork: string;
|
|
213
|
+
paymentAmount: string;
|
|
214
|
+
paymentCurrency: string;
|
|
215
|
+
paymentMethod: string;
|
|
216
|
+
country: string;
|
|
217
|
+
subdivision?: string;
|
|
218
|
+
}) => Promise<OnrampBuyQuoteResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "react";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FundAction, FundState } from './types';
|
|
2
|
+
export declare const useFundReducer: (initialState: FundState) => [FundState, import('react').ActionDispatch<[action: FundAction]>];
|
|
3
|
+
export declare const createSetFieldAction: <K extends keyof FundState>(field: K, value: FundState[K]) => {
|
|
4
|
+
type: "SET_FIELD";
|
|
5
|
+
payload: {
|
|
6
|
+
field: K;
|
|
7
|
+
value: FundState[K];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useReducer as t } from "react";
|
|
2
|
+
const n = (a, e) => {
|
|
3
|
+
if (e.statusName === "init" || e.statusName === "exit" || e.statusName === "transactionPending")
|
|
4
|
+
return e;
|
|
5
|
+
if (e.statusName === "error" || e.statusName === "transactionSuccess") {
|
|
6
|
+
if (a.statusName === "error")
|
|
7
|
+
return e;
|
|
8
|
+
if (a.statusName === "transactionSuccess" && e.statusName === "transactionSuccess" && a.statusData)
|
|
9
|
+
return {
|
|
10
|
+
...e,
|
|
11
|
+
statusData: {
|
|
12
|
+
...a.statusData,
|
|
13
|
+
...e.statusData
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return e;
|
|
18
|
+
};
|
|
19
|
+
function s(a, e) {
|
|
20
|
+
const { type: r } = e;
|
|
21
|
+
switch (r) {
|
|
22
|
+
case "SET_AMOUNTS":
|
|
23
|
+
return {
|
|
24
|
+
...a,
|
|
25
|
+
cryptoAmount: e.payload.cryptoAmount,
|
|
26
|
+
fiatAmount: e.payload.fiatAmount
|
|
27
|
+
};
|
|
28
|
+
case "SET_FIELD":
|
|
29
|
+
return e.payload ? { ...a, [e.payload.field]: e.payload.value } : a;
|
|
30
|
+
case "FETCH_EXCHANGE_RATE":
|
|
31
|
+
return {
|
|
32
|
+
...a,
|
|
33
|
+
isExchangeRatePending: !0,
|
|
34
|
+
exchangeRateError: null
|
|
35
|
+
};
|
|
36
|
+
case "SET_EXCHANGE_RATE_SUCCESS":
|
|
37
|
+
return {
|
|
38
|
+
...a,
|
|
39
|
+
isExchangeRatePending: !1,
|
|
40
|
+
exchangeRate: e.payload.exchangeRate,
|
|
41
|
+
exchangeRateError: null
|
|
42
|
+
};
|
|
43
|
+
case "SET_EXCHANGE_RATE_ERROR":
|
|
44
|
+
return {
|
|
45
|
+
...a,
|
|
46
|
+
exchangeRate: void 0,
|
|
47
|
+
isExchangeRatePending: !1,
|
|
48
|
+
exchangeRateError: {
|
|
49
|
+
code: e.payload.error.code || "UNKNOWN_EXCHANGE_RATE_ERROR",
|
|
50
|
+
message: e.payload.error.message || "Something went wrong fetching exchange rate"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
case "FETCH_PAYMENT_METHODS":
|
|
54
|
+
return {
|
|
55
|
+
...a,
|
|
56
|
+
isPaymentMethodsPending: !0,
|
|
57
|
+
paymentMethodsError: null
|
|
58
|
+
};
|
|
59
|
+
case "SET_PAYMENT_METHODS_SUCCESS":
|
|
60
|
+
return {
|
|
61
|
+
...a,
|
|
62
|
+
isPaymentMethodsPending: !1,
|
|
63
|
+
paymentMethods: e.payload.paymentMethods,
|
|
64
|
+
selectedPaymentMethod: e.payload.paymentMethods[0],
|
|
65
|
+
paymentMethodsError: null
|
|
66
|
+
};
|
|
67
|
+
case "SET_PAYMENT_METHODS_ERROR":
|
|
68
|
+
return {
|
|
69
|
+
...a,
|
|
70
|
+
paymentMethods: void 0,
|
|
71
|
+
isPaymentMethodsPending: !1,
|
|
72
|
+
paymentMethodsError: {
|
|
73
|
+
code: e.payload.error.code || "UNKNOWN_PAYMENT_METHODS_ERROR",
|
|
74
|
+
message: e.payload.error.message || "Something went wrong fetching payment methods"
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
case "SET_TRANSACTION_STATUS":
|
|
78
|
+
return {
|
|
79
|
+
...a,
|
|
80
|
+
transactionStatus: n(
|
|
81
|
+
a.transactionStatus,
|
|
82
|
+
e.payload.transactionStatus
|
|
83
|
+
)
|
|
84
|
+
};
|
|
85
|
+
case "SYNC_WITH_PROPS":
|
|
86
|
+
return {
|
|
87
|
+
...a,
|
|
88
|
+
...e.payload
|
|
89
|
+
};
|
|
90
|
+
default:
|
|
91
|
+
throw new Error("Unknown action type");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const d = (a) => t(s, a), E = (a, e) => ({
|
|
95
|
+
type: "SET_FIELD",
|
|
96
|
+
payload: {
|
|
97
|
+
field: a,
|
|
98
|
+
value: e
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
export {
|
|
102
|
+
E as createSetFieldAction,
|
|
103
|
+
d as useFundReducer
|
|
104
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OnrampBuyOptionsResponse, FundPaymentMethod } from '../types';
|
|
2
|
+
export declare const buildCoinbasePaymentMethodDescription: (paymentMethodLimits: Array<{
|
|
3
|
+
id: string;
|
|
4
|
+
}>) => string;
|
|
5
|
+
export declare const buildPaymentMethods: (paymentOptions: OnrampBuyOptionsResponse, currency: string, country: string) => FundPaymentMethod[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import { IconAppleLogo as u } from "../../../icons/IconAppleLogo.js";
|
|
3
|
+
import { IconCoinbaseMark as A } from "../../../icons/IconCoinbaseMark.js";
|
|
4
|
+
import { IconCreditCard as C } from "../../../icons/IconCreditCard.js";
|
|
5
|
+
const s = 2, c = 500, M = (n) => [
|
|
6
|
+
// Check API-provided methods
|
|
7
|
+
n.some((e) => e.id === "ACH_BANK_ACCOUNT") && "ACH",
|
|
8
|
+
n.some((e) => e.id === "CARD") && "debit",
|
|
9
|
+
n.some((e) => e.id === "FIAT_WALLET") && "cash",
|
|
10
|
+
// Always include these methods
|
|
11
|
+
"crypto balance"
|
|
12
|
+
].filter(Boolean).join(", "), b = ({ limits: n }) => {
|
|
13
|
+
const o = n.flatMap((t) => t.min ? [Number(t.min)] : []), e = n.flatMap((t) => t.max ? [Number(t.max)] : []);
|
|
14
|
+
return {
|
|
15
|
+
id: n[0].id,
|
|
16
|
+
// use the first limit id as the coinbase payment method id to avoid passing in an invalid option
|
|
17
|
+
name: "Coinbase",
|
|
18
|
+
description: M(n),
|
|
19
|
+
icon: /* @__PURE__ */ r(A, {}),
|
|
20
|
+
minAmount: o.length > 0 ? Math.min(...o) : s,
|
|
21
|
+
maxAmount: e.length > 0 ? Math.max(...e) : c
|
|
22
|
+
};
|
|
23
|
+
}, l = (n) => [
|
|
24
|
+
{
|
|
25
|
+
id: "APPLE_PAY_GUEST",
|
|
26
|
+
name: "Apple Pay",
|
|
27
|
+
icon: /* @__PURE__ */ r(u, {})
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: "CARD_GUEST",
|
|
31
|
+
name: "Debit card",
|
|
32
|
+
icon: /* @__PURE__ */ r(C, {})
|
|
33
|
+
}
|
|
34
|
+
].map((e) => {
|
|
35
|
+
const t = n.limits.find(
|
|
36
|
+
(a) => a.id === e.id.replace("_GUEST", "")
|
|
37
|
+
);
|
|
38
|
+
return {
|
|
39
|
+
...e,
|
|
40
|
+
description: "Up to $500/week. No sign up required.",
|
|
41
|
+
minAmount: Number(t?.min) || s,
|
|
42
|
+
maxAmount: Number(t?.max) || c
|
|
43
|
+
};
|
|
44
|
+
}), N = (n, o, e) => {
|
|
45
|
+
const t = o.toUpperCase(), a = e.toUpperCase(), i = n.paymentCurrencies.find(
|
|
46
|
+
(p) => p.id.toUpperCase() === t
|
|
47
|
+
);
|
|
48
|
+
if (!i)
|
|
49
|
+
return [];
|
|
50
|
+
const d = b(i);
|
|
51
|
+
let m = [];
|
|
52
|
+
return a === "US" && t === "USD" && (m = l(i)), [d, ...m];
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
M as buildCoinbasePaymentMethodDescription,
|
|
56
|
+
N as buildPaymentMethods
|
|
57
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EventMetadata, OnrampError, OnrampSuccessEventData } from '../types';
|
|
2
|
+
type SetupOnrampEventListenersParams = {
|
|
3
|
+
host?: string;
|
|
4
|
+
onEvent?: (event: EventMetadata) => void;
|
|
5
|
+
onExit?: (error?: OnrampError) => void;
|
|
6
|
+
onSuccess?: (data?: OnrampSuccessEventData) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function setupOnrampEventListeners({ host, onEvent, onExit, onSuccess, }: SetupOnrampEventListenersParams): () => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
import { subscribeToWindowMessage as o, DEFAULT_ONRAMP_URL as a } from "./subscribeToWindowMessage.js";
|
|
3
|
+
function b({
|
|
4
|
+
host: s = a,
|
|
5
|
+
onEvent: t,
|
|
6
|
+
onExit: n,
|
|
7
|
+
onSuccess: r
|
|
8
|
+
}) {
|
|
9
|
+
return o({
|
|
10
|
+
allowedOrigin: s,
|
|
11
|
+
onMessage: (i) => {
|
|
12
|
+
const e = i;
|
|
13
|
+
e.eventName === "success" && r?.(e.data), e.eventName === "exit" && n?.(e.error), t?.(e);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
b as setupOnrampEventListeners
|
|
19
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type JsonObject = {
|
|
2
|
+
[Key in string]?: JsonValue;
|
|
3
|
+
};
|
|
4
|
+
export type JsonArray = JsonValue[];
|
|
5
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
6
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
7
|
+
export declare const DEFAULT_ONRAMP_URL = "https://pay.coinbase.com";
|
|
8
|
+
type MessageData = JsonObject;
|
|
9
|
+
export declare function subscribeToWindowMessage({ onMessage, allowedOrigin, onValidateOrigin, }: {
|
|
10
|
+
onMessage: (data?: MessageData) => void;
|
|
11
|
+
allowedOrigin: string;
|
|
12
|
+
onValidateOrigin?: (origin: string) => Promise<boolean>;
|
|
13
|
+
}): () => void;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const a = "https://pay.coinbase.com";
|
|
2
|
+
function d({
|
|
3
|
+
onMessage: s,
|
|
4
|
+
allowedOrigin: e = a,
|
|
5
|
+
onValidateOrigin: n = () => Promise.resolve(!0)
|
|
6
|
+
}) {
|
|
7
|
+
const o = (i) => {
|
|
8
|
+
if (!c({ event: i, allowedOrigin: e }))
|
|
9
|
+
return;
|
|
10
|
+
const { eventName: t, data: r } = JSON.parse(i.data);
|
|
11
|
+
t === "event" && (async () => await n(i.origin) && s(r))();
|
|
12
|
+
};
|
|
13
|
+
return window.addEventListener("message", o), () => {
|
|
14
|
+
window.removeEventListener("message", o);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const c = ({
|
|
18
|
+
event: s,
|
|
19
|
+
allowedOrigin: e
|
|
20
|
+
}) => !e || s.origin === e;
|
|
21
|
+
export {
|
|
22
|
+
a as DEFAULT_ONRAMP_URL,
|
|
23
|
+
d as subscribeToWindowMessage
|
|
24
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { unstable_FundProps as FundProps } from '../Fund';
|
|
3
|
+
interface FundModalProps extends FundProps {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
open?: boolean;
|
|
6
|
+
setIsOpen?: (value: boolean) => void;
|
|
7
|
+
}
|
|
8
|
+
declare const FundModal: ({ children, open, setIsOpen, openIn, submitLabel, title, ...fundProps }: FundModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export { FundModal as unstable_FundModal, type FundModalProps as unstable_FundModalProps };
|