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: Integrate Snaps into the redesigned confirmations #26435

Merged
merged 5 commits into from
Aug 22, 2024

Conversation

FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Aug 15, 2024

Description

This PR integrates Snaps insights into the redesigned signature confirmations, showing them at the bottom using the new Delineator component. Snaps are exposed to the new confirmations via SnapsSection and SnapInsight, these two components use the newly written useInsightSnaps hook.

By request of @eriknson this PR makes some slight adjustments to the Delineator component, tweaking the font colors, adding a disabled state etc.

This PR does not integrate Snaps into the alert system, that'll be done in a follow-up PR at a later date.

Open in GitHub Codespaces

Related issues

Closes MetaMask/snaps#2530

Manual testing steps

  1. Install the signature insights example Snap from https://metamask.github.io/snaps/test-snaps/latest/
  2. Use the test-dapp to trigger any signature confirmation
  3. See that insights are now present at the bottom of the signature confirmation.

Screenshots/Recordings

image

@FrederikBolding FrederikBolding added the team-snaps-platform Snaps Platform team label Aug 15, 2024
@FrederikBolding FrederikBolding force-pushed the fb/confirmation-redesign-insights branch from 9f0dd14 to 59f7357 Compare August 22, 2024 07:31
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Aug 22, 2024
@FrederikBolding FrederikBolding force-pushed the fb/confirmation-redesign-insights branch from 0523104 to 02025bf Compare August 22, 2024 10:45
Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.05%. Comparing base (b3865bc) to head (a331fa1).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26435      +/-   ##
===========================================
+ Coverage    70.04%   70.05%   +0.01%     
===========================================
  Files         1411     1411              
  Lines        49205    49210       +5     
  Branches     13754    13758       +4     
===========================================
+ Hits         34463    34472       +9     
+ Misses       14742    14738       -4     

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

@FrederikBolding FrederikBolding marked this pull request as ready for review August 22, 2024 11:07
@FrederikBolding FrederikBolding requested review from a team as code owners August 22, 2024 11:07
@metamaskbot
Copy link
Collaborator

Builds ready [02025bf]
Page Load Metrics (99 ± 23 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint933941336431
domContentLoaded58290974923
load61290994823
domInteractive2110240199
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 10.98 KiB (0.15%)
  • common: -16 Bytes (-0.00%)

Copy link

sonarcloud bot commented Aug 22, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [a331fa1]
Page Load Metrics (85 ± 10 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint791641152211
domContentLoaded44152822411
load51152852110
domInteractive126330136
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 10.98 KiB (0.15%)
  • common: -16 Bytes (-0.00%)

@@ -38,7 +38,7 @@ const ExpandableIcon = ({ isExpanded }: { isExpanded: boolean }) => {
<Icon
name={isExpanded ? IconName.ArrowUp : IconName.ArrowDown}
size={IconSize.Sm}
color={IconColor.iconMuted}
color={IconColor.primaryDefault}
Copy link
Member

Choose a reason for hiding this comment

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

Minor, would it have value for audit to include a before screenshot with the old styling?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! This is roughly what the integration looked like before the design changes.

image


export const SnapsSection = () => {
const currentConfirmation = useSelector(currentConfirmationSelector);
const { data } = useInsightSnaps(currentConfirmation?.id);
Copy link
Member

Choose a reason for hiding this comment

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

Just for my own understanding, am I right that the hook and underlying controller don't use the actual frontend data itself, but rather query the data direct from the controllers using just the ID?

This should be harmless if so given I believe both signatures and transactions uses UUIDs for IDs so clashes are almost impossible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed! SnapInsightsController populates metamask.insights[ID] per transaction and signature that it detects via the events emitted by the TransactionController and SignatureController. It assumes the IDs doesn't clash, which should be safe given that they are UUIDs. For more details see: MetaMask/snaps#2555

<SnapInsight
key={snapId}
snapId={snapId}
interfaceId={interfaceId}
Copy link
Member

@matthewwalsh0 matthewwalsh0 Aug 22, 2024

Choose a reason for hiding this comment

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

Am I right that the hook and insight controller don't return any actual data or JSON to the UI, but just this interface ID that corresponds to a template in the state via the controller?

Copy link
Member Author

@FrederikBolding FrederikBolding Aug 22, 2024

Choose a reason for hiding this comment

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

Yes! All that is stored in the insights controller are these interfaceIds. They are effectively a pointer to an interface stored in state at metamask.interfaces, which is constructed using the Snaps UI JSX syntax. The SnapUIRenderer takes this interface ID and renders the interface that is available in state. For certain Snaps this interface may change over time, e.g. with a button press or some other trigger. The SnapUIRenderer handles re-rendering the interface when that happens!

@FrederikBolding FrederikBolding merged commit d81d69b into develop Aug 22, 2024
78 checks passed
@FrederikBolding FrederikBolding deleted the fb/confirmation-redesign-insights branch August 22, 2024 14:23
@github-actions github-actions bot locked and limited conversation to collaborators Aug 22, 2024
@metamaskbot metamaskbot added the release-12.5.0 Issue or pull request that will be included in release 12.5.0 label Aug 22, 2024
@gauthierpetetin gauthierpetetin added release-12.4.0 Issue or pull request that will be included in release 12.4.0 and removed release-12.5.0 Issue or pull request that will be included in release 12.5.0 labels Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
INVALID-PR-TEMPLATE PR's body doesn't match template release-12.4.0 Issue or pull request that will be included in release 12.4.0 team-snaps-platform Snaps Platform team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate signature insights into the redesigned signature screens
6 participants