Skip to content

Commit

Permalink
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
Browse files Browse the repository at this point in the history
…k-meta
  • Loading branch information
jiexi authored Sep 22, 2023
2 parents aef5ebb + 55475df commit 14a02e1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ exports[`Security Tab should match snapshot 1`] = `
<div
class="mm-box mm-text mm-avatar-base mm-avatar-base--size-sm mm-avatar-network mm-text--body-sm mm-text--text-transform-uppercase mm-box--display-flex mm-box--justify-content-center mm-box--align-items-center mm-box--color-text-default mm-box--background-color-background-alternative mm-box--rounded-full mm-box--border-color-transparent box--border-style-solid box--border-width-1"
>
C
<img
alt="Custom Mainnet RPC logo"
class="mm-avatar-network__network-image"
src="./images/eth_logo.png"
/>
</div>
<div
class="mm-box mm-box--display-flex mm-box--flex-direction-column"
Expand Down
14 changes: 13 additions & 1 deletion ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
LINEA_GOERLI_TOKEN_IMAGE_URL,
LINEA_MAINNET_DISPLAY_NAME,
LINEA_MAINNET_TOKEN_IMAGE_URL,
CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP,
} from '../../shared/constants/network';
import {
WebHIDConnectedStatuses,
Expand Down Expand Up @@ -1347,7 +1348,18 @@ export function getNonTestNetworks(state) {
// Custom networks added by the user
...Object.values(networkConfigurations)
.filter(({ chainId }) => ![CHAIN_IDS.LOCALHOST].includes(chainId))
.map((network) => ({ ...network, removable: true })),
.map((network) => ({
...network,
rpcPrefs: {
...network.rpcPrefs,
// Provide an image based on chainID if a network
// has been added without an image
imageUrl:
network?.rpcPrefs?.imageUrl ??
CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[network.chainId],
},
removable: true,
})),
];
}

Expand Down
23 changes: 23 additions & 0 deletions ui/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
CHAIN_IDS,
LOCALHOST_DISPLAY_NAME,
NETWORK_TYPES,
OPTIMISM_DISPLAY_NAME,
} from '../../shared/constants/network';
import * as selectors from './selectors';

Expand Down Expand Up @@ -342,6 +343,28 @@ describe('Selectors', () => {
);
expect(customNetwork.removable).toBe(true);
});

it('properly proposes a known network image when not provided by adding function', () => {
const networks = selectors.getAllNetworks({
metamask: {
preferences: {
showTestNetworks: true,
},
networkConfigurations: {
'some-config-name': {
chainId: CHAIN_IDS.OPTIMISM,
nickname: OPTIMISM_DISPLAY_NAME,
id: 'some-config-name',
},
},
},
});

const optimismConfig = networks.find(
({ chainId }) => chainId === CHAIN_IDS.OPTIMISM,
);
expect(optimismConfig.rpcPrefs.imageUrl).toBe('./images/optimism.svg');
});
});

describe('#getCurrentNetwork', () => {
Expand Down

0 comments on commit 14a02e1

Please sign in to comment.