Skip to content

Commit

Permalink
Merge pull request #1950 from ardriveapp/PE-7394-fallback-tx-id-not-d…
Browse files Browse the repository at this point in the history
…isplayed-after-updating-manifest

PE-7394: fallback tx id not displayed after updating manifest
  • Loading branch information
thiagocarvalhodev authored Jan 10, 2025
2 parents 41e63b3 + a5ec725 commit 09bdce7
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 14 deletions.
17 changes: 10 additions & 7 deletions lib/blocs/create_manifest/create_manifest_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ class CreateManifestCubit extends Cubit<CreateManifestState> {
createManifestUploadReview.existingManifestFileId,
uploadType: uploadType,
wallet: _auth.currentUser.wallet,
fallbackTxId: _getFallbackTxId(),
),
processId: _selectedAntRecord?.processId,
undername: getSelectedUndername(),
Expand Down Expand Up @@ -373,15 +374,17 @@ class CreateManifestCubit extends Cubit<CreateManifestState> {

TxID? _fallbackTxId;

void setFallbackTxId(TxID txId) {
void setFallbackTxId(TxID txId, {bool emitState = true}) {
_fallbackTxId = txId;

emit(
(state as CreateManifestFolderLoadSuccess).copyWith(
fallbackTxId: _getFallbackTxId(),
enableManifestCreationButton: _getEnableManifestCreationButton(),
),
);
if (emitState) {
emit(
(state as CreateManifestFolderLoadSuccess).copyWith(
fallbackTxId: _getFallbackTxId(),
enableManifestCreationButton: _getEnableManifestCreationButton(),
),
);
}
}

TxID? _getFallbackTxId() {
Expand Down
14 changes: 10 additions & 4 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class UploadCubit extends Cubit<UploadState> {
)
.getSingle();

/// If the manifest has a fallback tx id, we need to reuse it
await _createManifestCubit.prepareManifestTx(
manifestName: manifestFileEntry.name,
folderId: manifestFileEntry.parentFolderId,
Expand Down Expand Up @@ -223,20 +224,25 @@ class UploadCubit extends Cubit<UploadState> {
)
.getSingle();

if (manifestFileEntry.fallbackTxId != null) {
_createManifestCubit.setFallbackTxId(
manifestFileEntry.fallbackTxId!,
emitState: false,
);
}

await _createManifestCubit.prepareManifestTx(
manifestName: manifestFileEntry.name,
folderId: manifestFileEntry.parentFolderId,
existingManifestFileId: manifestModels[i].existingManifestFileId,
);

emit(UploadingManifests(
manifestFiles: manifestModels,
manifestFiles: manifestModels,
completedCount: completedCount,
));

await _createManifestCubit.uploadManifest(
method: _manifestUploadMethod,
);
await _createManifestCubit.uploadManifest(method: _manifestUploadMethod);

final manifestFile = await _driveDao
.fileById(
Expand Down
15 changes: 15 additions & 0 deletions lib/components/details_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,21 @@ class _DetailsPanelState extends State<DetailsPanel> {
itemTitle: appLocalizationsOf(context).dataTxID,
),
sizedBoxHeight16px,
if (item.fallbackTxId != null)
DetailsPanelItem(
leading: Row(
mainAxisSize: MainAxisSize.min,
children: [
_TxIdTextLink(txId: item.fallbackTxId!),
const SizedBox(width: 12),
CopyButton(
text: item.fallbackTxId!,
),
],
),
itemTitle: 'Manifest Fallback TxID',
),
sizedBoxHeight16px,
if (state is FsEntryFileInfoSuccess)
DetailsPanelItem(
// TODO: Localize
Expand Down
4 changes: 4 additions & 0 deletions lib/entities/file_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class FileEntity extends EntityWithCustomMetadata {
@JsonKey(includeFromJson: true, includeToJson: true)
Thumbnail? thumbnail;

@JsonKey(includeIfNull: false, name: 'fallbackTxId')
String? fallbackTxId;

@override
@JsonKey(includeFromJson: false, includeToJson: false)
List<String> reservedGqlTags = [
Expand Down Expand Up @@ -79,6 +82,7 @@ class FileEntity extends EntityWithCustomMetadata {
this.isHidden,
this.thumbnail,
this.assignedNames,
this.fallbackTxId,
}) : super(ArDriveCrypto());

FileEntity.withUserProvidedDetails({
Expand Down
4 changes: 4 additions & 0 deletions lib/manifest/domain/manifest_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ManifestRepositoryImpl implements ManifestRepository {
dataContentType: ContentType.manifest,
assignedNames:
manifest.assignedName != null ? [manifest.assignedName!] : null,
fallbackTxId: manifest.fallbackTxId,
);

manifestFileEntity.txId = manifest.metadataTxId!;
Expand Down Expand Up @@ -133,6 +134,7 @@ class ManifestRepositoryImpl implements ManifestRepository {
privacy: DrivePrivacyTag.public,
assignedName:
undername != null ? getLiteralARNSRecordName(undername) : null,
fallbackTxId: params.fallbackTxId,
),
wallet: params.wallet,
type: params.uploadType,
Expand Down Expand Up @@ -307,6 +309,7 @@ class ManifestUploadParams {
final String? existingManifestFileId;
final UploadType uploadType;
final Wallet wallet;
final String? fallbackTxId;

ManifestUploadParams({
required this.manifestFile,
Expand All @@ -315,5 +318,6 @@ class ManifestUploadParams {
required this.uploadType,
this.existingManifestFileId,
required this.wallet,
this.fallbackTxId,
});
}
1 change: 1 addition & 0 deletions lib/models/daos/drive_dao/drive_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ class DriveDao extends DatabaseAccessor<Database> with _$DriveDaoMixin {
? Value(jsonEncode(entity.thumbnail!.toJson()))
: const Value(null),
assignedNames: Value(_encodeAssignedNames(entity.assignedNames)),
fallbackTxId: Value(entity.fallbackTxId),
);

return into(fileEntries).insert(
Expand Down
8 changes: 7 additions & 1 deletion lib/models/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Database extends _$Database {
Database([QueryExecutor? e]) : super(e ?? openConnection());

@override
int get schemaVersion => 23;
int get schemaVersion => 24;
@override
MigrationStrategy get migration => MigrationStrategy(
onCreate: (Migrator m) {
Expand Down Expand Up @@ -148,6 +148,12 @@ class Database extends _$Database {
await m.addColumn(drives, drives.isHidden);
await m.addColumn(driveRevisions, driveRevisions.isHidden);
}
if (from < 24) {
logger.d('Migrating schema from v23 to v24');

await m.addColumn(fileEntries, fileEntries.fallbackTxId);
await m.addColumn(fileRevisions, fileRevisions.fallbackTxId);
}
} catch (e, stacktrace) {
logger.e(
'CRITICAL! Failed to migrate database from $from to $to',
Expand Down
1 change: 1 addition & 0 deletions lib/models/file_entry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extension FileEntryExtensions on FileEntry {
.map((e) => e.toString())
.toList()
: null,
fallbackTxId: fallbackTxId,
);

file.customJsonMetadata = parseCustomJsonMetadata(customJsonMetadata);
Expand Down
5 changes: 5 additions & 0 deletions lib/models/file_revision.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extension FileRevisionsCompanionExtensions on FileRevisionsCompanion {
path: '',
thumbnail: Value(thumbnail.value),
assignedNames: Value(assignedNames.value),
fallbackTxId: fallbackTxId,
);

/// Returns a list of [NetworkTransactionsCompanion] representing the metadata and data transactions
Expand Down Expand Up @@ -81,6 +82,7 @@ extension FileEntityExtensions on FileEntity {
isHidden: Value(isHidden ?? false),
thumbnail: Value(thumbnailData),
assignedNames: Value(assignedNamesData),
fallbackTxId: Value(fallbackTxId),
);
}

Expand Down Expand Up @@ -127,6 +129,9 @@ extension FileEntityExtensions on FileEntity {
[FileRevisionsCompanion? previousRevision]) {
if (previousRevision == null) {
return RevisionAction.create;
} else if (fallbackTxId != null &&
fallbackTxId != previousRevision.fallbackTxId.value) {
return RevisionAction.uploadNewVersion;
} else if (name != previousRevision.name.value) {
return RevisionAction.rename;
} else if (parentFolderId != previousRevision.parentFolderId.value) {
Expand Down
2 changes: 2 additions & 0 deletions lib/models/tables/file_entries.drift
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ CREATE TABLE file_entries (

assignedNames TEXT,

fallbackTxId TEXT,

PRIMARY KEY (id, driveId)
) AS FileEntry;
2 changes: 2 additions & 0 deletions lib/models/tables/file_revisions.drift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ CREATE TABLE file_revisions (

assignedNames TEXT,

fallbackTxId TEXT,

PRIMARY KEY (fileId, driveId, dateCreated),
FOREIGN KEY (licenseTxId) REFERENCES network_transactions(id),
FOREIGN KEY (metadataTxId) REFERENCES network_transactions(id),
Expand Down
8 changes: 6 additions & 2 deletions lib/pages/drive_detail/models/data_table_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class FileDataTableItem extends ArDriveDataTableItem {
final String? pinnedDataOwnerAddress;
final Thumbnail? thumbnail;
final List<String>? assignedNames;

final String? fallbackTxId;
FileDataTableItem(
{required super.driveId,
required super.lastUpdated,
Expand All @@ -108,6 +108,7 @@ class FileDataTableItem extends ArDriveDataTableItem {
required this.metadataTx,
required this.dataTx,
required this.pinnedDataOwnerAddress,
this.fallbackTxId,
this.assignedNames,
this.thumbnail,
super.licenseType,
Expand Down Expand Up @@ -158,6 +159,7 @@ class DriveDataTableItemMapper {
thumbnail: file.thumbnail != null && file.thumbnail != 'null'
? Thumbnail.fromJson(jsonDecode(file.thumbnail!))
: null,
fallbackTxId: file.fallbackTxId,
);
}

Expand Down Expand Up @@ -188,10 +190,11 @@ class DriveDataTableItemMapper {
thumbnail: fileEntry.thumbnail != null && fileEntry.thumbnail != 'null'
? Thumbnail.fromJson(jsonDecode(fileEntry.thumbnail!))
: null,
fallbackTxId: fileEntry.fallbackTxId,
);
}

static FolderDataTableItem fromFolderEntry(
static FolderDataTableItem fromFolderEntry(
FolderEntry folderEntry,
int index,
bool isOwner,
Expand Down Expand Up @@ -256,6 +259,7 @@ static FolderDataTableItem fromFolderEntry(
thumbnail: revision.thumbnail != null && revision.thumbnail != 'null'
? Thumbnail.fromJson(jsonDecode(revision.thumbnail!))
: null,
fallbackTxId: revision.fallbackTxId,
);
}
}
4 changes: 4 additions & 0 deletions packages/ardrive_uploader/lib/src/arfs_upload_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class ARFSFileUploadMetadata extends ARFSUploadMetadata with ARFSUploadData {
required super.id,
required super.isPrivate,
this.assignedName,
this.fallbackTxId,
});

/// The size of the file in bytes.
Expand Down Expand Up @@ -207,6 +208,8 @@ class ARFSFileUploadMetadata extends ARFSUploadMetadata with ARFSUploadData {

String? assignedName;

final String? fallbackTxId;

// Public method to set licenseTxId with validation or additional logic
void updateLicenseTxId(String licenseTxId) {
_licenseTxId = licenseTxId;
Expand Down Expand Up @@ -236,6 +239,7 @@ class ARFSFileUploadMetadata extends ARFSUploadMetadata with ARFSUploadData {
},
if (licenseTxId != null) 'licenseTxId': licenseTxId,
if (assignedName != null) 'assignedNames': [assignedName!],
if (fallbackTxId != null) 'fallbackTxId': fallbackTxId,
};
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/ardrive_uploader/lib/src/metadata_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class ARFSUploadMetadataGenerator
licenseDefinitionTxId: arguments.licenseDefinitionTxId,
licenseAdditionalTags: arguments.licenseAdditionalTags,
assignedName: arguments.assignedName,
fallbackTxId: arguments.fallbackTxId,
)
..setDataTags(tags['data-item']!)
..setEntityMetadataTags(tags['entity']!);
Expand Down Expand Up @@ -174,6 +175,7 @@ class ARFSUploadMetadataArgs extends Equatable {
final String? licenseDefinitionTxId;
final Map<String, String>? licenseAdditionalTags;
final String? assignedName;
final String? fallbackTxId;

factory ARFSUploadMetadataArgs.file({
required String driveId,
Expand All @@ -183,6 +185,7 @@ class ARFSUploadMetadataArgs extends Equatable {
String? entityId,
Map<String, String>? customBundleTags,
String? assignedName,
String? fallbackTxId,
}) {
return ARFSUploadMetadataArgs(
driveId: driveId,
Expand All @@ -191,6 +194,7 @@ class ARFSUploadMetadataArgs extends Equatable {
entityId: entityId,
type: type,
assignedName: assignedName,
fallbackTxId: fallbackTxId,
);
}

Expand Down Expand Up @@ -231,6 +235,7 @@ class ARFSUploadMetadataArgs extends Equatable {
this.licenseDefinitionTxId,
this.licenseAdditionalTags,
this.assignedName,
this.fallbackTxId,
});

@override
Expand Down

0 comments on commit 09bdce7

Please sign in to comment.