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-3173: Utilize Turbo Uploads for Quick Sync #1362

Merged
merged 31 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d36e8b6
feat(payment method selector): factors out a component in order to ma…
matibat Sep 12, 2023
c944ac1
feat(snapshots): let snapshots be uploaded with Turbo PE-3173
matibat Sep 12, 2023
96c167f
feat(snapshots): missing await PE-3173
matibat Sep 12, 2023
ae2937d
Merge remote-tracking branch 'origin/dev' into PE-3173
matibat Sep 13, 2023
2c461a9
feat(create snapshot cubit): free turbo uploads PE-3173
matibat Sep 14, 2023
598c77e
feat(upload form): adds back the call to _getInsufficientBalanceMessa…
matibat Sep 14, 2023
546900d
test(create snapshot): fixes nbronken tests PE-3173
matibat Sep 14, 2023
ea9f1c7
chore(create snapshot cubit & upload plan): cleanup PE-3173
matibat Sep 22, 2023
6636abd
feat(new button): makes the option for snaqpshots be enabled even whe…
matibat Sep 25, 2023
90f4685
Merge pull request #1382 from ardriveapp/PE-4665
matibat Sep 26, 2023
91b078b
feat(snapshot & upload): makes no balance message be part of payment …
matibat Sep 26, 2023
1a2e618
feat(upload cubit): makes the file upload modal show the correct not …
matibat Sep 26, 2023
405149c
feat(create snapshot cubit): let the snapshot use turbo uploads when …
matibat Sep 27, 2023
144aa4e
test(create snapshot cubit): fixes brokwn tests PE-4687
matibat Sep 27, 2023
abf45c6
feat(create snapshot cubit): corrects typo PE-4687
matibat Sep 27, 2023
51d4d63
Merge pull request #1385 from ardriveapp/PE-4676
matibat Sep 27, 2023
35e0cda
Merge pull request #1387 from ardriveapp/PE-4687
matibat Sep 27, 2023
9b8bfdd
Merge remote-tracking branch 'origin/dev' into PE-3173
matibat Sep 27, 2023
2e886f9
feat(create snapshot dialog): makes the turbo balance be refreshed on…
matibat Sep 28, 2023
853a3dd
feat(pubspec): updates the ardrive-ui dep PE-4694
matibat Sep 28, 2023
3b21e36
chore(create snapshot cubit): cleanup PE-4694
matibat Sep 28, 2023
b5ba8fc
feat(create snapshot cubit): adds a delay to ensure we'll read the co…
matibat Oct 2, 2023
6d84457
feat(dev tools): adds optoins for disabling free uploads, setting a f…
matibat Oct 2, 2023
4d1bf6c
feat(create snapshot cubit): update the state of the button after top…
matibat Oct 2, 2023
cf19253
test(create snapshot cubit): updates broken tests PE-4694
matibat Oct 2, 2023
dfb546d
chore(topup review view): corrects typo in a comment PE-4694
matibat Oct 3, 2023
faf9687
Merge pull request #1394 from ardriveapp/PE-4694
matibat Oct 4, 2023
f34cc58
Merge remote-tracking branch 'origin/dev' into PE-3173
matibat Oct 4, 2023
26ef3cf
chore(create snapshot cubit): removes unnecessary non-null assertion …
matibat Oct 4, 2023
ef0493c
feat(pubspec): version bump of ardrive-ui PE-3173
matibat Oct 4, 2023
2ab486d
Merge pull request #1402 from ardriveapp/PE-3173_dep_version_bump
matibat Oct 4, 2023
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
305 changes: 259 additions & 46 deletions lib/blocs/create_snapshot/create_snapshot_cubit.dart

Large diffs are not rendered by default.

