@phantom/react-sdk 0.0.5 → 0.0.7
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 +9 -21
- package/dist/solana/index.d.ts +5 -27
- package/dist/solana/index.js +16 -97
- package/dist/solana/index.mjs +22 -102
- package/package.json +11 -5
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ npm install @phantom/react-sdk @phantom/browser-sdk
|
|
|
12
12
|
|
|
13
13
|
```tsx
|
|
14
14
|
import React from "react";
|
|
15
|
-
import { PhantomProvider, useConnect } from "@phantom/react-sdk";
|
|
15
|
+
import { PhantomProvider, useConnect } from "@phantom/react-sdk/solana";
|
|
16
16
|
import { createSolanaPlugin } from "@phantom/browser-sdk/solana";
|
|
17
17
|
|
|
18
18
|
function App() {
|
|
@@ -64,17 +64,6 @@ The `usePhantom` hoo provides access to the phantom instance. With Phantom insta
|
|
|
64
64
|
|
|
65
65
|
## Solana API Reference
|
|
66
66
|
|
|
67
|
-
### useProvider
|
|
68
|
-
|
|
69
|
-
The `useProvider` hook provides access to the Solana provider with automatic retry logic and state management.
|
|
70
|
-
|
|
71
|
-
#### Return Value
|
|
72
|
-
|
|
73
|
-
The hook returns an object with the following properties:
|
|
74
|
-
|
|
75
|
-
- `status: 'loading' | 'success' | 'error'` - Current status of the provider
|
|
76
|
-
- `provider: NonNullable<unknown> | null` - The Solana provider instance (null when not available)
|
|
77
|
-
|
|
78
67
|
### useConnect (Solana)
|
|
79
68
|
|
|
80
69
|
The `useConnect` hook provides a function to connect to the Phantom wallet for Solana.
|
|
@@ -90,7 +79,7 @@ The hook returns an object with the following property:
|
|
|
90
79
|
- `connect: () => Promise<ConnectResponse>` - An asynchronous function that initiates the connection process. Returns a promise that resolves with the connection response (e.g., `{ publicKey: string }`) or rejects if connection fails.
|
|
91
80
|
|
|
92
81
|
```tsx
|
|
93
|
-
import { useConnect } from "@phantom/react-sdk"; // Or '@phantom/react-sdk/solana' if specific
|
|
82
|
+
import { useConnect } from "@phantom/react-sdk/solana"; // Or '@phantom/react-sdk/solana' if specific
|
|
94
83
|
|
|
95
84
|
function MyComponent() {
|
|
96
85
|
const { connect } = useConnect({ autoConnect: true });
|
|
@@ -118,7 +107,7 @@ The hook returns an object with the following property:
|
|
|
118
107
|
- `disconnect: () => Promise<void>` - An asynchronous function that initiates the disconnection process. Returns a promise that resolves when disconnection is complete or rejects if disconnection fails.
|
|
119
108
|
|
|
120
109
|
```tsx
|
|
121
|
-
import { useDisconnect } from "@phantom/react-sdk";
|
|
110
|
+
import { useDisconnect } from "@phantom/react-sdk/solana";
|
|
122
111
|
|
|
123
112
|
function MyComponent() {
|
|
124
113
|
const { disconnect } = useDisconnect();
|
|
@@ -137,14 +126,13 @@ function MyComponent() {
|
|
|
137
126
|
|
|
138
127
|
### useAccount
|
|
139
128
|
|
|
140
|
-
The `useAccount` hook provides access the currently connected
|
|
129
|
+
The `useAccount` hook provides access the currently connected address
|
|
141
130
|
|
|
142
131
|
#### Return Value
|
|
143
132
|
|
|
144
|
-
The hook returns
|
|
133
|
+
The hook returns a string with the currently connected address or undefined when account is not connected.
|
|
145
134
|
|
|
146
|
-
|
|
147
|
-
- `publicKey: string | null` - Current public key of the connected account or null when account is not connected.
|
|
135
|
+
````tsx
|
|
148
136
|
|
|
149
137
|
### useSignIn (Solana)
|
|
150
138
|
|
|
@@ -157,7 +145,7 @@ The hook returns an object with the following property:
|
|
|
157
145
|
- `signIn: (signInData: SolanaSignInData) => Promise<{ address: string; signature: Uint8Array; signedMessage: Uint8Array }>` - An asynchronous function that initiates the sign-in process. `SolanaSignInData` is a type imported from `@phantom/browser-sdk/solana`. Returns a promise that resolves with the `address` (string), `signature` (Uint8Array), and `signedMessage` (Uint8Array), or rejects if the sign-in fails.
|
|
158
146
|
|
|
159
147
|
```tsx
|
|
160
|
-
import { useSignIn } from "@phantom/react-sdk";
|
|
148
|
+
import { useSignIn } from "@phantom/react-sdk/solana";
|
|
161
149
|
import { SolanaSignInData } from "@phantom/browser-sdk/solana"; // This type might be needed from the browser-sdk
|
|
162
150
|
|
|
163
151
|
function MyComponent() {
|
|
@@ -185,7 +173,7 @@ function MyComponent() {
|
|
|
185
173
|
|
|
186
174
|
return <button onClick={handleSignInClick}>Sign In with Solana</button>;
|
|
187
175
|
}
|
|
188
|
-
|
|
176
|
+
````
|
|
189
177
|
|
|
190
178
|
### useSignMessage (Solana)
|
|
191
179
|
|
|
@@ -198,7 +186,7 @@ The hook returns an object with the following property:
|
|
|
198
186
|
- `signMessage: (message: Uint8Array, display?: 'utf8' | 'hex') => Promise<{ signature: Uint8Array; publicKey: string }>` - An asynchronous function that prompts the user to sign a message. The `message` must be a `Uint8Array`. The optional `display` parameter can be 'utf8' (default) or 'hex' to suggest how the wallet should display the message bytes. Returns a promise that resolves with the `signature` (Uint8Array) and `publicKey` (string) of the signer, or rejects if signing fails.
|
|
199
187
|
|
|
200
188
|
```tsx
|
|
201
|
-
import { useSignMessage } from "@phantom/react-sdk";
|
|
189
|
+
import { useSignMessage } from "@phantom/react-sdk/solana";
|
|
202
190
|
|
|
203
191
|
function MyComponent() {
|
|
204
192
|
const { signMessage } = useSignMessage();
|
package/dist/solana/index.d.ts
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SolanaSignInData } from '@phantom/browser-sdk/solana';
|
|
2
2
|
import { Transaction } from '@solana/kit';
|
|
3
|
-
|
|
4
|
-
type ProviderState = {
|
|
5
|
-
status: "loading";
|
|
6
|
-
provider: null;
|
|
7
|
-
} | {
|
|
8
|
-
status: "success";
|
|
9
|
-
provider: PhantomSolanaProvider;
|
|
10
|
-
} | {
|
|
11
|
-
status: "error";
|
|
12
|
-
provider: null;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Retrieves the Phantom injected provider. If for some reason the provider is not available, it will retry up to 10 times with exponential backoff.
|
|
16
|
-
* @returns Object containing the provider status, provider instance, and any error.
|
|
17
|
-
*/
|
|
18
|
-
declare function useProvider(): ProviderState;
|
|
3
|
+
import { VersionedTransaction } from '@solana/web3.js';
|
|
19
4
|
|
|
20
5
|
type UseConnectProps = {
|
|
21
6
|
autoConnect?: boolean;
|
|
@@ -38,7 +23,7 @@ interface UseSignInResult {
|
|
|
38
23
|
declare function useSignIn(): UseSignInResult;
|
|
39
24
|
|
|
40
25
|
interface UseSignAndSendTransactionResult {
|
|
41
|
-
signAndSendTransaction: (transaction: Transaction) => Promise<{
|
|
26
|
+
signAndSendTransaction: (transaction: Transaction | VersionedTransaction) => Promise<{
|
|
42
27
|
signature: string;
|
|
43
28
|
publicKey?: string;
|
|
44
29
|
}>;
|
|
@@ -53,20 +38,13 @@ interface UseSignMessageResult {
|
|
|
53
38
|
}
|
|
54
39
|
declare function useSignMessage(): UseSignMessageResult;
|
|
55
40
|
|
|
56
|
-
type UseAccountResult = {
|
|
57
|
-
status: "connected";
|
|
58
|
-
address: string;
|
|
59
|
-
} | {
|
|
60
|
-
status: "disconnected" | "loading";
|
|
61
|
-
address: null;
|
|
62
|
-
};
|
|
63
41
|
/**
|
|
64
42
|
* React hook that provides the current account connection status and public key.
|
|
65
43
|
* Automatically updates when the account connects, disconnects, or changes.
|
|
66
44
|
*
|
|
67
45
|
* @returns Object containing status ('connected' | 'disconnected') and address (string | null)
|
|
68
46
|
*/
|
|
69
|
-
declare function useAccount():
|
|
47
|
+
declare function useAccount(): string | undefined;
|
|
70
48
|
|
|
71
49
|
type UseAccountEffectParameters = {
|
|
72
50
|
onConnect?(data: {
|
|
@@ -83,4 +61,4 @@ type UseAccountEffectParameters = {
|
|
|
83
61
|
*/
|
|
84
62
|
declare function useAccountEffect(parameters?: UseAccountEffectParameters): void;
|
|
85
63
|
|
|
86
|
-
export { useAccount, useAccountEffect, useConnect, useDisconnect,
|
|
64
|
+
export { useAccount, useAccountEffect, useConnect, useDisconnect, useSignAndSendTransaction, useSignIn, useSignMessage };
|
package/dist/solana/index.js
CHANGED
|
@@ -34,7 +34,6 @@ __export(solana_exports, {
|
|
|
34
34
|
useAccountEffect: () => useAccountEffect,
|
|
35
35
|
useConnect: () => useConnect,
|
|
36
36
|
useDisconnect: () => useDisconnect,
|
|
37
|
-
useProvider: () => useProvider,
|
|
38
37
|
useSignAndSendTransaction: () => useSignAndSendTransaction,
|
|
39
38
|
useSignIn: () => useSignIn,
|
|
40
39
|
useSignMessage: () => useSignMessage
|
|
@@ -42,7 +41,7 @@ __export(solana_exports, {
|
|
|
42
41
|
module.exports = __toCommonJS(solana_exports);
|
|
43
42
|
var import_solana = require("@phantom/browser-sdk/solana");
|
|
44
43
|
|
|
45
|
-
// src/solana/
|
|
44
|
+
// src/solana/useConnect.ts
|
|
46
45
|
var React2 = __toESM(require("react"));
|
|
47
46
|
|
|
48
47
|
// src/PhantomContext.tsx
|
|
@@ -58,84 +57,16 @@ function usePhantom() {
|
|
|
58
57
|
return context;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
// src/solana/useProvider.ts
|
|
62
|
-
var MAX_RETRIES = 10;
|
|
63
|
-
var BASE_DELAY = 100;
|
|
64
|
-
function useProvider() {
|
|
65
|
-
const { phantom, isReady } = usePhantom();
|
|
66
|
-
const [state, setState] = React2.useState({
|
|
67
|
-
status: "loading",
|
|
68
|
-
provider: null
|
|
69
|
-
});
|
|
70
|
-
const tryResolvingProvider = React2.useCallback(() => {
|
|
71
|
-
if (!phantom) {
|
|
72
|
-
setState({
|
|
73
|
-
status: "error",
|
|
74
|
-
provider: null
|
|
75
|
-
});
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
if (!phantom.solana) {
|
|
79
|
-
setState({
|
|
80
|
-
status: "error",
|
|
81
|
-
provider: null
|
|
82
|
-
});
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
const provider = phantom.solana.getProvider();
|
|
87
|
-
if (provider != null) {
|
|
88
|
-
setState({ status: "success", provider });
|
|
89
|
-
return true;
|
|
90
|
-
} else {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
} catch (error) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}, [phantom]);
|
|
97
|
-
React2.useEffect(() => {
|
|
98
|
-
if (!isReady) {
|
|
99
|
-
setState({ status: "loading", provider: null });
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (tryResolvingProvider()) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
let retryCount = 0;
|
|
106
|
-
const scheduleRetry = () => {
|
|
107
|
-
const delay = BASE_DELAY * Math.pow(2, Math.min(retryCount, 5));
|
|
108
|
-
setTimeout(() => {
|
|
109
|
-
if (tryResolvingProvider()) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
retryCount++;
|
|
113
|
-
if (retryCount >= MAX_RETRIES) {
|
|
114
|
-
setState({
|
|
115
|
-
status: "error",
|
|
116
|
-
provider: null
|
|
117
|
-
});
|
|
118
|
-
} else {
|
|
119
|
-
scheduleRetry();
|
|
120
|
-
}
|
|
121
|
-
}, delay);
|
|
122
|
-
};
|
|
123
|
-
scheduleRetry();
|
|
124
|
-
}, [isReady, tryResolvingProvider]);
|
|
125
|
-
return state;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
60
|
// src/solana/useConnect.ts
|
|
129
|
-
var React3 = __toESM(require("react"));
|
|
130
61
|
function useConnect({ autoConnect = false } = {}) {
|
|
131
62
|
const { phantom } = usePhantom();
|
|
132
|
-
const connect =
|
|
63
|
+
const connect = React2.useCallback(async () => {
|
|
133
64
|
if (!phantom?.solana) {
|
|
134
65
|
throw new Error("Phantom solana plugin not found.");
|
|
135
66
|
}
|
|
136
67
|
return await phantom.solana.connect();
|
|
137
68
|
}, [phantom]);
|
|
138
|
-
|
|
69
|
+
React2.useEffect(() => {
|
|
139
70
|
if (autoConnect && phantom?.solana) {
|
|
140
71
|
connect();
|
|
141
72
|
}
|
|
@@ -144,10 +75,10 @@ function useConnect({ autoConnect = false } = {}) {
|
|
|
144
75
|
}
|
|
145
76
|
|
|
146
77
|
// src/solana/useDisconnect.ts
|
|
147
|
-
var
|
|
78
|
+
var React3 = __toESM(require("react"));
|
|
148
79
|
function useDisconnect() {
|
|
149
80
|
const { phantom } = usePhantom();
|
|
150
|
-
const disconnect =
|
|
81
|
+
const disconnect = React3.useCallback(async () => {
|
|
151
82
|
if (!phantom?.solana) {
|
|
152
83
|
throw new Error("Phantom solana disconnect method not found.");
|
|
153
84
|
}
|
|
@@ -208,7 +139,7 @@ function useSignMessage() {
|
|
|
208
139
|
}
|
|
209
140
|
|
|
210
141
|
// src/solana/useAccount.ts
|
|
211
|
-
var
|
|
142
|
+
var React4 = __toESM(require("react"));
|
|
212
143
|
|
|
213
144
|
// src/solana/assertions.ts
|
|
214
145
|
function assertSolanaConfigured(phantom) {
|
|
@@ -222,25 +153,15 @@ function assertSolanaConfigured(phantom) {
|
|
|
222
153
|
// src/solana/useAccount.ts
|
|
223
154
|
function useAccount() {
|
|
224
155
|
const { phantom, isReady } = usePhantom();
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
if (!isReady)
|
|
228
|
-
return { status: "loading", address: null };
|
|
229
|
-
assertSolanaConfigured(phantom);
|
|
230
|
-
return phantom.solana.getAccount();
|
|
231
|
-
});
|
|
232
|
-
React5.useEffect(() => {
|
|
156
|
+
const [account, setAccount] = React4.useState(void 0);
|
|
157
|
+
React4.useEffect(() => {
|
|
233
158
|
if (!isReady)
|
|
234
159
|
return;
|
|
235
160
|
assertSolanaConfigured(phantom);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (account.status === "loading") {
|
|
239
|
-
setAccount(phantom.solana.getAccount());
|
|
240
|
-
}
|
|
241
|
-
const updateAccount = () => {
|
|
242
|
-
setAccount(phantom.solana.getAccount());
|
|
161
|
+
const updateAccount = async () => {
|
|
162
|
+
setAccount(await phantom.solana.getAccount());
|
|
243
163
|
};
|
|
164
|
+
updateAccount();
|
|
244
165
|
phantom.solana.addEventListener("connect", updateAccount);
|
|
245
166
|
phantom.solana.addEventListener("disconnect", updateAccount);
|
|
246
167
|
phantom.solana.addEventListener("accountChanged", updateAccount);
|
|
@@ -249,18 +170,17 @@ function useAccount() {
|
|
|
249
170
|
phantom.solana.removeEventListener("disconnect", updateAccount);
|
|
250
171
|
phantom.solana.removeEventListener("accountChanged", updateAccount);
|
|
251
172
|
};
|
|
252
|
-
}, [
|
|
173
|
+
}, [phantom, isReady]);
|
|
253
174
|
return account;
|
|
254
175
|
}
|
|
255
176
|
|
|
256
177
|
// src/solana/useAccountEffect.ts
|
|
257
|
-
var
|
|
178
|
+
var React5 = __toESM(require("react"));
|
|
258
179
|
function useAccountEffect(parameters = {}) {
|
|
259
180
|
const { onConnect, onDisconnect, onAccountChanged } = parameters;
|
|
260
181
|
const { phantom, isReady } = usePhantom();
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (!isReady || providerStatus !== "success" || !provider)
|
|
182
|
+
React5.useEffect(() => {
|
|
183
|
+
if (!isReady)
|
|
264
184
|
return;
|
|
265
185
|
assertSolanaConfigured(phantom);
|
|
266
186
|
const handleConnect = (publicKey) => {
|
|
@@ -296,7 +216,7 @@ function useAccountEffect(parameters = {}) {
|
|
|
296
216
|
phantom.solana.removeEventListener("accountChanged", handleAccountChanged);
|
|
297
217
|
}
|
|
298
218
|
};
|
|
299
|
-
}, [isReady,
|
|
219
|
+
}, [isReady, phantom, onConnect, onDisconnect, onAccountChanged]);
|
|
300
220
|
}
|
|
301
221
|
// Annotate the CommonJS export names for ESM import in node:
|
|
302
222
|
0 && (module.exports = {
|
|
@@ -304,7 +224,6 @@ function useAccountEffect(parameters = {}) {
|
|
|
304
224
|
useAccountEffect,
|
|
305
225
|
useConnect,
|
|
306
226
|
useDisconnect,
|
|
307
|
-
useProvider,
|
|
308
227
|
useSignAndSendTransaction,
|
|
309
228
|
useSignIn,
|
|
310
229
|
useSignMessage
|
package/dist/solana/index.mjs
CHANGED
|
@@ -5,85 +5,17 @@ import {
|
|
|
5
5
|
// src/solana/index.ts
|
|
6
6
|
import "@phantom/browser-sdk/solana";
|
|
7
7
|
|
|
8
|
-
// src/solana/useProvider.ts
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
var MAX_RETRIES = 10;
|
|
11
|
-
var BASE_DELAY = 100;
|
|
12
|
-
function useProvider() {
|
|
13
|
-
const { phantom, isReady } = usePhantom();
|
|
14
|
-
const [state, setState] = React.useState({
|
|
15
|
-
status: "loading",
|
|
16
|
-
provider: null
|
|
17
|
-
});
|
|
18
|
-
const tryResolvingProvider = React.useCallback(() => {
|
|
19
|
-
if (!phantom) {
|
|
20
|
-
setState({
|
|
21
|
-
status: "error",
|
|
22
|
-
provider: null
|
|
23
|
-
});
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
if (!phantom.solana) {
|
|
27
|
-
setState({
|
|
28
|
-
status: "error",
|
|
29
|
-
provider: null
|
|
30
|
-
});
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const provider = phantom.solana.getProvider();
|
|
35
|
-
if (provider != null) {
|
|
36
|
-
setState({ status: "success", provider });
|
|
37
|
-
return true;
|
|
38
|
-
} else {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
} catch (error) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}, [phantom]);
|
|
45
|
-
React.useEffect(() => {
|
|
46
|
-
if (!isReady) {
|
|
47
|
-
setState({ status: "loading", provider: null });
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
if (tryResolvingProvider()) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
let retryCount = 0;
|
|
54
|
-
const scheduleRetry = () => {
|
|
55
|
-
const delay = BASE_DELAY * Math.pow(2, Math.min(retryCount, 5));
|
|
56
|
-
setTimeout(() => {
|
|
57
|
-
if (tryResolvingProvider()) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
retryCount++;
|
|
61
|
-
if (retryCount >= MAX_RETRIES) {
|
|
62
|
-
setState({
|
|
63
|
-
status: "error",
|
|
64
|
-
provider: null
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
scheduleRetry();
|
|
68
|
-
}
|
|
69
|
-
}, delay);
|
|
70
|
-
};
|
|
71
|
-
scheduleRetry();
|
|
72
|
-
}, [isReady, tryResolvingProvider]);
|
|
73
|
-
return state;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
8
|
// src/solana/useConnect.ts
|
|
77
|
-
import * as
|
|
9
|
+
import * as React from "react";
|
|
78
10
|
function useConnect({ autoConnect = false } = {}) {
|
|
79
11
|
const { phantom } = usePhantom();
|
|
80
|
-
const connect =
|
|
12
|
+
const connect = React.useCallback(async () => {
|
|
81
13
|
if (!phantom?.solana) {
|
|
82
14
|
throw new Error("Phantom solana plugin not found.");
|
|
83
15
|
}
|
|
84
16
|
return await phantom.solana.connect();
|
|
85
17
|
}, [phantom]);
|
|
86
|
-
|
|
18
|
+
React.useEffect(() => {
|
|
87
19
|
if (autoConnect && phantom?.solana) {
|
|
88
20
|
connect();
|
|
89
21
|
}
|
|
@@ -92,10 +24,10 @@ function useConnect({ autoConnect = false } = {}) {
|
|
|
92
24
|
}
|
|
93
25
|
|
|
94
26
|
// src/solana/useDisconnect.ts
|
|
95
|
-
import * as
|
|
27
|
+
import * as React2 from "react";
|
|
96
28
|
function useDisconnect() {
|
|
97
29
|
const { phantom } = usePhantom();
|
|
98
|
-
const disconnect =
|
|
30
|
+
const disconnect = React2.useCallback(async () => {
|
|
99
31
|
if (!phantom?.solana) {
|
|
100
32
|
throw new Error("Phantom solana disconnect method not found.");
|
|
101
33
|
}
|
|
@@ -105,10 +37,10 @@ function useDisconnect() {
|
|
|
105
37
|
}
|
|
106
38
|
|
|
107
39
|
// src/solana/useSignIn.ts
|
|
108
|
-
import { useCallback as
|
|
40
|
+
import { useCallback as useCallback3 } from "react";
|
|
109
41
|
function useSignIn() {
|
|
110
42
|
const { phantom } = usePhantom();
|
|
111
|
-
const signIn =
|
|
43
|
+
const signIn = useCallback3(
|
|
112
44
|
async (signInData) => {
|
|
113
45
|
if (!phantom?.solana) {
|
|
114
46
|
throw new Error("Phantom Solana provider not available.");
|
|
@@ -122,10 +54,10 @@ function useSignIn() {
|
|
|
122
54
|
}
|
|
123
55
|
|
|
124
56
|
// src/solana/useSignAndSendTransaction.ts
|
|
125
|
-
import { useCallback as
|
|
57
|
+
import { useCallback as useCallback4 } from "react";
|
|
126
58
|
function useSignAndSendTransaction() {
|
|
127
59
|
const { phantom } = usePhantom();
|
|
128
|
-
const signAndSendTransaction =
|
|
60
|
+
const signAndSendTransaction = useCallback4(
|
|
129
61
|
async (transaction) => {
|
|
130
62
|
if (!phantom?.solana) {
|
|
131
63
|
throw new Error("Phantom Solana provider not available.");
|
|
@@ -139,10 +71,10 @@ function useSignAndSendTransaction() {
|
|
|
139
71
|
}
|
|
140
72
|
|
|
141
73
|
// src/solana/useSignMessage.ts
|
|
142
|
-
import { useCallback as
|
|
74
|
+
import { useCallback as useCallback5 } from "react";
|
|
143
75
|
function useSignMessage() {
|
|
144
76
|
const { phantom } = usePhantom();
|
|
145
|
-
const signMessage =
|
|
77
|
+
const signMessage = useCallback5(
|
|
146
78
|
async (message, display) => {
|
|
147
79
|
if (!phantom?.solana) {
|
|
148
80
|
throw new Error("Phantom Solana provider not available.");
|
|
@@ -156,7 +88,7 @@ function useSignMessage() {
|
|
|
156
88
|
}
|
|
157
89
|
|
|
158
90
|
// src/solana/useAccount.ts
|
|
159
|
-
import * as
|
|
91
|
+
import * as React3 from "react";
|
|
160
92
|
|
|
161
93
|
// src/solana/assertions.ts
|
|
162
94
|
function assertSolanaConfigured(phantom) {
|
|
@@ -170,25 +102,15 @@ function assertSolanaConfigured(phantom) {
|
|
|
170
102
|
// src/solana/useAccount.ts
|
|
171
103
|
function useAccount() {
|
|
172
104
|
const { phantom, isReady } = usePhantom();
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
if (!isReady)
|
|
176
|
-
return { status: "loading", address: null };
|
|
177
|
-
assertSolanaConfigured(phantom);
|
|
178
|
-
return phantom.solana.getAccount();
|
|
179
|
-
});
|
|
180
|
-
React4.useEffect(() => {
|
|
105
|
+
const [account, setAccount] = React3.useState(void 0);
|
|
106
|
+
React3.useEffect(() => {
|
|
181
107
|
if (!isReady)
|
|
182
108
|
return;
|
|
183
109
|
assertSolanaConfigured(phantom);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (account.status === "loading") {
|
|
187
|
-
setAccount(phantom.solana.getAccount());
|
|
188
|
-
}
|
|
189
|
-
const updateAccount = () => {
|
|
190
|
-
setAccount(phantom.solana.getAccount());
|
|
110
|
+
const updateAccount = async () => {
|
|
111
|
+
setAccount(await phantom.solana.getAccount());
|
|
191
112
|
};
|
|
113
|
+
updateAccount();
|
|
192
114
|
phantom.solana.addEventListener("connect", updateAccount);
|
|
193
115
|
phantom.solana.addEventListener("disconnect", updateAccount);
|
|
194
116
|
phantom.solana.addEventListener("accountChanged", updateAccount);
|
|
@@ -197,18 +119,17 @@ function useAccount() {
|
|
|
197
119
|
phantom.solana.removeEventListener("disconnect", updateAccount);
|
|
198
120
|
phantom.solana.removeEventListener("accountChanged", updateAccount);
|
|
199
121
|
};
|
|
200
|
-
}, [
|
|
122
|
+
}, [phantom, isReady]);
|
|
201
123
|
return account;
|
|
202
124
|
}
|
|
203
125
|
|
|
204
126
|
// src/solana/useAccountEffect.ts
|
|
205
|
-
import * as
|
|
127
|
+
import * as React4 from "react";
|
|
206
128
|
function useAccountEffect(parameters = {}) {
|
|
207
129
|
const { onConnect, onDisconnect, onAccountChanged } = parameters;
|
|
208
130
|
const { phantom, isReady } = usePhantom();
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (!isReady || providerStatus !== "success" || !provider)
|
|
131
|
+
React4.useEffect(() => {
|
|
132
|
+
if (!isReady)
|
|
212
133
|
return;
|
|
213
134
|
assertSolanaConfigured(phantom);
|
|
214
135
|
const handleConnect = (publicKey) => {
|
|
@@ -244,14 +165,13 @@ function useAccountEffect(parameters = {}) {
|
|
|
244
165
|
phantom.solana.removeEventListener("accountChanged", handleAccountChanged);
|
|
245
166
|
}
|
|
246
167
|
};
|
|
247
|
-
}, [isReady,
|
|
168
|
+
}, [isReady, phantom, onConnect, onDisconnect, onAccountChanged]);
|
|
248
169
|
}
|
|
249
170
|
export {
|
|
250
171
|
useAccount,
|
|
251
172
|
useAccountEffect,
|
|
252
173
|
useConnect,
|
|
253
174
|
useDisconnect,
|
|
254
|
-
useProvider,
|
|
255
175
|
useSignAndSendTransaction,
|
|
256
176
|
useSignIn,
|
|
257
177
|
useSignMessage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/react-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,13 +21,15 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"scripts": {
|
|
24
|
-
"build": "
|
|
25
|
-
"
|
|
24
|
+
"build": "rimraf ./dist && tsup src/index.ts src/solana/index.ts --format cjs,esm --dts",
|
|
25
|
+
"?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
|
|
26
|
+
"pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
|
|
27
|
+
"dev": "rimraf ./dist && tsup src/index.ts src/solana/index.ts --format cjs,esm --dts --watch",
|
|
26
28
|
"lint": "tsc --noEmit && eslint --cache . --ext .ts,.tsx",
|
|
27
29
|
"test": "jest"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"@phantom/browser-sdk": "
|
|
32
|
+
"@phantom/browser-sdk": "^0.0.7"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@testing-library/dom": "^10.4.0",
|
|
@@ -40,11 +42,15 @@
|
|
|
40
42
|
"jest-environment-jsdom": "^29.7.0",
|
|
41
43
|
"react": "18.2.0",
|
|
42
44
|
"react-dom": "18.2.0",
|
|
45
|
+
"rimraf": "^6.0.1",
|
|
43
46
|
"ts-jest": "^29",
|
|
44
47
|
"tsup": "^6.7.0",
|
|
45
48
|
"typescript": "^5.0.4"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
48
51
|
"react": ">=18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"directory": "_release/package"
|
|
49
55
|
}
|
|
50
|
-
}
|
|
56
|
+
}
|