Skip to content

Commit ed9ed94

Browse files
feat: bump assets-controllers to v54 and add PV to NFT tab (#30903)
## **Description** PR to add network filter to NFT tab. This core PR MetaMask/core#5448 should be released before updating this one. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/30903?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Choose Ethereum mainnet 2. Click on NFTs tab 3. You should see network filter + your detected NFTs on Ethereum mainnet and linea (if you have any) 4. Switch between networks and try importing manually your NFTs on networks that are not (Ethereum/linea) 5. Make sure you see your NFTs correctly ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> https://github.com/user-attachments/assets/81b99e68-3d25-40ca-9c0f-f103b5904fa6 ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: MetaMask Bot <[email protected]>
1 parent 9576f7c commit ed9ed94

File tree

20 files changed

+204
-102
lines changed

20 files changed

+204
-102
lines changed

.yarn/patches/@metamask-assets-controllers-npm-53.1.1-644979f986.patch renamed to .yarn/patches/@metamask-assets-controllers-npm-54.0.0-1b1fcfcc45.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/dist/assetsUtil.cjs b/dist/assetsUtil.cjs
2-
index 017fb94055b64f99c75f8d54b763a501bdd03e97..34396ba143e3ebcb04fa2c80f7a35d1abd06710e 100644
2+
index 0eb212b5eb9a9ef2f61c44b9e5f04b14d5571865..f4f097a86a0feba2d20f84199536fdd097360777 100644
33
--- a/dist/assetsUtil.cjs
44
+++ b/dist/assetsUtil.cjs
55
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
@@ -10,7 +10,7 @@ index 017fb94055b64f99c75f8d54b763a501bdd03e97..34396ba143e3ebcb04fa2c80f7a35d1a
1010
exports.getKeyByValue = exports.fetchTokenContractExchangeRates = exports.reduceInBatchesSerially = exports.divideIntoBatches = exports.ethersBigNumberToBN = exports.addUrlProtocolPrefix = exports.getFormattedIpfsUrl = exports.getIpfsCIDv1AndPath = exports.removeIpfsProtocolPrefix = exports.isTokenListSupportedForNetwork = exports.isTokenDetectionSupportedForNetwork = exports.SupportedStakedBalanceNetworks = exports.SupportedTokenDetectionNetworks = exports.formatIconUrlWithProxy = exports.formatAggregatorNames = exports.hasNewCollectionFields = exports.compareNftMetadata = exports.TOKEN_PRICES_BATCH_SIZE = void 0;
1111
const controller_utils_1 = require("@metamask/controller-utils");
1212
const utils_1 = require("@metamask/utils");
13-
@@ -233,7 +234,7 @@ async function getIpfsCIDv1AndPath(ipfsUrl) {
13+
@@ -234,7 +235,7 @@ async function getIpfsCIDv1AndPath(ipfsUrl) {
1414
const index = url.indexOf('/');
1515
const cid = index !== -1 ? url.substring(0, index) : url;
1616
const path = index !== -1 ? url.substring(index) : undefined;

.yarn/patches/@metamask-assets-controllers-patch-3424767802.patch

-12
This file was deleted.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@
263263
"@metamask/address-book-controller": "^6.0.3",
264264
"@metamask/announcement-controller": "^7.0.3",
265265
"@metamask/approval-controller": "^7.0.0",
266-
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A53.1.1#~/.yarn/patches/@metamask-assets-controllers-npm-53.1.1-644979f986.patch",
266+
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@npm%3A54.0.0#~/.yarn/patches/@metamask-assets-controllers-npm-54.0.0-1b1fcfcc45.patch",
267267
"@metamask/base-controller": "^8.0.0",
268268
"@metamask/bitcoin-wallet-snap": "^0.9.0",
269269
"@metamask/browser-passworder": "^4.3.0",

test/e2e/fixture-builder.js

+2
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ class FixtureBuilder {
394394
image:
395395
'ipfs://bafkreifvhjdf6ve4jfv6qytqtux5nd4nwnelioeiqx5x2ez5yrgrzk7ypi',
396396
standard: 'ERC1155',
397+
chainId: 1337,
397398
},
398399
],
399400
},
@@ -428,6 +429,7 @@ class FixtureBuilder {
428429
name: 'Test Dapp NFTs #1',
429430
standard: 'ERC721',
430431
tokenId: '1',
432+
chainId: 1337,
431433
},
432434
],
433435
},

