Skip to content

Commit dc83137

Browse files
authored
fix: fix hide nft (MetaMask#23833)
## **Description** PR to fix hiding nft. ## **Changelog** CHANGELOG entry: fixed hiding nft flow. ## **Related issues** Fixes: MetaMask#16069 ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **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/cc92ba95-8204-43cd-a205-3df3556160d5 ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > <sup>[Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) is generating a summary for commit d303671. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 7203db7 commit dc83137

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

app/components/UI/NftGrid/NftGridItemActionSheet.test.tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ jest.mock('react-native', () => ({
1414
},
1515
}));
1616

17-
jest.mock('../../../selectors/networkController', () => ({
18-
selectChainId: jest.fn(),
19-
selectSelectedNetworkClientId: jest.fn(),
20-
}));
21-
2217
jest.mock('../../../util/theme', () => ({
2318
useTheme: () => ({
2419
themeAppearance: 'light',
@@ -45,6 +40,9 @@ jest.mock('../../../core/Engine', () => ({
4540
removeAndIgnoreNft: jest.fn(),
4641
addNft: jest.fn(),
4742
},
43+
NetworkController: {
44+
findNetworkClientIdByChainId: jest.fn().mockReturnValue('mainnet'),
45+
},
4846
},
4947
}));
5048

@@ -93,20 +91,8 @@ jest.mock('@metamask/react-native-actionsheet', () => {
9391
);
9492
});
9593

96-
import {
97-
selectChainId,
98-
selectSelectedNetworkClientId,
99-
} from '../../../selectors/networkController';
10094
import Engine from '../../../core/Engine';
10195

102-
const mockSelectChainId = selectChainId as jest.MockedFunction<
103-
typeof selectChainId
104-
>;
105-
const mockSelectSelectedNetworkClientId =
106-
selectSelectedNetworkClientId as jest.MockedFunction<
107-
typeof selectSelectedNetworkClientId
108-
>;
109-
11096
describe('NftGridItemActionSheet', () => {
11197
const mockNft: Nft = {
11298
address: '0x123',
@@ -124,8 +110,6 @@ describe('NftGridItemActionSheet', () => {
124110

125111
beforeEach(() => {
126112
jest.clearAllMocks();
127-
mockSelectChainId.mockReturnValue('0x1');
128-
mockSelectSelectedNetworkClientId.mockReturnValue('mainnet');
129113
});
130114

131115
it('renders action sheet with correct options', () => {

app/components/UI/NftGrid/NftGridItemActionSheet.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import ActionSheet from '@metamask/react-native-actionsheet';
55
import { strings } from '../../../../locales/i18n';
66
import Engine from '../../../core/Engine';
77
import { useTheme } from '../../../util/theme';
8-
import { useSelector } from 'react-redux';
9-
import { selectSelectedNetworkClientId } from '../../../selectors/networkController';
8+
import { toHex } from '@metamask/controller-utils';
109

1110
const NftGridItemActionSheet = ({
1211
actionSheetRef,
@@ -16,17 +15,25 @@ const NftGridItemActionSheet = ({
1615
longPressedCollectible: Nft | null;
1716
}) => {
1817
const { themeAppearance } = useTheme();
19-
const selectedNetworkClientId = useSelector(selectSelectedNetworkClientId);
18+
19+
const getNetworkClientIdForNft = (nft: Nft) => {
20+
if (!nft.chainId) return undefined;
21+
const { NetworkController } = Engine.context;
22+
return NetworkController.findNetworkClientIdByChainId(toHex(nft.chainId));
23+
};
2024

2125
const removeNft = () => {
2226
if (!longPressedCollectible) return;
2327

2428
const { NftController } = Engine.context;
29+
const networkClientId = getNetworkClientIdForNft(longPressedCollectible);
30+
31+
if (!networkClientId) return;
2532

2633
NftController.removeAndIgnoreNft(
2734
longPressedCollectible.address,
2835
longPressedCollectible.tokenId,
29-
selectedNetworkClientId,
36+
networkClientId,
3037
);
3138

3239
Alert.alert(
@@ -39,11 +46,14 @@ const NftGridItemActionSheet = ({
3946
if (!longPressedCollectible) return;
4047

4148
const { NftController } = Engine.context;
49+
const networkClientId = getNetworkClientIdForNft(longPressedCollectible);
50+
51+
if (!networkClientId) return;
4252

4353
NftController.addNft(
4454
longPressedCollectible.address,
4555
longPressedCollectible.tokenId,
46-
selectedNetworkClientId,
56+
networkClientId,
4757
);
4858
};
4959

0 commit comments

Comments
 (0)