|
1 | 1 | // @flow
|
2 | 2 |
|
3 | 3 | import React, { useState } from "react";
|
4 |
| -import styled from "styled-components"; |
5 |
| -import { useLocation } from "react-router-dom"; |
6 | 4 | import { useTranslation } from "react-i18next";
|
| 5 | +import { useLocation } from "react-router-dom"; |
| 6 | +import styled from "styled-components"; |
7 | 7 |
|
| 8 | +import { useRampCatalog } from "@ledgerhq/live-common/platform/providers/RampCatalogProvider/index"; |
| 9 | +import type { RampCatalog } from "@ledgerhq/live-common/platform/providers/RampCatalogProvider/types"; |
8 | 10 | import Box from "~/renderer/components/Box";
|
9 |
| -import type { ThemedComponent } from "~/renderer/styles/StyleProvider"; |
10 |
| -import TabBar from "~/renderer/components/TabBar"; |
11 | 11 | import Card from "~/renderer/components/Box/Card";
|
| 12 | +import TabBar from "~/renderer/components/TabBar"; |
| 13 | +import type { ThemedComponent } from "~/renderer/styles/StyleProvider"; |
12 | 14 | import OnRamp from "./Buy";
|
13 |
| -import OffRamp from "./Sell"; |
14 | 15 | 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"; |
17 | 22 |
|
18 | 23 | const Container: ThemedComponent<{ selectable: boolean, pb: number }> = styled(Box)`
|
19 | 24 | flex: 1;
|
@@ -47,7 +52,41 @@ type QueryParams = {
|
47 | 52 | defaultTicker?: string,
|
48 | 53 | };
|
49 | 54 |
|
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 = () => { |
51 | 90 | const rampCatalog = useRampCatalog();
|
52 | 91 |
|
53 | 92 | const location = useLocation();
|
@@ -85,4 +124,17 @@ const Exchange = () => {
|
85 | 124 | );
|
86 | 125 | };
|
87 | 126 |
|
| 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 | + |
88 | 140 | export default Exchange;
|
0 commit comments