test/e2e/tests/tokens/nft/mocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function setupAutoDetectMocking(
370370
.withQuery({
371371
limit: 50,
372372
includeTopBid: true,
373-
chainIds: '1',
373+
chainIds: ['1', '59144'],
374374
continuation: '',
375375
})
376376
.thenCallback(() => {

ui/components/app/assets/asset-list/asset-list-control-bar/asset-list-control-bar.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ import { getMultichainNetwork } from '../../../../../selectors/multichain';
5555

5656
type AssetListControlBarProps = {
5757
showTokensLinks?: boolean;
58+
showTokenFiatBalance?: boolean;
5859
};
5960

60-
const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
61+
const AssetListControlBar = ({
62+
showTokensLinks,
63+
showTokenFiatBalance,
64+
}: AssetListControlBarProps) => {
6165
const t = useI18nContext();
6266
const dispatch = useDispatch();
6367
const trackEvent = useContext(MetaMetricsContext);
@@ -113,6 +117,8 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
113117
useEffect(() => {
114118
if (Object.keys(tokenNetworkFilter).length === 1) {
115119
dispatch(setTokenNetworkFilter({ [currentNetwork.chainId]: true }));
120+
} else {
121+
dispatch(setTokenNetworkFilter(allOpts));
116122
}
117123
}, [Object.keys(allNetworks).length]);
118124

@@ -253,7 +259,10 @@ const AssetListControlBar = ({ showTokensLinks }: AssetListControlBarProps) => {
253259
minWidth: isFullScreen ? '250px' : '',
254260
}}
255261
>
256-
<NetworkFilter handleClose={closePopover} />
262+
<NetworkFilter
263+
handleClose={closePopover}
264+
showTokenFiatBalance={showTokenFiatBalance}
265+
/>
257266
</Popover>
258267
<Popover
259268
onClickOutside={closePopover}

ui/components/app/assets/asset-list/network-filter/network-filter.tsx

+31-23
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,13 @@ import InfoTooltip from '../../../../ui/info-tooltip';
4040

4141
type SortControlProps = {
4242
handleClose: () => void;
43+
showTokenFiatBalance?: boolean;
4344
};
4445

45-
const NetworkFilter = ({ handleClose }: SortControlProps) => {
46+
const NetworkFilter = ({
47+
handleClose,
48+
showTokenFiatBalance = true,
49+
}: SortControlProps) => {
4650
const t = useI18nContext();
4751
const dispatch = useDispatch();
4852
const chainId = useSelector(getCurrentChainId);
@@ -121,20 +125,22 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
121125
>
122126
{t('popularNetworks')}
123127
</Text>
124-
<Text
125-
variant={TextVariant.bodySmMedium}
126-
color={TextColor.textAlternative}
127-
data-testid="network-filter-all__total"
128-
>
129-
<UserPreferencedCurrencyDisplay
130-
value={selectedAccountBalanceForAllNetworks}
131-
type="PRIMARY"
132-
ethNumberOfDecimals={4}
133-
hideTitle
134-
showFiat
135-
isAggregatedFiatOverviewBalance
136-
/>
137-
</Text>
128+
{showTokenFiatBalance && (
129+
<Text
130+
variant={TextVariant.bodySmMedium}
131+
color={TextColor.textAlternative}
132+
data-testid="network-filter-all__total"
133+
>
134+
<UserPreferencedCurrencyDisplay
135+
value={selectedAccountBalanceForAllNetworks}
136+
type="PRIMARY"
137+
ethNumberOfDecimals={4}
138+
hideTitle
139+
showFiat
140+
isAggregatedFiatOverviewBalance
141+
/>
142+
</Text>
143+
)}
138144
</Box>
139145
<Box display={Display.Flex} alignItems={AlignItems.center}>
140146
<InfoTooltip
@@ -191,14 +197,16 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
191197
variant={TextVariant.bodySmMedium}
192198
color={TextColor.textAlternative}
193199
>
194-
<UserPreferencedCurrencyDisplay
195-
value={selectedAccountBalance}
196-
type="PRIMARY"
197-
ethNumberOfDecimals={4}
198-
hideTitle
199-
showFiat
200-
isAggregatedFiatOverviewBalance
201-
/>
200+
{showTokenFiatBalance && (
201+
<UserPreferencedCurrencyDisplay
202+
value={selectedAccountBalance}
203+
type="PRIMARY"
204+
ethNumberOfDecimals={4}
205+
hideTitle
206+
showFiat
207+
isAggregatedFiatOverviewBalance
208+
/>
209+
)}
202210
</Text>
203211
</Box>
204212
<AvatarNetwork

ui/components/app/assets/nfts/nft-grid/nft-grid.tsx

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { useSelector } from 'react-redux';
3-
import { Hex } from '@metamask/utils';
3+
import { toHex } from '@metamask/controller-utils';
44
import {
55
AlignItems,
66
Display,
@@ -12,26 +12,20 @@ import { getNftImageAlt } from '../../../../../helpers/utils/nfts';
1212
import { NftItem } from '../../../../multichain/nft-item';
1313
import { NFT } from '../../../../multichain/asset-picker-amount/asset-picker-modal/types';
1414
import {
15-
getCurrentNetwork,
1615
getIpfsGateway,
1716
getNftIsStillFetchingIndication,
1817
} from '../../../../../selectors';
1918
import useGetAssetImageUrl from '../../../../../hooks/useGetAssetImageUrl';
19+
import { getImageForChainId } from '../../../../../selectors/multichain';
20+
import { getNetworkConfigurationsByChainId } from '../../../../../../shared/modules/selectors/networks';
2021
import NFTGridItemErrorBoundary from './nft-grid-item-error-boundary';
2122

2223
const NFTGridItem = (props: {
2324
nft: NFT;
2425
onClick: () => void;
2526
privacyMode?: boolean;
26-
currentChain: {
27-
chainId: Hex;
28-
nickname: string;
29-
rpcPrefs?: {
30-
imageUrl: string;
31-
};
32-
};
3327
}) => {
34-
const { nft, onClick, privacyMode, currentChain } = props;
28+
const { nft, onClick, privacyMode } = props;
3529

3630
const { image, imageOriginal } = nft;
3731

@@ -40,6 +34,7 @@ const NFTGridItem = (props: {
4034
imageOriginal ?? image ?? undefined,
4135
ipfsGateway,
4236
);
37+
const allNetworks = useSelector(getNetworkConfigurationsByChainId);
4338

4439
const isImageHosted =
4540
image?.startsWith('https:') || image?.startsWith('http:');
@@ -55,8 +50,8 @@ const NFTGridItem = (props: {
5550
nft={nft}
5651
alt={nftImageAlt}
5752
src={nftItemSrc}
58-
networkName={currentChain.nickname}
59-
networkSrc={currentChain.rpcPrefs?.imageUrl}
53+
networkName={allNetworks?.[toHex(nft.chainId)]?.name}
54+
networkSrc={getImageForChainId(toHex(nft.chainId)) || undefined}
6055
onClick={onClick}
6156
isIpfsURL={isIpfsURL}
6257
privacyMode={privacyMode}
@@ -74,11 +69,6 @@ export default function NftGrid({
7469
handleNftClick: (nft: NFT) => void;
7570
privacyMode?: boolean;
7671
}) {
77-
const currentChain = useSelector(getCurrentNetwork) as {
78-
chainId: Hex;
79-
nickname: string;
80-
rpcPrefs?: { imageUrl: string };
81-
};
8272
const nftsStillFetchingIndication = useSelector(
8373
getNftIsStillFetchingIndication,
8474
);
@@ -96,7 +86,6 @@ export default function NftGrid({
9686
className="nft-items__image-wrapper"
9787
>
9888
<NFTGridItem
99-
currentChain={currentChain}
10089
nft={nft}
10190
onClick={() => handleNftClick(nft)}
10291
privacyMode={privacyMode}

ui/components/app/assets/nfts/nfts-detection-notice-nfts-tab/nfts-detection-notice-nfts-tab.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import React from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import { useI18nContext } from '../../../../../hooks/useI18nContext';
4-
import { getOpenSeaEnabled } from '../../../../../selectors';
4+
import {
5+
getAllChainsToPoll,
6+
getOpenSeaEnabled,
7+
} from '../../../../../selectors';
58
import {
69
detectNfts,
710
setOpenSeaEnabled,
@@ -14,6 +17,7 @@ export default function NFTsDetectionNoticeNFTsTab() {
1417
const t = useI18nContext();
1518
const dispatch = useDispatch();
1619
const isDisplayNFTMediaToggleEnabled = useSelector(getOpenSeaEnabled);
20+
const allChainIds = useSelector(getAllChainsToPoll);
1721

1822
return (
1923
<BannerAlert
@@ -28,7 +32,7 @@ export default function NFTsDetectionNoticeNFTsTab() {
2832
// Show toast
2933
dispatch(setShowNftDetectionEnablementToast(true));
3034
// dispatch action to detect nfts
31-
dispatch(detectNfts());
35+
dispatch(detectNfts(allChainIds));
3236
}}
3337
>
3438
{

ui/components/app/assets/nfts/nfts-tab/nfts-tab.test.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const NFTS = [
3636
image:
3737
'https://lh3.googleusercontent.com/BdxvLseXcfl57BiuQcQYdJ64v-aI8din7WPk0Pgo3qQFhAUH-B6i-dCqqc_mCkRIzULmwzwecnohLhrcH8A9mpWIZqA7ygc52Sr81hE',
3838
standard: 'ERC1155',
39+
chainId: '1',
3940
},
4041
{
4142
address: '0x495f947276749Ce646f68AC8c248420045cb7b5e',
@@ -54,6 +55,7 @@ const NFTS = [
5455
image:
5556
'https://lh3.googleusercontent.com/H7VrxaalZv4PF1B8U7ADuc8AfuqTVyzmMEDQ5OXKlx0Tqu5XiwsKYj4j_pAF6wUJjLMQbSN_0n3fuj84lNyRhFW9hyrxqDfY1IiQEQ',
5657
standard: 'ERC1155',
58+
chainId: '1',
5759
},
5860
{
5961
address: '0x495f947276749Ce646f68AC8c248420045cb7b5e',
@@ -72,6 +74,7 @@ const NFTS = [
7274
image:
7375
'https://lh3.googleusercontent.com/CHNTSlKB_Gob-iwTq8jcag6XwBkTqBMLt_vEKeBv18Q4AoPFAEPceqK6mRzkad2s5djx6CT5zbGQwDy81WwtNzViK5dQbG60uAWv',
7476
standard: 'ERC1155',
77+
chainId: '1',
7578
},
7679
{
7780
address: '0x495f947276749Ce646f68AC8c248420045cb7b5e',
@@ -89,6 +92,7 @@ const NFTS = [
8992
image:
9093
'https://lh3.googleusercontent.com/4jfPi-nQNWCUXD5qVNVWX7LX2UufU_elEJcvICFlsTdcBXv70asnDEOlI8oKECZxlXq1wseeIXMwmP5tLyOUxMKk',
9194
standard: 'ERC1155',
95+
chainId: '1',
9296
},
9397
{
9498
address: '0x495f947276749Ce646f68AC8c248420045cb7b5e',
@@ -106,6 +110,7 @@ const NFTS = [
106110
image:
107111
'https://lh3.googleusercontent.com/BdxvLseXcfl57BiuQcQYdJ64v-aI8din7WPk0Pgo3qQFhAUH-B6i-dCqqc_mCkRIzULmwzwecnohLhrcH8A9mpWIZqA7ygc52Sr81hE',
108112
standard: 'ERC1155',
113+
chainId: '1',
109114
},
110115
{
111116
address: '0xDc7382Eb0Bc9C352A4CbA23c909bDA01e0206414',
@@ -114,6 +119,7 @@ const NFTS = [
114119
description: null,
115120
image: 'ipfs://QmTSZUNt8AKyDabkyXXXP4oHWDnaVXgNdXoJGEyaYzLbeL',
116121
standard: 'ERC721',
122+
chainId: '1',
117123
},
118124
{
119125
address: '0xDc7382Eb0Bc9C352A4CbA23c909bDA01e0206414',
@@ -122,6 +128,7 @@ const NFTS = [
122128
description: null,
123129
image: 'ipfs://QmTSZUNt8AKyDabkyXXXP4oHWDnaVXgNdXoJGEyaYzLbeL',
124130
standard: 'ERC721',
131+
chainId: '1',
125132
},
126133
{
127134
address: '0xDc7382Eb0Bc9C352A4CbA23c909bDA01e0206414',
@@ -130,6 +137,7 @@ const NFTS = [
130137
description: null,
131138
image: 'ipfs://QmTSZUNt8AKyDabkyXXXP4oHWDnaVXgNdXoJGEyaYzLbeL',
132139
standard: 'ERC721',
140+
chainId: '1',
133141
},
134142
];
135143

@@ -142,7 +150,7 @@ const ACCOUNT_1 = '0x123';
142150
const ACCOUNT_2 = '0x456';
143151
const setUseNftDetectionStub = jest.fn();
144152
const setDisplayNftMediaStub = jest.fn();
145-
153+
const setPreferenceStub = jest.fn();
146154
const render = ({
147155
nftContracts = [],
148156
nfts = [],
@@ -219,6 +227,7 @@ describe('NFT Items', () => {
219227
updateNftDropDownState: updateNftDropDownStateStub,
220228
setUseNftDetection: setUseNftDetectionStub,
221229
setOpenSeaEnabled: setDisplayNftMediaStub,
230+
setPreference: setPreferenceStub,
222231
});
223232
const historyPushMock = jest.fn();
224233

0 commit comments

Comments
 (0)