subscribeEvents method

void subscribeEvents({
  1. required dynamic onPairing(
    1. Map
    ),
  2. required dynamic onPaired(
    1. Map
    ),
  3. required dynamic onCallRequest(
    1. Map
    ),
  4. required dynamic onDisconnect(
    1. String
    ),
  5. String? uri,
  6. bool isV2 = false,
})

Implementation

void subscribeEvents({
  required Function(Map) onPairing,
  required Function(Map) onPaired,
  required Function(Map) onCallRequest,
  required Function(String) onDisconnect,
  String? uri,
  bool isV2 = false,
}) {
  serviceRoot.webView!
      .addMsgHandler("wallet_connect_message${isV2 ? '_v2' : ''}", (data) {
    final event = data['event'];
    switch (event) {
      case 'session_request':
      case 'session_proposal':
        onPairing(data);
        break;
      case 'connect':
        onPaired(data['session']);
        break;
      case 'call_request':
        onCallRequest(data);
        break;
      case 'disconnect':
        onDisconnect(uri == null ? data['topic'] : uri);
        break;
    }
  });
}