Skip to content
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

[Bug]: Bring popup to the foreground functionality is not working as expected. #25397

Closed
sleepytanya opened this issue Jun 18, 2024 · 12 comments · Fixed by MetaMask/core#4456
Closed
Labels
regression-RC-12.0.0 release-blocker This bug is blocking the next release Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-wallet-ux type-bug

Comments

@sleepytanya
Copy link
Contributor

sleepytanya commented Jun 18, 2024

Describe the bug

When a user has an unapproved transaction pending, initiating a connect request does not trigger the expected popup to appear.
After the first request is rejected and the subsequent request can be accessed MM can break with an error.
Related issues:

#25393

#25361

Slack discussion links:

https://consensys.slack.com/archives/C03ETQA9EPK/p1695933147044299

https://consensys.slack.com/archives/C03ETQA9EPK/p1695932531166009

Expected behavior

All necessary popups are displayed appropriately.

Screenshots/Recordings

Screen.Recording.2024-06-17.at.10.36.41.AM.mov
Screenshot 2024-06-18 at 17 53 06 340407819-904bd247-432b-4b71-9465-d3547e498e91

Steps to reproduce

  1. Connect to test-dapp
  2. Click button to start legacy send transaction; popup comes up, I see a "1" in the extension icon, I ignore the popup window
  3. Open new tab, go to Uniswap
  4. Click "Connect" button, click MetaMask; I see a "2" in the extension icon, no popup occurs
  5. Click "Connect" button again, click MetaMask; I see a "3" in the extension icon, no popup occurs

Error messages or log output

No response

Version

12.0.0

Build type

None

Browser

Chrome

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

Severity

No response

@jiexi
Copy link
Contributor

jiexi commented Jun 18, 2024

To be clear here, subsequent requests in steps 4 and 5 should cause a popup that shows the pending confirmation from step 2 to show up

@hesterbruikman
Copy link

@sleepytanya @jiexi To make sure I understand the issue, is this right?

GIVEN A pending transaction request
AND MetaMask is closed
AND Initiate a dapp connection
THEN Count goes up, but popup does not open automatically

It looks like the confirmation from step 2 is shown when opening MM manually, but expected is for the popup to open automatically. Is that right?

@sleepytanya
Copy link
Contributor Author

sleepytanya commented Jun 18, 2024

@hesterbruikman Right!
If you open popup manually by clicking MM icon you'll see pending transaction. There is no navigation for the user to be able to see another pending request.

Screenshot 2024-06-18 at 17 34 35

You can also reject unapproved transaction from the homepage. But if you reject from there the next request will be displayed in fullscreen:

Screen.Recording.2024-06-18.at.17.35.28.mov

@hesterbruikman Also while at the full screen homepage MM sometimes breaks with an error:
Screenshot 2024-06-18 at 17 43 56

@seaona
Copy link
Contributor

seaona commented Jun 19, 2024

ℹ️ I've added repro steps for the Cannot destructure property 'balance' of 'K[Z]' as it is undefined here

@sleepytanya
Copy link
Contributor Author

sleepytanya commented Jun 20, 2024

