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

feat: Delete legacy signature confirmation code #30038

Merged
merged 2 commits into from
Feb 5, 2025
Merged

Conversation

pedronfigueiredo
Copy link
Contributor

@pedronfigueiredo pedronfigueiredo commented Jan 31, 2025

Description

Building up on #29926, the goal of this PR is to remove as much dead code as possible related to the signatures and transactions confirmations that predate the redesign.

  • Remove signature entry points from confirm-transaction and confirm-transaction-switch.
  • Remove signature-related components
    • signature-request-header
    • signature-request-original
    • signature-request-siwe
    • signature-request
    • signature-request-message
    • confirm-signature-request
  • Remove other unused code from confirmations
    • confirm-hexdata
    • confirm-detail-row
    • confirm-page-container
    • confirm-page-container-summary
    • confirm-page-container-navigation
    • confirm-subtitle
    • confirm-title
    • transaction-decoding
    • custom-spending-cap
    • review-spending-cap
    • security-provider-banner-alert
    • transaction-alerts
    • ledger-instruction-field
  • After removing these components, a pass was done on the deleted code to identify deleted uses of selectors, actions, util, and hooks. Some of these become dead code so they were deleted in this PR as well.
  • I went back and did the same in the diff for the PR to remove dead transactions code.
  • Removed unit tests, storybook stories, styles and localization files associated with the removed files.

Attempt at automated way to flag dead code for removal

I tried using the import/no-unused-modules ESLint rule to catch unused exports. Here's the config I tried:

{
  files: [
    'ui/**/*.{js,ts,tsx}',
    'shared/**/*.{js,ts,tsx}',
  ],
  rules: {
    'import/no-unused-modules': [
      2,
      {
        unusedExports: true,
        missingExports: false,
        ignoreExports: [
          // Any usage in test or Storybook files is ignored,
          // so if a function is only imported by these files,
          // it will still be flagged as unused.
          '**/*.test.*',
          '**/*.spec.*',
          '**/*.stories.*',
        ],
      },
    ],
  },
}

However, given the way selectors are exported on ui/selectors/index.js, the rule can't correctly pattern match the unused selectors. I commented the index manually and ran the rule to find "dead code" selectors but this time all selectors were flagged as unused.

Finally, I wondered if this rule could still give useful outputs for other folders of the project besides the selectors folder. When running the lint rule against the whole ui directory, the script ran for more than 2 hours before I stopped it.

Unfortunately, using an ESLint rule to detect dead code is not time efficient, so for this PR I resorted to using the manual methods described above.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/4062

Manual testing steps

  1. Go to this page...

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@pedronfigueiredo pedronfigueiredo added the team-confirmations Push issues to confirmations team label Jan 31, 2025
@pedronfigueiredo pedronfigueiredo self-assigned this Jan 31, 2025
@pedronfigueiredo pedronfigueiredo requested review from a team as code owners January 31, 2025 18:30
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
Copy link
Collaborator

