Skip to content

Commit

Permalink
Merge pull request #1934 from ardriveapp/PE-4381-wallet-switch-dialog…
Browse files Browse the repository at this point in the history
…-uses-the-old-modal-component

PE-4381: wallet switch dialog uses the old modal component
  • Loading branch information
thiagocarvalhodev authored Jan 6, 2025
2 parents f3b0d60 + 8a88ca8 commit caf8abd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
17 changes: 13 additions & 4 deletions lib/app_shell.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,14 +47,22 @@ class AppShellState extends State<AppShell> {
@override
void initState() {
onArConnectWalletSwitch(() {
logger.d('Wallet switch detected');
context.read<ProfileCubit>().isCurrentProfileArConnect().then(
(isCurrentProfileArConnect) {
if (_showWalletSwitchDialog) {
if (isCurrentProfileArConnect) {
showDialog(
context: context,
builder: (context) => const WalletSwitchDialog(),
);
context.read<ArDriveAuth>().isUserLoggedIn().then((isLoggedIn) {
context.read<ProfileCubit>().logoutIfWalletMismatch();
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.');
Expand Down
11 changes: 6 additions & 5 deletions lib/authentication/ardrive_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,17 @@ class ArDriveAuthImpl implements ArDriveAuth {
logger.d('Logging out user');

try {
await _userRepository.deleteUser();

if (_currentUser != null) {
await _disconnectFromArConnect();
(await _metadataCache).clear();
await _secureKeyValueStore.remove('password');
await _secureKeyValueStore.remove('biometricEnabled');
currentUser = null;
await _disconnectFromArConnect();
}

await _userRepository.deleteUser();

await _databaseHelpers.deleteAllTables();
(await _metadataCache).clear();
currentUser = null;
_userStreamController.add(null);
} catch (e, stacktrace) {
logger.e('Failed to logout user', e, stacktrace);
Expand Down
1 change: 1 addition & 0 deletions lib/authentication/login/blocs/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
}

onArConnectWalletSwitch(() async {
logger.d('Wallet switch detected on LoginBloc');
final isUserLoggedIng = await _arDriveAuth.isUserLoggedIn();
if (isUserLoggedIng && !_isArConnectWallet()) {
logger.d(
Expand Down
32 changes: 3 additions & 29 deletions lib/components/wallet_switch_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,42 +1,16 @@
// ignore_for_file: use_build_context_synchronously

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_utils/ardrive_utils.dart';
import 'package:ardrive_ui/ardrive_ui.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)],
),
actions: [
TextButton(
onPressed: () async {
await context.read<ArDriveAuth>().logout();
await context.read<ProfileCubit>().logoutProfile();

Navigator.pop(context);

if (fromAuthPage) {
triggerHTMLPageReload();
context.read<ProfileAddCubit>().promptForWallet();
}
},
child: Text(appLocalizationsOf(context).logOut),
)
],
description: appLocalizationsOf(context).walletChangeDetected,
);
}

0 comments on commit caf8abd

Please sign in to comment.