@pooflabs/web 0.0.28 → 0.0.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.esm.js CHANGED
@@ -10344,7 +10344,7 @@ class PhantomWalletProvider {
10344
10344
  } : null,
10345
10345
  };
10346
10346
  }
10347
- }, [phantom, phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, connect, disconnect, isDisconnecting, modal, modal.isOpened, solana, connectError]);
10347
+ }, [phantom, phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, connect, disconnect, isDisconnecting, modal, modal.isOpened, solana, solana === null || solana === void 0 ? void 0 : solana.isAvailable, connectError]);
10348
10348
  // Handle modal close without connection
10349
10349
  React$1.useEffect(() => {
10350
10350
  // Detect when modal was open and is now closed
@@ -10371,52 +10371,55 @@ class PhantomWalletProvider {
10371
10371
  React$1.useEffect(() => {
10372
10372
  const handleConnectionSuccess = async () => {
10373
10373
  var _a;
10374
- if ((phantom === null || phantom === void 0 ? void 0 : phantom.isConnected) && ((_a = phantom === null || phantom === void 0 ? void 0 : phantom.addresses) === null || _a === void 0 ? void 0 : _a.length) > 0 && that.pendingLogin && that.loginInProgress) {
10375
- try {
10376
- // Find Solana address
10377
- const solAddress = phantom.addresses.find((addr) => addr.addressType === AddressType.solana);
10378
- if (!solAddress) {
10379
- that.pendingLogin.reject(new Error('No Solana address returned'));
10380
- that.pendingLogin = null;
10381
- that.loginInProgress = false;
10382
- return;
10383
- }
10384
- const publicKey = solAddress.address;
10385
- // Check if we already have a valid session
10386
- const existingSession = await WebSessionManager.getSession();
10387
- if (existingSession && existingSession.address === publicKey) {
10388
- const user = { provider: that, address: publicKey };
10389
- setCurrentUser(user);
10390
- that.pendingLogin.resolve(user);
10391
- that.pendingLogin = null;
10392
- that.loginInProgress = false;
10393
- return;
10394
- }
10395
- // Wait for solana methods to be available
10396
- if (!solana || !solana.isAvailable) {
10397
- // Solana not ready yet, wait a bit and retry
10398
- setTimeout(() => handleConnectionSuccess(), 100);
10399
- return;
10400
- }
10401
- // Create new session with signature
10402
- const nonce = await genAuthNonce();
10403
- const messageText = await genSolanaMessage(publicKey, nonce);
10404
- // signMessage returns a string directly
10405
- const signature = await solana.signMessage(messageText);
10406
- const createSessionResult = await createSessionWithSignature(publicKey, messageText, signature);
10407
- await WebSessionManager.storeSession(publicKey, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
10374
+ // All conditions must be met for login to proceed
10375
+ if (!(phantom === null || phantom === void 0 ? void 0 : phantom.isConnected) || !((_a = phantom === null || phantom === void 0 ? void 0 : phantom.addresses) === null || _a === void 0 ? void 0 : _a.length) || !that.pendingLogin || !that.loginInProgress) {
10376
+ return;
10377
+ }
10378
+ // Solana must be available for signing
10379
+ // If not ready yet, just return - this effect will re-run when solana?.isAvailable changes
10380
+ if (!solana || !solana.isAvailable) {
10381
+ console.log('[Phantom] Waiting for Solana to be available...');
10382
+ return;
10383
+ }
10384
+ try {
10385
+ // Immediately set loginInProgress to false to prevent double execution
10386
+ // if the effect runs again before async operations complete
10387
+ that.loginInProgress = false;
10388
+ // Find Solana address
10389
+ const solAddress = phantom.addresses.find((addr) => addr.addressType === AddressType.solana);
10390
+ if (!solAddress) {
10391
+ that.pendingLogin.reject(new Error('No Solana address returned'));
10392
+ that.pendingLogin = null;
10393
+ return;
10394
+ }
10395
+ const publicKey = solAddress.address;
10396
+ // Check if we already have a valid session
10397
+ const existingSession = await WebSessionManager.getSession();
10398
+ if (existingSession && existingSession.address === publicKey) {
10408
10399
  const user = { provider: that, address: publicKey };
10409
10400
  setCurrentUser(user);
10410
10401
  that.pendingLogin.resolve(user);
10411
10402
  that.pendingLogin = null;
10412
- that.loginInProgress = false;
10403
+ return;
10413
10404
  }
10414
- catch (error) {
10415
- if (that.pendingLogin) {
10416
- that.pendingLogin.reject(error);
10417
- that.pendingLogin = null;
10418
- that.loginInProgress = false;
10419
- }
10405
+ console.log('[Phantom] Creating session with signature...');
10406
+ // Create new session with signature
10407
+ const nonce = await genAuthNonce();
10408
+ const messageText = await genSolanaMessage(publicKey, nonce);
10409
+ // signMessage returns a string directly - this should trigger the Phantom sign popup
10410
+ const signature = await solana.signMessage(messageText);
10411
+ const createSessionResult = await createSessionWithSignature(publicKey, messageText, signature);
10412
+ await WebSessionManager.storeSession(publicKey, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
10413
+ const user = { provider: that, address: publicKey };
10414
+ setCurrentUser(user);
10415
+ that.pendingLogin.resolve(user);
10416
+ that.pendingLogin = null;
10417
+ }
10418
+ catch (error) {
10419
+ if (that.pendingLogin) {
10420
+ that.pendingLogin.reject(error);
10421
+ that.pendingLogin = null;
10422
+ that.loginInProgress = false;
10420
10423
  }
10421
10424
  }
10422
10425
  };