Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix add network form when addMode is true #12833

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export class NetworkSettings extends PureComponent {
editable = false;
blockExplorerUrl =
networkConfigurations?.[chainId]?.blockExplorerUrls[
networkConfigurations?.[chainId]?.defaultBlockExplorerUrlIndex
networkConfigurations?.[chainId]?.defaultBlockExplorerUrlIndex
];
rpcUrl =
networkConfigurations?.[chainId]?.rpcEndpoints[
Expand All @@ -563,13 +563,13 @@ export class NetworkSettings extends PureComponent {
({ rpcEndpoints, defaultRpcEndpointIndex }) =>
rpcEndpoints[defaultRpcEndpointIndex].url === networkTypeOrRpcUrl ||
rpcEndpoints[defaultRpcEndpointIndex].networkClientId ===
networkTypeOrRpcUrl,
networkTypeOrRpcUrl,
);
nickname = networkConfiguration?.name;
chainId = networkConfiguration?.chainId;
blockExplorerUrl =
networkConfiguration?.blockExplorerUrls[
networkConfiguration?.defaultBlockExplorerUrlIndex
networkConfiguration?.defaultBlockExplorerUrlIndex
];
ticker = networkConfiguration?.nativeCurrency;
editable = true;
Expand Down Expand Up @@ -854,8 +854,8 @@ export class NetworkSettings extends PureComponent {
networkConfig,
existingNetwork.chainId === chainId
? {
replacementSelectedRpcEndpointIndex: indexRpc,
}
replacementSelectedRpcEndpointIndex: indexRpc,
}
: undefined,
);
} else {
Expand All @@ -867,8 +867,8 @@ export class NetworkSettings extends PureComponent {
isCustomMainnet
? navigation.navigate('OptinMetrics')
: shouldNetworkSwitchPopToWallet
? navigation.navigate('WalletView')
: navigation.goBack();
? navigation.navigate('WalletView')
: navigation.goBack();
};

/**
Expand Down Expand Up @@ -1534,7 +1534,7 @@ export class NetworkSettings extends PureComponent {

const { networkClientId } =
networkConfigurations?.rpcEndpoints?.[
networkConfigurations.defaultRpcEndpointIndex
networkConfigurations.defaultRpcEndpointIndex
] ?? {};

NetworkController.setActiveNetwork(networkClientId);
Expand Down Expand Up @@ -1950,15 +1950,15 @@ export class NetworkSettings extends PureComponent {
// Conditionally include secondaryText only if rpcName exists
{...(rpcName
? {
secondaryText:
hideKeyFromUrl(rpcUrl) ??
hideKeyFromUrl(
networkConfigurations?.[chainId]?.rpcEndpoints?.[
networkConfigurations?.[chainId]
?.defaultRpcEndpointIndex
]?.url,
),
}
secondaryText:
hideKeyFromUrl(rpcUrl) ??
hideKeyFromUrl(
networkConfigurations?.[chainId]?.rpcEndpoints?.[
networkConfigurations?.[chainId]
?.defaultRpcEndpointIndex
]?.url,
),
}
: {})}
isSelected={false}
withAvatar={false}
Expand Down Expand Up @@ -1993,17 +1993,17 @@ export class NetworkSettings extends PureComponent {

{!isNetworkUiRedesignEnabled()
? warningRpcUrl && (
<View
style={
isNetworkUiRedesignEnabled()
? styles.newWarningContainer
: styles.warningContainer
}
testID={NetworksViewSelectorsIDs.RPC_WARNING_BANNER}
>
<Text style={styles.warningText}>{warningRpcUrl}</Text>
</View>
)
<View
style={
isNetworkUiRedesignEnabled()
? styles.newWarningContainer
: styles.warningContainer
}
testID={NetworksViewSelectorsIDs.RPC_WARNING_BANNER}
>
<Text style={styles.warningText}>{warningRpcUrl}</Text>
</View>
)
: null}

<Text style={styles.label}>
Expand Down Expand Up @@ -2268,10 +2268,12 @@ export class NetworkSettings extends PureComponent {
) : null}

{isNetworkUiRedesignEnabled() &&
showMultiBlockExplorerAddModal.isVisible ? (
showMultiBlockExplorerAddModal.isVisible ? (
<ReusableModal
style={
blockExplorerUrls.length > 0 ? styles.sheet : styles.sheetSmall
blockExplorerUrls.length > 0 || addMode
salimtb marked this conversation as resolved.
Show resolved Hide resolved
? styles.sheet
: styles.sheetSmall
}
onDismiss={this.closeBlockExplorerModal}
shouldGoBack={false}
Expand Down Expand Up @@ -2338,7 +2340,9 @@ export class NetworkSettings extends PureComponent {

{isNetworkUiRedesignEnabled() && showMultiRpcAddModal.isVisible ? (
<ReusableModal
style={rpcUrls.length > 0 ? styles.sheet : styles.sheetSmall}
style={
rpcUrls.length > 0 || addMode ? styles.sheet : styles.sheetSmall
}
onDismiss={this.closeRpcModal}
shouldGoBack={false}
>
Expand Down Expand Up @@ -2478,7 +2482,7 @@ export class NetworkSettings extends PureComponent {
>
<View style={styles.informationWrapper}>
{(isNetworkUiRedesignEnabled() && !shouldShowPopularNetworks) ||
networkTypeOrRpcUrl ? (
networkTypeOrRpcUrl ? (
this.customNetwork()
) : (
<ScrollableTabView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,18 @@ describe('NetworkSettings', () => {
expect(wrapper.state('rpcUrls')[0].name).toBe('New RPC');
});

it('adds add RPC URL through modal and update state when addMode is true', async () => {
wrapper.setState({ addMode: true });

const instance = wrapper.instance();

await instance.onRpcItemAdd('https://new-rpc-url.com', 'New RPC');

expect(wrapper.state('rpcUrls').length).toBe(1);
expect(wrapper.state('rpcUrls')[0].url).toBe('https://new-rpc-url.com');
expect(wrapper.state('rpcUrls')[0].name).toBe('New RPC');
});

it('should correctly add Block Explorer URL through modal and update state', async () => {
const instance = wrapper.instance();

Expand All @@ -828,6 +840,21 @@ describe('NetworkSettings', () => {
);
});

it('adds correctly add Block Explorer URL through modal and update state when addMode is true', async () => {
wrapper.setState({ addMode: true });

const instance = wrapper.instance();

// Open Block Explorer form modal and add a new URL
instance.openAddBlockExplorerForm();
await instance.onBlockExplorerItemAdd('https://new-blockexplorer.com');

expect(wrapper.state('blockExplorerUrls').length).toBe(1);
expect(wrapper.state('blockExplorerUrls')[0]).toBe(
'https://new-blockexplorer.com',
);
});

it('should not add an empty Block Explorer URL and should return early', async () => {
const instance = wrapper.instance();

Expand Down
Loading