@dubsdotapp/expo 0.2.27 → 0.2.29

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
@@ -455,6 +455,7 @@ var DubsClient = class {
455
455
  // src/storage.ts
456
456
  var STORAGE_KEYS = {
457
457
  MWA_AUTH_TOKEN: "dubs_mwa_auth_token",
458
+ MWA_WALLET_ADDRESS: "dubs_mwa_wallet_address",
458
459
  JWT_TOKEN: "dubs_jwt_token",
459
460
  PHANTOM_SESSION: "dubs_phantom_session",
460
461
  PHANTOM_CONNECT_IN_FLIGHT: "dubs_phantom_connect_in_flight"
@@ -528,34 +529,41 @@ var MwaWalletAdapter = class {
528
529
  setAuthToken(token) {
529
530
  this._authToken = token;
530
531
  }
532
+ /**
533
+ * Restore a previous session silently (no wallet interaction).
534
+ * Sets the public key and auth token so the adapter appears connected.
535
+ * The next signing operation will reauthorize with Phantom.
536
+ */
537
+ restoreSession(token, walletAddressBase58) {
538
+ this._authToken = token;
539
+ this._publicKey = new PublicKey(walletAddressBase58);
540
+ this._connected = true;
541
+ }
531
542
  /**
532
543
  * Connect to a mobile wallet. Call this before any signing.
544
+ * Tries reauthorize first (if we have a saved token), then falls back to
545
+ * a fresh authorize in a SEPARATE transact session.
533
546
  */
534
547
  async connect() {
535
- await this.transact(async (wallet) => {
536
- let authResult;
537
- if (this._authToken) {
538
- try {
539
- authResult = await wallet.reauthorize({ auth_token: this._authToken });
540
- } catch {
541
- console.log("[Dubs:MWA] reauthorize failed, falling back to authorize");
542
- this._authToken = null;
543
- authResult = await wallet.authorize({
544
- identity: this.config.appIdentity,
545
- cluster: this.config.cluster || "mainnet-beta"
546
- });
547
- }
548
- } else {
549
- authResult = await wallet.authorize({
550
- identity: this.config.appIdentity,
551
- cluster: this.config.cluster || "mainnet-beta"
548
+ if (this._authToken) {
549
+ try {
550
+ await this.transact(async (wallet) => {
551
+ const authResult = await wallet.reauthorize({ auth_token: this._authToken });
552
+ this.applyAuthResult(authResult);
552
553
  });
554
+ return;
555
+ } catch {
556
+ console.log("[Dubs:MWA] reauthorize failed, clearing token and doing fresh authorize");
557
+ this._authToken = null;
558
+ this.config.onAuthTokenChange?.(null);
553
559
  }
554
- this._mwaAddress = authResult.accounts[0].address;
555
- this._publicKey = toPublicKey(this._mwaAddress);
556
- this._authToken = authResult.auth_token;
557
- this._connected = true;
558
- this.config.onAuthTokenChange?.(this._authToken);
560
+ }
561
+ await this.transact(async (wallet) => {
562
+ const authResult = await wallet.authorize({
563
+ identity: this.config.appIdentity,
564
+ cluster: this.config.cluster || "mainnet-beta"
565
+ });
566
+ this.applyAuthResult(authResult);
559
567
  });
560
568
  }
561
569
  /**
@@ -572,8 +580,7 @@ var MwaWalletAdapter = class {
572
580
  if (!this._connected) throw new Error("Wallet not connected");
573
581
  const signed = await this.transact(async (wallet) => {
574
582
  const reauth = await wallet.reauthorize({ auth_token: this._authToken });
575
- this._authToken = reauth.auth_token;
576
- this.config.onAuthTokenChange?.(this._authToken);
583
+ this.applyAuthResult(reauth);
577
584
  const result = await wallet.signTransactions({
578
585
  transactions: [transaction]
579
586
  });
@@ -585,9 +592,7 @@ var MwaWalletAdapter = class {
585
592
  if (!this._connected || !this._publicKey) throw new Error("Wallet not connected");
586
593
  const sig = await this.transact(async (wallet) => {
587
594
  const reauth = await wallet.reauthorize({ auth_token: this._authToken });
588
- this._authToken = reauth.auth_token;
589
- this._mwaAddress = reauth.accounts[0].address;
590
- this.config.onAuthTokenChange?.(this._authToken);
595
+ this.applyAuthResult(reauth);
591
596
  const result = await wallet.signMessages({
592
597
  addresses: [reauth.accounts[0].address],
593
598
  payloads: [message]
@@ -600,8 +605,7 @@ var MwaWalletAdapter = class {
600
605
  if (!this._connected) throw new Error("Wallet not connected");
601
606
  const signature = await this.transact(async (wallet) => {
602
607
  const reauth = await wallet.reauthorize({ auth_token: this._authToken });
603
- this._authToken = reauth.auth_token;
604
- this.config.onAuthTokenChange?.(this._authToken);
608
+ this.applyAuthResult(reauth);
605
609
  const result = await wallet.signAndSendTransactions({
606
610
  transactions: [transaction]
607
611
  });
@@ -612,6 +616,13 @@ var MwaWalletAdapter = class {
612
616
  }
613
617
  return String(signature);
614
618
  }
619
+ applyAuthResult(authResult) {
620
+ this._mwaAddress = authResult.accounts[0].address;
621
+ this._publicKey = toPublicKey(this._mwaAddress);
622
+ this._authToken = authResult.auth_token;
623
+ this._connected = true;
624
+ this.config.onAuthTokenChange?.(this._authToken);
625
+ }
615
626
  };
616
627
 
617
628
  // src/wallet/phantom-deeplink/phantom-deeplink-adapter.ts
@@ -1320,7 +1331,7 @@ function ManagedWalletProvider({
1320
1331
  }
1321
1332
  return transactRef.current(...args);
1322
1333
  },
1323
- appIdentity: { name: appName },
1334
+ appIdentity: { name: appName, uri: appUrl },
1324
1335
  cluster,
1325
1336
  onAuthTokenChange: (token) => {
1326
1337
  if (token) {
@@ -1398,19 +1409,20 @@ function ManagedWalletProvider({
1398
1409
  }
1399
1410
  try {
1400
1411
  const savedToken = await storage.getItem(STORAGE_KEYS.MWA_AUTH_TOKEN);
1401
- if (savedToken && !cancelled) {
1402
- console.log(TAG3, "Found saved MWA auth token, reconnecting...");
1403
- adapter.setAuthToken(savedToken);
1404
- await adapter.connect();
1405
- if (!cancelled) {
1406
- console.log(TAG3, "MWA reconnected from saved token");
1407
- setConnected(true);
1408
- }
1412
+ const savedAddress = await storage.getItem(STORAGE_KEYS.MWA_WALLET_ADDRESS);
1413
+ if (savedToken && savedAddress && !cancelled) {
1414
+ console.log(TAG3, "Found saved MWA session, restoring silently for wallet:", savedAddress);
1415
+ adapter.restoreSession(savedToken, savedAddress);
1416
+ setConnected(true);
1409
1417
  } else {
1410
- console.log(TAG3, "No saved MWA auth token");
1418
+ console.log(TAG3, "No saved MWA session (token or address missing)");
1411
1419
  }
1412
1420
  } catch (err) {
1413
- console.log(TAG3, "MWA silent reconnect failed:", err instanceof Error ? err.message : err);
1421
+ console.log(TAG3, "MWA session restore failed:", err instanceof Error ? err.message : err);
1422
+ await storage.deleteItem(STORAGE_KEYS.MWA_AUTH_TOKEN).catch(() => {
1423
+ });
1424
+ await storage.deleteItem(STORAGE_KEYS.MWA_WALLET_ADDRESS).catch(() => {
1425
+ });
1414
1426
  } finally {
1415
1427
  if (!cancelled) {
1416
1428
  console.log(TAG3, "MWA init complete, marking ready");
@@ -1429,7 +1441,12 @@ function ManagedWalletProvider({
1429
1441
  setError(null);
1430
1442
  try {
1431
1443
  await adapter.connect();
1432
- console.log(TAG3, "handleConnect() \u2014 success, wallet:", adapter.publicKey?.toBase58());
1444
+ const walletAddress = adapter.publicKey?.toBase58();
1445
+ console.log(TAG3, "handleConnect() \u2014 success, wallet:", walletAddress);
1446
+ if (!usePhantom && walletAddress) {
1447
+ storage.setItem(STORAGE_KEYS.MWA_WALLET_ADDRESS, walletAddress).catch(() => {
1448
+ });
1449
+ }
1433
1450
  setConnected(true);
1434
1451
  } catch (err) {
1435
1452
  const message = err instanceof Error ? err.message : "Connection failed";
@@ -1438,7 +1455,7 @@ function ManagedWalletProvider({
1438
1455
  } finally {
1439
1456
  setConnecting(false);
1440
1457
  }
1441
- }, [adapter]);
1458
+ }, [adapter, storage, usePhantom]);
1442
1459
  const disconnect = useCallback(async () => {
1443
1460
  console.log(TAG3, "disconnect() \u2014 clearing all state");
1444
1461
  adapter.disconnect?.();
@@ -1450,6 +1467,8 @@ function ManagedWalletProvider({
1450
1467
  }
1451
1468
  await storage.deleteItem(STORAGE_KEYS.MWA_AUTH_TOKEN).catch(() => {
1452
1469
  });
1470
+ await storage.deleteItem(STORAGE_KEYS.MWA_WALLET_ADDRESS).catch(() => {
1471
+ });
1453
1472
  await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {
1454
1473
  });
1455
1474
  await storage.deleteItem(STORAGE_KEYS.JWT_TOKEN).catch(() => {