Skip to content

Commit

Permalink
Merge pull request #1366 from ardriveapp/PE-4597
Browse files Browse the repository at this point in the history
PE-4597: adds a description of the selected drive privacy
  • Loading branch information
matibat authored Sep 21, 2023
2 parents c1236e4 + 7f07e6d commit 668cb18
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 123 deletions.
33 changes: 23 additions & 10 deletions lib/blocs/drive_create/drive_create_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/entities/entities.dart';
import 'package:ardrive/core/arfs/entities/arfs_entities.dart'
show DrivePrivacy;
import 'package:ardrive/entities/constants.dart' as constants;
import 'package:ardrive/entities/drive_entity.dart';
import 'package:ardrive/entities/folder_entity.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/services.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
Expand All @@ -15,7 +19,9 @@ part 'drive_create_state.dart';
class DriveCreateCubit extends Cubit<DriveCreateState> {
final form = FormGroup({
'privacy': FormControl<String>(
value: DrivePrivacy.private, validators: [Validators.required]),
value: DrivePrivacy.private.name,
validators: [Validators.required],
),
});

final ArweaveService _arweave;
Expand All @@ -35,25 +41,32 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
_driveDao = driveDao,
_profileCubit = profileCubit,
_drivesCubit = drivesCubit,
super(DriveCreateInitial());
super(const DriveCreateInitial(privacy: DrivePrivacy.private));

void onPrivacyChanged() {
final privacy = form.control('privacy').value == DrivePrivacy.private.name
? DrivePrivacy.private
: DrivePrivacy.public;
emit(state.copyWith(privacy: privacy));
}

Future<void> submit(
String driveName,
) async {
final profile = _profileCubit.state as ProfileLoggedIn;
if (await _profileCubit.logoutIfWalletMismatch()) {
emit(DriveCreateWalletMismatch());
emit(DriveCreateWalletMismatch(privacy: state.privacy));
return;
}

final minimumWalletBalance = BigInt.from(10000000);
if (profile.walletBalance <= minimumWalletBalance &&
!_turboUploadService.useTurboUpload) {
emit(DriveCreateZeroBalance());
emit(DriveCreateZeroBalance(privacy: state.privacy));
return;
}

emit(DriveCreateInProgress());
emit(DriveCreateInProgress(privacy: state.privacy));

try {
final String drivePrivacy = form.control('privacy').value;
Expand All @@ -72,8 +85,8 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
name: driveName,
rootFolderId: createRes.rootFolderId,
privacy: drivePrivacy,
authMode: drivePrivacy == DrivePrivacy.private
? DriveAuthMode.password
authMode: drivePrivacy == constants.DrivePrivacy.private
? constants.DriveAuthMode.password
: null,
);

Expand Down Expand Up @@ -140,12 +153,12 @@ class DriveCreateCubit extends Cubit<DriveCreateState> {
addError(err);
}

emit(DriveCreateSuccess());
emit(DriveCreateSuccess(privacy: state.privacy));
}

