Skip to content

Commit

Permalink
Add title for failed
Browse files Browse the repository at this point in the history
refactor code
  • Loading branch information
segun committed Aug 4, 2023
1 parent 316e30c commit 3ec9aa5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
5 changes: 4 additions & 1 deletion app/components/UI/BlockaidBanner/BlockaidBanner.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ export const REASON_DESCRIPTION_I18N_KEY_MAP = Object.freeze({
[Reason.unfairTrade]: 'blockaid_banner.unfair_trade_description',
});

export const SUSPICIOUS_TITLED_REQUESTS = [Reason.rawSignatureFarming];
export const REASON_TITLE_I18N_KEY_MAP: Record<string, string> = Object.freeze({
[Reason.rawSignatureFarming]: 'blockaid_banner.suspicious_request_title',
[Reason.failed]: 'blockaid_banner.failed_title',
});
28 changes: 11 additions & 17 deletions app/components/UI/BlockaidBanner/BlockaidBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,23 @@ import AttributionLink from './AttributionLink';
import {
ATTRIBUTION_LINE_TEST_ID,
REASON_DESCRIPTION_I18N_KEY_MAP,
SUSPICIOUS_TITLED_REQUESTS,
REASON_TITLE_I18N_KEY_MAP,
} from './BlockaidBanner.constants';
import styleSheet from './BlockaidBanner.styles';
import { BlockaidBannerProps, FlagType, Reason } from './BlockaidBanner.types';

const getTitle = (reason: Reason): string => {
if (SUSPICIOUS_TITLED_REQUESTS.indexOf(reason) >= 0) {
return strings('blockaid_banner.suspicious_request_title');
}
return strings('blockaid_banner.deceptive_request_title');
};
const getTitle = (reason: Reason): string =>
strings(
REASON_TITLE_I18N_KEY_MAP[reason] ||
'blockaid_banner.deceptive_request_title',
);

const getTitleDescription = (
reason: Reason,
): { title: string; description: string } => {
const title = getTitle(reason);
const description = strings(
const getDescription = (reason: Reason) =>
strings(
REASON_DESCRIPTION_I18N_KEY_MAP[reason] ||
REASON_DESCRIPTION_I18N_KEY_MAP[Reason.other],
);

return { title, description };
};

const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
const { style, flagType, reason, features, onToggleShowDetails } =
bannerProps;
Expand All @@ -56,12 +49,13 @@ const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
return null;
}

const { title, description } = getTitleDescription(reason);

if (flagType === FlagType.Benign) {
return null;
}

const title = getTitle(reason);
const description = getDescription(reason);

if (flagType === FlagType.Failed) {
return (
<BannerAlert
Expand Down
2 changes: 1 addition & 1 deletion locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"attribution_link_name": "Blockaid",
"blur_farming_description": "If you approve this request, someone can steal your assets listed on Blur.",
"deceptive_request_title": "This is a deceptive request",
"failed": "Request may not be safe",
"failed_title": "Request may not be safe",
"failed_description": "Because of an error, this request was not verified by the security provider. Proceed with caution.",
"malicious_domain_description": "You're interacting with a malicious domain. If you approve this request, you might lose your assets.",
"other_description": "If you approve this request, you might lose your assets.",
Expand Down

0 comments on commit 3ec9aa5

Please sign in to comment.