Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE-4381: wallet switch dialog uses the old modal component #1934

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
);
}
Loading