Skip to content

Commit

Permalink
fix: kyc data first load waiting (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
Merculiar authored Dec 13, 2024
1 parent 708d073 commit 8365230
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class KycSharingService extends ValueNotifier<UserData?> {

StreamSubscription<void>? _pollingSubscription;

final _isInitialized = Completer<void>();
Future<void> get initialized => _isInitialized.future.then((_) async {
if (value == null) {
await fetchUserData();
}
});

@PostConstruct()
void init() {
if (!sl<FeatureFlagsManager>().isBrijEnabled()) return;
Expand All @@ -34,6 +41,7 @@ class KycSharingService extends ValueNotifier<UserData?> {

Future<void> _initializeKyc() async {
await fetchUserData();
_isInitialized.complete();

if (value?.kycStatus == ValidationStatus.pending) {
_subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class _KycSectionState extends State<KycSection> {
@override
void initState() {
super.initState();
final kycService = sl<KycSharingService>();
if (kycService.value == null) {
kycService.fetchUserData();
}
sl<KycSharingService>().initialized;
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import '../services/brij_on_ramp_order_service.dart';

extension BuildContextExt on BuildContext {
Future<void> launchKycOnRamp() async {
final user = sl<KycSharingService>().value;
final kycService = sl<KycSharingService>();

await runWithLoader(this, () async => kycService.initialized);

final user = kycService.value;

if (user == null) {
showCpErrorSnackbar(this, message: l10n.tryAgainLater);
Expand Down Expand Up @@ -136,7 +140,11 @@ extension BuildContextExt on BuildContext {
}

Future<void> launchKycOffRamp() async {
final user = sl<KycSharingService>().value;
final kycService = sl<KycSharingService>();

await runWithLoader(this, () async => kycService.initialized);

final user = kycService.value;

if (user == null) {
showCpErrorSnackbar(this, message: l10n.tryAgainLater);
Expand Down

0 comments on commit 8365230

Please sign in to comment.