Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(suite): Enhance HiddenPlaceholder #13914

Closed
wants to merge 3 commits into from

Conversation

Lemonexe
Copy link
Contributor

@Lemonexe Lemonexe commented Aug 21, 2024

Discreet mode currently leaves numerical values blurred, but technically still possible to decypher.
Enhance it to actually replace the characters with ####, making them completely illegible.

Description

TODO. WIP

  • originally I tried to replace the number with random characters
    • then I tried replacing it with constant four characters ####
    • it does not work for short strings - when the #### is wider than 0, it leads to horrible flickering if you hover at certain place
    • instead it replaces with as many # as per original length, but max 4
    • still not ideal, at some places it can still flicker, TBD

Related Issue

Resolve #10567

Screenshots:

Uncovered numbers for reference:
uncovered
Original, only blurred, but you can kinda discern the numbers:
only blurred
Blured and redacted:
blurred and redacted
Blured and redacted onhover:
blurred and redacted onhover

collectCoverage: true,
collectCoverageFrom: ['src/**/*.ts'],
testEnvironment: '../../JestCustomEnv.js',
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

react-utils did not have unit tests at all. I set it up for the first test. Code coverage is not great 😄

if (isValidElement(node)) {
const rewrittenChildren = rewriteReactNodeRecursively(node.props.children, callback);

return cloneElement(node, { ...node.props, key: reactKey, children: rewrittenChildren });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR: Should I scrap this? 🤔

My idea was to have HiddenPlaceholder.tsx alone handle redacting numbers, so you would just wrap any content with it and it'd be completely automatic.
As I wrote in the comment there, this only works for simple cases of components wrapping children, such as:
<Wrapper>Label: <SomeStyle>12345 CZK</SomeStyle></Wrapper>.

But this procedure simply stops when it encounters more complex components, which calculate their content instead of just wrapping children, like <Formatter value={1234} />. They're returned "as is".

So those components have to do the redacting themselves: see prepareFiatAmountFormatter.ts, prepareCryptoAmountFormatter.ts.

I'm not happy with this mixed approach, where sometimes it does things automagically under the hood, but sometimes you just have to do it yourself. I fear this might lead to confusion and mistakes later on.
So should we drop this magic, and redact numbers at all specific places where we display them?
Reminder: this won't make HiddenPlaceholder.tsx useless, it still does CSS blur, and will provide the context for shouldRedactNumbers.

@@ -34,11 +36,13 @@ export const HiddenPlaceholder = ({
children,
enforceIntensity,
className,
...rest
'data-testid': dataTestId,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incidental cleanup, rest did not contain anything else

if (Array.isArray(node)) {
return node.map((child, index) => {
const newReactKey: Key | undefined = isValidElement(child)
? child.key ?? index
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When rewriting the ReactNode, I do have to provide key even when the original element did not.
This is not an edge case, it's actually very common:
<span>label<i>123</i></span>
the span has children = array ["label", <i>123</i>]. Now the <i> has to have a key, idk why 🤦


return formatter;
return FormatterComponent;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually a React component, so its name should be in CamelCase.
Otherwise I get an unjustified error from eslint rule of hooks because of calling useShouldRedactNumbers.

* @returns shouldRedactNumbers whether numbers should be redacted in displayed output
*/
export const useShouldRedactNumbers = () =>
useContext(RedactNumbersContext)?.shouldRedactNumbers ?? false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if all of this belongs to wallet-utils. Seemed suitable to me. Where would you place it?

@Lemonexe Lemonexe marked this pull request as ready for review August 21, 2024 13:55
@Lemonexe Lemonexe requested a review from komret August 21, 2024 13:55
@Lemonexe Lemonexe marked this pull request as draft September 23, 2024 11:37
@Lemonexe
Copy link
Contributor Author

Closing in favor of #14528

@Lemonexe Lemonexe closed this Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the "Hide balances" feature
1 participant