Skip to content

Commit

Permalink
Merge pull request #1413 from ardriveapp/PE-4752
Browse files Browse the repository at this point in the history
PE-4752: Wallet address in login page PoC
  • Loading branch information
thiagocarvalhodev authored Oct 18, 2023
2 parents 5f1c9d1 + 302de7e commit 1653a07
Show file tree
Hide file tree
Showing 8 changed files with 951 additions and 859 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
2 changes: 2 additions & 0 deletions 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/entities/profile_types.dart';
import 'package:ardrive/services/arconnect/arconnect.dart';
import 'package:ardrive/services/arconnect/arconnect_wallet.dart';
import 'package:ardrive/user/repositories/user_repository.dart';
import 'package:ardrive/user/user.dart';
import 'package:ardrive/utils/html/html_util.dart';
import 'package:ardrive/utils/logger/logger.dart';
Expand Down Expand Up @@ -37,6 +38,7 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
LoginBloc({
required ArDriveAuth arDriveAuth,
required ArConnectService arConnectService,
required UserRepository userRepository,
}) : _arDriveAuth = arDriveAuth,
_arConnectService = arConnectService,
super(LoginLoading()) {
Expand Down
52 changes: 50 additions & 2 deletions lib/authentication/login/views/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import 'package:ardrive/authentication/login/blocs/stub_web_wallet.dart' // stub
if (dart.library.html) 'package:ardrive/authentication/login/blocs/web_wallet.dart';
import 'package:ardrive/blocs/profile/profile_cubit.dart';
import 'package:ardrive/components/app_version_widget.dart';
import 'package:ardrive/components/truncated_address.dart';
import 'package:ardrive/misc/resources.dart';
import 'package:ardrive/pages/drive_detail/components/hover_widget.dart';
import 'package:ardrive/services/arconnect/arconnect.dart';
import 'package:ardrive/services/authentication/biometric_authentication.dart';
import 'package:ardrive/services/authentication/biometric_permission_dialog.dart';
import 'package:ardrive/services/config/config_service.dart';
import 'package:ardrive/user/repositories/user_repository.dart';
import 'package:ardrive/utils/app_localizations_wrapper.dart';
import 'package:ardrive/utils/app_platform.dart';
import 'package:ardrive/utils/io_utils.dart';
Expand Down Expand Up @@ -48,6 +50,7 @@ class _LoginPageState extends State<LoginPage> {
create: (context) => LoginBloc(
arConnectService: ArConnectService(),
arDriveAuth: context.read<ArDriveAuth>(),
userRepository: context.read<UserRepository>(),
)..add(const CheckIfUserIsLoggedIn()),
child: BlocConsumer<LoginBloc, LoginState>(
listener: (context, state) {
Expand Down Expand Up @@ -314,7 +317,9 @@ class _LoginPageScaffoldState extends State<LoginPageScaffold> {
} else if (enableSeedPhraseLogin &&
state is LoginDownloadGeneratedWallet) {
content = DownloadWalletView(
mnemonic: state.mnemonic, wallet: state.walletFile);
mnemonic: state.mnemonic,
wallet: state.walletFile,
);
} else {
content = PromptWalletView(
key: const Key('promptWalletView'),
Expand Down Expand Up @@ -684,6 +689,10 @@ class _PromptPasswordViewState extends State<PromptPasswordView> {
textAlign: TextAlign.center,
style: ArDriveTypography.headline.headline4Bold(),
),
_buildAddressPreview(
context,
maybeWallet: widget.wallet,
),
Column(
children: [
ArDriveTextField(
Expand Down Expand Up @@ -2243,7 +2252,7 @@ class CreateNewWalletViewState extends State<CreateNewWalletView> {
color: colors.themeErrorMuted,
)
.copyWith(fontSize: 14)))
]),
]),
shape: RoundedRectangleBorder(
side: BorderSide(
color: colors.themeErrorMuted, width: 1),
Expand Down Expand Up @@ -2637,3 +2646,42 @@ class _LoginCopyButtonState extends State<LoginCopyButton> {
}
}
}

Widget _buildAddressPreview(
BuildContext context, {
required Wallet? maybeWallet,
}) {
Future<String?> getWalletAddress() async {
if (maybeWallet == null) {
return context.read<ArDriveAuth>().getWalletAddress();
}
return maybeWallet.getAddress();
}

return FutureBuilder(
future: getWalletAddress(),
builder: (BuildContext context, AsyncSnapshot<String?> snapshot) {
if (snapshot.hasData) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
appLocalizationsOf(context).walletAddress,
style: ArDriveTypography.body
.captionRegular()
.copyWith(fontSize: 18),
),
const SizedBox(width: 8),
TruncatedAddress(
walletAddress: snapshot.data!,
fontSize: 18,
),
],
);
} else {
return const SizedBox.shrink();
}
},
);
}
6 changes: 5 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1970,6 +1970,10 @@
"@waitForDownload": {
"description": "User must to wait this download"
},
"walletAddress": "Wallet address:",
"@walletAddress": {
"description": "E.g. \"The wallet address is… ABCDEFGH\""
},
"walletChangedDuringManifestCreation": "Provided wallet has unexpectedly changed during manifest creation...",
"@walletChangedDuringManifestCreation": {
"description": "The wallet has been changed while the creation of the manifest was in process"
Expand Down Expand Up @@ -2078,4 +2082,4 @@
"@zippingYourFiles": {
"description": "Download failure message when a file is too big"
}
}
}
15 changes: 15 additions & 0 deletions lib/user/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ abstract class UserRepository {
Wallet wallet,
);
Future<void> deleteUser();
Future<String?> getOwnerOfDefaultProfile();

factory UserRepository(ProfileDao profileDao, ArweaveService arweave) =>
_UserRepository(
Expand All @@ -33,6 +34,8 @@ class _UserRepository implements UserRepository {
_arweave = arweave;

// TODO: Check ProfileDAO to implement only one source for user data

// Will return null if no user is not logged in - i.e. not present in the DB
@override
Future<User?> getUser(String password) async {
final profile = await _profileDao.getDefaultProfile();
Expand Down Expand Up @@ -86,6 +89,18 @@ class _UserRepository implements UserRepository {

return profile != null;
}

// Will return null if no user is not logged in - i.e. not present in the DB
@override
Future<String?> getOwnerOfDefaultProfile() async {
final profile = await _profileDao.getDefaultProfile();

if (profile == null) {
return null;
}

return profile.walletPublicKey;
}
}

class NoProfileFoundException implements Exception {
Expand Down
Loading

0 comments on commit 1653a07

Please sign in to comment.