Skip to content

Commit

Permalink
fix: dix back button lld card
Browse files Browse the repository at this point in the history
  • Loading branch information
sarneijim committed Sep 7, 2024
1 parent f00f598 commit eccd275
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
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,17 @@ 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 = {
compare_providers: t("common.quote"),
card: t("card.backToCard"),
};

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

const handleReload = useCallback(() => {
Expand Down
21 changes: 13 additions & 8 deletions apps/ledger-live-desktop/src/renderer/screens/card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ 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();
const LiveAppCard = ({ appId }: { appId: string }) => {
const { state: urlParams, search } = useLocation<ExchangeState>();
const searchParams = new URLSearchParams(search);
const locale = useSelector(localeSelector);
const language = useSelector(languageSelector);
Expand All @@ -26,8 +26,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 +36,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 +67,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

0 comments on commit eccd275

Please sign in to comment.