Skip to content

Commit

Permalink
handle consistency between idenfy and getVerification
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaaElattar committed Jan 8, 2025
1 parent 9217f7b commit eb5c850
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions app/lib/widgets/kyc_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,35 @@ Future<void> verifyIdentityProcess({
Future<void> handleIdenfyResponse({
required BuildContext context,
required String walletSeed,
AutoIdentificationStatus? idenfyState,
}) async {
VerificationStatus verificationStatus;
try {
final idenfyServiceUrl = Globals().idenfyServiceUrl;
verificationStatus = await getVerificationStatus(
address: walletSeed, idenfyServiceUrl: idenfyServiceUrl);
bool statesMatch =
_areStatesMatching(idenfyState, verificationStatus.status);

if (!statesMatch) {
logger.i('States do not match. Retrying after 5 seconds...');
await Future.delayed(const Duration(seconds: 5));

verificationStatus = await getVerificationStatus(
address: walletSeed, idenfyServiceUrl: idenfyServiceUrl);

statesMatch = _areStatesMatching(idenfyState, verificationStatus.status);

if (!statesMatch) {
showErrorDialog(
context: context,
title: 'Error',
description:
'Something went wrong. Please contact support if this issue persists.',
);
return;
}
}
} catch (e) {
logger.e(e);
showErrorDialog(
Expand Down Expand Up @@ -300,11 +323,12 @@ Future<void> initIdenfySdk(String token,
'Something went wrong. Please contact support if this issue persists.');
}
}
await Future.delayed(const Duration(seconds: 13));
if (idenfySDKresult != null &&
idenfySDKresult.autoIdentificationStatus !=
AutoIdentificationStatus.UNVERIFIED) {
await handleIdenfyResponse(context: context, walletSeed: walletSeed);
await Future.delayed(const Duration(seconds: 10));
if (idenfySDKresult != null) {
await handleIdenfyResponse(
context: context,
walletSeed: walletSeed,
idenfyState: idenfySDKresult.autoIdentificationStatus);
}
}

Expand Down Expand Up @@ -641,3 +665,19 @@ Future<dynamic> showIdentityDetails(BuildContext context, String walletSeed) {
),
));
}

bool _areStatesMatching(AutoIdentificationStatus? idenfyState,
VerificationState? verificationState) {
if (idenfyState == null || verificationState == null) {
return false;
}

final stateMapping = {
'APPROVED': VerificationState.VERIFIED,
'FAILED': VerificationState.REJECTED,
'UNVERIFIED': VerificationState.UNVERIFIED,
};

final mappedState = stateMapping[idenfyState.name];
return mappedState == verificationState;
}

0 comments on commit eb5c850

Please sign in to comment.