@phantom/react-sdk 1.0.0-beta.7 → 1.0.0-beta.8
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/dist/index.d.ts +4 -4
- package/dist/index.js +39 -8
- package/dist/index.mjs +39 -8
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { ReactNode } from 'react';
|
|
|
3
3
|
import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult } from '@phantom/browser-sdk';
|
|
4
4
|
export { AddressType, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, DebugLevel, DebugMessage, NetworkId, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
|
|
5
5
|
import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
|
|
6
|
-
import * as _phantom_chain_interfaces from '@phantom/chain-interfaces';
|
|
7
6
|
export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
|
|
8
7
|
|
|
9
8
|
type PhantomSDKConfig = BrowserSDKConfig;
|
|
@@ -15,7 +14,7 @@ interface ConnectOptions {
|
|
|
15
14
|
authOptions?: AuthOptions;
|
|
16
15
|
}
|
|
17
16
|
interface PhantomContextValue {
|
|
18
|
-
sdk: BrowserSDK;
|
|
17
|
+
sdk: BrowserSDK | null;
|
|
19
18
|
isConnected: boolean;
|
|
20
19
|
isConnecting: boolean;
|
|
21
20
|
connectError: Error | null;
|
|
@@ -23,6 +22,7 @@ interface PhantomContextValue {
|
|
|
23
22
|
walletId: string | null;
|
|
24
23
|
currentProviderType: "injected" | "embedded" | null;
|
|
25
24
|
isPhantomAvailable: boolean;
|
|
25
|
+
isClient: boolean;
|
|
26
26
|
}
|
|
27
27
|
interface PhantomProviderProps {
|
|
28
28
|
children: ReactNode;
|
|
@@ -74,7 +74,7 @@ declare function useAutoConfirm(): UseAutoConfirmResult;
|
|
|
74
74
|
* @returns Solana chain interface with connection enforcement
|
|
75
75
|
*/
|
|
76
76
|
declare function useSolana(): {
|
|
77
|
-
solana:
|
|
77
|
+
solana: any;
|
|
78
78
|
isAvailable: boolean;
|
|
79
79
|
};
|
|
80
80
|
|
|
@@ -84,7 +84,7 @@ declare function useSolana(): {
|
|
|
84
84
|
* @returns Ethereum chain interface with connection enforcement
|
|
85
85
|
*/
|
|
86
86
|
declare function useEthereum(): {
|
|
87
|
-
ethereum:
|
|
87
|
+
ethereum: any;
|
|
88
88
|
isAvailable: boolean;
|
|
89
89
|
};
|
|
90
90
|
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,8 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
53
53
|
var PhantomContext = (0, import_react.createContext)(void 0);
|
|
54
54
|
function PhantomProvider({ children, config, debugConfig }) {
|
|
55
55
|
const memoizedConfig = (0, import_react.useMemo)(() => config, [config]);
|
|
56
|
+
const [sdk, setSdk] = (0, import_react.useState)(null);
|
|
57
|
+
const [isClient, setIsClient] = (0, import_react.useState)(false);
|
|
56
58
|
const [isConnected, setIsConnected] = (0, import_react.useState)(false);
|
|
57
59
|
const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
|
|
58
60
|
const [connectError, setConnectError] = (0, import_react.useState)(null);
|
|
@@ -62,8 +64,22 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
62
64
|
memoizedConfig.providerType || null
|
|
63
65
|
);
|
|
64
66
|
const [isPhantomAvailable, setIsPhantomAvailable] = (0, import_react.useState)(false);
|
|
65
|
-
const sdk = (0, import_react.useMemo)(() => new import_browser_sdk.BrowserSDK(memoizedConfig), [memoizedConfig]);
|
|
66
67
|
(0, import_react.useEffect)(() => {
|
|
68
|
+
setIsClient(true);
|
|
69
|
+
}, []);
|
|
70
|
+
(0, import_react.useEffect)(() => {
|
|
71
|
+
if (!isClient)
|
|
72
|
+
return;
|
|
73
|
+
const sdkInstance = new import_browser_sdk.BrowserSDK(memoizedConfig);
|
|
74
|
+
setSdk(sdkInstance);
|
|
75
|
+
return () => {
|
|
76
|
+
sdkInstance.disconnect().catch(() => {
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
}, [isClient, memoizedConfig]);
|
|
80
|
+
(0, import_react.useEffect)(() => {
|
|
81
|
+
if (!sdk)
|
|
82
|
+
return;
|
|
67
83
|
const handleConnectStart = () => {
|
|
68
84
|
setIsConnecting(true);
|
|
69
85
|
setConnectError(null);
|
|
@@ -110,12 +126,12 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
110
126
|
};
|
|
111
127
|
}, [sdk]);
|
|
112
128
|
(0, import_react.useEffect)(() => {
|
|
113
|
-
if (!
|
|
129
|
+
if (!debugConfig || !sdk)
|
|
114
130
|
return;
|
|
115
131
|
sdk.configureDebug(debugConfig);
|
|
116
132
|
}, [sdk, debugConfig]);
|
|
117
133
|
(0, import_react.useEffect)(() => {
|
|
118
|
-
if (!sdk)
|
|
134
|
+
if (!isClient || !sdk)
|
|
119
135
|
return;
|
|
120
136
|
const initialize = async () => {
|
|
121
137
|
try {
|
|
@@ -131,7 +147,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
131
147
|
}
|
|
132
148
|
};
|
|
133
149
|
initialize();
|
|
134
|
-
}, [sdk, memoizedConfig.autoConnect]);
|
|
150
|
+
}, [sdk, memoizedConfig.autoConnect, isClient]);
|
|
135
151
|
const value = (0, import_react.useMemo)(
|
|
136
152
|
() => ({
|
|
137
153
|
sdk,
|
|
@@ -141,9 +157,10 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
141
157
|
addresses,
|
|
142
158
|
walletId,
|
|
143
159
|
currentProviderType,
|
|
144
|
-
isPhantomAvailable
|
|
160
|
+
isPhantomAvailable,
|
|
161
|
+
isClient
|
|
145
162
|
}),
|
|
146
|
-
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable]
|
|
163
|
+
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable, isClient]
|
|
147
164
|
);
|
|
148
165
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
|
|
149
166
|
}
|
|
@@ -346,7 +363,14 @@ function useAutoConfirm() {
|
|
|
346
363
|
|
|
347
364
|
// src/hooks/useSolana.ts
|
|
348
365
|
function useSolana() {
|
|
349
|
-
const { sdk, isConnected } = usePhantom();
|
|
366
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
367
|
+
if (!isClient || !sdk) {
|
|
368
|
+
return {
|
|
369
|
+
solana: {},
|
|
370
|
+
// This will be replaced when SDK is ready
|
|
371
|
+
isAvailable: false
|
|
372
|
+
};
|
|
373
|
+
}
|
|
350
374
|
return {
|
|
351
375
|
// Chain instance with connection enforcement for signing methods
|
|
352
376
|
solana: sdk.solana,
|
|
@@ -357,7 +381,14 @@ function useSolana() {
|
|
|
357
381
|
|
|
358
382
|
// src/hooks/useEthereum.ts
|
|
359
383
|
function useEthereum() {
|
|
360
|
-
const { sdk, isConnected } = usePhantom();
|
|
384
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
385
|
+
if (!isClient || !sdk) {
|
|
386
|
+
return {
|
|
387
|
+
ethereum: {},
|
|
388
|
+
// This will be replaced when SDK is ready
|
|
389
|
+
isAvailable: false
|
|
390
|
+
};
|
|
391
|
+
}
|
|
361
392
|
return {
|
|
362
393
|
// Chain instance with connection enforcement for signing methods
|
|
363
394
|
ethereum: sdk.ethereum,
|
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,8 @@ import { jsx } from "react/jsx-runtime";
|
|
|
5
5
|
var PhantomContext = createContext(void 0);
|
|
6
6
|
function PhantomProvider({ children, config, debugConfig }) {
|
|
7
7
|
const memoizedConfig = useMemo(() => config, [config]);
|
|
8
|
+
const [sdk, setSdk] = useState(null);
|
|
9
|
+
const [isClient, setIsClient] = useState(false);
|
|
8
10
|
const [isConnected, setIsConnected] = useState(false);
|
|
9
11
|
const [isConnecting, setIsConnecting] = useState(false);
|
|
10
12
|
const [connectError, setConnectError] = useState(null);
|
|
@@ -14,8 +16,22 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
14
16
|
memoizedConfig.providerType || null
|
|
15
17
|
);
|
|
16
18
|
const [isPhantomAvailable, setIsPhantomAvailable] = useState(false);
|
|
17
|
-
const sdk = useMemo(() => new BrowserSDK(memoizedConfig), [memoizedConfig]);
|
|
18
19
|
useEffect(() => {
|
|
20
|
+
setIsClient(true);
|
|
21
|
+
}, []);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!isClient)
|
|
24
|
+
return;
|
|
25
|
+
const sdkInstance = new BrowserSDK(memoizedConfig);
|
|
26
|
+
setSdk(sdkInstance);
|
|
27
|
+
return () => {
|
|
28
|
+
sdkInstance.disconnect().catch(() => {
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}, [isClient, memoizedConfig]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!sdk)
|
|
34
|
+
return;
|
|
19
35
|
const handleConnectStart = () => {
|
|
20
36
|
setIsConnecting(true);
|
|
21
37
|
setConnectError(null);
|
|
@@ -62,12 +78,12 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
62
78
|
};
|
|
63
79
|
}, [sdk]);
|
|
64
80
|
useEffect(() => {
|
|
65
|
-
if (!
|
|
81
|
+
if (!debugConfig || !sdk)
|
|
66
82
|
return;
|
|
67
83
|
sdk.configureDebug(debugConfig);
|
|
68
84
|
}, [sdk, debugConfig]);
|
|
69
85
|
useEffect(() => {
|
|
70
|
-
if (!sdk)
|
|
86
|
+
if (!isClient || !sdk)
|
|
71
87
|
return;
|
|
72
88
|
const initialize = async () => {
|
|
73
89
|
try {
|
|
@@ -83,7 +99,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
83
99
|
}
|
|
84
100
|
};
|
|
85
101
|
initialize();
|
|
86
|
-
}, [sdk, memoizedConfig.autoConnect]);
|
|
102
|
+
}, [sdk, memoizedConfig.autoConnect, isClient]);
|
|
87
103
|
const value = useMemo(
|
|
88
104
|
() => ({
|
|
89
105
|
sdk,
|
|
@@ -93,9 +109,10 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
93
109
|
addresses,
|
|
94
110
|
walletId,
|
|
95
111
|
currentProviderType,
|
|
96
|
-
isPhantomAvailable
|
|
112
|
+
isPhantomAvailable,
|
|
113
|
+
isClient
|
|
97
114
|
}),
|
|
98
|
-
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable]
|
|
115
|
+
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable, isClient]
|
|
99
116
|
);
|
|
100
117
|
return /* @__PURE__ */ jsx(PhantomContext.Provider, { value, children });
|
|
101
118
|
}
|
|
@@ -298,7 +315,14 @@ function useAutoConfirm() {
|
|
|
298
315
|
|
|
299
316
|
// src/hooks/useSolana.ts
|
|
300
317
|
function useSolana() {
|
|
301
|
-
const { sdk, isConnected } = usePhantom();
|
|
318
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
319
|
+
if (!isClient || !sdk) {
|
|
320
|
+
return {
|
|
321
|
+
solana: {},
|
|
322
|
+
// This will be replaced when SDK is ready
|
|
323
|
+
isAvailable: false
|
|
324
|
+
};
|
|
325
|
+
}
|
|
302
326
|
return {
|
|
303
327
|
// Chain instance with connection enforcement for signing methods
|
|
304
328
|
solana: sdk.solana,
|
|
@@ -309,7 +333,14 @@ function useSolana() {
|
|
|
309
333
|
|
|
310
334
|
// src/hooks/useEthereum.ts
|
|
311
335
|
function useEthereum() {
|
|
312
|
-
const { sdk, isConnected } = usePhantom();
|
|
336
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
337
|
+
if (!isClient || !sdk) {
|
|
338
|
+
return {
|
|
339
|
+
ethereum: {},
|
|
340
|
+
// This will be replaced when SDK is ready
|
|
341
|
+
isAvailable: false
|
|
342
|
+
};
|
|
343
|
+
}
|
|
313
344
|
return {
|
|
314
345
|
// Chain instance with connection enforcement for signing methods
|
|
315
346
|
ethereum: sdk.ethereum,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/react-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.8",
|
|
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.
|
|
29
|
+
"@phantom/browser-sdk": "^1.0.0-beta.8",
|
|
30
30
|
"@phantom/chain-interfaces": "^1.0.0-beta.6",
|
|
31
31
|
"@phantom/constants": "^1.0.0-beta.6"
|
|
32
32
|
},
|