Skip to content

Commit

Permalink
BlockaidBannerAlert: update tkeys based on reason
Browse files Browse the repository at this point in the history
  • Loading branch information
digiwand committed Aug 3, 2023
1 parent 6fea522 commit ba39516
Showing 1 changed file with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const REASON_TO_DESCRIPTION_TKEY = Object.freeze({

[BlockaidReason.blurFarming]: 'blockaidDescriptionBlurFarming',

[BlockaidReason.failed]: 'blockaidDescriptionFailed',

[BlockaidReason.seaportFarming]: 'blockaidDescriptionSeaportFarming',

[BlockaidReason.maliciousDomain]: 'blockaidDescriptionMaliciousDomain',
Expand All @@ -36,8 +38,11 @@ const REASON_TO_DESCRIPTION_TKEY = Object.freeze({
[BlockaidReason.other]: 'blockaidDescriptionMightLoseAssets',
});

/** List of suspicious reason(s). Other reasons will be deemed as deceptive. */
const SUSPCIOUS_REASON = [BlockaidReason.rawSignatureFarming];
/** Reason to title translation key mapping. */
const REASON_TO_TITLE_TKEY = Object.freeze({
[BlockaidReason.failed]: 'blockaidTitleMayNotBeSafe',
[BlockaidReason.rawSignatureFarming]: 'blockaidDescriptionApproveFarming',
});

function BlockaidBannerAlert({ securityAlertResponse }) {
const t = useContext(I18nContext);
Expand All @@ -52,16 +57,12 @@ function BlockaidBannerAlert({ securityAlertResponse }) {
return null;
}

const descriptionTKey =
resultType === BlockaidResultType.Failed
? 'blockaidDescriptionFailed'
: REASON_TO_DESCRIPTION_TKEY[reason];
const description = t(descriptionTKey || 'other');

if (!descriptionTKey) {
if (!REASON_TO_DESCRIPTION_TKEY[reason]) {
captureException(`BlockaidBannerAlert: Unidentified reason '${reason}'`);
}

const description = t(REASON_TO_DESCRIPTION_TKEY[reason] || 'other');

const details = Boolean(features?.length) && (
<Text as="ul">
{features.map((feature, i) => (
Expand All @@ -75,14 +76,7 @@ function BlockaidBannerAlert({ securityAlertResponse }) {
? Severity.Danger
: Severity.Warning;

let title;
if (resultType === BlockaidResultType.Failed) {
title = t('blockaidTitleMayNotBeSafe');
} else if (SUSPCIOUS_REASON.indexOf(reason) > -1) {
title = t('blockaidTitleSuspicious');
} else {
title = t('blockaidTitleDeceptive');
}
const title = REASON_TO_TITLE_TKEY[reason] || t('blockaidTitleDeceptive');

return (
<SecurityProviderBannerAlert
Expand Down

0 comments on commit ba39516

Please sign in to comment.