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 back button lld card #7772

Merged
merged 3 commits into from
Sep 9, 2024
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
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/src/renderer/Default.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export default function Default() {
<Route path="/" exact render={withSuspense(Dashboard)} />
<Route path="/settings" render={withSuspense(Settings)} />
<Route path="/accounts" render={withSuspense(Accounts)} />
<Route path="/card" render={withSuspense(Card)} />
<Route exact path="/card/:appId?" render={withSuspense(Card)} />
<Redirect from="/manager/reload" to="/manager" />
<Route path="/manager" render={withSuspense(Manager)} />
<Route
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ export const TopBar = ({ manifest, webviewAPIRef, webviewState }: Props) => {
flow: flowName,
});

const pathname = match.path.replace("/:appId?", "");
history.replace({
pathname: "/exchange",
pathname,
search: `?referrer=isExternal`,
state: {
mode: flowName,
Expand All @@ -167,12 +168,19 @@ export const TopBar = ({ manifest, webviewAPIRef, webviewState }: Props) => {
await webview.loadURL(safeUrl);
webview.clearHistory();
}
}, [localStorage, history, webviewAPIRef, webviewState.url]);
}, [localStorage, history, match.path, webviewAPIRef, webviewState.url]);

const getButtonLabel = useCallback(() => {
const lastScreen = localStorage.getItem("last-screen") || "";

return lastScreen === "compare_providers" ? t("common.quote") : manifest.name;
const screenMap: {
[key: string]: string;
} = {
compare_providers: t("common.quote"),
card: t("card.backToCard"),
};

return screenMap[lastScreen] || manifest.name;
}, [localStorage, manifest, t]);

const handleReload = useCallback(() => {
Expand All @@ -192,7 +200,10 @@ export const TopBar = ({ manifest, webviewAPIRef, webviewState }: Props) => {
if (goToURL) {
localStorage.setItem("manifest-id", manifestId);
localStorage.setItem("flow-name", url.searchParams.get("flowName") || "buy");
localStorage.setItem("last-screen", url.searchParams.get("lastScreen") || "");
localStorage.setItem(
"last-screen",
url.searchParams.get("lastScreen") || url.searchParams.get("flowName") || "",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe flowName can take values that are not a valid screen name!

);

history.replace(`${match.url}/${manifestId}?goToURL=${goToURL}`);
}
Expand Down
25 changes: 16 additions & 9 deletions apps/ledger-live-desktop/src/renderer/screens/card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { useLocation } from "react-router-dom";
import { useLocation, RouteComponentProps } from "react-router-dom";
import { useSelector } from "react-redux";
import Card from "~/renderer/components/Box/Card";
import {
Expand All @@ -12,12 +12,14 @@ import useTheme from "~/renderer/hooks/useTheme";
import WebPTXPlayer from "~/renderer/components/WebPTXPlayer";
import { LiveAppManifest } from "@ledgerhq/live-common/platform/types";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { CARD_APP_ID } from "@ledgerhq/live-common/wallet-api/constants";
import { CARD_APP_ID, INTERNAL_APP_IDS } from "@ledgerhq/live-common/wallet-api/constants";
import { useLocalLiveAppManifest } from "@ledgerhq/live-common/wallet-api/LocalLiveAppProvider/index";
import CardPlatformApp from "./CardPlatformApp";

const LiveAppCard = () => {
const { state: urlParams, search } = useLocation();
type CardState = { account?: string } | undefined;

const LiveAppCard = ({ appId }: { appId: string }) => {
const { state: urlParams, search } = useLocation<CardState>();
const searchParams = new URLSearchParams(search);
const locale = useSelector(localeSelector);
const language = useSelector(languageSelector);
Expand All @@ -26,8 +28,8 @@ const LiveAppCard = () => {
const mockManifest: LiveAppManifest | undefined =
process.env.MOCK_REMOTE_LIVE_MANIFEST && JSON.parse(process.env.MOCK_REMOTE_LIVE_MANIFEST)[0];

const localManifest = useLocalLiveAppManifest(CARD_APP_ID);
const remoteManifest = useRemoteLiveAppManifest(CARD_APP_ID);
const localManifest = useLocalLiveAppManifest(appId);
const remoteManifest = useRemoteLiveAppManifest(appId);
const manifest = localManifest || mockManifest || remoteManifest;
const themeType = useTheme().colors.palette.type;

Expand All @@ -36,7 +38,7 @@ const LiveAppCard = () => {
* to ensure the context is reset. last-screen is used to give an external app's webview context
* of the last screen the user was on before navigating to the external app screen.
*/
if (manifest?.id) {
if (manifest?.id && INTERNAL_APP_IDS.includes(manifest.id)) {
const { localStorage } = window;
localStorage.removeItem("last-screen");
localStorage.removeItem("manifest-id");
Expand Down Expand Up @@ -67,10 +69,15 @@ const LiveAppCard = () => {
);
};

const CardDapp = () => {
export type ComponentParams = {
appId?: string;
};

const CardDapp = ({ match }: RouteComponentProps<ComponentParams>) => {
const appId = match?.params?.appId;
const ptxCardFlag = useFeature("ptxCard");
if (ptxCardFlag?.enabled) {
return <LiveAppCard />;
return <LiveAppCard appId={appId || CARD_APP_ID} />;
} else {
return <CardPlatformApp />; // Baanx card
}
Expand Down
3 changes: 3 additions & 0 deletions apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,9 @@
"continue": "Continue"
}
},
"card": {
"backToCard": "all cards"
},
"lend": {
"title": "Lend crypto",
"tabs": {
Expand Down
Loading