-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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: Sort/Import Tokens in Extension #27184
base: develop
Are you sure you want to change the base?
feat: Sort/Import Tokens in Extension #27184
Conversation
…ub.com:MetaMask/metamask-extension into feat/mmassets-356_sort-import-tokens-extension
…ub.com:MetaMask/metamask-extension into feat/mmassets-356_sort-import-tokens-extension
…ub.com:MetaMask/metamask-extension into feat/mmassets-356_sort-import-tokens-extension
Builds ready [8b8f05d]
Page Load Metrics (1653 ± 77 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
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.
Added some code nits! Overall I really like what you've done!
@@ -136,6 +136,9 @@ describe('Transfer custom tokens @no-mmi', function () { | |||
text: '-1.5 TST', | |||
}); | |||
|
|||
// this delay helps prevent flakiness. it allows driver to wait until send transer is "confirmed" | |||
await driver.delay(5000); |
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.
Is there a selector we can poll for here? We really want to get away from these types of generic delays.
borderStyle={BorderStyle.solid} | ||
color={TextColor.textDefault} | ||
> | ||
Sort By |
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.
This needs localization
padding-left: 16px; | ||
padding-right: 16px; | ||
padding-top: 16px; | ||
padding-bottom: 16px; |
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.
We can just do padding: 16px;
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.
Good call. I should probably use the design system props here actually
isSelected={tokenSortConfig.key === 'symbol'} | ||
onClick={() => handleSort('symbol', 'alphaNumeric', 'asc')} | ||
> | ||
Alphabetically (A-Z) |
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.
Needs localization
isSelected={tokenSortConfig.key === 'tokenFiatAmount'} | ||
onClick={() => handleSort('tokenFiatAmount', 'stringNumeric', 'dsc')} | ||
> | ||
Declining balance ($ high-low) |
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.
Needs localization
Closed my previous PR, but want to surface this comment as it is still relevant regarding |
@@ -114,7 +114,7 @@ const HeaderInfo = () => { | |||
alignSelf: 'flex-end', | |||
}} | |||
> | |||
<Tooltip position="bottom" title={t('accountDetails')} interactive> |
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.
This was also breaking an e2e test. I'm wondering if someone on @MetaMask/confirmations can help me understand this
const controlBarRef = useRef<HTMLDivElement>(null); // Create a ref | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
// TODO: Replace `any` with type | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any |
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.
Is this TODO to be removed?
) => { | ||
dispatch( | ||
setTokenSortConfig({ | ||
key, |
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.
Looks like we are setting tokenSortConfig
only in this component and i did not see a default value in preferences-controller for tokenSortConfig
,
this could result in this selector erroring
const tokenSortConfig = useSelector((state: any) => {
return state.metamask.preferences.tokenSortConfig;
});
Similary to what you added in fixture-builder; im thinking we can add in preferences controller default values for tokenSortConfig?
tokenSortConfig: {
key: 'tokenFiatAmount',
order: 'dsc',
sortCriteria: 'stringNumeric',
},
I think we will also need to create a new migration for users who upgrade to add tokenSortConfig preference into their state 🙏
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.
Great points, ty for pointing this out
// TODO: Replace `any` with type | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const tokenSortConfig = useSelector((state: any) => { | ||
return state.metamask.preferences.tokenSortConfig; |
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.
We can maybe create a selector for this?
const tokenSortConfig = useSelector(getTokenSortConfig);
and then in selectors.js
export function getTokenSortConfig(state) {
const { tokenSortConfig } = getPreferences(state);
return tokenSortConfig;
}
if (err) { | ||
dispatch(displayWarning(err)); | ||
reject(err); | ||
return; | ||
} | ||
console.log('updatedPreferences', updatedPreferences); |
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.
console to remove
Looks great! 🎉 I noticed this behavior where when you click on the sort selector; then you click outside without choosing a select option; the dropdown does not close; is that intentional? Screen.Recording.2024-09-19.at.11.21.35.mov |
ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx
Show resolved
Hide resolved
const showFiat = useSelector(getMultichainShouldShowFiat); | ||
const primaryTokenImage = useSelector(getMultichainCurrencyImage); | ||
const { useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences); | ||
const { chainId, ticker, type, rpcUrl } = useSelector( |
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.
Just mentioning thatuseNativeCurrencyAsPrimaryCurrency
will be removed in the aggregated balance feature;
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.
Yup, this is definitely something that we are going to have conflicts with, hoping it should just be an easy swap. Will keep this comment open to keep eyes on this
…nsion--persistence-telemetry
…nsion--persistence-telemetry
…nsion--persistence-telemetry
Quality Gate passedIssues Measures |
Description
This PR adds Token sorting to the Asset List page, and also moves Token importing to the top of the Token List. A few of the main changes introduced:
NativeToken
inTokenList
component to be included in sorting logic, and treated (as far as sorting is concerned) as any other token in the listtokenSortConfig
into state that keeps track of the sort order, the key being sorted by, and the direction of the sort order. Also includes an action to update this state.useEffect
that subscribes totokenSortConfig
as well as a few other application state variables to update and sort tokenList when appropriate.asset-list
component, and move some of it's relevant code into theuseAccountTotalFiatBalance
Acceptance Criteria:
A couple of disclaimers. There are still (at least) two bugs that I discovered that were not caught by tests:
When toggling preferred currency setting, Native Token sorted incorrectly by decreasing fiat balance✅ fixedWhen switching between accounts, token list does not update✅ fixedRelated issues
Fixes: https://consensyssoftware.atlassian.net/browse/MMASSETS-356
Manual testing steps
Screenshots/Recordings
Screen.Recording.2024-09-16.at.7.57.32.PM.mov
Pre-merge author checklist
Pre-merge reviewer checklist