Builds ready [cee2f77]
Page Load Metrics (1823 ± 106 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint35023341740388186
domContentLoaded154522811795223107
load155923351823222106
domInteractive26108442512
backgroundConnect1278332211
firstReactRender16103453015
getState680202210
initialActions00000
loadScripts11071723130717584
setupStore85614136
uiStartup179326132104278134
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: -208.66 KiB (-2.65%)
  • common: -5.85 KiB (-0.06%)

Copy link

socket-security bot commented Feb 3, 2025

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/[email protected]

View full report↗︎

@pedronfigueiredo
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@metamaskbot metamaskbot requested review from a team as code owners February 3, 2025 12:07
@pedronfigueiredo
Copy link
Contributor Author

@MetaMask/policy-reviewers, the policy change results from removing the package react-inspector.

Copy link
Member

Choose a reason for hiding this comment

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

How come the Snaps E2E's didn't need to be adapted for this? IIRC we are testing both the legacy and new confirmations for both signatures and transactions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The e2e tests for old code were removed in #29695 and #29819, when the toggles were removed because legacy confirmations became no longer accessible.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe it stayed by mistake, I'll remove this too!

@FrederikBolding
Copy link
Member

@MetaMask/policy-reviewers, the policy change results from removing the package react-inspector.

Policy changes lgtm

@metamaskbot
Copy link
Collaborator

Builds ready [a3621e6]
Page Load Metrics (1745 ± 59 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint25320631673351168
domContentLoaded15112030171712560
load15462048174512459
domInteractive24140463115
backgroundConnect87131209
firstReactRender1793382612
getState45919189
initialActions01000
loadScripts10861465125810852
setupStore85917168
uiStartup17932563201018086
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: -208.66 KiB (-2.65%)
  • common: -7.72 KiB (-0.08%)

@FrederikBolding
Copy link
Member

@pedronfigueiredo /ui/components/app/snaps/insight-warnings is dead code now too AFAIK, would be good to remove if you don't mind

@@ -414,7 +414,6 @@
"react-dom": "^16.12.0",
"react-focus-lock": "^2.9.4",
"react-idle-timer": "^4.2.5",
"react-inspector": "^6.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

PATH_NAME_MAP[
`${CONFIRM_TRANSACTION_ROUTE}/:id${CONFIRM_INCREASE_ALLOWANCE_PATH}`
] = 'Confirm Increase Allowance Transaction Page';

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @pedronfigueiredo : are these paths still needed, may be we can simplify routing to route all confirmations to Confirm.tsx. I think we no longer need sub-paths like above.

But this can be done in separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we have planned work for refactoring the routing separately 👍

export function getSnaps(state) {
return state.metamask.snaps;
}

export function testFunctionToSeeIfItsCaught(state) {
return state.metamask.snaps;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed, it looks same as getSnaps above ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was committed by mistake, great catch Jyoti. I'll remove this now.

jpuri
jpuri previously approved these changes Feb 3, 2025
Copy link
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

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

Great work, I left some small feedbacks.

FrederikBolding
FrederikBolding previously approved these changes Feb 3, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [c958b4d]
Page Load Metrics (1607 ± 56 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint25018151549318153
domContentLoaded13971773158111656
load14471817160711756
domInteractive24163443618
backgroundConnect679292110
firstReactRender15102412814
getState413731
initialActions01000
loadScripts9841338113010751
setupStore792242412
uiStartup16362180184415474
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: -208.66 KiB (-2.65%)
  • common: -8.56 KiB (-0.09%)

jpuri
jpuri previously approved these changes Feb 4, 2025
FrederikBolding
FrederikBolding previously approved these changes Feb 4, 2025
@sleepytanya
Copy link
Contributor

@pedronfigueiredo

The PR does not appear to negatively impact any of the signatures and transactions confirmations, all basic flows
and functionalities work as expected for Signatures and Transactions.

@pedronfigueiredo pedronfigueiredo added this pull request to the merge queue Feb 5, 2025
github-merge-queue bot pushed a commit that referenced this pull request Feb 5, 2025
## **Description**

Building up on
[#29926](#29926), the
goal of this PR is to remove as much dead code as possible related to
the signatures and transactions confirmations that predate the redesign.

- Remove signature entry points from `confirm-transaction` and
`confirm-transaction-switch`.
- Remove signature-related components
  - `signature-request-header`
  - `signature-request-original`
  - `signature-request-siwe`
  - `signature-request`
  - `signature-request-message`
  - `confirm-signature-request`
- Remove other unused code from confirmations
  - `confirm-hexdata`
  - `confirm-detail-row`
  - `confirm-page-container`
  - `confirm-page-container-summary`
  - `confirm-page-container-navigation`
  - `confirm-subtitle`
  - `confirm-title`
  - `transaction-decoding`
  - `custom-spending-cap`
  - `review-spending-cap`
  - `security-provider-banner-alert`
  - `transaction-alerts`
  - `ledger-instruction-field`
- After removing these components, a pass was done on the deleted code
to identify deleted uses of `selectors`, `actions`, `util`, and `hooks`.
Some of these become dead code so they were deleted in this PR as well.
- I went back and did the same in the diff for the PR to remove dead
transactions code.
- Removed unit tests, storybook stories, styles and localization files
associated with the removed files.

## Attempt at automated way to flag dead code for removal

I tried using the
[import/no-unused-modules](https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-unused-modules.md)
ESLint rule to catch unused exports. Here's the config I tried:

```js
{
  files: [
    'ui/**/*.{js,ts,tsx}',
    'shared/**/*.{js,ts,tsx}',
  ],
  rules: {
    'import/no-unused-modules': [
      2,
      {
        unusedExports: true,
        missingExports: false,
        ignoreExports: [
          // Any usage in test or Storybook files is ignored,
          // so if a function is only imported by these files,
          // it will still be flagged as unused.
          '**/*.test.*',
          '**/*.spec.*',
          '**/*.stories.*',
        ],
      },
    ],
  },
}
```

However, given the way selectors are exported on
`ui/selectors/index.js`, the rule can't correctly pattern match the
unused selectors. I commented the index manually and ran the rule to
find "dead code" selectors but this time all selectors were flagged as
unused.

Finally, I wondered if this rule could still give useful outputs for
other folders of the project besides the selectors folder. When running
the lint rule against the whole ui directory, the script ran for more
than 2 hours before I stopped it.

Unfortunately, using an ESLint rule to detect dead code is not time
efficient, so for this PR I resorted to using the manual methods
described above.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/30038?quickstart=1)

## **Related issues**

Fixes: MetaMask/MetaMask-planning#4062

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2025
@pedronfigueiredo pedronfigueiredo added this pull request to the merge queue Feb 5, 2025
@pedronfigueiredo pedronfigueiredo removed this pull request from the merge queue due to a manual request Feb 5, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [b0d4839]
Page Load Metrics (1688 ± 74 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15322111168715474
domContentLoaded15232105165615474
load15322111168815474
domInteractive237036157
backgroundConnect980342311
firstReactRender1674332210
getState55717199
initialActions01000
loadScripts10631582119913766
setupStore85316147
uiStartup17542392192317082
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: -208.66 KiB (-2.64%)
  • common: -8.56 KiB (-0.09%)

@pedronfigueiredo pedronfigueiredo added this pull request to the merge queue Feb 5, 2025
Merged via the queue into main with commit b4fc88e Feb 5, 2025
72 checks passed
@pedronfigueiredo pedronfigueiredo deleted the pnf/4062 branch February 5, 2025 11:02
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 2025
@metamaskbot metamaskbot added the release-12.13.0 Issue or pull request that will be included in release 12.13.0 label Feb 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
QA Passed release-12.13.0 Issue or pull request that will be included in release 12.13.0 team-confirmations Push issues to confirmations team
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants