-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: cp-7.41.0 support NFT collectibles that have multiple images (#1…
…3689) ## **Description** Ensures that we handle array images correctly by defaulting to their first image ## **Related issues** Fixes: https://consensys.slack.com/archives/C8RSKCNCD/p1739984618053419 ## **Manual testing steps** This is not really testable unless you comment out validation in a dev version to add this NFT. ``` https://polygonscan.com/token/0x4b22c268e3f7f643686e0dfb160b40fe5328cccd?a=0x397d7171504776AD3d5f578ce772914539E28a49 contract address: 0x4b22C268E3f7f643686E0dfB160B40fE5328cccD TokenID: 6822 ``` 1. Add the above NFT. 2. Does it render in the NFT tab. 3. Can you click on an NFT to visit the details page 4. Can you click on the NFT in the details page to expand the image? ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] 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). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] 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.
- Loading branch information
1 parent
af66b55
commit 7180605
Showing
5 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { getNftImage } from './get-nft-image'; | ||
|
||
describe('getNftImage', () => { | ||
it('returns original image if string', () => { | ||
const image = | ||
'ipfs://bafybeidgklvljyifilhtrxzh77brgnhcy6s2wxoxqc2l73zr2nxlwuxfcy'; | ||
const result = getNftImage(image); | ||
expect(result).toBe(image); | ||
}); | ||
|
||
it('returns the first image if image is an array', () => { | ||
const image = [ | ||
'ipfs://bafybeidgklvljyifilhtrxzh77brgnhcy6s2wxoxqc2l73zr2nxlwuxfcy', | ||
'ipfs://bafybeic26kitpujb3q5h5w7yovmvgmtxl3y4ldsb2pfgual5jq62emsmxq', | ||
]; | ||
const result = getNftImage(image); | ||
expect(result).toBe(image[0]); | ||
}); | ||
|
||
it('returns undefined if image is missing', () => { | ||
const image = undefined; | ||
const result = getNftImage(image); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('returns undefined if image is not a type we were expecting ', () => { | ||
const image = { badType: 'badType' } as unknown as string; | ||
const result = getNftImage(image); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
type NFTImage = string | string[] | undefined | null; | ||
export const getNftImage = (image: NFTImage): string | undefined => { | ||
if (typeof image === 'string') { | ||
return image; | ||
} | ||
|
||
if (Array.isArray(image)) { | ||
return image[0]; | ||
} | ||
|
||
return undefined; | ||
}; |