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: Add SnapInsightsController #2555

Merged
merged 10 commits into from
Jul 12, 2024
Merged

Conversation

FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Jul 9, 2024

This PR adds SnapInsightsController, which is meant to handle fetching a persistent response from transaction/signature insight Snaps. This controller will temporarily store the insight response, letting the client UI consume it wherever necessary.

The controller listens to events from TransactionController and SignatureController to determine when new signatures or transactions have entered the state. The events immediately trigger requests to any available Snaps. The controller also manages cleaning up its own state as well as the interface state when a confirmation finishes.

Most of the controller logic should mirror the implementation currently found in the extension. With the exception that this controller now populates the state as Snaps respond instead of waiting for all the Snaps to load before triggering a state update.

Closes #2560

Copy link

socket-security bot commented Jul 9, 2024

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

@FrederikBolding FrederikBolding changed the title feat: Add SnapInsightController feat: Add SnapInsightsController Jul 9, 2024
@FrederikBolding
Copy link
Member Author

@metamaskbot update-pr

@FrederikBolding FrederikBolding force-pushed the fb/snap-insight-controller branch from 875565c to 5b90101 Compare July 10, 2024 08:12
@FrederikBolding FrederikBolding force-pushed the fb/snap-insight-controller branch from 3327cf8 to f6dba70 Compare July 11, 2024 09:42
@FrederikBolding FrederikBolding marked this pull request as ready for review July 11, 2024 10:47
@FrederikBolding FrederikBolding requested a review from a team as a code owner July 11, 2024 10:47
Copy link

codecov bot commented Jul 11, 2024

Codecov Report

Attention: Patch coverage is 98.73418% with 1 line in your changes missing coverage. Please review.

Project coverage is 93.99%. Comparing base (1480459) to head (bccbbcb).

Files Patch % Lines
...ackages/snaps-controllers/src/types/controllers.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2555      +/-   ##
==========================================
+ Coverage   93.95%   93.99%   +0.03%     
==========================================
  Files         456      459       +3     
  Lines        9568     9647      +79     
  Branches     1465     1480      +15     
==========================================
+ Hits         8990     9068      +78     
- Misses        578      579       +1     

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

import type { Hex, Json } from '@metamask/utils';

// Partial types that should overlap with types from controllers.
export type TransactionMeta = {
Copy link
Member

Choose a reason for hiding this comment

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

It's not ideal that we have to copy this. Can we add a dev dependency and type tests to make sure the types are in sync at least?

}) {
this.update((state) => {
state.insights[id][snapId].loading = false;
state.insights[id][snapId].interfaceId = response?.id as string;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a type cast here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The response type is typed as Json, but we know the return type for an insight Snap will contain id as a string or undefined.

@FrederikBolding FrederikBolding changed the title feat: Add SnapInsightsController feat: Add SnapInsightsController Jul 12, 2024
@FrederikBolding FrederikBolding merged commit c7f73bd into main Jul 12, 2024
156 checks passed
@FrederikBolding FrederikBolding deleted the fb/snap-insight-controller branch July 12, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move insights logic to SnapInsightsController
3 participants