fix(native): mail-pattern domain extraction + drop Pressable from FormSheet

Two bugs reported on the new mail-pattern flow:

1. The sheet sent the full local@domain.tld pattern to the backend so a
   user blocking communications@only4-subscribers.com would only catch
   that exact local-part — newsletter@, info@, promo@ from the same
   sender would slip through. Casino affiliates rotate the local-part
   on every blast while keeping the domain stable, so we now strip the
   local-part on submit. The preview-card under the input shows what
   actually gets stored (only4-subscribers.com), so the user sees the
   pattern that will hit. Bare tokens without "@" stay as-is and reach
   the backend as display-name candidates.

2. FormSheet's backdrop was a <Pressable> — straight violation of the
   "TouchableOpacity, never Pressable" rule. Swapped for
   <TouchableOpacity activeOpacity={1}> so the tap-to-dismiss still
   works with no visible feedback on the dim layer.
This commit is contained in:
chahinebrini 2026-05-16 02:03:53 +02:00
parent 5c6fa3d45b
commit 1e07e8303f
2 changed files with 32 additions and 7 deletions

View File

@ -5,8 +5,8 @@ import {
Modal,
PanResponder,
Platform,
Pressable,
Text,
TouchableOpacity,
View,
useWindowDimensions,
} from 'react-native';
@ -188,7 +188,8 @@ export function FormSheet({
return (
<Modal visible={visible} transparent animationType="slide" onRequestClose={handleClose} statusBarTranslucent>
{/* Backdrop */}
<Pressable
<TouchableOpacity
activeOpacity={1}
onPress={dismissOnBackdrop ? handleClose : undefined}
style={{ flex: 1, backgroundColor: `rgba(0,0,0,${backdropOpacity})` }}
/>

View File

@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import {
ActivityIndicator,
Image,
@ -22,22 +22,42 @@ type InputKind = 'web' | 'mail';
type Props = {
visible: boolean;
tier: Tier;
initialType?: InputKind;
onClose: () => void;
onAdd: (pattern: string, kind: InputKind) => Promise<{ ok: boolean; error?: string; alreadyGlobal?: boolean }>;
};
export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
export function AddDomainSheet({ visible, tier, initialType, onClose, onAdd }: Props) {
const { t } = useTranslation();
const colors = useColors();
const [kind, setKind] = useState<InputKind>('web');
const [kind, setKind] = useState<InputKind>(initialType ?? 'web');
const [input, setInput] = useState('');
const [confirmPermanent, setConfirmPermanent] = useState(false);
const [adding, setAdding] = useState(false);
const [error, setError] = useState<string | null>(null);
const [fieldsDone, setFieldsDone] = useState(false);
useEffect(() => {
if (visible) setKind(initialType ?? 'web');
}, [visible, initialType]);
const normalizedWeb = kind === 'web' ? normalizeDomain(input) : '';
// For mail input: if the user typed a full address (local@domain.tld), strip
// the local-part and keep only the domain — casino affiliates rotate the
// local-part rapidly (communications@, newsletter@, info@, …) while the
// sender-domain stays stable. Blocking on the domain is more durable.
// A bare token without "@" stays as-is (will be matched as display-name on
// the backend).
const mailPattern = (() => {
if (kind !== 'mail') return '';
const raw = input.trim();
if (!raw) return '';
const atIdx = raw.lastIndexOf('@');
if (atIdx === -1) return raw;
return raw.slice(atIdx + 1).trim().toLowerCase();
})();
function close() {
setInput('');
setConfirmPermanent(false);
@ -63,7 +83,7 @@ export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
if (!isInputValid() || !confirmPermanent || adding) return;
setAdding(true);
setError(null);
const pattern = kind === 'web' ? input : input.trim();
const pattern = kind === 'web' ? input : mailPattern;
const result = await onAdd(pattern, kind);
setAdding(false);
if (result.ok) {
@ -72,6 +92,10 @@ export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
}
if (result.alreadyGlobal) {
setError(t('blocker.add_sheet_already_global', { domain: normalizedWeb || input.trim() }));
} else if (result.error?.includes('WEB_LIMIT_REACHED')) {
setError(t('blocker.error_web_limit_reached'));
} else if (result.error?.includes('MAIL_LIMIT_REACHED')) {
setError(t('blocker.error_mail_limit_reached'));
} else {
setError(result.error ?? t('blocker.add_sheet_add_failed'));
}
@ -223,7 +247,7 @@ export function AddDomainSheet({ visible, tier, onClose, onAdd }: Props) {
}}
numberOfLines={1}
>
{input.trim() || inputPlaceholder}
{mailPattern || inputPlaceholder}
</Text>
</View>
)}