-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
Make safelyExecute
type safe
#3629
Conversation
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.
Thanks, this makes sense! Could you mark this as a breaking change for both safelyExecute
and safelyExecuteWithTimeout
in the PR description? I've also left a couple of comments and a question.
packages/assets-controllers/src/Standards/NftStandards/ERC1155/ERC1155Standard.ts
Show resolved
Hide resolved
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.
This looks good to me!
@@ -520,13 +520,13 @@ export class NftController extends BaseControllerV1<NftConfig, NftState> { | |||
|
|||
return { | |||
...openSeaMetadata, | |||
name: blockchainMetadata.name ?? openSeaMetadata?.name ?? null, | |||
name: blockchainMetadata?.name ?? openSeaMetadata?.name ?? 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.
@bergeron How would you describe the impact of these changes? It looks like they'd have a functional impact.
This suggests that there may have been cases where blockchainMetadata
was nullish, which previously would have thrown an error on this line. But now it's no longer thrown.
Similarly, below in getNftContractInformation
, the changes suggest that address
and contract.name
would previously be missing sometimes, but now they're always included.
Is that the case? Or are the affected scenarios really non-existent, with these changes being made just for type reasons.
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.
It looks like this does fix something. In the case where the request fails, this would crash on this line previously, but now it doesn't.
Too bad this isn't represented in tests either, there are no tests for this method (as it's private). And even indirect uses of it are stubbed out in the tests 🤦
Explanation
safelyExecute
andsafelyExecuteWithTimeout
are convenient utility functions, but they were returningany
which removes type safety. This PR makes them generic so they return the type of the underlying operation.References
Changelog
@metamask/controller-utils
safelyExecute
andsafelyExecuteWithTimeout
generic so they preserve typesChecklist