@phantom/react-sdk 0.3.5 → 0.3.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
@@ -641,7 +641,7 @@ interface PhantomSDKConfig {
641
641
  providerType: "injected" | "embedded";
642
642
  appName?: string; // Optional app name for branding
643
643
  appLogo?: string; // Optional app logo URL for branding
644
- addressTypes?: AddressType[]; // Networks to enable (e.g., [AddressType.solana])
644
+ addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
645
645
 
646
646
  // Required for embedded provider only
647
647
  apiBaseUrl?: string; // Phantom API base URL
@@ -653,13 +653,69 @@ interface PhantomSDKConfig {
653
653
  embeddedWalletType?: "app-wallet" | "user-wallet"; // Wallet type
654
654
  solanaProvider?: "web3js" | "kit"; // Solana library choice (default: 'web3js')
655
655
  autoConnect?: boolean; // Auto-connect to existing session on SDK instantiation (default: true for embedded, false for injected)
656
+ }
657
+ ```
658
+
659
+ ## Debug Configuration
660
+
661
+ The React SDK supports separate debug configuration that can be changed without reinstantiating the underlying SDK, providing better performance.
662
+
663
+ ### PhantomDebugConfig Interface
664
+
665
+ ```typescript
666
+ interface PhantomDebugConfig {
667
+ enabled?: boolean; // Enable debug logging
668
+ level?: DebugLevel; // Debug level (ERROR, WARN, INFO, DEBUG)
669
+ callback?: DebugCallback; // Custom debug message handler
670
+ }
671
+ ```
672
+
673
+ ### Using Debug Configuration
674
+
675
+ Pass the `debugConfig` as a separate prop to `PhantomProvider`:
676
+
677
+ ```typescript
678
+ import { PhantomProvider, type PhantomSDKConfig, type PhantomDebugConfig, DebugLevel } from "@phantom/react-sdk";
679
+
680
+ function App() {
681
+ const [debugLevel, setDebugLevel] = useState(DebugLevel.INFO);
682
+ const [debugMessages, setDebugMessages] = useState([]);
656
683
 
657
- // Debug options
658
- debug?: {
659
- enabled?: boolean; // Enable debug logging
660
- level?: "info" | "warn" | "error"; // Debug level
661
- callback?: (level: string, message: string, data?: any) => void; // Custom debug callback
684
+ // SDK configuration - static, won't change when debug settings change
685
+ const config: PhantomSDKConfig = {
686
+ providerType: "embedded",
687
+ organizationId: "your-org-id",
688
+ // ... other config
689
+ };
690
+
691
+ // Debug configuration - separate to avoid SDK reinstantiation
692
+ const debugConfig: PhantomDebugConfig = {
693
+ enabled: true,
694
+ level: debugLevel,
695
+ callback: (message) => {
696
+ setDebugMessages(prev => [...prev, message]);
697
+ }
662
698
  };
699
+
700
+ return (
701
+ <PhantomProvider config={config} debugConfig={debugConfig}>
702
+ {/* Your app components */}
703
+ </PhantomProvider>
704
+ );
705
+ }
706
+ ```
707
+
708
+ ### Debug Message Structure
709
+
710
+ Debug callbacks receive a `DebugMessage` object:
711
+
712
+ ```typescript
713
+ interface DebugMessage {
714
+ timestamp: number; // Unix timestamp
715
+ level: DebugLevel; // Message level
716
+ category: string; // Component category
717
+ message: string; // Debug message text
718
+ data?: any; // Additional debug data (optional)
663
719
  }
664
720
  ```
665
721
 
package/dist/index.d.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { BrowserSDKConfig, AuthOptions, BrowserSDK, WalletAddress, SignMessageParams, SignMessageResult, SignAndSendTransactionParams, SignedTransaction } from '@phantom/browser-sdk';
3
+ import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress, SignMessageParams, SignMessageResult, SignAndSendTransactionParams, SignedTransaction } from '@phantom/browser-sdk';
4
4
  export { AddressType, DebugLevel, DebugMessage, NetworkId, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
5
5
  import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
6
6
 
7
7
  interface PhantomSDKConfig extends BrowserSDKConfig {
8
8
  }
9
+ interface PhantomDebugConfig extends DebugConfig {
10
+ }
9
11
  interface ConnectOptions {
10
12
  providerType?: "injected" | "embedded";
11
13
  embeddedWalletType?: "app-wallet" | "user-wallet";
12
14
  authOptions?: AuthOptions;
13
15
  }
14
16
  interface PhantomContextValue {
15
- sdk: BrowserSDK;
17
+ sdk: BrowserSDK | null;
16
18
  isConnected: boolean;
17
19
  isConnecting: boolean;
18
20
  connectError: Error | null;
@@ -24,8 +26,9 @@ interface PhantomContextValue {
24
26
  interface PhantomProviderProps {
25
27
  children: ReactNode;
26
28
  config: PhantomSDKConfig;
29
+ debugConfig?: PhantomDebugConfig;
27
30
  }
28
- declare function PhantomProvider({ children, config }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
31
+ declare function PhantomProvider({ children, config, debugConfig }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
29
32
  declare function usePhantom(): PhantomContextValue;
30
33
 
31
34
  declare function useConnect(): {
@@ -63,4 +66,4 @@ declare function useIsExtensionInstalled(): {
63
66
 
64
67
  type ProviderType = "injected" | "embedded";
65
68
 
66
- export { ConnectOptions, PhantomProvider, PhantomProviderProps, PhantomSDKConfig, ProviderType, useAccounts, useConnect, useDisconnect, useIsExtensionInstalled, usePhantom, useSignAndSendTransaction, useSignMessage };
69
+ export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomProviderProps, PhantomSDKConfig, ProviderType, useAccounts, useConnect, useDisconnect, useIsExtensionInstalled, usePhantom, useSignAndSendTransaction, useSignMessage };
package/dist/index.js CHANGED
@@ -50,7 +50,15 @@ var import_react = require("react");
50
50
  var import_browser_sdk = require("@phantom/browser-sdk");
51
51
  var import_jsx_runtime = require("react/jsx-runtime");
52
52
  var PhantomContext = (0, import_react.createContext)(void 0);
53
- function PhantomProvider({ children, config }) {
53
+ function PhantomProvider({ children, config, debugConfig }) {
54
+ const [isConnected, setIsConnected] = (0, import_react.useState)(false);
55
+ const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
56
+ const [connectError, setConnectError] = (0, import_react.useState)(null);
57
+ const [addresses, setAddresses] = (0, import_react.useState)([]);
58
+ const [walletId, setWalletId] = (0, import_react.useState)(null);
59
+ const [currentProviderType, setCurrentProviderType] = (0, import_react.useState)(null);
60
+ const [isPhantomAvailable, setIsPhantomAvailable] = (0, import_react.useState)(false);
61
+ const [sdk, setSdk] = (0, import_react.useState)(null);
54
62
  const memoizedConfig = (0, import_react.useMemo)(() => {
55
63
  return {
56
64
  ...config,
@@ -58,7 +66,7 @@ function PhantomProvider({ children, config }) {
58
66
  providerType: config.providerType || "embedded"
59
67
  };
60
68
  }, [config]);
61
- const sdk = (0, import_react.useMemo)(() => {
69
+ (0, import_react.useEffect)(() => {
62
70
  const sdkInstance = new import_browser_sdk.BrowserSDK(memoizedConfig);
63
71
  const handleConnectStart = () => {
64
72
  setIsConnecting(true);
@@ -98,16 +106,22 @@ function PhantomProvider({ children, config }) {
98
106
  sdkInstance.on("connect", handleConnect);
99
107
  sdkInstance.on("connect_error", handleConnectError);
100
108
  sdkInstance.on("disconnect", handleDisconnect);
101
- return sdkInstance;
109
+ setSdk(sdkInstance);
110
+ return () => {
111
+ sdkInstance.off("connect_start", handleConnectStart);
112
+ sdkInstance.off("connect", handleConnect);
113
+ sdkInstance.off("connect_error", handleConnectError);
114
+ sdkInstance.off("disconnect", handleDisconnect);
115
+ };
102
116
  }, [memoizedConfig]);
103
- const [isConnected, setIsConnected] = (0, import_react.useState)(false);
104
- const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
105
- const [connectError, setConnectError] = (0, import_react.useState)(null);
106
- const [addresses, setAddresses] = (0, import_react.useState)([]);
107
- const [walletId, setWalletId] = (0, import_react.useState)(null);
108
- const [currentProviderType, setCurrentProviderType] = (0, import_react.useState)(null);
109
- const [isPhantomAvailable, setIsPhantomAvailable] = (0, import_react.useState)(false);
110
117
  (0, import_react.useEffect)(() => {
118
+ if (!sdk || !debugConfig)
119
+ return;
120
+ sdk.configureDebug(debugConfig);
121
+ }, [sdk, debugConfig]);
122
+ (0, import_react.useEffect)(() => {
123
+ if (!sdk)
124
+ return;
111
125
  const initialize = async () => {
112
126
  try {
113
127
  const available = await sdk.waitForPhantomExtension(1e3);
package/dist/index.mjs CHANGED
@@ -3,7 +3,15 @@ import { createContext, useContext, useState, useEffect, useMemo } from "react";
3
3
  import { BrowserSDK } from "@phantom/browser-sdk";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  var PhantomContext = createContext(void 0);
6
- function PhantomProvider({ children, config }) {
6
+ function PhantomProvider({ children, config, debugConfig }) {
7
+ const [isConnected, setIsConnected] = useState(false);
8
+ const [isConnecting, setIsConnecting] = useState(false);
9
+ const [connectError, setConnectError] = useState(null);
10
+ const [addresses, setAddresses] = useState([]);
11
+ const [walletId, setWalletId] = useState(null);
12
+ const [currentProviderType, setCurrentProviderType] = useState(null);
13
+ const [isPhantomAvailable, setIsPhantomAvailable] = useState(false);
14
+ const [sdk, setSdk] = useState(null);
7
15
  const memoizedConfig = useMemo(() => {
8
16
  return {
9
17
  ...config,
@@ -11,7 +19,7 @@ function PhantomProvider({ children, config }) {
11
19
  providerType: config.providerType || "embedded"
12
20
  };
13
21
  }, [config]);
14
- const sdk = useMemo(() => {
22
+ useEffect(() => {
15
23
  const sdkInstance = new BrowserSDK(memoizedConfig);
16
24
  const handleConnectStart = () => {
17
25
  setIsConnecting(true);
@@ -51,16 +59,22 @@ function PhantomProvider({ children, config }) {
51
59
  sdkInstance.on("connect", handleConnect);
52
60
  sdkInstance.on("connect_error", handleConnectError);
53
61
  sdkInstance.on("disconnect", handleDisconnect);
54
- return sdkInstance;
62
+ setSdk(sdkInstance);
63
+ return () => {
64
+ sdkInstance.off("connect_start", handleConnectStart);
65
+ sdkInstance.off("connect", handleConnect);
66
+ sdkInstance.off("connect_error", handleConnectError);
67
+ sdkInstance.off("disconnect", handleDisconnect);
68
+ };
55
69
  }, [memoizedConfig]);
56
- const [isConnected, setIsConnected] = useState(false);
57
- const [isConnecting, setIsConnecting] = useState(false);
58
- const [connectError, setConnectError] = useState(null);
59
- const [addresses, setAddresses] = useState([]);
60
- const [walletId, setWalletId] = useState(null);
61
- const [currentProviderType, setCurrentProviderType] = useState(null);
62
- const [isPhantomAvailable, setIsPhantomAvailable] = useState(false);
63
70
  useEffect(() => {
71
+ if (!sdk || !debugConfig)
72
+ return;
73
+ sdk.configureDebug(debugConfig);
74
+ }, [sdk, debugConfig]);
75
+ useEffect(() => {
76
+ if (!sdk)
77
+ return;
64
78
  const initialize = async () => {
65
79
  try {
66
80
  const available = await sdk.waitForPhantomExtension(1e3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/react-sdk",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
27
27
  },
28
28
  "dependencies": {
29
- "@phantom/browser-sdk": "^0.3.5"
29
+ "@phantom/browser-sdk": "^0.3.6"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@testing-library/dom": "^10.4.0",