@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.
Files changed (88) 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/ExchangeAmountInput.css +1 -1
  5. package/dist/assets/Fund.css +1 -0
  6. package/dist/assets/FundAmountInput.css +1 -0
  7. package/dist/assets/FundErrorScreen.css +1 -0
  8. package/dist/assets/FundForm.css +1 -0
  9. package/dist/assets/FundModal.css +1 -0
  10. package/dist/assets/FundPaymentMethods.css +1 -0
  11. package/dist/assets/FundPresetAmountInputs.css +1 -0
  12. package/dist/assets/FundTitle.css +1 -0
  13. package/dist/assets/FundTransactionStatus.css +1 -0
  14. package/dist/assets/Input.css +1 -1
  15. package/dist/assets/Modal.css +1 -1
  16. package/dist/assets/ThemeProvider.css +1 -1
  17. package/dist/components/Fund/FundForm.d.ts +18 -0
  18. package/dist/components/Fund/FundForm.js +156 -0
  19. package/dist/components/Fund/FundProvider.d.ts +6 -0
  20. package/dist/components/Fund/FundProvider.js +128 -0
  21. package/dist/components/Fund/FundTitle.d.ts +5 -0
  22. package/dist/components/Fund/FundTitle.js +17 -0
  23. package/dist/components/Fund/components/FundAmountInput.d.ts +5 -0
  24. package/dist/components/Fund/components/FundAmountInput.js +58 -0
  25. package/dist/components/Fund/components/FundErrorScreen.d.ts +6 -0
  26. package/dist/components/Fund/components/FundErrorScreen.js +118 -0
  27. package/dist/components/Fund/components/FundPaymentMethods.d.ts +6 -0
  28. package/dist/components/Fund/components/FundPaymentMethods.js +55 -0
  29. package/dist/components/Fund/components/FundPresetAmountInputs.d.ts +6 -0
  30. package/dist/components/Fund/components/FundPresetAmountInputs.js +41 -0
  31. package/dist/components/Fund/components/FundTransactionStatus.d.ts +8 -0
  32. package/dist/components/Fund/components/FundTransactionStatus.js +106 -0
  33. package/dist/components/Fund/hooks/useBuyUrl.d.ts +14 -0
  34. package/dist/components/Fund/hooks/useBuyUrl.js +65 -0
  35. package/dist/components/Fund/hooks/useEmitLifecycleStatus.d.ts +5 -0
  36. package/dist/components/Fund/hooks/useEmitLifecycleStatus.js +14 -0
  37. package/dist/components/Fund/hooks/useExchangeRate.d.ts +11 -0
  38. package/dist/components/Fund/hooks/useExchangeRate.js +62 -0
  39. package/dist/components/Fund/hooks/usePaymentMethods.d.ts +11 -0
  40. package/dist/components/Fund/hooks/usePaymentMethods.js +112 -0
  41. package/dist/components/Fund/hooks/usePopupMonitor.d.ts +3 -0
  42. package/dist/components/Fund/hooks/usePopupMonitor.js +17 -0
  43. package/dist/components/Fund/hooks/useSetupOnrampEventListeners.d.ts +1 -0
  44. package/dist/components/Fund/hooks/useSetupOnrampEventListeners.js +56 -0
  45. package/dist/components/Fund/index.d.ts +10 -0
  46. package/dist/components/Fund/index.js +30 -0
  47. package/dist/components/Fund/types.d.ts +218 -0
  48. package/dist/components/Fund/types.js +1 -0
  49. package/dist/components/Fund/useFundReducer.d.ts +9 -0
  50. package/dist/components/Fund/useFundReducer.js +104 -0
  51. package/dist/components/Fund/utils/buildPaymentMethods.d.ts +5 -0
  52. package/dist/components/Fund/utils/buildPaymentMethods.js +57 -0
  53. package/dist/components/Fund/utils/setupOnrampEventListeners.d.ts +9 -0
  54. package/dist/components/Fund/utils/setupOnrampEventListeners.js +19 -0
  55. package/dist/components/Fund/utils/subscribeToWindowMessage.d.ts +14 -0
  56. package/dist/components/Fund/utils/subscribeToWindowMessage.js +24 -0
  57. package/dist/components/FundModal/index.d.ts +9 -0
  58. package/dist/components/FundModal/index.js +92 -0
  59. package/dist/components/forms/ExchangeAmountInput/index.js +93 -65
  60. package/dist/components/forms/ExchangeAmountInput/types.d.ts +2 -1
  61. package/dist/components/forms/ExchangeAmountInput/useExchangeAmountInput.js +42 -38
  62. package/dist/components/forms/Input/index.d.ts +6 -2
  63. package/dist/components/forms/Input/index.js +27 -12
  64. package/dist/components/forms/PhoneNumberInput/index.d.ts +2 -2
  65. package/dist/components/ui/Button/index.js +7 -7
  66. package/dist/components/ui/ButtonBase/index.js +19 -19
  67. package/dist/components/ui/LoadingSpinner/index.d.ts +9 -2
  68. package/dist/components/ui/LoadingSpinner/index.js +39 -17
  69. package/dist/icons/IconAppleLogo.d.ts +2 -0
  70. package/dist/icons/IconAppleLogo.js +10 -0
  71. package/dist/icons/IconCoinbaseMark.d.ts +2 -0
  72. package/dist/icons/IconCoinbaseMark.js +13 -0
  73. package/dist/icons/IconCreditCard.d.ts +2 -0
  74. package/dist/icons/IconCreditCard.js +10 -0
  75. package/dist/icons/IconExclamationTriangle.d.ts +2 -0
  76. package/dist/icons/IconExclamationTriangle.js +14 -0
  77. package/dist/icons/index.d.ts +1 -0
  78. package/dist/icons/index.js +18 -16
  79. package/dist/index.d.ts +2 -0
  80. package/dist/index.js +86 -73
  81. package/dist/theme/theme.d.ts +23 -0
  82. package/dist/theme/tokens.d.ts +67 -0
  83. package/dist/theme/tokens.js +19 -2
  84. package/dist/utils/formatFiat.d.ts +1 -0
  85. package/dist/utils/formatFiat.js +13 -0
  86. package/dist/utils/openPopup.d.ts +7 -0
  87. package/dist/utils/openPopup.js +15 -0
  88. package/package.json +6 -6
