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-6731: Release ArDrive v2.54.1 #1851

Merged
merged 10 commits into from
Sep 12, 2024
1 change: 1 addition & 0 deletions android/fastlane/metadata/android/en-US/changelogs/151.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Improved ArNS names load for single upload modal
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));
} 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
14 changes: 2 additions & 12 deletions lib/turbo/services/payment_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,10 @@ class PaymentService {
Future<BigInt> getBalance({
required Wallet wallet,
}) async {
final nonce = const Uuid().v4();
final publicKey = await wallet.getOwner();
final signature = await signNonceAndData(
nonce: nonce,
wallet: wallet,
);
try {
final result = await httpClient.get(
url: '$turboPaymentUri/v1/balance',
headers: {
'x-nonce': nonce,
'x-signature': signature,
'x-public-key': publicKey,
},
url:
'$turboPaymentUri/v1/account/balance/arweave?address=${await wallet.getAddress()}',
);

final price = BigInt.parse((json.decode(result.data)['winc']));
Expand Down
6 changes: 3 additions & 3 deletions test/services/payment_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void main() async {

when(
() => httpClient.get(
url: '$fakeUrl/v1/balance',
url: '$fakeUrl/v1/account/balance/arweave?address=$walletAddress',
headers: any(named: 'headers'),
),
).thenAnswer(
Expand Down Expand Up @@ -249,7 +249,7 @@ void main() async {
() async {
when(
() => httpClient.get(
url: '$fakeUrl/v1/balance',
url: '$fakeUrl/v1/account/balance/arweave?address=$walletAddress',
headers: any(named: 'headers'),
),
).thenThrow(ArDriveHTTPException(
Expand All @@ -266,7 +266,7 @@ void main() async {
test('should throw an exception if the status code is not 404', () async {
when(
() => httpClient.get(
url: '$fakeUrl/v1/balance',
url: '$fakeUrl/v1/account/balance/arweave?address=$walletAddress',
headers: any(named: 'headers'),
),
).thenThrow(ArDriveHTTPException(
Expand Down
Loading