@dubsdotapp/expo 0.2.13 → 0.2.14

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.mjs CHANGED
@@ -1155,6 +1155,31 @@ var styles = StyleSheet.create({
1155
1155
  // src/managed-wallet.tsx
1156
1156
  import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
1157
1157
  var TAG3 = "[Dubs:ManagedWallet]";
1158
+ var phantomSingleton = null;
1159
+ function getOrCreatePhantomAdapter(config) {
1160
+ if (!phantomSingleton) {
1161
+ console.log(TAG3, "Creating PhantomDeeplinkAdapter (singleton)");
1162
+ phantomSingleton = new PhantomDeeplinkAdapter({
1163
+ redirectUri: config.redirectUri,
1164
+ appUrl: config.appUrl,
1165
+ cluster: config.cluster,
1166
+ onSessionChange: (session) => {
1167
+ if (session) {
1168
+ console.log(TAG3, "Phantom session changed \u2014 saving to storage, wallet:", session.walletPublicKey);
1169
+ config.storage.setItem(STORAGE_KEYS.PHANTOM_SESSION, JSON.stringify(session)).catch((err) => {
1170
+ console.log(TAG3, "Failed to save Phantom session:", err);
1171
+ });
1172
+ } else {
1173
+ console.log(TAG3, "Phantom session cleared \u2014 removing from storage");
1174
+ config.storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch((err) => {
1175
+ console.log(TAG3, "Failed to delete Phantom session:", err);
1176
+ });
1177
+ }
1178
+ }
1179
+ });
1180
+ }
1181
+ return phantomSingleton;
1182
+ }
1158
1183
  var DisconnectContext = createContext(null);
1159
1184
  function useDisconnect() {
1160
1185
  return useContext(DisconnectContext);
@@ -1181,24 +1206,11 @@ function ManagedWalletProvider({
1181
1206
  const transactRef = useRef(null);
1182
1207
  if (!adapterRef.current) {
1183
1208
  if (usePhantom) {
1184
- console.log(TAG3, "Creating PhantomDeeplinkAdapter");
1185
- adapterRef.current = new PhantomDeeplinkAdapter({
1209
+ adapterRef.current = getOrCreatePhantomAdapter({
1186
1210
  redirectUri,
1187
1211
  appUrl,
1188
1212
  cluster,
1189
- onSessionChange: (session) => {
1190
- if (session) {
1191
- console.log(TAG3, "Phantom session changed \u2014 saving to storage, wallet:", session.walletPublicKey);
1192
- storage.setItem(STORAGE_KEYS.PHANTOM_SESSION, JSON.stringify(session)).catch((err) => {
1193
- console.log(TAG3, "Failed to save Phantom session:", err);
1194
- });
1195
- } else {
1196
- console.log(TAG3, "Phantom session cleared \u2014 removing from storage");
1197
- storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch((err) => {
1198
- console.log(TAG3, "Failed to delete Phantom session:", err);
1199
- });
1200
- }
1201
- }
1213
+ storage
1202
1214
  });
1203
1215
  } else {
1204
1216
  console.log(TAG3, "Creating MwaWalletAdapter");
@@ -1230,13 +1242,22 @@ function ManagedWalletProvider({
1230
1242
  let cancelled = false;
1231
1243
  (async () => {
1232
1244
  if (usePhantom) {
1245
+ const phantom = adapter;
1246
+ if (phantom.connected) {
1247
+ console.log(TAG3, "Phantom adapter already connected, skipping restore");
1248
+ if (!cancelled) {
1249
+ setConnected(true);
1250
+ setIsReady(true);
1251
+ }
1252
+ return;
1253
+ }
1233
1254
  console.log(TAG3, "Phantom path \u2014 checking for saved session...");
1234
1255
  try {
1235
1256
  const savedJson = await storage.getItem(STORAGE_KEYS.PHANTOM_SESSION);
1236
1257
  if (savedJson && !cancelled) {
1237
1258
  console.log(TAG3, "Found saved Phantom session, restoring...");
1238
1259
  const saved = JSON.parse(savedJson);
1239
- adapter.restoreSession(saved);
1260
+ phantom.restoreSession(saved);
1240
1261
  if (!cancelled) {
1241
1262
  console.log(TAG3, "Session restored, marking connected");
1242
1263
  setConnected(true);
@@ -1308,6 +1329,12 @@ function ManagedWalletProvider({
1308
1329
  const disconnect = useCallback(async () => {
1309
1330
  console.log(TAG3, "disconnect() \u2014 clearing all state");
1310
1331
  adapter.disconnect?.();
1332
+ if (usePhantom && phantomSingleton) {
1333
+ console.log(TAG3, "Destroying Phantom singleton");
1334
+ phantomSingleton.destroy();
1335
+ phantomSingleton = null;
1336
+ adapterRef.current = null;
1337
+ }
1311
1338
  await storage.deleteItem(STORAGE_KEYS.MWA_AUTH_TOKEN).catch(() => {
1312
1339
  });
1313
1340
  await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {
@@ -1316,15 +1343,7 @@ function ManagedWalletProvider({
1316
1343
  });
1317
1344
  setConnected(false);
1318
1345
  console.log(TAG3, "disconnect() \u2014 done");
1319
- }, [adapter, storage]);
1320
- useEffect(() => {
1321
- return () => {
1322
- if (usePhantom && adapter && "destroy" in adapter) {
1323
- console.log(TAG3, "Unmounting \u2014 destroying Phantom adapter");
1324
- adapter.destroy();
1325
- }
1326
- };
1327
- }, [adapter, usePhantom]);
1346
+ }, [adapter, storage, usePhantom]);
1328
1347
  if (!isReady) {
1329
1348
  console.log(TAG3, "Not ready yet \u2014 rendering null");
1330
1349
  return null;