Skip to content

feat: unite connection requests #1923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

janek26
Copy link
Contributor

@janek26 janek26 commented Jul 16, 2025

Fixes BX-1802

What changed

If the same tab with the same host sends 2 or more connection requests, we just focus the existing approve window and resolve all requests based on that

What to test

Try to break the connection flow with any dapp, try to connect multiple times on the same host and tab, and same host in 2 different tabs etc


PR-Codex overview

This PR enhances the handling of connection requests in the application, specifically targeting the eth_requestAccounts method. It introduces deduplication for connection requests from the same host and improves the management of pending requests and connection resolvers.

Detailed summary

  • Removed the NODE_OPTIONS setting when running tests.
  • Added getSenderHost and getTabIdString utility functions.
  • Improved handleTabAndWindowUpdates to clean up pending requests and resolve connection requests.
  • Updated addPendingRequest to prevent duplicates from the same host and tab.
  • Introduced connection resolvers to manage multiple requests from the same host.
  • Enhanced tests to verify the deduplication of requests and the addition/removal of pending requests.
  • Improved logic in messengerProviderRequest to handle existing requests and connection resolution.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

linear bot commented Jul 16, 2025

@DanielSinclair DanielSinclair self-requested a review July 16, 2025 17:08
Copy link
Collaborator

@DanielSinclair DanielSinclair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main issue I noticed was a few new failing unit tests. You should be able to run those locally with yarn test to debug. Trying to understand more about the resolver concept here as well

Here is the failing test logs: https://github.com/rainbow-me/browser-extension/actions/runs/16313515910/job/46074063502?pr=1923

@@ -20,7 +20,7 @@ echo "Anvil Launched..."

# Run the tests and store the result
echo "Running Tests..."
NODE_OPTIONS='--no-experimental-fetch' vitest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't recall exactly why we adopted this, but this conflicts with amockFetch injection; this could have changed since node v18

},
removePendingRequest: (id) => {
const pendingRequests = get().pendingRequests;
set({
pendingRequests: pendingRequests.filter((request) => request.id !== id),
});
},
addConnectionResolver: (host, resolver) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some notes about the resolver paradigm used here? Trying to wrap my head around the goal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some in code comments :) Basically it's needed to allow multiple connect requests to resolve when one dialog gets accepted/declined

});
};

const resolveConnectionRequestsIfNeeded = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any duplicative implementation between this concept and handleTabAndWindowUpdates? We attach to the window/tab listeners there for things like expiry

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helped me to prevent some memory leaks, thanks
but in general I think it's not the same concept

tabId -> popups/requests
vs
popup/request -> inpage request resolvers

Copy link

changeset-bot bot commented Jul 17, 2025

⚠️ No Changeset found

Latest commit: d400812

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

2 participants