Skip to content

Commit

Permalink
fix: fix displayed selected rpc for linea (#12255)
Browse files Browse the repository at this point in the history
<!--
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**
the displayed selected rpc for linea is not the correct one

<!--
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: #12252 

## **Manual testing steps**

1. Go Network selector
2. add another rpc for linea
3. check the selected rpc on the network selector view

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**



https://github.com/user-attachments/assets/77b16939-5730-4d06-a9a0-e641e8e7f657



<!-- [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
salimtb authored Nov 12, 2024
1 parent 722d4bb commit 0d77c6e
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 7 deletions.
73 changes: 73 additions & 0 deletions app/components/Views/NetworkSelector/NetworkSelector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,46 @@ const initialState = {
mainnet: { status: 'available', EIPS: { '1559': true } },
},
networkConfigurationsByChainId: {
'0x1': {
blockExplorerUrls: [],
chainId: '0x1',
defaultRpcEndpointIndex: 1,
name: 'Ethereum Mainnet',
nativeCurrency: 'ETH',
rpcEndpoints: [
{
networkClientId: 'mainnet',
type: 'infura',
url: 'https://mainnet.infura.io/v3/{infuraProjectId}',
},
{
name: 'public',
networkClientId: 'ea57f659-c004-4902-bfca-0c9688a43872',
type: 'custom',
url: 'https://mainnet-rpc.publicnode.com',
},
],
},
'0xe708': {
blockExplorerUrls: [],
chainId: '0xe708',
defaultRpcEndpointIndex: 1,
name: 'Linea',
nativeCurrency: 'ETH',
rpcEndpoints: [
{
networkClientId: 'linea-mainnet',
type: 'infura',
url: 'https://linea-mainnet.infura.io/v3/{infuraProjectId}',
},
{
name: 'public',
networkClientId: 'ea57f659-c004-4902-bfca-0c9688a43877',
type: 'custom',
url: 'https://linea-rpc.publicnode.com',
},
],
},
'0xa86a': {
blockExplorerUrls: ['https://snowtrace.io'],
chainId: '0xa86a',
Expand Down Expand Up @@ -459,4 +499,37 @@ describe('Network Selector', () => {
fireEvent(testNetworksSwitch, 'onValueChange', false);
expect(setShowTestNetworksSpy).toBeCalledWith(false);
});

describe('renderLineaMainnet', () => {
it('renders the linea mainnet cell correctly', () => {
(isNetworkUiRedesignEnabled as jest.Mock).mockImplementation(() => true);
const { getByText } = renderComponent(initialState);
const lineaRpcUrl = getByText('https://linea-rpc.publicnode.com');
const lineaCell = getByText('Linea');
expect(lineaCell).toBeTruthy();
expect(lineaRpcUrl).toBeTruthy();
});
});

describe('renderRpcUrl', () => {
it('renders the RPC URL correctly for avalanche', () => {
(isNetworkUiRedesignEnabled as jest.Mock).mockImplementation(() => true);
const { getByText } = renderComponent(initialState);
const avalancheRpcUrl = getByText('api.avax.network/ext/bc/C');
const avalancheCell = getByText('Avalanche Mainnet C-Chain');
expect(avalancheRpcUrl).toBeTruthy();
expect(avalancheCell).toBeTruthy();
});
});

describe('renderMainnet', () => {
it('renders the mainnet cell correctly', () => {
(isNetworkUiRedesignEnabled as jest.Mock).mockImplementation(() => true);
const { getByText } = renderComponent(initialState);
const mainnetRpcUrl = getByText('https://mainnet-rpc.publicnode.com');
const mainnetCell = getByText('Ethereum Mainnet');
expect(mainnetCell).toBeTruthy();
expect(mainnetRpcUrl).toBeTruthy();
});
});
});
7 changes: 5 additions & 2 deletions app/components/Views/NetworkSelector/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ import { isNetworkUiRedesignEnabled } from '../../../util/networks/isNetworkUiRe
import { Hex } from '@metamask/utils';
import hideProtocolFromUrl from '../../../util/hideProtocolFromUrl';
import { CHAIN_IDS } from '@metamask/transaction-controller';
import { LINEA_DEFAULT_RPC_URL } from '../../../constants/urls';
import { useNetworkInfo } from '../../../selectors/selectedNetworkController';
import { NetworkConfiguration } from '@metamask/network-controller';
import Logger from '../../../util/Logger';
Expand Down Expand Up @@ -509,6 +508,10 @@ const NetworkSelector = () => {
const renderLineaMainnet = () => {
const { name: lineaMainnetName, chainId } = Networks['linea-mainnet'];
const name = networkConfigurations?.[chainId]?.name ?? lineaMainnetName;
const rpcUrl =
networkConfigurations?.[chainId]?.rpcEndpoints?.[
networkConfigurations?.[chainId]?.defaultRpcEndpointIndex
].url;

if (isNetworkUiRedesignEnabled() && isNoSearchResults('linea-mainnet'))
return null;
Expand All @@ -529,7 +532,7 @@ const NetworkSelector = () => {
onPress={() => onNetworkChange(LINEA_MAINNET)}
style={styles.networkCell}
buttonIcon={IconName.MoreVertical}
secondaryText={hideKeyFromUrl(LINEA_DEFAULT_RPC_URL)}
secondaryText={hideKeyFromUrl(rpcUrl)}
buttonProps={{
onButtonClick: () => {
openModal(chainId, false, LINEA_MAINNET, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ exports[`Network Selector renders correctly 1`] = `
}
testID="cellbase-avatar-title"
>
Ethereum Main Network
Ethereum Mainnet
</Text>
</View>
</View>
Expand Down Expand Up @@ -686,7 +686,7 @@ exports[`Network Selector renders correctly 1`] = `
}
testID="cellbase-avatar-title"
>
Linea Main Network
Linea
</Text>
</View>
</View>
Expand Down Expand Up @@ -1890,8 +1890,68 @@ exports[`Network Selector renders correctly when network UI redesign is enabled
}
testID="cellbase-avatar-title"
>
Ethereum Main Network
Ethereum Mainnet
</Text>
<TouchableOpacity
accessibilityState={
{
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessible={true}
focusable={false}
onClick={[Function]}
onPress={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
style={
{
"alignItems": "flex-start",
"flexDirection": "row",
"marginBottom": 0,
"zIndex": 1,
}
}
>
<Text
accessibilityRole="text"
numberOfLines={1}
style={
{
"color": "#6a737d",
"fontFamily": "EuclidCircularB-Regular",
"fontSize": 14,
"fontWeight": "400",
"letterSpacing": 0,
"lineHeight": 22,
}
}
>
https://mainnet-rpc.publicnode.com
</Text>
<SvgMock
color="#141618"
height={10}
name="ArrowDown"
style={
{
"height": 10,
"paddingLeft": 8,
"paddingTop": 24,
"width": 10,
}
}
width={10}
/>
</TouchableOpacity>
</View>
</View>
</View>
Expand Down Expand Up @@ -2080,7 +2140,7 @@ exports[`Network Selector renders correctly when network UI redesign is enabled
}
testID="cellbase-avatar-title"
>
Linea Main Network
Linea
</Text>
<TouchableOpacity
accessibilityState={
Expand Down Expand Up @@ -2125,7 +2185,7 @@ exports[`Network Selector renders correctly when network UI redesign is enabled
}
}
>
https://linea-mainnet.infura.io/v3
https://linea-rpc.publicnode.com
</Text>
<SvgMock
color="#141618"
Expand Down

0 comments on commit 0d77c6e

Please sign in to comment.