Skip to content

Contract class balances method calls are typed as implicit any #4464

Open
@MajorLift

Description

@MajorLift

In the following, contract.balances and result are implicitly typed as any, because the Contract class doesn't have a balances method.

import { Contract } from '@ethersproject/contracts';
...
async getBalancesInSingleCall(
  ...
  ) {
    ...
    const contract = new Contract(
      contractAddress,
      abiSingleCallBalancesContract,
      provider,
    );
    const result = await contract.balances([selectedAddress], tokensToDetect);
    const nonZeroBalances: BalanceMap = {};
    /* istanbul ignore else */
    if (result.length > 0) {
      tokensToDetect.forEach((tokenAddress, index) => {
        const balance: BN = result[index];
        /* istanbul ignore else */
        if (String(balance) !== '0') {
          nonZeroBalances[tokenAddress] = balance;
        }
      });
    }
    return nonZeroBalances;
  }
}

https://github.com/MetaMask/core/blob/main/packages/assets-controllers/src/AssetsContractController.ts#L522-L554

All tests for getBalancesInSingleCall only check for toBeDefined() or strictEquals({}), with the exception of the following:

  • 'should track and use the currently selected chain ID and provider when getting balances in a single call'

The fact that this test passes at runtime suggests that either this bug is only an issue at the type level, or there is a fallback method being called instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions