Skip to content

Commit

Permalink
fix(stax): stax image loader only allow one error page in navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
ak-ledger committed Nov 28, 2023
1 parent 134cb77 commit 5e7b558
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Step0Welcome from "../../screens/CustomImage/Step0Welcome";
import PreviewPreEdit from "../../screens/CustomImage/PreviewPreEdit";
import PreviewPostEdit from "../../screens/CustomImage/PreviewPostEdit";
import NFTGallerySelector from "../../screens/CustomImage/NFTGallerySelector";
import { NavigationHeaderBackButton } from "../NavigationHeaderBackButton";
import { CustomImageNavigatorParamList } from "./types/CustomImageNavigator";

export default function CustomImageNavigator() {
Expand Down Expand Up @@ -48,11 +47,11 @@ export default function CustomImageNavigator() {
<Stack.Screen
name={ScreenName.CustomImageErrorScreen}
component={ErrorScreen}
options={({ navigation }) => ({
options={{
title: "",
headerLeft: () => <NavigationHeaderBackButton onPress={() => navigation.popToTop()} />,
headerLeft: undefined,
gestureEnabled: false,
})}
}}
/>
<Stack.Screen
name={ScreenName.CustomImagePreviewPreEdit}
Expand Down
24 changes: 22 additions & 2 deletions apps/ledger-live-mobile/src/screens/CustomImage/ErrorScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Flex } from "@ledgerhq/native-ui";
import React, { useCallback, useState } from "react";
import React, { useCallback, useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { SafeAreaView } from "react-native-safe-area-context";
import styled from "styled-components/native";
Expand All @@ -25,11 +25,31 @@ const buttonClickedEventProperties = {
button: "upload another image",
};

const ErrorScreen = ({ route }: NavigationProps) => {
const ErrorScreen = ({ route, navigation }: NavigationProps) => {
const [isModalOpened, setIsModalOpened] = useState(false);
const { params } = route;
const { error, device } = params;

// Only keep 1 instance of error page in the navigation
useEffect(() => {
const navigationState = navigation.getState();
const { index, routes } = navigationState;
const firstErrorPageIndex = routes.findIndex(
(route: { name: string }, id: number) =>
route.name === ScreenName.CustomImageErrorScreen && index !== id,
);

if (firstErrorPageIndex !== -1) {
const filteredRoutes = routes.filter((route, id) => id !== firstErrorPageIndex);

navigation.reset({
...navigationState,
index: filteredRoutes.length - 1,
routes: filteredRoutes,
});
}
}, [navigation]);

const { t } = useTranslation();

const closeModal = useCallback(() => {
Expand Down

0 comments on commit 5e7b558

Please sign in to comment.