@phantom/react-sdk 1.0.0-beta.7 → 1.0.0-beta.9
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 +35 -8
- package/dist/index.mjs +35 -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,18 @@ 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
|
+
}, [isClient, memoizedConfig]);
|
|
76
|
+
(0, import_react.useEffect)(() => {
|
|
77
|
+
if (!sdk)
|
|
78
|
+
return;
|
|
67
79
|
const handleConnectStart = () => {
|
|
68
80
|
setIsConnecting(true);
|
|
69
81
|
setConnectError(null);
|
|
@@ -110,12 +122,12 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
110
122
|
};
|
|
111
123
|
}, [sdk]);
|
|
112
124
|
(0, import_react.useEffect)(() => {
|
|
113
|
-
if (!
|
|
125
|
+
if (!debugConfig || !sdk)
|
|
114
126
|
return;
|
|
115
127
|
sdk.configureDebug(debugConfig);
|
|
116
128
|
}, [sdk, debugConfig]);
|
|
117
129
|
(0, import_react.useEffect)(() => {
|
|
118
|
-
if (!sdk)
|
|
130
|
+
if (!isClient || !sdk)
|
|
119
131
|
return;
|
|
120
132
|
const initialize = async () => {
|
|
121
133
|
try {
|
|
@@ -131,7 +143,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
131
143
|
}
|
|
132
144
|
};
|
|
133
145
|
initialize();
|
|
134
|
-
}, [sdk, memoizedConfig.autoConnect]);
|
|
146
|
+
}, [sdk, memoizedConfig.autoConnect, isClient]);
|
|
135
147
|
const value = (0, import_react.useMemo)(
|
|
136
148
|
() => ({
|
|
137
149
|
sdk,
|
|
@@ -141,9 +153,10 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
141
153
|
addresses,
|
|
142
154
|
walletId,
|
|
143
155
|
currentProviderType,
|
|
144
|
-
isPhantomAvailable
|
|
156
|
+
isPhantomAvailable,
|
|
157
|
+
isClient
|
|
145
158
|
}),
|
|
146
|
-
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable]
|
|
159
|
+
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable, isClient]
|
|
147
160
|
);
|
|
148
161
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
|
|
149
162
|
}
|
|
@@ -346,7 +359,14 @@ function useAutoConfirm() {
|
|
|
346
359
|
|
|
347
360
|
// src/hooks/useSolana.ts
|
|
348
361
|
function useSolana() {
|
|
349
|
-
const { sdk, isConnected } = usePhantom();
|
|
362
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
363
|
+
if (!isClient || !sdk) {
|
|
364
|
+
return {
|
|
365
|
+
solana: {},
|
|
366
|
+
// This will be replaced when SDK is ready
|
|
367
|
+
isAvailable: false
|
|
368
|
+
};
|
|
369
|
+
}
|
|
350
370
|
return {
|
|
351
371
|
// Chain instance with connection enforcement for signing methods
|
|
352
372
|
solana: sdk.solana,
|
|
@@ -357,7 +377,14 @@ function useSolana() {
|
|
|
357
377
|
|
|
358
378
|
// src/hooks/useEthereum.ts
|
|
359
379
|
function useEthereum() {
|
|
360
|
-
const { sdk, isConnected } = usePhantom();
|
|
380
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
381
|
+
if (!isClient || !sdk) {
|
|
382
|
+
return {
|
|
383
|
+
ethereum: {},
|
|
384
|
+
// This will be replaced when SDK is ready
|
|
385
|
+
isAvailable: false
|
|
386
|
+
};
|
|
387
|
+
}
|
|
361
388
|
return {
|
|
362
389
|
// Chain instance with connection enforcement for signing methods
|
|
363
390
|
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,18 @@ 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
|
+
}, [isClient, memoizedConfig]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!sdk)
|
|
30
|
+
return;
|
|
19
31
|
const handleConnectStart = () => {
|
|
20
32
|
setIsConnecting(true);
|
|
21
33
|
setConnectError(null);
|
|
@@ -62,12 +74,12 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
62
74
|
};
|
|
63
75
|
}, [sdk]);
|
|
64
76
|
useEffect(() => {
|
|
65
|
-
if (!
|
|
77
|
+
if (!debugConfig || !sdk)
|
|
66
78
|
return;
|
|
67
79
|
sdk.configureDebug(debugConfig);
|
|
68
80
|
}, [sdk, debugConfig]);
|
|
69
81
|
useEffect(() => {
|
|
70
|
-
if (!sdk)
|
|
82
|
+
if (!isClient || !sdk)
|
|
71
83
|
return;
|
|
72
84
|
const initialize = async () => {
|
|
73
85
|
try {
|
|
@@ -83,7 +95,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
83
95
|
}
|
|
84
96
|
};
|
|
85
97
|
initialize();
|
|
86
|
-
}, [sdk, memoizedConfig.autoConnect]);
|
|
98
|
+
}, [sdk, memoizedConfig.autoConnect, isClient]);
|
|
87
99
|
const value = useMemo(
|
|
88
100
|
() => ({
|
|
89
101
|
sdk,
|
|
@@ -93,9 +105,10 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
93
105
|
addresses,
|
|
94
106
|
walletId,
|
|
95
107
|
currentProviderType,
|
|
96
|
-
isPhantomAvailable
|
|
108
|
+
isPhantomAvailable,
|
|
109
|
+
isClient
|
|
97
110
|
}),
|
|
98
|
-
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable]
|
|
111
|
+
[sdk, isConnected, isConnecting, connectError, addresses, walletId, currentProviderType, isPhantomAvailable, isClient]
|
|
99
112
|
);
|
|
100
113
|
return /* @__PURE__ */ jsx(PhantomContext.Provider, { value, children });
|
|
101
114
|
}
|
|
@@ -298,7 +311,14 @@ function useAutoConfirm() {
|
|
|
298
311
|
|
|
299
312
|
// src/hooks/useSolana.ts
|
|
300
313
|
function useSolana() {
|
|
301
|
-
const { sdk, isConnected } = usePhantom();
|
|
314
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
315
|
+
if (!isClient || !sdk) {
|
|
316
|
+
return {
|
|
317
|
+
solana: {},
|
|
318
|
+
// This will be replaced when SDK is ready
|
|
319
|
+
isAvailable: false
|
|
320
|
+
};
|
|
321
|
+
}
|
|
302
322
|
return {
|
|
303
323
|
// Chain instance with connection enforcement for signing methods
|
|
304
324
|
solana: sdk.solana,
|
|
@@ -309,7 +329,14 @@ function useSolana() {
|
|
|
309
329
|
|
|
310
330
|
// src/hooks/useEthereum.ts
|
|
311
331
|
function useEthereum() {
|
|
312
|
-
const { sdk, isConnected } = usePhantom();
|
|
332
|
+
const { sdk, isConnected, isClient } = usePhantom();
|
|
333
|
+
if (!isClient || !sdk) {
|
|
334
|
+
return {
|
|
335
|
+
ethereum: {},
|
|
336
|
+
// This will be replaced when SDK is ready
|
|
337
|
+
isAvailable: false
|
|
338
|
+
};
|
|
339
|
+
}
|
|
313
340
|
return {
|
|
314
341
|
// Chain instance with connection enforcement for signing methods
|
|
315
342
|
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.9",
|
|
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.9",
|
|
30
30
|
"@phantom/chain-interfaces": "^1.0.0-beta.6",
|
|
31
31
|
"@phantom/constants": "^1.0.0-beta.6"
|
|
32
32
|
},
|