Skip to content

Commit

Permalink
fix(llm): ledger sync navigation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrellard-ledger committed Sep 5, 2024
1 parent 5f88c36 commit 68a4b09
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-ads-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": patch
---

LLM - Ledger sync small navigation fixes
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ManageInstancesProcess } from "./screens/ManageInstances/ManageInstance
import { WalletSyncManageInstanceDeletionSuccess } from "./screens/ManageInstances/DeletionSuccess";
import { LedgerSyncDeepLinkHandler } from "./screens/LedgerSyncDeepLinkHandler";
import { NavigationHeaderCloseButton } from "~/components/NavigationHeaderCloseButton";
import { useClose } from "./hooks/useClose";

const Stack = createStackNavigator<WalletSyncNavigatorStackParamList>();

Expand All @@ -24,6 +25,7 @@ export default function WalletSyncNavigator() {
const stackNavConfig = useMemo(() => getStackNavigatorConfig(colors), [colors]);
const { t } = useTranslation();
useInitMemberCredentials();
const close = useClose();

return (
<Stack.Navigator screenOptions={stackNavConfig}>
Expand All @@ -49,7 +51,7 @@ export default function WalletSyncNavigator() {
options={{
title: "",
headerLeft: () => null,
headerRight: () => <NavigationHeaderCloseButton />,
headerRight: () => <NavigationHeaderCloseButton onPress={close} />,
}}
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useNavigation } from "@react-navigation/native";
import { useDispatch, useSelector } from "react-redux";
import { setFromLedgerSyncOnboarding } from "~/actions/settings";
import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator";
import {
RootNavigationComposite,
StackNavigatorNavigation,
} from "~/components/RootNavigator/types/helpers";
import { NavigatorName } from "~/const";
import { isFromLedgerSyncOnboardingSelector } from "~/reducers/settings";

export function useClose() {
const navigationOnbarding =
useNavigation<RootNavigationComposite<StackNavigatorNavigation<BaseNavigatorStackParamList>>>();
const isFromLedgerSyncOnboarding = useSelector(isFromLedgerSyncOnboardingSelector);
const dispatch = useDispatch();

const close = () => {
if (isFromLedgerSyncOnboarding) {
dispatch(setFromLedgerSyncOnboarding(false));
}
navigationOnbarding.replace(NavigatorName.Base, {
screen: NavigatorName.Main,
});
};

return close;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import { useMutation } from "@tanstack/react-query";
import { QueryKey } from "./type.hooks";
import { useCloudSyncSDK } from "./useWatchWalletSync";
import { walletSyncUpdate } from "@ledgerhq/live-wallet/store";
import { useCurrentStep } from "./useCurrentStep";
import { Steps } from "../types/Activation";

export function useDestroyTrustchain() {
const dispatch = useDispatch();
const cloudSyncSDK = useCloudSyncSDK();
const sdk = useTrustchainSdk();
const trustchain = useSelector(trustchainSelector);
const memberCredentials = useSelector(memberCredentialsSelector);
const { setCurrentStep } = useCurrentStep();

const deleteMutation = useMutation({
mutationFn: async () => {
Expand All @@ -29,6 +32,7 @@ export function useDestroyTrustchain() {
onSuccess: () => {
dispatch(resetTrustchainStore());
dispatch(walletSyncUpdate(null, 0));
setCurrentStep(Steps.Activation);
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { ScreenName } from "~/const";
import { StackNavigatorNavigation } from "~/components/RootNavigator/types/helpers";
import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/types/WalletSyncNavigator";
import { DrawerProps, SceneKind, useFollowInstructionDrawer } from "./useFollowInstructionDrawer";
import { useCurrentStep } from "./useCurrentStep";
import { Steps } from "../types/Activation";

type Props = {
device: Device | null;
Expand Down Expand Up @@ -72,7 +74,7 @@ export function useRemoveMember({ device, member }: Props): DrawerProps {
}
}
},
[setScene, device, memberCredentials, sdk, transitionToNextScreen, trustchain],
[device, trustchain, memberCredentials, sdk, transitionToNextScreen, setScene],
);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/ty
import { NavigatorName, ScreenName } from "~/const";
import { useDispatch, useSelector } from "react-redux";
import { isFromLedgerSyncOnboardingSelector } from "~/reducers/settings";
import { useNavigation } from "@react-navigation/native";
import { BaseNavigatorStackParamList } from "~/components/RootNavigator/types/BaseNavigator";
import { setFromLedgerSyncOnboarding } from "~/actions/settings";
import { AnalyticsButton, AnalyticsFlow, AnalyticsPage } from "../../hooks/useLedgerSyncAnalytics";
import { track } from "~/analytics";
import { setLedgerSyncActivateDrawer } from "~/actions/walletSync";
import { Steps } from "../../types/Activation";
import { useCurrentStep } from "../../hooks/useCurrentStep";
import { useClose } from "../../hooks/useClose";

type Props = BaseComposite<
StackNavigatorProps<WalletSyncNavigatorStackParamList, ScreenName.WalletSyncSuccess>
Expand All @@ -35,10 +34,9 @@ export function ActivationSuccess({ navigation, route }: Props) {
const dispatch = useDispatch();
const { setCurrentStep } = useCurrentStep();

const navigationOnbarding =
useNavigation<RootNavigationComposite<StackNavigatorNavigation<BaseNavigatorStackParamList>>>();
const close = useClose();

function syncAnother(): void {
function onSyncAnother(): void {
track("button_clicked", {
button: AnalyticsButton.SyncWithAnotherLedgerLive,
page,
Expand All @@ -54,22 +52,13 @@ export function ActivationSuccess({ navigation, route }: Props) {
dispatch(setLedgerSyncActivateDrawer(true));
}

function close(): void {
function onClose(): void {
track("button_clicked", {
button: AnalyticsButton.Close,
page,
flow: AnalyticsFlow.LedgerSync,
});
if (isFromLedgerSyncOnboarding) {
dispatch(setFromLedgerSyncOnboarding(false));
navigationOnbarding.navigate(NavigatorName.Base, {
screen: NavigatorName.Main,
});
} else {
navigation.navigate(NavigatorName.Settings, {
screen: ScreenName.GeneralSettings,
});
}
close();
}

return (
Expand All @@ -78,11 +67,11 @@ export function ActivationSuccess({ navigation, route }: Props) {
desc={t(desc)}
mainButton={{
label: t("walletSync.success.syncAnother"),
onPress: syncAnother,
onPress: onSyncAnother,
}}
secondaryButton={{
label: t("walletSync.success.close"),
onPress: close,
onPress: onClose,
}}
analyticsPage={page}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useAppDeviceAction } from "~/hooks/deviceActions";
import { AppResult } from "@ledgerhq/live-common/hw/actions/app";
import { WalletSyncNavigatorStackParamList } from "~/components/RootNavigator/types/WalletSyncNavigator";
import { TRUSTCHAIN_APP_NAME } from "@ledgerhq/hw-trustchain";
import { SafeAreaView } from "react-native-safe-area-context";

type NavigationProps = BaseComposite<
StackNavigatorProps<
Expand Down Expand Up @@ -100,7 +101,7 @@ const WalletSyncActivationDeviceSelection: React.FC<ChooseDeviceProps> = ({
if (!isFocused) return null;

return (
<>
<SafeAreaView edges={["top", "left", "right"]} style={{ flex: 1 }}>
<TrackScreen category="Manager" name="ChooseDevice" />
{!isHeaderOverridden ? (
<Flex px={16} pb={8}>
Expand Down Expand Up @@ -128,7 +129,7 @@ const WalletSyncActivationDeviceSelection: React.FC<ChooseDeviceProps> = ({
request={request}
onError={onError}
/>
</>
</SafeAreaView>
);
};

Expand Down

0 comments on commit 68a4b09

Please sign in to comment.