getAvailableChains method

  1. @override
List<String>? getAvailableChains()
override

Will get the list of available chains to add

Implementation

@override
List<String>? getAvailableChains() {
  // if there's no session or if supportsAddChain method then every chain can be used
  if (_currentSession == null) {
    // meaning all chains in the list are available
    return null;
  }
  // Valid only for EVM chains
  final hasSwitchMethod = _currentSession!.hasSwitchMethod();
  if (!hasSwitchMethod) {
    return getApprovedChains();
  }

  final isMagic = _currentSession!.sessionService.isMagic;
  final isCoinbase = _currentSession!.sessionService.isCoinbase;
  if (isMagic || isCoinbase) {
    return getApprovedChains();
  }

  List<String> availableChains = [];
  final namespaces = ReownAppKitModalNetworks.getAllSupportedNamespaces();
  for (var ns in namespaces) {
    final chains =
        ReownAppKitModalNetworks.getAllSupportedNetworks(namespace: ns)
            .map((e) => '$ns:${e.chainId}')
            .toList();
    availableChains.addAll(chains);
  }
  if (availableChains.isEmpty) {
    return getApprovedChains();
  }

  return availableChains;
}