parseEvent static method

  1. @visibleForTesting
MoonetixEvent? parseEvent(
  1. Object? arguments
)

Turns a native event map (type, and code and message for errors) into a MoonetixEvent. Returns null for anything it does not know.

Implementation

@visibleForTesting
static MoonetixEvent? parseEvent(Object? arguments) {
  if (arguments is! Map) {
    return null;
  }
  switch (arguments['type']) {
    case 'opened':
      return const MoonetixOpened();
    case 'closed':
      return const MoonetixClosed();
    case 'error':
      final Object? code = arguments['code'];
      final Object? message = arguments['message'];
      return MoonetixErrorEvent(MoonetixError(
        MoonetixErrorCode.fromWireName(code is String ? code : null),
        message is String && message.isNotEmpty
            ? message
            : 'The offerwall reported an error.',
      ));
  }
  return null;
}