-
-
Notifications
You must be signed in to change notification settings - Fork 248
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
base: develop
Are you sure you want to change the base?
Changes from all commits
6170481
eb2c718
d7c09a3
5be1adc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { sortByCoin, getFailedAccounts, accountSearchFn } from '@suite-common/wallet-utils'; | ||
import { Account } from '@suite-common/wallet-types'; | ||
import { useAccountSearch, useDiscovery, useSelector } from 'src/hooks/suite'; | ||
import { selectDevice } from '@suite-common/wallet-core'; | ||
import { selectAccounts, selectDevice } from '@suite-common/wallet-core'; | ||
import { selectAccountLabels } from 'src/reducers/suite/metadataReducer'; | ||
import { Translation } from 'src/components/suite'; | ||
import { AccountItemSkeleton } from './AccountItemSkeleton'; | ||
|
@@ -10,17 +10,19 @@ import { AccountsMenuNotice } from './AccountsMenuNotice'; | |
import { spacings } from '@trezor/theme'; | ||
import { Column } from '@trezor/components'; | ||
import { AccountSection } from './AcccountSection'; | ||
import { useDefaultAccountLabel } from 'src/hooks/suite'; | ||
|
||
interface AccountListProps { | ||
onItemClick?: () => void; | ||
} | ||
|
||
export const AccountsList = ({ onItemClick }: AccountListProps) => { | ||
const device = useSelector(selectDevice); | ||
const accounts = useSelector(state => state.wallet.accounts); | ||
const accounts = useSelector(selectAccounts); | ||
const selectedAccount = useSelector(state => state.wallet.selectedAccount); | ||
const coinjoinIsPreloading = useSelector(state => state.wallet.coinjoin.isPreloading); | ||
const accountLabels = useSelector(selectAccountLabels); | ||
const { getDefaultAccountLabel } = useDefaultAccountLabel(); | ||
|
||
const { discovery, getDiscoveryStatus } = useDiscovery(); | ||
const { coinFilter, searchString } = useAccountSearch(); | ||
|
@@ -37,7 +39,14 @@ export const AccountsList = ({ onItemClick }: AccountListProps) => { | |
const list = sortByCoin(accounts.filter(a => a.deviceState === device.state).concat(failed)); | ||
const filteredAccounts = | ||
searchString || coinFilter | ||
? list.filter(a => accountSearchFn(a, searchString, coinFilter, accountLabels[a.key])) | ||
? list.filter(account => { | ||
const { key, accountType, symbol, index } = account; | ||
const accountLabel = accountLabels.hasOwnProperty(key) | ||
? accountLabels[key] | ||
: getDefaultAccountLabel({ accountType, symbol, index }); | ||
|
||
return accountSearchFn(account, searchString, coinFilter, accountLabel); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
|
||
}) | ||
: list; | ||
|
||
const filterAccountsByType = (type: Account['accountType']) => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getTitleForNetwork, getTitleForCoinjoinAccount } from '@suite-common/wallet-utils'; | ||
import { useCallback } from 'react'; | ||
import { useTranslation } from './useTranslation'; | ||
import { AccountType, NetworkSymbol } from '@suite-common/wallet-config'; | ||
|
||
export interface GetDefaultAccountLabelParams { | ||
accountType: AccountType; | ||
symbol: NetworkSymbol; | ||
index?: number; | ||
} | ||
|
||
export const useDefaultAccountLabel = () => { | ||
const { translationString } = useTranslation(); | ||
|
||
const getDefaultAccountLabel = useCallback( | ||
({ accountType, symbol, index = 0 }: GetDefaultAccountLabelParams): string => { | ||
if (accountType === 'coinjoin') { | ||
return translationString(getTitleForCoinjoinAccount(symbol)); | ||
} | ||
|
||
const displayedAccountNumber = index + 1; | ||
|
||
return translationString('LABELING_ACCOUNT', { | ||
networkName: translationString(getTitleForNetwork(symbol)), // Bitcoin, Ethereum, ... | ||
index: displayedAccountNumber, | ||
}); | ||
}, | ||
[translationString], | ||
); | ||
|
||
return { | ||
getDefaultAccountLabel, | ||
}; | ||
}; |
There was a problem hiding this comment.
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 👍