From 5acf0d71774fd02128620a7240e6459efb964622 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:54:50 -0300 Subject: [PATCH 1/4] fix(arconnect logout) - update modal styles - only show modal if user is logged in --- lib/app_shell.dart | 16 ++++++++++++---- lib/authentication/ardrive_auth.dart | 11 ++++------- lib/components/wallet_switch_dialog.dart | 18 ++++++------------ 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/app_shell.dart b/lib/app_shell.dart index b759fdc55d..46db313cb9 100644 --- a/lib/app_shell.dart +++ b/lib/app_shell.dart @@ -1,3 +1,4 @@ +import 'package:ardrive/authentication/ardrive_auth.dart'; import 'package:ardrive/blocs/prompt_to_snapshot/prompt_to_snapshot_bloc.dart'; import 'package:ardrive/blocs/prompt_to_snapshot/prompt_to_snapshot_event.dart'; import 'package:ardrive/components/profile_card.dart'; @@ -45,14 +46,21 @@ class AppShellState extends State { @override void initState() { onArConnectWalletSwitch(() { + logger.d('Wallet switch detected'); context.read().isCurrentProfileArConnect().then( (isCurrentProfileArConnect) { if (_showWalletSwitchDialog) { if (isCurrentProfileArConnect) { - showDialog( - context: context, - builder: (context) => const WalletSwitchDialog(), - ); + context.read().isUserLoggedIn().then((isLoggedIn) { + if (isLoggedIn) { + logger.d('Wallet switch detected while logged in' + ' to ArConnect. Showing wallet switch dialog.'); + showArDriveDialog( + context, + content: const WalletSwitchDialog(), + ); + } + }); } else { logger.d('Wallet switch detected while not logged in' ' to ArConnect. Ignoring.'); diff --git a/lib/authentication/ardrive_auth.dart b/lib/authentication/ardrive_auth.dart index 0918bab9bb..c4995eba09 100644 --- a/lib/authentication/ardrive_auth.dart +++ b/lib/authentication/ardrive_auth.dart @@ -231,16 +231,13 @@ class ArDriveAuthImpl implements ArDriveAuth { logger.d('Logging out user'); try { - if (_currentUser != null) { - await _secureKeyValueStore.remove('password'); - await _secureKeyValueStore.remove('biometricEnabled'); - currentUser = null; - await _disconnectFromArConnect(); - } - await _userRepository.deleteUser(); + await _disconnectFromArConnect(); await _databaseHelpers.deleteAllTables(); (await _metadataCache).clear(); + await _secureKeyValueStore.remove('password'); + await _secureKeyValueStore.remove('biometricEnabled'); + currentUser = null; _userStreamController.add(null); } catch (e, stacktrace) { logger.e('Failed to logout user', e, stacktrace); diff --git a/lib/components/wallet_switch_dialog.dart b/lib/components/wallet_switch_dialog.dart index 4f3f99bde3..1c1a9d58fa 100644 --- a/lib/components/wallet_switch_dialog.dart +++ b/lib/components/wallet_switch_dialog.dart @@ -2,29 +2,23 @@ import 'package:ardrive/authentication/ardrive_auth.dart'; import 'package:ardrive/blocs/blocs.dart'; -import 'package:ardrive/components/app_dialog.dart'; import 'package:ardrive/utils/app_localizations_wrapper.dart'; +import 'package:ardrive_ui/ardrive_ui.dart'; import 'package:ardrive_utils/ardrive_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -// TODO: Add the new modal PE-4381 class WalletSwitchDialog extends StatelessWidget { final bool fromAuthPage; const WalletSwitchDialog({super.key, this.fromAuthPage = false}); @override - Widget build(BuildContext context) => AppDialog( - dismissable: false, + Widget build(BuildContext context) => ArDriveStandardModalNew( title: appLocalizationsOf(context).walletSwitch, - content: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.end, - children: [Text(appLocalizationsOf(context).walletChangeDetected)], - ), + description: appLocalizationsOf(context).walletChangeDetected, actions: [ - TextButton( - onPressed: () async { + ModalAction( + action: () async { await context.read().logout(); await context.read().logoutProfile(); @@ -35,7 +29,7 @@ class WalletSwitchDialog extends StatelessWidget { context.read().promptForWallet(); } }, - child: Text(appLocalizationsOf(context).logOut), + title: appLocalizationsOf(context).logOut, ) ], ); From 4cbea89ec96388ef39767a918bb095b3380db61f Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:03:22 -0300 Subject: [PATCH 2/4] Update ardrive_auth.dart --- lib/authentication/ardrive_auth.dart | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/authentication/ardrive_auth.dart b/lib/authentication/ardrive_auth.dart index c4995eba09..50bb0acb8b 100644 --- a/lib/authentication/ardrive_auth.dart +++ b/lib/authentication/ardrive_auth.dart @@ -232,11 +232,15 @@ class ArDriveAuthImpl implements ArDriveAuth { try { await _userRepository.deleteUser(); - await _disconnectFromArConnect(); await _databaseHelpers.deleteAllTables(); - (await _metadataCache).clear(); - await _secureKeyValueStore.remove('password'); - await _secureKeyValueStore.remove('biometricEnabled'); + + if (_currentUser != null) { + await _disconnectFromArConnect(); + (await _metadataCache).clear(); + await _secureKeyValueStore.remove('password'); + await _secureKeyValueStore.remove('biometricEnabled'); + } + currentUser = null; _userStreamController.add(null); } catch (e, stacktrace) { From e3610e74a22ca1e7b721a6d62aa26523de6661bc Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:06:27 -0300 Subject: [PATCH 3/4] Update ardrive_auth.dart --- lib/authentication/ardrive_auth.dart | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/authentication/ardrive_auth.dart b/lib/authentication/ardrive_auth.dart index 50bb0acb8b..e5c5990161 100644 --- a/lib/authentication/ardrive_auth.dart +++ b/lib/authentication/ardrive_auth.dart @@ -232,7 +232,6 @@ class ArDriveAuthImpl implements ArDriveAuth { try { await _userRepository.deleteUser(); - await _databaseHelpers.deleteAllTables(); if (_currentUser != null) { await _disconnectFromArConnect(); @@ -240,7 +239,7 @@ class ArDriveAuthImpl implements ArDriveAuth { await _secureKeyValueStore.remove('password'); await _secureKeyValueStore.remove('biometricEnabled'); } - + await _databaseHelpers.deleteAllTables(); currentUser = null; _userStreamController.add(null); } catch (e, stacktrace) { From 23c471d5a70d243cf51fb948b53edaf1077a7a74 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:27:42 -0300 Subject: [PATCH 4/4] fix attach drive --- lib/app_shell.dart | 1 + lib/authentication/ardrive_auth.dart | 1 + .../login/blocs/login_bloc.dart | 1 + lib/components/wallet_switch_dialog.dart | 20 ------------------- 4 files changed, 3 insertions(+), 20 deletions(-) diff --git a/lib/app_shell.dart b/lib/app_shell.dart index 46db313cb9..e7338a3e9d 100644 --- a/lib/app_shell.dart +++ b/lib/app_shell.dart @@ -52,6 +52,7 @@ class AppShellState extends State { if (_showWalletSwitchDialog) { if (isCurrentProfileArConnect) { context.read().isUserLoggedIn().then((isLoggedIn) { + context.read().logoutIfWalletMismatch(); if (isLoggedIn) { logger.d('Wallet switch detected while logged in' ' to ArConnect. Showing wallet switch dialog.'); diff --git a/lib/authentication/ardrive_auth.dart b/lib/authentication/ardrive_auth.dart index e5c5990161..258c90fd26 100644 --- a/lib/authentication/ardrive_auth.dart +++ b/lib/authentication/ardrive_auth.dart @@ -239,6 +239,7 @@ class ArDriveAuthImpl implements ArDriveAuth { await _secureKeyValueStore.remove('password'); await _secureKeyValueStore.remove('biometricEnabled'); } + await _databaseHelpers.deleteAllTables(); currentUser = null; _userStreamController.add(null); diff --git a/lib/authentication/login/blocs/login_bloc.dart b/lib/authentication/login/blocs/login_bloc.dart index d481619321..c755f9884f 100644 --- a/lib/authentication/login/blocs/login_bloc.dart +++ b/lib/authentication/login/blocs/login_bloc.dart @@ -571,6 +571,7 @@ class LoginBloc extends Bloc { } onArConnectWalletSwitch(() async { + logger.d('Wallet switch detected on LoginBloc'); final isUserLoggedIng = await _arDriveAuth.isUserLoggedIn(); if (isUserLoggedIng && !_isArConnectWallet()) { logger.d( diff --git a/lib/components/wallet_switch_dialog.dart b/lib/components/wallet_switch_dialog.dart index 1c1a9d58fa..d9f00dd1e2 100644 --- a/lib/components/wallet_switch_dialog.dart +++ b/lib/components/wallet_switch_dialog.dart @@ -1,12 +1,8 @@ // ignore_for_file: use_build_context_synchronously -import 'package:ardrive/authentication/ardrive_auth.dart'; -import 'package:ardrive/blocs/blocs.dart'; import 'package:ardrive/utils/app_localizations_wrapper.dart'; import 'package:ardrive_ui/ardrive_ui.dart'; -import 'package:ardrive_utils/ardrive_utils.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; class WalletSwitchDialog extends StatelessWidget { final bool fromAuthPage; @@ -16,21 +12,5 @@ class WalletSwitchDialog extends StatelessWidget { Widget build(BuildContext context) => ArDriveStandardModalNew( title: appLocalizationsOf(context).walletSwitch, description: appLocalizationsOf(context).walletChangeDetected, - actions: [ - ModalAction( - action: () async { - await context.read().logout(); - await context.read().logoutProfile(); - - Navigator.pop(context); - - if (fromAuthPage) { - triggerHTMLPageReload(); - context.read().promptForWallet(); - } - }, - title: appLocalizationsOf(context).logOut, - ) - ], ); }