diff --git a/lib/authentication/login/blocs/login_bloc.dart b/lib/authentication/login/blocs/login_bloc.dart index 9ed6f13e53..c960547289 100644 --- a/lib/authentication/login/blocs/login_bloc.dart +++ b/lib/authentication/login/blocs/login_bloc.dart @@ -5,6 +5,7 @@ import 'package:ardrive/authentication/ardrive_auth.dart'; import 'package:ardrive/authentication/login/blocs/ethereum_signer.dart'; import 'package:ardrive/authentication/login/blocs/stub_web_wallet.dart' // stub implementation if (dart.library.html) 'package:ardrive/authentication/login/blocs/web_wallet.dart'; +import 'package:ardrive/blocs/profile/profile_cubit.dart'; import 'package:ardrive/core/crypto/crypto.dart'; import 'package:ardrive/core/download_service.dart'; import 'package:ardrive/entities/profile_types.dart'; @@ -40,6 +41,7 @@ class LoginBloc extends Bloc { final ArweaveService _arweaveService; final DownloadService _downloadService; final ConfigService _configService; + final ProfileCubit _profileCubit; bool ignoreNextWaletSwitch = false; @@ -61,6 +63,7 @@ class LoginBloc extends Bloc { required DownloadService downloadService, required UserRepository userRepository, required ConfigService configService, + required ProfileCubit profileCubit, }) : _arDriveAuth = arDriveAuth, _arConnectService = arConnectService, _ethereumProviderService = ethereumProviderService, @@ -68,6 +71,7 @@ class LoginBloc extends Bloc { _turboUploadService = turboUploadService, _downloadService = downloadService, _configService = configService, + _profileCubit = profileCubit, super(LoginLoading()) { on(_onLoginEvent); _listenToWalletChange(); @@ -500,7 +504,9 @@ class LoginBloc extends Bloc { Emitter emit, ) async { if (await _arDriveAuth.isUserLoggedIn()) { - await _arDriveAuth.logout(); + await _arDriveAuth + .logout() + .then((value) => _profileCubit.logoutProfile()); } usingSeedphrase = false; diff --git a/lib/authentication/login/views/forget_wallet.dart b/lib/authentication/login/views/forget_wallet.dart deleted file mode 100644 index 30f609c606..0000000000 --- a/lib/authentication/login/views/forget_wallet.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:ardrive/authentication/login/blocs/login_bloc.dart'; -import 'package:ardrive/utils/app_localizations_wrapper.dart'; -import 'package:ardrive_ui/ardrive_ui.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -void forgetWallet( - BuildContext context, -) { - final actions = [ - ModalAction( - action: () { - Navigator.pop(context); - }, - title: appLocalizationsOf(context).cancel, - ), - ModalAction( - action: () { - Navigator.pop(context); - - context.read().add(const ForgetWallet()); - }, - title: appLocalizationsOf(context).ok, - ) - ]; - showStandardDialog( - context, - title: appLocalizationsOf(context).forgetWalletTitle, - description: appLocalizationsOf(context).forgetWalletDescription, - actions: actions, - ); -} diff --git a/lib/authentication/login/views/login_page.dart b/lib/authentication/login/views/login_page.dart index c10e780d34..fff781ca61 100644 --- a/lib/authentication/login/views/login_page.dart +++ b/lib/authentication/login/views/login_page.dart @@ -72,6 +72,7 @@ class _LoginPageState extends State { arDriveAuth: context.read(), userRepository: context.read(), configService: context.read(), + profileCubit: context.read(), )..add( CheckIfUserIsLoggedIn( gettingStarted: widget.gettingStarted, diff --git a/lib/pages/app_router_delegate.dart b/lib/pages/app_router_delegate.dart index c243d7b6a1..9228675ab6 100644 --- a/lib/pages/app_router_delegate.dart +++ b/lib/pages/app_router_delegate.dart @@ -119,6 +119,13 @@ class AppRouterDelegate extends RouterDelegate notifyListeners(); } + if (state is ProfileLoggingOut) { + driveId = null; + driveName = null; + sharedDriveKey = null; + notifyListeners(); + } + // Redirect the user away from sign in if they are already signed in. if ((signingIn || gettingStarted) && state is ProfileLoggedIn) { signingIn = false; diff --git a/test/authentication/login/blocs/login_bloc_test.dart b/test/authentication/login/blocs/login_bloc_test.dart index 6ae91c5645..053933441f 100644 --- a/test/authentication/login/blocs/login_bloc_test.dart +++ b/test/authentication/login/blocs/login_bloc_test.dart @@ -1,5 +1,6 @@ import 'package:ardrive/authentication/ardrive_auth.dart'; import 'package:ardrive/authentication/login/blocs/login_bloc.dart'; +import 'package:ardrive/blocs/profile/profile_cubit.dart'; import 'package:ardrive/core/download_service.dart'; import 'package:ardrive/entities/profile_types.dart'; import 'package:ardrive/services/services.dart'; @@ -25,6 +26,7 @@ void main() { late DownloadService mockDownloadService; late ArweaveService mockArweaveService; + late ProfileCubit mockProfileCubit; final wallet = getTestWallet(); @@ -33,14 +35,16 @@ void main() { LoginBloc createBloc() { return LoginBloc( - arDriveAuth: mockArDriveAuth, - arConnectService: mockArConnectService, - ethereumProviderService: mockEthereumProviderService, - turboUploadService: mockTurboUploadService, - arweaveService: mockArweaveService, - downloadService: mockDownloadService, - userRepository: mockUserRepository, - configService: mockConfigService); + arDriveAuth: mockArDriveAuth, + arConnectService: mockArConnectService, + ethereumProviderService: mockEthereumProviderService, + turboUploadService: mockTurboUploadService, + arweaveService: mockArweaveService, + downloadService: mockDownloadService, + userRepository: mockUserRepository, + configService: mockConfigService, + profileCubit: mockProfileCubit, + ); } setUp(() { @@ -52,6 +56,7 @@ void main() { mockDownloadService = MockDownloadService(); mockArweaveService = MockArweaveService(); mockConfigService = MockConfigService(); + mockProfileCubit = MockProfileCubit(); }); group('AddWalletFile', () { @@ -72,6 +77,7 @@ void main() { downloadService: mockDownloadService, userRepository: mockUserRepository, configService: mockConfigService, + profileCubit: mockProfileCubit, ); }, setUp: () { @@ -107,6 +113,7 @@ void main() { downloadService: mockDownloadService, userRepository: mockUserRepository, configService: mockConfigService, + profileCubit: mockProfileCubit, ); }, setUp: () { @@ -144,6 +151,7 @@ void main() { downloadService: mockDownloadService, userRepository: mockUserRepository, configService: mockConfigService, + profileCubit: mockProfileCubit, ); }, setUp: () { @@ -249,6 +257,7 @@ void main() { downloadService: mockDownloadService, userRepository: mockUserRepository, configService: mockConfigService, + profileCubit: mockProfileCubit, ); }, setUp: () { @@ -752,6 +761,8 @@ void main() { .thenAnswer((invocation) => false); when(() => mockArConnectService.disconnect()) .thenAnswer((invocation) => Future.value(null)); + when(() => mockProfileCubit.logoutProfile()) + .thenAnswer((_) => Future.value(null)); }, act: (bloc) async { bloc.add(const ForgetWallet());