@@ -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 };
@@ -0,0 +1,92 @@
1
+ import { jsxs as t, jsx as o, Fragment as x } from "react/jsx-runtime";
2
+ import { useId as O, useState as v, useCallback as h } from "react";
3
+ import { useAppConfig as T } from "../CDPReactProvider/index.js";
4
+ import { unstable_Fund as j, unstable_FundFooter as I } from "../Fund/index.js";
5
+ import { Button as p } from "../ui/Button/index.js";
6
+ import { Modal as $, ModalTrigger as z, ModalContent as A, ModalTitle as S, ModalClose as k } from "../ui/Modal/index.js";
7
+ import { VisuallyHidden as M } from "../ui/VisuallyHidden/index.js";
8
+ import { IconXMark as U } from "../../icons/IconXMark.js";
9
+ import { FundTitle as a } from "../Fund/FundTitle.js";
10
+ import { FundForm as V } from "../Fund/FundForm.js";
11
+ import '../../assets/FundModal.css';const W = "FundModal-module__trigger___2IuXj", X = "FundModal-module__fund___1AmQa", q = "FundModal-module__title___lNsoT", B = "FundModal-module__content___9f3ze", n = {
12
+ trigger: W,
13
+ fund: X,
14
+ "no-footer": "FundModal-module__no-footer___WKV78",
15
+ "title-buttons": "FundModal-module__title-buttons___Lctf7",
16
+ "close-button": "FundModal-module__close-button___jzdFM",
17
+ "close-icon": "FundModal-module__close-icon___WoA4a",
18
+ "fund-inner": "FundModal-module__fund-inner___UuOq3",
19
+ "tx-status": "FundModal-module__tx-status___fc-3f",
20
+ title: q,
21
+ content: B
22
+ }, Y = ({
23
+ children: b,
24
+ open: i,
25
+ setIsOpen: c,
26
+ openIn: u,
27
+ submitLabel: _,
28
+ title: d,
29
+ ...m
30
+ }) => {
31
+ const { showCoinbaseFooter: f } = T(), l = O(), r = i !== void 0, [g, F] = v(!1), C = r ? i : g, s = h(
32
+ (e) => r ? c?.(e) : F(e),
33
+ [r, c, F]
34
+ ), N = h(() => {
35
+ s(!1);
36
+ }, [s]);
37
+ return /* @__PURE__ */ t($, { open: C, onOpenChange: s, children: [
38
+ /* @__PURE__ */ o(z, { asChild: !0, children: b || /* @__PURE__ */ t(p, { variant: "primary", className: n.trigger, children: [
39
+ "Deposit ",
40
+ m.cryptoCurrency.toUpperCase()
41
+ ] }) }),
42
+ /* @__PURE__ */ o(A, { "aria-describedby": void 0, children: /* @__PURE__ */ o(
43
+ j,
44
+ {
45
+ className: `${n.fund} ${f ? "" : n["no-footer"]}`,
46
+ openIn: u,
47
+ submitLabel: _,
48
+ title: d,
49
+ ...m,
50
+ children: /* @__PURE__ */ t(x, { children: [
51
+ /* @__PURE__ */ o(M, { children: /* @__PURE__ */ o(S, { asChild: !0, children: /* @__PURE__ */ o(a, { as: "span", children: d }) }) }),
52
+ /* @__PURE__ */ o(
53
+ V,
54
+ {
55
+ "aria-labelledby": l,
56
+ openIn: u,
57
+ unmountOnTransactionSuccess: !0,
58
+ unmount: N,
59
+ submitLabel: _,
60
+ children: ({ view: e, Content: y }) => /* @__PURE__ */ t(
61
+ "div",
62
+ {
63
+ className: `${n["fund-inner"]} ${e === "transaction-status" ? n["tx-status"] : ""}`,
64
+ children: [
65
+ /* @__PURE__ */ t("div", { className: n["title-buttons"], children: [
66
+ e === "error" ? /* @__PURE__ */ o(M, { children: /* @__PURE__ */ o(a, { id: l, children: d }) }) : /* @__PURE__ */ o(a, { className: n.title, id: l, children: d }),
67
+ /* @__PURE__ */ o(k, { asChild: !0, children: /* @__PURE__ */ o(
68
+ p,
69
+ {
70
+ className: n["close-button"],
71
+ "aria-label": "Close",
72
+ size: "md",
73
+ variant: "transparentSecondary",
74
+ children: /* @__PURE__ */ o(U, { className: n["close-icon"] })
75
+ }
76
+ ) })
77
+ ] }),
78
+ /* @__PURE__ */ o("div", { className: n.content, children: y })
79
+ ]
80
+ }
81
+ )
82
+ }
83
+ ),
84
+ f && /* @__PURE__ */ o(I, {})
85
+ ] })
86
+ }
87
+ ) })
88
+ ] });
89
+ };
90
+ export {
91
+ Y as unstable_FundModal
92
+ };