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

support kyc for each wallet #827

Open
wants to merge 32 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
949f839
WIP: support kyc for each wallet
AlaaElattar Dec 25, 2024
c77aece
WIP: move kyc verification steps to separate component
AlaaElattar Dec 25, 2024
5e1d4c0
WIP: move kyc to separate componnet
AlaaElattar Dec 25, 2024
521495e
WIP: add kyc fucntions in separate file
AlaaElattar Dec 29, 2024
8b13b92
WIP: trying to fix error while verifying kyc
AlaaElattar Dec 29, 2024
f8f76a8
undo changes in podfile.lock
AlaaElattar Dec 29, 2024
6263895
idenfy-service-url
AlaaElattar Dec 29, 2024
1bce7c0
remove prints && commnted lines
AlaaElattar Dec 29, 2024
bd42cbb
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Dec 29, 2024
0406d98
fix threads bug
AlaaElattar Dec 29, 2024
9c150e9
wip: fix verifying kyc
AlaaElattar Dec 30, 2024
2e157bf
fix kyc data dialog && remove kyc from identity screen
AlaaElattar Dec 31, 2024
35e3511
fix context bug
AlaaElattar Jan 1, 2025
7699e63
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Jan 1, 2025
3b490f4
remove kyc stuff from identity preferences
AlaaElattar Jan 2, 2025
b3d9d11
remove debug logs
AlaaElattar Jan 5, 2025
746a3d6
fix bug of not showing email
AlaaElattar Jan 5, 2025
374c859
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Jan 6, 2025
f97c6ec
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Jan 6, 2025
655bd20
remove debug logs
AlaaElattar Jan 8, 2025
9217f7b
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Jan 8, 2025
eb5c850
handle consistency between idenfy and getVerification
AlaaElattar Jan 8, 2025
559b137
handle checking for status until it matches idenfy
AlaaElattar Jan 8, 2025
bd535d8
remove identity global var && shred prefrences functions
AlaaElattar Jan 8, 2025
a1b1cce
fix bug of failed verification
AlaaElattar Jan 8, 2025
1bfe5f7
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Jan 9, 2025
b7f4ca1
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Jan 9, 2025
23cffe3
Merge branch 'development' of github.com:threefoldtech/threefold_conn…
AlaaElattar Jan 15, 2025
c6ac685
fix warnings in workflow
AlaaElattar Jan 15, 2025
0262cce
WIP: handle refresh wallet after verification
AlaaElattar Jan 15, 2025
e2721b6
WIP: fix refreshing state
AlaaElattar Jan 16, 2025
38749aa
added listener on idenfy state for refreshing
AlaaElattar Jan 16, 2025
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
1 change: 0 additions & 1 deletion app/lib/helpers/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Globals {

ValueNotifier<bool> emailVerified = ValueNotifier(false);
ValueNotifier<bool> phoneVerified = ValueNotifier(false);
ValueNotifier<bool> identityVerified = ValueNotifier(false);

final JRouter router = JRouter();

Expand Down
41 changes: 0 additions & 41 deletions app/lib/helpers/kyc_helpers.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import 'dart:convert';

import 'package:flutter_pkid/flutter_pkid.dart';
import 'package:threebotlogin/models/idenfy.dart';
import 'package:threebotlogin/services/idenfy_service.dart';
import 'package:threebotlogin/services/migration_service.dart';
import 'package:threebotlogin/services/pkid_service.dart';
import 'package:threebotlogin/services/tfchain_service.dart';
import 'package:threebotlogin/services/tools_service.dart';
import 'package:threebotlogin/services/shared_preference_service.dart';

Expand All @@ -31,16 +28,9 @@ Future<void> fetchPKidData() async {

Future<void> handleKYCData(
Map<dynamic, dynamic> emailData, Map<dynamic, dynamic> phoneData) async {
final address = await getMyAddress();
final identityVerificationStatus =
await getVerificationStatus(address: address);

await saveCorrectVerificationStates(
emailData, phoneData, identityVerificationStatus);

bool? isEmailVerified = await getIsEmailVerified();
bool? isPhoneVerified = await getIsPhoneVerified();
bool? isIdentityVerified = await getIsIdentityVerified();

// This method got refactored due my mistake in one little mapping in the migration from no pkid to pkid
if (isEmailVerified == false) {
Expand All @@ -64,39 +54,8 @@ Future<void> handleKYCData(
Globals().phoneVerified.value = true;
await savePhoneInCorrectFormatPKid(phoneData);
}

if (isIdentityVerified == true) {
Globals().identityVerified.value = true;
final data = await getVerificationData();
final firstName = utf8.decode(latin1.encode(data.orgFirstName!));
final lastName = utf8.decode(latin1.encode(data.orgLastName!));
await saveIdentity('$lastName $firstName', data.docIssuingCountry,
data.docDob, data.docSex, data.idenfyRef);
}
}

Future<void> saveCorrectVerificationStates(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you remove this method?

Map<dynamic, dynamic> emailData,
Map<dynamic, dynamic> phoneData,
VerificationStatus identityVerificationStatus) async {
if (identityVerificationStatus.status == VerificationState.VERIFIED) {
await setIsIdentityVerified(true);
} else {
await setIsIdentityVerified(false);
}

if (phoneData.containsKey('spi')) {
await setIsPhoneVerified(true);
} else {
await setIsPhoneVerified(false);
}

if (emailData.containsKey('sei')) {
await setIsEmailVerified(true);
} else {
await setIsEmailVerified(false);
}
}

bool checkEmail(String email) {
String? emailValue =
Expand Down
74 changes: 0 additions & 74 deletions app/lib/helpers/login_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,80 +49,6 @@ Future<Map<String, dynamic>?> readScopeAsObject(
scope['digitalTwin'] = 'OK';
}

if (scopePermissionsDecoded['identityName'] == true) {
Map<String, dynamic> identityDetails = await getIdentity();

String identityName = identityDetails['identityName'];
String sIdentityName = identityDetails['signedIdentityNameIdentifier'];

scope['identityName'] = {
'identityName': identityName,
'signedIdentityNameIdentifier': sIdentityName
};
}

if (scopePermissionsDecoded['identityDOB'] == true) {
Map<String, dynamic> identityDetails = await getIdentity();

String identityDOB = identityDetails['identityDOB'];
String sIdentityDOB = identityDetails['signedIdentityDOBIdentifier'];

scope['identityDOB'] = {
'identityDOB': identityDOB,
'signedIdentityDOB': sIdentityDOB
};
}

if (scopePermissionsDecoded['identityCountry'] == true) {
Map<String, dynamic> identityDetails = await getIdentity();

String identityCountry = identityDetails['identityCountry'];
String sIdentityCountryIdentifier =
identityDetails['signedIdentityCountryIdentifier'];

scope['identityCountry'] = {
'identityCountry': identityCountry,
'signedIdentityCountryIdentifier': sIdentityCountryIdentifier
};
}

if (scopePermissionsDecoded['identityCountry'] == true) {
Map<String, dynamic> identityDetails = await getIdentity();

String identityCountry = identityDetails['identityCountry'];
String sIdentityCountryIdentifier =
identityDetails['signedIdentityCountryIdentifier'];

scope['identityCountry'] = {
'identityCountry': identityCountry,
'signedIdentityCountryIdentifier': sIdentityCountryIdentifier
};
}

if (scopePermissionsDecoded['identityDocumentMeta'] == true) {
Map<String, dynamic> identityDetails = await getIdentity();

String identityDocumentMeta = identityDetails['identityDocumentMeta'];
String sIdentityDocumentMeta =
identityDetails['signedIdentityCountryIdentifier'];

scope['identityDocumentMeta'] = {
'identityDocumentMeta': identityDocumentMeta,
'signedIdentityDocumentMeta': sIdentityDocumentMeta
};
}

if (scopePermissionsDecoded['identityGender'] == true) {
Map<String, dynamic> identityDetails = await getIdentity();

String identityGender = identityDetails['identityGender'];
String sIdentityGender = identityDetails['signedIdentityGender'];

scope['identityGender'] = {
'identityGender': identityGender,
'signedIdentityGender': sIdentityGender
};
}

if (scopePermissionsDecoded['walletAddress'] == true) {
scope['walletAddressData'] = {
Expand Down
4 changes: 1 addition & 3 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ Future<void> main() async {
Future<void> setGlobalValues() async {
Map<String, String?> email = await getEmail();
Map<String, String?> phone = await getPhone();
Map<String, dynamic> identity = await getIdentity();

Globals().emailVerified.value = (email['sei'] != null);
Globals().phoneVerified.value = (phone['spi'] != null);
Globals().identityVerified.value =
(identity['signedIdentityNameIdentifier'] != null);

}

class MyApp extends ConsumerWidget {
Expand Down
2 changes: 2 additions & 0 deletions app/lib/models/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Wallet {
required this.tfchainAddress,
required this.tfchainBalance,
required this.type,
required this.verificationStatus,
});
String name;
final String stellarSecret;
Expand All @@ -23,6 +24,7 @@ class Wallet {
String stellarBalance;
String tfchainBalance;
final WalletType type;
String verificationStatus;
}

class PkidWallet {
Expand Down
21 changes: 21 additions & 0 deletions app/lib/providers/wallets_provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:mutex/mutex.dart';
import 'package:threebotlogin/helpers/globals.dart';
import 'package:threebotlogin/helpers/logger.dart';
import 'package:threebotlogin/models/wallet.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:threebotlogin/services/idenfy_service.dart';
import 'package:threebotlogin/services/wallet_service.dart';

import 'package:threebotlogin/services/stellar_service.dart' as StellarService;
Expand Down Expand Up @@ -48,6 +50,25 @@ class WalletsNotifier extends StateNotifier<List<Wallet>> {
});
}

Future<void> verifyWallet(String walletName) async {
final idenfyServiceUrl = Globals().idenfyServiceUrl;
await _mutex.protect(() async {
final wallet = state.where((w) => w.name == walletName).firstOrNull;
if (wallet != null) {
try {
final updatedVerificationStatus = await getVerificationStatus(
address: wallet.tfchainAddress,
idenfyServiceUrl: idenfyServiceUrl,
);
wallet.verificationStatus = updatedVerificationStatus.status.name;
state = [...state];
} catch (e) {
logger.e('[verifyWallet] Error during verification: $e');
}
}
});
}

void reloadBalances() async {
if (!_reload) return await TFChainService.disconnect();
if (!_loading) {
Expand Down
Loading
Loading