Skip to content

Commit

Permalink
errors fix, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
n13 committed Jun 22, 2024
1 parent bd5505e commit ac72252
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
5 changes: 0 additions & 5 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ linter:
always_put_control_body_on_new_line: true
use_string_buffers: false
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
always_require_non_null_named_parameters: true
always_specify_types: false
always_use_package_imports: true
annotate_overrides: true
Expand Down Expand Up @@ -97,13 +96,10 @@ linter:
hash_and_equals: true
implementation_imports: true
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
iterable_contains_unrelated_type: true
# - join_return_with_assignment # not required by flutter style
leading_newlines_in_multiline_strings: true
library_names: true
library_prefixes: true
#- lines_longer_than_80_chars # not required by flutter style
list_remove_unrelated_type: true
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
missing_whitespace_between_adjacent_strings: true
no_adjacent_strings_in_list: true
Expand Down Expand Up @@ -134,7 +130,6 @@ linter:
prefer_constructors_over_static_methods: true
prefer_contains: true
# - prefer_double_quotes # opposite of prefer_single_quotes
prefer_equal_for_default_values: true
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
prefer_final_fields: true
prefer_final_in_for_each: true
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/remote/model/token_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class TokenModel extends Equatable {

static String getAssetString(String? id, double quantity) {
if (id != null && TokenModel.fromId(id) != null && contractPrecisions.containsKey(id)) {
final symbol = TokenModel.fromId(id)!.symbol;
final symbol = TokenModel.fromId(id)?.symbol;
return symbol == null ? "" : "${quantity.toStringAsFixed(contractPrecisions[id]!)} $symbol";
} else {
return "";
Expand Down
54 changes: 26 additions & 28 deletions lib/domain-shared/shared_use_cases/get_token_models_use_case.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:collection/collection.dart';
import 'package:dynamic_parallel_queue/dynamic_parallel_queue.dart';
import 'package:seeds/datasource/remote/api/tokenmodels_repository.dart';
import 'package:seeds/datasource/remote/api/stat_repository.dart';
import 'package:seeds/datasource/remote/api/tokenmodels_repository.dart';
import 'package:seeds/datasource/remote/model/token_model.dart';
import 'package:seeds/domain-shared/base_use_case.dart';
import 'package:seeds/screens/wallet/components/tokens_cards/interactor/usecases/load_token_balances_use_case.dart';

class TokenModelSelector {
final List<String> acceptList;
Expand All @@ -23,25 +22,24 @@ class GetTokenModelsUseCase extends InputUseCase<List<TokenModel>, TokenModelSel
Future<Result<List<TokenModel>>> run(TokenModelSelector input) async {
print("[http] importing token models");
final idSet = <int>{};
final useCaseMap = <int, List<String>>{} ;
final useCaseMap = <int, List<String>>{};

/// accumulate accepted token id's in idSet
/// record valid usecases (from both acceptList and infoList) for each token in useCaseMap
for(final useCase in input.acceptList + (input.infoList ?? [])) {
for (final useCase in input.acceptList + (input.infoList ?? [])) {
bool more = true;
int lastRetrieved = -1;
fetchOneUseCase:
while(more) {
final acceptedTokenIdsResult = await TokenModelsRepository()
.getAcceptedTokenIds(useCase, lastRetrieved+1);
if(acceptedTokenIdsResult.isError) {
while (more) {
final acceptedTokenIdsResult = await TokenModelsRepository().getAcceptedTokenIds(useCase, lastRetrieved + 1);
if (acceptedTokenIdsResult.isError) {
break fetchOneUseCase;
}
final resultValue = acceptedTokenIdsResult.asValue!.value;
more = resultValue['more'];
final acceptances = resultValue['rows'].toList();
final tokenIds = List<int>.from(
acceptances.map((row) => row['token_id']).toList());
if(tokenIds.isEmpty) {
final tokenIds = List<int>.from(acceptances.map((row) => row['token_id']).toList());
if (tokenIds.isEmpty) {
continue;
}
for (final id in tokenIds) {
Expand All @@ -59,9 +57,8 @@ class GetTokenModelsUseCase extends InputUseCase<List<TokenModel>, TokenModelSel
remainingIds.sort();
bool more = true;
final rv = <TokenModel>[];
while(more && remainingIds.isNotEmpty) {
final allTokensResult = await TokenModelsRepository()
.getMasterTokenTable(remainingIds[0]);
while (more && remainingIds.isNotEmpty) {
final allTokensResult = await TokenModelsRepository().getMasterTokenTable(remainingIds[0]);
if (allTokensResult.isError) {
return Result.error("failed to get master token list");
}
Expand All @@ -77,30 +74,31 @@ class GetTokenModelsUseCase extends InputUseCase<List<TokenModel>, TokenModelSel
return false;
}
}).toList();

/// retrieve entire list of tokens from master list, then filter by idSet; paginate by "more"
for (final token in tokens) {
token['usecases'] = useCaseMap[token['id']];
}
final StatRepository _statRepository = StatRepository();
List<TokenModel?> theseTokens = [];

/// verify token contract on chain and get contract precision
loadData(token) async {
TokenModel? tm = TokenModel.fromJson(token as Map<String, dynamic>);
if (tm != null) {
await _statRepository
.getTokenStat(tokenContract: tm.contract, symbol: tm.symbol)
.then(
(stats) async {
if (stats.asValue != null) {
final supply = stats.asValue!.value.supplyString;
tm.setPrecisionFromString(supply);
theseTokens.add(tm);
print("supply: $supply");
}
},
).catchError((dynamic error) => _statRepository.mapHttpError(error));
await _statRepository.getTokenStat(tokenContract: tm.contract, symbol: tm.symbol).then(
(stats) async {
if (stats.asValue != null) {
final supply = stats.asValue!.value.supplyString;
tm.setPrecisionFromString(supply);
theseTokens.add(tm);
print("supply: $supply");
}
},
).catchError((dynamic error) => _statRepository.mapHttpError(error));
}
}

final queue = Queue(parallel: 5);
for (final dynamic token in tokens) {
queue.add(() async {
Expand All @@ -109,9 +107,9 @@ class GetTokenModelsUseCase extends InputUseCase<List<TokenModel>, TokenModelSel
}
await queue.whenComplete();
rv.addAll(theseTokens.whereNotNull());
/// build a TokenModel from each selected token's metadata

/// build a TokenModel from each selected token's metadata
}
return Result.value(rv);
}

}

0 comments on commit ac72252

Please sign in to comment.