Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/analytics/widgets/analytics_lifecycle_handler.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import 'package:web_dex/app_config/package_information.dart';
import 'package:web_dex/bloc/analytics/analytics_repo.dart';
import 'package:web_dex/analytics/events/user_engagement_events.dart';
import 'package:web_dex/services/platform_info/plaftorm_info.dart';
import 'package:web_dex/shared/utils/utils.dart';
import 'package:web_dex/bloc/auth_bloc/auth_bloc.dart';

/// A widget that handles analytics lifecycle events like app opened/resumed.
///
Expand Down Expand Up @@ -53,6 +55,7 @@ class _AnalyticsLifecycleHandlerState extends State<AnalyticsLifecycleHandler>
// Schedule the initial app opened event to be logged after the first frame
WidgetsBinding.instance.addPostFrameCallback((_) {
_logAppOpenedEvent();
_checkAuthStatus();
});
}

Expand All @@ -69,6 +72,7 @@ class _AnalyticsLifecycleHandlerState extends State<AnalyticsLifecycleHandler>
// Log app opened event when app is resumed (but not on initial open)
if (state == AppLifecycleState.resumed && _hasLoggedInitialOpen) {
_logAppOpenedEvent();
_checkAuthStatus();
}
}

Expand Down Expand Up @@ -100,6 +104,14 @@ class _AnalyticsLifecycleHandlerState extends State<AnalyticsLifecycleHandler>
}
}

void _checkAuthStatus() {
try {
context.read<AuthBloc>().add(const AuthLifecycleCheckRequested());
} catch (e) {
log('AnalyticsLifecycleHandler: Failed to check auth status - $e');
}
}

@override
Widget build(BuildContext context) {
return widget.child;
Expand Down
14 changes: 13 additions & 1 deletion lib/bloc/auth_bloc/auth_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> {
on<AuthRestoreRequested>(_onRestore);
on<AuthSeedBackupConfirmed>(_onSeedBackupConfirmed);
on<AuthWalletDownloadRequested>(_onWalletDownloadRequested);
on<AuthLifecycleCheckRequested>(_onLifecycleCheckRequested);
}

final KomodoDefiSdk _kdfSdk;
Expand Down Expand Up @@ -292,9 +293,20 @@ class AuthBloc extends Bloc<AuthBlocEvent, AuthBlocState> {
}
}

Future<void> _onLifecycleCheckRequested(
AuthLifecycleCheckRequested event,
Emitter<AuthBlocState> emit,
) async {
final currentUser = await _kdfSdk.auth.currentUser;
if (currentUser != null) {
emit(AuthBlocState.loggedIn(currentUser));
_listenToAuthStateChanges();
}
}

