Skip to content

Commit b29d8c2

Browse files
authored
[LIVE-3341][FEATURE] use navigation for buy sell screen (#923)
* [LIVE-2943] Feat/add back forward buttons to web platform player (#625) * add possibility to go back and forward * use arrow icon * move webview specific callbacks to TopBar * disable nav buttons when nav not possible * Add shouldDisplayNavigation to TopBarConfig * Use webview ref as prop instead of ref current value * add comments for events listened to * small code style changes * Add changeset * use navigation is buy/sell screen * Revert "use navigation is buy/sell screen" This reverts commit 647b892da5763154cc2eae656029bd1fd862c828. * handle Buy Sell live app in exchange screen * add changeset * Revert "[LIVE-2943] Feat/add back forward buttons to web platform player (#625)" This reverts commit 3caf8e1.
1 parent d6634bc commit b29d8c2

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

.changeset/dull-moles-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ledger-live-desktop": minor
3+
---
4+
5+
use navigation for buy sell screen

apps/ledger-live-desktop/src/renderer/Default.jsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useEffect, useRef } from "react";
33
import styled from "styled-components";
44
import { ipcRenderer } from "electron";
55
import { Redirect, Route, Switch, useLocation } from "react-router-dom";
6-
import { FeatureToggle, useFeature } from "@ledgerhq/live-common/featureFlags/index";
6+
import { FeatureToggle } from "@ledgerhq/live-common/featureFlags/index";
77
import TrackAppStart from "~/renderer/components/TrackAppStart";
88
import { BridgeSyncProvider } from "~/renderer/bridge/BridgeSyncContext";
99
import { SyncNewAccounts } from "~/renderer/bridge/SyncNewAccounts";
@@ -142,9 +142,6 @@ export default function Default() {
142142
useDeeplink();
143143
useUSBTroubleshooting();
144144

145-
// PTX smart routing feature flag - buy sell live app flag
146-
const ptxSmartRouting = useFeature("ptxSmartRouting");
147-
148145
useProviders(); // prefetch data from swap providers here
149146

150147
// every time location changes, scroll back up
@@ -218,19 +215,7 @@ export default function Default() {
218215
render={(props: any) => <PlatformApp {...props} />}
219216
/>
220217
<Route path="/lend" render={props => <Lend {...props} />} />
221-
<Route
222-
path="/exchange"
223-
render={(props: any) =>
224-
ptxSmartRouting?.enabled ? (
225-
<PlatformApp
226-
appId={ptxSmartRouting?.params?.liveAppId ?? "multibuy"}
227-
{...props}
228-
/>
229-
) : (
230-
<Exchange {...props} />
231-
)
232-
}
233-
/>
218+
<Route path="/exchange" render={(props: any) => <Exchange />} />
234219
<Route
235220
exact
236221
path="/account/:id/nft-collection"

apps/ledger-live-desktop/src/renderer/screens/exchange/index.jsx

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
// @flow
22

33
import React, { useState } from "react";
4-
import styled from "styled-components";
5-
import { useLocation } from "react-router-dom";
64
import { useTranslation } from "react-i18next";
5+
import { useLocation } from "react-router-dom";
6+
import styled from "styled-components";
77

8+
import { useRampCatalog } from "@ledgerhq/live-common/platform/providers/RampCatalogProvider/index";
9+
import type { RampCatalog } from "@ledgerhq/live-common/platform/providers/RampCatalogProvider/types";
810
import Box from "~/renderer/components/Box";
9-
import type { ThemedComponent } from "~/renderer/styles/StyleProvider";
10-
import TabBar from "~/renderer/components/TabBar";
1111
import Card from "~/renderer/components/Box/Card";
12+
import TabBar from "~/renderer/components/TabBar";
13+
import type { ThemedComponent } from "~/renderer/styles/StyleProvider";
1214
import OnRamp from "./Buy";
13-
import OffRamp from "./Sell";
1415
import { useExchangeProvider } from "./hooks";
15-
import { useRampCatalog } from "@ledgerhq/live-common/platform/providers/RampCatalogProvider/index";
16-
import type { RampCatalog } from "@ledgerhq/live-common/platform/providers/RampCatalogProvider/types";
16+
import OffRamp from "./Sell";
17+
18+
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
19+
import { useRemoteLiveAppManifest } from "@ledgerhq/live-common/platform/providers/RemoteLiveAppProvider/index";
20+
import WebPlatformPlayer from "~/renderer/components/WebPlatformPlayer";
21+
import useTheme from "~/renderer/hooks/useTheme";
1722

1823
const Container: ThemedComponent<{ selectable: boolean, pb: number }> = styled(Box)`
1924
flex: 1;
@@ -47,7 +52,41 @@ type QueryParams = {
4752
defaultTicker?: string,
4853
};
4954

50-
const Exchange = () => {
55+
const DEFAULT_MULTIBUY_APP_ID = "multibuy";
56+
57+
// Exchange (Buy / Sell) as a live app screen
58+
const LiveAppExchange = ({ appId }: { appId: string }) => {
59+
const { state: urlParams } = useLocation();
60+
61+
const manifest = useRemoteLiveAppManifest(appId);
62+
63+
const themeType = useTheme("colors.palette.type");
64+
65+
return (
66+
<Card grow style={{ overflow: "hidden" }}>
67+
{manifest ? (
68+
<WebPlatformPlayer
69+
config={{
70+
topBarConfig: {
71+
shouldDisplayName: false,
72+
shouldDisplayInfo: false,
73+
shouldDisplayClose: false,
74+
shouldDisplayNavigation: true,
75+
},
76+
}}
77+
manifest={manifest}
78+
inputs={{
79+
theme: themeType,
80+
...urlParams,
81+
}}
82+
/>
83+
) : null}
84+
</Card>
85+
);
86+
};
87+
88+
// Legacy native Exchange (Buy / Sell) screen, should be deprecated soonish
89+
const LegacyExchange = () => {
5190
const rampCatalog = useRampCatalog();
5291

5392
const location = useLocation();
@@ -85,4 +124,17 @@ const Exchange = () => {
85124
);
86125
};
87126

127+
const Exchange = () => {
128+
// PTX smart routing feature flag - buy sell live app flag
129+
const ptxSmartRouting = useFeature("ptxSmartRouting");
130+
131+
if (ptxSmartRouting?.enabled) {
132+
return (
133+
<LiveAppExchange appId={ptxSmartRouting?.params?.liveAppId ?? DEFAULT_MULTIBUY_APP_ID} />
134+
);
135+
}
136+
137+
return <LegacyExchange />;
138+
};
139+
88140
export default Exchange;

0 commit comments

Comments
 (0)