@phantom/react-sdk 0.0.9 → 0.1.0

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.
@@ -1,137 +0,0 @@
1
- import {
2
- usePhantom
3
- } from "../chunk-5KSEZ3MC.mjs";
4
-
5
- // src/auto-confirm/index.ts
6
- import "@phantom/browser-sdk/auto-confirm";
7
-
8
- // src/auto-confirm/useAutoConfirmState.ts
9
- import * as React from "react";
10
-
11
- // src/auto-confirm/assertions.ts
12
- function assertAutoConfirmConfigured(phantom) {
13
- if (!phantom?.autoConfirm) {
14
- throw new Error(
15
- "Phantom auto-confirm plugin not found. Please ensure the auto-confirm plugin is installed and configured properly."
16
- );
17
- }
18
- }
19
-
20
- // src/auto-confirm/useAutoConfirmState.ts
21
- function useAutoConfirmState() {
22
- const { phantom, isReady } = usePhantom();
23
- const isMountedRef = React.useRef(true);
24
- const isInitializedRef = React.useRef(false);
25
- const [status, setStatus] = React.useState(null);
26
- const [supportedChains, setSupportedChains] = React.useState(null);
27
- const [isLoading, setIsLoading] = React.useState(true);
28
- const [error, setError] = React.useState(null);
29
- React.useEffect(() => {
30
- return () => {
31
- isMountedRef.current = false;
32
- };
33
- }, []);
34
- const updateState = React.useCallback(async () => {
35
- if (!isReady || !isMountedRef.current)
36
- return;
37
- try {
38
- assertAutoConfirmConfigured(phantom);
39
- if (!isMountedRef.current)
40
- return;
41
- setError(null);
42
- if (status === null && isMountedRef.current) {
43
- setIsLoading(true);
44
- }
45
- const [statusResult, supportedChainsResult] = await Promise.all([
46
- phantom.autoConfirm.autoConfirmStatus(),
47
- phantom.autoConfirm.autoConfirmSupportedChains()
48
- ]);
49
- if (!isMountedRef.current)
50
- return;
51
- setStatus(statusResult);
52
- setSupportedChains(supportedChainsResult.chains);
53
- } catch (err) {
54
- if (!isMountedRef.current)
55
- return;
56
- setError(err instanceof Error ? err : new Error("Failed to fetch auto-confirm state"));
57
- setStatus(null);
58
- setSupportedChains(null);
59
- } finally {
60
- if (isMountedRef.current) {
61
- setIsLoading(false);
62
- }
63
- }
64
- }, [phantom, isReady, status]);
65
- React.useEffect(() => {
66
- if (!isInitializedRef.current && isReady) {
67
- isInitializedRef.current = true;
68
- updateState();
69
- }
70
- const handleStateChange = () => {
71
- updateState();
72
- };
73
- window.addEventListener("phantomAutoConfirmStateChanged", handleStateChange);
74
- return () => {
75
- window.removeEventListener("phantomAutoConfirmStateChanged", handleStateChange);
76
- };
77
- }, [updateState, isReady]);
78
- return {
79
- status,
80
- supportedChains,
81
- isLoading,
82
- error
83
- };
84
- }
85
-
86
- // src/auto-confirm/useAutoConfirmActions.ts
87
- import * as React2 from "react";
88
- function useAutoConfirmActions() {
89
- const { phantom, isReady } = usePhantom();
90
- const enable = React2.useCallback(
91
- async (params) => {
92
- if (!isReady) {
93
- throw new Error("Phantom is not ready");
94
- }
95
- assertAutoConfirmConfigured(phantom);
96
- const result = await phantom.autoConfirm.autoConfirmEnable(params);
97
- window.dispatchEvent(new CustomEvent("phantomAutoConfirmStateChanged"));
98
- return result;
99
- },
100
- [phantom, isReady]
101
- );
102
- const disable = React2.useCallback(async () => {
103
- if (!isReady) {
104
- throw new Error("Phantom is not ready");
105
- }
106
- assertAutoConfirmConfigured(phantom);
107
- const result = await phantom.autoConfirm.autoConfirmDisable();
108
- window.dispatchEvent(new CustomEvent("phantomAutoConfirmStateChanged"));
109
- return result;
110
- }, [phantom, isReady]);
111
- const getSupportedChains = React2.useCallback(async () => {
112
- if (!isReady) {
113
- throw new Error("Phantom is not ready");
114
- }
115
- assertAutoConfirmConfigured(phantom);
116
- const result = await phantom.autoConfirm.autoConfirmSupportedChains();
117
- return result;
118
- }, [phantom, isReady]);
119
- const getStatus = React2.useCallback(async () => {
120
- if (!isReady) {
121
- throw new Error("Phantom is not ready");
122
- }
123
- assertAutoConfirmConfigured(phantom);
124
- const result = await phantom.autoConfirm.autoConfirmStatus();
125
- return result;
126
- }, [phantom, isReady]);
127
- return {
128
- enable,
129
- disable,
130
- getSupportedChains,
131
- getStatus
132
- };
133
- }
134
- export {
135
- useAutoConfirmActions,
136
- useAutoConfirmState
137
- };
@@ -1,25 +0,0 @@
1
- // src/PhantomContext.tsx
2
- import { createPhantom } from "@phantom/browser-sdk";
3
- import * as React from "react";
4
- import { jsx } from "react/jsx-runtime";
5
- var PhantomContext = React.createContext({ phantom: void 0, isReady: false });
6
- var PhantomProvider = ({ children, config }) => {
7
- const [context, setContext] = React.useState({ phantom: void 0, isReady: false });
8
- React.useEffect(() => {
9
- const phantom = createPhantom(config);
10
- setContext({ phantom, isReady: true });
11
- }, [config]);
12
- return /* @__PURE__ */ jsx(PhantomContext.Provider, { value: context, children });
13
- };
14
- function usePhantom() {
15
- const context = React.useContext(PhantomContext);
16
- if (!context) {
17
- throw new Error("usePhantom must be used within a PhantomProvider");
18
- }
19
- return context;
20
- }
21
-
22
- export {
23
- PhantomProvider,
24
- usePhantom
25
- };
@@ -1,64 +0,0 @@
1
- import { SolanaSignInData } from '@phantom/browser-sdk/solana';
2
- import { Transaction } from '@solana/kit';
3
- import { VersionedTransaction } from '@solana/web3.js';
4
-
5
- type UseConnectProps = {
6
- autoConnect?: boolean;
7
- };
8
- declare function useConnect({ autoConnect }?: UseConnectProps): {
9
- connect: () => Promise<string | undefined>;
10
- };
11
-
12
- declare function useDisconnect(): {
13
- disconnect: () => Promise<void>;
14
- };
15
-
16
- interface UseSignInResult {
17
- signIn: (signInData: SolanaSignInData) => Promise<{
18
- address: string;
19
- signature: Uint8Array;
20
- signedMessage: Uint8Array;
21
- }>;
22
- }
23
- declare function useSignIn(): UseSignInResult;
24
-
25
- interface UseSignAndSendTransactionResult {
26
- signAndSendTransaction: (transaction: Transaction | VersionedTransaction) => Promise<{
27
- signature: string;
28
- publicKey?: string;
29
- }>;
30
- }
31
- declare function useSignAndSendTransaction(): UseSignAndSendTransactionResult;
32
-
33
- interface UseSignMessageResult {
34
- signMessage: (message: Uint8Array, display?: "utf8" | "hex") => Promise<{
35
- signature: Uint8Array;
36
- address: string;
37
- }>;
38
- }
39
- declare function useSignMessage(): UseSignMessageResult;
40
-
41
- /**
42
- * React hook that provides the current account connection status and public key.
43
- * Automatically updates when the account connects, disconnects, or changes.
44
- *
45
- * @returns Object containing status ('connected' | 'disconnected') and address (string | null)
46
- */
47
- declare function useAccount(): string | undefined;
48
-
49
- type UseAccountEffectParameters = {
50
- onConnect?(data: {
51
- publicKey: string;
52
- }): void;
53
- onDisconnect?(): void;
54
- onAccountChanged?(data: {
55
- publicKey: string;
56
- }): void;
57
- };
58
- /**
59
- * Hook for listening to account lifecycle events.
60
- * Provides callbacks for connect, disconnect, and account change events.
61
- */
62
- declare function useAccountEffect(parameters?: UseAccountEffectParameters): void;
63
-
64
- export { useAccount, useAccountEffect, useConnect, useDisconnect, useSignAndSendTransaction, useSignIn, useSignMessage };
@@ -1,230 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/solana/index.ts
31
- var solana_exports = {};
32
- __export(solana_exports, {
33
- useAccount: () => useAccount,
34
- useAccountEffect: () => useAccountEffect,
35
- useConnect: () => useConnect,
36
- useDisconnect: () => useDisconnect,
37
- useSignAndSendTransaction: () => useSignAndSendTransaction,
38
- useSignIn: () => useSignIn,
39
- useSignMessage: () => useSignMessage
40
- });
41
- module.exports = __toCommonJS(solana_exports);
42
- var import_solana = require("@phantom/browser-sdk/solana");
43
-
44
- // src/solana/useConnect.ts
45
- var React2 = __toESM(require("react"));
46
-
47
- // src/PhantomContext.tsx
48
- var import_browser_sdk = require("@phantom/browser-sdk");
49
- var React = __toESM(require("react"));
50
- var import_jsx_runtime = require("react/jsx-runtime");
51
- var PhantomContext = React.createContext({ phantom: void 0, isReady: false });
52
- function usePhantom() {
53
- const context = React.useContext(PhantomContext);
54
- if (!context) {
55
- throw new Error("usePhantom must be used within a PhantomProvider");
56
- }
57
- return context;
58
- }
59
-
60
- // src/solana/useConnect.ts
61
- function useConnect({ autoConnect = false } = {}) {
62
- const { phantom } = usePhantom();
63
- const connect = React2.useCallback(async () => {
64
- if (!phantom?.solana) {
65
- throw new Error("Phantom solana plugin not found.");
66
- }
67
- return await phantom.solana.connect();
68
- }, [phantom]);
69
- React2.useEffect(() => {
70
- if (autoConnect && phantom?.solana) {
71
- connect();
72
- }
73
- }, [autoConnect, connect, phantom?.solana]);
74
- return { connect };
75
- }
76
-
77
- // src/solana/useDisconnect.ts
78
- var React3 = __toESM(require("react"));
79
- function useDisconnect() {
80
- const { phantom } = usePhantom();
81
- const disconnect = React3.useCallback(async () => {
82
- if (!phantom?.solana) {
83
- throw new Error("Phantom solana disconnect method not found.");
84
- }
85
- return await phantom.solana.disconnect();
86
- }, [phantom]);
87
- return { disconnect };
88
- }
89
-
90
- // src/solana/useSignIn.ts
91
- var import_react = require("react");
92
- function useSignIn() {
93
- const { phantom } = usePhantom();
94
- const signIn = (0, import_react.useCallback)(
95
- async (signInData) => {
96
- if (!phantom?.solana) {
97
- throw new Error("Phantom Solana provider not available.");
98
- }
99
- const result = await phantom.solana.signIn(signInData);
100
- return result;
101
- },
102
- [phantom]
103
- );
104
- return { signIn };
105
- }
106
-
107
- // src/solana/useSignAndSendTransaction.ts
108
- var import_react2 = require("react");
109
- function useSignAndSendTransaction() {
110
- const { phantom } = usePhantom();
111
- const signAndSendTransaction = (0, import_react2.useCallback)(
112
- async (transaction) => {
113
- if (!phantom?.solana) {
114
- throw new Error("Phantom Solana provider not available.");
115
- }
116
- const result = await phantom.solana.signAndSendTransaction(transaction);
117
- return result;
118
- },
119
- [phantom]
120
- );
121
- return { signAndSendTransaction };
122
- }
123
-
124
- // src/solana/useSignMessage.ts
125
- var import_react3 = require("react");
126
- function useSignMessage() {
127
- const { phantom } = usePhantom();
128
- const signMessage = (0, import_react3.useCallback)(
129
- async (message, display) => {
130
- if (!phantom?.solana) {
131
- throw new Error("Phantom Solana provider not available.");
132
- }
133
- const result = await phantom.solana.signMessage(message, display);
134
- return result;
135
- },
136
- [phantom]
137
- );
138
- return { signMessage };
139
- }
140
-
141
- // src/solana/useAccount.ts
142
- var React4 = __toESM(require("react"));
143
-
144
- // src/solana/assertions.ts
145
- function assertSolanaConfigured(phantom) {
146
- if (!phantom?.solana) {
147
- throw new Error(
148
- "Phantom solana chain plugin not found. Please ensure the solana chain plugin is installed and configured properly."
149
- );
150
- }
151
- }
152
-
153
- // src/solana/useAccount.ts
154
- function useAccount() {
155
- const { phantom, isReady } = usePhantom();
156
- const [account, setAccount] = React4.useState(void 0);
157
- React4.useEffect(() => {
158
- if (!isReady)
159
- return;
160
- assertSolanaConfigured(phantom);
161
- const updateAccount = async () => {
162
- setAccount(await phantom.solana.getAccount());
163
- };
164
- updateAccount();
165
- phantom.solana.addEventListener("connect", updateAccount);
166
- phantom.solana.addEventListener("disconnect", updateAccount);
167
- phantom.solana.addEventListener("accountChanged", updateAccount);
168
- return () => {
169
- phantom.solana.removeEventListener("connect", updateAccount);
170
- phantom.solana.removeEventListener("disconnect", updateAccount);
171
- phantom.solana.removeEventListener("accountChanged", updateAccount);
172
- };
173
- }, [phantom, isReady]);
174
- return account;
175
- }
176
-
177
- // src/solana/useAccountEffect.ts
178
- var React5 = __toESM(require("react"));
179
- function useAccountEffect(parameters = {}) {
180
- const { onConnect, onDisconnect, onAccountChanged } = parameters;
181
- const { phantom, isReady } = usePhantom();
182
- React5.useEffect(() => {
183
- if (!isReady)
184
- return;
185
- assertSolanaConfigured(phantom);
186
- const handleConnect = (publicKey) => {
187
- onConnect?.({
188
- publicKey
189
- });
190
- };
191
- const handleDisconnect = () => {
192
- onDisconnect?.();
193
- };
194
- const handleAccountChanged = (publicKey) => {
195
- onAccountChanged?.({
196
- publicKey
197
- });
198
- };
199
- if (onConnect) {
200
- phantom.solana.addEventListener("connect", handleConnect);
201
- }
202
- if (onDisconnect) {
203
- phantom.solana.addEventListener("disconnect", handleDisconnect);
204
- }
205
- if (onAccountChanged) {
206
- phantom.solana.addEventListener("accountChanged", handleAccountChanged);
207
- }
208
- return () => {
209
- if (onConnect) {
210
- phantom.solana.removeEventListener("connect", handleConnect);
211
- }
212
- if (onDisconnect) {
213
- phantom.solana.removeEventListener("disconnect", handleDisconnect);
214
- }
215
- if (onAccountChanged) {
216
- phantom.solana.removeEventListener("accountChanged", handleAccountChanged);
217
- }
218
- };
219
- }, [isReady, phantom, onConnect, onDisconnect, onAccountChanged]);
220
- }
221
- // Annotate the CommonJS export names for ESM import in node:
222
- 0 && (module.exports = {
223
- useAccount,
224
- useAccountEffect,
225
- useConnect,
226
- useDisconnect,
227
- useSignAndSendTransaction,
228
- useSignIn,
229
- useSignMessage
230
- });
@@ -1,178 +0,0 @@
1
- import {
2
- usePhantom
3
- } from "../chunk-5KSEZ3MC.mjs";
4
-
5
- // src/solana/index.ts
6
- import "@phantom/browser-sdk/solana";
7
-
8
- // src/solana/useConnect.ts
9
- import * as React from "react";
10
- function useConnect({ autoConnect = false } = {}) {
11
- const { phantom } = usePhantom();
12
- const connect = React.useCallback(async () => {
13
- if (!phantom?.solana) {
14
- throw new Error("Phantom solana plugin not found.");
15
- }
16
- return await phantom.solana.connect();
17
- }, [phantom]);
18
- React.useEffect(() => {
19
- if (autoConnect && phantom?.solana) {
20
- connect();
21
- }
22
- }, [autoConnect, connect, phantom?.solana]);
23
- return { connect };
24
- }
25
-
26
- // src/solana/useDisconnect.ts
27
- import * as React2 from "react";
28
- function useDisconnect() {
29
- const { phantom } = usePhantom();
30
- const disconnect = React2.useCallback(async () => {
31
- if (!phantom?.solana) {
32
- throw new Error("Phantom solana disconnect method not found.");
33
- }
34
- return await phantom.solana.disconnect();
35
- }, [phantom]);
36
- return { disconnect };
37
- }
38
-
39
- // src/solana/useSignIn.ts
40
- import { useCallback as useCallback3 } from "react";
41
- function useSignIn() {
42
- const { phantom } = usePhantom();
43
- const signIn = useCallback3(
44
- async (signInData) => {
45
- if (!phantom?.solana) {
46
- throw new Error("Phantom Solana provider not available.");
47
- }
48
- const result = await phantom.solana.signIn(signInData);
49
- return result;
50
- },
51
- [phantom]
52
- );
53
- return { signIn };
54
- }
55
-
56
- // src/solana/useSignAndSendTransaction.ts
57
- import { useCallback as useCallback4 } from "react";
58
- function useSignAndSendTransaction() {
59
- const { phantom } = usePhantom();
60
- const signAndSendTransaction = useCallback4(
61
- async (transaction) => {
62
- if (!phantom?.solana) {
63
- throw new Error("Phantom Solana provider not available.");
64
- }
65
- const result = await phantom.solana.signAndSendTransaction(transaction);
66
- return result;
67
- },
68
- [phantom]
69
- );
70
- return { signAndSendTransaction };
71
- }
72
-
73
- // src/solana/useSignMessage.ts
74
- import { useCallback as useCallback5 } from "react";
75
- function useSignMessage() {
76
- const { phantom } = usePhantom();
77
- const signMessage = useCallback5(
78
- async (message, display) => {
79
- if (!phantom?.solana) {
80
- throw new Error("Phantom Solana provider not available.");
81
- }
82
- const result = await phantom.solana.signMessage(message, display);
83
- return result;
84
- },
85
- [phantom]
86
- );
87
- return { signMessage };
88
- }
89
-
90
- // src/solana/useAccount.ts
91
- import * as React3 from "react";
92
-
93
- // src/solana/assertions.ts
94
- function assertSolanaConfigured(phantom) {
95
- if (!phantom?.solana) {
96
- throw new Error(
97
- "Phantom solana chain plugin not found. Please ensure the solana chain plugin is installed and configured properly."
98
- );
99
- }
100
- }
101
-
102
- // src/solana/useAccount.ts
103
- function useAccount() {
104
- const { phantom, isReady } = usePhantom();
105
- const [account, setAccount] = React3.useState(void 0);
106
- React3.useEffect(() => {
107
- if (!isReady)
108
- return;
109
- assertSolanaConfigured(phantom);
110
- const updateAccount = async () => {
111
- setAccount(await phantom.solana.getAccount());
112
- };
113
- updateAccount();
114
- phantom.solana.addEventListener("connect", updateAccount);
115
- phantom.solana.addEventListener("disconnect", updateAccount);
116
- phantom.solana.addEventListener("accountChanged", updateAccount);
117
- return () => {
118
- phantom.solana.removeEventListener("connect", updateAccount);
119
- phantom.solana.removeEventListener("disconnect", updateAccount);
120
- phantom.solana.removeEventListener("accountChanged", updateAccount);
121
- };
122
- }, [phantom, isReady]);
123
- return account;
124
- }
125
-
126
- // src/solana/useAccountEffect.ts
127
- import * as React4 from "react";
128
- function useAccountEffect(parameters = {}) {
129
- const { onConnect, onDisconnect, onAccountChanged } = parameters;
130
- const { phantom, isReady } = usePhantom();
131
- React4.useEffect(() => {
132
- if (!isReady)
133
- return;
134
- assertSolanaConfigured(phantom);
135
- const handleConnect = (publicKey) => {
136
- onConnect?.({
137
- publicKey
138
- });
139
- };
140
- const handleDisconnect = () => {
141
- onDisconnect?.();
142
- };
143
- const handleAccountChanged = (publicKey) => {
144
- onAccountChanged?.({
145
- publicKey
146
- });
147
- };
148
- if (onConnect) {
149
- phantom.solana.addEventListener("connect", handleConnect);
150
- }
151
- if (onDisconnect) {
152
- phantom.solana.addEventListener("disconnect", handleDisconnect);
153
- }
154
- if (onAccountChanged) {
155
- phantom.solana.addEventListener("accountChanged", handleAccountChanged);
156
- }
157
- return () => {
158
- if (onConnect) {
159
- phantom.solana.removeEventListener("connect", handleConnect);
160
- }
161
- if (onDisconnect) {
162
- phantom.solana.removeEventListener("disconnect", handleDisconnect);
163
- }
164
- if (onAccountChanged) {
165
- phantom.solana.removeEventListener("accountChanged", handleAccountChanged);
166
- }
167
- };
168
- }, [isReady, phantom, onConnect, onDisconnect, onAccountChanged]);
169
- }
170
- export {
171
- useAccount,
172
- useAccountEffect,
173
- useConnect,
174
- useDisconnect,
175
- useSignAndSendTransaction,
176
- useSignIn,
177
- useSignMessage
178
- };