-
Notifications
You must be signed in to change notification settings - Fork 5.1k
feat: Resimulate transactions for every 3 seconds on focused MM window #29878
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: Resimulate transactions for every 3 seconds on focused MM window #29878
Conversation
No dependency changes detected. Learn more about Socket for GitHub ↗︎ 👍 No dependency changes detected in pull request |
## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> This PR adds `ResimulateHelper`, which focuses on `transactionMeta.isActive` property and re-simulates transaction depending on that value. In order to capsulate re-simulation logic, this PR also relocates other utility functions under the new created `ResimulationHelper.ts` file. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> Fixes: MetaMask/MetaMask-planning#3922 Extension PR: MetaMask/metamask-extension#29878 ## Changelog <!-- If you're making any consumer-facing changes, list those changes here as if you were updating a changelog, using the template below as a guide. (CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or FIXED. For security-related issues, follow the Security Advisory process.) Please take care to name the exact pieces of the API you've added or changed (e.g. types, interfaces, functions, or methods). If there are any breaking changes, make sure to offer a solution for consumers to follow once they upgrade to the changes. Finally, if you're only making changes to development scripts or tests, you may replace the template below with "None". --> ### `@metamask/transaction-controller` - **ADDED**: Adds ability of re-simulating transaction depending on the `isActive` property on `transactionMeta` - `isActive` property is expected to set by client. - Re-simulation of transactions will occur every 3 seconds if `isActive` is `true`. - Adds `setTransactionActive` function to update the `isActive` property on `transactionMeta`. ## Checklist - [X] I've updated the test suite for new or updated code as appropriate - [X] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [X] I've highlighted breaking changes using the "BREAKING" category above as appropriate - [X] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes --------- Co-authored-by: Elliot Winkler <[email protected]>
4642c4d
to
ef97961
Compare
Builds ready [cef1628]
Page Load Metrics (1900 ± 107 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
cef1628
to
ddcad08
Compare
Builds ready [af73098]
Page Load Metrics (3125 ± 1431 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
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.
logic looks good. suggestion to rename some methods and variables to improve readability through more explicit naming
type === TransactionType.tokenMethodTransferFrom || | ||
type === TransactionType.tokenMethodSafeTransferFrom | ||
); | ||
}; |
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.
[suggestion] we could use an O(1) lookup rather than the conditional O(n)
const FOCUSABLE_TYPES: Set<TransactionType> = new Set([
TransactionType.contractInteraction,
TransactionType.deployContract,
TransactionType.simpleSend,
TransactionType.smart,
TransactionType.tokenMethodTransfer,
TransactionType.tokenMethodTransferFrom,
TransactionType.tokenMethodSafeTransferFrom,
]);
then we could update
const shouldBeMarked = shouldSetFocusedForType(type as TransactionType);
to
const shouldBeMarked = FOCUSABLE_TYPES.has(type);
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 were initially other logics inside shouldSetFocusedForType
but they all removed, Set
definitely make sense now, done.
const { id, type } = currentConfirmation ?? {}; | ||
const isWindowFocused = useWindowFocus(); | ||
const dispatch = useDispatch(); | ||
const [focusedConfirmation, setFocusedConfirmation] = useState<string | null>( |
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.
[suggestion] rename focusedConfirmation → focusedConfirmationId for more context and improved readability
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.
Good call, done
); | ||
|
||
useEffect(() => { | ||
const shouldBeMarked = shouldSetFocusedForType(type as TransactionType); |
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.
[suggestion] maybe renaming shouldBeMarked → isFocusable.
I think "should" in shouldBeMarked implies that it will be set. However, the state is only conditionally set. The reason I suggested removing "Marked" is to avoid introducing synonyms. There is room for interpretation using Marked. We can be more explicit by choosing e.g. isFocusable, canSetFocus, canSetTransactionFocus
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
af73098
to
2dd406e
Compare
2dd406e
to
66dda95
Compare
Builds ready [66dda95]
Page Load Metrics (3289 ± 1145 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
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.
Lgtm!
Description
This PR aims to implement re-simulation (updating
simulationData
ontransactionMeta
) of transaction type of confirmations on every 3 seconds if notification window is focused.Core PR that updates simulation data on
active
transactions: MetaMask/core#5189Related issues
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3922
Manual testing steps
See original task description.
Screenshots/Recordings
Resimulation.mov
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist