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

[Spam tokens] manually hide tokens #1377

Merged
merged 30 commits into from
Jan 9, 2023
Merged

[Spam tokens] manually hide tokens #1377

merged 30 commits into from
Jan 9, 2023

Conversation

schmanu
Copy link
Member

@schmanu schmanu commented Dec 15, 2022

What it solves

Unwanted / spam tokens could not be hidden from the interface.

Resolves #1337

How this PR fixes it

  • New button in Assets page to manually hide / unhide tokens
  • new parameter for useBalances to get all or only not hidden tokens

How to test it

  • Hide some tokens in the Assets page of a safe
  • These tokens should be hidden for all Safes on that chain
    • Not appear in assets
    • not counted in total balance
    • not appear through safe apps sdk getBalance
    • not show in Dashboard Overview

Analytics changes

  • New events for hiding / unhiding tokens
  • We decided not to track which token addresses get hidden

Screenshots

@github-actions
Copy link

github-actions bot commented Dec 15, 2022

Branch preview

✅ Deploy successful!

https://spam_tokens_manually_hide--webcore.review-web-core.5afe.dev

@github-actions
Copy link

github-actions bot commented Dec 15, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@schmanu schmanu marked this pull request as draft December 16, 2022 09:32
@schmanu schmanu marked this pull request as ready for review December 21, 2022 07:59
Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

I would suggest rethinking the terminology. E.g. UserTokenBlocklist instead of HiddenAssets.

src/hooks/useBalances.ts Outdated Show resolved Hide resolved
src/hooks/useBalances.ts Outdated Show resolved Hide resolved
src/store/hiddenAssetsSlice.ts Outdated Show resolved Hide resolved
src/store/hiddenAssetsSlice.ts Outdated Show resolved Hide resolved
src/components/balances/HiddenAssetsProvider/index.tsx Outdated Show resolved Hide resolved
- remove SelectDialog => add ToggleButton
- change icon order for hiding / unhiding
- improve sticky TokenMenu positioning
- make buttons the same size in TokenMenu
- Moves hiddenAssetsSlice into settingsSlice
- renames variables / hooks
- moves TokenMenu inside of AssetsTable
- adjusts tests
@github-actions
Copy link

github-actions bot commented Dec 27, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

- show text in toggle button instead of tooltip
- rename TokenListSelect to HiddenTokenToggle
- increase size of hide token / show token button in assetTable
- click on IconButton immediately hides token with collapse animation
- rename apply -> save
- header button will only open menu but not toggle it
- in hide token menu all tokens are shown, not just the hidden ones
- checkboxes when in hide token menu instead of eye-icon
- add Deselect all button
- New property collapsed for rows of EnhancedTable
- collapsed rows will be collapsed by wrapping it's Cells in Collapse
- fixes tests
Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

As you TODO says, there's a lot of new logic inside the AssetsTable that would be good to extract into a module dedicated to token hiding.

