setTokens method

  1. @action
void setTokens(
  1. List<TokenBalanceData> ls, {
  2. bool isFromCache = false,
})

Implementation

@action
void setTokens(List<TokenBalanceData> ls, {bool isFromCache = false}) {
  final data = ls;
  if (!isFromCache) {
    tokens.toList().forEach((old) {
      final newDataIndex = ls.indexWhere((token) {
        if (old.tokenNameId == null) {
          // check by token.symbol with old data cache
          return token.symbol == old.symbol || token.symbol == old.id;
        } else {
          // or check by tokenNameId with new data
          return token.tokenNameId == old.tokenNameId;
        }
      });
      if (newDataIndex < 0) {
        data.add(old);
      }
    });
  }

  tokens = data;
  isTokensFromCache = isFromCache;
}