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

Fix/accounts tab search does not work correctly with special chars #14600

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

mempoolboy
Copy link

Unlabeled accounts are represented by default labels created as translation strings. As these are derived from account data based on user settings and require an intl provider, they are not saved in the store and therefore are not included in the search).

Description

Include default labels in subject of account search, consolidate and refactor related code.

Related Issue

Resolve #11383

Screenshots:

image image image image

@mempoolboy mempoolboy force-pushed the fix/accounts-tab-search-does-not-work-correctly-with-special-chars branch from 86b8b35 to bd936ca Compare September 27, 2024 21:20
@MiroslavProchazka
Copy link
Contributor

Hello @mempoolboy ,

Thank you for your contribution!
I've asked my colleagues to do a code review. Once this will be done, I will create a separate PR from your source code in our repository to run the pipelines. Then we can merge this.

Thanks

Copy link
Contributor

@Lemonexe Lemonexe left a comment

Choose a reason for hiding this comment

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

I love this improvement, we were missing it, thank you! 🎉
Codewise looking good, I have only small codestyle nits 🙂
Tested locally rebased on develop, and works as expected ✔️

Note: there is conflict in one file, but it's trivial, so no need to re-review after solving it.


return translationString('LABELING_ACCOUNT', {
networkName: translationString(getTitleForNetwork(symbol)), // Bitcoin, Ethereum, ...
index: index + 1, // This is the number which shows after hash, e.g. Ethereum #3
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I know this line was copied as is from the old function, but we could make it neater 🙂
I'd extract index+1 as a variable, could be named for example displayedAccountNumber or something, then comment is not needed. Code that explains itself is preferred over commentary, but it's a tiny thing 🙂

@@ -82,7 +81,7 @@ export const AccountDetails = ({ selectedAccount, isBalanceShown }: AccountDetai
const [shouldAnimate, setShouldAnimate] = useState(false);
const [hasMounted, setHasMounted] = useState(false);
const selectedAccountLabels = useSelector(selectLabelingDataForSelectedAccount);
const { defaultAccountLabelString } = useAccountLabel();
const { getDefaultAccountLabel } = useDefaultAccountLabel();
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for renaming the returned callback, the old name didn't make much sense 👍

import { useTranslation } from './useTranslation';
import { AccountType, NetworkSymbol } from '@suite-common/wallet-config';

export interface GetDefaultAccountLabel {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think GetDefaultAccountLabelParams would be more suitable, because this isn't type of the function, just its params.

? list.filter(account => {
const { key, accountType, symbol, index } = account;
const accountLabel =
accountLabels[key] || getDefaultAccountLabel({ accountType, symbol, index });
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this is imho more semantic - although it's longer, it makes it clear we're not checking for truthiness, but if the value exists on the record at all. Though this code is also fine 👌

Suggested change
accountLabels[key] || getDefaultAccountLabel({ accountType, symbol, index });
accountLabels.hasOwnProperty(key) ? accountLabels[key] : getDefaultAccountLabel({ accountType, symbol, index });

Copy link
Author

Choose a reason for hiding this comment

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

I really like this solution. 🤩

const accountLabel =
accountLabels[key] || getDefaultAccountLabel({ accountType, symbol, index });

return accountSearchFn(account, searchString, coinFilter, accountLabel);
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 I'd add a test case for this at accountUtils.test.ts#L217.
Although the accountSearchFn function is itself unchanged, its usage has slightly changed. There is now no test case to match substring with supplied label, only whole string.
This will test it, and at the same time it'll help describe what is the fn typically used for 🙂

expect(accountSearchFn(btcAcc, '#1', undefined, 'Bitcoin #1')).toBe(true);

@mempoolboy mempoolboy force-pushed the fix/accounts-tab-search-does-not-work-correctly-with-special-chars branch from bd936ca to 5be1adc Compare October 2, 2024 19:27
@mempoolboy
Copy link
Author

I love this improvement, we were missing it, thank you! 🎉 Codewise looking good, I have only small codestyle nits 🙂 Tested locally rebased on develop, and works as expected ✔️

Note: there is conflict in one file, but it's trivial, so no need to re-review after solving it.

Thanks for the thorough CR, it's much needed and appreciated. 😃

I've rebased the branch, resolved the conflict, addressed the issues and added the test scenario (well, I've rebased the branch and resolved the conflict 😄).

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.

Accounts tab - search does not work correctly with special chars
3 participants