@@ -192,27 +192,36 @@ export class AssetsContractController {
192
192
this . ipfsGateway = IPFS_DEFAULT_GATEWAY_URL ;
193
193
this . chainId = initialChainId ;
194
194
195
- this . messagingSystem . registerActionHandler (
196
- 'AssetsContractController:getERC20Standard' ,
197
- this . getERC20Standard . bind ( this ) ,
198
- ) ;
199
- this . messagingSystem . registerActionHandler (
200
- 'AssetsContractController:getERC721Standard' ,
201
- this . getERC721Standard . bind ( this ) ,
202
- ) ;
203
- this . messagingSystem . registerActionHandler (
204
- 'AssetsContractController:getERC1155Standard' ,
205
- this . getERC1155Standard . bind ( this ) ,
206
- ) ;
207
- this . messagingSystem . registerActionHandler (
208
- 'AssetsContractController:getTokenStandardAndDetails' ,
209
- this . getTokenStandardAndDetails . bind ( this ) ,
210
- ) ;
211
- this . messagingSystem . registerActionHandler (
212
- 'AssetsContractController:getBalancesInSingleCall' ,
213
- this . getBalancesInSingleCall . bind ( this ) ,
214
- ) ;
195
+ this . #registerActionHandlers( ) ;
196
+ this . #registerEventSubscriptions( ) ;
197
+ }
215
198
199
+ // TODO: Expand into base-controller utility function that batch registers action handlers.
200
+ #registerActionHandlers( ) {
201
+ for ( const method of Object . getOwnPropertyNames (
202
+ Object . getPrototypeOf ( this ) ,
203
+ ) as ( keyof this) [ ] ) {
204
+ if (
205
+ ( ( key : keyof this) : key is AssetsContractControllerMethodName =>
206
+ ! [
207
+ 'constructor' ,
208
+ 'messagingSystem' ,
209
+ 'provider' ,
210
+ 'ipfsGateway' ,
211
+ 'chainId' ,
212
+ ] . find ( ( e ) => e === key ) && typeof this [ key ] === 'function' ) ( method )
213
+ ) {
214
+ this . messagingSystem . registerActionHandler (
215
+ `${ name } :${ method } ` ,
216
+ // TODO: Write a for-loop function that iterates over an input union type in tandem with the input array.
217
+ // @ts -expect-error Both assigned argument and assignee parameter are using the entire union type for `method`
218
+ this [ method ] . bind ( this ) ,
219
+ ) ;
220
+ }
221
+ }
222
+ }
223
+
224
+ #registerEventSubscriptions( ) {
216
225
this . messagingSystem . subscribe (
217
226
`PreferencesController:stateChange` ,
218
227
( { ipfsGateway } ) => {
@@ -232,7 +241,6 @@ export class AssetsContractController {
232
241
233
242
if ( this . chainId !== chainId ) {
234
243
this . chainId = chainId ;
235
-
236
244
// @ts -expect-error TODO: remove this annotation once the `Eip1193Provider` class is released
237
245
this . #provider = this . #getCorrectProvider( ) ;
238
246
}
0 commit comments