From a784199e7f0712a6a1bb9669e07286a2a3e05cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Vytick=20Vytrhl=C3=ADk?= Date: Fri, 13 Dec 2024 14:26:42 +0100 Subject: [PATCH] feat(suite-native): redact graph errors --- suite-native/graph/src/hooks.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/suite-native/graph/src/hooks.ts b/suite-native/graph/src/hooks.ts index b3bae195b17..ad2f51922f7 100644 --- a/suite-native/graph/src/hooks.ts +++ b/suite-native/graph/src/hooks.ts @@ -68,8 +68,31 @@ const useWatchTimeframeChangeForAnalytics = ( }, [timeframeHours, symbol, isFirstRender]); }; +const redactAfterSubstring = (string: string, substring: string) => { + const index = string.indexOf(substring); + + if (index !== -1) { + return string.slice(0, index + substring.length) + ' redacted'; + } + + return string; +}; + +const redact = (string: string) => { + const redactAfterSubstringArray = [ + 'Account not found:', + 'Unable to fetch fiat rates for defined timestamps. ', + ]; + let msg = string; + redactAfterSubstringArray.map(substring => { + msg = redactAfterSubstring(msg, substring); + }); + + return msg; +}; + const checkAndReportGraphError = (error: string | null) => { - if (error) captureException(error); + if (error) captureException(redact(error)); }; export const useGraphForSingleAccount = ({