isValidChains static method

bool isValidChains({
  1. required String nsOrChainId,
  2. List<String>? chains,
  3. required String context,
})

This function will throw an error if

  1. the nsOrChainId parameter is a chainId, and the chains param exists
  2. The list of chains contains an invalid chainId

Implementation

static bool isValidChains({
  required String nsOrChainId,
  List<String>? chains,
  required String context,
}) {
  // If the key is a valid chain Id, then the chains should be empty
  final bool isChainId = NamespaceUtils.isValidChainId(nsOrChainId);
  if (isChainId) {
    if (chains != null && chains.isNotEmpty) {
      throw Errors.getSdkError(
        Errors.UNSUPPORTED_CHAINS,
        context: '$context, namespace is a chainId, but chains is not empty',
      ).toSignError();
    }
  } else {
    for (String c in chains!) {
      if (!NamespaceUtils.isValidChainId(c)) {
        throw Errors.getSdkError(
          Errors.UNSUPPORTED_CHAINS,
          context: '$context, chain $c should conform to "CAIP-2" format',
        ).toSignError();
      }
    }
  }

  return true;
}