Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions lib/screens/kyc/cubits/kyc/kyc_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,22 @@ class KycCubit extends Cubit<KycState> {

Future<void> checkKyc({String? context}) async {
_kycContext = context ?? _kycContext;
// The merge-processing waiting screen must survive a slow refresh: the
// backend may still be re-parenting the merge when the user taps refresh,
// and surfacing the watchdog timeout as KycFailure would route them to the
// error screen — the exact failure mode the waiting page exists to avoid.
// Captured before _runCheckKyc, which immediately replaces the state with
// KycLoading.
final wasMergeProcessing = state is KycMergeProcessing;
final generation = ++_runGeneration;
try {
await _runCheckKyc(generation).timeout(_checkKycTimeout);
} on TimeoutException {
if (isClosed || generation != _runGeneration) return;
if (wasMergeProcessing) {
emit(const KycMergeProcessing());
return;
}
emit(const KycFailure('KYC backend did not respond in time'));
} catch (e) {
if (isClosed || generation != _runGeneration) return;
Expand Down
Binary file modified test/goldens/screens/home/goldens/macos/home_page_loaded.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions test/goldens/screens/kyc/kyc_merge_processing_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:realunit_wallet/screens/kyc/cubits/kyc/kyc_cubit.dart';
import 'package:realunit_wallet/screens/kyc/subpages/kyc_merge_processing_page.dart';

import '../../../helper/helper.dart';

class _MockKycCubit extends MockCubit<KycState> implements KycCubit {}

void main() {
late _MockKycCubit kycCubit;

setUp(() {
kycCubit = _MockKycCubit();
when(() => kycCubit.state).thenReturn(const KycInitial());
});

group('$KycMergeProcessingPage', () {
goldenTest(
'default state',
fileName: 'kyc_merge_processing_page_default',
constraints: phoneConstraints,
// The page shows a CupertinoActivityIndicator (an endless animation), so
// pumpAndSettle would never settle — pump a single frame instead.
pumpBeforeTest: pumpOnce,
builder: () => wrapForGolden(
BlocProvider<KycCubit>.value(
value: kycCubit,
child: const KycMergeProcessingPage(),
),
),
);
});
}
44 changes: 44 additions & 0 deletions test/screens/kyc/cubits/kyc/kyc_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,50 @@ void main() {
});
},
);

// A slow refresh from the merge-processing waiting screen must NOT route the
// user to the error screen: when the watchdog fires and the previous state
// was KycMergeProcessing, the cubit returns to KycMergeProcessing instead of
// emitting KycFailure. Contrast with the watchdog test above (non-merge
// state -> KycFailure), which still holds.
test(
'stays on KycMergeProcessing instead of KycFailure when a refresh exceeds the timeout',
() {
fakeAsync((async) {
// Phase 1: backend reports MergeProcessing -> cubit reaches the waiting state.
when(() => kycService.getKycStatus()).thenAnswer(
(_) async => _kycStatus(
level: KycLevel.level20,
processStatus: KycProcessStatus.mergeProcessing,
),
);
when(() => kycService.getUser()).thenAnswer((_) async => _user());

final cubit = buildCubit();
final states = <KycState>[];
final sub = cubit.stream.listen(states.add);

cubit.markLegalDisclaimerAccepted();
unawaited(cubit.checkKyc());
async.flushMicrotasks();

// Phase 2: refresh while the backend hangs past the 30s watchdog.
when(() => kycService.getKycStatus()).thenAnswer((_) => Completer<KycLevelDto>().future);
unawaited(cubit.checkKyc());
async.elapse(const Duration(seconds: 31));

expect(states, [
const KycLoading(),
const KycMergeProcessing(),
const KycLoading(),
const KycMergeProcessing(),
]);

sub.cancel();
cubit.close();
});
},
);
});

group('$KycCubit context forwarding', () {
Expand Down
Loading