Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into localizely_2023-09-18_…
Browse files Browse the repository at this point in the history
…15-14-27
  • Loading branch information
matibat committed Sep 21, 2023
2 parents cc06f73 + 9b053df commit 10cd331
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 135 deletions.
3 changes: 3 additions & 0 deletions android/fastlane/metadata/android/en-US/changelogs/62.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Adds an explanation for the privacy of drives on the Create Drive Modal
- Starts tagging public pins with new GQL Tags: ArFS-Pin and Pinned-Data-Tx
- Updates the icon for the Detach Drive option
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);
}
}
37 changes: 34 additions & 3 deletions lib/blocs/pin_file/pin_file_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:async';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/core/arfs/entities/arfs_entities.dart';
import 'package:ardrive/core/crypto/crypto.dart';
import 'package:ardrive/entities/file_entity.dart';
import 'package:ardrive/entities/entities.dart' show EntityTag, FileEntity;
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/misc/misc.dart';
import 'package:ardrive/models/models.dart';
Expand Down Expand Up @@ -279,6 +279,7 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
) async {
final stateAsPinFileFieldsValid = state as PinFileFieldsValid;
final profileState = _profileCubit.state as ProfileLoggedIn;
final wallet = profileState.wallet;

emit(PinFileCreating(
id: stateAsPinFileFieldsValid.id,
Expand Down Expand Up @@ -311,13 +312,29 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
.folderById(driveId: _driveId, folderId: _parentFolderId)
.getSingle();

final isAPublicPin = fileKey == null;

if (_turboUploadService.useTurboUpload) {
final fileDataItem = await _arweave.prepareEntityDataItem(
newFileEntity,
profileState.wallet,
wallet,
key: fileKey,
skipSignature: true,
);

if (isAPublicPin) {
fileDataItem.addTag(
EntityTag.arFsPin,
'true',
);
fileDataItem.addTag(
EntityTag.pinnedDataTx,
newFileEntity.dataTxId!,
);
}

await fileDataItem.sign(wallet);

await _turboUploadService.postDataItem(
dataItem: fileDataItem,
wallet: profileState.wallet,
Expand All @@ -326,10 +343,24 @@ class PinFileBloc extends Bloc<PinFileEvent, PinFileState> {
} else {
final fileDataItem = await _arweave.prepareEntityTx(
newFileEntity,
profileState.wallet,
wallet,
fileKey,
skipSignature: true,
);

if (isAPublicPin) {
fileDataItem.addTag(
EntityTag.arFsPin,
'true',
);
fileDataItem.addTag(
EntityTag.pinnedDataTx,
newFileEntity.dataTxId!,
);
}

await fileDataItem.sign(wallet);

await _arweave.postTx(fileDataItem);
newFileEntity.txId = fileDataItem.id;
}
Expand Down
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
3 changes: 3 additions & 0 deletions lib/entities/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class EntityTag {
static const blockEnd = 'Block-End';
static const dataStart = 'Data-Start';
static const dataEnd = 'Data-End';

static const pinnedDataTx = 'Pinned-Data-Tx';
static const arFsPin = 'ArFS-Pin';
}

class ContentType {
Expand Down
7 changes: 4 additions & 3 deletions lib/pages/drive_detail/drive_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,10 @@ class _DriveDetailPageState extends State<DriveDetailPage> {
);
},
content: _buildItem(
appLocalizationsOf(context)
.detachDrive,
ArDriveIcons.triangle()),
appLocalizationsOf(context)
.detachDrive,
ArDriveIcons.detach(),
),
),
],
child: HoverWidget(
Expand Down
5 changes: 4 additions & 1 deletion lib/services/arweave/arweave_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,14 @@ class ArweaveService {
Entity entity,
Wallet wallet, {
SecretKey? key,
bool skipSignature = false,
}) async {
final item = await entity.asDataItem(key);
item.setOwner(await wallet.getOwner());

await item.sign(wallet);
if (!skipSignature) {
await item.sign(wallet);
}

return item;
}
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "v1.9.1"
resolved-ref: c240bab3c61efec613832ce5636226aff2a18d63
ref: "v1.9.2"
resolved-ref: f8fb1bf502541e46caeb6e7e6270e2c488d7e126
url: "https://github.com/ar-io/ardrive_ui.git"
source: git
version: "1.9.1"
version: "1.9.2"
args:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Secure, permanent storage

publish_to: 'none'

version: 2.13.0
version: 2.14.0

environment:
sdk: '>=2.18.5 <3.0.0'
Expand Down Expand Up @@ -39,7 +39,7 @@ dependencies:
ardrive_ui:
git:
url: https://github.com/ar-io/ardrive_ui.git
ref: v1.9.1
ref: v1.9.2
artemis: ^7.0.0-beta.13
arweave:
git:
Expand Down
Loading

0 comments on commit 10cd331

Please sign in to comment.