Skip to content

Add Petnames Name Component to Transaction Approval Screen#22190

Merged
dbrans merged 15 commits intodevelopfrom
dbrans/petnames-name-display
Jan 9, 2024
Merged

Add Petnames Name Component to Transaction Approval Screen#22190
dbrans merged 15 commits intodevelopfrom
dbrans/petnames-name-display

Conversation

@dbrans
Copy link
Copy Markdown
Contributor

@dbrans dbrans commented Dec 6, 2023

Description

Currently

The extension uses the SenderToRecipient React component to display the from and to address when creating most types of transaction. This is displayed in the header of most transaction confirmations:

Image

This internally uses a RecipientWithAddress component to render the target of the transaction.

This currently also supports names and nicknames but by using state from the AddressBookController, EnsController, and the names of the wallet accounts.

Goal of this PR

  • use the Name component in the RecipientWithAddress component to use petnames to display the transaction to address.
  • Continue to use the usePetnamesEnabled hook to only use the Name component if the petnames build feature is enabled.

Notes

Once petnames is in main, the build feature can be removed and the legacy code removed in a separate PR.

See the Name component storybook entry for usage details.

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/1625
Fixes: https://github.com/MetaMask/MetaMask-planning/issues/1626

Manual testing steps

In a flask build:

  1. Click the Send button on the home screen
  2. Fill out an address to send to.
  3. On the confirmation screen you should see the recipient inside a name component (shaped like a pill) with either a warning or a bookmark icon, depending on whether or not there is a petname for this address-chain combination.

Screenshots/Recordings

Before

Image

After

image

Pre-merge author checklist

  • Add Tests
  • 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 6, 2023

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.

@dbrans dbrans force-pushed the dbrans/petnames-name-display branch 2 times, most recently from 1f3852f to ae07d8e Compare December 11, 2023 18:43
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [fec59c1]
Page Load Metrics (1271 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint89126101105
domContentLoaded9251632
load1088146812717837
domInteractive9251632
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 548 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 11, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (c6a2af2) 68.15% compared to head (eeccb97) 68.15%.
Report is 21 commits behind head on develop.

Files Patch % Lines
...nder-to-recipient/sender-to-recipient.component.js 84.62% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #22190      +/-   ##
===========================================
- Coverage    68.15%   68.15%   -0.00%     
===========================================
  Files         1081     1081              
  Lines        42346    42348       +2     
  Branches     11316    11314       -2     
===========================================
+ Hits         28858    28859       +1     
- Misses       13488    13489       +1     

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

@dbrans dbrans added the team-confirmations-system-deprecated DEPRECATED: please use "team-confirmations" instead label Dec 12, 2023
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [ab1f76c]
Page Load Metrics (1379 ± 126 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint914371818943
domContentLoaded10180526330
load95019401379263126
domInteractive10180526330
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 548 Bytes (0.01%)
  • common: 0 Bytes (0.00%)

@dbrans dbrans marked this pull request as ready for review January 8, 2024 03:58
@dbrans dbrans requested a review from a team as a code owner January 8, 2024 03:58
@dbrans dbrans changed the title Use name component to display transaction destination Add Petnames Name Component to Transaction Approval Screen Jan 8, 2024
if (name) {
const input = await driver.findElement('.form-combo-field input');
await input.fill(name);
await input.press(driver.Key.ENTER);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For sure not related with this PR, but do you happen to know the intention of pressing "Enter" here?
I was wondering maybe this is not needed since we click "Save" afterwards.

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.

Good observation. I removed it and the tests continue to pass.

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.

It turns out, pressing enter before saving is needed for firefox to get the dropdown to go away. I re-added it along with a comment to explain why.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for digging out Derek!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❤️

OGPoyraz
OGPoyraz previously approved these changes Jan 8, 2024
OGPoyraz
OGPoyraz previously approved these changes Jan 8, 2024
@dbrans dbrans merged commit de85de5 into develop Jan 9, 2024
@dbrans dbrans deleted the dbrans/petnames-name-display branch January 9, 2024 20:03
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2024
@metamaskbot metamaskbot added the release-11.9.0 Issue or pull request that will be included in release 11.9.0 label Jan 9, 2024
};

export function RecipientWithAddress({
recipientAddress,
Copy link
Copy Markdown
Member

@matthewwalsh0 matthewwalsh0 Jan 9, 2024

Choose a reason for hiding this comment

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

Do we need the non-normalized address? Does the Name component and hook not normalize any input?

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.

Moved to #22515

recipientEns ||
shortenAddress(checksummedRecipientAddress);

if (addressOnly && !displayName) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking at the original logic, is the newContract fallback used only when addressOnly is false?

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.

Good catch! Done in #22515

);
}

let displayName;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor, but could we instead assign to a const using a ternary to avoid the uninitialised let?

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.

Done in #22515

await driver.delay(3000);
}

describe('Petnames', function () {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we use alternate names here to distinguish the two sets of tests, maybe Petnames - Signatures and Petnames - Transactions?

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.

Done in #22515

await createTransactionRequest(driver);
await switchToNotificationWindow(driver, 3);
await expectName(driver, '0x0c54F...7AaFb', false);
await saveName(driver, '0x0c54F...7AaFb', 'test.lens', undefined);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In the signature tests, there were multiple addresses per confirmation, so for some we used a proposed name, and for one we saved a custom name.

Here we are exclusively using a proposed name so there is an argument that we could have a separate test for saving a transaction with a custom name, though it's low risk since we know it's fundamentally the same underlying component.

Equally we know that most transaction types ultimately use the sender-to-recipient component we've updated but for the sake of coverage, we could also add additional tests for different transaction types such as send transactions from within the wallet, or an approve transaction which uses some alternate components.

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.

Moved to #22515

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-11.9.0 Issue or pull request that will be included in release 11.9.0 team-confirmations-system-deprecated DEPRECATED: please use "team-confirmations" instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants