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-4694: Credit update issue during snapshot creation purchase #1394

Merged
merged 8 commits into from
Oct 4, 2023
36 changes: 36 additions & 0 deletions lib/blocs/create_snapshot/create_snapshot_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,42 @@ class CreateSnapshotCubit extends Cubit<CreateSnapshotState> {
);
}

Future<void> refreshTurboBalance() async {
final profileState = _profileCubit.state as ProfileLoggedIn;
final wallet = profileState.wallet;

final turboBalance =
await turboBalanceRetriever.getBalance(wallet).catchError((e) {
logger.e('Error while retrieving turbo balance', e);
return BigInt.zero;
});

_turboBalance = turboBalance;
_hasNoTurboBalance = turboBalance == BigInt.zero;
_turboCredits = convertCreditsToLiteralString(turboBalance);
_sufficentCreditsBalance = _costEstimateTurbo.totalCost <= _turboBalance;
_computeIsTurboEnabled();
_computeIsButtonEnabled();

if (state is ConfirmingSnapshotCreation) {
final stateAsConfirming = state as ConfirmingSnapshotCreation;
logger.d('Refreshing turbo balance...');
logger.d('Turbo balance: $_turboCredits - ($_turboBalance)');
logger.d('Has no turbo balance: $_hasNoTurboBalance');
logger
.d('Sufficient balance to pay with turbo: $_sufficentCreditsBalance');
logger.d('Upload method: $_uploadMethod');
matibat marked this conversation as resolved.
Show resolved Hide resolved
emit(
stateAsConfirming.copyWith(
turboCredits: _turboCredits,
hasNoTurboBalance: _hasNoTurboBalance,
sufficientBalanceToPayWithTurbo: _sufficentCreditsBalance,
uploadMethod: _uploadMethod,
),
);
}
}

Future<void> _computeBalanceEstimate() async {
final profileState = _profileCubit.state as ProfileLoggedIn;
final wallet = profileState.wallet;
Expand Down
3 changes: 1 addition & 2 deletions lib/components/create_snapshot_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ Widget _confirmDialog(
state.sufficientBalanceToPayWithTurbo,
isFreeThanksToTurbo: false,
onTurboTopupSucess: () {
createSnapshotCubit
.setUploadMethod(UploadMethod.turbo);
createSnapshotCubit.refreshTurboBalance();
},
onArSelect: () {
createSnapshotCubit.setUploadMethod(UploadMethod.ar);
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "v1.10.0"
resolved-ref: "72cd21de7cbd52067924cefac579cdb9d7ef39b7"
ref: PE-4694
resolved-ref: "031eeac4673b636bbd44f2a91cc03bdcedf9762d"
url: "https://github.com/ar-io/ardrive_ui.git"
source: git
version: "1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies:
ardrive_ui:
git:
url: https://github.com/ar-io/ardrive_ui.git
ref: v1.10.0
ref: PE-4694
artemis: ^7.0.0-beta.13
arweave:
git:
Expand Down
Loading