75 changes: 70 additions & 5 deletions lib/blocs/create_snapshot/create_snapshot_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,85 @@ class CreateSnapshotInsufficientBalance extends CreateSnapshotState {

class ConfirmingSnapshotCreation extends CreateSnapshotState {
final int snapshotSize;
final String arUploadCost;
final double? usdUploadCost;

final UploadCostEstimate costEstimateAr;
final UploadCostEstimate? costEstimateTurbo;
final bool hasNoTurboBalance;
final bool isTurboUploadPossible;
final String arBalance;
final String turboCredits;
final UploadMethod uploadMethod;
final bool isButtonToUploadEnabled;
final bool sufficientBalanceToPayWithAr;
final bool sufficientBalanceToPayWithTurbo;
final bool isFreeThanksToTurbo;

ConfirmingSnapshotCreation({
required this.snapshotSize,
required this.arUploadCost,
required this.usdUploadCost,
required this.costEstimateAr,
required this.costEstimateTurbo,
required this.hasNoTurboBalance,
required this.isTurboUploadPossible,
required this.arBalance,
required this.turboCredits,
required this.uploadMethod,
required this.isButtonToUploadEnabled,
required this.sufficientBalanceToPayWithAr,
required this.sufficientBalanceToPayWithTurbo,
required this.isFreeThanksToTurbo,
});

@override
List<Object> get props => [
snapshotSize,
arUploadCost,
costEstimateAr,
costEstimateTurbo ?? '',
hasNoTurboBalance,
isTurboUploadPossible,
arBalance,
turboCredits,
uploadMethod,
isButtonToUploadEnabled,
sufficientBalanceToPayWithAr,
sufficientBalanceToPayWithTurbo,
isFreeThanksToTurbo,
];

ConfirmingSnapshotCreation copyWith({
int? snapshotSize,
String? arUploadCost,
double? usdUploadCost,
UploadCostEstimate? costEstimateAr,
UploadCostEstimate? costEstimateTurbo,
bool? hasNoTurboBalance,
bool? isTurboUploadPossible,
String? arBalance,
String? turboCredits,
UploadMethod? uploadMethod,
bool? isButtonToUploadEnabled,
bool? sufficientBalanceToPayWithAr,
bool? sufficientBalanceToPayWithTurbo,
bool? isFreeThanksToTurbo,
}) {
return ConfirmingSnapshotCreation(
snapshotSize: snapshotSize ?? this.snapshotSize,
costEstimateAr: costEstimateAr ?? this.costEstimateAr,
costEstimateTurbo: costEstimateTurbo ?? this.costEstimateTurbo,
hasNoTurboBalance: hasNoTurboBalance ?? this.hasNoTurboBalance,
isTurboUploadPossible:
isTurboUploadPossible ?? this.isTurboUploadPossible,
arBalance: arBalance ?? this.arBalance,
turboCredits: turboCredits ?? this.turboCredits,
uploadMethod: uploadMethod ?? this.uploadMethod,
isButtonToUploadEnabled:
isButtonToUploadEnabled ?? this.isButtonToUploadEnabled,
sufficientBalanceToPayWithAr:
sufficientBalanceToPayWithAr ?? this.sufficientBalanceToPayWithAr,
sufficientBalanceToPayWithTurbo: sufficientBalanceToPayWithTurbo ??
this.sufficientBalanceToPayWithTurbo,
isFreeThanksToTurbo: isFreeThanksToTurbo ?? this.isFreeThanksToTurbo,
);
}
}

class UploadingSnapshot extends CreateSnapshotState {}
Expand Down
6 changes: 4 additions & 2 deletions lib/blocs/upload/upload_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ class UploadCubit extends Cubit<UploadState> {
logger.d('Disabling button');
}

emit((state as UploadReady).copyWith(
uploadMethod: method, isButtonToUploadEnabled: isButtonEnabled));
emit(uploadReady.copyWith(
uploadMethod: method,
isButtonToUploadEnabled: isButtonEnabled,
));
}
}

Expand Down
31 changes: 31 additions & 0 deletions lib/blocs/upload/upload_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,42 @@ class UploadReady extends UploadState {
@override
List<Object?> get props => [
costEstimateAr,
costEstimateTurbo,
sufficientArBalance,
isZeroBalance,
sufficentCreditsBalance,
uploadIsPublic,
uploadPlanForAR,
uploadPlanForTurbo,
isTurboUploadPossible,
isFreeThanksToTurbo,
uploadSize,
credits,
arBalance,
turboCredits,
uploadMethod,
isButtonToUploadEnabled,
];

@override
toString() => 'UploadReady { '
'costEstimateAr: $costEstimateAr, '
'costEstimateTurbo: $costEstimateTurbo, '
'sufficientArBalance: $sufficientArBalance, '
'isZeroBalance: $isZeroBalance, '
'sufficentCreditsBalance: $sufficentCreditsBalance, '
'uploadIsPublic: $uploadIsPublic, '
'uploadPlanForAR: $uploadPlanForAR, '
'uploadPlanForTurbo: $uploadPlanForTurbo, '
'isTurboUploadPossible: $isTurboUploadPossible, '
'isFreeThanksToTurbo: $isFreeThanksToTurbo, '
'uploadSize: $uploadSize, '
'credits: $credits, '
'arBalance: $arBalance, '
'turboCredits: $turboCredits, '
'uploadMethod: $uploadMethod, '
'isButtonToUploadEnabled: $isButtonToUploadEnabled, '
'}';
}

