Skip to content

Commit

Permalink
Merge pull request #1806 from ardriveapp/PE-6011
Browse files Browse the repository at this point in the history
PE-6011: fix attach drive
  • Loading branch information
thiagocarvalhodev authored Jul 24, 2024
2 parents eade1ce + 8885b1a commit d0df45f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 41 deletions.
8 changes: 7 additions & 1 deletion lib/authentication/login/blocs/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -40,6 +41,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
final ArweaveService _arweaveService;
final DownloadService _downloadService;
final ConfigService _configService;
final ProfileCubit _profileCubit;

bool ignoreNextWaletSwitch = false;

Expand All @@ -61,13 +63,15 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
required DownloadService downloadService,
required UserRepository userRepository,
required ConfigService configService,
required ProfileCubit profileCubit,
}) : _arDriveAuth = arDriveAuth,
_arConnectService = arConnectService,
_ethereumProviderService = ethereumProviderService,
_arweaveService = arweaveService,
_turboUploadService = turboUploadService,
_downloadService = downloadService,
_configService = configService,
_profileCubit = profileCubit,
super(LoginLoading()) {
on<LoginEvent>(_onLoginEvent);
_listenToWalletChange();
Expand Down Expand Up @@ -500,7 +504,9 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
Emitter<LoginState> emit,
) async {
if (await _arDriveAuth.isUserLoggedIn()) {
await _arDriveAuth.logout();
await _arDriveAuth
.logout()
.then((value) => _profileCubit.logoutProfile());
}

usingSeedphrase = false;
Expand Down
32 changes: 0 additions & 32 deletions lib/authentication/login/views/forget_wallet.dart

This file was deleted.

1 change: 1 addition & 0 deletions lib/authentication/login/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class _LoginPageState extends State<LoginPage> {
arDriveAuth: context.read<ArDriveAuth>(),
userRepository: context.read<UserRepository>(),
configService: context.read<ConfigService>(),
profileCubit: context.read<ProfileCubit>(),
)..add(
CheckIfUserIsLoggedIn(
gettingStarted: widget.gettingStarted,
Expand Down
7 changes: 7 additions & 0 deletions lib/pages/app_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
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;
Expand Down
27 changes: 19 additions & 8 deletions test/authentication/login/blocs/login_bloc_test.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -25,6 +26,7 @@ void main() {

late DownloadService mockDownloadService;
late ArweaveService mockArweaveService;
late ProfileCubit mockProfileCubit;

final wallet = getTestWallet();

Expand All @@ -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(() {
Expand All @@ -52,6 +56,7 @@ void main() {
mockDownloadService = MockDownloadService();
mockArweaveService = MockArweaveService();
mockConfigService = MockConfigService();
mockProfileCubit = MockProfileCubit();
});

group('AddWalletFile', () {
Expand All @@ -72,6 +77,7 @@ void main() {
downloadService: mockDownloadService,
userRepository: mockUserRepository,
configService: mockConfigService,
profileCubit: mockProfileCubit,
);
},
setUp: () {
Expand Down Expand Up @@ -107,6 +113,7 @@ void main() {
downloadService: mockDownloadService,
userRepository: mockUserRepository,
configService: mockConfigService,
profileCubit: mockProfileCubit,
);
},
setUp: () {
Expand Down Expand Up @@ -144,6 +151,7 @@ void main() {
downloadService: mockDownloadService,
userRepository: mockUserRepository,
configService: mockConfigService,
profileCubit: mockProfileCubit,
);
},
setUp: () {
Expand Down Expand Up @@ -249,6 +257,7 @@ void main() {
downloadService: mockDownloadService,
userRepository: mockUserRepository,
configService: mockConfigService,
profileCubit: mockProfileCubit,
);
},
setUp: () {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit d0df45f

Please sign in to comment.