Skip to content

Commit

Permalink
added listener on idenfy state for refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaaElattar committed Jan 16, 2025
1 parent e2721b6 commit 38749aa
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/lib/models/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Wallet {
String stellarBalance;
String tfchainBalance;
final WalletType type;
late String verificationStatus;
String verificationStatus;
}

class PkidWallet {
Expand Down
28 changes: 17 additions & 11 deletions app/lib/providers/wallets_provider.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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';
Expand Down Expand Up @@ -49,19 +50,24 @@ 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;
final updatedVerificationStatus = await getVerificationStatus(
address: wallet!.tfchainAddress, idenfyServiceUrl: idenfyServiceUrl);

if (wallet.verificationStatus != updatedVerificationStatus.status.name) {
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');
}
state = [...state];
});
}
}
});
}

void reloadBalances() async {
if (!_reload) return await TFChainService.disconnect();
Expand Down
29 changes: 28 additions & 1 deletion app/lib/screens/wallets/wallet_info.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:threebotlogin/events/events.dart';
import 'package:threebotlogin/events/identity_callback_event.dart';
import 'package:threebotlogin/helpers/logger.dart';
import 'package:threebotlogin/models/wallet.dart';
import 'package:threebotlogin/providers/wallets_provider.dart';
Expand Down Expand Up @@ -289,7 +293,30 @@ class _WalletDetailsWidgetState extends ConsumerState<WalletDetailsWidget> {
if (wallet.verificationStatus != 'VERIFIED') {
await termsAndConditionsDialog(
context: context, wallet: wallet);
await walletsRef.verifyWallet(wallet.name);

final completer = Completer<void>();
StreamSubscription? subscription;
try {
subscription =
Events().onEvent(IdentityCallbackEvent, (event) {
if (event is IdentityCallbackEvent &&
event.type == 'success') {
logger.i(
'[Event Listener] IdentityCallbackEvent with success received.');
completer.complete();
}
});

await completer.future;
await walletsRef.verifyWallet(wallet.name);
} catch (e) {
logger.e(
'[Event Listener] Error while waiting for event: $e');
} finally {
if (subscription != null) {
await subscription.cancel();
}
}
} else {
showIdentityDetails(context, wallet.tfchainSecret);
}
Expand Down

0 comments on commit 38749aa

Please sign in to comment.