Skip to content

Commit 57a71ae

Browse files
committed
Use getKnownPropertyNames for iterative registerActionHandlers logic
1 parent a1fed8a commit 57a71ae

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

packages/assets-controllers/src/AssetsContractController.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
Provider,
1616
} from '@metamask/network-controller';
1717
import type { PreferencesControllerStateChangeEvent } from '@metamask/preferences-controller';
18-
import type { Hex } from '@metamask/utils';
18+
import { getKnownPropertyNames, type Hex } from '@metamask/utils';
1919
import type BN from 'bn.js';
2020
import abiSingleCallBalancesContract from 'single-call-balance-checker-abi';
2121

@@ -213,22 +213,22 @@ export class AssetsContractController {
213213
'chainId',
214214
];
215215

216-
for (const method of Object.getOwnPropertyNames(
217-
Object.getPrototypeOf(this),
218-
) as (keyof this)[]) {
219-
if (
220-
((key: keyof this): key is AssetsContractControllerMethodName =>
221-
!nonMethodClassProperties.find((e) => e === key) &&
222-
typeof this[key] === 'function')(method)
223-
) {
224-
this.messagingSystem.registerActionHandler(
225-
`${name}:${method}`,
226-
// TODO: Write a for-loop function that iterates over an input union type in tandem with the input array.
227-
// @ts-expect-error Both assigned argument and assignee parameter are using the entire union type for `method`
228-
this[method].bind(this),
229-
);
230-
}
231-
}
216+
getKnownPropertyNames<keyof this>(Object.getPrototypeOf(this)).forEach(
217+
(method) => {
218+
if (
219+
((key: keyof this): key is AssetsContractControllerMethodName =>
220+
!nonMethodClassProperties.find((e) => e === key) &&
221+
typeof this[key] === 'function')(method)
222+
) {
223+
this.messagingSystem.registerActionHandler(
224+
`${name}:${method}`,
225+
// TODO: Write a generic for-loop implementation that iterates over an input union type in tandem with the input array.
226+
// @ts-expect-error Both assigned argument and assignee parameter are using the entire union type for `method` instead of the type for the current element
227+
this[method].bind(this),
228+
);
229+
}
230+
},
231+
);
232232
}
233233

234234
#registerEventSubscriptions() {

0 commit comments

Comments
 (0)