class UploadInProgress extends UploadState {
Expand Down
83 changes: 53 additions & 30 deletions lib/components/create_snapshot_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import 'package:ardrive/authentication/ardrive_auth.dart';
import 'package:ardrive/blocs/blocs.dart';
import 'package:ardrive/blocs/create_snapshot/create_snapshot_cubit.dart';
import 'package:ardrive/blocs/profile/profile_cubit.dart';
import 'package:ardrive/components/components.dart';
import 'package:ardrive/components/payment_method_selector_widget.dart';
import 'package:ardrive/entities/string_types.dart';
import 'package:ardrive/models/models.dart';
import 'package:ardrive/services/arweave/arweave.dart';
import 'package:ardrive/services/config/config.dart';
import 'package:ardrive/services/pst/pst.dart';
import 'package:ardrive/theme/theme.dart';
import 'package:ardrive/turbo/services/payment_service.dart';
import 'package:ardrive/turbo/services/upload_service.dart';
import 'package:ardrive/turbo/turbo.dart';
import 'package:ardrive/utils/app_localizations_wrapper.dart';
import 'package:ardrive/utils/filesize.dart';
import 'package:ardrive/utils/html/html_util.dart';
import 'package:ardrive/utils/logger/logger.dart';
import 'package:ardrive/utils/show_general_dialog.dart';
import 'package:ardrive/utils/split_localizations.dart';
import 'package:ardrive_ui/ardrive_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../utils/usd_upload_cost_to_string.dart';

Future<void> promptToCreateSnapshot(
BuildContext context,
Drive drive,
) async {
return showArDriveDialog(
return showAnimatedDialog(
context,
barrierDismissible: false,
content: BlocProvider(
Expand All @@ -32,6 +35,13 @@ Future<void> promptToCreateSnapshot(
profileCubit: context.read<ProfileCubit>(),
pst: context.read<PstService>(),
tabVisibility: TabVisibilitySingleton(),
auth: context.read<ArDriveAuth>(),
paymentService: context.read<PaymentService>(),
turboBalanceRetriever: TurboBalanceRetriever(
paymentService: context.read<PaymentService>(),
),
configService: context.read<ConfigService>(),
turboService: context.read<TurboUploadService>(),
),
child: CreateSnapshotDialog(
drive: drive,
Expand Down Expand Up @@ -365,31 +375,6 @@ Widget _confirmDialog(
),
style: ArDriveTypography.body.buttonNormalRegular(),
),
const Divider(),
const SizedBox(height: 16),
Text.rich(
TextSpan(
children: [
TextSpan(
text: appLocalizationsOf(context).cost(
state.arUploadCost,
),
),
if (state.usdUploadCost != null)
TextSpan(
text: usdUploadCostToString(
state.usdUploadCost!,
),
)
else
TextSpan(
text:
' ${appLocalizationsOf(context).usdPriceNotAvailable}',
),
],
style: ArDriveTypography.body.buttonNormalRegular(),
),
),
Text.rich(
TextSpan(
children: [
Expand All @@ -402,6 +387,43 @@ Widget _confirmDialog(
style: ArDriveTypography.body.buttonNormalRegular(),
),
),
const Divider(),
const SizedBox(height: 16),
if (state.isFreeThanksToTurbo) ...{
Text(
appLocalizationsOf(context).freeTurboTransaction,
style: ArDriveTypography.body.buttonNormalRegular(
color: ArDriveTheme.of(context)
.themeData
.colors
.themeFgDefault,
),
),
} else ...{
PaymentMethodSelector(
uploadMethod: state.uploadMethod,
costEstimateTurbo: state.costEstimateTurbo,
costEstimateAr: state.costEstimateAr,
hasNoTurboBalance: state.hasNoTurboBalance,
isTurboUploadPossible: true,
arBalance: state.arBalance,
sufficientArBalance: state.sufficientBalanceToPayWithAr,
turboCredits: state.turboCredits,
sufficentCreditsBalance:
state.sufficientBalanceToPayWithTurbo,
isFreeThanksToTurbo: false,
onTurboTopupSucess: () {
createSnapshotCubit.refreshTurboBalance();
},
onArSelect: () {
createSnapshotCubit.setUploadMethod(UploadMethod.ar);
},
onTurboSelect: () {
createSnapshotCubit
.setUploadMethod(UploadMethod.turbo);
},
),
}
],
),
),
Expand All @@ -425,6 +447,7 @@ Widget _confirmDialog(
await createSnapshotCubit.confirmSnapshotCreation(),
},
title: appLocalizationsOf(context).uploadEmphasized,
isEnable: state.isButtonToUploadEnabled,
),
}
],
Expand Down
11 changes: 3 additions & 8 deletions lib/components/new_button/new_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ class NewButton extends StatelessWidget {
icon: ArDriveIcons.iconAttachDrive(size: defaultIconSize),
),
if (driveDetailState is DriveDetailLoadSuccess && drive != null) ...[
if (driveDetailState.currentDrive.privacy == 'public' &&
drive != null)
if (driveDetailState.currentDrive.privacy == 'public')
ArDriveNewButtonItem(
onClick: () {
promptToCreateManifest(
Expand All @@ -319,8 +318,7 @@ class NewButton extends StatelessWidget {
name: appLocalizations.createManifest,
icon: ArDriveIcons.tournament(size: defaultIconSize),
),
if (context.read<ConfigService>().config.enableQuickSyncAuthoring &&
drive != null)
if (context.read<ConfigService>().config.enableQuickSyncAuthoring)
ArDriveNewButtonItem(
onClick: () {
promptToCreateSnapshot(
Expand All @@ -329,10 +327,7 @@ class NewButton extends StatelessWidget {
);
},
isDisabled: !driveDetailState.hasWritePermissions ||
driveDetailState.driveIsEmpty ||
!profile.hasMinimumBalanceForUpload(
minimumWalletBalance: minimumWalletBalance,
),
driveDetailState.driveIsEmpty,
name: appLocalizations.createSnapshot,
icon: ArDriveIcons.iconCreateSnapshot(size: defaultIconSize),
),
Expand Down
Loading
Loading