@phantom/react-sdk 1.0.0-beta.6 → 1.0.0-beta.8

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/index.d.ts CHANGED
@@ -3,11 +3,9 @@ import { ReactNode } from 'react';
3
3
  import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult } from '@phantom/browser-sdk';
4
4
  export { AddressType, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, DebugLevel, DebugMessage, NetworkId, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
5
5
  import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
6
- import * as _phantom_chain_interfaces from '@phantom/chain-interfaces';
7
6
  export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
8
7
 
9
- interface PhantomSDKConfig extends BrowserSDKConfig {
10
- }
8
+ type PhantomSDKConfig = BrowserSDKConfig;
11
9
  interface PhantomDebugConfig extends DebugConfig {
12
10
  }
13
11
  interface ConnectOptions {
@@ -16,7 +14,7 @@ interface ConnectOptions {
16
14
  authOptions?: AuthOptions;
17
15
  }
18
16
  interface PhantomContextValue {
19
- sdk: BrowserSDK;
17
+ sdk: BrowserSDK | null;
20
18
  isConnected: boolean;
21
19
  isConnecting: boolean;
22
20
  connectError: Error | null;
@@ -24,6 +22,7 @@ interface PhantomContextValue {
24
22
  walletId: string | null;
25
23
  currentProviderType: "injected" | "embedded" | null;
26
24
  isPhantomAvailable: boolean;
25
+ isClient: boolean;
27
26
  }
28
27
  interface PhantomProviderProps {
29
28
  children: ReactNode;
@@ -75,7 +74,7 @@ declare function useAutoConfirm(): UseAutoConfirmResult;
75
74
  * @returns Solana chain interface with connection enforcement
76
75
  */
77
76
  declare function useSolana(): {
78
- solana: _phantom_chain_interfaces.ISolanaChain;
77
+ solana: any;
79
78
  isAvailable: boolean;
80
79
  };
81
80
 
@@ -85,7 +84,7 @@ declare function useSolana(): {
85
84
  * @returns Ethereum chain interface with connection enforcement
86
85
  */
87
86
  declare function useEthereum(): {
88
- ethereum: _phantom_chain_interfaces.IEthereumChain;
87
+ ethereum: any;
89
88
  isAvailable: boolean;
90
89
  };
91
90
 
package/dist/index.js CHANGED
@@ -52,13 +52,9 @@ var import_browser_sdk = require("@phantom/browser-sdk");
52
52
  var import_jsx_runtime = require("react/jsx-runtime");
53
53
  var PhantomContext = (0, import_react.createContext)(void 0);
54
54
  function PhantomProvider({ children, config, debugConfig }) {
55
- const memoizedConfig = (0, import_react.useMemo)(() => {
56
- return {
57
- ...config,
58
- // Use providerType if provided, default to embedded
59
- providerType: config.providerType || "embedded"
60
- };
61
- }, [config]);
55
+ const memoizedConfig = (0, import_react.useMemo)(() => config, [config]);
56
+ const [sdk, setSdk] = (0, import_react.useState)(null);
57
+ const [isClient, setIsClient] = (0, import_react.useState)(false);
62
58
  const [isConnected, setIsConnected] = (0, import_react.useState)(false);
63
59
  const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
64
60
  const [connectError, setConnectError] = (0, import_react.useState)(null);
@@ -68,8 +64,22 @@ function PhantomProvider({ children, config, debugConfig }) {
68
64
  memoizedConfig.providerType || null
69
65
  );
70
66
  const [isPhantomAvailable, setIsPhantomAvailable] = (0, import_react.useState)(false);
71
- const sdk = (0, import_react.useMemo)(() => new import_browser_sdk.BrowserSDK(memoizedConfig), [memoizedConfig]);
72
67
  (0, import_react.useEffect)(() => {
68
+ setIsClient(true);
69
+ }, []);
70
+ (0, import_react.useEffect)(() => {
71
+ if (!isClient)
72
+ return;
73
+ const sdkInstance = new import_browser_sdk.BrowserSDK(memoizedConfig);
74
+ setSdk(sdkInstance);
75
+ return () => {
76
+ sdkInstance.disconnect().catch(() => {
77
+ });
78
+ };
79
+ }, [isClient, memoizedConfig]);
80
+ (0, import_react.useEffect)(() => {
81
+ if (!sdk)
82
+ return;
73
83
  const handleConnectStart = () => {
74
84
  setIsConnecting(true);
75
85
  setConnectError(null);
@@ -116,12 +126,12 @@ function PhantomProvider({ children, config, debugConfig }) {
116
126
  };
117
127
  }, [sdk]);
118
128
  (0, import_react.useEffect)(() => {
119
- if (!sdk || !debugConfig)
129
+ if (!debugConfig || !sdk)
120
130
  return;
121
131
  sdk.configureDebug(debugConfig);
122
132
  }, [sdk, debugConfig]);
123
133
  (0, import_react.useEffect)(() => {
124
- if (!sdk)
134
+ if (!isClient || !sdk)
125
135
  return;
126
136
  const initialize = async () => {
127
137
  try {
@@ -137,7 +147,7 @@ function PhantomProvider({ children, config, debugConfig }) {
137
147
  }
138
148
  };
139
149
  initialize();
140
- }, [sdk, memoizedConfig.autoConnect]);
150
+ }, [sdk, memoizedConfig.autoConnect, isClient]);
141
151
  const value = (0, import_react.useMemo)(
142
152
  () => ({
143
153
  sdk,
@@ -147,9 +157,10 @@ function PhantomProvider({ children, config, debugConfig }) {
147
157
  addresses,
148
158
  walletId,
149
159
  currentProviderType,
150
- isPhantomAvailable
160
+ isPhantomAvailable,
161
+ isClient
151
162
  }),
152
- [sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable]
163
+ [sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable, isClient]
153
164
  );
154
165
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
155
166
  }
@@ -352,7 +363,14 @@ function useAutoConfirm() {
352
363
 
353
364
  // src/hooks/useSolana.ts
354
365
  function useSolana() {
355
- const { sdk, isConnected } = usePhantom();
366
+ const { sdk, isConnected, isClient } = usePhantom();
367
+ if (!isClient || !sdk) {
368
+ return {
369
+ solana: {},
370
+ // This will be replaced when SDK is ready
371
+ isAvailable: false
372
+ };
373
+ }
356
374
  return {
357
375
  // Chain instance with connection enforcement for signing methods
358
376
  solana: sdk.solana,
@@ -363,7 +381,14 @@ function useSolana() {
363
381
 
364
382
  // src/hooks/useEthereum.ts
365
383
  function useEthereum() {
366
- const { sdk, isConnected } = usePhantom();
384
+ const { sdk, isConnected, isClient } = usePhantom();
385
+ if (!isClient || !sdk) {
386
+ return {
387
+ ethereum: {},
388
+ // This will be replaced when SDK is ready
389
+ isAvailable: false
390
+ };
391
+ }
367
392
  return {
368
393
  // Chain instance with connection enforcement for signing methods
369
394
  ethereum: sdk.ethereum,
package/dist/index.mjs CHANGED
@@ -4,13 +4,9 @@ import { BrowserSDK } from "@phantom/browser-sdk";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  var PhantomContext = createContext(void 0);
6
6
  function PhantomProvider({ children, config, debugConfig }) {
7
- const memoizedConfig = useMemo(() => {
8
- return {
9
- ...config,
10
- // Use providerType if provided, default to embedded
11
- providerType: config.providerType || "embedded"
12
- };
13
- }, [config]);
7
+ const memoizedConfig = useMemo(() => config, [config]);
8
+ const [sdk, setSdk] = useState(null);
9
+ const [isClient, setIsClient] = useState(false);
14
10
  const [isConnected, setIsConnected] = useState(false);
15
11
  const [isConnecting, setIsConnecting] = useState(false);
16
12
  const [connectError, setConnectError] = useState(null);
@@ -20,8 +16,22 @@ function PhantomProvider({ children, config, debugConfig }) {
20
16
  memoizedConfig.providerType || null
21
17
  );
22
18
  const [isPhantomAvailable, setIsPhantomAvailable] = useState(false);
23
- const sdk = useMemo(() => new BrowserSDK(memoizedConfig), [memoizedConfig]);
24
19
  useEffect(() => {
20
+ setIsClient(true);
21
+ }, []);
22
+ useEffect(() => {
23
+ if (!isClient)
24
+ return;
25
+ const sdkInstance = new BrowserSDK(memoizedConfig);
26
+ setSdk(sdkInstance);
27
+ return () => {
28
+ sdkInstance.disconnect().catch(() => {
29
+ });
30
+ };
31
+ }, [isClient, memoizedConfig]);
32
+ useEffect(() => {
33
+ if (!sdk)
34
+ return;
25
35
  const handleConnectStart = () => {
26
36
  setIsConnecting(true);
27
37
  setConnectError(null);
@@ -68,12 +78,12 @@ function PhantomProvider({ children, config, debugConfig }) {
68
78
  };
69
79
  }, [sdk]);
70
80
  useEffect(() => {
71
- if (!sdk || !debugConfig)
81
+ if (!debugConfig || !sdk)
72
82
  return;
73
83
  sdk.configureDebug(debugConfig);
74
84
  }, [sdk, debugConfig]);
75
85
  useEffect(() => {
76
- if (!sdk)
86
+ if (!isClient || !sdk)
77
87
  return;
78
88
  const initialize = async () => {
79
89
  try {
@@ -89,7 +99,7 @@ function PhantomProvider({ children, config, debugConfig }) {
89
99
  }
90
100
  };
91
101
  initialize();
92
- }, [sdk, memoizedConfig.autoConnect]);
102
+ }, [sdk, memoizedConfig.autoConnect, isClient]);
93
103
  const value = useMemo(
94
104
  () => ({
95
105
  sdk,
@@ -99,9 +109,10 @@ function PhantomProvider({ children, config, debugConfig }) {
99
109
  addresses,
100
110
  walletId,
101
111
  currentProviderType,
102
- isPhantomAvailable
112
+ isPhantomAvailable,
113
+ isClient
103
114
  }),
104
- [sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable]
115
+ [sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable, isClient]
105
116
  );
106
117
  return /* @__PURE__ */ jsx(PhantomContext.Provider, { value, children });
107
118
  }
@@ -304,7 +315,14 @@ function useAutoConfirm() {
304
315
 
305
316
  // src/hooks/useSolana.ts
306
317
  function useSolana() {
307
- const { sdk, isConnected } = usePhantom();
318
+ const { sdk, isConnected, isClient } = usePhantom();
319
+ if (!isClient || !sdk) {
320
+ return {
321
+ solana: {},
322
+ // This will be replaced when SDK is ready
323
+ isAvailable: false
324
+ };
325
+ }
308
326
  return {
309
327
  // Chain instance with connection enforcement for signing methods
310
328
  solana: sdk.solana,
@@ -315,7 +333,14 @@ function useSolana() {
315
333
 
316
334
  // src/hooks/useEthereum.ts
317
335
  function useEthereum() {
318
- const { sdk, isConnected } = usePhantom();
336
+ const { sdk, isConnected, isClient } = usePhantom();
337
+ if (!isClient || !sdk) {
338
+ return {
339
+ ethereum: {},
340
+ // This will be replaced when SDK is ready
341
+ isAvailable: false
342
+ };
343
+ }
319
344
  return {
320
345
  // Chain instance with connection enforcement for signing methods
321
346
  ethereum: sdk.ethereum,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/react-sdk",
3
- "version": "1.0.0-beta.6",
3
+ "version": "1.0.0-beta.8",
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": "^1.0.0-beta.6",
29
+ "@phantom/browser-sdk": "^1.0.0-beta.8",
30
30
  "@phantom/chain-interfaces": "^1.0.0-beta.6",
31
31
  "@phantom/constants": "^1.0.0-beta.6"
32
32
  },