From d1b49ef4e784f8252aa98d0cea4df9f028d78af8 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Thu, 4 Dec 2025 12:42:48 +0100 Subject: [PATCH] fix: RPC request with id already seen error when using firefox --- CHANGELOG.md | 4 ++++ src/transports/windowPostMessageTransport.ts | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccee932..519b3c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- fix: make sure `getUniqueId` is called on each `windowPostMessageTransport` request to avoid `RPC request with id already seen.` error on extension when using firefox ([#91](https://github.com/MetaMask/multichain-api-client/pull/91)) + ## [0.10.0] ### Added diff --git a/src/transports/windowPostMessageTransport.ts b/src/transports/windowPostMessageTransport.ts index 472e877..5ba2ced 100644 --- a/src/transports/windowPostMessageTransport.ts +++ b/src/transports/windowPostMessageTransport.ts @@ -28,7 +28,6 @@ export function getWindowPostMessageTransport( const { defaultTimeout = DEFAULT_REQUEST_TIMEOUT, warmupTimeout = DEFAULT_WARMUP_TIMEOUT } = params; let messageListener: ((event: MessageEvent) => void) | null = null; const pendingRequests: Map void> = new Map(); - let requestId = getUniqueId(); /** * Storing notification callbacks. * If we detect a "notification" (a message without an id) coming from the extension, we'll call each callback in here. @@ -115,7 +114,7 @@ export function getWindowPostMessageTransport( throw new TransportError('Transport not connected'); } - const id = requestId++; + const id = getUniqueId(); const request = { jsonrpc: '2.0' as const, id,