@@ -8,6 +8,7 @@ import type {
88 ControllerStateChangeEvent ,
99} from '@metamask/base-controller' ;
1010import { BaseController } from '@metamask/base-controller' ;
11+ import type { InternalAccount } from '@metamask/keyring-internal-api' ;
1112import type {
1213 MaybeUpdateState ,
1314 TestOrigin ,
@@ -22,14 +23,15 @@ import type {
2223import { ContentType } from '@metamask/snaps-sdk' ;
2324import type { JSXElement } from '@metamask/snaps-sdk/jsx' ;
2425import { getJsonSizeUnsafe , validateJsxLinks } from '@metamask/snaps-utils' ;
25- import type { CaipAssetType , Json } from '@metamask/utils' ;
26- import { assert , hasProperty } from '@metamask/utils' ;
26+ import type { CaipAccountId , CaipAssetType , Json } from '@metamask/utils' ;
27+ import { assert , hasProperty , parseCaipAccountId } from '@metamask/utils' ;
2728import { castDraft } from 'immer' ;
2829import { nanoid } from 'nanoid' ;
2930
3031import {
3132 constructState ,
3233 getJsxInterface ,
34+ validateAssetSelector ,
3335 validateInterfaceContext ,
3436} from './utils' ;
3537import type { GetSnap } from '../snaps' ;
@@ -68,6 +70,11 @@ export type ResolveInterface = {
6870 handler : SnapInterfaceController [ 'resolveInterface' ] ;
6971} ;
7072
73+ type AccountsControllerGetAccountByAddressAction = {
74+ type : `AccountsController:getAccountByAddress`;
75+ handler : ( address : string ) => InternalAccount | undefined ;
76+ } ;
77+
7178export type SnapInterfaceControllerGetStateAction = ControllerGetStateAction <
7279 typeof controllerName ,
7380 SnapInterfaceControllerState
@@ -89,7 +96,8 @@ export type SnapInterfaceControllerAllowedActions =
8996 | HasApprovalRequest
9097 | AcceptRequest
9198 | GetSnap
92- | MultichainAssetsControllerGetStateAction ;
99+ | MultichainAssetsControllerGetStateAction
100+ | AccountsControllerGetAccountByAddressAction ;
93101
94102export type SnapInterfaceControllerActions =
95103 | CreateInterface
@@ -442,6 +450,27 @@ export class SnapInterfaceController extends BaseController<
442450 ) ;
443451 }
444452
453+ /**
454+ * Get an account by its address.
455+ *
456+ * @param address - The account address.
457+ * @returns The account or undefined if not found.
458+ */
459+ #getAccountByAddress( address : CaipAccountId ) {
460+ const { address : parsedAddress } = parseCaipAccountId ( address ) ;
461+
462+ return this . messagingSystem . call (
463+ 'AccountsController:getAccountByAddress' ,
464+ parsedAddress ,
465+ ) ;
466+ }
467+
468+ /**
469+ * Get the asset metadata for a given asset ID.
470+ *
471+ * @param assetId - The asset ID.
472+ * @returns The asset metadata or undefined if not found.
473+ */
445474 #getAssetMetadata( assetId : CaipAssetType ) {
446475 // TODO: Introduce an action in MultichainAssetsController to get a specific asset metadata.
447476 const assets = this . messagingSystem . call (
@@ -472,6 +501,8 @@ export class SnapInterfaceController extends BaseController<
472501 this . #checkPhishingList. bind ( this ) ,
473502 ( id : string ) => this . messagingSystem . call ( 'SnapController:get' , id ) ,
474503 ) ;
504+
505+ validateAssetSelector ( element , this . #getAccountByAddress. bind ( this ) ) ;
475506 }
476507
477508 #onNotificationsListUpdated( notificationsList : Notification [ ] ) {
0 commit comments