@coinbase/cdp-react-native 0.0.97 → 0.0.99
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/dist/types/index.d.ts +195 -0
- package/package.json +7 -7
package/dist/types/index.d.ts
CHANGED
|
@@ -3,76 +3,271 @@ import { JSX } from 'react';
|
|
|
3
3
|
import { Network } from '@coinbase/cdp-api-client';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* ApplePayButton component that renders an inline WebView for the Apple Pay payment flow.
|
|
8
|
+
* The WebView displays Coinbase's Apple Pay button and handles the payment process.
|
|
9
|
+
* This component is iOS-only and will return null on other platforms.
|
|
10
|
+
* Available in US only.
|
|
11
|
+
*
|
|
12
|
+
* This component must be used within an ApplePayProvider and works in conjunction with
|
|
13
|
+
* the useApplePay hook. The button automatically reads the payment URL from context
|
|
14
|
+
* after an order is created.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* function App() {
|
|
19
|
+
* return (
|
|
20
|
+
* <ApplePayProvider>
|
|
21
|
+
* <ApplePayFlow />
|
|
22
|
+
* </ApplePayProvider>
|
|
23
|
+
* );
|
|
24
|
+
* }
|
|
25
|
+
*
|
|
26
|
+
* function ApplePayFlow() {
|
|
27
|
+
* const { data, status, createOrder } = useApplePay();
|
|
28
|
+
*
|
|
29
|
+
* const handleCreateOrder = async () => {
|
|
30
|
+
* await createOrder({
|
|
31
|
+
* destination: { address: "0x1234567890123456789012345678901234567890", network: "base" },
|
|
32
|
+
* purchase: { amount: "100", currency: "usdc" },
|
|
33
|
+
* payment: { currency: "usd" },
|
|
34
|
+
* isSandbox: true,
|
|
35
|
+
* });
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* return (
|
|
39
|
+
* <>
|
|
40
|
+
* <Button onPress={handleCreateOrder} />
|
|
41
|
+
* {data && <ApplePayButton />}
|
|
42
|
+
* </>
|
|
43
|
+
* );
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param props - The component props.
|
|
48
|
+
* @param props.style - Optional style for the container.
|
|
49
|
+
* @returns An inline WebView with Apple Pay on iOS, or null on other platforms or if no order exists.
|
|
50
|
+
* @throws Error if used outside of ApplePayProvider.
|
|
51
|
+
*/
|
|
6
52
|
export declare function ApplePayButton({ style }: ApplePayButtonProps): JSX.Element | null;
|
|
7
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Props for the ApplePayButton component.
|
|
56
|
+
*/
|
|
8
57
|
export declare interface ApplePayButtonProps {
|
|
58
|
+
/** Optional style for the container. */
|
|
9
59
|
style?: object;
|
|
10
60
|
}
|
|
11
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Context value exposed by ApplePayProvider.
|
|
64
|
+
*/
|
|
12
65
|
export declare interface ApplePayContextValue {
|
|
66
|
+
/**
|
|
67
|
+
* Creates an Apple Pay onramp order.
|
|
68
|
+
*
|
|
69
|
+
* @param options - The order creation options.
|
|
70
|
+
*/
|
|
13
71
|
createOrder: (options: CreateOrderOptions) => Promise<void>;
|
|
72
|
+
/** The data for the created order, or undefined. */
|
|
14
73
|
data: EndUserApplePayOnrampOrderCreateResponse | undefined;
|
|
74
|
+
/** The current status of the onramp flow. */
|
|
15
75
|
status: ApplePayOnrampStatus;
|
|
76
|
+
/** Any error that occurred, or undefined. */
|
|
16
77
|
error: OnrampError | undefined;
|
|
78
|
+
/** Resets the hook state to idle. */
|
|
17
79
|
reset: () => void;
|
|
80
|
+
/** Whether debug mode is enabled. */
|
|
18
81
|
debug: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Internal: Handles payment events from the WebView.
|
|
84
|
+
* Used by ApplePayButton component.
|
|
85
|
+
*
|
|
86
|
+
* @param event - The event from the onramp widget.
|
|
87
|
+
*/
|
|
19
88
|
paymentEventHandler: (event: OnrampEvent) => void;
|
|
20
89
|
}
|
|
21
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Status states for the Apple Pay onramp flow.
|
|
93
|
+
*/
|
|
22
94
|
export declare type ApplePayOnrampStatus = "idle" | "pending" | "error" | "success";
|
|
23
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Provider component for Apple Pay onramp functionality.
|
|
98
|
+
* Manages order creation, user verification, and payment status.
|
|
99
|
+
* Must wrap components that use useApplePay hook or ApplePayButton.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* function App() {
|
|
104
|
+
* return (
|
|
105
|
+
* <ApplePayProvider>
|
|
106
|
+
* <ApplePayFlow />
|
|
107
|
+
* </ApplePayProvider>
|
|
108
|
+
* );
|
|
109
|
+
* }
|
|
110
|
+
*
|
|
111
|
+
* function ApplePayFlow() {
|
|
112
|
+
* const { status, data, createOrder, reset } = useApplePay();
|
|
113
|
+
*
|
|
114
|
+
* return (
|
|
115
|
+
* <>
|
|
116
|
+
* <Button onPress={() => createOrder({...})} />
|
|
117
|
+
* {data && <ApplePayButton />}
|
|
118
|
+
* </>
|
|
119
|
+
* );
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @param {ApplePayProviderProps} props - The provider props.
|
|
124
|
+
* @param {ReactNode} props.children - The child components to render within the provider.
|
|
125
|
+
* @param {boolean} [props.debug] - When true, logs webview events to the console.
|
|
126
|
+
* @returns {JSX.Element} The provider component.
|
|
127
|
+
*/
|
|
24
128
|
export declare function ApplePayProvider({ children, debug }: ApplePayProviderProps): JSX.Element;
|
|
25
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Props for ApplePayProvider.
|
|
132
|
+
*/
|
|
26
133
|
export declare interface ApplePayProviderProps {
|
|
134
|
+
/** The child components. */
|
|
27
135
|
children: ReactNode;
|
|
136
|
+
/** When true, logs webview events to the console. Defaults to false. */
|
|
28
137
|
debug?: boolean;
|
|
29
138
|
}
|
|
30
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Options for creating an Apple Pay onramp order.
|
|
142
|
+
*/
|
|
31
143
|
export declare interface CreateOrderOptions {
|
|
32
144
|
destination: {
|
|
145
|
+
/** The blockchain address receiving the purchased crypto. */
|
|
33
146
|
address: string;
|
|
147
|
+
/** The blockchain network for the destination address. */
|
|
34
148
|
network: Network;
|
|
35
149
|
};
|
|
36
150
|
purchase: {
|
|
151
|
+
/** The crypto amount to purchase, exclusive of fees (e.g., "10.00"). */
|
|
37
152
|
amount: string;
|
|
153
|
+
/** The cryptocurrency to purchase (e.g., "usdc"). */
|
|
38
154
|
currency: "usdc" | (string & {});
|
|
39
155
|
};
|
|
40
156
|
payment: {
|
|
157
|
+
/** The fiat currency to use for payment (e.g., "usd"). */
|
|
41
158
|
currency: "usd" | (string & {});
|
|
42
159
|
};
|
|
160
|
+
/** Set to true to perform a sandbox transaction for testing. Defaults to false. */
|
|
43
161
|
isSandbox?: boolean;
|
|
44
162
|
}
|
|
45
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Valid onramp event types.
|
|
166
|
+
*/
|
|
46
167
|
declare const ONRAMP_EVENT_TYPES: readonly ["onramp_api.load_pending", "onramp_api.load_success", "onramp_api.load_error", "onramp_api.polling_start", "onramp_api.polling_success", "onramp_api.polling_error", "onramp_api.commit_success", "onramp_api.commit_error", "onramp_api.cancel"];
|
|
47
168
|
|
|
169
|
+
/**
|
|
170
|
+
* An error that occurred during the onramp process.
|
|
171
|
+
*/
|
|
48
172
|
export declare interface OnrampError {
|
|
173
|
+
/** A unique identifier for the request that generated the error. This can be used to help debug issues with the API. */
|
|
49
174
|
correlationId?: string;
|
|
175
|
+
/** The error message. */
|
|
50
176
|
message?: string;
|
|
177
|
+
/** The error code. This is a code returned by the webview when rendering the payment link. */
|
|
51
178
|
code?: string;
|
|
52
179
|
}
|
|
53
180
|
|
|
181
|
+
/**
|
|
182
|
+
* An error event emitted by the onramp widget.
|
|
183
|
+
*/
|
|
54
184
|
declare type OnrampErrorEvent = {
|
|
55
185
|
type: Extract<OnrampEventType, "onramp_api.load_error" | "onramp_api.commit_error" | "onramp_api.polling_error">;
|
|
56
186
|
error: {
|
|
187
|
+
/** Optional error code. */
|
|
57
188
|
code?: string;
|
|
189
|
+
/** Optional error message. */
|
|
58
190
|
message?: string;
|
|
59
191
|
};
|
|
60
192
|
};
|
|
61
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Event emitted by the onramp widget.
|
|
196
|
+
*/
|
|
62
197
|
declare type OnrampEvent = {
|
|
198
|
+
/** The type of event. */
|
|
63
199
|
type: Exclude<OnrampEventType, "onramp_api.load_error" | "onramp_api.commit_error" | "onramp_api.polling_error">;
|
|
200
|
+
/** Optional message with additional details. */
|
|
64
201
|
message?: string;
|
|
65
202
|
} | OnrampErrorEvent;
|
|
66
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Event types emitted by the onramp widget.
|
|
206
|
+
* These match the event types from the Coinbase Pay API.
|
|
207
|
+
*/
|
|
67
208
|
declare type OnrampEventType = (typeof ONRAMP_EVENT_TYPES)[number];
|
|
68
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Hook for managing Apple Pay onramp flow on iOS.
|
|
212
|
+
* Provides access to order creation and payment status from ApplePayProvider context.
|
|
213
|
+
* Must be used within an ApplePayProvider.
|
|
214
|
+
*
|
|
215
|
+
* You can get started testing the Apple Pay Onramp API using sandbox mode.
|
|
216
|
+
* When you're ready to test with real funds contact us to get production access.
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```tsx
|
|
220
|
+
* function App() {
|
|
221
|
+
* return (
|
|
222
|
+
* <ApplePayProvider>
|
|
223
|
+
* <ApplePayFlow />
|
|
224
|
+
* </ApplePayProvider>
|
|
225
|
+
* );
|
|
226
|
+
* }
|
|
227
|
+
*
|
|
228
|
+
* function ApplePayFlow() {
|
|
229
|
+
* const { status, data, createOrder, reset } = useApplePay();
|
|
230
|
+
*
|
|
231
|
+
* const handleCreateOrder = async () => {
|
|
232
|
+
* await createOrder({
|
|
233
|
+
* destination: { address: "0x1234567890123456789012345678901234567890", network: "base" },
|
|
234
|
+
* purchase: { amount: "100", currency: "usdc" },
|
|
235
|
+
* payment: { currency: "usd" },
|
|
236
|
+
* isSandbox: true,
|
|
237
|
+
* });
|
|
238
|
+
* };
|
|
239
|
+
*
|
|
240
|
+
* return (
|
|
241
|
+
* <>
|
|
242
|
+
* <Button onPress={handleCreateOrder} />
|
|
243
|
+
* {data && <ApplePayButton />}
|
|
244
|
+
* </>
|
|
245
|
+
* );
|
|
246
|
+
* }
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @returns An object with functions and state for managing the onramp flow.
|
|
250
|
+
* @throws Error if used outside of ApplePayProvider.
|
|
251
|
+
*/
|
|
69
252
|
export declare function useApplePay(): UseApplePayReturn;
|
|
70
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Return type for the useApplePay hook.
|
|
256
|
+
*/
|
|
71
257
|
export declare interface UseApplePayReturn {
|
|
258
|
+
/**
|
|
259
|
+
* Creates an Apple Pay onramp order.
|
|
260
|
+
*
|
|
261
|
+
* @param options - The order creation options.
|
|
262
|
+
*/
|
|
72
263
|
createOrder: (options: CreateOrderOptions) => Promise<void>;
|
|
264
|
+
/** The data for the created order, or undefined. */
|
|
73
265
|
data: EndUserApplePayOnrampOrderCreateResponse | undefined;
|
|
266
|
+
/** The current status of the onramp flow. */
|
|
74
267
|
status: ApplePayOnrampStatus;
|
|
268
|
+
/** Any error that occurred, or undefined. */
|
|
75
269
|
error: OnrampError | undefined;
|
|
270
|
+
/** Resets the hook state to idle. */
|
|
76
271
|
reset: () => void;
|
|
77
272
|
}
|
|
78
273
|
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-react-native",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.99",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"expo-apple-authentication": ">=4.0.0",
|
|
7
7
|
"react": ">=18.2.0",
|
|
8
8
|
"react-native": ">=0.70.0",
|
|
9
9
|
"react-native-webview": ">=13.0.0",
|
|
10
|
-
"@coinbase/cdp-
|
|
11
|
-
"@coinbase/cdp-
|
|
12
|
-
"@coinbase/cdp-
|
|
10
|
+
"@coinbase/cdp-api-client": "^0.0.99",
|
|
11
|
+
"@coinbase/cdp-core": "^0.0.99",
|
|
12
|
+
"@coinbase/cdp-hooks": "^0.0.99"
|
|
13
13
|
},
|
|
14
14
|
"peerDependenciesMeta": {
|
|
15
15
|
"expo-apple-authentication": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"react-dom": "^19.1.2",
|
|
24
24
|
"react-native": "^0.79.6",
|
|
25
25
|
"react-native-webview": "^13.13.5",
|
|
26
|
-
"@coinbase/cdp-
|
|
27
|
-
"@coinbase/cdp-
|
|
28
|
-
"@coinbase/cdp-
|
|
26
|
+
"@coinbase/cdp-api-client": "0.0.99",
|
|
27
|
+
"@coinbase/cdp-core": "0.0.99",
|
|
28
|
+
"@coinbase/cdp-hooks": "0.0.99"
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
31
|
"dist/**",
|