File tree Expand file tree Collapse file tree 6 files changed +72
-1
lines changed
apps/ledger-live-mobile/src Expand file tree Collapse file tree 6 files changed +72
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " live-mobile " : minor
3
+ ---
4
+
5
+ Add new deeplink for earn deposit screen on llm
Original file line number Diff line number Diff line change @@ -50,6 +50,20 @@ const Earn = (props: NavigationProps) => {
50
50
51
51
function deeplinkRouting ( ) {
52
52
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
+ }
53
67
case "stake" :
54
68
navigation . navigate ( NavigatorName . StakeFlow , {
55
69
screen : ScreenName . Stake ,
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { ScreenName } from "~/const";
4
4
export type EarnLiveAppNavigatorParamList = {
5
5
[ ScreenName . Earn ] : {
6
6
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" ;
8
8
currencyId ?: string ;
9
9
learnMore ?: string ;
10
10
message ?: string ;
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ import {
39
39
validateEarnMenuModal ,
40
40
logSecurityEvent ,
41
41
EarnDeeplinkAction ,
42
+ validateEarnDepositScreen ,
42
43
} from "./deeplinks/validation" ;
43
44
import { viewNamePredicate } from "~/datadog" ;
44
45
@@ -670,6 +671,19 @@ export const DeeplinksProvider = ({
670
671
return ;
671
672
}
672
673
}
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
+ }
673
687
}
674
688
if ( ( hostname === "discover" || hostname === "recover" ) && platform ) {
675
689
if ( ! hasCompletedOnboarding && ! platform . startsWith ( "protect" ) ) return undefined ;
Original file line number Diff line number Diff line change
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
+ } ) ;
Original file line number Diff line number Diff line change @@ -41,6 +41,11 @@ export interface ValidatedEarnInfoModal {
41
41
learnMoreLink : string ;
42
42
}
43
43
44
+ export interface ValidatedEarnDepositScreen {
45
+ cryptoAssetId ?: string ;
46
+ accountId ?: string ;
47
+ }
48
+
44
49
export interface ValidatedEarnMenuModal {
45
50
title : string ;
46
51
options : Array < {
@@ -274,6 +279,16 @@ export function validateEarnInfoModal(
274
279
} ;
275
280
}
276
281
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
+
277
292
/**
278
293
* Validates earn menu modal parameters
279
294
*/
You can’t perform that action at this time.
0 commit comments