Files
buzz/mobile/lib/features/pairing/pairing_page/sas_verification_view.dart
klopez4212 e922dc08ff Unify mobile onboarding and community entry screens (#8687)
## Summary

Use consistent fullscreen screens for identity setup, community
selection, joining, and Add Community. Restore all memberships and open
the selected community; share the community grid with the switcher.

Add QR-first choices, animated link entry with 12px keyboard clearance,
a two-finger double-tap pairing toggle, and the centered reversing bee
loader. Preserve cancellation, Back, and reduced-motion behavior.

Add intentionally omits community creation and Builderlab sign-in: this
route follows sign-in and the existing-community picker.

### Related issue

Related: #8628 (native profile setup). No duplicate fullscreen
onboarding PR found.

### Testing

- Full standard and hosted-authentication mobile suites, static
analysis, and required push checks passed.
- iPhone preview iterated with Kenny; final simulator walkthrough below
uses synthetic data and does not authenticate or save account changes.
- Independent review completed; regressions cover cancellation during
loading, Add recovery after failed/conflicting memberships, retrying
skipped communities, and explicit picker stages.

Walkthrough recorded before the copy and recovery followups:


https://github.com/user-attachments/assets/bfea3ad3-1dde-40c4-8748-44c84226c292

---------

Signed-off-by: kenny lopez <klopez4212@gmail.com>
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz>
2026-10-29 16:12:31 +00:00

297 lines
10 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

part of '../pairing_page.dart';
/// SAS verification screen shown during NIP-AB pairing.
class _SasVerificationView extends HookConsumerWidget {
final String sasCode;
final bool fullScreen;
final Future<bool> Function(String)? verifyDesktopCode;
final bool confirmed;
final bool sendsIdentityToDesktop;
final String biometricLabel;
final String? errorMessage;
final ValueChanged<bool> onProtectionChanged;
final VoidCallback onConfirm;
final VoidCallback onDeny;
const _SasVerificationView({
super.key,
this.fullScreen = false,
required this.sasCode,
this.verifyDesktopCode,
required this.confirmed,
required this.sendsIdentityToDesktop,
required this.biometricLabel,
required this.errorMessage,
required this.onProtectionChanged,
required this.onConfirm,
required this.onDeny,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final controller = useTextEditingController();
final enteredCode = useValueListenable(controller).text;
final mismatch = useState(false);
final checkingCode = useState(false);
final rejectedCode = useRef<String?>(null);
final verificationError = useState<String?>(null);
final shakeRevision = useState(0);
final codeAccepted = useState(false);
final confirmationSent = useRef(false);
useEffect(() {
if (!confirmed) confirmationSent.value = false;
return null;
}, [confirmed, errorMessage]);
void confirm({bool? protection}) {
if (confirmed || confirmationSent.value) return;
confirmationSent.value = true;
if (protection != null) onProtectionChanged(protection);
onConfirm();
}
void checkCode(String value) {
if (confirmed || codeAccepted.value || checkingCode.value) return;
verificationError.value = null;
if (verifyDesktopCode != null) {
mismatch.value = false;
if (value.length != 6) return;
if (value == rejectedCode.value) {
mismatch.value = true;
shakeRevision.value++;
unawaited(errorHaptic());
return;
}
checkingCode.value = true;
unawaited(() async {
try {
final accepted = await verifyDesktopCode!(value);
if (!context.mounted) return;
if (accepted) {
codeAccepted.value = true;
FocusScope.of(context).unfocus();
} else {
rejectedCode.value = value;
mismatch.value = true;
shakeRevision.value++;
unawaited(errorHaptic());
}
} catch (_) {
if (context.mounted) {
verificationError.value = 'Couldn’t check the code. Try again.';
}
} finally {
if (context.mounted) checkingCode.value = false;
}
}());
return;
}
mismatch.value = value.length == 6 && value != sasCode;
if (mismatch.value) {
shakeRevision.value++;
unawaited(errorHaptic());
} else if (value.length == 6) {
codeAccepted.value = true;
FocusScope.of(context).unfocus();
if (sendsIdentityToDesktop) confirm();
}
}
useEffect(() {
if (verifyDesktopCode == null) return null;
var active = true;
// Negotiation can arrive after the user typed a code under legacy SAS
// rules. Re-evaluate that input against the source-only desktop code.
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!active || !context.mounted) return;
rejectedCode.value = null;
mismatch.value = false;
codeAccepted.value = false;
checkCode(controller.text);
});
return () => active = false;
}, [verifyDesktopCode != null]);
final showProtection = codeAccepted.value && !sendsIdentityToDesktop;
final verificationContent = Column(
mainAxisSize: MainAxisSize.min,
children: [
if (showProtection) ...[
Icon(
biometricLabel == 'Use Face ID'
? BuzzIcons.scanFace
: BuzzIcons.fingerprint,
size: 64,
color: context._onboardingInk,
),
const SizedBox(height: Grid.sm),
if (!fullScreen)
Text(
'Protect your identity',
textAlign: TextAlign.center,
style: OnboardingTypography.title.copyWith(
color: context._onboardingInk,
),
),
const SizedBox(height: Grid.xs),
if (!fullScreen)
Text(
'$biometricLabel to confirm it’s you before sending your Buzz identity to another device.',
textAlign: TextAlign.center,
style: OnboardingTypography.subtitle.copyWith(
color: context._onboardingMutedInk,
),
),
] else if (codeAccepted.value) ...[
Icon(BuzzIcons.shieldCheck, size: 64, color: context._onboardingInk),
const SizedBox(height: Grid.sm),
if (!fullScreen)
Text('Code confirmed', style: OnboardingTypography.title),
] else ...[
if (!fullScreen)
Text(
'Enter pairing code',
textAlign: TextAlign.center,
style: OnboardingTypography.title.copyWith(
color: context._onboardingInk,
),
),
const SizedBox(height: Grid.md),
_PairingErrorShake(
revision: shakeRevision.value,
child: _PairingCodeEntry(
controller: controller,
enabled: !confirmed && !checkingCode.value,
invalid: mismatch.value,
onChanged: checkCode,
onSubmitted: () => checkCode(enteredCode),
onRejectedInput: () => checkCode(controller.text),
),
),
const SizedBox(height: Grid.xxs),
AnimatedOpacity(
key: const Key('pairing-code-error'),
opacity: mismatch.value ? 1 : 0,
duration: const Duration(milliseconds: 280),
curve: Curves.easeOut,
child: ExcludeSemantics(
excluding: !mismatch.value,
child: Semantics(
liveRegion: true,
child: Text(
'Check the desktop code and try again.',
textAlign: TextAlign.center,
style: context.textTheme.bodySmall?.copyWith(
color: context._onboardingInk,
),
),
),
),
),
],
if (errorMessage != null || verificationError.value != null) ...[
const SizedBox(height: Grid.xs),
Text(
errorMessage ?? verificationError.value!,
textAlign: TextAlign.center,
style: context.textTheme.bodySmall?.copyWith(
color: context._onboardingInk,
),
),
],
],
);
final verificationActions = confirmed
? Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
BuzzLoadingIndicator(
size: 24,
color: context._onboardingInk,
semanticLabel: 'Connecting',
),
const SizedBox(width: Grid.twelve),
Text(
'Confirmed — waiting for desktop',
style: context.textTheme.bodySmall?.copyWith(
color: context._onboardingMutedInk,
),
),
],
)
: SizedBox(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
if (showProtection ||
(codeAccepted.value && errorMessage != null)) ...[
FilledButton(
style: context._onboardingButtonStyle,
onPressed: () =>
confirm(protection: showProtection ? true : null),
child: Text(showProtection ? biometricLabel : 'Try again'),
),
const SizedBox(height: Grid.xxs),
],
TextButton(
style: context._onboardingSecondaryButtonStyle.copyWith(
minimumSize: const WidgetStatePropertyAll(
Size.fromHeight(52),
),
),
onPressed: showProtection
? () => confirm(protection: false)
: onDeny,
child: Text(showProtection ? 'Skip' : 'Cancel'),
),
],
),
);
if (fullScreen) {
return OnboardingStepPage(
title: showProtection
? 'Protect your identity'
: codeAccepted.value
? 'Code confirmed'
: 'Enter pairing code',
subtitle: showProtection
? '$biometricLabel to confirm it’s you before sending your Buzz identity to another device.'
: codeAccepted.value
? null
: 'Enter the six-digit code shown on your desktop.',
onBack: onDeny,
content: verificationContent,
actions: [verificationActions],
);
}
return Column(
children: [
Expanded(
child: LayoutBuilder(
builder: (context, constraints) {
final verticalPadding = Grid.sm * 2;
final minimumContentHeight =
constraints.maxHeight > verticalPadding
? constraints.maxHeight - verticalPadding
: 0.0;
return SingleChildScrollView(
padding: const EdgeInsets.symmetric(vertical: Grid.sm),
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: minimumContentHeight),
child: Center(child: verificationContent),
),
);
},
),
),
verificationActions,
const SizedBox(height: Grid.sm),
],
);
}
}