Skip to content

Commit

Permalink
chore: Integrate SnapInsightsController
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Aug 14, 2024
1 parent 50949f8 commit fc23b5b
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 277 deletions.
24 changes: 24 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
SnapController,
IframeExecutionService,
SnapInterfaceController,
SnapInsightsController,
OffscreenExecutionService,
} from '@metamask/snaps-controllers';
import {
Expand Down Expand Up @@ -1413,6 +1414,27 @@ export default class MetamaskController extends EventEmitter {
messenger: snapInterfaceControllerMessenger,
});

const snapInsightsControllerMessenger =
this.controllerMessenger.getRestricted({
name: 'SnapInsightsController',
allowedActions: [
`${this.snapController.name}:handleRequest`,
`${this.snapController.name}:getAll`,
`${this.permissionController.name}:getPermissions`,
`${this.snapInterfaceController.name}:deleteInterface`,
],
allowedEvents: [
`TransactionController:unapprovedTransactionAdded`,
`TransactionController:transactionStatusUpdated`,
`SignatureController:stateChange`,
],
});

this.snapInsightsController = new SnapInsightsController({
state: initState.SnapInsightsController,
messenger: snapInsightsControllerMessenger,
});

// Notification Controllers
this.authenticationController = new AuthenticationController({
state: initState.AuthenticationController,
Expand Down Expand Up @@ -2212,6 +2234,7 @@ export default class MetamaskController extends EventEmitter {
SnapsRegistry: this.snapsRegistry,
NotificationController: this.notificationController,
SnapInterfaceController: this.snapInterfaceController,
SnapInsightsController: this.snapInsightsController,
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
CustodyController: this.custodyController.store,
InstitutionalFeaturesController:
Expand Down Expand Up @@ -2264,6 +2287,7 @@ export default class MetamaskController extends EventEmitter {
SnapsRegistry: this.snapsRegistry,
NotificationController: this.notificationController,
SnapInterfaceController: this.snapInterfaceController,
SnapInsightsController: this.snapInsightsController,
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
CustodyController: this.custodyController.store,
InstitutionalFeaturesController:
Expand Down
4 changes: 2 additions & 2 deletions ui/components/app/snaps/insight-warnings/insight-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export default function InsightWarnings({
return (
<Box className="insights-warnings-modal__content">
{warnings.map((warning, idx) => {
const { snapId, id } = warning;
const { snapId, interfaceId } = warning;
return (
<SnapUIRenderer
key={`${snapId}-${idx}`}
snapId={snapId}
interfaceId={id}
interfaceId={interfaceId}
delineatorType={DelineatorType.Warning}
onClick={() => handleWarningClick(snapId)}
isCollapsable
Expand Down
8 changes: 4 additions & 4 deletions ui/components/app/snaps/snap-insight/snap-insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { Copyable } from '../copyable';
import { getSnapMetadata } from '../../../../selectors';
import { trackInsightSnapUsage } from '../../../../store/actions';

export const SnapInsight = ({ snapId, data, loading }) => {
export const SnapInsight = ({ snapId, data }) => {
const dispatch = useDispatch();
const t = useI18nContext();
const isLoading = loading;
const isLoading = data?.loading;
const error = data?.error;
const interfaceId = data?.response?.id;
const interfaceId = data?.interfaceId;

useEffect(() => {
const trackInsightUsage = async () => {
Expand Down Expand Up @@ -88,7 +88,7 @@ export const SnapInsight = ({ snapId, data, loading }) => {
<Text variant={TextVariant.bodySm} marginBottom={4}>
{t('snapsUIError', [<b key="0">{snapName}</b>])}
</Text>
<Copyable text={error.message} />
<Copyable text={error} />
</SnapDelineator>
</Box>
)}
Expand Down
15 changes: 15 additions & 0 deletions ui/hooks/snaps/useInsightSnaps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useSelector } from 'react-redux';
import { SeverityLevel } from '@metamask/snaps-sdk';
import { getSnapInsights } from '../../selectors';

export function useInsightSnaps(id) {
const insight = useSelector((state) => getSnapInsights(state, id));

const data = insight ? Object.values(insight) : [];

const warnings = data.filter(
(result) => result.severity === SeverityLevel.Critical,
);

return { data, warnings };
}
130 changes: 0 additions & 130 deletions ui/hooks/snaps/useSignatureInsights.js

This file was deleted.

115 changes: 0 additions & 115 deletions ui/hooks/snaps/useTransactionInsightSnaps.js

This file was deleted.

Loading

0 comments on commit fc23b5b

Please sign in to comment.