getAllChains static method

List<ChainInfo> getAllChains([
  1. int comparator(
    1. ChainInfo,
    2. ChainInfo
    )?
])

Implementation

static List<ChainInfo> getAllChains(
    [int Function(ChainInfo, ChainInfo)? comparator]) {
  List<ChainInfo> list = ParticleChains.values.toList();

  List<String> sortKeys = [
    'Solana',
    'Ethereum',
    'BSC',
    'opBNB',
    'Polygon',
    'Avalanche',
    'Moonbeam',
    'Moonriver',
    'Heco',
    'Fantom',
    'Arbitrum',
    'Harmony',
    'Aurora',
    'Optimism',
    'KCC',
    'PlatON',
    'Tron',
  ];

  if (comparator != null) {
    list.sort(comparator);
    return list;
  }

  list.sort((ChainInfo a, ChainInfo b) {
    if (sortKeys.contains(a.name) && sortKeys.contains(b.name)) {
      if (a.name == b.name) {
        if (a.network == 'Mainnet') {
          return -1;
        } else if (b.network == 'Mainnet') {
          return 1;
        }
        return 0;
      } else if (sortKeys.indexOf(a.name) > sortKeys.indexOf(b.name)) {
        return 1;
      }
      return -1;
    } else if (sortKeys.contains(a.name)) {
      return -1;
    } else if (sortKeys.contains(b.name)) {
      return 1;
    } else if (a.name == b.name) {
      if (a.network == 'Mainnet') {
        return -1;
      } else if (b.network == 'Mainnet') {
        return 1;
      }
      return a.fullname.compareTo(b.fullname);
    } else {
      return a.name.compareTo(b.name);
    }
  });

  return list;
}