From bd8821eca29fe0a350fc3f0464c5339a5e9a6916 Mon Sep 17 00:00:00 2001 From: Nikolaus Heger Date: Thu, 3 Oct 2024 13:53:01 +0800 Subject: [PATCH] set firebase token on launch (#1961) made code less messy --- .../get_token_models_use_case.dart | 25 ++++++++++--------- .../app/interactor/viewmodels/app_bloc.dart | 8 ++++++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/domain-shared/shared_use_cases/get_token_models_use_case.dart b/lib/domain-shared/shared_use_cases/get_token_models_use_case.dart index 22d7c8518..0bfbacde8 100644 --- a/lib/domain-shared/shared_use_cases/get_token_models_use_case.dart +++ b/lib/domain-shared/shared_use_cases/get_token_models_use_case.dart @@ -83,19 +83,20 @@ class GetTokenModelsUseCase extends InputUseCase, TokenModelSel List theseTokens = []; /// verify token contract on chain and get contract precision - loadData(token) async { - TokenModel? tm = TokenModel.fromJson(token as Map); + Future loadData(dynamic token) async { + final TokenModel? tm = TokenModel.fromJson(token as Map); 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); + } } } diff --git a/lib/screens/app/interactor/viewmodels/app_bloc.dart b/lib/screens/app/interactor/viewmodels/app_bloc.dart index c5480a3e1..2aeafaf90 100644 --- a/lib/screens/app/interactor/viewmodels/app_bloc.dart +++ b/lib/screens/app/interactor/viewmodels/app_bloc.dart @@ -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'; @@ -64,6 +66,12 @@ class AppBloc extends Bloc { } Future _onAppMounted(OnAppMounted event, Emitter 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