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

feat: Mitigate risk for distracted users on queued transactions from different dApps #25852

Merged
merged 9 commits into from
Jul 25, 2024

Conversation

pedronfigueiredo
Copy link
Contributor

@pedronfigueiredo pedronfigueiredo commented Jul 16, 2024

Description

Adds new Banner alert and corresponding metrics event. Also adds metric to navigation when there's are queued confirmations.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/2758

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

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.

@pedronfigueiredo pedronfigueiredo added the team-confirmations Push issues to confirmations team label Jul 16, 2024
@pedronfigueiredo pedronfigueiredo self-assigned this Jul 16, 2024
@pedronfigueiredo pedronfigueiredo requested review from a team as code owners July 16, 2024 10:30
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@@ -1920,6 +1920,9 @@
"etherscanViewOn": {
"message": "View on Etherscan"
},
"existingRequestsBannerAlertDesc": {
"message": "To view and confirm your most recent request, you'll need to approve or reject existing requests first."
Copy link
Member

Choose a reason for hiding this comment

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

Is this a sample or final?

Is the fundamental risk here not the fact that the dApp or chain could have changed without the user realising?

Should that be referenced also?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Raising this with @bschorchit

Choose a reason for hiding this comment

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

Is the fundamental risk here not the fact that the dApp or chain could have changed without the user realising?

Wouldn't that be this issue here: https://github.com/MetaMask/MetaMask-planning/issues/2759 , @matthewwalsh0 ?

Copy link

@bschorchit bschorchit Jul 17, 2024

Choose a reason for hiding this comment

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

The current one that Pedro is working on is regarding queued requests initially not showing up until the user rejects or confirms the first. https://github.com/MetaMask/MetaMask-planning/issues/2758

Copy link
Member

Choose a reason for hiding this comment

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

I understand that, but does it not seem obvious to say you have to approve or reject existing requests first? Is the confusion we are trying to address that requests from another dApp aren't yet visible in the navigation?

ui/pages/confirmations/components/confirm/nav/nav.tsx Outdated Show resolved Hide resolved
test/e2e/tests/confirmations/queued-confirmations.spec.ts Outdated Show resolved Hide resolved
test/e2e/tests/confirmations/queued-confirmations.spec.ts Outdated Show resolved Hide resolved
test/e2e/tests/confirmations/queued-confirmations.spec.ts Outdated Show resolved Hide resolved
test/e2e/tests/confirmations/queued-confirmations.spec.ts Outdated Show resolved Hide resolved
test/e2e/tests/confirmations/queued-confirmations.spec.ts Outdated Show resolved Hide resolved
@pedronfigueiredo pedronfigueiredo changed the title Mitigate risk for distracted users on queued transactions from different dApps feat: Mitigate risk for distracted users on queued transactions from different dApps Jul 19, 2024
});
}
}, [JSON.stringify(properties), queuedRequestCount]);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks bit unusual to have hook which does not return anything but itself performs task, an option could be we return a callback from this hook which user can invoke.

Copy link
Member

Choose a reason for hiding this comment

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

It's rare, but it feels like a good usage since we can automate the metrics based on dependencies and encapsulate that logic, rather than it being a component problem.

We do something similar in useSimulationMetrics already.

Concerning the documentation, it feels suitable since we are still synchronizing with an external system, in this case Segment.

@@ -54,6 +54,10 @@ export function getPendingApprovals(state: ApprovalsMetaMaskState) {
return Object.values(state.metamask.pendingApprovals ?? []);
}

