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 non regression tests #11768

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions app/components/UI/ReusableModal/ReusableModal.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ export interface ReusableModalProps extends ViewProps {
* @default true
*/
isInteractable?: boolean;

/**
* Determines whether the navigation should revert to the previous path when the modal is closed.
* If set to `true`, closing the modal will trigger the navigation to go back to the previous screen or route.
* If set to `false`, the navigation will remain on the current path when the modal is closed.
* @default true
*/
shouldGoBack?: boolean;
}

export type ReusableModalPostCallback = () => void;
Expand Down
18 changes: 15 additions & 3 deletions app/components/UI/ReusableModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,17 @@ import {
export type { ReusableModalRef } from './ReusableModal.types';

const ReusableModal = forwardRef<ReusableModalRef, ReusableModalProps>(
({ children, onDismiss, isInteractable = true, style, ...props }, ref) => {
(
{
children,
onDismiss,
isInteractable = true,
shouldGoBack = true,
style,
...props
},
ref,
) => {
const postCallback = useRef<ReusableModalPostCallback>();
const { height: screenHeight } = useWindowDimensions();
const { styles } = useStyles(styleSheet, {});
Expand All @@ -66,10 +76,12 @@ const ReusableModal = forwardRef<ReusableModalRef, ReusableModalProps>(

const onHidden = useCallback(() => {
// Sheet is automatically unmounted from the navigation stack.
navigation.goBack();
if (shouldGoBack) {
navigation.goBack();
}
onDismiss?.(!!postCallback.current);
postCallback.current?.();
}, [navigation, onDismiss]);
}, [navigation, onDismiss, shouldGoBack]);

const gestureHandler = useAnimatedGestureHandler<
PanGestureHandlerGestureEvent,
Expand Down
130 changes: 70 additions & 60 deletions app/components/Views/NetworkSelector/NetworkSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,15 @@ const NetworkSelector = () => {
networkName: '',
});

const [showNetworkMenuModal, setNetworkMenuModal] = useState({
const [showNetworkMenuModal, setNetworkMenuModal] = useState<{
isVisible: boolean;
chainId: `0x${string}`;
displayEdit: boolean;
networkTypeOrRpcUrl: string;
isReadOnly: boolean;
}>({
isVisible: false,
chainId: '',
chainId: '0x1',
displayEdit: false,
networkTypeOrRpcUrl: '',
isReadOnly: false,
Expand Down Expand Up @@ -200,8 +206,15 @@ const NetworkSelector = () => {

// Set the active network
NetworkController.setActiveNetwork(clientId);
// Redirect to wallet page
navigate(Routes.WALLET.HOME, {
screen: Routes.WALLET.TAB_STACK_FLOW,
params: {
screen: Routes.WALLET_VIEW,
},
});
},
[networkConfigurations],
[networkConfigurations, navigate],
);

const [showMultiRpcSelectModal, setShowMultiRpcSelectModal] = useState<{
Expand All @@ -220,54 +233,6 @@ const NetworkSelector = () => {

const deleteModalSheetRef = useRef<BottomSheetRef>(null);

// The only possible value types are mainnet, linea-mainnet, sepolia and linea-sepolia
const onNetworkChange = (type: InfuraNetworkType) => {
const {
NetworkController,
CurrencyRateController,
AccountTrackerController,
SelectedNetworkController,
} = Engine.context;

if (domainIsConnectedDapp && process.env.MULTICHAIN_V1) {
SelectedNetworkController.setNetworkClientIdForDomain(origin, type);
} else {
let ticker = type;
if (type === LINEA_SEPOLIA) {
ticker = TESTNET_TICKER_SYMBOLS.LINEA_SEPOLIA as InfuraNetworkType;
}
if (type === SEPOLIA) {
ticker = TESTNET_TICKER_SYMBOLS.SEPOLIA as InfuraNetworkType;
}

const networkConfiguration =
NetworkController.getNetworkConfigurationByChainId(
BUILT_IN_NETWORKS[type].chainId,
);

const clientId =
networkConfiguration?.rpcEndpoints[
networkConfiguration.defaultRpcEndpointIndex
].networkClientId ?? type;

CurrencyRateController.updateExchangeRate(ticker);
NetworkController.setActiveNetwork(clientId);
AccountTrackerController.refresh();

setTimeout(async () => {
await updateIncomingTransactions();
}, 1000);
}

sheetRef.current?.onCloseBottomSheet();

trackEvent(MetaMetricsEvents.NETWORK_SWITCHED, {
chain_id: getDecimalChainId(selectedChainId),
from_network: selectedNetworkName,
to_network: type,
});
};

const onSetRpcTarget = async (networkConfiguration: NetworkConfiguration) => {
const {
CurrencyRateController,
Expand Down Expand Up @@ -343,7 +308,7 @@ const NetworkSelector = () => {

const closeModal = useCallback(() => {
setNetworkMenuModal(() => ({
chainId: '',
chainId: '0x1',
isVisible: false,
displayEdit: false,
networkTypeOrRpcUrl: '',
Expand Down Expand Up @@ -384,6 +349,55 @@ const NetworkSelector = () => {
Linking.openURL(strings('networks.learn_more_url'));
};

// The only possible value types are mainnet, linea-mainnet, sepolia and linea-sepolia
const onNetworkChange = (type: InfuraNetworkType) => {
const {
NetworkController,
CurrencyRateController,
AccountTrackerController,
SelectedNetworkController,
} = Engine.context;

if (domainIsConnectedDapp && process.env.MULTICHAIN_V1) {
SelectedNetworkController.setNetworkClientIdForDomain(origin, type);
} else {
let ticker = type;
if (type === LINEA_SEPOLIA) {
ticker = TESTNET_TICKER_SYMBOLS.LINEA_SEPOLIA as InfuraNetworkType;
}
if (type === SEPOLIA) {
ticker = TESTNET_TICKER_SYMBOLS.SEPOLIA as InfuraNetworkType;
}

const networkConfiguration =
NetworkController.getNetworkConfigurationByChainId(
BUILT_IN_NETWORKS[type].chainId,
);

const clientId =
networkConfiguration?.rpcEndpoints[
networkConfiguration.defaultRpcEndpointIndex
].networkClientId ?? type;

CurrencyRateController.updateExchangeRate(ticker);
NetworkController.setActiveNetwork(clientId);
closeRpcModal();
AccountTrackerController.refresh();

setTimeout(async () => {
await updateIncomingTransactions();
}, 1000);
}

sheetRef.current?.onCloseBottomSheet();

trackEvent(MetaMetricsEvents.NETWORK_SWITCHED, {
chain_id: getDecimalChainId(selectedChainId),
from_network: selectedNetworkName,
to_network: type,
});
};

const filterNetworksByName = (
networks: ExtendedNetwork[],
networkName: string,
Expand Down Expand Up @@ -632,9 +646,7 @@ const NetworkSelector = () => {
>;
const { name, imageSource, chainId } = TypedNetworks[networkType];

const networkConfiguration = Object.values(networkConfigurations).find(
({ chainId: networkId }) => networkId === chainId,
);
const networkConfiguration = networkConfigurations[chainId];

const rpcUrl =
networkConfiguration?.rpcEndpoints?.[
Expand Down Expand Up @@ -794,10 +806,8 @@ const NetworkSelector = () => {
setSearchString('');
};

const removeRpcUrl = (chainId: string) => {
const networkConfiguration = Object.values(networkConfigurations).find(
(config) => config.chainId === chainId,
);
const removeRpcUrl = (chainId: `0x${string}`) => {
const networkConfiguration = networkConfigurations[chainId];

if (!networkConfiguration) {
throw new Error(`Unable to find network with chain id ${chainId}`);
Expand Down Expand Up @@ -1020,7 +1030,7 @@ const NetworkSelector = () => {
actionTitle={strings('app_settings.delete')}
iconName={IconName.Trash}
onPress={() => removeRpcUrl(showNetworkMenuModal.chainId)}
testID={`delete-network-button-${showNetworkMenuModal.chainId}`}
testID={NetworkListModalSelectorsIDs.DELETE_NETWORK}
/>
) : null}
</View>
Expand Down
Loading
Loading