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

Hide assets from views #1797

Open
wants to merge 15 commits into
base: release/5.28.0
Choose a base branch
from

Conversation

aristidesstaffieri
Copy link
Contributor

@aristidesstaffieri aristidesstaffieri commented Jan 16, 2025

Closes #1620
Design: https://www.figma.com/design/C3G0a4Gd6RQyplRBppGDsL/Freighter-(SDS-v3)?node-id=2932-3383&t=KhdFFpbyyxRgbwuo-1

What
Adds a "Toggle Assets" page, where users can select assets to hide from their views.

Why
Users may no longer want to see assets where they have "dust" and no longer care or for whatever other reason they may want to remove the asset from view while still keeping it in their assets list.

Notable Changes:
Adds new internal actions GET_HIDDEN_ASSETS & CHANGE_ASSET_VISIBILITY which operate on a new storage key HIDDEN_ASSETS. HIDDEN_ASSETS is a map of <issuer key, "hidden" | "visible">.
Adds new "toggle assets" page and navigation action from the "Manage Assets" page.
Changes getAccountBalances to accept a new arg, showHidden. This can be used to filter out assets according to their state in HIDDEN_ASSETS.
Refactors ChooseAsset to fetch it's own balances, it now needs to account for hidden assets.
Extracts a new hook, useFetchDomains to be used in both ChooseAsset and AssetVisibility.
Adds new test for toggling an asset's visibility.

Screenshot 2025-01-16 at 12 15 38 PM

Screenshot 2025-01-16 at 12 15 57 PM

@aristidesstaffieri aristidesstaffieri self-assigned this Jan 16, 2025
soroswapTokens,
networkDetails,
]);
const goBack = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that we need to fetch balances here, this pattern suffers more from the stale store state so this resets the store in order for the state to be correct on the Account page once navigation lands there. I noted a possible refactor to help this in the new hook fetchDomains.


const [assets, setAssets] = useState({
assetRows: [] as ManageAssetCurrency[],
// TODO: REFACTOR getAccountBalances to a hook
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would be good to line up getAccountBalances to move to a hook similar to useGetHistory. This shared state made it tricky to ensure the correct loading/initial state across several views sharing it. Each view relies on unrelated views to "clean up" the state in order for the pages to work correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, good call - that'd be a much nicer improvement than having to manually rehydrate

import "./styles.scss";

export const defaultAccountBalances = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just getting rid of a little cruft here.

import { PrivateKeyRoute } from "popup/Router";
import { ROUTES } from "popup/constants/routes";

export const ManageAssets = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both views that need balances here now need to fetch them on render, this is because AssetVisibility needs to not filter hidden assets, and ChooseAsset needs to take the hidden assets into account.

response = await sendMessageToBackground({
type: SERVICE_TYPES.CHANGE_ASSET_VISIBILITY,
assetVisibility: {
issuer: assetIssuer,
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll run into an issue here when a G address is the issuer for multiple assets.

Here's an example of an issuer on Mainnet who issues multiple assets under one address: GBX23RCWKV7DA23J2MA2OFMTRV3XZHHKOTHBQF6AKOEP7AGQUIZZXLMG

I think you might just want to use {assetCode}:{assetIssuer} as your key here

Choose a reason for hiding this comment

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

@

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@piyalbasu very good point thank you, will update to use the composite key.
Can an issuer have two assets that use the same ticker?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 0512f6c

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that's a good question about multiple assets using the same ticket. Off the top of my head, I'm not 100% sure. We may need to test it out and see if the network lets us do it

/>
<Toggle
checked={isAssetVisible(hiddenAssets, issuer)}
id="isVisible"
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: you'll potentially end up with multiple elements with the same id. Not sure how much that actually matters here - but to be syntactically correct, you might wanna use something like isVisible-${code}:${issuer}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yeah I didn't use the ID in this case but will update for completeness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 0512f6c

color: var(--sds-clr-gray-09);

svg {
margin-right: 0.25rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: would you mind using pxToRem? It'd be nice to start removing rem altogether from the codebase over time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 0512f6c

@@ -175,7 +165,6 @@ export const Account = () => {
return (
<>
<AccountHeader
// accountDropDownRef={accountDropDownRef}
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

expect(childInput).toBeChecked();
fireEvent.change(childInput, { target: { checked: false } });
expect(childInput).not.toBeChecked();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to have an e2e test for this. It would cover the UI stuff plus make sure the background is properly saving hidden assets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah good call it would make sense to navigate to the account view and test for the hidden asset being missing from the list also, let me see what I can add here.

@@ -23,3 +23,4 @@ export const IS_HASH_SIGNING_ENABLED_ID = "isHashSigningEnabled";
export const IS_NON_SSL_ENABLED_ID = "isNonSSLEnabled";
export const IS_BLOCKAID_ANNOUNCED_ID = "isBlockaidAnnounced";
export const IS_HIDE_DUST_ENABLED_ID = "isHideDustEnabled";
export const HIDDEN_ASSETS = "hiddenAsset";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export const HIDDEN_ASSETS = "hiddenAsset";
export const HIDDEN_ASSETS = "hiddenAssets";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄 thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 365d79b

Comment on lines 40 to 42
&--short {
flex-grow: 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

does it make sense to have this one since it's not adding any actual change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh good call this came from a similar view but its not needed here. Removing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 365d79b

&__content {
display: flex;
flex-direction: column;
gap: 1.5rem;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use pxToRem() in all values from this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup! Adding...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in 365d79b

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.

4 participants