@override
void onError(Object error, StackTrace stackTrace) {
emit(DriveCreateFailure());
emit(DriveCreateFailure(privacy: state.privacy));
super.onError(error, stackTrace);

logger.e('Failed to create drive', error, stackTrace);
Expand Down
64 changes: 57 additions & 7 deletions lib/blocs/drive_create/drive_create_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,68 @@ part of 'drive_create_cubit.dart';

@immutable
abstract class DriveCreateState extends Equatable {
final DrivePrivacy privacy;

const DriveCreateState({required this.privacy});

DriveCreateState copyWith({DrivePrivacy? privacy}) {
throw UnimplementedError();
}

@override
List<Object> get props => [];
List<Object> get props => [privacy];
}

class DriveCreateInitial extends DriveCreateState {}
class DriveCreateInitial extends DriveCreateState {
const DriveCreateInitial({required super.privacy});

class DriveCreateZeroBalance extends DriveCreateState {}
@override
DriveCreateInitial copyWith({DrivePrivacy? privacy}) {
return DriveCreateInitial(privacy: privacy ?? this.privacy);
}
}

class DriveCreateInProgress extends DriveCreateState {}
class DriveCreateZeroBalance extends DriveCreateState {
const DriveCreateZeroBalance({required super.privacy});

class DriveCreateSuccess extends DriveCreateState {}
@override
DriveCreateZeroBalance copyWith({DrivePrivacy? privacy}) {
return DriveCreateZeroBalance(privacy: privacy ?? this.privacy);
}
}

class DriveCreateInProgress extends DriveCreateState {
const DriveCreateInProgress({required super.privacy});

@override
DriveCreateInProgress copyWith({DrivePrivacy? privacy}) {
return DriveCreateInProgress(privacy: privacy ?? this.privacy);
}
}

class DriveCreateFailure extends DriveCreateState {}
class DriveCreateSuccess extends DriveCreateState {
const DriveCreateSuccess({required super.privacy});

class DriveCreateWalletMismatch extends DriveCreateState {}
@override
DriveCreateSuccess copyWith({DrivePrivacy? privacy}) {
return DriveCreateSuccess(privacy: privacy ?? this.privacy);
}
}

class DriveCreateFailure extends DriveCreateState {
const DriveCreateFailure({required super.privacy});

@override
DriveCreateFailure copyWith({DrivePrivacy? privacy}) {
return DriveCreateFailure(privacy: privacy ?? this.privacy);
}
}

class DriveCreateWalletMismatch extends DriveCreateState {
const DriveCreateWalletMismatch({required super.privacy});

@override
DriveCreateWalletMismatch copyWith({DrivePrivacy? privacy}) {
return DriveCreateWalletMismatch(privacy: privacy ?? this.privacy);
}
}
28 changes: 25 additions & 3 deletions lib/components/drive_create_form.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/core/arfs/entities/arfs_entities.dart';
import 'package:ardrive/l11n/l11n.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/pages/congestion_warning_wrapper.dart';
Expand Down Expand Up @@ -73,6 +74,8 @@ class _DriveCreateFormState extends State<DriveCreateForm> {
],
);
} else {
final privacy = state.privacy;

return ArDriveStandardModal(
title: appLocalizationsOf(context).createDriveEmphasized,
content: SizedBox(
Expand Down Expand Up @@ -108,24 +111,43 @@ class _DriveCreateFormState extends State<DriveCreateForm> {
ReactiveDropdownField(
formControlName: 'privacy',
decoration: InputDecoration(
labelText: appLocalizationsOf(context).privacy),
labelText: appLocalizationsOf(context).privacy,
),
showErrors: (control) =>
control.dirty && control.invalid,
validationMessages:
kValidationMessages(appLocalizationsOf(context)),
items: [
DropdownMenuItem(
value: 'public',
value: DrivePrivacy.public.name,
child: Text(appLocalizationsOf(context).public),
),
DropdownMenuItem(
value: 'private',
value: DrivePrivacy.private.name,
child: Text(
appLocalizationsOf(context).private,
),
)
],
onChanged: (_) {
context.read<DriveCreateCubit>().onPrivacyChanged();
},
),
const SizedBox(height: 32),
Row(children: [
if (privacy == DrivePrivacy.private)
Flexible(
child: Text(
appLocalizationsOf(context)
.drivePrivacyDescriptionPrivate,
))
else
Flexible(
child: Text(
appLocalizationsOf(context)
.drivePrivacyDescriptionPublic,
))
]),
],
),
),
Expand Down
8 changes: 8 additions & 0 deletions lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,14 @@
"@driveName": {
"description": "The name of certain drive"
},
"drivePrivacyDescriptionPrivate": "Private Drives offer state-of-the-art security, you control access.",
"@drivePrivacyDescriptionPrivate": {
"description": "Explains private drives."
},
"drivePrivacyDescriptionPublic": "Public Drives are discoverable, others can find and view the contents.",
"@drivePrivacyDescriptionPublic": {
"description": "Explains public drives."
},
"driveRoot": "Drive root",
"@driveRoot": {
"description": "The folder entity that is at the top of the folder hierarchy"
Expand Down
Loading

0 comments on commit 668cb18

Please sign in to comment.