mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 17:47:00 -05:00
fix(privacy): hide currency symbols in redacted overlay (#6438)
* fix(privacy): hide currency symbols in redacted overlay Add RedactedContent component that uses useLayoutEffect to walk the DOM and replace non-alphanumeric characters (like currency symbols) with spaces. This ensures characters not rendered by Redacted Script font are hidden, regardless of how deeply nested they are in the component tree. * refactor: simplify RedactedContent text node processing loop
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
// @ts-strict-ignore
|
||||
import React, {
|
||||
import {
|
||||
Children,
|
||||
type ComponentPropsWithRef,
|
||||
type ReactNode,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
} from 'react';
|
||||
|
||||
import { useResponsive } from '@actual-app/components/hooks/useResponsive';
|
||||
@@ -67,6 +69,36 @@ export function PrivacyFilter({
|
||||
);
|
||||
}
|
||||
|
||||
type RedactedContentProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
// Component that filters text content to remove non-alphanumeric characters
|
||||
// This works by intercepting the actual rendered text via a ref and modifying it
|
||||
function RedactedContent({ children }: RedactedContentProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (containerRef.current) {
|
||||
// Walk all text nodes and replace non-alphanumeric characters
|
||||
const walker = document.createTreeWalker(
|
||||
containerRef.current,
|
||||
NodeFilter.SHOW_TEXT,
|
||||
null,
|
||||
);
|
||||
|
||||
let node: Text | null;
|
||||
while ((node = walker.nextNode() as Text | null)) {
|
||||
if (node.textContent) {
|
||||
node.textContent = node.textContent.replace(/[^a-zA-Z0-9]/g, '*');
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [children]);
|
||||
|
||||
return <div ref={containerRef}>{children}</div>;
|
||||
}
|
||||
|
||||
function PrivacyOverlay({ children, ...props }) {
|
||||
const { style, ...restProps } = props;
|
||||
|
||||
@@ -122,7 +154,7 @@ function PrivacyOverlay({ children, ...props }) {
|
||||
width: '100%',
|
||||
})}
|
||||
>
|
||||
{children}
|
||||
<RedactedContent>{children}</RedactedContent>
|
||||
</div>
|
||||
</View>
|
||||
);
|
||||
|
||||
6
upcoming-release-notes/6438.md
Normal file
6
upcoming-release-notes/6438.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Enhancements
|
||||
authors: [StephenBrown2]
|
||||
---
|
||||
|
||||
Fixes redacted content to work with currency symbols
|
||||
Reference in New Issue
Block a user