void _listenToAuthStateChanges() {
_authChangesSubscription?.cancel();
_authChangesSubscription = _kdfSdk.auth.authStateChanges.listen((user) {
_authChangesSubscription = _kdfSdk.auth.watchCurrentUser().listen((user) {
final AuthorizeMode event =
user != null ? AuthorizeMode.logIn : AuthorizeMode.noLogin;
add(AuthModeChanged(mode: event, currentUser: user));
Expand Down
6 changes: 6 additions & 0 deletions lib/bloc/auth_bloc/auth_bloc_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ class AuthWalletDownloadRequested extends AuthBlocEvent {
const AuthWalletDownloadRequested({required this.password});
final String password;
}

/// Event emitted on app lifecycle changes to check if a user is already signed
/// in and restore the auth state.
class AuthLifecycleCheckRequested extends AuthBlocEvent {
const AuthLifecycleCheckRequested();
}
3 changes: 2 additions & 1 deletion lib/bloc/bridge_form/bridge_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class BridgeBloc extends Bloc<BridgeEvent, BridgeState> {
dexRepository: dexRepository,
);

_authorizationSubscription = _kdfSdk.auth.authStateChanges.listen((event) {
_authorizationSubscription =
_kdfSdk.auth.watchCurrentUser().listen((event) {
_isLoggedIn = event != null;
if (!_isLoggedIn) add(const BridgeLogout());
});
Expand Down
5 changes: 5 additions & 0 deletions lib/bloc/coins_bloc/coins_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class CoinsBloc extends Bloc<CoinsEvent, CoinsState> {
) async {
emit(state.copyWith(coins: _coinsRepo.getKnownCoinsMap()));

final existingUser = await _kdfSdk.auth.currentUser;
if (existingUser != null) {
add(CoinsSessionStarted(existingUser));
}

add(CoinsPricesUpdated());
_updatePricesTimer?.cancel();
_updatePricesTimer = Timer.periodic(
Expand Down
3 changes: 2 additions & 1 deletion lib/bloc/dex_tab_bar/dex_tab_bar_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class DexTabBarBloc extends Bloc<DexTabBarEvent, DexTabBarState> {
ListenToOrdersRequested event,
Emitter<DexTabBarState> emit,
) {
_authorizationSubscription = _kdfSdk.auth.authStateChanges.listen((event) {
_authorizationSubscription =
_kdfSdk.auth.watchCurrentUser().listen((event) {
if (event != null) {
add(const TabChanged(0));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/nft_transactions/bloc/nft_transactions_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class NftTransactionsBloc extends Bloc<NftTxnEvent, NftTxnState> {
on<NftTxnEventFullFilterChanged>(_changeFullFilter);
on<NftTxnEventNoLogin>(_noLogin);

_authorizationSubscription = kdfSdk.auth.authStateChanges.listen((event) {
_authorizationSubscription = kdfSdk.auth.watchCurrentUser().listen((event) {
final bool prevLoginState = _isLoggedIn;
_isLoggedIn = event != null;

Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/nfts/nft_main_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class NftMainBloc extends Bloc<NftMainEvent, NftMainState> {
on<NftMainUpdateNftsStarted>(_onStartUpdate);
on<NftMainUpdateNftsStopped>(_onStopUpdate);

_authorizationSubscription = _sdk.auth.authStateChanges.listen((event) {
_authorizationSubscription = _sdk.auth.watchCurrentUser().listen((event) {
final isSignedIn = event != null;
if (isSignedIn) {
add(const NftMainChainUpdateRequested());
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/taker_form/taker_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TakerBloc extends Bloc<TakerEvent, TakerState> {
on<TakerVerifyOrderVolume>(_onVerifyOrderVolume);
on<TakerSetWalletIsReady>(_onSetWalletReady);

_authorizationSubscription = kdfSdk.auth.authStateChanges.listen((event) {
_authorizationSubscription = kdfSdk.auth.watchCurrentUser().listen((event) {
if (event != null && state.step == TakerStep.confirm) {
add(TakerBackButtonClick());
}
Expand Down
3 changes: 2 additions & 1 deletion lib/bloc/trezor_connection_bloc/trezor_connection_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class TrezorConnectionBloc
super(TrezorConnectionState.initial()) {
_trezorConnectionStatusListener = trezorRepo.connectionStatusStream
.listen(_onTrezorConnectionStatusChanged);
_authModeListener = kdfSdk.auth.authStateChanges.listen(_onAuthModeChanged);
_authModeListener =
kdfSdk.auth.watchCurrentUser().listen(_onAuthModeChanged);

on<TrezorConnectionStatusChange>(_onConnectionStatusChange);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/bloc/trezor_init_bloc/trezor_init_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TrezorInitBloc extends Bloc<TrezorInitEvent, TrezorInitState> {
on<TrezorInitSendPassphrase>(_onSendPassphrase);
on<TrezorInitUpdateAuthMode>(_onAuthModeChange);

_authorizationSubscription = _kdfSdk.auth.authStateChanges.listen((user) {
_authorizationSubscription = _kdfSdk.auth.watchCurrentUser().listen((user) {
add(TrezorInitUpdateAuthMode(user));
});
}
Expand Down
8 changes: 6 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,12 @@ class MyApp extends StatelessWidget {
return MultiBlocProvider(
providers: [
BlocProvider<AuthBloc>(
create: (_) =>
AuthBloc(komodoDefiSdk, walletsRepository, SettingsRepository()),
create: (_) {
final bloc = AuthBloc(
komodoDefiSdk, walletsRepository, SettingsRepository());
bloc.add(const AuthLifecycleCheckRequested());
return bloc;
},
),
],
child: BetterFeedback(
Expand Down
10 changes: 5 additions & 5 deletions packages/komodo_ui_kit/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ packages:
dependency: transitive
description:
name: freezed_annotation
sha256: c87ff004c8aa6af2d531668b46a4ea379f7191dc6dfa066acd53d506da6e044b
sha256: "7294967ff0a6d98638e7acb774aac3af2550777accd8149c90af5b014e6d44d8"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "3.1.0"
intl:
dependency: "direct main"
description:
Expand All @@ -95,7 +95,7 @@ packages:
description:
path: "packages/komodo_defi_rpc_methods"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -104,7 +104,7 @@ packages:
description:
path: "packages/komodo_defi_types"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -113,7 +113,7 @@ packages:
description:
path: "packages/komodo_ui"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand Down
28 changes: 14 additions & 14 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,10 @@ packages:
dependency: transitive
description:
name: freezed_annotation
sha256: c87ff004c8aa6af2d531668b46a4ea379f7191dc6dfa066acd53d506da6e044b
sha256: "7294967ff0a6d98638e7acb774aac3af2550777accd8149c90af5b014e6d44d8"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "3.1.0"
frontend_server_client:
dependency: transitive
description:
Expand Down Expand Up @@ -648,7 +648,7 @@ packages:
description:
path: "packages/komodo_cex_market_data"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.0.1"
Expand All @@ -657,7 +657,7 @@ packages:
description:
path: "packages/komodo_coin_updates"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "1.0.0"
Expand All @@ -666,7 +666,7 @@ packages:
description:
path: "packages/komodo_coins"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -675,7 +675,7 @@ packages:
description:
path: "packages/komodo_defi_framework"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0"
Expand All @@ -684,7 +684,7 @@ packages:
description:
path: "packages/komodo_defi_local_auth"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -693,7 +693,7 @@ packages:
description:
path: "packages/komodo_defi_rpc_methods"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -702,7 +702,7 @@ packages:
description:
path: "packages/komodo_defi_sdk"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -711,7 +711,7 @@ packages:
description:
path: "packages/komodo_defi_types"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -727,7 +727,7 @@ packages:
description:
path: "packages/komodo_ui"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand All @@ -743,7 +743,7 @@ packages:
description:
path: "packages/komodo_wallet_build_transformer"
ref: dev
resolved-ref: cda849860aac05b7951ea118cce58225c51c73b0
resolved-ref: "9cf9e3756542edea823edf9fb81dbb8abb8186ca"
url: "https://github.com/KomodoPlatform/komodo-defi-sdk-flutter.git"
source: git
version: "0.2.0+0"
Expand Down Expand Up @@ -799,10 +799,10 @@ packages:
dependency: transitive
description:
name: local_auth_darwin
sha256: "630996cd7b7f28f5ab92432c4b35d055dd03a747bc319e5ffbb3c4806a3e50d2"
sha256: "25163ce60a5a6c468cf7a0e3dc8a165f824cabc2aa9e39a5e9fc5c2311b7686f"
url: "https://pub.dev"
source: hosted
version: "1.4.3"
version: "1.5.0"
local_auth_platform_interface:
dependency: transitive
description:
Expand Down
Loading