Skip to content

feat: add supported for typedSignData V1#23539

Merged
jpuri merged 6 commits intodevelopfrom
typed_sign_v1
Mar 26, 2024
Merged

feat: add supported for typedSignData V1#23539
jpuri merged 6 commits intodevelopfrom
typed_sign_v1

Conversation

@jpuri
Copy link
Copy Markdown
Contributor

@jpuri jpuri commented Mar 18, 2024

Description

Re-design implementation for typed sign V1 signature requests.

Related issues

Fixes: #23481

Manual testing steps

  1. Enable re-designs locally
  2. Go to test dapp
  3. Submit typed sign V1 message signature

Screenshots/Recordings

Screenshot 2024-03-18 at 10 24 44 AM

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@jpuri jpuri added team-confirmations-secure-ux-PR PRs from the confirmations team needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) confirmation-redesign labels Mar 18, 2024
@jpuri jpuri requested a review from a team as a code owner March 18, 2024 04:52
@github-actions
Copy link
Copy Markdown
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.

@jpuri jpuri changed the title Add supported for typedSignData V1 feat: add supported for typedSignData V1 Mar 18, 2024
const t = useI18nContext();
const currentConfirmation = useSelector(currentConfirmationSelector);

if (!currentConfirmation?.msgParams) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it possible for currentConfirmation to be undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TS complains if I do not use ?


describe('personalSign', () => {
it('renders origin for personal sign request', () => {
describe('PersonalSignInfo', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In case the currentConfirmation can be undefined, should we add a test for that?

Copy link
Copy Markdown
Contributor Author

@jpuri jpuri Mar 22, 2024

Choose a reason for hiding this comment

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

Not really... but since hook can possible return undefined, TS requires me to handle it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for optional chainig.. we have arleady validated in the previous if clause

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also would love if we could avoid type casting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep optional chaining can be avoided here but typecasting not

Comment on lines 28 to 33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be abstracted in the ConfirmationInfoConponentMap?
We could isolate Confirmation component selection logic within it (in my opinion making it more isolate and readable). Something like:

const getTypedSignInfo = (currentConfirmation) => {
  const { version } = currentConfirmation?.msgParams ?? {};
  if (version === 'V1') {
    return TypedSignV1Info;
  }

  return TypedSignInfo;
}

const ConfirmationInfoConponentMap = {
  [TransactionType.personalSign]: () => PersonalSignInfo,
  [TransactionType.signTypedData]: getTypedSignInfo,
};

...

const InfoComponent =
    ConfirmationInfoConponentMap[currentConfirmation?.type as ConfirmationType](currentConfirmation);

What do you think?

(Also just noticed, ConfirmationInfoConponentMap has a typo.. should be ConfirmationInfoComponentMap)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can do it either way, since the logic will stay in 1 file to me either looks ok

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PR is updated

Base automatically changed from typed_sign_mmi to develop March 22, 2024 15:36
@jpuri jpuri requested a review from cryptotavares March 22, 2024 16:27
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 95.83333% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 69.30%. Comparing base (8b12ade) to head (04efefe).

Files Patch % Lines
...ges/confirmations/components/confirm/info/info.tsx 90.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #23539      +/-   ##
===========================================
+ Coverage    69.28%   69.30%   +0.02%     
===========================================
  Files         1158     1160       +2     
  Lines        44069    44083      +14     
  Branches     11758    11760       +2     
===========================================
+ Hits         30531    30548      +17     
+ Misses       13538    13535       -3     

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

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [04efefe]
Page Load Metrics (451 ± 336 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint621611172713
domContentLoaded1384372311
load502021451700336
domInteractive1384372311
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@jpuri jpuri merged commit 23c2d27 into develop Mar 26, 2024
@jpuri jpuri deleted the typed_sign_v1 branch March 26, 2024 14:32
@github-actions github-actions bot removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Mar 26, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2024
@metamaskbot metamaskbot added the release-11.15.0 Issue or pull request that will be included in release 11.15.0 label Mar 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

confirmation-redesign release-11.15.0 Issue or pull request that will be included in release 11.15.0 team-confirmations-secure-ux-PR PRs from the confirmations team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Confirmation redesign - add support for type sign V1

5 participants