From f9cad66f5c04456a358a3296de7510b2fd0dd04a Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Tue, 23 Jul 2024 09:33:38 -0300 Subject: [PATCH 1/3] fix(attach drive) - cleans up the the private share drive url when the user forgets wallet or logouts --- .../login/blocs/login_bloc.dart | 8 ++++- .../login/views/forget_wallet.dart | 32 ------------------- .../login/views/login_page.dart | 1 + lib/pages/app_router_delegate.dart | 6 ++++ 4 files changed, 14 insertions(+), 33 deletions(-) delete mode 100644 lib/authentication/login/views/forget_wallet.dart 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 ff6c0c2fac..c4e9666b7b 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..a758c68bd0 100644 --- a/lib/pages/app_router_delegate.dart +++ b/lib/pages/app_router_delegate.dart @@ -119,6 +119,12 @@ class AppRouterDelegate extends RouterDelegate notifyListeners(); } + if (state is ProfileLoggingOut) { + driveId = null; + driveName = null; + notifyListeners(); + } + // Redirect the user away from sign in if they are already signed in. if ((signingIn || gettingStarted) && state is ProfileLoggedIn) { signingIn = false; From ad5760a500dbe4192d3e9cf246b13608dec94b18 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Tue, 23 Jul 2024 09:50:12 -0300 Subject: [PATCH 2/3] Update app_router_delegate.dart --- lib/pages/app_router_delegate.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pages/app_router_delegate.dart b/lib/pages/app_router_delegate.dart index a758c68bd0..9228675ab6 100644 --- a/lib/pages/app_router_delegate.dart +++ b/lib/pages/app_router_delegate.dart @@ -122,6 +122,7 @@ class AppRouterDelegate extends RouterDelegate if (state is ProfileLoggingOut) { driveId = null; driveName = null; + sharedDriveKey = null; notifyListeners(); } From 8885b1abbc7d46c8664e87f50c624b9167f0c6ef Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Tue, 23 Jul 2024 09:54:09 -0300 Subject: [PATCH 3/3] Update login_bloc_test.dart --- .../login/blocs/login_bloc_test.dart | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) 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());