@phantom/react-sdk 0.3.3 → 0.3.4

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.js CHANGED
@@ -93,7 +93,7 @@ function PhantomProvider({ children, config }) {
93
93
  }
94
94
  }, [sdk]);
95
95
  (0, import_react.useEffect)(() => {
96
- const checkPhantomExtension = async () => {
96
+ const initialize = async () => {
97
97
  try {
98
98
  const available = await sdk.waitForPhantomExtension(1e3);
99
99
  setIsPhantomAvailable(available);
@@ -101,23 +101,32 @@ function PhantomProvider({ children, config }) {
101
101
  console.error("Error checking Phantom extension:", err);
102
102
  setIsPhantomAvailable(false);
103
103
  }
104
+ await updateConnectionState();
104
105
  };
105
- checkPhantomExtension();
106
- updateConnectionState();
106
+ initialize();
107
107
  }, [sdk, updateConnectionState]);
108
- (0, import_react.useEffect)(() => {
109
- updateConnectionState();
110
- }, [updateConnectionState]);
111
- const value = {
112
- sdk,
113
- isConnected,
114
- addresses,
115
- updateConnectionState,
116
- walletId,
117
- error,
118
- currentProviderType,
119
- isPhantomAvailable
120
- };
108
+ const value = (0, import_react.useMemo)(
109
+ () => ({
110
+ sdk,
111
+ isConnected,
112
+ addresses,
113
+ updateConnectionState,
114
+ walletId,
115
+ error,
116
+ currentProviderType,
117
+ isPhantomAvailable
118
+ }),
119
+ [
120
+ sdk,
121
+ isConnected,
122
+ addresses,
123
+ updateConnectionState,
124
+ walletId,
125
+ error,
126
+ currentProviderType,
127
+ isPhantomAvailable
128
+ ]
129
+ );
121
130
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
122
131
  }
123
132
  function usePhantom() {
@@ -131,19 +140,19 @@ function usePhantom() {
131
140
  // src/hooks/useConnect.ts
132
141
  var import_react2 = require("react");
133
142
  function useConnect() {
134
- const context = usePhantom();
143
+ const { sdk, updateConnectionState, currentProviderType, isPhantomAvailable } = usePhantom();
135
144
  const [isConnecting, setIsConnecting] = (0, import_react2.useState)(false);
136
145
  const [error, setError] = (0, import_react2.useState)(null);
137
146
  const connect = (0, import_react2.useCallback)(
138
147
  async (options) => {
139
- if (!context.sdk) {
148
+ if (!sdk) {
140
149
  throw new Error("SDK not initialized");
141
150
  }
142
151
  setIsConnecting(true);
143
152
  setError(null);
144
153
  try {
145
- const result = await context.sdk.connect(options);
146
- await context.updateConnectionState();
154
+ const result = await sdk.connect(options);
155
+ await updateConnectionState();
147
156
  return result;
148
157
  } catch (err) {
149
158
  console.error("Error connecting to Phantom:", err);
@@ -153,14 +162,14 @@ function useConnect() {
153
162
  setIsConnecting(false);
154
163
  }
155
164
  },
156
- [context]
165
+ [sdk, updateConnectionState]
157
166
  );
158
167
  return {
159
168
  connect,
160
169
  isConnecting,
161
170
  error,
162
- currentProviderType: context.currentProviderType,
163
- isPhantomAvailable: context.isPhantomAvailable
171
+ currentProviderType,
172
+ isPhantomAvailable
164
173
  };
165
174
  }
166
175
 
package/dist/index.mjs CHANGED
@@ -46,7 +46,7 @@ function PhantomProvider({ children, config }) {
46
46
  }
47
47
  }, [sdk]);
48
48
  useEffect(() => {
49
- const checkPhantomExtension = async () => {
49
+ const initialize = async () => {
50
50
  try {
51
51
  const available = await sdk.waitForPhantomExtension(1e3);
52
52
  setIsPhantomAvailable(available);
@@ -54,23 +54,32 @@ function PhantomProvider({ children, config }) {
54
54
  console.error("Error checking Phantom extension:", err);
55
55
  setIsPhantomAvailable(false);
56
56
  }
57
+ await updateConnectionState();
57
58
  };
58
- checkPhantomExtension();
59
- updateConnectionState();
59
+ initialize();
60
60
  }, [sdk, updateConnectionState]);
61
- useEffect(() => {
62
- updateConnectionState();
63
- }, [updateConnectionState]);
64
- const value = {
65
- sdk,
66
- isConnected,
67
- addresses,
68
- updateConnectionState,
69
- walletId,
70
- error,
71
- currentProviderType,
72
- isPhantomAvailable
73
- };
61
+ const value = useMemo(
62
+ () => ({
63
+ sdk,
64
+ isConnected,
65
+ addresses,
66
+ updateConnectionState,
67
+ walletId,
68
+ error,
69
+ currentProviderType,
70
+ isPhantomAvailable
71
+ }),
72
+ [
73
+ sdk,
74
+ isConnected,
75
+ addresses,
76
+ updateConnectionState,
77
+ walletId,
78
+ error,
79
+ currentProviderType,
80
+ isPhantomAvailable
81
+ ]
82
+ );
74
83
  return /* @__PURE__ */ jsx(PhantomContext.Provider, { value, children });
75
84
  }
76
85
  function usePhantom() {
@@ -84,19 +93,19 @@ function usePhantom() {
84
93
  // src/hooks/useConnect.ts
85
94
  import { useCallback as useCallback2, useState as useState2 } from "react";
86
95
  function useConnect() {
87
- const context = usePhantom();
96
+ const { sdk, updateConnectionState, currentProviderType, isPhantomAvailable } = usePhantom();
88
97
  const [isConnecting, setIsConnecting] = useState2(false);
89
98
  const [error, setError] = useState2(null);
90
99
  const connect = useCallback2(
91
100
  async (options) => {
92
- if (!context.sdk) {
101
+ if (!sdk) {
93
102
  throw new Error("SDK not initialized");
94
103
  }
95
104
  setIsConnecting(true);
96
105
  setError(null);
97
106
  try {
98
- const result = await context.sdk.connect(options);
99
- await context.updateConnectionState();
107
+ const result = await sdk.connect(options);
108
+ await updateConnectionState();
100
109
  return result;
101
110
  } catch (err) {
102
111
  console.error("Error connecting to Phantom:", err);
@@ -106,14 +115,14 @@ function useConnect() {
106
115
  setIsConnecting(false);
107
116
  }
108
117
  },
109
- [context]
118
+ [sdk, updateConnectionState]
110
119
  );
111
120
  return {
112
121
  connect,
113
122
  isConnecting,
114
123
  error,
115
- currentProviderType: context.currentProviderType,
116
- isPhantomAvailable: context.isPhantomAvailable
124
+ currentProviderType,
125
+ isPhantomAvailable
117
126
  };
118
127
  }
119
128
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/react-sdk",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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": "^0.3.3"
29
+ "@phantom/browser-sdk": "^0.3.4"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@testing-library/dom": "^10.4.0",