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

feat: add locale and ticker query params for buy/sell #7610

Merged
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
6 changes: 6 additions & 0 deletions .changeset/six-numbers-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"ledger-live-desktop": patch
"live-mobile": patch
---

Add locale and ticker query params for buy/sell
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { RouteComponentProps, useLocation } from "react-router-dom";
import { useSelector } from "react-redux";
import { RampCatalog } from "@ledgerhq/live-common/platform/providers/RampCatalogProvider/types";
import Card from "~/renderer/components/Box/Card";
import { developerModeSelector, languageSelector } from "~/renderer/reducers/settings";
import {
counterValueCurrencySelector,
developerModeSelector,
languageSelector,
localeSelector,
} from "~/renderer/reducers/settings";
import { accountsSelector } from "~/renderer/reducers/accounts";
import { useRemoteLiveAppManifest } from "@ledgerhq/live-common/platform/providers/RemoteLiveAppProvider/index";
import useTheme from "~/renderer/hooks/useTheme";
Expand Down Expand Up @@ -34,7 +39,9 @@ type ExchangeState = { account?: string } | undefined;
const LiveAppExchange = ({ appId }: { appId: string }) => {
const { state: urlParams, search } = useLocation<ExchangeState>();
const searchParams = new URLSearchParams(search);
const locale = useSelector(languageSelector);
const lang = useSelector(languageSelector);
const locale = useSelector(localeSelector);
const { ticker: currencyTicker } = useSelector(counterValueCurrencySelector);
const devMode = useSelector(developerModeSelector);
const accounts = useSelector(accountsSelector);

Expand Down Expand Up @@ -96,7 +103,9 @@ const LiveAppExchange = ({ appId }: { appId: string }) => {
inputs={{
theme: themeType,
...customUrlParams,
lang: locale,
lang,
locale,
currencyTicker,
devMode,
...Object.fromEntries(searchParams.entries()),
}}
Expand Down
12 changes: 12 additions & 0 deletions apps/ledger-live-desktop/tests/specs/services/buy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ test("Buy / Sell @smoke", async ({ page }) => {
await liveAppWebview.waitForLoaded();
expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
await expect
.soft(page)
.toHaveScreenshot("buy-app-opened.png", { mask: [page.locator("webview")] });
Expand All @@ -74,6 +76,8 @@ test("Buy / Sell @smoke", async ({ page }) => {
).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
});

await test.step("Navigate to Buy app from asset", async () => {
Expand All @@ -83,6 +87,8 @@ test("Buy / Sell @smoke", async ({ page }) => {

expect(await liveAppWebview.waitForCorrectTextInWebview("theme: dark")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currency: ethereum")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
});
Expand All @@ -98,6 +104,8 @@ test("Buy / Sell @smoke", async ({ page }) => {
await liveAppWebview.waitForCorrectTextInWebview("account: mock:1:bitcoin:true_bitcoin_0:"),
).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: buy")).toBe(true);
});

Expand All @@ -112,6 +120,8 @@ test("Buy / Sell @smoke", async ({ page }) => {
await liveAppWebview.waitForCorrectTextInWebview("account: mock:1:bitcoin:true_bitcoin_0:"),
).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: en")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("mode: sell")).toBe(true);
});

Expand All @@ -123,5 +133,7 @@ test("Buy / Sell @smoke", async ({ page }) => {

expect(await liveAppWebview.waitForCorrectTextInWebview("theme: light")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("lang: fr")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("locale: en-US")).toBe(true);
expect(await liveAppWebview.waitForCorrectTextInWebview("currencyTicker: USD")).toBe(true);
});
});
10 changes: 7 additions & 3 deletions apps/ledger-live-mobile/src/screens/PTX/BuyAndSell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { useTheme } from "styled-components/native";
import { Flex, InfiniteLoader } from "@ledgerhq/native-ui";
import TrackScreen from "~/analytics/TrackScreen";
import GenericErrorView from "~/components/GenericErrorView";
import { useLocale } from "~/context/Locale";
import { WebPTXPlayer } from "~/components/WebPTXPlayer";
import { ExchangeNavigatorParamList } from "~/components/RootNavigator/types/ExchangeNavigator";
import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers";
Expand All @@ -23,6 +22,8 @@ import { useInternalAppIds } from "@ledgerhq/live-common/hooks/useInternalAppIds
import { INTERNAL_APP_IDS, WALLET_API_VERSION } from "@ledgerhq/live-common/wallet-api/constants";
import { walletSelector } from "~/reducers/wallet";
import useEnv from "@ledgerhq/live-common/hooks/useEnv";
import { counterValueCurrencySelector } from "~/reducers/settings";
import { useSettings } from "~/hooks";

export type Props = StackNavigatorProps<
ExchangeNavigatorParamList,
Expand All @@ -42,7 +43,8 @@ export function BuyAndSellScreen({ route }: Props) {
const localManifest = useLocalLiveAppManifest(platform);
const remoteManifest = useRemoteLiveAppManifest(platform);
const { state: remoteLiveAppState } = useRemoteLiveAppContext();
const { locale } = useLocale();
const { language, locale } = useSettings();
const { ticker: currencyTicker } = useSelector(counterValueCurrencySelector);
const manifest = localManifest || remoteManifest;
const internalAppIds = useInternalAppIds() || INTERNAL_APP_IDS;
const walletState = useSelector(walletSelector);
Expand Down Expand Up @@ -95,7 +97,9 @@ export function BuyAndSellScreen({ route }: Props) {
manifest={manifest}
inputs={{
theme,
lang: locale,
lang: language,
locale,
currencyTicker,
devMode,
...customParams,
...Object.fromEntries(searchParams.entries()),
Expand Down
Loading