Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE-6730: Decouple arns loading from the main upload flow #1848

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/arns/domain/arns_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class _ARNSRepository implements ARNSRepository {
} catch (e) {
logger.e('Error getting ANT records for wallet: $e');

_getARNSUndernamesCompleter!.complete([]);
_getARNSUndernamesCompleter!.completeError(e);

_getARNSUndernamesCompleter = null;

Expand Down
70 changes: 53 additions & 17 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,60 @@ class UploadCubit extends Cubit<UploadState> {
isNextButtonEnabled: canUpload,
));
} else if (state is UploadReadyToPrepare) {
final hasUndernames = (await _arnsRepository
.getAntRecordsForWallet(_auth.currentUser.walletAddress))
.isNotEmpty;
bool showArnsCheckbox = false;

emit(
UploadReady(
params: (state as UploadReadyToPrepare).params,
paymentInfo: paymentInfo,
numberOfFiles: files.length,
uploadIsPublic: !_targetDrive.isPrivate,
isDragNDrop: isDragNDrop,
isNextButtonEnabled: canUpload,
isArConnect: (state as UploadReadyToPrepare).isArConnect,
showArnsCheckbox:
hasUndernames && files.length == 1 && _targetDrive.isPublic,
showArnsNameSelection: false,
),
);
if (_targetDrive.isPublic && files.length == 1) {
emit(
UploadReady(
params: (state as UploadReadyToPrepare).params,
paymentInfo: paymentInfo,
numberOfFiles: files.length,
uploadIsPublic: !_targetDrive.isPrivate,
isDragNDrop: isDragNDrop,
isNextButtonEnabled: canUpload,
isArConnect: (state as UploadReadyToPrepare).isArConnect,
showArnsCheckbox: showArnsCheckbox,
showArnsNameSelection: false,
loadingArNSNames: true,
),
);

try {
final hasUndernames = (await _arnsRepository
.getAntRecordsForWallet(_auth.currentUser.walletAddress))
.isNotEmpty;

showArnsCheckbox = hasUndernames;

if (state is! UploadReady) {
logger.d('State is not UploadReady');
return;
}

final readyState = state as UploadReady;

emit(readyState.copyWith(
loadingArNSNames: false, showArnsCheckbox: showArnsCheckbox));
kunstmusik marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
final readyState = state as UploadReady;
emit(readyState.copyWith(
loadingArNSNamesError: true, loadingArNSNames: false));
}
} else {
emit(
UploadReady(
params: (state as UploadReadyToPrepare).params,
paymentInfo: paymentInfo,
numberOfFiles: files.length,
uploadIsPublic: !_targetDrive.isPrivate,
isDragNDrop: isDragNDrop,
isNextButtonEnabled: canUpload,
isArConnect: (state as UploadReadyToPrepare).isArConnect,
showArnsCheckbox: showArnsCheckbox,
showArnsNameSelection: false,
),
);
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions lib/blocs/upload/upload_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class UploadReady extends UploadState {
final UploadParams params;
final bool showArnsCheckbox;
final bool showArnsNameSelection;
final bool loadingArNSNames;
final bool loadingArNSNamesError;

final bool isArConnect;

Expand All @@ -108,6 +110,8 @@ class UploadReady extends UploadState {
required this.isArConnect,
required this.showArnsCheckbox,
required this.showArnsNameSelection,
this.loadingArNSNames = false,
this.loadingArNSNamesError = false,
});

// copyWith
Expand All @@ -123,8 +127,11 @@ class UploadReady extends UploadState {
bool? showSettings,
bool? showArnsCheckbox,
bool? showArnsNameSelection,
bool? loadingArNSNames,
bool? loadingArNSNamesError,
}) {
return UploadReady(
loadingArNSNames: loadingArNSNames ?? this.loadingArNSNames,
isArConnect: isArConnect ?? this.isArConnect,
uploadIsPublic: uploadIsPublic ?? this.uploadIsPublic,
isDragNDrop: isDragNDrop ?? this.isDragNDrop,
Expand All @@ -135,6 +142,8 @@ class UploadReady extends UploadState {
showArnsCheckbox: showArnsCheckbox ?? this.showArnsCheckbox,
showArnsNameSelection:
showArnsNameSelection ?? this.showArnsNameSelection,
loadingArNSNamesError:
loadingArNSNamesError ?? this.loadingArNSNamesError,
);
}

Expand All @@ -143,6 +152,9 @@ class UploadReady extends UploadState {
paymentInfo,
isNextButtonEnabled,
showArnsNameSelection,
loadingArNSNamesError,
loadingArNSNames,
showArnsCheckbox,
];

@override
Expand Down
39 changes: 38 additions & 1 deletion lib/components/upload_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,44 @@ class _UploadFormState extends State<UploadForm> {
],
),
),
if (state.showArnsCheckbox)
if (state.loadingArNSNamesError)
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
Text(
'Error loading ARNS names',
style: typography.paragraphLarge(
fontWeight: ArFontWeight.semiBold,
color: colorTokens.textRed,
),
),
],
),
),
if (state.loadingArNSNames)
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [
Text(
'Loading ArNS names...',
style: typography.paragraphLarge(
fontWeight: ArFontWeight.semiBold,
),
),
const SizedBox(width: 8),
const SizedBox(
height: 16,
width: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
),
)
],
),
),
if (state.showArnsCheckbox && !state.loadingArNSNames)
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
Expand Down
Loading