Latest build [https://github.com/MetaMask/metamask-extension/commit/eebc4d5b2284024eaeb190cddfa89990f593ca34]

Popup behavior didn't change:

  • only the first popup displayed
  • Cannot destructure property 'balance' of 'K[Z]' as it is undefined is present
  • Cannot read properties of undefined (reading 'permission') is present
  • Cannot destructure property 'balance' of 'account[fromAddress]' as it is undefined is present
connectTxTx.mov
Screen.Recording.2024-06-20.at.17.43.05.mov

@darkwing
Copy link
Contributor

Findings thus far:

  1. The function that ultimately shows the popup is triggerUi in app/scripts/background.js
  2. triggerUi is called when NOTIFICATION_MANAGER_EVENTS.POPUP_CLOSED is signaled and when MetamaskController's showUserConfirmation is called.
  3. Clicking "Send Transaction" in test dapp on the current network brings forth the popup every time
  4. Switch to a tab connected to a different network and triggering a transaction (ex: PancakeSwap swap) does not trigger triggerUi via MetamaskController's showUserConfirmation
  5. It's clear that MetamaskController's showUserConfirmation only calls triggerUi when the confirmation is on the currently selected network
  6. showUserConfirmation is called by ApprovalController's showApprovalRequest

@sleepytanya
Copy link
Contributor Author

sleepytanya commented Jun 21, 2024

New error.

  1. Start send+swap txs with low gas
  2. Send another (approve) tx from a dapp
  3. Confirmation is stuck on the spinner
  4. Activity tab has two txs - Pending and Unapproved
  5. Unapprovedtxs can't be rejected
  6. If user rejects first tx MM displays an error Cannot destructure property 'balance' of 'Q[z]' as it is undefined.
Screenshot 2024-06-21 at 16 09 26

@gauthierpetetin gauthierpetetin added the Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. label Jun 24, 2024
@darkwing
Copy link
Contributor

There's a separate issue for balance destructuring issues.

@jiexi
Copy link
Contributor

jiexi commented Jun 24, 2024

The issue is the QueuedRequestController will only allow requests to continue on to the ApprovalController if all currently unapproved transactions belong to the same networkClientId. Once a request (that requires confirmation) is received for a networkClientId that differs from the current set of unapproved transactions, that transaction and all transactions afterward (including those matching the original networkClientId with unapproved transactions still visible and scrubbable by the user) are held in the request queue until the current set of unapproved transactions for the first networkClientId are approved/rejected.

This means that the notification window will not be focused starting with the first transaction that differs from the existing unapproved transactions batch.

I believe the fix here is to expose the showUserConfirmation/triggerUi hook to either the QueuedRequestMiddleware or Controller and call that each time a request is queued.

@hesterbruikman
Copy link

@jiexi is my understanding correct that your PR fixes the issue: Popup does not appear when a new confirmation request is received, for a networkClientId that differs from the current set of unapproved transactions?

If so it seems like we can close this issue when your PR gets merged.

There might be residual work related to queue batches not represented clearly in the UI, but that seems like a larger project and out of scope for v12.

cc @darkwing

jiexi added a commit that referenced this issue Jun 25, 2024
…onfirmation popup focus in request queue (#25497)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25497?quickstart=1)

## **Related issues**

See: MetaMask/core#4457
See: #25397

## **Manual testing steps**

1. Ensure request queue is toggled on
2. In Tab 1, Visit the test dapp
3. run `await window.ethereum.request({method:
'wallet_switchEthereumChain', params: [{"chainId": "0xaa36a7"}]})` in
console to change the network to sepolia for this dapp
4. In Tab 2, Visit a different dapp
5. run `await window.ethereum.request({method:
'wallet_switchEthereumChain', params: [{"chainId": "1"}]})` in console
to change the network to mainnet for this dapp
6. In Tab 1, click the Send Transaction button, but ignore the
confirmation notification (leave it open)
7. In Tab 2, run `await window.ethereum.request({method:
'eth_requestAccounts'})`
8. The confirmation notification window should be focused and visible
now, but still be displaying the pending transaction from before

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**


https://github.com/MetaMask/metamask-extension/assets/918701/48693083-fe60-402f-8798-c32b5db541b6

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
jiexi added a commit that referenced this issue Jun 25, 2024
…onfirmation popup focus in request queue (#25497)

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25497?quickstart=1)

## **Related issues**

See: MetaMask/core#4457
See: #25397

## **Manual testing steps**

1. Ensure request queue is toggled on
2. In Tab 1, Visit the test dapp
3. run `await window.ethereum.request({method:
'wallet_switchEthereumChain', params: [{"chainId": "0xaa36a7"}]})` in
console to change the network to sepolia for this dapp
4. In Tab 2, Visit a different dapp
5. run `await window.ethereum.request({method:
'wallet_switchEthereumChain', params: [{"chainId": "1"}]})` in console
to change the network to mainnet for this dapp
6. In Tab 1, click the Send Transaction button, but ignore the
confirmation notification (leave it open)
7. In Tab 2, run `await window.ethereum.request({method:
'eth_requestAccounts'})`
8. The confirmation notification window should be focused and visible
now, but still be displaying the pending transaction from before

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**


https://github.com/MetaMask/metamask-extension/assets/918701/48693083-fe60-402f-8798-c32b5db541b6

## **Pre-merge author checklist**

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@jiexi
Copy link
Contributor

jiexi commented Jun 25, 2024

Should be fixed by #25514

@danjm danjm closed this as completed Jun 26, 2024
@benjisclowder
Copy link
Contributor

Collaborative Effort Required for Root Cause Analysis (RCA) on Critical Issues

We are quickly approaching the end of the quarter and we encourage you once again to take some moments and perform RCA on this critical issue. You may do so by answering the questions below:

1. What PR fixed the issue?
2. Can you pinpoint the commit from which the issue originated?
3. Write a short explanation of the technical cause of the bug
4. How could we have avoided merging this bug? What would have had to be different about our code, tests or processes?

4.1. Were there any missing unit, e2e or manual tests that could have preempted this issue?
4.2. Were there any other elements lacking, such as typed code, comprehensive documentation, well-architected APIs, etc., that might have prevented this issue?
4.3. If your answer to a and b is no, then is there anything at all that you can think of that, if it had been different before this bug was introduced, would have prevented it from being merged?

Please provide your answers as a reply to this comment and tag me as well.

You can read more about the initiative here. Thank you!

Tagging eng. who added the fix: @jiexi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-RC-12.0.0 release-blocker This bug is blocking the next release Sev1-high High severity; partial loss of service with severe impact upon users, with no workaround. team-wallet-ux type-bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

10 participants