isValidNamespacesEvent static method

bool isValidNamespacesEvent({
  1. required Map<String, Namespace> namespaces,
  2. required String chainId,
  3. required String eventName,
})

Validates the provided chainId, then gets the events for that chainId and ensures that the event request is contained in the events

Implementation

static bool isValidNamespacesEvent({
  required Map<String, Namespace> namespaces,
  required String chainId,
  required String eventName,
}) {
  // Validate the chainId
  if (!NamespaceUtils.isValidChainId(chainId)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_CHAINS,
      context: 'chain $chainId should conform to "CAIP-2" format',
    ).toSignError();
  }

  // Validate the namespaces
  isValidNamespaces(
    namespaces: namespaces,
    context: 'isValidNamespacesEvent',
  );

  List<dynamic> events = NamespaceUtils.getNamespacesEventsForChain(
    namespaces: namespaces,
    chainId: chainId,
  );

  if (!events.contains(eventName)) {
    throw Errors.getSdkError(
      Errors.UNSUPPORTED_EVENTS,
      context: 'The event $eventName is not supported',
    ).toSignError();
  }

  return true;
}