@phantom/react-native-sdk 1.0.0-beta.21 → 1.0.0-beta.24
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 +178 -27
- package/dist/index.d.ts +23 -13
- package/dist/index.js +444 -102
- package/dist/index.mjs +438 -94
- 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.24",
|
|
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 });
|
|
@@ -185,7 +590,6 @@ var ExpoAuthProvider = class {
|
|
|
185
590
|
const url = new URL(result.url);
|
|
186
591
|
const walletId = url.searchParams.get("wallet_id");
|
|
187
592
|
const organizationId = url.searchParams.get("organization_id");
|
|
188
|
-
const provider2 = url.searchParams.get("provider");
|
|
189
593
|
const accountDerivationIndex = url.searchParams.get("selected_account_index");
|
|
190
594
|
const expiresInMs = url.searchParams.get("expires_in_ms");
|
|
191
595
|
const authUserId = url.searchParams.get("auth_user_id");
|
|
@@ -199,7 +603,7 @@ var ExpoAuthProvider = class {
|
|
|
199
603
|
console.log("[ExpoAuthProvider] Auth redirect parameters", {
|
|
200
604
|
walletId,
|
|
201
605
|
organizationId,
|
|
202
|
-
provider
|
|
606
|
+
provider,
|
|
203
607
|
accountDerivationIndex,
|
|
204
608
|
expiresInMs,
|
|
205
609
|
authUserId
|
|
@@ -207,7 +611,7 @@ var ExpoAuthProvider = class {
|
|
|
207
611
|
return {
|
|
208
612
|
walletId,
|
|
209
613
|
organizationId,
|
|
210
|
-
provider:
|
|
614
|
+
provider: provider || void 0,
|
|
211
615
|
accountDerivationIndex: accountDerivationIndex ? parseInt(accountDerivationIndex) : 0,
|
|
212
616
|
expiresInMs: expiresInMs ? parseInt(expiresInMs) : 0,
|
|
213
617
|
authUserId: authUserId || void 0
|
|
@@ -230,7 +634,7 @@ var ExpoAuthProvider = class {
|
|
|
230
634
|
};
|
|
231
635
|
|
|
232
636
|
// src/providers/embedded/url-params.ts
|
|
233
|
-
var
|
|
637
|
+
var import_react_native5 = require("react-native");
|
|
234
638
|
var ExpoURLParamsAccessor = class {
|
|
235
639
|
constructor() {
|
|
236
640
|
this.listeners = /* @__PURE__ */ new Set();
|
|
@@ -242,7 +646,7 @@ var ExpoURLParamsAccessor = class {
|
|
|
242
646
|
}
|
|
243
647
|
async getInitialParams() {
|
|
244
648
|
try {
|
|
245
|
-
const url = await
|
|
649
|
+
const url = await import_react_native5.Linking.getInitialURL();
|
|
246
650
|
if (!url) {
|
|
247
651
|
return null;
|
|
248
652
|
}
|
|
@@ -258,7 +662,7 @@ var ExpoURLParamsAccessor = class {
|
|
|
258
662
|
if (this.subscription) {
|
|
259
663
|
return;
|
|
260
664
|
}
|
|
261
|
-
this.subscription =
|
|
665
|
+
this.subscription = import_react_native5.Linking.addEventListener("url", ({ url }) => {
|
|
262
666
|
const params = this.parseURLParams(url);
|
|
263
667
|
if (params && Object.keys(params).length > 0) {
|
|
264
668
|
this.currentParams = { ...this.currentParams, ...params };
|
|
@@ -513,17 +917,16 @@ var ReactNativePhantomAppProvider = class {
|
|
|
513
917
|
};
|
|
514
918
|
|
|
515
919
|
// src/PhantomProvider.tsx
|
|
516
|
-
var
|
|
517
|
-
var
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
const [
|
|
521
|
-
const [
|
|
522
|
-
const [
|
|
523
|
-
const [
|
|
524
|
-
const [
|
|
525
|
-
const
|
|
526
|
-
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)(() => {
|
|
527
930
|
const redirectUrl = config.authOptions?.redirectUrl || `${config.scheme}://phantom-auth-callback`;
|
|
528
931
|
return {
|
|
529
932
|
...config,
|
|
@@ -536,7 +939,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
536
939
|
}
|
|
537
940
|
};
|
|
538
941
|
}, [config]);
|
|
539
|
-
const sdk = (0,
|
|
942
|
+
const sdk = (0, import_react8.useMemo)(() => {
|
|
540
943
|
const storage = new ExpoSecureStorage();
|
|
541
944
|
const authProvider = new ExpoAuthProvider();
|
|
542
945
|
const urlParamsAccessor = new ExpoURLParamsAccessor();
|
|
@@ -545,7 +948,7 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
545
948
|
keyPrefix: `phantom-rn-${memoizedConfig.appId}`,
|
|
546
949
|
appId: memoizedConfig.appId
|
|
547
950
|
});
|
|
548
|
-
const platformName = `${
|
|
951
|
+
const platformName = `${import_react_native6.Platform.OS}-${import_react_native6.Platform.Version}`;
|
|
549
952
|
const platform = {
|
|
550
953
|
storage,
|
|
551
954
|
authProvider,
|
|
@@ -555,17 +958,17 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
555
958
|
name: platformName,
|
|
556
959
|
analyticsHeaders: {
|
|
557
960
|
[import_constants2.ANALYTICS_HEADERS.SDK_TYPE]: "react-native",
|
|
558
|
-
[import_constants2.ANALYTICS_HEADERS.PLATFORM]:
|
|
559
|
-
[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}`,
|
|
560
963
|
[import_constants2.ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
561
964
|
[import_constants2.ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
562
|
-
[import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.
|
|
965
|
+
[import_constants2.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.0-beta.24"
|
|
563
966
|
// Replaced at build time
|
|
564
967
|
}
|
|
565
968
|
};
|
|
566
969
|
return new import_embedded_provider_core.EmbeddedProvider(memoizedConfig, platform, logger);
|
|
567
970
|
}, [memoizedConfig, debugConfig, config.appId, config.embeddedWalletType]);
|
|
568
|
-
(0,
|
|
971
|
+
(0, import_react8.useEffect)(() => {
|
|
569
972
|
const handleConnectStart = () => {
|
|
570
973
|
setIsConnecting(true);
|
|
571
974
|
setConnectError(null);
|
|
@@ -610,13 +1013,11 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
610
1013
|
sdk.off("disconnect", handleDisconnect);
|
|
611
1014
|
};
|
|
612
1015
|
}, [sdk]);
|
|
613
|
-
(0,
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
}, [sdk, config.autoConnect]);
|
|
619
|
-
const value = (0, import_react.useMemo)(
|
|
1016
|
+
(0, import_react8.useEffect)(() => {
|
|
1017
|
+
sdk.autoConnect().catch(() => {
|
|
1018
|
+
});
|
|
1019
|
+
}, [sdk]);
|
|
1020
|
+
const value = (0, import_react8.useMemo)(
|
|
620
1021
|
() => ({
|
|
621
1022
|
sdk,
|
|
622
1023
|
isConnected,
|
|
@@ -625,76 +1026,13 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
625
1026
|
addresses,
|
|
626
1027
|
walletId,
|
|
627
1028
|
setWalletId,
|
|
628
|
-
user
|
|
1029
|
+
user,
|
|
1030
|
+
allowedProviders: config.providers
|
|
629
1031
|
}),
|
|
630
|
-
[sdk, isConnected, isConnecting, connectError, addresses, walletId, setWalletId, user]
|
|
631
|
-
);
|
|
632
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
|
|
633
|
-
}
|
|
634
|
-
function usePhantom() {
|
|
635
|
-
const context = (0, import_react.useContext)(PhantomContext);
|
|
636
|
-
if (context === void 0) {
|
|
637
|
-
throw new Error("usePhantom must be used within a PhantomProvider");
|
|
638
|
-
}
|
|
639
|
-
return context;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
// src/hooks/useConnect.ts
|
|
643
|
-
var import_react2 = require("react");
|
|
644
|
-
function useConnect() {
|
|
645
|
-
const { sdk, isConnecting, connectError, setWalletId } = usePhantom();
|
|
646
|
-
const connect = (0, import_react2.useCallback)(
|
|
647
|
-
async (options) => {
|
|
648
|
-
if (!sdk) {
|
|
649
|
-
throw new Error("SDK not initialized");
|
|
650
|
-
}
|
|
651
|
-
try {
|
|
652
|
-
const result = await sdk.connect(options);
|
|
653
|
-
if (result.status === "completed" && result.walletId) {
|
|
654
|
-
setWalletId(result.walletId);
|
|
655
|
-
}
|
|
656
|
-
return result;
|
|
657
|
-
} catch (err) {
|
|
658
|
-
const error = err;
|
|
659
|
-
throw error;
|
|
660
|
-
}
|
|
661
|
-
},
|
|
662
|
-
[sdk, setWalletId]
|
|
1032
|
+
[sdk, isConnected, isConnecting, connectError, addresses, walletId, setWalletId, user, config.providers]
|
|
663
1033
|
);
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
isConnecting,
|
|
667
|
-
error: connectError
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// src/hooks/useDisconnect.ts
|
|
672
|
-
var import_react3 = require("react");
|
|
673
|
-
function useDisconnect() {
|
|
674
|
-
const { sdk } = usePhantom();
|
|
675
|
-
const [isDisconnecting, setIsDisconnecting] = (0, import_react3.useState)(false);
|
|
676
|
-
const [error, setError] = (0, import_react3.useState)(null);
|
|
677
|
-
const disconnect = (0, import_react3.useCallback)(async () => {
|
|
678
|
-
if (!sdk) {
|
|
679
|
-
throw new Error("SDK not initialized");
|
|
680
|
-
}
|
|
681
|
-
setIsDisconnecting(true);
|
|
682
|
-
setError(null);
|
|
683
|
-
try {
|
|
684
|
-
await sdk.disconnect();
|
|
685
|
-
} catch (err) {
|
|
686
|
-
const error2 = err;
|
|
687
|
-
setError(error2);
|
|
688
|
-
throw error2;
|
|
689
|
-
} finally {
|
|
690
|
-
setIsDisconnecting(false);
|
|
691
|
-
}
|
|
692
|
-
}, [sdk]);
|
|
693
|
-
return {
|
|
694
|
-
disconnect,
|
|
695
|
-
isDisconnecting,
|
|
696
|
-
error
|
|
697
|
-
};
|
|
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 }) }) });
|
|
698
1036
|
}
|
|
699
1037
|
|
|
700
1038
|
// src/hooks/useAccounts.ts
|
|
@@ -732,15 +1070,19 @@ function useEthereum() {
|
|
|
732
1070
|
// src/index.ts
|
|
733
1071
|
var import_client = require("@phantom/client");
|
|
734
1072
|
var import_constants3 = require("@phantom/constants");
|
|
1073
|
+
var import_wallet_sdk_ui5 = require("@phantom/wallet-sdk-ui");
|
|
735
1074
|
// Annotate the CommonJS export names for ESM import in node:
|
|
736
1075
|
0 && (module.exports = {
|
|
737
1076
|
AddressType,
|
|
738
1077
|
NetworkId,
|
|
739
1078
|
PhantomProvider,
|
|
1079
|
+
darkTheme,
|
|
1080
|
+
lightTheme,
|
|
740
1081
|
useAccounts,
|
|
741
1082
|
useConnect,
|
|
742
1083
|
useDisconnect,
|
|
743
1084
|
useEthereum,
|
|
1085
|
+
useModal,
|
|
744
1086
|
usePhantom,
|
|
745
1087
|
useSolana
|
|
746
1088
|
});
|