@phantom/react-native-sdk 1.0.0-beta.22 → 1.0.0-beta.25
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 +144 -13
- package/dist/index.d.ts +21 -7
- package/dist/index.js +439 -94
- package/dist/index.mjs +427 -85
- package/package.json +18 -13
package/dist/index.js
CHANGED
|
@@ -33,19 +33,424 @@ __export(src_exports, {
|
|
|
33
33
|
AddressType: () => import_client.AddressType,
|
|
34
34
|
NetworkId: () => import_constants3.NetworkId,
|
|
35
35
|
PhantomProvider: () => PhantomProvider,
|
|
36
|
+
darkTheme: () => import_wallet_sdk_ui5.darkTheme,
|
|
37
|
+
lightTheme: () => import_wallet_sdk_ui5.lightTheme,
|
|
36
38
|
useAccounts: () => useAccounts,
|
|
37
39
|
useConnect: () => useConnect,
|
|
38
40
|
useDisconnect: () => useDisconnect,
|
|
39
41
|
useEthereum: () => useEthereum,
|
|
42
|
+
useModal: () => useModal,
|
|
40
43
|
usePhantom: () => usePhantom,
|
|
41
44
|
useSolana: () => useSolana
|
|
42
45
|
});
|
|
43
46
|
module.exports = __toCommonJS(src_exports);
|
|
44
47
|
|
|
45
48
|
// src/PhantomProvider.tsx
|
|
46
|
-
var
|
|
49
|
+
var import_react8 = require("react");
|
|
47
50
|
var import_embedded_provider_core = require("@phantom/embedded-provider-core");
|
|
48
51
|
var import_constants2 = require("@phantom/constants");
|
|
52
|
+
var import_wallet_sdk_ui4 = require("@phantom/wallet-sdk-ui");
|
|
53
|
+
|
|
54
|
+
// src/ModalProvider.tsx
|
|
55
|
+
var import_react7 = require("react");
|
|
56
|
+
|
|
57
|
+
// src/ModalContext.ts
|
|
58
|
+
var import_react = require("react");
|
|
59
|
+
var ModalContext = (0, import_react.createContext)(void 0);
|
|
60
|
+
function useModal() {
|
|
61
|
+
const context = (0, import_react.useContext)(ModalContext);
|
|
62
|
+
if (!context) {
|
|
63
|
+
throw new Error("useModal must be used within a ModalProvider");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
open: context.openModal,
|
|
67
|
+
close: context.closeModal,
|
|
68
|
+
isOpened: context.isModalOpen
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/components/Modal.tsx
|
|
73
|
+
var import_react_native = require("react-native");
|
|
74
|
+
var import_wallet_sdk_ui = require("@phantom/wallet-sdk-ui");
|
|
75
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
76
|
+
function Modal({ isVisible, onClose, children }) {
|
|
77
|
+
const theme = (0, import_wallet_sdk_ui.useTheme)();
|
|
78
|
+
const styles = import_react_native.StyleSheet.create({
|
|
79
|
+
bottomSheet: {
|
|
80
|
+
backgroundColor: theme.background,
|
|
81
|
+
borderTopLeftRadius: 32,
|
|
82
|
+
borderTopRightRadius: 32,
|
|
83
|
+
bottom: 0,
|
|
84
|
+
left: 0,
|
|
85
|
+
paddingBottom: 20,
|
|
86
|
+
position: "absolute",
|
|
87
|
+
right: 0
|
|
88
|
+
},
|
|
89
|
+
handle: {
|
|
90
|
+
alignSelf: "center",
|
|
91
|
+
backgroundColor: theme.secondary,
|
|
92
|
+
borderRadius: 2.5,
|
|
93
|
+
height: 5,
|
|
94
|
+
marginTop: 12,
|
|
95
|
+
opacity: 0.3,
|
|
96
|
+
width: 40
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Modal, { visible: isVisible, transparent: true, animationType: "slide", onRequestClose: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.SafeAreaView, { style: styles.bottomSheet, children: [
|
|
100
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: styles.handle }),
|
|
101
|
+
children
|
|
102
|
+
] }) });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/PhantomContext.tsx
|
|
106
|
+
var import_react2 = require("react");
|
|
107
|
+
var PhantomContext = (0, import_react2.createContext)(void 0);
|
|
108
|
+
function usePhantom() {
|
|
109
|
+
const context = (0, import_react2.useContext)(PhantomContext);
|
|
110
|
+
if (context === void 0) {
|
|
111
|
+
throw new Error("usePhantom must be used within a PhantomProvider");
|
|
112
|
+
}
|
|
113
|
+
return context;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/components/ConnectModalContent.tsx
|
|
117
|
+
var import_react4 = require("react");
|
|
118
|
+
var import_react_native2 = require("react-native");
|
|
119
|
+
var import_wallet_sdk_ui2 = require("@phantom/wallet-sdk-ui");
|
|
120
|
+
|
|
121
|
+
// src/hooks/useConnect.ts
|
|
122
|
+
var import_react3 = require("react");
|
|
123
|
+
function useConnect() {
|
|
124
|
+
const { sdk, isConnecting, connectError, setWalletId } = usePhantom();
|
|
125
|
+
const connect = (0, import_react3.useCallback)(
|
|
126
|
+
async (options) => {
|
|
127
|
+
if (!sdk) {
|
|
128
|
+
throw new Error("SDK not initialized");
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const result = await sdk.connect(options);
|
|
132
|
+
if (result.status === "completed" && result.walletId) {
|
|
133
|
+
setWalletId(result.walletId);
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
const error = err;
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
[sdk, setWalletId]
|
|
142
|
+
);
|
|
143
|
+
return {
|
|
144
|
+
connect,
|
|
145
|
+
isConnecting,
|
|
146
|
+
error: connectError
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/components/ConnectModalContent.tsx
|
|
151
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
152
|
+
function ConnectModalContent({ appIcon, onClose }) {
|
|
153
|
+
const theme = (0, import_wallet_sdk_ui2.useTheme)();
|
|
154
|
+
const { isConnecting: contextIsConnecting, allowedProviders } = usePhantom();
|
|
155
|
+
const { connect } = useConnect();
|
|
156
|
+
const [isConnecting, setIsConnecting] = (0, import_react4.useState)(false);
|
|
157
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
158
|
+
const [providerType, setProviderType] = (0, import_react4.useState)(null);
|
|
159
|
+
const isLoading = contextIsConnecting || isConnecting;
|
|
160
|
+
const errorBackgroundColor = (0, import_wallet_sdk_ui2.hexToRgba)(theme.error, 0.1);
|
|
161
|
+
const errorBorderColor = (0, import_wallet_sdk_ui2.hexToRgba)(theme.error, 0.3);
|
|
162
|
+
const errorTextColor = theme.error;
|
|
163
|
+
const connectWithAuthProvider = (0, import_react4.useCallback)(
|
|
164
|
+
async (provider) => {
|
|
165
|
+
try {
|
|
166
|
+
setIsConnecting(true);
|
|
167
|
+
setError(null);
|
|
168
|
+
setProviderType(provider);
|
|
169
|
+
await connect({ provider });
|
|
170
|
+
onClose();
|
|
171
|
+
} catch (err) {
|
|
172
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
173
|
+
setError(error2);
|
|
174
|
+
} finally {
|
|
175
|
+
setIsConnecting(false);
|
|
176
|
+
setProviderType(null);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
[connect, onClose]
|
|
180
|
+
);
|
|
181
|
+
const styles = import_react_native2.StyleSheet.create({
|
|
182
|
+
appIcon: {
|
|
183
|
+
borderRadius: 28,
|
|
184
|
+
height: 56,
|
|
185
|
+
marginBottom: 12,
|
|
186
|
+
width: 56
|
|
187
|
+
},
|
|
188
|
+
buttonContainer: {
|
|
189
|
+
alignItems: "center",
|
|
190
|
+
flexDirection: "column",
|
|
191
|
+
gap: 12,
|
|
192
|
+
paddingHorizontal: 32,
|
|
193
|
+
width: "100%"
|
|
194
|
+
},
|
|
195
|
+
buttonContent: {
|
|
196
|
+
alignItems: "center",
|
|
197
|
+
flexDirection: "row",
|
|
198
|
+
justifyContent: "space-between",
|
|
199
|
+
width: "100%"
|
|
200
|
+
},
|
|
201
|
+
buttonContentLeft: {
|
|
202
|
+
alignItems: "center",
|
|
203
|
+
flexDirection: "row",
|
|
204
|
+
gap: 8
|
|
205
|
+
},
|
|
206
|
+
container: {
|
|
207
|
+
alignItems: "center",
|
|
208
|
+
flexDirection: "column",
|
|
209
|
+
gap: 12,
|
|
210
|
+
paddingBottom: 24,
|
|
211
|
+
width: "100%"
|
|
212
|
+
},
|
|
213
|
+
errorContainer: {
|
|
214
|
+
backgroundColor: errorBackgroundColor,
|
|
215
|
+
borderColor: errorBorderColor,
|
|
216
|
+
borderRadius: parseInt(theme.borderRadius),
|
|
217
|
+
borderWidth: 1,
|
|
218
|
+
padding: 12,
|
|
219
|
+
width: "100%"
|
|
220
|
+
},
|
|
221
|
+
errorText: {
|
|
222
|
+
color: errorTextColor,
|
|
223
|
+
fontSize: 14
|
|
224
|
+
},
|
|
225
|
+
footer: {
|
|
226
|
+
alignItems: "center",
|
|
227
|
+
borderColor: theme.aux,
|
|
228
|
+
borderTopWidth: 1,
|
|
229
|
+
flexDirection: "row",
|
|
230
|
+
gap: 4,
|
|
231
|
+
justifyContent: "center",
|
|
232
|
+
marginTop: 24,
|
|
233
|
+
padding: 16,
|
|
234
|
+
width: "100%"
|
|
235
|
+
},
|
|
236
|
+
loadingContainer: {
|
|
237
|
+
alignItems: "center",
|
|
238
|
+
flexDirection: "column",
|
|
239
|
+
gap: 12,
|
|
240
|
+
justifyContent: "center",
|
|
241
|
+
padding: 24
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.container, children: [
|
|
245
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.ModalHeader, { title: "Login or Sign Up", onClose }),
|
|
246
|
+
appIcon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Image, { testID: "app-icon", source: { uri: appIcon }, style: styles.appIcon }),
|
|
247
|
+
isLoading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.loadingContainer, children: [
|
|
248
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.ActivityIndicator, { testID: "activity-indicator", size: "large", color: theme.brand }),
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Loading..." })
|
|
250
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContainer, children: [
|
|
251
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles.errorContainer, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { style: styles.errorText, children: error.message }) }),
|
|
252
|
+
allowedProviders.includes("google") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
253
|
+
import_wallet_sdk_ui2.Button,
|
|
254
|
+
{
|
|
255
|
+
onClick: () => connectWithAuthProvider("google"),
|
|
256
|
+
disabled: isConnecting,
|
|
257
|
+
isLoading: isConnecting && providerType === "google",
|
|
258
|
+
fullWidth: true,
|
|
259
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContent, children: [
|
|
260
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContentLeft, children: [
|
|
261
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "google", size: 20, color: theme.text }),
|
|
262
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with Google" })
|
|
263
|
+
] }),
|
|
264
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
|
|
265
|
+
] })
|
|
266
|
+
}
|
|
267
|
+
),
|
|
268
|
+
allowedProviders.includes("apple") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
269
|
+
import_wallet_sdk_ui2.Button,
|
|
270
|
+
{
|
|
271
|
+
onClick: () => connectWithAuthProvider("apple"),
|
|
272
|
+
disabled: isConnecting,
|
|
273
|
+
isLoading: isConnecting && providerType === "apple",
|
|
274
|
+
fullWidth: true,
|
|
275
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContent, children: [
|
|
276
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContentLeft, children: [
|
|
277
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "apple", size: 20, color: theme.text }),
|
|
278
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with Apple" })
|
|
279
|
+
] }),
|
|
280
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
|
|
281
|
+
] })
|
|
282
|
+
}
|
|
283
|
+
),
|
|
284
|
+
allowedProviders.includes("x") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
285
|
+
import_wallet_sdk_ui2.Button,
|
|
286
|
+
{
|
|
287
|
+
onClick: () => connectWithAuthProvider("x"),
|
|
288
|
+
disabled: isConnecting,
|
|
289
|
+
isLoading: isConnecting && providerType === "x",
|
|
290
|
+
fullWidth: true,
|
|
291
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContent, children: [
|
|
292
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContentLeft, children: [
|
|
293
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "x", size: 20, color: theme.text }),
|
|
294
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with X" })
|
|
295
|
+
] }),
|
|
296
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
|
|
297
|
+
] })
|
|
298
|
+
}
|
|
299
|
+
),
|
|
300
|
+
allowedProviders.includes("tiktok") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
301
|
+
import_wallet_sdk_ui2.Button,
|
|
302
|
+
{
|
|
303
|
+
onClick: () => connectWithAuthProvider("tiktok"),
|
|
304
|
+
disabled: isConnecting,
|
|
305
|
+
isLoading: isConnecting && providerType === "tiktok",
|
|
306
|
+
fullWidth: true,
|
|
307
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContent, children: [
|
|
308
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.buttonContentLeft, children: [
|
|
309
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "tiktok", size: 20, color: theme.text }),
|
|
310
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with TikTok" })
|
|
311
|
+
] }),
|
|
312
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
|
|
313
|
+
] })
|
|
314
|
+
}
|
|
315
|
+
)
|
|
316
|
+
] }),
|
|
317
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.footer, children: [
|
|
318
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Powered by" }),
|
|
319
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "phantom", size: 16, color: theme.secondary }),
|
|
320
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Phantom" })
|
|
321
|
+
] })
|
|
322
|
+
] });
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// src/components/ConnectedModalContent.tsx
|
|
326
|
+
var import_react6 = require("react");
|
|
327
|
+
var import_react_native3 = require("react-native");
|
|
328
|
+
var import_wallet_sdk_ui3 = require("@phantom/wallet-sdk-ui");
|
|
329
|
+
|
|
330
|
+
// src/hooks/useDisconnect.ts
|
|
331
|
+
var import_react5 = require("react");
|
|
332
|
+
function useDisconnect() {
|
|
333
|
+
const { sdk } = usePhantom();
|
|
334
|
+
const [isDisconnecting, setIsDisconnecting] = (0, import_react5.useState)(false);
|
|
335
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
336
|
+
const disconnect = (0, import_react5.useCallback)(async () => {
|
|
337
|
+
if (!sdk) {
|
|
338
|
+
throw new Error("SDK not initialized");
|
|
339
|
+
}
|
|
340
|
+
setIsDisconnecting(true);
|
|
341
|
+
setError(null);
|
|
342
|
+
try {
|
|
343
|
+
await sdk.disconnect();
|
|
344
|
+
} catch (err) {
|
|
345
|
+
const error2 = err;
|
|
346
|
+
setError(error2);
|
|
347
|
+
throw error2;
|
|
348
|
+
} finally {
|
|
349
|
+
setIsDisconnecting(false);
|
|
350
|
+
}
|
|
351
|
+
}, [sdk]);
|
|
352
|
+
return {
|
|
353
|
+
disconnect,
|
|
354
|
+
isDisconnecting,
|
|
355
|
+
error
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// src/components/ConnectedModalContent.tsx
|
|
360
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
361
|
+
function ConnectedModalContent({ onClose }) {
|
|
362
|
+
const theme = (0, import_wallet_sdk_ui3.useTheme)();
|
|
363
|
+
const { addresses } = usePhantom();
|
|
364
|
+
const { disconnect } = useDisconnect();
|
|
365
|
+
const [isDisconnecting, setIsDisconnecting] = (0, import_react6.useState)(false);
|
|
366
|
+
const [disconnectError, setDisconnectError] = (0, import_react6.useState)(null);
|
|
367
|
+
const errorBackgroundColor = (0, import_wallet_sdk_ui3.hexToRgba)(theme.error, 0.1);
|
|
368
|
+
const errorBorderColor = (0, import_wallet_sdk_ui3.hexToRgba)(theme.error, 0.3);
|
|
369
|
+
(0, import_react6.useEffect)(() => {
|
|
370
|
+
setDisconnectError(null);
|
|
371
|
+
}, []);
|
|
372
|
+
const handleDisconnect = async () => {
|
|
373
|
+
try {
|
|
374
|
+
setIsDisconnecting(true);
|
|
375
|
+
setDisconnectError(null);
|
|
376
|
+
await disconnect();
|
|
377
|
+
onClose();
|
|
378
|
+
} catch (err) {
|
|
379
|
+
const error = err instanceof Error ? err : new Error(String(err));
|
|
380
|
+
setDisconnectError(error);
|
|
381
|
+
} finally {
|
|
382
|
+
setIsDisconnecting(false);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const styles = import_react_native3.StyleSheet.create({
|
|
386
|
+
accountItem: {
|
|
387
|
+
flexDirection: "column",
|
|
388
|
+
gap: 8,
|
|
389
|
+
width: "100%"
|
|
390
|
+
},
|
|
391
|
+
accountList: {
|
|
392
|
+
flexDirection: "column",
|
|
393
|
+
gap: 16,
|
|
394
|
+
width: "100%"
|
|
395
|
+
},
|
|
396
|
+
accountTypeText: {
|
|
397
|
+
textTransform: "uppercase"
|
|
398
|
+
},
|
|
399
|
+
addressText: {
|
|
400
|
+
fontFamily: "monospace"
|
|
401
|
+
},
|
|
402
|
+
container: {
|
|
403
|
+
alignItems: "center",
|
|
404
|
+
flexDirection: "column",
|
|
405
|
+
gap: 24,
|
|
406
|
+
paddingBottom: 24,
|
|
407
|
+
paddingHorizontal: 32,
|
|
408
|
+
width: "100%"
|
|
409
|
+
},
|
|
410
|
+
errorContainer: {
|
|
411
|
+
backgroundColor: errorBackgroundColor,
|
|
412
|
+
borderColor: errorBorderColor,
|
|
413
|
+
borderRadius: theme.borderRadius,
|
|
414
|
+
borderWidth: 1,
|
|
415
|
+
padding: 12,
|
|
416
|
+
width: "100%"
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native3.View, { style: styles.container, children: [
|
|
420
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.ModalHeader, { title: "Wallet", onClose }),
|
|
421
|
+
addresses && addresses.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style: styles.accountList, children: addresses.map((account, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react_native3.View, { style: styles.accountItem, children: [
|
|
422
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "label", color: theme.secondary, style: styles.accountTypeText, children: account.addressType }),
|
|
423
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "caption", style: styles.addressText, children: account.address })
|
|
424
|
+
] }, index)) }),
|
|
425
|
+
disconnectError && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native3.View, { style: styles.errorContainer, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "caption", color: theme.error, children: "Failed to disconnect" }) }),
|
|
426
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Button, { onClick: handleDisconnect, disabled: isDisconnecting, isLoading: isDisconnecting, fullWidth: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "captionBold", children: isDisconnecting ? "Disconnecting..." : "Disconnect" }) })
|
|
427
|
+
] });
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// src/ModalProvider.tsx
|
|
431
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
432
|
+
function ModalProvider({ children, appIcon, appName }) {
|
|
433
|
+
const { isConnected } = usePhantom();
|
|
434
|
+
const [isModalOpen, setIsModalOpen] = (0, import_react7.useState)(false);
|
|
435
|
+
const openModal = (0, import_react7.useCallback)(() => {
|
|
436
|
+
setIsModalOpen(true);
|
|
437
|
+
}, []);
|
|
438
|
+
const closeModal = (0, import_react7.useCallback)(() => {
|
|
439
|
+
setIsModalOpen(false);
|
|
440
|
+
}, []);
|
|
441
|
+
const modalContextValue = (0, import_react7.useMemo)(
|
|
442
|
+
() => ({
|
|
443
|
+
isModalOpen,
|
|
444
|
+
openModal,
|
|
445
|
+
closeModal
|
|
446
|
+
}),
|
|
447
|
+
[isModalOpen, openModal, closeModal]
|
|
448
|
+
);
|
|
449
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ModalContext.Provider, { value: modalContextValue, children: [
|
|
450
|
+
children,
|
|
451
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Modal, { isVisible: isModalOpen, onClose: closeModal, appIcon, appName, isMobile: true, children: isConnected ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConnectedModalContent, { onClose: closeModal }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConnectModalContent, { appIcon, appName, onClose: closeModal }) })
|
|
452
|
+
] });
|
|
453
|
+
}
|
|
49
454
|
|
|
50
455
|
// src/providers/embedded/storage.ts
|
|
51
456
|
var SecureStore = __toESM(require("expo-secure-store"));
|
|
@@ -128,7 +533,7 @@ var ExpoSecureStorage = class {
|
|
|
128
533
|
|
|
129
534
|
// src/providers/embedded/auth.ts
|
|
130
535
|
var WebBrowser = __toESM(require("expo-web-browser"));
|
|
131
|
-
var
|
|
536
|
+
var import_react_native4 = require("react-native");
|
|
132
537
|
var import_constants = require("@phantom/constants");
|
|
133
538
|
var ExpoAuthProvider = class {
|
|
134
539
|
async authenticate(options) {
|
|
@@ -153,9 +558,9 @@ var ExpoAuthProvider = class {
|
|
|
153
558
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
154
559
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
155
560
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
156
|
-
sdk_version: "1.0.0-beta.
|
|
561
|
+
sdk_version: "1.0.0-beta.25",
|
|
157
562
|
sdk_type: "react-native",
|
|
158
|
-
platform:
|
|
563
|
+
platform: import_react_native4.Platform.OS
|
|
159
564
|
});
|
|
160
565
|
if (provider) {
|
|
161
566
|
console.log("[ExpoAuthProvider] Provider specified, will skip selection", { provider });
|
|
@@ -229,7 +634,7 @@ var ExpoAuthProvider = class {
|
|
|
229
634
|
};
|
|
230
635
|
|
|
231
636
|
// src/providers/embedded/url-params.ts
|
|
232
|
-
var
|
|
637
|
+
var import_react_native5 = require("react-native");
|
|
233
638
|
var ExpoURLParamsAccessor = class {
|
|
234
639
|
constructor() {
|
|
235
640
|
this.listeners = /* @__PURE__ */ new Set();
|
|
@@ -241,7 +646,7 @@ var ExpoURLParamsAccessor = class {
|
|
|
241
646
|
}
|
|
242
647
|
async getInitialParams() {
|
|
243
648
|
try {
|
|
244
|
-
const url = await
|
|
649
|
+
const url = await import_react_native5.Linking.getInitialURL();
|
|
245
650
|
if (!url) {
|
|
246
651
|
return null;
|
|
247
652
|
}
|
|
@@ -257,7 +662,7 @@ var ExpoURLParamsAccessor = class {
|
|
|
257
662
|
if (this.subscription) {
|
|
258
663
|
return;
|
|
259
664
|
}
|
|
260
|
-
this.subscription =
|
|
665
|
+
this.subscription = import_react_native5.Linking.addEventListener("url", ({ url }) => {
|
|
261
666
|
const params = this.parseURLParams(url);
|
|
262
667
|
if (params && Object.keys(params).length > 0) {
|
|
263
668
|
this.currentParams = { ...this.currentParams, ...params };
|
|
@@ -512,17 +917,16 @@ var ReactNativePhantomAppProvider = class {
|
|
|
512
917
|
};
|
|
513
918
|
|
|
514
919
|
// src/PhantomProvider.tsx
|
|
515
|
-
var
|
|
516
|
-
var
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
const [
|
|
520
|
-
const [
|
|
521
|
-
const [
|
|
522
|
-
const [
|
|
523
|
-
const [
|
|
524
|
-
const
|
|
525
|
-
const memoizedConfig = (0, import_react.useMemo)(() => {
|
|
920
|
+
var import_react_native6 = require("react-native");
|
|
921
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
922
|
+
function PhantomProvider({ children, config, debugConfig, theme, appIcon, appName }) {
|
|
923
|
+
const [isConnected, setIsConnected] = (0, import_react8.useState)(false);
|
|
924
|
+
const [isConnecting, setIsConnecting] = (0, import_react8.useState)(false);
|
|
925
|
+
const [connectError, setConnectError] = (0, import_react8.useState)(null);
|
|
926
|
+
const [addresses, setAddresses] = (0, import_react8.useState)([]);
|
|
927
|
+
const [walletId, setWalletId] = (0, import_react8.useState)(null);
|
|
928
|
+
const [user, setUser] = (0, import_react8.useState)(null);
|
|
929
|
+
const memoizedConfig = (0, import_react8.useMemo)(() => {
|
|
526
930
|
const redirectUrl = config.authOptions?.redirectUrl || `${config.scheme}://phantom-auth-callback`;
|
|
527
931
|
return {
|
|
528
932
|
...config,
|
|
@@ -535,7 +939,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
535
939
|
}
|
|
536
940
|
};
|
|
537
941
|
}, [config]);
|
|
538
|
-
const sdk = (0,
|
|
942
|
+
const sdk = (0, import_react8.useMemo)(() => {
|
|
539
943
|
const storage = new ExpoSecureStorage();
|
|
540
944
|
const authProvider = new ExpoAuthProvider();
|
|
541
945
|
const urlParamsAccessor = new ExpoURLParamsAccessor();
|
|
@@ -544,7 +948,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
544
948
|
keyPrefix: `phantom-rn-${memoizedConfig.appId}`,
|
|
545
949
|
appId: memoizedConfig.appId
|
|
546
950
|
});
|
|
547
|
-
const platformName = `${
|
|
951
|
+
const platformName = `${import_react_native6.Platform.OS}-${import_react_native6.Platform.Version}`;
|
|
548
952
|
const platform = {
|
|
549
953
|
storage,
|
|
550
954
|
authProvider,
|
|
@@ -554,17 +958,17 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
554
958
|
name: platformName,
|
|
555
959
|
analyticsHeaders: {
|
|
556
960
|
[import_constants2.ANALYTICS_HEADERS.SDK_TYPE]: "react-native",
|
|
557
|
-
[import_constants2.ANALYTICS_HEADERS.PLATFORM]:
|
|
558
|
-
[import_constants2.ANALYTICS_HEADERS.PLATFORM_VERSION]: `${
|
|
961
|
+
[import_constants2.ANALYTICS_HEADERS.PLATFORM]: import_react_native6.Platform.OS,
|
|
962
|
+
[import_constants2.ANALYTICS_HEADERS.PLATFORM_VERSION]: `${import_react_native6.Platform.Version}`,
|
|
559
963
|
[import_constants2.ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
560
964
|
[import_constants2.ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
561
|
-
[import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.
|
|
965
|
+
[import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.25"
|
|
562
966
|
// Replaced at build time
|
|
563
967
|
}
|
|
564
968
|
};
|
|
565
969
|
return new import_embedded_provider_core.EmbeddedProvider(memoizedConfig, platform, logger);
|
|
566
970
|
}, [memoizedConfig, debugConfig, config.appId, config.embeddedWalletType]);
|
|
567
|
-
(0,
|
|
971
|
+
(0, import_react8.useEffect)(() => {
|
|
568
972
|
const handleConnectStart = () => {
|
|
569
973
|
setIsConnecting(true);
|
|
570
974
|
setConnectError(null);
|
|
@@ -609,11 +1013,11 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
609
1013
|
sdk.off("disconnect", handleDisconnect);
|
|
610
1014
|
};
|
|
611
1015
|
}, [sdk]);
|
|
612
|
-
(0,
|
|
1016
|
+
(0, import_react8.useEffect)(() => {
|
|
613
1017
|
sdk.autoConnect().catch(() => {
|
|
614
1018
|
});
|
|
615
1019
|
}, [sdk]);
|
|
616
|
-
const value = (0,
|
|
1020
|
+
const value = (0, import_react8.useMemo)(
|
|
617
1021
|
() => ({
|
|
618
1022
|
sdk,
|
|
619
1023
|
isConnected,
|
|
@@ -622,76 +1026,13 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
622
1026
|
addresses,
|
|
623
1027
|
walletId,
|
|
624
1028
|
setWalletId,
|
|
625
|
-
user
|
|
1029
|
+
user,
|
|
1030
|
+
allowedProviders: config.providers
|
|
626
1031
|
}),
|
|
627
|
-
[sdk, isConnected, isConnecting, connectError, addresses, walletId, setWalletId, user]
|
|
628
|
-
);
|
|
629
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
|
|
630
|
-
}
|
|
631
|
-
function usePhantom() {
|
|
632
|
-
const context = (0, import_react.useContext)(PhantomContext);
|
|
633
|
-
if (context === void 0) {
|
|
634
|
-
throw new Error("usePhantom must be used within a PhantomProvider");
|
|
635
|
-
}
|
|
636
|
-
return context;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// src/hooks/useConnect.ts
|
|
640
|
-
var import_react2 = require("react");
|
|
641
|
-
function useConnect() {
|
|
642
|
-
const { sdk, isConnecting, connectError, setWalletId } = usePhantom();
|
|
643
|
-
const connect = (0, import_react2.useCallback)(
|
|
644
|
-
async (options) => {
|
|
645
|
-
if (!sdk) {
|
|
646
|
-
throw new Error("SDK not initialized");
|
|
647
|
-
}
|
|
648
|
-
try {
|
|
649
|
-
const result = await sdk.connect(options);
|
|
650
|
-
if (result.status === "completed" && result.walletId) {
|
|
651
|
-
setWalletId(result.walletId);
|
|
652
|
-
}
|
|
653
|
-
return result;
|
|
654
|
-
} catch (err) {
|
|
655
|
-
const error = err;
|
|
656
|
-
throw error;
|
|
657
|
-
}
|
|
658
|
-
},
|
|
659
|
-
[sdk, setWalletId]
|
|
1032
|
+
[sdk, isConnected, isConnecting, connectError, addresses, walletId, setWalletId, user, config.providers]
|
|
660
1033
|
);
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
isConnecting,
|
|
664
|
-
error: connectError
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// src/hooks/useDisconnect.ts
|
|
669
|
-
var import_react3 = require("react");
|
|
670
|
-
function useDisconnect() {
|
|
671
|
-
const { sdk } = usePhantom();
|
|
672
|
-
const [isDisconnecting, setIsDisconnecting] = (0, import_react3.useState)(false);
|
|
673
|
-
const [error, setError] = (0, import_react3.useState)(null);
|
|
674
|
-
const disconnect = (0, import_react3.useCallback)(async () => {
|
|
675
|
-
if (!sdk) {
|
|
676
|
-
throw new Error("SDK not initialized");
|
|
677
|
-
}
|
|
678
|
-
setIsDisconnecting(true);
|
|
679
|
-
setError(null);
|
|
680
|
-
try {
|
|
681
|
-
await sdk.disconnect();
|
|
682
|
-
} catch (err) {
|
|
683
|
-
const error2 = err;
|
|
684
|
-
setError(error2);
|
|
685
|
-
throw error2;
|
|
686
|
-
} finally {
|
|
687
|
-
setIsDisconnecting(false);
|
|
688
|
-
}
|
|
689
|
-
}, [sdk]);
|
|
690
|
-
return {
|
|
691
|
-
disconnect,
|
|
692
|
-
isDisconnecting,
|
|
693
|
-
error
|
|
694
|
-
};
|
|
1034
|
+
const resolvedTheme = theme || import_wallet_sdk_ui4.darkTheme;
|
|
1035
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_wallet_sdk_ui4.ThemeProvider, { theme: resolvedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PhantomContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ModalProvider, { appIcon, appName, children }) }) });
|
|
695
1036
|
}
|
|
696
1037
|
|
|
697
1038
|
// src/hooks/useAccounts.ts
|
|
@@ -729,15 +1070,19 @@ function useEthereum() {
|
|
|
729
1070
|
// src/index.ts
|
|
730
1071
|
var import_client = require("@phantom/client");
|
|
731
1072
|
var import_constants3 = require("@phantom/constants");
|
|
1073
|
+
var import_wallet_sdk_ui5 = require("@phantom/wallet-sdk-ui");
|
|
732
1074
|
// Annotate the CommonJS export names for ESM import in node:
|
|
733
1075
|
0 && (module.exports = {
|
|
734
1076
|
AddressType,
|
|
735
1077
|
NetworkId,
|
|
736
1078
|
PhantomProvider,
|
|
1079
|
+
darkTheme,
|
|
1080
|
+
lightTheme,
|
|
737
1081
|
useAccounts,
|
|
738
1082
|
useConnect,
|
|
739
1083
|
useDisconnect,
|
|
740
1084
|
useEthereum,
|
|
1085
|
+
useModal,
|
|
741
1086
|
usePhantom,
|
|
742
1087
|
useSolana
|
|
743
1088
|
});
|