-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
refactor: clean up profile sync hooks #28132
refactor: clean up profile sync hooks #28132
Conversation
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. |
ui/hooks/metamask-notifications/useProfileSyncing/accountSyncing.test.tsx
Outdated
Show resolved
Hide resolved
@@ -1,6 +1,9 @@ | |||
import type { InternalAccount } from '@metamask/keyring-api'; | |||
import { SubjectMetadata } from '@metamask/permission-controller'; | |||
import { KeyringType } from '../hooks/metamask-notifications/useProfileSyncing'; |
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 did not like this selector type importing the profile-sync type.
Instead copied the type here, and the accounts team can provide a better narrow type.
Builds ready [b4eafe7]
Page Load Metrics (2341 ± 87 ms)
Bundle size diffs
|
* @template {(...args: any) => any} Hook | ||
* @template {Parameters<Hook>} HookParams | ||
* @template {ReturnType<Hook>} HookReturn | ||
* @template {import('@testing-library/react-hooks').RenderHookResult<HookParams, HookReturn>} RenderHookResult | ||
* @template {import('history').History} History | ||
* @param {Hook} hook - The hook to be rendered. | ||
* @param [state] - The initial state for the store. | ||
* @param [pathname] - The initial pathname for the history. | ||
* @param [Container] - An optional container component. | ||
* @returns {RenderHookResult & { history: History }} The result of the rendered hook and the history object. |
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.
JSDOC is actually pretty powerful. I did not know we can utilise generics.
This give us a nicer return type which gives us correct intellisense when creating tests.
const hook = renderWithProviderTyped(() => useMyFoo())
hook.result.callBar() // <-- this will now autocomplete and give us info on return/params required
We can migrate this over to TS in a diff PR (along with the other render helper functions in this file).
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.
As for why not adding JSDOC to the original function - I tested this, but many other tests that use this function failed TSC (due to not using the correct result.current
type or passing incorrect arguments)
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 think we can get a follow-up PR to add the JSDOC types to the original function, and fix the type issues on other files.
It might require coordinating with other teams to make sure that the type fixes are expected.
Builds ready [246ede3]
Page Load Metrics (2200 ± 214 ms)
Bundle size diffs
|
these changes make it easier for us to extend and add other syncing features
create a JSDOC typed version which is easier to use
246ede3
to
d2ae206
Compare
Builds ready [d2ae206]
Page Load Metrics (2016 ± 65 ms)
Bundle size diffs
|
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!
Builds ready [f7fb949]
Page Load Metrics (1914 ± 98 ms)
Bundle size diffs
|
Builds ready [df0cf4a]
Page Load Metrics (1994 ± 53 ms)
Bundle size diffs
|
Description
These changes make it easier for us to extend and add other syncing features.
Originally this was part of my local network sync feature, but decoupled parts of it since the change are a lot.
Related issues
Fixes: N/A
Manual testing steps
There should be no changes as this is a code refactor and the interfaces/exports do not change.
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist