diff --git a/src/app/transactions/page.tsx b/src/app/transactions/page.tsx index 8602798..e22104c 100644 --- a/src/app/transactions/page.tsx +++ b/src/app/transactions/page.tsx @@ -86,20 +86,19 @@ function SaveAsRulePrompt({ const createRule = useCreateRule(); const [saving, setSaving] = useState(false); - // Build a sensible default rule from the transaction context - const merchantMatch = tx.effective_merchant || tx.description; + // Build a sensible default rule from the transaction context. + // Prefer merchant_normalized (full name, exact match) over a partial description word. + const hasMerchant = !!tx.effective_merchant; + const conditionField = hasMerchant ? "merchant_normalized" : "description"; + const conditionOperator = hasMerchant ? "equals" : "contains"; + const conditionValue = hasMerchant ? tx.effective_merchant : tx.description; + const defaultName = field === "category" - ? `${merchantMatch} → ${formatCategory(newValue)}` - : `Rename ${tx.effective_merchant || tx.description} → ${newValue}`; + ? `${conditionValue} → ${formatCategory(newValue)}` + : `Rename ${conditionValue} → ${newValue}`; - const conditions = [ - { - field: "description", - operator: "contains", - value: (tx.effective_merchant || tx.description).split(" ")[0] ?? "", - }, - ]; + const conditions = [{ field: conditionField, operator: conditionOperator, value: conditionValue }]; const actions = field === "category" ? { set_category: newValue } @@ -118,7 +117,7 @@ function SaveAsRulePrompt({ Automatically apply this {field === "category" ? "category" : "merchant name"} to future matching transactions.
If description contains "{conditions[0].value}"
+If {conditionField === "merchant_normalized" ? "merchant" : "description"} {conditionOperator} "{conditionValue}"
Then{" "} {field === "category"