Skip to content

Commit

Permalink
feat(ardrive auth): moves the getWalletAddress out of the login bloc …
Browse files Browse the repository at this point in the history
…PE-4752
  • Loading branch information
matibat committed Oct 9, 2023
1 parent ffeeea0 commit 7f29329
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
11 changes: 11 additions & 0 deletions lib/authentication/ardrive_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive/utils/metadata_cache.dart';
import 'package:ardrive/utils/secure_key_value_store.dart';
import 'package:arweave/arweave.dart';
import 'package:arweave/utils.dart';
import 'package:cryptography/cryptography.dart';
import 'package:flutter/foundation.dart';
import 'package:stash_shared_preferences/stash_shared_preferences.dart';
Expand All @@ -29,6 +30,7 @@ abstract class ArDriveAuth {
User get currentUser;
Stream<User?> onAuthStateChanged();
Future<bool> isBiometricsEnabled();
Future<String?> getWalletAddress();

factory ArDriveAuth({
required ArweaveService arweave,
Expand Down Expand Up @@ -326,6 +328,15 @@ class ArDriveAuthImpl implements ArDriveAuth {

return firstPrivateDriveTxId;
}

@override
Future<String?> getWalletAddress() async {
final owner = await _userRepository.getOwnerOfDefaultProfile();
if (owner == null) {
return null;
}
return ownerToAddress(owner);
}
}

class AuthenticationFailedException implements Exception {
Expand Down
11 changes: 0 additions & 11 deletions lib/authentication/login/blocs/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:ardrive/utils/html/html_util.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive_io/ardrive_io.dart';
import 'package:arweave/arweave.dart';
import 'package:arweave/utils.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -27,7 +26,6 @@ part 'login_state.dart';
class LoginBloc extends Bloc<LoginEvent, LoginState> {
final ArDriveAuth _arDriveAuth;
final ArConnectService _arConnectService;
final UserRepository _userRepository;

bool ignoreNextWaletSwitch = false;

Expand All @@ -37,21 +35,12 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
@visibleForTesting
ProfileType? profileType;

Future<String?> getWalletAddress() async {
final owner = await _userRepository.getOwnerOfDefaultProfile();
if (owner == null) {
return null;
}
return ownerToAddress(owner);
}

LoginBloc({
required ArDriveAuth arDriveAuth,
required ArConnectService arConnectService,
required UserRepository userRepository,
}) : _arDriveAuth = arDriveAuth,
_arConnectService = arConnectService,
_userRepository = userRepository,
super(LoginLoading()) {
on<LoginEvent>(_onLoginEvent);
_listenToWalletChange();
Expand Down
2 changes: 1 addition & 1 deletion lib/authentication/login/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ class _PromptPasswordViewState extends State<PromptPasswordView> {
style: ArDriveTypography.headline.headline4Bold(),
),
FutureBuilder(
future: context.read<LoginBloc>().getWalletAddress(),
future: context.read<ArDriveAuth>().getWalletAddress(),
builder:
(BuildContext context, AsyncSnapshot<String?> snapshot) {
if (snapshot.hasData) {
Expand Down

0 comments on commit 7f29329

Please sign in to comment.