src/components/balances/AssetsTable/index.tsx Outdated Show resolved Hide resolved
src/components/balances/AssetsTable/index.tsx Outdated Show resolved Hide resolved
src/hooks/useBalances.ts Outdated Show resolved Hide resolved
src/components/balances/TokenMenu/styles.module.css Outdated Show resolved Hide resolved
src/hooks/useBalances.ts Outdated Show resolved Hide resolved
src/hooks/useBalances.ts Outdated Show resolved Hide resolved
src/services/analytics/events/assets.ts Outdated Show resolved Hide resolved
- reverts useBalances changes
- adds useVisibleBalance
- does not change the fiatTotal anymore
- hidden balances only have an effect on AssetTable, Asset Autocompletions is SendAssetForm and SpendingLimitForm
Comment on lines 14 to 19
return {
...balances,
balances: {
items: items.filter((item) => !hiddenTokens.includes(item.tokenInfo.address)),
fiatTotal,
},
Copy link
Member

Choose a reason for hiding this comment

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

Bear in mind this will filter the list and create a new object on each render. Would be good to memo it.

import { useCallback, useState } from 'react'

// This is the default for MUI Collapse
export const COLLAPSE_TIMEOUT_MS = 300
Copy link
Member

Choose a reason for hiding this comment

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

No need to export it, it's used in the same module.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test is using it.

@usame-algan
Copy link
Member

There is some overlap/spacing issues on smaller screens. Do we have mobile designs? cc @liliiaorlenko

Screenshot 2023-01-05 at 11 30 37

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

Looks good from my side, apart from the remaining comments.

@schmanu schmanu requested a review from usame-algan January 5, 2023 11:13
Copy link
Member

@usame-algan usame-algan left a comment

Choose a reason for hiding this comment

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

👍

@francovenica
Copy link
Contributor

1 - The feature works fine for desktop, but for mobile it not usable: you cannot see the checkboxes while the "hide tokens menu" is open so you cannot use the feature.
I'd suggest hiding the button for mobile views until we can design it to be mobile friendly
image

2 - The widget that counts the amount of tokens in the homepage still shows all the tokens you have, hidden or not. I'd argue that if you want to hide tokens, you don't want them to be counted with the ones you didn't hide.
I'd propose not count them at all or, if you have hidden tokens, you show a number in "()" indicating how many of them are hidden ones.
image

3 - Just refreshing a page with a bunch of tokens throws a ton of GTM calls. No tokens are hidden right now.
I'd assume the calls should be:
When the menu is opened/closed
When the cancel/deselect button are clicked
When the save button is clicked, sending how many tokens are being hidden by that save action.
When the "eye" icon is clicked to hide a token
image

Questions/Concerns:

  • Deselect all seems to clear the storage, so if you use it in a safe with barely no tokens you will end up deselecting a ton of tokens that you might have hidden in another safe without you knowing it. Maybe deselect can just trigger the click action in the checkboxes that are visible instead, so deselecting in one safe won't affect the others (unless they share the token being hidden/shown)

  • The total safe balance is not being affected by hiding tokens. I've been told that we are going to ask Johannes first about this, but I personally think that yes, the balances should reflect only the visible tokens

  • Is unlikely that somebody will set the "Safe" token as invisible, but if somebody does the token widget in the top bar and in the Home widget is still there. I'm gonna assume that is expected behaviour.

- adjusts total balance in useVisibleBalances()
- uses useVisibleBalances in Overview and SidebarHeader
- hides "Hide Tokens" button in mobile
- moves analytics into useMetaEvents
@github-actions
Copy link

github-actions bot commented Jan 6, 2023

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@schmanu
Copy link
Member Author

schmanu commented Jan 6, 2023

Hey @francovenica

I addresses most issues:

  1. I removed the button in mobile.
  2. The widget now does not count hidden assets anymore.
  3. I moved the tracking to how we track the totalBalance (useMetaEvents). That should fix these issues. Although I wasn't able to reproduce those issues :/

For the questions:

  1. Deselect all was implemented wrong. Now it only deselects tokens which are present in the opened Safe
  2. After talking with product we agreed that the total balance should be adjusted. I added that now.
  3. That is expected. The Safe token widget should not be affected by this.

@francovenica
Copy link
Contributor

Yes, all the issues were addressed. The GTM calls are also working fine (not 10 calls just by refreshing the page anymore)

Copy link
Member

@katspaugh katspaugh left a comment

Choose a reason for hiding this comment

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

Looks good!

Btw according to the SafeBalanceResponse type, items and fiatTotal are the only fields in this object, so you don't need the ...balances.

@schmanu
Copy link
Member Author

schmanu commented Jan 9, 2023

@katspaugh
The names are a bit misleading there the returned object from const balances = useBalances will return

{
 balances: SafeBalanceResponse
  loading: boolean
  error?: string
}

So I spread to use the loading and error props from the useBalances hook as the visibleBalances would be loading / erroneous too.

@schmanu schmanu merged commit a1c0502 into dev Jan 9, 2023
@schmanu schmanu deleted the spam-tokens-manually-hide branch January 9, 2023 13:47
@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Epic] Manually hiding tokens
4 participants