Skip to content

Commit

Permalink
feat: add buy sell ui flag, include buy sell ui next to multibuy logic
Browse files Browse the repository at this point in the history
  • Loading branch information
beths-ledger committed Apr 22, 2024
1 parent 68e2e47 commit bbe790e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .changeset/few-parents-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ledgerhq/types-live": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

Add buy-sell-ui feature flag to enable progressive roll out of new manifest ID.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import { LiveAppManifest, Loadable } from "@ledgerhq/live-common/platform/types"
import { accountToWalletAPIAccount } from "@ledgerhq/live-common/wallet-api/converters";
import {
DEFAULT_MULTIBUY_APP_ID,
BUY_SELL_UI_APP_ID,
INTERNAL_APP_IDS,
WALLET_API_VERSION,
} from "@ledgerhq/live-common/wallet-api/constants";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";

export type DProps = {
defaultCurrencyId?: string | null;
Expand Down Expand Up @@ -105,7 +107,9 @@ export type ExchangeComponentParams = {

const Exchange = ({ match }: RouteComponentProps<ExchangeComponentParams>) => {
const appId = match?.params?.appId;
const buySellUiFlag = useFeature("buySellUi");
const defaultPlatform = buySellUiFlag?.enabled ? BUY_SELL_UI_APP_ID : DEFAULT_MULTIBUY_APP_ID;

return <LiveAppExchange appId={appId || DEFAULT_MULTIBUY_APP_ID} />;
return <LiveAppExchange appId={appId || defaultPlatform} />;
};
export default Exchange;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import React, { useMemo } from "react";
import { createStackNavigator } from "@react-navigation/stack";
import { useTheme } from "styled-components/native";
import { findCryptoCurrencyByKeyword } from "@ledgerhq/live-common/currencies/index";
import { DEFAULT_MULTIBUY_APP_ID } from "@ledgerhq/live-common/wallet-api/constants";
import {
DEFAULT_MULTIBUY_APP_ID,
BUY_SELL_UI_APP_ID,
} from "@ledgerhq/live-common/wallet-api/constants";
import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { ScreenName } from "~/const";
import { getStackNavigatorConfig } from "~/navigation/navigatorConfig";

Expand All @@ -16,6 +20,8 @@ const Stack = createStackNavigator<ExchangeLiveAppNavigatorParamList>();
const ExchangeBuy = (
_props: StackNavigatorProps<ExchangeLiveAppNavigatorParamList, ScreenName.ExchangeBuy>,
) => {
const buySellUiFlag = useFeature("buySellUi");
const defaultPlatform = buySellUiFlag?.enabled ? BUY_SELL_UI_APP_ID : DEFAULT_MULTIBUY_APP_ID;
return (
<BuyAndSellScreen
{..._props}
Expand All @@ -29,7 +35,7 @@ const ExchangeBuy = (
goToURL: _props.route.params?.goToURL,
lastScreen: _props.route.params?.lastScreen,
mode: "buy",
platform: _props.route.params?.platform || DEFAULT_MULTIBUY_APP_ID,
platform: _props.route.params?.platform || defaultPlatform,
referrer: _props.route.params?.referrer,
},
}}
Expand All @@ -40,6 +46,8 @@ const ExchangeBuy = (
const ExchangeSell = (
_props: StackNavigatorProps<ExchangeLiveAppNavigatorParamList, ScreenName.ExchangeSell>,
) => {
const buySellUiFlag = useFeature("buySellUi");
const defaultPlatform = buySellUiFlag?.enabled ? BUY_SELL_UI_APP_ID : DEFAULT_MULTIBUY_APP_ID;
return (
<BuyAndSellScreen
{..._props}
Expand All @@ -53,7 +61,7 @@ const ExchangeSell = (
goToURL: _props.route.params?.goToURL,
lastScreen: _props.route.params?.lastScreen,
mode: "sell",
platform: _props.route.params?.platform || DEFAULT_MULTIBUY_APP_ID,
platform: _props.route.params?.platform || defaultPlatform,
referrer: _props.route.params?.referrer,
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
} from "@ledgerhq/live-common/platform/react";
import trackingWrapper from "@ledgerhq/live-common/platform/tracking";
import BigNumber from "bignumber.js";
import { DEFAULT_MULTIBUY_APP_ID } from "@ledgerhq/live-common/wallet-api/constants";
import {
DEFAULT_MULTIBUY_APP_ID,
BUY_SELL_UI_APP_ID,
} from "@ledgerhq/live-common/wallet-api/constants";
import { safeGetRefValue } from "@ledgerhq/live-common/wallet-api/react";
import { NavigatorName, ScreenName } from "~/const";
import { broadcastSignedTx } from "~/logic/screenTransactionHooks";
Expand Down Expand Up @@ -508,7 +511,8 @@ export const PlatformAPIWebview = forwardRef<WebviewAPI, WebviewProps>(
tracking.platformLoad(manifest);
}, [manifest, tracking]);

const javaScriptCanOpenWindowsAutomatically = manifest.id === DEFAULT_MULTIBUY_APP_ID;
const javaScriptCanOpenWindowsAutomatically =
manifest.id === DEFAULT_MULTIBUY_APP_ID || manifest.id === BUY_SELL_UI_APP_ID;

return (
<RNWebView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import Config from "react-native-config";
import { WebviewAPI, WebviewProps } from "./types";
import { useWebView } from "./helpers";
import { NetworkError } from "./NetworkError";
import { DEFAULT_MULTIBUY_APP_ID } from "@ledgerhq/live-common/wallet-api/constants";
import {
DEFAULT_MULTIBUY_APP_ID,
BUY_SELL_UI_APP_ID,
} from "@ledgerhq/live-common/wallet-api/constants";
import { INJECTED_JAVASCRIPT } from "./dappInject";
import { NoAccountScreen } from "./NoAccountScreen";

Expand Down Expand Up @@ -36,7 +39,8 @@ export const WalletAPIWebview = forwardRef<WebviewAPI, WebviewProps>(
webviewRef.current?.reload();
};

const javaScriptCanOpenWindowsAutomatically = manifest.id === DEFAULT_MULTIBUY_APP_ID;
const javaScriptCanOpenWindowsAutomatically =
manifest.id === DEFAULT_MULTIBUY_APP_ID || manifest.id === BUY_SELL_UI_APP_ID;

if (!!manifest.dapp && noAccounts) {
return <NoAccountScreen manifest={manifest} currentAccountHistDb={currentAccountHistDb} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { safeGetRefValue } from "@ledgerhq/live-common/wallet-api/react";
import {
DEFAULT_MULTIBUY_APP_ID,
INTERNAL_APP_IDS,
BUY_SELL_UI_APP_ID,
} from "@ledgerhq/live-common/wallet-api/constants";
import { safeUrl } from "@ledgerhq/live-common/wallet-api/helpers";

Expand Down Expand Up @@ -77,7 +78,11 @@ function BackToInternalDomain({
referrer: "isExternal",
},
});
} else if (manifest.id === DEFAULT_MULTIBUY_APP_ID && lastMatchingURL && webviewURL) {
} else if (
(manifest.id === DEFAULT_MULTIBUY_APP_ID || manifest.id === BUY_SELL_UI_APP_ID) &&
lastMatchingURL &&
webviewURL
) {
const currentHostname = new URL(webviewURL).hostname;
const url = new URL(lastMatchingURL);
const urlParams = new URLSearchParams(url.searchParams);
Expand Down
7 changes: 5 additions & 2 deletions apps/ledger-live-mobile/src/navigation/DeeplinksProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
import Config from "react-native-config";
import { useFlipper } from "@react-navigation/devtools";
import { useRemoteLiveAppContext } from "@ledgerhq/live-common/platform/providers/RemoteLiveAppProvider/index";
import { DEFAULT_MULTIBUY_APP_ID } from "@ledgerhq/live-common/wallet-api/constants";
import {
DEFAULT_MULTIBUY_APP_ID,
BUY_SELL_UI_APP_ID,
} from "@ledgerhq/live-common/wallet-api/constants";

import Braze from "@braze/react-native-sdk";
import { LiveAppManifest } from "@ledgerhq/live-common/platform/types";
Expand Down Expand Up @@ -71,7 +74,7 @@ function getProxyURL(url: string) {
// This is to handle links set in the useFromAmountStatusMessage in LLC.
// Also handles a difference in paths between LLD on LLD /platform/:app_id
// but on LLM /discover/:app_id
if (hostname === "platform" && [DEFAULT_MULTIBUY_APP_ID].includes(platform)) {
if (hostname === "platform" && [DEFAULT_MULTIBUY_APP_ID, BUY_SELL_UI_APP_ID].includes(platform)) {
return url.replace("://platform", "://discover");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const DEFAULT_FEATURES: Features = {
postOnboardingAssetsTransfer: DEFAULT_FEATURE,
counterValue: DEFAULT_FEATURE,
mockFeature: DEFAULT_FEATURE,
buySellUi: DEFAULT_FEATURE,
multibuyNavigation: DEFAULT_FEATURE,
ptxServiceCtaExchangeDrawer: DEFAULT_FEATURE,
ptxServiceCtaScreens: DEFAULT_FEATURE,
Expand Down
4 changes: 3 additions & 1 deletion libs/ledger-live-common/src/wallet-api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export const DISCOVER_INITIAL_CATEGORY = "all";

export const DEFAULT_MULTIBUY_APP_ID = "multibuy-v2";

export const INTERNAL_APP_IDS = [DEFAULT_MULTIBUY_APP_ID];
export const BUY_SELL_UI_APP_ID = "buy-sell-ui";

export const INTERNAL_APP_IDS = [DEFAULT_MULTIBUY_APP_ID, BUY_SELL_UI_APP_ID];
2 changes: 2 additions & 0 deletions libs/ledgerjs/packages/types-live/src/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export type Features = CurrencyFeatures & {
deviceInitialApps: Feature_DeviceInitialApps;
buyDeviceFromLive: Feature_BuyDeviceFromLive;
mockFeature: Feature_MockFeature;
buySellUi: Feature_BuySellUi;
multibuyNavigation: Feature_MultibuyNavigation;
referralProgramDesktopSidebar: Feature_ReferralProgramDesktopSidebar;
referralProgramMobile: Feature_ReferralProgramMobile;
Expand Down Expand Up @@ -461,6 +462,7 @@ export type Feature_LldRefreshMarketData = Feature<{

export type Feature_CounterValue = DefaultFeature;
export type Feature_MockFeature = DefaultFeature;
export type Feature_BuySellUi = DefaultFeature;
export type Feature_MultibuyNavigation = DefaultFeature;
export type Feature_DisableNftSend = DefaultFeature;
export type Feature_DisableNftLedgerMarket = DefaultFeature;
Expand Down

0 comments on commit bbe790e

Please sign in to comment.