@phantom/react-native-sdk 0.1.5 → 0.1.6

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
@@ -99,7 +99,6 @@ export default function App() {
99
99
  redirectUrl: "mywalletapp://phantom-auth-callback",
100
100
  },
101
101
  appName: "My Wallet App", // Optional branding
102
- debug: false, // Optional debug logging
103
102
  }}
104
103
  >
105
104
  <YourAppContent />
@@ -193,7 +192,7 @@ interface PhantomSDKConfig {
193
192
  organizationId: string; // Your Phantom organization ID
194
193
  scheme: string; // Custom URL scheme for your app
195
194
  embeddedWalletType: "user-wallet" | "app-wallet";
196
- addressTypes: AddressType[]; // e.g., [AddressType.solana]
195
+ addressTypes: [AddressType, ...AddressType[]]; // e.g., [AddressType.solana]
197
196
  apiBaseUrl: string; // e.g., "https://api.phantom.app/v1/wallets"
198
197
  solanaProvider: "web3js" | "kit"; // Solana provider to use
199
198
  authOptions?: {
@@ -203,7 +202,6 @@ interface PhantomSDKConfig {
203
202
  appName?: string; // Optional app name for branding
204
203
  appLogo?: string; // Optional app logo URL for branding
205
204
  autoConnect?: boolean; // Auto-connect to existing session on SDK instantiation (default: true)
206
- debug?: boolean; // Enable debug logging (optional)
207
205
  }
208
206
  ```
209
207
 
@@ -422,19 +420,40 @@ adb shell am start -W -a android.intent.action.VIEW -d "myapp://phantom-auth-cal
422
420
  - Verify URL scheme configuration
423
421
  - Check intent filters (Android) or URL schemes (iOS)
424
422
 
425
- ### Debug Mode
423
+ ### Debug Configuration
426
424
 
427
- Enable debug logging in development:
425
+ The React Native SDK supports separate debug configuration for better performance and dynamic control:
428
426
 
429
427
  ```typescript
430
- <PhantomProvider
431
- config={{
432
- ...config,
433
- debug: true // Enable debug logging
434
- }}
435
- >
436
- <App />
437
- </PhantomProvider>
428
+ import { PhantomProvider, type PhantomSDKConfig, type PhantomDebugConfig } from "@phantom/react-native-sdk";
429
+
430
+ function App() {
431
+ // SDK configuration - static, won't change when debug settings change
432
+ const config: PhantomSDKConfig = {
433
+ organizationId: "your-org-id",
434
+ scheme: "mywalletapp",
435
+ // ... other config
436
+ };
437
+
438
+ // Debug configuration - separate to avoid SDK reinstantiation
439
+ const debugConfig: PhantomDebugConfig = {
440
+ enabled: true, // Enable debug logging
441
+ };
442
+
443
+ return (
444
+ <PhantomProvider config={config} debugConfig={debugConfig}>
445
+ <App />
446
+ </PhantomProvider>
447
+ );
448
+ }
449
+ ```
450
+
451
+ **PhantomDebugConfig Interface:**
452
+
453
+ ```typescript
454
+ interface PhantomDebugConfig {
455
+ enabled?: boolean; // Enable debug logging (default: false)
456
+ }
438
457
  ```
439
458
 
440
459
  ## Support
package/dist/index.d.ts CHANGED
@@ -6,11 +6,13 @@ export { ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignMes
6
6
  export { AddressType } from '@phantom/client';
7
7
  export { NetworkId } from '@phantom/constants';
8
8
 
9
+ interface PhantomDebugConfig {
10
+ /** Enable debug logging */
11
+ enabled?: boolean;
12
+ }
9
13
  interface PhantomSDKConfig extends EmbeddedProviderConfig {
10
14
  /** Custom URL scheme for your app (e.g., "myapp") */
11
15
  scheme: string;
12
- /** Enable debug logging */
13
- debug?: boolean;
14
16
  /** Enable auto-connect to existing sessions (default: true) */
15
17
  autoConnect?: boolean;
16
18
  }
@@ -24,7 +26,7 @@ interface ConnectOptions {
24
26
  }
25
27
 
26
28
  interface PhantomContextValue {
27
- sdk: EmbeddedProvider;
29
+ sdk: EmbeddedProvider | null;
28
30
  isConnected: boolean;
29
31
  isConnecting: boolean;
30
32
  connectError: Error | null;
@@ -35,8 +37,9 @@ interface PhantomContextValue {
35
37
  interface PhantomProviderProps {
36
38
  children: ReactNode;
37
39
  config: PhantomSDKConfig;
40
+ debugConfig?: PhantomDebugConfig;
38
41
  }
39
- declare function PhantomProvider({ children, config }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
42
+ declare function PhantomProvider({ children, config, debugConfig }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
40
43
  /**
41
44
  * Hook to access the Phantom context
42
45
  * Must be used within a PhantomProvider
@@ -73,4 +76,4 @@ declare function useSignAndSendTransaction(): {
73
76
  error: Error | null;
74
77
  };
75
78
 
76
- export { ConnectOptions, PhantomProvider, PhantomSDKConfig, useAccounts, useConnect, useDisconnect, usePhantom, useSignAndSendTransaction, useSignMessage };
79
+ export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomSDKConfig, useAccounts, useConnect, useDisconnect, usePhantom, useSignAndSendTransaction, useSignMessage };
package/dist/index.js CHANGED
@@ -418,23 +418,31 @@ var ReactNativeStamper = class {
418
418
  var import_react_native2 = require("react-native");
419
419
  var import_jsx_runtime = require("react/jsx-runtime");
420
420
  var PhantomContext = (0, import_react.createContext)(void 0);
421
- function PhantomProvider({ children, config }) {
422
- const sdk = (0, import_react.useMemo)(() => {
421
+ function PhantomProvider({ children, config, debugConfig }) {
422
+ const [isConnected, setIsConnected] = (0, import_react.useState)(false);
423
+ const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
424
+ const [connectError, setConnectError] = (0, import_react.useState)(null);
425
+ const [addresses, setAddresses] = (0, import_react.useState)([]);
426
+ const [walletId, setWalletId] = (0, import_react.useState)(null);
427
+ const [sdk, setSdk] = (0, import_react.useState)(null);
428
+ const memoizedConfig = (0, import_react.useMemo)(() => {
423
429
  const redirectUrl = config.authOptions?.redirectUrl || `${config.scheme}://phantom-auth-callback`;
424
- const embeddedConfig = {
430
+ return {
425
431
  ...config,
426
432
  authOptions: {
427
433
  ...config.authOptions || {},
428
434
  redirectUrl
429
435
  }
430
436
  };
437
+ }, [config]);
438
+ (0, import_react.useEffect)(() => {
431
439
  const storage = new ExpoSecureStorage();
432
440
  const authProvider = new ExpoAuthProvider();
433
441
  const urlParamsAccessor = new ExpoURLParamsAccessor();
434
- const logger = new ExpoLogger(config.debug);
442
+ const logger = new ExpoLogger(debugConfig?.enabled || false);
435
443
  const stamper = new ReactNativeStamper({
436
- keyPrefix: `phantom-rn-${config.organizationId}`,
437
- organizationId: config.organizationId
444
+ keyPrefix: `phantom-rn-${memoizedConfig.organizationId}`,
445
+ organizationId: memoizedConfig.organizationId
438
446
  });
439
447
  const platform = {
440
448
  storage,
@@ -443,7 +451,7 @@ function PhantomProvider({ children, config }) {
443
451
  stamper,
444
452
  name: `${import_react_native2.Platform.OS}-${import_react_native2.Platform.Version}`
445
453
  };
446
- const sdkInstance = new import_embedded_provider_core.EmbeddedProvider(embeddedConfig, platform, logger);
454
+ const sdkInstance = new import_embedded_provider_core.EmbeddedProvider(memoizedConfig, platform, logger);
447
455
  const handleConnectStart = () => {
448
456
  setIsConnecting(true);
449
457
  setConnectError(null);
@@ -478,14 +486,17 @@ function PhantomProvider({ children, config }) {
478
486
  sdkInstance.on("connect", handleConnect);
479
487
  sdkInstance.on("connect_error", handleConnectError);
480
488
  sdkInstance.on("disconnect", handleDisconnect);
481
- return sdkInstance;
482
- }, [config]);
483
- const [isConnected, setIsConnected] = (0, import_react.useState)(false);
484
- const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
485
- const [connectError, setConnectError] = (0, import_react.useState)(null);
486
- const [addresses, setAddresses] = (0, import_react.useState)([]);
487
- const [walletId, setWalletId] = (0, import_react.useState)(null);
489
+ setSdk(sdkInstance);
490
+ return () => {
491
+ sdkInstance.off("connect_start", handleConnectStart);
492
+ sdkInstance.off("connect", handleConnect);
493
+ sdkInstance.off("connect_error", handleConnectError);
494
+ sdkInstance.off("disconnect", handleDisconnect);
495
+ };
496
+ }, [memoizedConfig, debugConfig]);
488
497
  (0, import_react.useEffect)(() => {
498
+ if (!sdk)
499
+ return;
489
500
  if (config.autoConnect !== false) {
490
501
  sdk.autoConnect().catch(() => {
491
502
  });
package/dist/index.mjs CHANGED
@@ -374,23 +374,31 @@ var ReactNativeStamper = class {
374
374
  import { Platform } from "react-native";
375
375
  import { jsx } from "react/jsx-runtime";
376
376
  var PhantomContext = createContext(void 0);
377
- function PhantomProvider({ children, config }) {
378
- const sdk = useMemo(() => {
377
+ function PhantomProvider({ children, config, debugConfig }) {
378
+ const [isConnected, setIsConnected] = useState(false);
379
+ const [isConnecting, setIsConnecting] = useState(false);
380
+ const [connectError, setConnectError] = useState(null);
381
+ const [addresses, setAddresses] = useState([]);
382
+ const [walletId, setWalletId] = useState(null);
383
+ const [sdk, setSdk] = useState(null);
384
+ const memoizedConfig = useMemo(() => {
379
385
  const redirectUrl = config.authOptions?.redirectUrl || `${config.scheme}://phantom-auth-callback`;
380
- const embeddedConfig = {
386
+ return {
381
387
  ...config,
382
388
  authOptions: {
383
389
  ...config.authOptions || {},
384
390
  redirectUrl
385
391
  }
386
392
  };
393
+ }, [config]);
394
+ useEffect(() => {
387
395
  const storage = new ExpoSecureStorage();
388
396
  const authProvider = new ExpoAuthProvider();
389
397
  const urlParamsAccessor = new ExpoURLParamsAccessor();
390
- const logger = new ExpoLogger(config.debug);
398
+ const logger = new ExpoLogger(debugConfig?.enabled || false);
391
399
  const stamper = new ReactNativeStamper({
392
- keyPrefix: `phantom-rn-${config.organizationId}`,
393
- organizationId: config.organizationId
400
+ keyPrefix: `phantom-rn-${memoizedConfig.organizationId}`,
401
+ organizationId: memoizedConfig.organizationId
394
402
  });
395
403
  const platform = {
396
404
  storage,
@@ -399,7 +407,7 @@ function PhantomProvider({ children, config }) {
399
407
  stamper,
400
408
  name: `${Platform.OS}-${Platform.Version}`
401
409
  };
402
- const sdkInstance = new EmbeddedProvider(embeddedConfig, platform, logger);
410
+ const sdkInstance = new EmbeddedProvider(memoizedConfig, platform, logger);
403
411
  const handleConnectStart = () => {
404
412
  setIsConnecting(true);
405
413
  setConnectError(null);
@@ -434,14 +442,17 @@ function PhantomProvider({ children, config }) {
434
442
  sdkInstance.on("connect", handleConnect);
435
443
  sdkInstance.on("connect_error", handleConnectError);
436
444
  sdkInstance.on("disconnect", handleDisconnect);
437
- return sdkInstance;
438
- }, [config]);
439
- const [isConnected, setIsConnected] = useState(false);
440
- const [isConnecting, setIsConnecting] = useState(false);
441
- const [connectError, setConnectError] = useState(null);
442
- const [addresses, setAddresses] = useState([]);
443
- const [walletId, setWalletId] = useState(null);
445
+ setSdk(sdkInstance);
446
+ return () => {
447
+ sdkInstance.off("connect_start", handleConnectStart);
448
+ sdkInstance.off("connect", handleConnect);
449
+ sdkInstance.off("connect_error", handleConnectError);
450
+ sdkInstance.off("disconnect", handleDisconnect);
451
+ };
452
+ }, [memoizedConfig, debugConfig]);
444
453
  useEffect(() => {
454
+ if (!sdk)
455
+ return;
445
456
  if (config.autoConnect !== false) {
446
457
  sdk.autoConnect().catch(() => {
447
458
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/react-native-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Phantom Wallet SDK for React Native and Expo applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -50,7 +50,7 @@
50
50
  "@phantom/client": "^0.1.8",
51
51
  "@phantom/constants": "^0.0.3",
52
52
  "@phantom/crypto": "^0.1.2",
53
- "@phantom/embedded-provider-core": "^0.1.6",
53
+ "@phantom/embedded-provider-core": "^0.1.7",
54
54
  "@phantom/sdk-types": "^0.1.4",
55
55
  "@types/bs58": "^5.0.0",
56
56
  "bs58": "^6.0.0",