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

Draft: Network filter asset list integration #28095

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
2f33dd5
feat: Init network filter
gambinish Oct 11, 2024
317cb44
chore: Add tokenNetworkFilter action
gambinish Oct 11, 2024
99ae620
chore: Add selected indicator on TokenNetworkList controls
gambinish Oct 11, 2024
ab6189f
chore: Subscribe to tokenNetworkFilter in token-list
gambinish Oct 11, 2024
90c9b0e
chore: Display multiAccountBalance, and selectedAccountBalance
gambinish Oct 11, 2024
a66c999
chore: Optimize multiAccountBalance with reduce function
gambinish Oct 11, 2024
7dd5a2c
chore: Cross chain balances do not yet exist, add todo
gambinish Oct 16, 2024
a838c74
chore: Polish styling of list items in dropdown
gambinish Oct 16, 2024
c91c747
chore: Cleanup
gambinish Oct 16, 2024
6ec980b
chore: Merge main, address conflicts
gambinish Oct 17, 2024
3b6d223
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 17, 2024
d670862
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 21, 2024
bf5913c
fix: Update unit tests in preferences-controller
gambinish Oct 21, 2024
85d5161
feat: Add filterAssets function
gambinish Oct 21, 2024
72ea2cf
chore: Polish filters to be layerable in order of importance, allowin…
gambinish Oct 21, 2024
8b52780
fix: Lint tsc, specifiy chain indication rather than arbitrary number
gambinish Oct 21, 2024
4349f4f
chore: Localize strings
gambinish Oct 21, 2024
8b83df4
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 22, 2024
bc82cb4
chore: Add localized Network string
gambinish Oct 22, 2024
42ad7d4
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 22, 2024
c4ce6c7
chore: Add FILTER_TOKENS_TOGGLE feature flag
gambinish Oct 22, 2024
5be0713
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 22, 2024
023b0ca
fix: Show current selection on Network filter, and ellipsize when ove…
gambinish Oct 22, 2024
c9a2d8d
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 22, 2024
ae96cea
fix: Lint
gambinish Oct 22, 2024
5b40705
fix: Remove duplicate locale string
gambinish Oct 22, 2024
f7f09da
fix: Cleanup
gambinish Oct 22, 2024
85fe12d
bump asset controllers to 39
bergeron Oct 22, 2024
0f3cd64
update ConfirmTransaction
bergeron Oct 22, 2024
bdf921b
fix useGasFeeEstimates unit test
bergeron Oct 22, 2024
9bc4ecf
fix usePolling tests
bergeron Oct 23, 2024
c6a408d
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 23, 2024
9b1529b
bump controller utils
bergeron Oct 23, 2024
c8bcc0b
remove patch
bergeron Oct 23, 2024
d1a3782
Merge branch 'develop' into brian/asset-controller-39
bergeron Oct 23, 2024
05fd6ef
Update LavaMoat policies
metamaskbot Oct 23, 2024
9dfdfa8
lint
bergeron Oct 23, 2024
04ea3d6
Merge branch 'brian/asset-controller-39' of github.com:MetaMask/metam…
bergeron Oct 23, 2024
cf66072
Merge branch 'develop' into brian/asset-controller-39
bergeron Oct 24, 2024
6934434
fix: Clean up filterAssets logic
gambinish Oct 24, 2024
15e4e47
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 24, 2024
a2074cd
fix: Update network-filter Avatar rendering logic
gambinish Oct 24, 2024
6e80b34
Merge branch 'develop' into feat/mmassets-432_network-filter-extension
gambinish Oct 24, 2024
836a11b
fix: Duplicate chainId
gambinish Oct 24, 2024
441d4cf
Merge branch 'feat/mmassets-432_network-filter-extension' of github.c…
gambinish Oct 24, 2024
d18d25a
chore: Aggregate token listings across chains, per account
gambinish Oct 24, 2024
dd0b3f5
chore: Cleanup variables and logs
gambinish Oct 24, 2024
1e461ee
Merge branch 'brian/asset-controller-39' into feat/mmassets-432_netwo…
gambinish Oct 24, 2024
a51fec4
chore: Update yarn resolution to provide marketData across chains
gambinish Oct 24, 2024
0d637fb
chore: get balances for tokens via TokenTracker
gambinish Oct 25, 2024
c923dfe
feat: poc of consolidated asset view across chains. balances are mocked
gambinish Oct 25, 2024
6a394a2
chore: Integrate filtering logic, to be improved
gambinish Oct 25, 2024
6fac24b
feat: add native tokens to multichain token list (#28193)
jonybur Nov 5, 2024
12570a5
chore: Merge develop, address conflicts
gambinish Nov 5, 2024
39a1285
fix: Missed merge conflict in filter funciton
gambinish Nov 5, 2024
95ce7de
fix: Address conflicts in lavamoat policies
gambinish Nov 5, 2024
f3a679b
fix: Address conflict in main lavamoat policy
gambinish Nov 5, 2024
b0c07c1
fix: Update selectors and various discrepancies after merge conflict …
gambinish Nov 5, 2024
03e047d
fix: Incorrect selector for marketData
gambinish Nov 5, 2024
3612b58
fix: Cleanup
gambinish Nov 5, 2024
776c63b
fix: conversionRate undefined error on network switch
gambinish Nov 5, 2024
9482953
fix: Get native token image from mapping
gambinish Nov 5, 2024
bd035f3
fix: Ethereum mainnet should be called Ethereum
gambinish Nov 5, 2024
23747ed
fix: Changing selected network should reset filters to all networks
gambinish Nov 5, 2024
14c9b57
fix: Cleanup selector console log
gambinish Nov 5, 2024
c308609
Styling changes
jonybur Nov 6, 2024
3c9049c
fix: Add percentage change for native currency
gambinish Nov 6, 2024
f81cbbc
fix: Multichain scam warning should not appear on native tokens, othe…
gambinish Nov 6, 2024
93cd913
fix: Network selector should also update network filter
gambinish Nov 7, 2024
f290926
fix: On mount, set the filters to show all networks by default
gambinish Nov 7, 2024
919faf5
fix: Temporarily stub out showScamWarning boolean. To improve on mult…
gambinish Nov 7, 2024
1710bc7
fix: pricePercentChange1d can be undefined, use optional chaining
gambinish Nov 7, 2024
ffe9e5f
fix: Tweak useEffect in asset-list-control-bar
gambinish Nov 7, 2024
46bc93c
fix: Use tokenChainId not cached chainId from selected network
gambinish Nov 7, 2024
5f0e632
Add auto switching for network on Send
jonybur Nov 7, 2024
f48e734
Merge branch 'feat/mmassets-432_network-filter-extension--integration…
jonybur Nov 7, 2024
25c8a90
Bugfixing, add tooltips
jonybur Nov 7, 2024
42ce9be
Padding fixes
jonybur Nov 7, 2024
6de2f95
UI fixes
jonybur Nov 7, 2024
ecb8508
Reduce size of selector
jonybur Nov 7, 2024
a241f5e
Fix native token clicking
jonybur Nov 7, 2024
3edf269
Fix toast for network switching
jonybur Nov 10, 2024
2dc23d3
Fix asset page for offchain native tokens
jonybur Nov 10, 2024
d778834
Filter out zero-value tokens on asset list picker
jonybur Nov 10, 2024
6537cb6
Design changes
jonybur Nov 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { useRef, useState } from 'react';
import { useSelector } from 'react-redux';
import { getCurrentNetwork, getPreferences } from '../../../../../selectors';
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
getCurrentNetwork,
getNetworkConfigurationsByChainId,
getPreferences,
} from '../../../../../selectors';
import {
Box,
ButtonBase,
Expand All @@ -12,11 +16,10 @@ import {
import SortControl from '../sort-control';
import {
BackgroundColor,
BorderColor,
BorderStyle,
Display,
JustifyContent,
TextColor,
TextVariant,
} from '../../../../../helpers/constants/design-system';
import ImportControl from '../import-control';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
Expand All @@ -28,21 +31,40 @@ import {
ENVIRONMENT_TYPE_POPUP,
} from '../../../../../../shared/constants/app';
import NetworkFilter from '../network-filter';
import { setTokenNetworkFilter } from '../../../../../store/actions';
import Tooltip from '../../../../ui/tooltip';

type AssetListControlBarProps = {
showTokensLinks?: boolean;
};

const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
const t = useI18nContext();
const dispatch = useDispatch();
const popoverRef = useRef<HTMLDivElement>(null);
const currentNetwork = useSelector(getCurrentNetwork);
const allNetworks = useSelector(getNetworkConfigurationsByChainId);
const { tokenNetworkFilter } = useSelector(getPreferences);
const [isTokenSortPopoverOpen, setIsTokenSortPopoverOpen] = useState(false);
const [isNetworkFilterPopoverOpen, setIsNetworkFilterPopoverOpen] =
useState(false);

const allNetworksFilterShown = Object.keys(tokenNetworkFilter ?? {}).length;
const allOpts: Record<string, boolean> = {};
Object.keys(allNetworks).forEach((chainId) => {
allOpts[chainId] = true;
});

const allNetworksFilterShown =
Object.keys(tokenNetworkFilter).length !== Object.keys(allOpts).length;

// TODO: This useEffect should be a migration
// We need to set the default filter for all users to be all included networks, rather than defaulting to empty object
// This effect is to unblock and derisk in the short-term
useEffect(() => {
if (Object.keys(tokenNetworkFilter).length === 0) {
dispatch(setTokenNetworkFilter(allOpts));
}
}, []);

const windowType = getEnvironmentType();
const isFullScreen =
Expand All @@ -67,21 +89,16 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
return (
<Box
className="asset-list-control-bar"
marginLeft={4}
marginRight={4}
paddingTop={4}
marginLeft={2}
marginRight={2}
ref={popoverRef}
>
<Box
display={Display.Flex}
justifyContent={
isFullScreen ? JustifyContent.flexStart : JustifyContent.spaceBetween
}
>
<Box display={Display.Flex} justifyContent={JustifyContent.spaceBetween}>
{process.env.FILTER_TOKENS_TOGGLE && (
<ButtonBase
data-testid="sort-by-popover-toggle"
className="asset-list-control-bar__button"
variant={TextVariant.bodyMdMedium}
className="asset-list-control-bar__button asset-list-control-bar__network_control"
onClick={toggleNetworkFilterPopover}
size={ButtonBaseSize.Sm}
endIconName={IconName.ArrowDown}
Expand All @@ -90,8 +107,6 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
? BackgroundColor.backgroundPressed
: BackgroundColor.backgroundDefault
}
borderColor={BorderColor.borderMuted}
borderStyle={BorderStyle.solid}
color={TextColor.textDefault}
marginRight={isFullScreen ? 2 : null}
ellipsis
Expand All @@ -102,26 +117,32 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
</ButtonBase>
)}

<ButtonBase
data-testid="sort-by-popover-toggle"
className="asset-list-control-bar__button"
onClick={toggleTokenSortPopover}
size={ButtonBaseSize.Sm}
endIconName={IconName.ArrowDown}
backgroundColor={
isTokenSortPopoverOpen
? BackgroundColor.backgroundPressed
: BackgroundColor.backgroundDefault
}
borderColor={BorderColor.borderMuted}
borderStyle={BorderStyle.solid}
color={TextColor.textDefault}
marginRight={isFullScreen ? 2 : null}
<Box
className="asset-list-control-bar__buttons"
display={Display.Flex}
justifyContent={JustifyContent.flexEnd}
>
{t('sortBy')}
</ButtonBase>
<Tooltip title={t('sortBy')} position="bottom" distance={20}>
<ButtonBase
data-testid="sort-by-popover-toggle"
className="asset-list-control-bar__button"
onClick={toggleTokenSortPopover}
size={ButtonBaseSize.Sm}
endIconName={IconName.SwapVertical}
backgroundColor={
isTokenSortPopoverOpen
? BackgroundColor.backgroundPressed
: BackgroundColor.backgroundDefault
}
color={TextColor.textDefault}
marginRight={isFullScreen ? 2 : null}
/>
</Tooltip>

<ImportControl showTokensLinks={showTokensLinks} />
<Tooltip title={t('importTokens')} position="bottom" distance={20}>
<ImportControl showTokensLinks={showTokensLinks} />
</Tooltip>
</Box>
</Box>

<Popover
Expand All @@ -143,7 +164,7 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
<Popover
onClickOutside={closePopover}
isOpen={isTokenSortPopoverOpen}
position={PopoverPosition.BottomStart}
position={PopoverPosition.BottomEnd}
referenceElement={popoverRef.current}
matchWidth={!isFullScreen}
style={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
.asset-list-control-bar {
padding-top: 8px;
padding-bottom: 8px;
padding-top: 4px;
padding-bottom: 4px;

&__button {
// using percentage here to allow for full network name to show when full screen, but ellipsize on extension view
max-width: 35%;
}

&__network_control {
justify-content: space-between;
min-width: 185px;
border-radius: 8px;
padding: 0px 8px !important;
gap: 5px;
text-transform: lowercase;

span::first-letter {
text-transform: uppercase;
}
}

&__buttons {
display: flex;
justify-content: flex-end;

& .asset-list-control-bar__button {
width: 32px;
min-width: 32px;
margin: 0;
border-radius: 8px;
padding: 0;
}
}

&__button:hover {
background-color: var(--color-background-hover);
}
Expand Down
8 changes: 3 additions & 5 deletions ui/components/app/assets/asset-list/asset-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
import { getIsNativeTokenBuyable } from '../../../../ducks/ramps';
///: END:ONLY_INCLUDE_IF
import AssetListControlBar from './asset-list-control-bar';
import NativeToken from './native-token';

export type TokenWithBalance = {
address: string;
Expand All @@ -51,7 +50,7 @@ export type TokenWithBalance = {
};

export type AssetListProps = {
onClickAsset: (arg: string) => void;
onClickAsset: (chainId: string, address: string) => void;
showTokensLinks?: boolean;
};

Expand Down Expand Up @@ -115,9 +114,8 @@ const AssetList = ({ onClickAsset, showTokensLinks }: AssetListProps) => {
)}
<AssetListControlBar showTokensLinks={showTokensLinks} />
<TokenList
nativeToken={<NativeToken onClickAsset={onClickAsset} />}
onTokenClick={(tokenAddress: string) => {
onClickAsset(tokenAddress);
onTokenClick={(chainId: string, tokenAddress: string) => {
onClickAsset(chainId, tokenAddress);
trackEvent({
event: MetaMetricsEventName.TokenScreenOpened,
category: MetaMetricsEventCategory.Navigation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
} from '../../../../component-library';
import {
BackgroundColor,
BorderColor,
BorderStyle,
TextColor,
} from '../../../../../helpers/constants/design-system';
import { showImportTokensModal } from '../../../../../store/actions';
Expand All @@ -18,7 +16,6 @@ import {
MetaMetricsEventName,
} from '../../../../../../shared/constants/metametrics';
import { getMultichainIsEvm } from '../../../../../selectors/multichain';
import { useI18nContext } from '../../../../../hooks/useI18nContext';

type AssetListControlBarProps = {
showTokensLinks?: boolean;
Expand All @@ -27,7 +24,6 @@ type AssetListControlBarProps = {
const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
const dispatch = useDispatch();
const trackEvent = useContext(MetaMetricsContext);
const t = useI18nContext();
const isEvm = useSelector(getMultichainIsEvm);
// NOTE: Since we can parametrize it now, we keep the original behavior
// for EVM assets
Expand All @@ -41,8 +37,6 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
size={ButtonBaseSize.Sm}
startIconName={IconName.Add}
backgroundColor={BackgroundColor.backgroundDefault}
borderColor={BorderColor.borderMuted}
borderStyle={BorderStyle.solid}
color={TextColor.textDefault}
onClick={() => {
dispatch(showImportTokensModal());
Expand All @@ -54,9 +48,7 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
},
});
}}
>
{t('import')}
</ButtonBase>
/>
);
};

Expand Down
Loading