@phantom/react-sdk 0.0.10 → 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,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
- };