@phantom/react-sdk 1.0.0-beta.15 → 1.0.0-beta.16

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
@@ -318,6 +318,33 @@ function ExtensionStatus() {
318
318
  }
319
319
  ```
320
320
 
321
+ #### useIsPhantomLoginAvailable
322
+
323
+ Check if Phantom Login is available (requires extension installed and `phantom_login` feature support):
324
+
325
+ ```tsx
326
+ import { useIsPhantomLoginAvailable } from "@phantom/react-sdk";
327
+
328
+ function PhantomLoginButton() {
329
+ const { isLoading, isAvailable } = useIsPhantomLoginAvailable();
330
+ const { connect } = useConnect();
331
+
332
+ if (isLoading) {
333
+ return <div>Checking Phantom Login availability...</div>;
334
+ }
335
+
336
+ if (!isAvailable) {
337
+ return null; // Don't show button if Phantom Login is not available
338
+ }
339
+
340
+ return (
341
+ <button onClick={() => connect({ provider: "phantom" })}>
342
+ Login with Phantom
343
+ </button>
344
+ );
345
+ }
346
+ ```
347
+
321
348
  ### Chain-Specific Hooks
322
349
 
323
350
  #### useSolana
@@ -746,16 +773,17 @@ function EthereumExample() {
746
773
 
747
774
  Quick reference of all available hooks:
748
775
 
749
- | Hook | Purpose | Returns |
750
- | ------------------------- | --------------------------------------- | --------------------------------------------------- |
751
- | `useConnect` | Connect to wallet | `{ connect, isConnecting, error }` |
752
- | `useAccounts` | Get wallet addresses | `WalletAddress[]` or `null` |
753
- | `useIsExtensionInstalled` | Check extension status | `{ isLoading, isInstalled }` |
754
- | `useDisconnect` | Disconnect from wallet | `{ disconnect, isDisconnecting }` |
755
- | `useAutoConfirm` | Auto-confirm management (injected only) | `{ enable, disable, status, supportedChains, ... }` |
756
- | `useSolana` | Solana chain operations | `{ signMessage, signAndSendTransaction, ... }` |
757
- | `useEthereum` | Ethereum chain operations | `{ signPersonalMessage, sendTransaction, ... }` |
758
- | `usePhantom` | Get provider context | `{ isConnected, isReady }` |
776
+ | Hook | Purpose | Returns |
777
+ | ----------------------------- | --------------------------------------- | --------------------------------------------------- |
778
+ | `useConnect` | Connect to wallet | `{ connect, isConnecting, error }` |
779
+ | `useAccounts` | Get wallet addresses | `WalletAddress[]` or `null` |
780
+ | `useIsExtensionInstalled` | Check extension status | `{ isLoading, isInstalled }` |
781
+ | `useIsPhantomLoginAvailable` | Check Phantom Login availability | `{ isLoading, isAvailable }` |
782
+ | `useDisconnect` | Disconnect from wallet | `{ disconnect, isDisconnecting }` |
783
+ | `useAutoConfirm` | Auto-confirm management (injected only) | `{ enable, disable, status, supportedChains, ... }` |
784
+ | `useSolana` | Solana chain operations | `{ signMessage, signAndSendTransaction, ... }` |
785
+ | `useEthereum` | Ethereum chain operations | `{ signPersonalMessage, sendTransaction, ... }` |
786
+ | `usePhantom` | Get provider context | `{ isConnected, isReady }` |
759
787
 
760
788
  ## Configuration Reference
761
789
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult } from '@phantom/browser-sdk';
4
- export { AddressType, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, DebugLevel, DebugMessage, NetworkId, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
3
+ import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress, ConnectResult, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult } from '@phantom/browser-sdk';
4
+ export { AddressType, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, ConnectErrorEventData, ConnectEventData, ConnectStartEventData, DebugLevel, DebugMessage, DisconnectEventData, EmbeddedProviderEvent, EmbeddedProviderEventMap, EventCallback, NetworkId, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
5
5
  import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
6
6
  import { ISolanaChain, IEthereumChain } from '@phantom/chain-interfaces';
7
7
  export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
@@ -23,6 +23,7 @@ interface PhantomContextValue {
23
23
  currentProviderType: "injected" | "embedded" | null;
24
24
  isPhantomAvailable: boolean;
25
25
  isClient: boolean;
26
+ user: ConnectResult | null;
26
27
  }
27
28
  interface PhantomProviderProps {
28
29
  children: ReactNode;
@@ -57,6 +58,15 @@ declare function useIsExtensionInstalled(): {
57
58
  isInstalled: boolean;
58
59
  };
59
60
 
61
+ /**
62
+ * React hook to check if Phantom Login is available
63
+ * Checks if extension is installed and supports phantom_login feature
64
+ */
65
+ declare function useIsPhantomLoginAvailable(): {
66
+ isLoading: boolean;
67
+ isAvailable: boolean;
68
+ };
69
+
60
70
  interface UseAutoConfirmResult {
61
71
  enable: (params: AutoConfirmEnableParams) => Promise<AutoConfirmResult>;
62
72
  disable: () => Promise<void>;
@@ -90,4 +100,4 @@ declare function useEthereum(): {
90
100
 
91
101
  type ProviderType = "injected" | "embedded";
92
102
 
93
- export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomProviderProps, PhantomSDKConfig, ProviderType, useAccounts, useAutoConfirm, useConnect, useDisconnect, useEthereum, useIsExtensionInstalled, usePhantom, useSolana };
103
+ export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomProviderProps, PhantomSDKConfig, ProviderType, useAccounts, useAutoConfirm, useConnect, useDisconnect, useEthereum, useIsExtensionInstalled, useIsPhantomLoginAvailable, usePhantom, useSolana };
package/dist/index.js CHANGED
@@ -30,17 +30,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- AddressType: () => import_browser_sdk3.AddressType,
34
- DebugLevel: () => import_browser_sdk3.DebugLevel,
35
- NetworkId: () => import_browser_sdk3.NetworkId,
33
+ AddressType: () => import_browser_sdk4.AddressType,
34
+ DebugLevel: () => import_browser_sdk4.DebugLevel,
35
+ NetworkId: () => import_browser_sdk4.NetworkId,
36
36
  PhantomProvider: () => PhantomProvider,
37
- debug: () => import_browser_sdk3.debug,
37
+ debug: () => import_browser_sdk4.debug,
38
38
  useAccounts: () => useAccounts,
39
39
  useAutoConfirm: () => useAutoConfirm,
40
40
  useConnect: () => useConnect,
41
41
  useDisconnect: () => useDisconnect,
42
42
  useEthereum: () => useEthereum,
43
43
  useIsExtensionInstalled: () => useIsExtensionInstalled,
44
+ useIsPhantomLoginAvailable: () => useIsPhantomLoginAvailable,
44
45
  usePhantom: () => usePhantom,
45
46
  useSolana: () => useSolana
46
47
  });
@@ -63,6 +64,7 @@ function PhantomProvider({ children, config, debugConfig }) {
63
64
  memoizedConfig.providerType || null
64
65
  );
65
66
  const [isPhantomAvailable, setIsPhantomAvailable] = (0, import_react.useState)(false);
67
+ const [user, setUser] = (0, import_react.useState)(null);
66
68
  (0, import_react.useEffect)(() => {
67
69
  setIsClient(true);
68
70
  }, []);
@@ -79,12 +81,12 @@ function PhantomProvider({ children, config, debugConfig }) {
79
81
  setIsConnecting(true);
80
82
  setConnectError(null);
81
83
  };
82
- const handleConnect = async () => {
84
+ const handleConnect = async (data) => {
83
85
  try {
84
86
  setIsConnected(true);
85
87
  setIsConnecting(false);
86
- const providerInfo = sdk.getCurrentProviderInfo();
87
- setCurrentProviderType(providerInfo?.type || null);
88
+ setUser(data);
89
+ setCurrentProviderType(data.providerType || null);
88
90
  const addrs = await sdk.getAddresses();
89
91
  setAddresses(addrs);
90
92
  } catch (err) {
@@ -100,12 +102,14 @@ function PhantomProvider({ children, config, debugConfig }) {
100
102
  setIsConnecting(false);
101
103
  setIsConnected(false);
102
104
  setConnectError(new Error(errorData.error || "Connection failed"));
105
+ setAddresses([]);
103
106
  };
104
107
  const handleDisconnect = () => {
105
108
  setIsConnected(false);
106
109
  setIsConnecting(false);
107
110
  setConnectError(null);
108
111
  setAddresses([]);
112
+ setUser(null);
109
113
  };
110
114
  sdk.on("connect_start", handleConnectStart);
111
115
  sdk.on("connect", handleConnect);
@@ -150,9 +154,10 @@ function PhantomProvider({ children, config, debugConfig }) {
150
154
  addresses,
151
155
  currentProviderType,
152
156
  isPhantomAvailable,
153
- isClient
157
+ isClient,
158
+ user
154
159
  }),
155
- [sdk, isConnected, isConnecting, connectError, addresses, currentProviderType, isPhantomAvailable, isClient]
160
+ [sdk, isConnected, isConnecting, connectError, addresses, currentProviderType, isPhantomAvailable, isClient, user]
156
161
  );
157
162
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
158
163
  }
@@ -259,6 +264,39 @@ function useIsExtensionInstalled() {
259
264
  return { isLoading, isInstalled };
260
265
  }
261
266
 
267
+ // src/hooks/useIsPhantomLoginAvailable.ts
268
+ var React2 = __toESM(require("react"));
269
+ var import_browser_sdk3 = require("@phantom/browser-sdk");
270
+ function useIsPhantomLoginAvailable() {
271
+ const [isLoading, setIsLoading] = React2.useState(true);
272
+ const [isAvailable, setIsAvailable] = React2.useState(false);
273
+ React2.useEffect(() => {
274
+ let isMounted = true;
275
+ const checkPhantomLogin = async () => {
276
+ try {
277
+ setIsLoading(true);
278
+ const result = await (0, import_browser_sdk3.isPhantomLoginAvailable)(3e3);
279
+ if (isMounted) {
280
+ setIsAvailable(result);
281
+ }
282
+ } catch (error) {
283
+ if (isMounted) {
284
+ setIsAvailable(false);
285
+ }
286
+ } finally {
287
+ if (isMounted) {
288
+ setIsLoading(false);
289
+ }
290
+ }
291
+ };
292
+ checkPhantomLogin();
293
+ return () => {
294
+ isMounted = false;
295
+ };
296
+ }, []);
297
+ return { isLoading, isAvailable };
298
+ }
299
+
262
300
  // src/hooks/useAutoConfirm.ts
263
301
  var import_react4 = require("react");
264
302
  function useAutoConfirm() {
@@ -390,4 +428,4 @@ function useEthereum() {
390
428
  }
391
429
 
392
430
  // src/index.ts
393
- var import_browser_sdk3 = require("@phantom/browser-sdk");
431
+ var import_browser_sdk4 = require("@phantom/browser-sdk");
package/dist/index.mjs CHANGED
@@ -15,6 +15,7 @@ function PhantomProvider({ children, config, debugConfig }) {
15
15
  memoizedConfig.providerType || null
16
16
  );
17
17
  const [isPhantomAvailable, setIsPhantomAvailable] = useState(false);
18
+ const [user, setUser] = useState(null);
18
19
  useEffect(() => {
19
20
  setIsClient(true);
20
21
  }, []);
@@ -31,12 +32,12 @@ function PhantomProvider({ children, config, debugConfig }) {
31
32
  setIsConnecting(true);
32
33
  setConnectError(null);
33
34
  };
34
- const handleConnect = async () => {
35
+ const handleConnect = async (data) => {
35
36
  try {
36
37
  setIsConnected(true);
37
38
  setIsConnecting(false);
38
- const providerInfo = sdk.getCurrentProviderInfo();
39
- setCurrentProviderType(providerInfo?.type || null);
39
+ setUser(data);
40
+ setCurrentProviderType(data.providerType || null);
40
41
  const addrs = await sdk.getAddresses();
41
42
  setAddresses(addrs);
42
43
  } catch (err) {
@@ -52,12 +53,14 @@ function PhantomProvider({ children, config, debugConfig }) {
52
53
  setIsConnecting(false);
53
54
  setIsConnected(false);
54
55
  setConnectError(new Error(errorData.error || "Connection failed"));
56
+ setAddresses([]);
55
57
  };
56
58
  const handleDisconnect = () => {
57
59
  setIsConnected(false);
58
60
  setIsConnecting(false);
59
61
  setConnectError(null);
60
62
  setAddresses([]);
63
+ setUser(null);
61
64
  };
62
65
  sdk.on("connect_start", handleConnectStart);
63
66
  sdk.on("connect", handleConnect);
@@ -102,9 +105,10 @@ function PhantomProvider({ children, config, debugConfig }) {
102
105
  addresses,
103
106
  currentProviderType,
104
107
  isPhantomAvailable,
105
- isClient
108
+ isClient,
109
+ user
106
110
  }),
107
- [sdk, isConnected, isConnecting, connectError, addresses, currentProviderType, isPhantomAvailable, isClient]
111
+ [sdk, isConnected, isConnecting, connectError, addresses, currentProviderType, isPhantomAvailable, isClient, user]
108
112
  );
109
113
  return /* @__PURE__ */ jsx(PhantomContext.Provider, { value, children });
110
114
  }
@@ -211,14 +215,47 @@ function useIsExtensionInstalled() {
211
215
  return { isLoading, isInstalled };
212
216
  }
213
217
 
218
+ // src/hooks/useIsPhantomLoginAvailable.ts
219
+ import * as React2 from "react";
220
+ import { isPhantomLoginAvailable } from "@phantom/browser-sdk";
221
+ function useIsPhantomLoginAvailable() {
222
+ const [isLoading, setIsLoading] = React2.useState(true);
223
+ const [isAvailable, setIsAvailable] = React2.useState(false);
224
+ React2.useEffect(() => {
225
+ let isMounted = true;
226
+ const checkPhantomLogin = async () => {
227
+ try {
228
+ setIsLoading(true);
229
+ const result = await isPhantomLoginAvailable(3e3);
230
+ if (isMounted) {
231
+ setIsAvailable(result);
232
+ }
233
+ } catch (error) {
234
+ if (isMounted) {
235
+ setIsAvailable(false);
236
+ }
237
+ } finally {
238
+ if (isMounted) {
239
+ setIsLoading(false);
240
+ }
241
+ }
242
+ };
243
+ checkPhantomLogin();
244
+ return () => {
245
+ isMounted = false;
246
+ };
247
+ }, []);
248
+ return { isLoading, isAvailable };
249
+ }
250
+
214
251
  // src/hooks/useAutoConfirm.ts
215
- import { useCallback as useCallback3, useState as useState4, useEffect as useEffect3 } from "react";
252
+ import { useCallback as useCallback3, useState as useState5, useEffect as useEffect4 } from "react";
216
253
  function useAutoConfirm() {
217
254
  const { sdk, currentProviderType } = usePhantom();
218
- const [status, setStatus] = useState4(null);
219
- const [supportedChains, setSupportedChains] = useState4(null);
220
- const [isLoading, setIsLoading] = useState4(false);
221
- const [error, setError] = useState4(null);
255
+ const [status, setStatus] = useState5(null);
256
+ const [supportedChains, setSupportedChains] = useState5(null);
257
+ const [isLoading, setIsLoading] = useState5(false);
258
+ const [error, setError] = useState5(null);
222
259
  const isInjected = currentProviderType === "injected";
223
260
  const enable = useCallback3(
224
261
  async (params) => {
@@ -285,7 +322,7 @@ function useAutoConfirm() {
285
322
  setIsLoading(false);
286
323
  }
287
324
  }, [sdk, isInjected]);
288
- useEffect3(() => {
325
+ useEffect4(() => {
289
326
  if (sdk && isInjected) {
290
327
  refetch();
291
328
  } else {
@@ -355,6 +392,7 @@ export {
355
392
  useDisconnect,
356
393
  useEthereum,
357
394
  useIsExtensionInstalled,
395
+ useIsPhantomLoginAvailable,
358
396
  usePhantom,
359
397
  useSolana
360
398
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/react-sdk",
3
- "version": "1.0.0-beta.15",
3
+ "version": "1.0.0-beta.16",
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.15",
29
+ "@phantom/browser-sdk": "^1.0.0-beta.16",
30
30
  "@phantom/chain-interfaces": "^1.0.0-beta.7",
31
31
  "@phantom/constants": "^1.0.0-beta.7"
32
32
  },