Skip to content

Commit

Permalink
set firebase token on launch (#1961)
Browse files Browse the repository at this point in the history
made code less messy
  • Loading branch information
n13 authored Oct 3, 2024
1 parent ac72252 commit bd8821e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/domain-shared/shared_use_cases/get_token_models_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,20 @@ class GetTokenModelsUseCase extends InputUseCase<List<TokenModel>, TokenModelSel
List<TokenModel?> theseTokens = [];

/// verify token contract on chain and get contract precision
loadData(token) async {
TokenModel? tm = TokenModel.fromJson(token as Map<String, dynamic>);
Future<void> loadData(dynamic token) async {
final 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));
try {
final stats = await _statRepository.getTokenStat(tokenContract: tm.contract, symbol: tm.symbol);
if (stats.isValue) {
final supply = stats.asValue!.value.supplyString;
tm.setPrecisionFromString(supply);
theseTokens.add(tm);
print("supply: $supply");
}
} catch (error) {
_statRepository.mapHttpError(error);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions lib/screens/app/interactor/viewmodels/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:equatable/equatable.dart';
import 'package:seeds/blocs/deeplink/model/guardian_recovery_request_data.dart';
import 'package:seeds/blocs/deeplink/viewmodels/deeplink_bloc.dart';
import 'package:seeds/datasource/local/models/scan_qr_code_result_data.dart';
import 'package:seeds/datasource/local/settings_storage.dart';
import 'package:seeds/datasource/remote/firebase/firebase_message_token_repository.dart';
import 'package:seeds/domain-shared/page_command.dart';
import 'package:seeds/domain-shared/page_state.dart';
import 'package:seeds/navigation/navigation_service.dart';
Expand Down Expand Up @@ -64,6 +66,12 @@ class AppBloc extends Bloc<AppEvent, AppState> {
}

Future<void> _onAppMounted(OnAppMounted event, Emitter<AppState> emit) async {
// Firebase was misconfigured at some point
final String account = settingsStorage.accountName;
if (account != '') {
await FirebaseMessageTokenRepository().setFirebaseMessageToken(account);
}

// The first time app widged is mounted, check if there is a signing request waiting.
if (_deeplinkBloc.state.signingRequest != null) {
// When user clicks a signing deeplink
Expand Down

0 comments on commit bd8821e

Please sign in to comment.