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

chore(suite-native): redact more graph error messages #16122

Merged
merged 1 commit into from
Jan 6, 2025
Merged
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
33 changes: 23 additions & 10 deletions suite-native/graph/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,37 @@ const useWatchTimeframeChangeForAnalytics = (
}, [timeframeHours, symbol, isFirstRender]);
};

const redactAfterSubstring = (string: string, substring: string) => {
const index = string.indexOf(substring);
const redactBetweenSubstrings = (string: string, substring1: string, substring2?: string) => {
const start = string.indexOf(substring1);
const end = substring2 ? string.indexOf(substring2) : -1;

if (start !== -1) {
const str = string.slice(0, start + substring1.length) + ' redacted';
if (end !== -1 && end > start + substring1.length) {
return str + ' ' + string.slice(end);
}

if (index !== -1) {
return string.slice(0, index + substring.length) + ' redacted';
return str;
}

return string;
};

// this array defines start and end substrings for redacting using redact()
const redactSubstringsArray: { start: string; end?: string }[] = [
{ start: 'Account not found:' },
{ start: 'Unable to fetch fiat rates for defined timestamps. ' },
{ start: 'Aborted by timeout -' },
{
start: 'getTransaction ',
end: 'not found (transaction indexing still in progress)',
},
];

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);
redactSubstringsArray.map(a => {
msg = redactBetweenSubstrings(msg, a.start, a.end);
});

return msg;
Expand Down
Loading