-
Notifications
You must be signed in to change notification settings - Fork 5k
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: Add origin throttling modal #29656
base: main
Are you sure you want to change the base?
Conversation
} | ||
|
||
export default function createOriginThrottlingMiddleware({ | ||
appStateController, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try and encapsulate as much logic as possible inside this middleware for the sake of maintainability and testing?
As this is constructed from the MetamaskController
, can we define callbacks for anything we need such as:
onApprovalAccept
onApprovalReject
updateThrottledOrigins
getThrottledOrigins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return; | ||
} | ||
|
||
next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we gain by subscribing to the approval controller events if we already have the means to check all the request responses via a callback provided to next
similar to what we do in app/scripts/lib/createRPCMethodTrackingMiddleware.js
?
Could we just check the result error and update the throttled state via our callbacks?
It would reduce coupling between this middleware and the controllers and further modularise all this throttling functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed approval controller events, fixed all in middleware
export function validateOriginThrottling({ | ||
req, | ||
end, | ||
appStateController, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth a more specific callback to avoid coupling to the controller directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
'Request blocked due to spam filter.', | ||
); | ||
|
||
export function validateOriginThrottling({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function necessary if it's only used internally and encapsulates a call to a single function? Would it add readability to the main middleware to move it inline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're able to encapsulate all the logic in the middleware, should these constants be moved there if there's no other usages of them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constants still be shared between UI and background. Not all of them(BLOCKABLE_METHODS
used in background only) but is it make sense to have them together under shared
?
|
||
return ( | ||
<PageFooter className="confirm-footer_page-footer"> | ||
<OriginThrottleModal | ||
isOpen={showOriginThrottleModal} | ||
onConfirmationCancel={onFooterCancel} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than relying on forceCancel
, could we instead just use onCancel
here or a wrapper to avoid duplicating the location
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if I follow, can you elaborate on this?
<ModalFooter | ||
paddingTop={4} | ||
onSubmit={() => { | ||
// Order of operations is important here to ensure the origin is reset after the confirmation is cancelled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, is it worth storybooks for this component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return { | ||
origin, | ||
resetOrigin, | ||
willNextRejectionReachThreshold: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, could this be defined above in a variable to avoid the inline logic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return { | ||
origin, | ||
resetOrigin, | ||
willNextRejectionReachThreshold: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call this something like shouldThrottleOrigin
to be explicit and also include some extra context for the external usages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
return callback(); | ||
} | ||
|
||
if ('error' in res && res.error && isUserRejectedError(res.error)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in
operator here is to satisfy type check on response
Description
This PR brings origin throttling modal functionality which is done in the mobile MetaMask/metamask-mobile#10082
The PR also needs an
ApprovalController
to be updated in order to subscribe theaccepted
andrejected
approvals to handle user rejected approvals.Core PR: MetaMask/core#5127
Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3344
First mobile task: https://github.com/MetaMask/MetaMask-planning/issues/1822
Manual testing steps
Screenshots/Recordings
origin.throttling.modal.mov
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist