switchChain static method

Future<Map<String, dynamic>> switchChain(
  1. SwitchChainParameters switchChainParameters, {
  2. String configKey = 'default',
})

Implementation

static Future<Map<String, dynamic>> switchChain(
    SwitchChainParameters switchChainParameters, {
      String configKey = 'default',
    }) =>
    _guardFuture(() async {
      _logAction('switchChain');
      final result = await window.wagmiCore
          .switchChain(
        configKey.toJS,
        switchChainParameters.toJS,
      )
          .toDart;

      // Try different conversion strategies for WASM compatibility
      try {
        // First try: Use UtilsJS.dartify for the entire object
        final converted = UtilsJS.dartify(result);
        if (converted is Map<String, dynamic> && converted.isNotEmpty) {
          return converted;
        }
      } catch (_) {}

      // Second try: Use the JSChain's toDart method
      try {
        return result.toDart.toMap();
      } catch (_) {}

      // Fallback: Return basic info
      return {'id': 'Chain switched', 'result': 'Success'};
    });