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

feat: add manage tokens, closes #5643 #5896

Merged
merged 1 commit into from
Oct 15, 2024
Merged

feat: add manage tokens, closes #5643 #5896

merged 1 commit into from
Oct 15, 2024

Conversation

alter-eggo
Copy link
Collaborator

@alter-eggo alter-eggo commented Oct 7, 2024

Try out Leather build f7e50feExtension build, Test report, Storybook, Chromatic

This pr adds:

  • manage tokens feature
  • mocks all token types (sip10, runes, brc20, stx20, src20) and tests to enable/disable all of them

@cbadawi thanks a lot for working on this feature!

@alter-eggo alter-eggo force-pushed the feat/tokens-manage branch 2 times, most recently from b75a018 to 2c46b31 Compare October 7, 2024 18:37
@brandonmarshall-tm
Copy link

I downloaded the preview and am noticing all my Runes are hidden by default, even though we support USD prices on Runes. Ideally we would filter out low-quality Runes but keep ones that have higher value in wallets such as $DOG (DOG GO TO MOON)

@brandonmarshall-tm
Copy link

I am also seeing a bug where SRC20 is showing up even when unchecked
Screenshot 2024-10-07 at 1 40 33 PM

@brandonmarshall-tm
Copy link

I just noticed that even when enabling Runes, they do not show in the asset list. So Runes are always hidden and SRC20 are always shown 😉

@alter-eggo
Copy link
Collaborator Author

@brandonmarshall-tm fixed

@brandonmarshall-tm
Copy link

Confirming I am able to hide SRC20 and unhide Runes. All Runes are still hidden by default, though, which I don't think is our intention

@alter-eggo alter-eggo force-pushed the feat/tokens-manage branch 3 times, most recently from 1430dd0 to 0861792 Compare October 9, 2024 20:05
@alter-eggo alter-eggo marked this pull request as ready for review October 9, 2024 20:11
@brandonmarshall-tm
Copy link

Looks good to me!

src/app/common/hooks/use-manage-tokens.ts Outdated Show resolved Hide resolved
Comment on lines 40 to 61
if (assetRightElementVariant === 'toggle') {
return (
<CryptoAssetItemToggleLayout
key={key}
captionLeft={captionLeft}
icon={icon}
titleLeft={titleLeft}
assetId={token.info.symbol}
isCheckedByDefault={isTokenEnabled({ tokenId: token.info.symbol, preEnabledTokensIds })}
/>
);
}
return (
<CryptoAssetItemLayout
availableBalance={token.balance.availableBalance}
captionLeft={captionLeft}
key={key}
icon={<Src20AvatarIcon />}
titleLeft={titleLeft}
isPrivate={isPrivate}
dataTestId={token.info.symbol}
/>
);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

This approach seems a coupled to me. Rather than "baking in" the toggleable functionality to every single list, shouldn't we compose together a new view that has the toggle functionnality?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

refactored this, so it's in sep component

name: 'manageTokens',
initialState: manageTokensAdapter.getInitialState(),
reducers: {
setToken(state, action: PayloadAction<{ id: string; enabled: boolean; accountIndex: number }>) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we model over the action/event taking place? https://redux.js.org/style-guide/#model-actions-as-events-not-setters

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree here, trying to understand some of the changes, is it nec to have manage in the naming? Isn't a slice of state always managing state, would just tokensSlice be sufficient here to describe it? I think there might be a way to make what is happening here more clear, like what is setToken doing?

Copy link
Collaborator Author

@alter-eggo alter-eggo Oct 11, 2024

Choose a reason for hiding this comment

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

manageToken more refer to a feature itself, not like managing tokens state slice

@alter-eggo alter-eggo force-pushed the feat/tokens-manage branch 4 times, most recently from bcbd817 to f46def1 Compare October 15, 2024 07:26
@314159265359879
Copy link
Contributor

@alter-eggo I think I was looking at a different version when I tested this in the weekend. This is looking good now.

I would prefer the settings to be the same for all accounts instead of different per account. But as you said that can be an enhancement for later so that this can go live as it is now.

Should there be an option to easily hide/unhide all (except gas tokens) too?
image

The color difference between on and off is very small, that makes the color difference less helpful to see the difference.
image

@alter-eggo
Copy link
Collaborator Author

alter-eggo commented Oct 15, 2024

@314159265359879 we can add "all" switcher as further enhancement as well 👍 let's create sep issue for these ideas?

The color difference between on and off is very small, that makes the color difference less helpful to see the difference.

hm, as for me it looks ok, wdyt @fabric-8?
bg is ink.text-subdued in unchecked mode and ink.text-primary in checked mode

Comment on lines 19 to 28
updateTokenEnableState(
state,
action: PayloadAction<{ id: string; enabled: boolean; accountIndex: number }>
) {
manageTokensAdapter.setOne(state, {
id: action.payload.id,
enabled: action.payload.enabled,
accountIndex: action.payload.accountIndex,
});
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
updateTokenEnableState(
state,
action: PayloadAction<{ id: string; enabled: boolean; accountIndex: number }>
) {
manageTokensAdapter.setOne(state, {
id: action.payload.id,
enabled: action.payload.enabled,
accountIndex: action.payload.accountIndex,
});
},
updateTokenEnableState(
state,
action: PayloadAction<{ id: string; enabled: boolean; accountIndex: number }>
) {
manageTokensAdapter.setOne(state, {
id: action.payload.id,
enabled: action.payload.enabled,
accountIndex: action.payload.accountIndex,
});
},

This still kinda violates the "map to user actions, not state setters" practice. I'd go for something like userTogglesTokenVisibility etc

Copy link
Contributor

@pete-watters pete-watters left a comment

Choose a reason for hiding this comment

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

Great work @alter-eggo 👍

@alter-eggo alter-eggo added this pull request to the merge queue Oct 15, 2024
Merged via the queue into dev with commit 7d3ac6f Oct 15, 2024
30 checks passed
@alter-eggo alter-eggo deleted the feat/tokens-manage branch October 15, 2024 11:26
@fabric-8
Copy link
Contributor

Great stuff — Let's revisit the toggle component states separately, I think it's ok for now to move on

@alter-eggo alter-eggo linked an issue Oct 17, 2024 that may be closed by this pull request
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.

Add option to manage tokens shown or hidden by default
7 participants