-
Notifications
You must be signed in to change notification settings - Fork 26
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
base: main
Are you sure you want to change the base?
Changes from 19 commits
4bc4e35
77f19ae
cfd98f6
1567896
a8cd382
2d6c680
4994511
9d3d370
9cfe7c8
b9c687f
1a64616
d6a3c86
30c392d
04027b6
cac86a4
9e53308
25f97c3
e35e8c1
8dad9b5
40b9d93
91af2e4
6bc3966
ddebe0a
38e58da
3038981
1394434
239bf34
3a23005
97737bf
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 |
---|---|---|
|
@@ -4,24 +4,36 @@ | |
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) => { | ||
const checks = [ | ||
() => Number(token.balance ?? 0n) !== 0, | ||
() => token.usdBalance && token.usdBalance !== 0, | ||
() => $showZeroBalances | ||
]; | ||
|
||
return checks.some((check) => check()); | ||
}; | ||
|
||
sortedTokensOrGroups = groupedTokens.filter((t: TokenUiOrGroupUi) => | ||
isTokenUiGroup(t) ? t.tokens.some((tok: TokenUi) => hasBalance(tok)) : hasBalance(t) | ||
); | ||
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. can the above be put in an util, using 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. @AntonioVentilii i can put the code into an util and write some tests, but why should i use |
||
} | ||
|
||
const updateTokensToDisplay = () => (tokens = [...groupedTokens]); | ||
const updateTokensToDisplay = () => (tokens = [...sortedTokensOrGroups]); | ||
|
||
const debounceUpdateTokensToDisplay = debounce(updateTokensToDisplay, 500); | ||
|
||
$: sortedTokens, debounceUpdateTokensToDisplay(); | ||
$: sortedTokensOrGroups, debounceUpdateTokensToDisplay(); | ||
</script> | ||
|
||
<slot /> |
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.
can we not use the
Number(balance ?? 0n) || (usdBalance ?? 0) || $showZeroBalances
logic? Will it not work?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.
@AntonioVentilii you are right. This is much better