Skip to content

Conversation

@EdouardBougon
Copy link
Contributor

@EdouardBougon EdouardBougon commented Nov 27, 2025

Description

New Features

  • Configurable Request Timeouts:

    • Default value is -1 (no timeout) to accommodate user interactions
    • Value of -1 explicitly disables timeout
  • Warmup Timeout: Added warmupTimeout parameter for the initial connection handshake

    • Default value is 200ms (defined in DEFAULT_WARMUP_TIMEOUT)
    • Used specifically for the first wallet_getSession request after connection
    • Helps handle cases where the extension needs time to initialize

Why These Changes?

  1. User Interaction Support: Most Multichain API operations require user confirmation (e.g., signing transactions). The default -1 timeout prevents premature request cancellation.

  2. Initialization Reliability: The warmupTimeout addresses a specific issue where the first request after connection may need extra time to complete (see MetaMask Mobile issue #16550).

  3. Flexibility: Developers can now configure timeouts based on their specific needs while maintaining sensible defaults.

Example Usage

// Default behavior (no timeout for requests, 200ms warmup)
const transport = getDefaultTransport();

// Custom timeouts
const transport = getDefaultTransport({
  defaultTimeout: 30000,  // 30 seconds for all requests
  warmupTimeout: 500      // 500ms for initialization
});

// Disable timeouts completely
const transport = getDefaultTransport({
  defaultTimeout: -1,
  warmupTimeout: -1
});

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds configurable warmupTimeout for the initial request and sets default request timeout to -1 across transports and client, with docs and tests updated.
> 
> - **Transport**:
>   - Add `warmupTimeout` to `Transport` interface and expose in `windowPostMessage` and `externallyConnectable` transports (default `200ms`, configurable, supports `-1`).
>   - Set `DEFAULT_REQUEST_TIMEOUT` to `-1` (no timeout by default); plumb `defaultTimeout`/`warmupTimeout` through `getDefaultTransport` and transport factories.
> - **Client**:
>   - Use `transport.warmupTimeout ?? 1_000` for initial `wallet_getSession` during initialization.
> - **Helpers**:
>   - `withTimeout` supports `-1` to disable timeouts.
> - **Docs**:
>   - README adds timeout configuration section with examples and comparison table.
> - **Tests**:
>   - Update/add tests for warmup timeout exposure/defaults, initial call timeout option, request timeout behavior, and `withTimeout(-1)`.
> 
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a2e5e9a541dfbad048b04672dbd8e00e8372a4f0. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

@EdouardBougon EdouardBougon marked this pull request as ready for review December 2, 2025 10:50
@EdouardBougon EdouardBougon requested a review from a team as a code owner December 2, 2025 10:50
@baptiste-marchand baptiste-marchand merged commit 5e52837 into main Dec 2, 2025
22 checks passed
@baptiste-marchand baptiste-marchand deleted the fix-timeout branch December 2, 2025 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants