-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: multichain detect tokens feat (#12417)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** PR to add the multichain autodetection to mobile under a feature flag <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Fixes: ## **Manual testing steps** 1. run `PORTFOLIO_VIEW=true yarn watch` 2. run `yarn start:ios` 3. check if the tokens autodetection is multichained ## **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/c4428c82-5fb7-4701-8625-cf7bb36ee4be ## **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. --------- Co-authored-by: sahar-fehri <[email protected]>
- Loading branch information
1 parent
57da0a9
commit b2f9eec
Showing
42 changed files
with
4,493 additions
and
202 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
3 changes: 3 additions & 0 deletions
3
app/components/UI/NetworkAssetLogo/__snapshots__/index.test.tsx.snap
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,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NetworkAssetLogo Component matches the snapshot for non-mainnet 1`] = `null`; |
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,73 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react-native'; | ||
import NetworkAssetLogo from '.'; | ||
import TokenIcon from '../Swaps/components/TokenIcon'; | ||
import { ChainId } from '@metamask/controller-utils'; | ||
|
||
// Mock the TokenIcon component | ||
jest.mock('../Swaps/components/TokenIcon', () => jest.fn(() => null)); | ||
|
||
describe('NetworkAssetLogo Component', () => { | ||
it('matches the snapshot for non-mainnet', () => { | ||
const { toJSON } = render( | ||
<NetworkAssetLogo | ||
chainId="42" | ||
ticker="DAI" | ||
style={{}} | ||
big | ||
biggest={false} | ||
testID="network-asset-logo" | ||
/>, | ||
); | ||
|
||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders TokenIcon with ETH for mainnet chainId', () => { | ||
const props = { | ||
chainId: ChainId.mainnet, | ||
ticker: 'TEST', | ||
style: { width: 50, height: 50 }, | ||
big: true, | ||
biggest: false, | ||
testID: 'network-asset-logo', | ||
}; | ||
|
||
render(<NetworkAssetLogo {...props} />); | ||
|
||
expect(TokenIcon).toHaveBeenCalledWith( | ||
{ | ||
big: props.big, | ||
biggest: props.biggest, | ||
symbol: 'ETH', | ||
style: props.style, | ||
testID: props.testID, | ||
}, | ||
{}, | ||
); | ||
}); | ||
|
||
it('renders TokenIcon with ticker for non-mainnet chainId', () => { | ||
const props = { | ||
chainId: '0x38', // Binance Smart Chain | ||
ticker: 'BNB', | ||
style: { width: 40, height: 40 }, | ||
big: false, | ||
biggest: true, | ||
testID: 'network-asset-logo', | ||
}; | ||
|
||
render(<NetworkAssetLogo {...props} />); | ||
|
||
expect(TokenIcon).toHaveBeenCalledWith( | ||
{ | ||
big: props.big, | ||
biggest: props.biggest, | ||
symbol: props.ticker, | ||
style: props.style, | ||
testID: props.testID, | ||
}, | ||
{}, | ||
); | ||
}); | ||
}); |
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,44 @@ | ||
import React from 'react'; | ||
import { ChainId } from '@metamask/controller-utils'; | ||
import TokenIcon from '../Swaps/components/TokenIcon'; | ||
|
||
interface NetworkAssetLogoProps { | ||
chainId: string; | ||
ticker: string; | ||
style: object; | ||
big: boolean; | ||
biggest: boolean; | ||
testID: string; | ||
} | ||
|
||
function NetworkAssetLogo({ | ||
chainId, | ||
ticker, | ||
style, | ||
big, | ||
biggest, | ||
testID, | ||
}: NetworkAssetLogoProps) { | ||
if (chainId === ChainId.mainnet) { | ||
return ( | ||
<TokenIcon | ||
big={big} | ||
biggest={biggest} | ||
symbol={'ETH'} | ||
style={style} | ||
testID={testID} | ||
/> | ||
); | ||
} | ||
return ( | ||
<TokenIcon | ||
big={big} | ||
biggest={biggest} | ||
symbol={ticker} | ||
style={style} | ||
testID={testID} | ||
/> | ||
); | ||
} | ||
|
||
export default NetworkAssetLogo; |
Oops, something went wrong.