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

refactor: Typescript conversion of eth-accounts.js #23504

Merged
merged 20 commits into from
Sep 23, 2024

Conversation

NiranjanaBinoy
Copy link
Contributor

@NiranjanaBinoy NiranjanaBinoy commented Mar 14, 2024

Description

Part of #23014
Fixes #23468

Converting the level 6 dependency file app/scripts/lib/rpc-method-middleware/handlers/eth-accounts.js to typescript for contributing to metamask-controller.js.

Open in GitHub Codespaces

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.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 14, 2024
@NiranjanaBinoy NiranjanaBinoy removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 14, 2024
@metamaskbot metamaskbot added INVALID-PR-TEMPLATE PR's body doesn't match template needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels Mar 14, 2024
@NiranjanaBinoy NiranjanaBinoy removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 14, 2024
Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 25.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 70.14%. Comparing base (ce04ae8) to head (aee2062).

Files with missing lines Patch % Lines
...lib/rpc-method-middleware/handlers/eth-accounts.ts 25.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #23504   +/-   ##
========================================
  Coverage    70.14%   70.14%           
========================================
  Files         1424     1424           
  Lines        49572    49572           
  Branches     13868    13868           
========================================
  Hits         34769    34769           
  Misses       14803    14803           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@davidmurdoch davidmurdoch changed the title feat: Typescript conversion of eth-accounts.js refactor: Typescript conversion of eth-accounts.js Mar 15, 2024
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 15, 2024
Copy link
Contributor

@MajorLift MajorLift left a comment

Choose a reason for hiding this comment

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

It looks like extension is using a version (v6.0.1) of the sunsetted json-rpc-engine package that was released 3 years ago. The current version (v8.0.1) of this package has been migrated into core and renamed @metamask/json-rpc-engine. There are major breaking changes between the two versions and important updates.

Packages used in extension are already using the latest version of @metamask/json-rpc-engine internally, which means incompatibilities might pop up if we use the older version.

Maybe we should considered this PR blocked until we can get an upgrade to @metamask/json-rpc-engine merged? This is a new issue arising from this TypeScript conversion and directly affects how the types in this file should be defined.

Comment on lines 49 to 51
async function ethAccountsHandler(
_req: JsonRpcRequest<unknown>,
res: PendingJsonRpcResponse<unknown>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.

Suggested change
async function ethAccountsHandler(
_req: JsonRpcRequest<unknown>,
res: PendingJsonRpcResponse<unknown>,
async function ethAccountsHandler<
Params extends JsonRpcParams = JsonRpcParams,
Result extends Json = Json
>(
_req: JsonRpcRequest<Params>,
res: PendingJsonRpcResponse<Result>,

@brad-decker
Copy link
Contributor

brad-decker commented Mar 15, 2024

@MajorLift i'm working on the upgrade of the json-rpc-engine dependency unless you already are.

@NiranjanaBinoy NiranjanaBinoy marked this pull request as draft March 18, 2024 18:53
@metamaskbot metamaskbot added in-progress and removed needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels Mar 18, 2024
@NiranjanaBinoy NiranjanaBinoy removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 18, 2024
@NiranjanaBinoy NiranjanaBinoy changed the base branch from develop to extract-wrapper-type March 27, 2024 19:45
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 27, 2024
Copy link
Contributor

github-actions bot commented Jun 8, 2024

This PR has been automatically marked as stale because it has not had recent activity in the last 60 days. It will be closed in 14 days. Thank you for your contributions.

@github-actions github-actions bot added the stale issues and PRs marked as stale label Jun 8, 2024
Copy link
Contributor

This PR was closed because there has been no follow up activity in the last 14 days. Thank you for your contributions.

@github-actions github-actions bot closed this Jun 22, 2024
@github-actions github-actions bot removed the stale issues and PRs marked as stale label Jun 24, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [d5a01f4]
Page Load Metrics (50 ± 4 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint61937984
domContentLoaded9271152
load40695074
domInteractive9271152
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@NiranjanaBinoy NiranjanaBinoy changed the base branch from extract-wrapper-type to develop June 25, 2024 14:34
Copy link

sonarcloud bot commented Sep 18, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [54ab602]
Page Load Metrics (1802 ± 86 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15032305179818086
domContentLoaded14962293177118388
load15742304180217886
domInteractive14189443818
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@@ -65,6 +65,8 @@ export const MESSAGE_TYPE = {
///: END:ONLY_INCLUDE_IF
} as const;

export type MessageType = (typeof MESSAGE_TYPE)[keyof typeof MESSAGE_TYPE];
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird, MessageType is resolving to string for me. Investigating...

Copy link
Contributor

Choose a reason for hiding this comment

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

OK IsEqual is evaluating to true, so I'm going to conclude that this is language server flakiness.

type IsEqual = [MessageType, AllMessageTypes] extends [AllMessageTypes, MessageType]
  ? true
  : false;
  
type AllMessageTypes =
  | 'wallet_addEthereumChain'
  | 'eth_accounts'
  | 'eth_decrypt'
  | 'eth_chainId'
  | 'eth_getEncryptionPublicKey'
  | 'eth_getBlockByNumber'
  | 'eth_requestAccounts'
  | 'eth_sendTransaction'
  | 'eth_sendRawTransaction'
  | 'eth_signTransaction'
  | 'eth_signTypedData'
  | 'eth_signTypedData_v1'
  | 'eth_signTypedData_v3'
  | 'eth_signTypedData_v4'
  | 'metamask_getProviderState'
  | 'metamask_logWeb3ShimUsage'
  | 'personal_sign'
  | 'metamask_sendDomainMetadata'
  | 'wallet_switchEthereumChain'
  | 'transaction'
  | 'wallet_requestPermissions'
  | 'wallet_watchAsset'
  | 'metamask_watchAsset'
  | typeof DIALOG_APPROVAL_TYPES.alert
  | typeof DIALOG_APPROVAL_TYPES.confirmation
  | typeof DIALOG_APPROVAL_TYPES.prompt
  | typeof DIALOG_APPROVAL_TYPES.default
  | 'metamaskinstitutional_authenticate'
  | 'metamaskinstitutional_reauthenticate'
  | 'metamaskinstitutional_refresh_token'
  | 'metamaskinstitutional_supported'
  | 'metamaskinstitutional_portfolio'
  | 'metamaskinstitutional_open_swaps'
  | 'metamaskinstitutional_checkIfTokenIsPresent'
  | 'metamaskinstitutional_setAccountAndNetwork'
  | 'metamaskinstitutional_openAddHardwareWallet';

Copy link
Contributor

@MajorLift MajorLift left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for your patience with all of the suggestions.

@NiranjanaBinoy NiranjanaBinoy merged commit 1329a39 into develop Sep 23, 2024
77 checks passed
@NiranjanaBinoy NiranjanaBinoy deleted the ts-eth-accounts branch September 23, 2024 20:05
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2024
@metamaskbot metamaskbot added release-12.6.0 Issue or pull request that will be included in release 12.6.0 release-12.5.0 Issue or pull request that will be included in release 12.5.0 and removed release-12.6.0 Issue or pull request that will be included in release 12.6.0 labels Sep 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.5.0 Issue or pull request that will be included in release 12.5.0 team-extension-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Convert eth-accounts.js to Typescript
5 participants