@phantom/react-native-sdk 1.0.0-beta.22 → 1.0.0-beta.24

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 CHANGED
@@ -30,10 +30,10 @@ yarn add @phantom/react-native-sdk
30
30
 
31
31
  ```bash
32
32
  # For Expo projects
33
- npx expo install expo-secure-store expo-web-browser expo-auth-session expo-router
33
+ npx expo install expo-secure-store expo-web-browser expo-auth-session expo-router react-native-svg
34
34
 
35
35
  # For bare React Native projects (additional setup required)
36
- npm install expo-secure-store expo-web-browser expo-auth-session
36
+ npm install expo-secure-store expo-web-browser expo-auth-session react-native-svg
37
37
 
38
38
  # Required polyfill for cryptographic operations
39
39
  npm install react-native-get-random-values
@@ -83,12 +83,13 @@ Wrap your app with `PhantomProvider`:
83
83
 
84
84
  ```tsx
85
85
  // App.tsx or _layout.tsx (for Expo Router)
86
- import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
86
+ import { PhantomProvider, AddressType, darkTheme } from "@phantom/react-native-sdk";
87
87
 
88
88
  export default function App() {
89
89
  return (
90
90
  <PhantomProvider
91
91
  config={{
92
+ providers: ["google", "apple"],
92
93
  appId: "your-app-id", // Get your app ID from phantom.com/portal
93
94
  scheme: "mywalletapp", // Must match app.json scheme
94
95
  addressTypes: [AddressType.solana],
@@ -96,6 +97,9 @@ export default function App() {
96
97
  redirectUrl: "mywalletapp://phantom-auth-callback",
97
98
  },
98
99
  }}
100
+ theme={darkTheme} // Optional: Customize modal appearance
101
+ appIcon="https://your-app.com/icon.png" // Optional: Your app icon
102
+ appName="Your App Name" // Optional: Your app name
99
103
  >
100
104
  <YourAppContent />
101
105
  </PhantomProvider>
@@ -103,7 +107,53 @@ export default function App() {
103
107
  }
104
108
  ```
105
109
 
106
- ### 3. Use hooks in your components
110
+ ### 3. Use the connection modal (Recommended)
111
+
112
+ The SDK includes a built-in bottom sheet modal that provides a user-friendly interface for connecting to Phantom. The modal supports multiple authentication methods (Google, Apple, X, TikTok) and handles all connection logic automatically.
113
+
114
+ ```tsx
115
+ // WalletScreen.tsx
116
+ import React from "react";
117
+ import { View, Button, Text } from "react-native";
118
+ import { useModal, useAccounts } from "@phantom/react-native-sdk";
119
+
120
+ export function WalletScreen() {
121
+ const modal = useModal();
122
+ const { isConnected, addresses } = useAccounts();
123
+
124
+ if (!isConnected) {
125
+ return (
126
+ <View style={{ padding: 20 }}>
127
+ <Button title="Connect Wallet" onPress={() => modal.open()} />
128
+ </View>
129
+ );
130
+ }
131
+
132
+ return (
133
+ <View style={{ padding: 20 }}>
134
+ <Text style={{ fontSize: 18, marginBottom: 10 }}>Wallet Connected</Text>
135
+ {addresses.map((addr, index) => (
136
+ <Text key={index}>
137
+ {addr.addressType}: {addr.address}
138
+ </Text>
139
+ ))}
140
+ <Button title="Manage Wallet" onPress={() => modal.open()} />
141
+ </View>
142
+ );
143
+ }
144
+ ```
145
+
146
+ **Modal Features:**
147
+
148
+ - **Multiple Auth Providers**: Google, Apple, X (Twitter), TikTok
149
+ - **Bottom Sheet UI**: Native bottom sheet design for mobile
150
+ - **Automatic State Management**: Shows connect screen when disconnected, wallet management when connected
151
+ - **Error Handling**: Clear error messages displayed in the modal
152
+ - **Loading States**: Visual feedback during connection attempts
153
+
154
+ ### 4. Or use hooks directly
155
+
156
+ Alternatively, you can use the hooks directly for more control:
107
157
 
108
158
  ```tsx
109
159
  // WalletScreen.tsx
@@ -197,6 +247,15 @@ The main provider component that initializes the SDK and provides context to all
197
247
  #### Configuration Options
198
248
 
199
249
  ```typescript
250
+ interface PhantomProviderProps {
251
+ config: PhantomSDKConfig;
252
+ debugConfig?: PhantomDebugConfig;
253
+ theme?: PhantomTheme; // Optional: Customize modal appearance
254
+ appIcon?: string; // Optional: Your app icon URL (shown in modal)
255
+ appName?: string; // Optional: Your app name (shown in modal)
256
+ children: ReactNode;
257
+ }
258
+
200
259
  interface PhantomSDKConfig {
201
260
  scheme: string; // Custom URL scheme for your app
202
261
  appId: string; // Your app ID from phantom.com/portal (required)
@@ -214,6 +273,34 @@ interface PhantomSDKConfig {
214
273
 
215
274
  ### Hooks
216
275
 
276
+ #### useModal
277
+
278
+ Control the connection modal visibility. The modal automatically shows the appropriate content based on connection status.
279
+
280
+ ```typescript
281
+ const modal = useModal();
282
+
283
+ // Open the modal
284
+ modal.open(); // Shows connect options when disconnected, wallet management when connected
285
+
286
+ // Close the modal
287
+ modal.close();
288
+
289
+ // Check if modal is open
290
+ const isOpen = modal.isOpened;
291
+ ```
292
+
293
+ **Returns:**
294
+
295
+ - `open()` - Function to open the modal
296
+ - `close()` - Function to close the modal
297
+ - `isOpened` - Boolean indicating if modal is currently visible
298
+
299
+ **Modal Behavior:**
300
+
301
+ - **When disconnected**: Shows authentication provider options (Google, Apple, X, TikTok)
302
+ - **When connected**: Shows connected wallet addresses and disconnect button
303
+
217
304
  #### useConnect
218
305
 
219
306
  Manages wallet connection functionality.
@@ -221,13 +308,11 @@ Manages wallet connection functionality.
221
308
  ```typescript
222
309
  const { connect, isConnecting, error } = useConnect();
223
310
 
224
- // Connect with specific provider
311
+ // Connect with specific provider (React Native supported providers)
225
312
  await connect({ provider: "google" }); // Google OAuth
226
313
  await connect({ provider: "apple" }); // Apple ID
227
- await connect({ provider: "phantom" }); // Phantom Login
228
314
  await connect({ provider: "x" }); // X/Twitter
229
315
  await connect({ provider: "tiktok" }); // TikTok
230
- await connect({ provider: "jwt", jwtToken: "your-jwt-token" }); // Custom JWT
231
316
  ```
232
317
 
233
318
  #### useAccounts
@@ -326,6 +411,50 @@ const { disconnect, isDisconnecting } = useDisconnect();
326
411
  await disconnect();
327
412
  ```
328
413
 
414
+ ## Theming
415
+
416
+ Customize the modal appearance by passing a `theme` prop to the `PhantomProvider`. The SDK includes built-in `darkTheme` (default).
417
+
418
+ ### Using Built-in Theme
419
+
420
+ ```tsx
421
+ import { PhantomProvider, darkTheme } from "@phantom/react-native-sdk";
422
+
423
+ <PhantomProvider config={config} theme={darkTheme} appIcon="https://your-app.com/icon.png" appName="Your App Name">
424
+ <App />
425
+ </PhantomProvider>;
426
+ ```
427
+
428
+ ### Custom Theme
429
+
430
+ You can pass a partial theme object to customize specific properties:
431
+
432
+ ```tsx
433
+ import { PhantomProvider } from "@phantom/react-native-sdk";
434
+
435
+ const customTheme = {
436
+ brand: "#7C3AED", // Primary brand color
437
+ background: "#1A1A1A", // Background color
438
+ primary: "#FFFFFF", // Primary text color
439
+ secondary: "#A0A0A0", // Secondary text color
440
+ error: "#EF4444", // Error color
441
+ borderRadius: 12, // Border radius for elements
442
+ };
443
+
444
+ <PhantomProvider config={config} theme={customTheme}>
445
+ <App />
446
+ </PhantomProvider>;
447
+ ```
448
+
449
+ **Theme Properties:**
450
+
451
+ - `brand` - Primary brand color (buttons, accents)
452
+ - `background` - Background color for modal
453
+ - `primary` - Primary text color
454
+ - `secondary` - Secondary text color (labels, descriptions)
455
+ - `error` - Error text and border color
456
+ - `borderRadius` - Border radius for buttons and containers
457
+
329
458
  ## Authentication Flows
330
459
 
331
460
  ### Available Providers
@@ -334,10 +463,10 @@ The SDK supports multiple authentication providers that you specify when calling
334
463
 
335
464
  - **Google** (`provider: "google"`) - Google OAuth authentication
336
465
  - **Apple** (`provider: "apple"`) - Apple ID authentication
337
- - **Phantom** (`provider: "phantom"`) - Phantom Login authentication
338
466
  - **X** (`provider: "x"`) - X/Twitter authentication
339
467
  - **TikTok** (`provider: "tiktok"`) - TikTok authentication
340
- - **JWT** (`provider: "jwt"`) - Custom JWT authentication (requires `jwtToken` parameter)
468
+
469
+ > **Note**: React Native SDK does not support Phantom Login or injected provider (browser extension) authentication. These are only available in the Browser SDK and React SDK for web applications.
341
470
 
342
471
  **Example Usage:**
343
472
 
@@ -348,11 +477,11 @@ await connect({ provider: "google" });
348
477
  // Apple ID
349
478
  await connect({ provider: "apple" });
350
479
 
351
- // Phantom Login
352
- await connect({ provider: "phantom" });
480
+ // X/Twitter
481
+ await connect({ provider: "x" });
353
482
 
354
- // JWT authentication
355
- await connect({ provider: "jwt", jwtToken: "your-jwt-token" });
483
+ // TikTok
484
+ await connect({ provider: "tiktok" });
356
485
  ```
357
486
 
358
487
  ### Authentication Process
@@ -395,6 +524,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
395
524
  <PhantomProvider
396
525
  config={{
397
526
  appId: "your-app-id",
527
+ providers: ["google", "apple"],
398
528
  scheme: "myapp",
399
529
  addressTypes: [AddressType.solana],
400
530
  }}
@@ -411,6 +541,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
411
541
  <PhantomProvider
412
542
  config={{
413
543
  appId: "your-app-id",
544
+ providers: ["google", "apple"],
414
545
  scheme: "mycompany-wallet",
415
546
  addressTypes: [AddressType.solana, AddressType.ethereum],
416
547
  authOptions: {
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ import { ReactNode } from 'react';
3
3
  import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
4
4
  import { EmbeddedProviderConfig, EmbeddedProviderAuthType, EmbeddedProvider, WalletAddress, ConnectResult } from '@phantom/embedded-provider-core';
5
5
  export { ConnectErrorEventData, ConnectEventData, ConnectResult, ConnectStartEventData, DisconnectEventData, EmbeddedProviderEvent, EmbeddedProviderEventMap, EventCallback, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
6
+ import { PhantomTheme } from '@phantom/wallet-sdk-ui';
7
+ export { PhantomTheme, darkTheme, lightTheme } from '@phantom/wallet-sdk-ui';
6
8
  import { ISolanaChain, IEthereumChain } from '@phantom/chain-interfaces';
7
9
  export { AddressType } from '@phantom/client';
8
10
  export { NetworkId } from '@phantom/constants';
@@ -12,6 +14,7 @@ interface PhantomDebugConfig {
12
14
  enabled?: boolean;
13
15
  }
14
16
  interface PhantomSDKConfig extends Omit<EmbeddedProviderConfig, "apiBaseUrl" | "embeddedWalletType" | "authOptions"> {
17
+ providers: EmbeddedProviderAuthType[];
15
18
  /** Custom URL scheme for your app (e.g., "myapp") */
16
19
  scheme: string;
17
20
  /** Base URL for Phantom API (default: "https://api.phantom.app/v1/wallets") */
@@ -30,6 +33,16 @@ interface ConnectOptions {
30
33
  customAuthData?: Record<string, any>;
31
34
  }
32
35
 
36
+ interface PhantomProviderProps {
37
+ children: ReactNode;
38
+ config: PhantomSDKConfig;
39
+ debugConfig?: PhantomDebugConfig;
40
+ theme?: Partial<PhantomTheme>;
41
+ appIcon?: string;
42
+ appName?: string;
43
+ }
44
+ declare function PhantomProvider({ children, config, debugConfig, theme, appIcon, appName }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
45
+
33
46
  interface PhantomContextValue {
34
47
  sdk: EmbeddedProvider;
35
48
  isConnected: boolean;
@@ -39,15 +52,16 @@ interface PhantomContextValue {
39
52
  walletId: string | null;
40
53
  setWalletId: (walletId: string | null) => void;
41
54
  user: ConnectResult | null;
55
+ allowedProviders: EmbeddedProviderAuthType[];
42
56
  }
43
- interface PhantomProviderProps {
44
- children: ReactNode;
45
- config: PhantomSDKConfig;
46
- debugConfig?: PhantomDebugConfig;
47
- }
48
- declare function PhantomProvider({ children, config, debugConfig }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
49
57
  declare function usePhantom(): PhantomContextValue;
50
58
 
59
+ declare function useModal(): {
60
+ open: () => void;
61
+ close: () => void;
62
+ isOpened: boolean;
63
+ };
64
+
51
65
  declare function useConnect(): {
52
66
  connect: (options: ConnectOptions) => Promise<ConnectResult>;
53
67
  isConnecting: boolean;
@@ -86,4 +100,4 @@ declare function useEthereum(): {
86
100
  isAvailable: boolean;
87
101
  };
88
102
 
89
- export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomSDKConfig, useAccounts, useConnect, useDisconnect, useEthereum, usePhantom, useSolana };
103
+ export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomSDKConfig, useAccounts, useConnect, useDisconnect, useEthereum, useModal, usePhantom, useSolana };