fetchTokenList method

Future<List<TokenInfo>> fetchTokenList()

fetch token list. if catch Error, return staticTokenList

Implementation

Future<List<TokenInfo>> fetchTokenList() async {
  final responses = await Future.wait<TokenList>(
    repositories.map((url) async {
      try {
        final resp = await http.get(Uri.parse(url));
        final tokenList = TokenList.fromJson(json.decode(resp.body) as Map);
        return tokenList;
      } catch (e) {
        print(e);
        return staticTokenList;
      }
    }),
  );
  final tokenInfoList = responses
      .map((e) => e.tokens)
      .where((e) => e.isNotEmpty)
      .reduce((value, element) => value + element);
  return tokenInfoList.toList();
}