@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.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
|
-
|
|
1185
|
-
adapterRef.current = new PhantomDeeplinkAdapter({
|
|
1209
|
+
adapterRef.current = getOrCreatePhantomAdapter({
|
|
1186
1210
|
redirectUri,
|
|
1187
1211
|
appUrl,
|
|
1188
1212
|
cluster,
|
|
1189
|
-
|
|
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,22 +1242,21 @@ function ManagedWalletProvider({
|
|
|
1230
1242
|
let cancelled = false;
|
|
1231
1243
|
(async () => {
|
|
1232
1244
|
if (usePhantom) {
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
if (
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
adapter.restoreSession(saved);
|
|
1240
|
-
if (!cancelled) {
|
|
1241
|
-
console.log(TAG3, "Session restored, marking connected");
|
|
1242
|
-
setConnected(true);
|
|
1243
|
-
}
|
|
1244
|
-
} else {
|
|
1245
|
-
console.log(TAG3, "No saved Phantom session found");
|
|
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);
|
|
1246
1251
|
}
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
console.log(TAG3, "Phantom path \u2014 clearing any saved session, will require fresh connect");
|
|
1255
|
+
await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {
|
|
1256
|
+
});
|
|
1257
|
+
try {
|
|
1247
1258
|
} catch (err) {
|
|
1248
|
-
console.log(TAG3, "
|
|
1259
|
+
console.log(TAG3, "Unexpected error during Phantom init:", err instanceof Error ? err.message : err);
|
|
1249
1260
|
} finally {
|
|
1250
1261
|
if (!cancelled) {
|
|
1251
1262
|
console.log(TAG3, "Phantom init complete, marking ready");
|
|
@@ -1308,6 +1319,12 @@ function ManagedWalletProvider({
|
|
|
1308
1319
|
const disconnect = useCallback(async () => {
|
|
1309
1320
|
console.log(TAG3, "disconnect() \u2014 clearing all state");
|
|
1310
1321
|
adapter.disconnect?.();
|
|
1322
|
+
if (usePhantom && phantomSingleton) {
|
|
1323
|
+
console.log(TAG3, "Destroying Phantom singleton");
|
|
1324
|
+
phantomSingleton.destroy();
|
|
1325
|
+
phantomSingleton = null;
|
|
1326
|
+
adapterRef.current = null;
|
|
1327
|
+
}
|
|
1311
1328
|
await storage.deleteItem(STORAGE_KEYS.MWA_AUTH_TOKEN).catch(() => {
|
|
1312
1329
|
});
|
|
1313
1330
|
await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {
|
|
@@ -1316,15 +1333,7 @@ function ManagedWalletProvider({
|
|
|
1316
1333
|
});
|
|
1317
1334
|
setConnected(false);
|
|
1318
1335
|
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]);
|
|
1336
|
+
}, [adapter, storage, usePhantom]);
|
|
1328
1337
|
if (!isReady) {
|
|
1329
1338
|
console.log(TAG3, "Not ready yet \u2014 rendering null");
|
|
1330
1339
|
return null;
|