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(frontend): fix hide zeros filter #4200

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4bc4e35
fixes token filter
BonomoAlessandro Jan 13, 2025
77f19ae
restructures code
BonomoAlessandro Jan 13, 2025
cfd98f6
simplifies filter logic
BonomoAlessandro Jan 13, 2025
1567896
reformat code
BonomoAlessandro Jan 13, 2025
a8cd382
resolves lint issue
BonomoAlessandro Jan 13, 2025
2d6c680
resolves lint issue
BonomoAlessandro Jan 13, 2025
4994511
resolves lint issue
BonomoAlessandro Jan 13, 2025
9d3d370
resolves lint issue
BonomoAlessandro Jan 13, 2025
9cfe7c8
resolves lint issue
BonomoAlessandro Jan 13, 2025
b9c687f
resolves lint issue
BonomoAlessandro Jan 13, 2025
1a64616
🤖 Apply formatting changes
github-actions[bot] Jan 13, 2025
d6a3c86
🤖 Apply formatting changes
github-actions[bot] Jan 13, 2025
30c392d
Merge branch 'main' into fix(frontend)/fix-hide-zeros-filter
BonomoAlessandro Jan 13, 2025
04027b6
resolves lint issue
BonomoAlessandro Jan 13, 2025
cac86a4
resolves lint issue
BonomoAlessandro Jan 13, 2025
9e53308
🤖 Apply formatting changes
github-actions[bot] Jan 13, 2025
25f97c3
Merge branch 'main' into fix(frontend)/fix-hide-zeros-filter
BonomoAlessandro Jan 13, 2025
e35e8c1
Merge branch 'main' into fix(frontend)/fix-hide-zeros-filter
BonomoAlessandro Jan 13, 2025
8dad9b5
Merge branch 'main' into fix(frontend)/fix-hide-zeros-filter
BonomoAlessandro Jan 13, 2025
40b9d93
resolves lint issue
BonomoAlessandro Jan 21, 2025
91af2e4
Merge branch 'main' into fix(frontend)/fix-hide-zeros-filter
BonomoAlessandro Jan 21, 2025
6bc3966
moves filter logic into token-group.utils.ts
BonomoAlessandro Jan 28, 2025
ddebe0a
implements some filterTokenGroups tests
BonomoAlessandro Jan 28, 2025
38e58da
🤖 Apply formatting changes
github-actions[bot] Jan 28, 2025
3038981
reformat comments
BonomoAlessandro Jan 28, 2025
1394434
resolves lint issues
BonomoAlessandro Jan 28, 2025
239bf34
resolves lint issues
BonomoAlessandro Jan 28, 2025
3a23005
resolves lint issues
BonomoAlessandro Jan 28, 2025
97737bf
Merge branch 'main' into fix(frontend)/fix-hide-zeros-filter
BonomoAlessandro Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
import { showZeroBalances } from '$lib/derived/settings.derived';
import type { TokenUi } from '$lib/types/token';
import type { TokenUiOrGroupUi } from '$lib/types/token-group';
import { groupTokensByTwin } from '$lib/utils/token-group.utils';
import { groupTokensByTwin, isTokenUiGroup } from '$lib/utils/token-group.utils';

// We start it as undefined to avoid showing an empty list before the first update.
export let tokens: TokenUiOrGroupUi[] | undefined = undefined;

let sortedTokens: TokenUi[];
$: sortedTokens = $combinedDerivedSortedNetworkTokensUi.filter(
({ balance, usdBalance }) => Number(balance ?? 0n) || (usdBalance ?? 0) || $showZeroBalances
);

let groupedTokens: TokenUiOrGroupUi[];
$: groupedTokens = groupTokensByTwin(sortedTokens);
$: groupedTokens = groupTokensByTwin($combinedDerivedSortedNetworkTokensUi);

let sortedTokensOrGroups: TokenUiOrGroupUi[];
$: {
const hasBalance = (token: TokenUiOrGroupUi) =>
Number(token.balance ?? 0n) || Number(token.usdBalance ?? 0n) || $showZeroBalances;

sortedTokensOrGroups = groupedTokens.filter((t: TokenUiOrGroupUi) =>
isTokenUiGroup(t) ? t.tokens.some((tok: TokenUi) => hasBalance(tok)) : hasBalance(t)
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can the above be put in an util, using reduce with a few tests please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@AntonioVentilii i can put the code into an util and write some tests, but why should i use reduce instead of filter? Filtering is exactly what i want to do in this case

}

const updateTokensToDisplay = () => (tokens = [...groupedTokens]);
const updateTokensToDisplay = () => (tokens = [...sortedTokensOrGroups]);

const debounceUpdateTokensToDisplay = debounce(updateTokensToDisplay, 500);

$: sortedTokens, debounceUpdateTokensToDisplay();
$: sortedTokensOrGroups, debounceUpdateTokensToDisplay();
</script>

<slot />
Loading