@dubsdotapp/expo 0.2.13 → 0.2.15
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 +47 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/managed-wallet.tsx +66 -47
package/dist/index.js
CHANGED
|
@@ -1212,6 +1212,31 @@ var styles = import_react_native3.StyleSheet.create({
|
|
|
1212
1212
|
// src/managed-wallet.tsx
|
|
1213
1213
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1214
1214
|
var TAG3 = "[Dubs:ManagedWallet]";
|
|
1215
|
+
var phantomSingleton = null;
|
|
1216
|
+
function getOrCreatePhantomAdapter(config) {
|
|
1217
|
+
if (!phantomSingleton) {
|
|
1218
|
+
console.log(TAG3, "Creating PhantomDeeplinkAdapter (singleton)");
|
|
1219
|
+
phantomSingleton = new PhantomDeeplinkAdapter({
|
|
1220
|
+
redirectUri: config.redirectUri,
|
|
1221
|
+
appUrl: config.appUrl,
|
|
1222
|
+
cluster: config.cluster,
|
|
1223
|
+
onSessionChange: (session) => {
|
|
1224
|
+
if (session) {
|
|
1225
|
+
console.log(TAG3, "Phantom session changed \u2014 saving to storage, wallet:", session.walletPublicKey);
|
|
1226
|
+
config.storage.setItem(STORAGE_KEYS.PHANTOM_SESSION, JSON.stringify(session)).catch((err) => {
|
|
1227
|
+
console.log(TAG3, "Failed to save Phantom session:", err);
|
|
1228
|
+
});
|
|
1229
|
+
} else {
|
|
1230
|
+
console.log(TAG3, "Phantom session cleared \u2014 removing from storage");
|
|
1231
|
+
config.storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch((err) => {
|
|
1232
|
+
console.log(TAG3, "Failed to delete Phantom session:", err);
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
return phantomSingleton;
|
|
1239
|
+
}
|
|
1215
1240
|
var DisconnectContext = (0, import_react.createContext)(null);
|
|
1216
1241
|
function useDisconnect() {
|
|
1217
1242
|
return (0, import_react.useContext)(DisconnectContext);
|
|
@@ -1238,24 +1263,11 @@ function ManagedWalletProvider({
|
|
|
1238
1263
|
const transactRef = (0, import_react.useRef)(null);
|
|
1239
1264
|
if (!adapterRef.current) {
|
|
1240
1265
|
if (usePhantom) {
|
|
1241
|
-
|
|
1242
|
-
adapterRef.current = new PhantomDeeplinkAdapter({
|
|
1266
|
+
adapterRef.current = getOrCreatePhantomAdapter({
|
|
1243
1267
|
redirectUri,
|
|
1244
1268
|
appUrl,
|
|
1245
1269
|
cluster,
|
|
1246
|
-
|
|
1247
|
-
if (session) {
|
|
1248
|
-
console.log(TAG3, "Phantom session changed \u2014 saving to storage, wallet:", session.walletPublicKey);
|
|
1249
|
-
storage.setItem(STORAGE_KEYS.PHANTOM_SESSION, JSON.stringify(session)).catch((err) => {
|
|
1250
|
-
console.log(TAG3, "Failed to save Phantom session:", err);
|
|
1251
|
-
});
|
|
1252
|
-
} else {
|
|
1253
|
-
console.log(TAG3, "Phantom session cleared \u2014 removing from storage");
|
|
1254
|
-
storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch((err) => {
|
|
1255
|
-
console.log(TAG3, "Failed to delete Phantom session:", err);
|
|
1256
|
-
});
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1270
|
+
storage
|
|
1259
1271
|
});
|
|
1260
1272
|
} else {
|
|
1261
1273
|
console.log(TAG3, "Creating MwaWalletAdapter");
|
|
@@ -1287,22 +1299,21 @@ function ManagedWalletProvider({
|
|
|
1287
1299
|
let cancelled = false;
|
|
1288
1300
|
(async () => {
|
|
1289
1301
|
if (usePhantom) {
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
if (
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
adapter.restoreSession(saved);
|
|
1297
|
-
if (!cancelled) {
|
|
1298
|
-
console.log(TAG3, "Session restored, marking connected");
|
|
1299
|
-
setConnected(true);
|
|
1300
|
-
}
|
|
1301
|
-
} else {
|
|
1302
|
-
console.log(TAG3, "No saved Phantom session found");
|
|
1302
|
+
const phantom = adapter;
|
|
1303
|
+
if (phantom.connected) {
|
|
1304
|
+
console.log(TAG3, "Phantom adapter already connected, skipping restore");
|
|
1305
|
+
if (!cancelled) {
|
|
1306
|
+
setConnected(true);
|
|
1307
|
+
setIsReady(true);
|
|
1303
1308
|
}
|
|
1309
|
+
return;
|
|
1310
|
+
}
|
|
1311
|
+
console.log(TAG3, "Phantom path \u2014 clearing any saved session, will require fresh connect");
|
|
1312
|
+
await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {
|
|
1313
|
+
});
|
|
1314
|
+
try {
|
|
1304
1315
|
} catch (err) {
|
|
1305
|
-
console.log(TAG3, "
|
|
1316
|
+
console.log(TAG3, "Unexpected error during Phantom init:", err instanceof Error ? err.message : err);
|
|
1306
1317
|
} finally {
|
|
1307
1318
|
if (!cancelled) {
|
|
1308
1319
|
console.log(TAG3, "Phantom init complete, marking ready");
|
|
@@ -1365,6 +1376,12 @@ function ManagedWalletProvider({
|
|
|
1365
1376
|
const disconnect = (0, import_react.useCallback)(async () => {
|
|
1366
1377
|
console.log(TAG3, "disconnect() \u2014 clearing all state");
|
|
1367
1378
|
adapter.disconnect?.();
|
|
1379
|
+
if (usePhantom && phantomSingleton) {
|
|
1380
|
+
console.log(TAG3, "Destroying Phantom singleton");
|
|
1381
|
+
phantomSingleton.destroy();
|
|
1382
|
+
phantomSingleton = null;
|
|
1383
|
+
adapterRef.current = null;
|
|
1384
|
+
}
|
|
1368
1385
|
await storage.deleteItem(STORAGE_KEYS.MWA_AUTH_TOKEN).catch(() => {
|
|
1369
1386
|
});
|
|
1370
1387
|
await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {
|
|
@@ -1373,15 +1390,7 @@ function ManagedWalletProvider({
|
|
|
1373
1390
|
});
|
|
1374
1391
|
setConnected(false);
|
|
1375
1392
|
console.log(TAG3, "disconnect() \u2014 done");
|
|
1376
|
-
}, [adapter, storage]);
|
|
1377
|
-
(0, import_react.useEffect)(() => {
|
|
1378
|
-
return () => {
|
|
1379
|
-
if (usePhantom && adapter && "destroy" in adapter) {
|
|
1380
|
-
console.log(TAG3, "Unmounting \u2014 destroying Phantom adapter");
|
|
1381
|
-
adapter.destroy();
|
|
1382
|
-
}
|
|
1383
|
-
};
|
|
1384
|
-
}, [adapter, usePhantom]);
|
|
1393
|
+
}, [adapter, storage, usePhantom]);
|
|
1385
1394
|
if (!isReady) {
|
|
1386
1395
|
console.log(TAG3, "Not ready yet \u2014 rendering null");
|
|
1387
1396
|
return null;
|