Skip to content

Commit

Permalink
fix: add linea mainnet to nft detection supported networks (#4515)
Browse files Browse the repository at this point in the history
## Explanation

PR to add linea mainnet to the list of supported networks for
nftDetection.

## References

<!--
Are there any issues that this pull request is tied to? Are there other
links that reviewers should consult to understand these changes better?

For example:

* Fixes #12345
* Related to #67890
-->

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/assets-controllers`

- **ADDED**: Added linea mainnet chainId to the list of supported
networks for nft auto-detection.


## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
sahar-fehri authored Jul 12, 2024
1 parent 43db7ac commit 448f8f0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
47 changes: 46 additions & 1 deletion packages/assets-controllers/src/NftDetectionController.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { AccountsController } from '@metamask/accounts-controller';
import { ControllerMessenger } from '@metamask/base-controller';
import { NFT_API_BASE_URL, ChainId } from '@metamask/controller-utils';
import {
NFT_API_BASE_URL,
ChainId,
InfuraNetworkType,
} from '@metamask/controller-utils';
import {
NetworkClientType,
defaultState as defaultNetworkState,
Expand Down Expand Up @@ -385,6 +389,47 @@ describe('NftDetectionController', () => {
);
});

it('should detect NFTs on Linea mainnet', async () => {
const selectedAddress = '0x1';
const selectedAccount = createMockInternalAccount({
address: selectedAddress,
});
const mockGetSelectedAccount = jest.fn().mockReturnValue(selectedAccount);

await withController(
{
mockNetworkState: {
selectedNetworkClientId: InfuraNetworkType['linea-mainnet'],
},
mockGetSelectedAccount,
},
async ({ controller, controllerEvents }) => {
controllerEvents.triggerPreferencesStateChange({
...getDefaultPreferencesState(),
useNftDetection: true,
selectedAddress,
});
// nock
const mockApiCall = nock(NFT_API_BASE_URL)
.get(`/users/${selectedAddress}/tokens`)
.query({
continuation: '',
limit: '50',
chainIds: '59144',
includeTopBid: true,
})
.reply(200, {
tokens: [],
});

// call detectNfts
await controller.detectNfts();

expect(mockApiCall.isDone()).toBe(true);
},
);
});

it('should detect mainnet falsy', async () => {
await withController(
{
Expand Down
5 changes: 4 additions & 1 deletion packages/assets-controllers/src/NftDetectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export type NftDetectionControllerMessenger = RestrictedControllerMessenger<
AllowedActions['type'],
AllowedEvents['type']
>;
const supportedNftDetectionNetworks: Hex[] = [ChainId.mainnet];
const supportedNftDetectionNetworks: Hex[] = [
ChainId.mainnet,
ChainId['linea-mainnet'],
];

/**
* @type ApiNft
Expand Down

0 comments on commit 448f8f0

Please sign in to comment.