export function pendingApprovalsSortedSelector(state: ApprovalsMetaMaskState) {
return getPendingApprovals(state).sort((a1, a2) => a1.time - a2.time);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be duplicate:

export function pendingConfirmationsSortedSelector(

Copy link
Member

Choose a reason for hiding this comment

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

Does the one in confirm.ts not filter to specific types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, I opted to create a new one that wouldn't filter any pending approvals.

} from '../../../selectors';

export const useQueuedConfirmationsEvent = (queueType: QueueType) => {
const pendingApprovals = useSelector(pendingApprovalsSortedSelector);
Copy link
Contributor

Choose a reason for hiding this comment

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

This selector may be useful here:

const internalLatestPendingConfirmationSelector = createSelector(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Jyoti. However, this selector uses pendingConfirmationsSortedSelector which in turn filters the approval types. We want to show this banner for all confirmation types, including switch ethereum chain and others.


describe('<QueuedRequestsBannerAlert />', () => {
beforeEach(() => {
jest.resetAllMocks();
Copy link
Contributor

Choose a reason for hiding this comment

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

test case does not seems to have mocks

);

expect(container).toMatchSnapshot();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Will be nice to test scenario when alerts are present

await mockedTrackedQueueControllerEvent(server),
await mockedTrackedQueueControllerEvent(server),
];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Great 👍

Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

Changes look great, I left some small feedbacks.

@@ -54,6 +54,10 @@ export function getPendingApprovals(state: ApprovalsMetaMaskState) {
return Object.values(state.metamask.pendingApprovals ?? []);
}

export function pendingApprovalsSortedSelector(state: ApprovalsMetaMaskState) {
return getPendingApprovals(state).sort((a1, a2) => a1.time - a2.time);
}
Copy link
Member

Choose a reason for hiding this comment

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

Does the one in confirm.ts not filter to specific types?

matthewwalsh0
matthewwalsh0 previously approved these changes Jul 19, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The pull request introduces a new banner alert and corresponding metrics event to mitigate risks for distracted users handling queued transactions from different dApps.

  • New Banner Alert: Added QueuedRequestsBannerAlert component in multiple files to notify users about queued transactions.
  • Metrics Event: Introduced ConfirmationQueued event and QueueType enum in shared/constants/metametrics.ts.
  • End-to-End Tests: Added test/e2e/tests/confirmations/alerts/queued-confirmations.spec.ts to cover new alert scenarios.
  • Localization: Added existingRequestsBannerAlertDesc message in app/_locales/en/messages.json.
  • Type Safety: Updated type definitions in various test files for better maintainability and clarity.

No major changes found since the last review.

39 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines +13 to +14
const queuedRequestCount = useSelector(getQueuedRequestCount);
const isQueuedConfirmation = queuedRequestCount > 0;
Copy link

Choose a reason for hiding this comment

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

Style: Consider renaming isQueuedConfirmation to hasQueuedConfirmations for better readability.

});
}
}, [
JSON.stringify(pendingApprovals),
Copy link

Choose a reason for hiding this comment

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

Style: Using JSON.stringify in the dependency array can cause performance issues. Consider using a more efficient method to track changes in pendingApprovals.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The pull request introduces a new banner alert and corresponding metrics event to mitigate risks for distracted users handling queued transactions from different dApps.

  • New Banner Alert: Added QueuedRequestsBannerAlert component in multiple files to notify users about queued transactions.
  • Metrics Event: Introduced ConfirmationQueued event and QueueType enum in shared/constants/metametrics.ts.
  • End-to-End Tests: Added test/e2e/tests/confirmations/alerts/queued-confirmations.spec.ts to cover new alert scenarios.
  • Localization: Added existingRequestsBannerAlertDesc message in app/_locales/en/messages.json.
  • Type Safety: Updated type definitions in various test files for better maintainability and clarity.

No major changes found since the last review.

82 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines +13 to +14
const queuedRequestCount = useSelector(getQueuedRequestCount);
const isQueuedConfirmation = queuedRequestCount > 0;
Copy link

Choose a reason for hiding this comment

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

Style: Consider renaming isQueuedConfirmation to hasQueuedConfirmations for better readability.

});
}
}, [
JSON.stringify(pendingApprovals),
Copy link

Choose a reason for hiding this comment

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

Style: Using JSON.stringify in the dependency array can cause performance issues. Consider using a more efficient method to track changes in pendingApprovals.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The pull request introduces a new banner alert and corresponding metrics event to mitigate risks for distracted users handling queued transactions from different dApps.

  • New Banner Alert: Added QueuedRequestsBannerAlert component in multiple files to notify users about queued transactions.
  • Metrics Event: Introduced ConfirmationQueued event and QueueType enum in shared/constants/metametrics.ts.
  • End-to-End Tests: Added test/e2e/tests/confirmations/alerts/queued-confirmations.spec.ts to cover new alert scenarios.
  • Localization: Added existingRequestsBannerAlertDesc message in app/_locales/en/messages.json.
  • Type Safety: Updated type definitions in various test files for better maintainability and clarity.

37 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines +13 to +14
const queuedRequestCount = useSelector(getQueuedRequestCount);
const isQueuedConfirmation = queuedRequestCount > 0;
Copy link

Choose a reason for hiding this comment

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

Style: Consider renaming isQueuedConfirmation to hasQueuedConfirmations for better readability.

});
}
}, [
JSON.stringify(pendingApprovals),
Copy link

Choose a reason for hiding this comment

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

Style: Using JSON.stringify in the dependency array can cause performance issues. Consider using a more efficient method to track changes in pendingApprovals.

@metamaskbot
Copy link
Collaborator

Builds ready [95bbcd3]
Page Load Metrics (81 ± 10 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint72140108188
domContentLoaded116433157
load56116812010
domInteractive116433157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 7.6 KiB (0.10%)
  • common: 404 Bytes (0.01%)

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The pull request introduces a new banner alert and corresponding metrics event to mitigate risks for distracted users handling queued transactions from different dApps.

  • New Banner Alert: Added QueuedRequestsBannerAlert component in multiple files to notify users about queued transactions.
  • Metrics Event: Introduced ConfirmationQueued event and QueueType enum in shared/constants/metametrics.ts.
  • End-to-End Tests: Added test/e2e/tests/confirmations/alerts/queued-confirmations.spec.ts to cover new alert scenarios.
  • Localization: Added existingRequestsBannerAlertDesc message in app/_locales/en/messages.json.
  • Type Safety: Updated type definitions in various test files for better maintainability and clarity.

102 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines +13 to +14
const queuedRequestCount = useSelector(getQueuedRequestCount);
const isQueuedConfirmation = queuedRequestCount > 0;
Copy link

Choose a reason for hiding this comment

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

Style: Consider renaming isQueuedConfirmation to hasQueuedConfirmations for better readability.

});
}
}, [
JSON.stringify(pendingApprovals),
Copy link

Choose a reason for hiding this comment

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

Style: Using JSON.stringify in the dependency array can cause performance issues. Consider using a more efficient method to track changes in pendingApprovals.

Copy link

sonarcloud bot commented Jul 25, 2024

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The pull request introduces a new banner alert and corresponding metrics event to mitigate risks for distracted users handling queued transactions from different dApps.

  • New Banner Alert: Added QueuedRequestsBannerAlert component in multiple files to notify users about queued transactions.
  • Metrics Event: Introduced ConfirmationQueued event and QueueType enum in shared/constants/metametrics.ts.
  • End-to-End Tests: Added test/e2e/tests/confirmations/alerts/queued-confirmations.spec.ts to cover new alert scenarios.
  • Localization: Added existingRequestsBannerAlertDesc message in app/_locales/en/messages.json.
  • Type Safety: Updated type definitions in various test files for better maintainability and clarity.

49 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings

Comment on lines +13 to +14
const queuedRequestCount = useSelector(getQueuedRequestCount);
const isQueuedConfirmation = queuedRequestCount > 0;
Copy link

Choose a reason for hiding this comment

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

Style: Consider renaming isQueuedConfirmation to hasQueuedConfirmations for better readability.

});
}
}, [
JSON.stringify(pendingApprovals),
Copy link

Choose a reason for hiding this comment

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

Style: Using JSON.stringify in the dependency array can cause performance issues. Consider using a more efficient method to track changes in pendingApprovals.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

Enhanced test coverage for the useSimulationMetrics hook to ensure robust behavior under various conditions.

  • Test Coverage: Expanded scenarios in ui/pages/confirmations/components/simulation-details/useSimulationMetrics.test.ts.
  • Mock Implementations: Utilized mocks for hooks and functions to simulate different simulation responses and asset types.
  • Unused Code Removal: Cleaned up unused mock return values to streamline the test suite.

No major changes found since the last review.

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

@metamaskbot
Copy link
Collaborator

Builds ready [907a000]
Page Load Metrics (63 ± 8 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint6912291178
domContentLoaded95723147
load3910463178
domInteractive95723147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 7.59 KiB (0.10%)
  • common: 404 Bytes (0.01%)

@pedronfigueiredo pedronfigueiredo merged commit 257acdd into develop Jul 25, 2024
76 checks passed
@pedronfigueiredo pedronfigueiredo deleted the pnf/2758 branch July 25, 2024 10:41
@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2024
@metamaskbot metamaskbot added the release-12.3.0 Issue or pull request that will be included in release 12.3.0 label Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-confirmations Push issues to confirmations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants