Skip to content

Commit a506724

Browse files
feat(LIVE-21099): Add deeplink for earn deposit screen redirection
1 parent 7e26552 commit a506724

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

.changeset/funny-rivers-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"live-mobile": minor
3+
---
4+
5+
Add new deeplink for earn deposit screen on llm

apps/ledger-live-mobile/src/components/RootNavigator/EarnLiveAppNavigator.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@ const Earn = (props: NavigationProps) => {
5050

5151
function deeplinkRouting() {
5252
switch (paramAction) {
53+
case "deposit": {
54+
navigation.navigate(NavigatorName.Base, {
55+
screen: NavigatorName.Earn,
56+
params: {
57+
screen: ScreenName.Earn,
58+
params: {
59+
intent: "deposit",
60+
cryptoAssetId: props.route.params?.cryptoAssetId,
61+
accountId: props.route.params?.accountId,
62+
},
63+
},
64+
});
65+
break;
66+
}
5367
case "stake":
5468
navigation.navigate(NavigatorName.StakeFlow, {
5569
screen: ScreenName.Stake,

apps/ledger-live-mobile/src/components/RootNavigator/types/EarnLiveAppNavigator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { ScreenName } from "~/const";
44
export type EarnLiveAppNavigatorParamList = {
55
[ScreenName.Earn]: {
66
accountId?: string;
7-
action?: "get-funds" | "stake" | "stake-account" | "info-modal" | "menu-modal" | "go-back";
7+
action?: "get-funds" | "stake" | "stake-account" | "info-modal" | "menu-modal" | "go-back" | "deposit";
88
currencyId?: string;
99
learnMore?: string;
1010
message?: string;

apps/ledger-live-mobile/src/navigation/DeeplinksProvider.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
validateEarnMenuModal,
4040
logSecurityEvent,
4141
EarnDeeplinkAction,
42+
validateEarnDepositScreen,
4243
} from "./deeplinks/validation";
4344
import { viewNamePredicate } from "~/datadog";
4445

@@ -670,6 +671,19 @@ export const DeeplinksProvider = ({
670671
return;
671672
}
672673
}
674+
if (pathname === "/deposit") {
675+
const validatedModal = validateEarnDepositScreen(
676+
searchParams.get("cryptoAssetId") || undefined,
677+
searchParams.get("accountId") || undefined,
678+
);
679+
// Handle deposit deeplink on earnLiveAppNavigator
680+
// Creating own search params for deposit deeplink
681+
url.pathname = "";
682+
url.searchParams.set("action", "deposit");
683+
url.searchParams.set("cryptoAssetId", validatedModal.cryptoAssetId ?? "");
684+
url.searchParams.set("accountId", validatedModal.accountId ?? "");
685+
return getStateFromPath(url.href?.split("://")[1], config);
686+
}
673687
}
674688
if ((hostname === "discover" || hostname === "recover") && platform) {
675689
if (!hasCompletedOnboarding && !platform.startsWith("protect")) return undefined;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { validateEarnDepositScreen } from "../validation";
2+
3+
describe("validateEarnDepositScreen", () => {
4+
it("should validate the deposit screen", () => {
5+
const validated = validateEarnDepositScreen("cryptoAssetId", "accountId");
6+
expect(validated).toEqual({ cryptoAssetId: "cryptoAssetId", accountId: "accountId" });
7+
});
8+
9+
it("should sanitize dangerous characters and protocols", () => {
10+
const validated = validateEarnDepositScreen(
11+
" <script>alert(1)</script>btc ",
12+
" javascript:mystery ",
13+
);
14+
expect(validated).toEqual({ cryptoAssetId: "btc", accountId: "mystery" });
15+
});
16+
17+
it("should truncate values longer than 100 characters", () => {
18+
const long = "a".repeat(150);
19+
const validated = validateEarnDepositScreen(long, long);
20+
expect(validated.cryptoAssetId?.length).toBe(100);
21+
expect(validated.accountId?.length).toBe(100);
22+
});
23+
});

apps/ledger-live-mobile/src/navigation/deeplinks/validation.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export interface ValidatedEarnInfoModal {
4141
learnMoreLink: string;
4242
}
4343

44+
export interface ValidatedEarnDepositScreen {
45+
cryptoAssetId?: string;
46+
accountId?: string;
47+
}
48+
4449
export interface ValidatedEarnMenuModal {
4550
title: string;
4651
options: Array<{
@@ -274,6 +279,16 @@ export function validateEarnInfoModal(
274279
};
275280
}
276281

282+
export function validateEarnDepositScreen(
283+
cryptoAssetId?: string,
284+
accountId?: string,
285+
): ValidatedEarnDepositScreen {
286+
return {
287+
cryptoAssetId: sanitizeString(cryptoAssetId || "", MAX_TITLE_LENGTH),
288+
accountId: sanitizeString(accountId || "", MAX_TITLE_LENGTH),
289+
};
290+
}
291+
277292
/**
278293
* Validates earn menu modal parameters
279294
*/

0 commit comments

Comments
 (0)