@phantom/react-sdk 0.2.3 → 0.3.1
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 +73 -31
- package/dist/index.d.ts +4 -5
- package/dist/index.js +39 -51
- package/dist/index.mjs +40 -52
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ function App() {
|
|
|
67
67
|
providerType: "embedded",
|
|
68
68
|
embeddedWalletType: "app-wallet", // or 'user-wallet'
|
|
69
69
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
70
|
-
apiBaseUrl: "https://api.phantom.
|
|
70
|
+
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
71
71
|
organizationId: "your-org-id",
|
|
72
72
|
}}
|
|
73
73
|
>
|
|
@@ -109,7 +109,7 @@ Creates non-custodial wallets embedded in your application.
|
|
|
109
109
|
providerType: "embedded",
|
|
110
110
|
embeddedWalletType: "app-wallet",
|
|
111
111
|
addressTypes: [AddressType.solana],
|
|
112
|
-
apiBaseUrl: "https://api.phantom.
|
|
112
|
+
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
113
113
|
organizationId: "your-org-id",
|
|
114
114
|
}}
|
|
115
115
|
>
|
|
@@ -129,7 +129,7 @@ Creates non-custodial wallets embedded in your application.
|
|
|
129
129
|
providerType: "embedded",
|
|
130
130
|
embeddedWalletType: "user-wallet",
|
|
131
131
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
132
|
-
apiBaseUrl: "https://api.phantom.
|
|
132
|
+
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
133
133
|
organizationId: "your-org-id",
|
|
134
134
|
}}
|
|
135
135
|
>
|
|
@@ -147,7 +147,7 @@ When using `AddressType.solana`, you can choose between two Solana libraries:
|
|
|
147
147
|
providerType: "embedded",
|
|
148
148
|
addressTypes: [AddressType.solana],
|
|
149
149
|
solanaProvider: "web3js", // or 'kit'
|
|
150
|
-
apiBaseUrl: "https://api.phantom.
|
|
150
|
+
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
151
151
|
organizationId: "your-org-id",
|
|
152
152
|
}}
|
|
153
153
|
>
|
|
@@ -318,25 +318,43 @@ function SignMessage() {
|
|
|
318
318
|
|
|
319
319
|
```tsx
|
|
320
320
|
import { useSignAndSendTransaction, NetworkId } from "@phantom/react-sdk";
|
|
321
|
-
import {
|
|
321
|
+
import {
|
|
322
|
+
VersionedTransaction,
|
|
323
|
+
TransactionMessage,
|
|
324
|
+
SystemProgram,
|
|
325
|
+
PublicKey,
|
|
326
|
+
LAMPORTS_PER_SOL,
|
|
327
|
+
Connection,
|
|
328
|
+
} from "@solana/web3.js";
|
|
322
329
|
|
|
323
330
|
function SendSolanaTransaction() {
|
|
324
331
|
const { signAndSendTransaction, isLoading, error } = useSignAndSendTransaction();
|
|
325
332
|
|
|
326
333
|
const handleSend = async () => {
|
|
327
|
-
//
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
334
|
+
// Get recent blockhash
|
|
335
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
336
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
337
|
+
|
|
338
|
+
// Create transfer instruction
|
|
339
|
+
const transferInstruction = SystemProgram.transfer({
|
|
340
|
+
fromPubkey: new PublicKey(fromAddress),
|
|
341
|
+
toPubkey: new PublicKey(toAddress),
|
|
342
|
+
lamports: 0.001 * LAMPORTS_PER_SOL,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// Create VersionedTransaction
|
|
346
|
+
const messageV0 = new TransactionMessage({
|
|
347
|
+
payerKey: new PublicKey(fromAddress),
|
|
348
|
+
recentBlockhash: blockhash,
|
|
349
|
+
instructions: [transferInstruction],
|
|
350
|
+
}).compileToV0Message();
|
|
351
|
+
|
|
352
|
+
const transaction = new VersionedTransaction(messageV0);
|
|
335
353
|
|
|
336
354
|
try {
|
|
337
355
|
const result = await signAndSendTransaction({
|
|
338
356
|
networkId: NetworkId.SOLANA_MAINNET,
|
|
339
|
-
transaction: transaction, // Native
|
|
357
|
+
transaction: transaction, // Native VersionedTransaction object!
|
|
340
358
|
});
|
|
341
359
|
console.log("Transaction sent:", result.rawTransaction);
|
|
342
360
|
} catch (err) {
|
|
@@ -430,20 +448,32 @@ The SDK automatically determines the transaction type from the NetworkId:
|
|
|
430
448
|
### Solana with @solana/web3.js
|
|
431
449
|
|
|
432
450
|
```tsx
|
|
433
|
-
import {
|
|
451
|
+
import { VersionedTransaction, TransactionMessage, SystemProgram, PublicKey, Connection } from "@solana/web3.js";
|
|
434
452
|
import { useSignAndSendTransaction, NetworkId } from "@phantom/react-sdk";
|
|
435
453
|
|
|
436
454
|
function SolanaExample() {
|
|
437
455
|
const { signAndSendTransaction } = useSignAndSendTransaction();
|
|
438
456
|
|
|
439
457
|
const sendTransaction = async () => {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
458
|
+
// Get recent blockhash
|
|
459
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
460
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
461
|
+
|
|
462
|
+
// Create transfer instruction
|
|
463
|
+
const transferInstruction = SystemProgram.transfer({
|
|
464
|
+
fromPubkey: new PublicKey(fromAddress),
|
|
465
|
+
toPubkey: new PublicKey(toAddress),
|
|
466
|
+
lamports: 1000000, // 0.001 SOL
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// Create VersionedTransaction
|
|
470
|
+
const messageV0 = new TransactionMessage({
|
|
471
|
+
payerKey: new PublicKey(fromAddress),
|
|
472
|
+
recentBlockhash: blockhash,
|
|
473
|
+
instructions: [transferInstruction],
|
|
474
|
+
}).compileToV0Message();
|
|
475
|
+
|
|
476
|
+
const transaction = new VersionedTransaction(messageV0);
|
|
447
477
|
|
|
448
478
|
// No serialization or encoding needed!
|
|
449
479
|
const result = await signAndSendTransaction({
|
|
@@ -537,20 +567,32 @@ function EthereumExample() {
|
|
|
537
567
|
|
|
538
568
|
```tsx
|
|
539
569
|
import { useSignAndSendTransaction, NetworkId } from "@phantom/react-sdk";
|
|
540
|
-
import {
|
|
570
|
+
import { VersionedTransaction, TransactionMessage, SystemProgram, PublicKey, Connection } from "@solana/web3.js";
|
|
541
571
|
import { parseEther } from "viem";
|
|
542
572
|
|
|
543
573
|
function MultiChainWallet() {
|
|
544
574
|
const { signAndSendTransaction } = useSignAndSendTransaction();
|
|
545
575
|
|
|
546
576
|
const sendSolana = async () => {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
577
|
+
// Get recent blockhash
|
|
578
|
+
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
579
|
+
const { blockhash } = await connection.getLatestBlockhash();
|
|
580
|
+
|
|
581
|
+
// Create transfer instruction
|
|
582
|
+
const transferInstruction = SystemProgram.transfer({
|
|
583
|
+
fromPubkey: new PublicKey(solanaAddress),
|
|
584
|
+
toPubkey: new PublicKey(recipient),
|
|
585
|
+
lamports: 1000000,
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
// Create VersionedTransaction
|
|
589
|
+
const messageV0 = new TransactionMessage({
|
|
590
|
+
payerKey: new PublicKey(solanaAddress),
|
|
591
|
+
recentBlockhash: blockhash,
|
|
592
|
+
instructions: [transferInstruction],
|
|
593
|
+
}).compileToV0Message();
|
|
594
|
+
|
|
595
|
+
const transaction = new VersionedTransaction(messageV0);
|
|
554
596
|
|
|
555
597
|
return await signAndSendTransaction({
|
|
556
598
|
networkId: NetworkId.SOLANA_MAINNET,
|
|
@@ -591,7 +633,7 @@ Quick reference of all available hooks:
|
|
|
591
633
|
| `useSignMessage` | Sign text messages | `{ signMessage, isSigning, error }` |
|
|
592
634
|
| `useSignAndSendTransaction` | Sign and send transactions | `{ signAndSendTransaction, isSigning, error }` |
|
|
593
635
|
| `useCreateUserOrganization` | Create user organization (embedded) | `{ createUserOrganization, isCreating, error }` |
|
|
594
|
-
| `usePhantom` | Get provider context | `{ isConnected, isReady
|
|
636
|
+
| `usePhantom` | Get provider context | `{ isConnected, isReady }` |
|
|
595
637
|
|
|
596
638
|
## Configuration Reference
|
|
597
639
|
|
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, AuthOptions, BrowserSDK, WalletAddress, SignMessageParams, SignAndSendTransactionParams, SignedTransaction, CreateUserOrganizationParams, CreateUserOrganizationResult } from '@phantom/browser-sdk';
|
|
4
|
-
export { AddressType, CreateUserOrganizationParams, CreateUserOrganizationResult, DebugLevel, DebugMessage, NetworkId, SignAndSendTransactionParams, SignMessageParams, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
|
|
3
|
+
import { BrowserSDKConfig, AuthOptions, BrowserSDK, WalletAddress, SignMessageParams, SignMessageResult, SignAndSendTransactionParams, SignedTransaction, CreateUserOrganizationParams, CreateUserOrganizationResult } from '@phantom/browser-sdk';
|
|
4
|
+
export { AddressType, CreateUserOrganizationParams, CreateUserOrganizationResult, DebugLevel, DebugMessage, NetworkId, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
|
|
5
5
|
import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
|
|
6
6
|
|
|
7
7
|
interface PhantomSDKConfig extends BrowserSDKConfig {
|
|
@@ -12,11 +12,10 @@ interface ConnectOptions {
|
|
|
12
12
|
authOptions?: AuthOptions;
|
|
13
13
|
}
|
|
14
14
|
interface PhantomContextValue {
|
|
15
|
-
sdk: BrowserSDK
|
|
15
|
+
sdk: BrowserSDK;
|
|
16
16
|
isConnected: boolean;
|
|
17
17
|
addresses: WalletAddress[];
|
|
18
18
|
walletId: string | null;
|
|
19
|
-
isReady: boolean;
|
|
20
19
|
error: Error | null;
|
|
21
20
|
currentProviderType: "injected" | "embedded" | null;
|
|
22
21
|
isPhantomAvailable: boolean;
|
|
@@ -44,7 +43,7 @@ declare function useDisconnect(): {
|
|
|
44
43
|
};
|
|
45
44
|
|
|
46
45
|
declare function useSignMessage(): {
|
|
47
|
-
signMessage: (params: SignMessageParams) => Promise<
|
|
46
|
+
signMessage: (params: SignMessageParams) => Promise<SignMessageResult>;
|
|
48
47
|
isSigning: boolean;
|
|
49
48
|
error: Error | null;
|
|
50
49
|
};
|
package/dist/index.js
CHANGED
|
@@ -52,71 +52,61 @@ 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 }) {
|
|
55
|
-
const
|
|
55
|
+
const sdk = (0, import_react.useMemo)(
|
|
56
|
+
() => new import_browser_sdk.BrowserSDK({
|
|
57
|
+
...config,
|
|
58
|
+
// Use providerType if provided, default to embedded
|
|
59
|
+
providerType: config.providerType || "embedded"
|
|
60
|
+
}),
|
|
61
|
+
[config]
|
|
62
|
+
);
|
|
56
63
|
const [isConnected, setIsConnected] = (0, import_react.useState)(false);
|
|
57
64
|
const [addresses, setAddresses] = (0, import_react.useState)([]);
|
|
58
65
|
const [walletId, setWalletId] = (0, import_react.useState)(null);
|
|
59
|
-
const [isReady, setIsReady] = (0, import_react.useState)(false);
|
|
60
66
|
const [error, setError] = (0, import_react.useState)(null);
|
|
61
67
|
const [currentProviderType, setCurrentProviderType] = (0, import_react.useState)(null);
|
|
62
68
|
const [isPhantomAvailable, setIsPhantomAvailable] = (0, import_react.useState)(false);
|
|
63
|
-
(0, import_react.
|
|
69
|
+
const updateConnectionState = (0, import_react.useCallback)(async () => {
|
|
64
70
|
try {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
checkPhantom();
|
|
79
|
-
setIsReady(true);
|
|
71
|
+
const connected = sdk.isConnected();
|
|
72
|
+
setIsConnected(connected);
|
|
73
|
+
const providerInfo = sdk.getCurrentProviderInfo();
|
|
74
|
+
setCurrentProviderType(providerInfo?.type || null);
|
|
75
|
+
if (connected) {
|
|
76
|
+
const addrs = await sdk.getAddresses();
|
|
77
|
+
setAddresses(addrs);
|
|
78
|
+
setWalletId(sdk.getWalletId());
|
|
79
|
+
} else {
|
|
80
|
+
setAddresses([]);
|
|
81
|
+
setWalletId(null);
|
|
82
|
+
}
|
|
80
83
|
} catch (err) {
|
|
84
|
+
console.error("Error updating connection state:", err);
|
|
81
85
|
setError(err);
|
|
82
|
-
setIsReady(true);
|
|
83
86
|
}
|
|
84
|
-
}, [
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
}, [sdk]);
|
|
88
|
+
(0, import_react.useEffect)(() => {
|
|
89
|
+
const checkPhantomExtension = async () => {
|
|
87
90
|
try {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
const providerInfo = sdk.getCurrentProviderInfo();
|
|
91
|
-
setCurrentProviderType(providerInfo?.type || null);
|
|
92
|
-
if (connected) {
|
|
93
|
-
const addrs = await sdk.getAddresses();
|
|
94
|
-
setAddresses(addrs);
|
|
95
|
-
setWalletId(sdk.getWalletId());
|
|
96
|
-
} else {
|
|
97
|
-
setAddresses([]);
|
|
98
|
-
setWalletId(null);
|
|
99
|
-
}
|
|
91
|
+
const available = await sdk.waitForPhantomExtension(1e3);
|
|
92
|
+
setIsPhantomAvailable(available);
|
|
100
93
|
} catch (err) {
|
|
101
|
-
console.error("Error
|
|
94
|
+
console.error("Error checking Phantom extension:", err);
|
|
95
|
+
setIsPhantomAvailable(false);
|
|
102
96
|
}
|
|
103
|
-
}
|
|
104
|
-
|
|
97
|
+
};
|
|
98
|
+
checkPhantomExtension();
|
|
99
|
+
updateConnectionState();
|
|
100
|
+
}, [sdk, updateConnectionState]);
|
|
105
101
|
(0, import_react.useEffect)(() => {
|
|
106
102
|
updateConnectionState();
|
|
107
103
|
}, [updateConnectionState]);
|
|
108
|
-
(0, import_react.useEffect)(() => {
|
|
109
|
-
if (sdk) {
|
|
110
|
-
sdk._updateConnectionState = updateConnectionState;
|
|
111
|
-
}
|
|
112
|
-
}, [sdk, updateConnectionState]);
|
|
113
104
|
const value = {
|
|
114
105
|
sdk,
|
|
115
106
|
isConnected,
|
|
116
107
|
addresses,
|
|
117
108
|
updateConnectionState,
|
|
118
109
|
walletId,
|
|
119
|
-
isReady,
|
|
120
110
|
error,
|
|
121
111
|
currentProviderType,
|
|
122
112
|
isPhantomAvailable
|
|
@@ -139,16 +129,14 @@ function useConnect() {
|
|
|
139
129
|
const [error, setError] = (0, import_react2.useState)(null);
|
|
140
130
|
const connect = (0, import_react2.useCallback)(
|
|
141
131
|
async (options) => {
|
|
142
|
-
if (!context.sdk
|
|
132
|
+
if (!context.sdk) {
|
|
143
133
|
throw new Error("SDK not initialized");
|
|
144
134
|
}
|
|
145
135
|
setIsConnecting(true);
|
|
146
136
|
setError(null);
|
|
147
137
|
try {
|
|
148
138
|
const result = await context.sdk.connect(options);
|
|
149
|
-
|
|
150
|
-
await context.sdk._updateConnectionState();
|
|
151
|
-
}
|
|
139
|
+
await context.updateConnectionState();
|
|
152
140
|
return result;
|
|
153
141
|
} catch (err) {
|
|
154
142
|
console.error("Error connecting to Phantom:", err);
|
|
@@ -158,7 +146,7 @@ function useConnect() {
|
|
|
158
146
|
setIsConnecting(false);
|
|
159
147
|
}
|
|
160
148
|
},
|
|
161
|
-
[context
|
|
149
|
+
[context]
|
|
162
150
|
);
|
|
163
151
|
return {
|
|
164
152
|
connect,
|
|
@@ -172,11 +160,11 @@ function useConnect() {
|
|
|
172
160
|
// src/hooks/useDisconnect.ts
|
|
173
161
|
var import_react3 = require("react");
|
|
174
162
|
function useDisconnect() {
|
|
175
|
-
const { sdk,
|
|
163
|
+
const { sdk, updateConnectionState } = usePhantom();
|
|
176
164
|
const [isDisconnecting, setIsDisconnecting] = (0, import_react3.useState)(false);
|
|
177
165
|
const [error, setError] = (0, import_react3.useState)(null);
|
|
178
166
|
const disconnect = (0, import_react3.useCallback)(async () => {
|
|
179
|
-
if (!sdk
|
|
167
|
+
if (!sdk) {
|
|
180
168
|
throw new Error("SDK not initialized");
|
|
181
169
|
}
|
|
182
170
|
setIsDisconnecting(true);
|
|
@@ -190,7 +178,7 @@ function useDisconnect() {
|
|
|
190
178
|
} finally {
|
|
191
179
|
setIsDisconnecting(false);
|
|
192
180
|
}
|
|
193
|
-
}, [sdk,
|
|
181
|
+
}, [sdk, updateConnectionState]);
|
|
194
182
|
return {
|
|
195
183
|
disconnect,
|
|
196
184
|
isDisconnecting,
|
package/dist/index.mjs
CHANGED
|
@@ -1,74 +1,64 @@
|
|
|
1
1
|
// src/PhantomProvider.tsx
|
|
2
|
-
import { createContext, useContext, useState, useEffect, useCallback } from "react";
|
|
2
|
+
import { createContext, useContext, useState, useEffect, useCallback, useMemo } from "react";
|
|
3
3
|
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 }) {
|
|
7
|
-
const
|
|
7
|
+
const sdk = useMemo(
|
|
8
|
+
() => new BrowserSDK({
|
|
9
|
+
...config,
|
|
10
|
+
// Use providerType if provided, default to embedded
|
|
11
|
+
providerType: config.providerType || "embedded"
|
|
12
|
+
}),
|
|
13
|
+
[config]
|
|
14
|
+
);
|
|
8
15
|
const [isConnected, setIsConnected] = useState(false);
|
|
9
16
|
const [addresses, setAddresses] = useState([]);
|
|
10
17
|
const [walletId, setWalletId] = useState(null);
|
|
11
|
-
const [isReady, setIsReady] = useState(false);
|
|
12
18
|
const [error, setError] = useState(null);
|
|
13
19
|
const [currentProviderType, setCurrentProviderType] = useState(null);
|
|
14
20
|
const [isPhantomAvailable, setIsPhantomAvailable] = useState(false);
|
|
15
|
-
|
|
21
|
+
const updateConnectionState = useCallback(async () => {
|
|
16
22
|
try {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
checkPhantom();
|
|
31
|
-
setIsReady(true);
|
|
23
|
+
const connected = sdk.isConnected();
|
|
24
|
+
setIsConnected(connected);
|
|
25
|
+
const providerInfo = sdk.getCurrentProviderInfo();
|
|
26
|
+
setCurrentProviderType(providerInfo?.type || null);
|
|
27
|
+
if (connected) {
|
|
28
|
+
const addrs = await sdk.getAddresses();
|
|
29
|
+
setAddresses(addrs);
|
|
30
|
+
setWalletId(sdk.getWalletId());
|
|
31
|
+
} else {
|
|
32
|
+
setAddresses([]);
|
|
33
|
+
setWalletId(null);
|
|
34
|
+
}
|
|
32
35
|
} catch (err) {
|
|
36
|
+
console.error("Error updating connection state:", err);
|
|
33
37
|
setError(err);
|
|
34
|
-
setIsReady(true);
|
|
35
38
|
}
|
|
36
|
-
}, [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
}, [sdk]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const checkPhantomExtension = async () => {
|
|
39
42
|
try {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
const providerInfo = sdk.getCurrentProviderInfo();
|
|
43
|
-
setCurrentProviderType(providerInfo?.type || null);
|
|
44
|
-
if (connected) {
|
|
45
|
-
const addrs = await sdk.getAddresses();
|
|
46
|
-
setAddresses(addrs);
|
|
47
|
-
setWalletId(sdk.getWalletId());
|
|
48
|
-
} else {
|
|
49
|
-
setAddresses([]);
|
|
50
|
-
setWalletId(null);
|
|
51
|
-
}
|
|
43
|
+
const available = await sdk.waitForPhantomExtension(1e3);
|
|
44
|
+
setIsPhantomAvailable(available);
|
|
52
45
|
} catch (err) {
|
|
53
|
-
console.error("Error
|
|
46
|
+
console.error("Error checking Phantom extension:", err);
|
|
47
|
+
setIsPhantomAvailable(false);
|
|
54
48
|
}
|
|
55
|
-
}
|
|
56
|
-
|
|
49
|
+
};
|
|
50
|
+
checkPhantomExtension();
|
|
51
|
+
updateConnectionState();
|
|
52
|
+
}, [sdk, updateConnectionState]);
|
|
57
53
|
useEffect(() => {
|
|
58
54
|
updateConnectionState();
|
|
59
55
|
}, [updateConnectionState]);
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (sdk) {
|
|
62
|
-
sdk._updateConnectionState = updateConnectionState;
|
|
63
|
-
}
|
|
64
|
-
}, [sdk, updateConnectionState]);
|
|
65
56
|
const value = {
|
|
66
57
|
sdk,
|
|
67
58
|
isConnected,
|
|
68
59
|
addresses,
|
|
69
60
|
updateConnectionState,
|
|
70
61
|
walletId,
|
|
71
|
-
isReady,
|
|
72
62
|
error,
|
|
73
63
|
currentProviderType,
|
|
74
64
|
isPhantomAvailable
|
|
@@ -91,16 +81,14 @@ function useConnect() {
|
|
|
91
81
|
const [error, setError] = useState2(null);
|
|
92
82
|
const connect = useCallback2(
|
|
93
83
|
async (options) => {
|
|
94
|
-
if (!context.sdk
|
|
84
|
+
if (!context.sdk) {
|
|
95
85
|
throw new Error("SDK not initialized");
|
|
96
86
|
}
|
|
97
87
|
setIsConnecting(true);
|
|
98
88
|
setError(null);
|
|
99
89
|
try {
|
|
100
90
|
const result = await context.sdk.connect(options);
|
|
101
|
-
|
|
102
|
-
await context.sdk._updateConnectionState();
|
|
103
|
-
}
|
|
91
|
+
await context.updateConnectionState();
|
|
104
92
|
return result;
|
|
105
93
|
} catch (err) {
|
|
106
94
|
console.error("Error connecting to Phantom:", err);
|
|
@@ -110,7 +98,7 @@ function useConnect() {
|
|
|
110
98
|
setIsConnecting(false);
|
|
111
99
|
}
|
|
112
100
|
},
|
|
113
|
-
[context
|
|
101
|
+
[context]
|
|
114
102
|
);
|
|
115
103
|
return {
|
|
116
104
|
connect,
|
|
@@ -124,11 +112,11 @@ function useConnect() {
|
|
|
124
112
|
// src/hooks/useDisconnect.ts
|
|
125
113
|
import { useCallback as useCallback3, useState as useState3 } from "react";
|
|
126
114
|
function useDisconnect() {
|
|
127
|
-
const { sdk,
|
|
115
|
+
const { sdk, updateConnectionState } = usePhantom();
|
|
128
116
|
const [isDisconnecting, setIsDisconnecting] = useState3(false);
|
|
129
117
|
const [error, setError] = useState3(null);
|
|
130
118
|
const disconnect = useCallback3(async () => {
|
|
131
|
-
if (!sdk
|
|
119
|
+
if (!sdk) {
|
|
132
120
|
throw new Error("SDK not initialized");
|
|
133
121
|
}
|
|
134
122
|
setIsDisconnecting(true);
|
|
@@ -142,7 +130,7 @@ function useDisconnect() {
|
|
|
142
130
|
} finally {
|
|
143
131
|
setIsDisconnecting(false);
|
|
144
132
|
}
|
|
145
|
-
}, [sdk,
|
|
133
|
+
}, [sdk, updateConnectionState]);
|
|
146
134
|
return {
|
|
147
135
|
disconnect,
|
|
148
136
|
isDisconnecting,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,31 +21,32 @@
|
|
|
21
21
|
"pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
|
|
22
22
|
"dev": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --watch",
|
|
23
23
|
"lint": "tsc --noEmit && eslint --cache . --ext .ts,.tsx",
|
|
24
|
+
"check-types": "tsc --noEmit",
|
|
24
25
|
"test": "jest",
|
|
25
26
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@phantom/browser-sdk": "^0.
|
|
29
|
+
"@phantom/browser-sdk": "^0.3.1"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@testing-library/dom": "^10.4.0",
|
|
32
33
|
"@testing-library/react": "^16.3.0",
|
|
33
34
|
"@types/jest": "^29.5.14",
|
|
34
|
-
"@types/react": "^19.1.
|
|
35
|
-
"@types/react-dom": "^19.1.
|
|
35
|
+
"@types/react": "^19.1.2",
|
|
36
|
+
"@types/react-dom": "^19.1.2",
|
|
36
37
|
"eslint": "8.53.0",
|
|
37
38
|
"jest": "^29.7.0",
|
|
38
39
|
"jest-environment-jsdom": "^29.7.0",
|
|
39
40
|
"prettier": "^3.5.2",
|
|
40
|
-
"react": "
|
|
41
|
-
"react-dom": "
|
|
41
|
+
"react": "19.1.1",
|
|
42
|
+
"react-dom": "19.1.1",
|
|
42
43
|
"rimraf": "^6.0.1",
|
|
43
44
|
"ts-jest": "^29",
|
|
44
45
|
"tsup": "^6.7.0",
|
|
45
46
|
"typescript": "^5.0.4"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
|
-
"react": ">=
|
|
49
|
+
"react": ">=19.0.0"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
51
52
|
"directory": "_release/package"
|