Skip to content

Commit

Permalink
fix: Avoid double scan to get and present #2668
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Jul 9, 2024
1 parent d1c7724 commit 5b7dd05
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 88 deletions.
9 changes: 9 additions & 0 deletions lib/credentials/cubit/credentials_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class CredentialsCubit extends Cubit<CredentialsState> {

Future<void> addWalletCredential({
required BlockchainType? blockchainType,
required QRCodeScanCubit qrCodeScanCubit,
}) async {
final log = getLogger('addRequiredCredentials');

Expand Down Expand Up @@ -175,6 +176,7 @@ class CredentialsCubit extends Cubit<CredentialsState> {
credential: walletCredential,
showMessage: false,
blockchainType: blockchainType,
qrCodeScanCubit: qrCodeScanCubit,
);
}
}
Expand Down Expand Up @@ -261,6 +263,7 @@ class CredentialsCubit extends Cubit<CredentialsState> {
Future<void> insertCredential({
required CredentialModel credential,
required BlockchainType? blockchainType,
required QRCodeScanCubit qrCodeScanCubit,
bool showMessage = true,
bool showStatus = true,
bool isPendingCredential = false,
Expand Down Expand Up @@ -335,6 +338,10 @@ class CredentialsCubit extends Cubit<CredentialsState> {
: null,
),
);

if (qrCodeScanCubit.missingCredentialCompleter != null) {
qrCodeScanCubit.missingCredentialCompleter!.complete(true);
}
}

void enableCredentialCategory({required CredentialCategory category}) {
Expand Down Expand Up @@ -503,6 +510,7 @@ class CredentialsCubit extends Cubit<CredentialsState> {

Future<void> insertAssociatedWalletCredential({
required CryptoAccountData cryptoAccountData,
required QRCodeScanCubit qrCodeScanCubit,
}) async {
final supportAssociatedCredential =
supportCryptoCredential(profileCubit.state.model);
Expand Down Expand Up @@ -549,6 +557,7 @@ class CredentialsCubit extends Cubit<CredentialsState> {
await insertCredential(
credential: credential,
blockchainType: cryptoAccountData.blockchainType,
qrCodeScanCubit: qrCodeScanCubit,
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class _CameraViewState extends State<CameraView> {
.currentAccount!
.blockchainType,
vcFormatType: customOidc4vcProfile.vcFormatType,
qrCodeScanCubit: context.read<QRCodeScanCubit>(),
);
LoadingView().hide();
await Navigator.pushReplacement<void, void>(
Expand Down
5 changes: 5 additions & 0 deletions lib/dashboard/home/home/cubit/home_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:altme/app/app.dart';
import 'package:altme/credentials/credentials.dart';
import 'package:altme/dashboard/dashboard.dart';
import 'package:altme/dashboard/home/tab_bar/credentials/models/activity/activity.dart';
import 'package:altme/dashboard/qr_code/qr_code.dart';
import 'package:bloc/bloc.dart';
import 'package:credential_manifest/credential_manifest.dart';
import 'package:crypto/crypto.dart';
Expand Down Expand Up @@ -44,6 +45,7 @@ class HomeCubit extends Cubit<HomeState> {
required OIDC4VCIDraftType oidc4vciDraftType,
required BlockchainType blockchainType,
required VCFormatType vcFormatType,
required QRCodeScanCubit qrCodeScanCubit,
}) async {
// launch url to get Over18, Over15, Over13,Over21,Over50,Over65,
// AgeRange Credentials
Expand Down Expand Up @@ -101,6 +103,7 @@ class HomeCubit extends Cubit<HomeState> {
oidc4vciDraftType: oidc4vciDraftType,
blockchainType: blockchainType,
vcFormatType: vcFormatType,
qrCodeScanCubit: qrCodeScanCubit,
);

await ageEstimate(
Expand Down Expand Up @@ -160,6 +163,7 @@ class HomeCubit extends Cubit<HomeState> {
required OIDC4VCIDraftType oidc4vciDraftType,
required BlockchainType blockchainType,
required VCFormatType vcFormatType,
required QRCodeScanCubit qrCodeScanCubit,
}) async {
/// if credential of this type is already in the wallet do nothing
/// Ensure credentialType = name of credential type in CredentialModel
Expand Down Expand Up @@ -216,6 +220,7 @@ class HomeCubit extends Cubit<HomeState> {
credential: credentialModel,
showMessage: true,
blockchainType: blockchainType,
qrCodeScanCubit: qrCodeScanCubit,
);
await cameraCubit.incrementAcquiredCredentialsQuantity();
emit(state.copyWith(status: AppStatus.success));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ class _CredentialsDetailsViewState extends State<CredentialsDetailsView> {
.read<QRCodeScanCubit>()
.startOIDC4VCDeferedCredentialIssuance(
credentialModel: widget.credentialModel,
qrCodeScanCubit:
context.read<QRCodeScanCubit>(),
);
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ Future<void> discoverCredential({
if (dummyCredential.credentialSubjectType.isBlockchainAccount) {
final credentialCubit = context.read<CredentialsCubit>();
final walletCubit = context.read<WalletCubit>();
final qrCodeScanCubit = context.read<QRCodeScanCubit>();

final cryptoAccountData = walletCubit.state.currentAccount;

if (cryptoAccountData != null) {
await credentialCubit.insertAssociatedWalletCredential(
cryptoAccountData: cryptoAccountData,
qrCodeScanCubit: qrCodeScanCubit,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
preAuthorizedCode: preAuthorizedCode,
isEBSIV3: isEBSIV3,
credentialOfferJson: credentialOfferJson,
qrCodeScanCubit:
context.read<QRCodeScanCubit>(),
);
},
text: l10n.proceed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ class PolygonIdCredentialOfferPage extends StatelessWidget {
context: context,
localAuthApi: LocalAuthApi(),
onSuccess: () {
context.read<PolygonIdCubit>().addPolygonIdCredentials();
context.read<PolygonIdCubit>().addPolygonIdCredentials(
qrCodeScanCubit: context.read<QRCodeScanCubit>(),
);
},
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ class _CredentialsReceivePageState extends State<CredentialsReceivePage> {
);
} else {
context.read<ScanCubit>().credentialOfferOrPresent(
uri: widget.uri,
credentialModel: credentialModel,
keyId: SecureStorageKeys.ssiKey,
issuer: widget.issuer,
credentialsToBePresented: [],
);
uri: widget.uri,
credentialModel: credentialModel,
keyId: SecureStorageKeys.ssiKey,
issuer: widget.issuer,
credentialsToBePresented: [],
qrCodeScanCubit: context.read<QRCodeScanCubit>(),
);
}
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class MissingCredentialsView extends StatelessWidget {
Widget build(BuildContext context) {
final l10n = context.l10n;


return BlocBuilder<MissingCredentialsCubit, MissingCredentialsState>(
builder: (context, state) {
return BasePage(
Expand Down Expand Up @@ -123,7 +122,7 @@ class MissingCredentialsView extends StatelessWidget {
),
);
}
Navigator.pop(context);
Navigator.pop(context, true);
},
text: l10n.getItNow,
),
Expand Down
Loading

0 comments on commit 5b7dd05

Please sign in to comment.