Skip to content

Commit

Permalink
make sure to show sim errors in send flow; add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piyalbasu committed Oct 4, 2024
1 parent ad93929 commit 4315dba
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 47 deletions.
39 changes: 38 additions & 1 deletion extension/src/popup/__testHelpers__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const mockBalances = {
available: new BigNumber("100"),
blockaidData: {
result_type: "Spam",
features: [{ description: "" }],
features: [{ feature_id: "METADATA", description: "baz" }],
},
},
native: {
Expand All @@ -110,6 +110,43 @@ export const mockBalances = {
subentryCount: 1,
};

// balances with no blockaid spam data as we only do the scan on Mainnet
export const mockTestnetBalances = {
balances: {
["DT:CCXVDIGMR6WTXZQX2OEVD6YM6AYCYPXPQ7YYH6OZMRS7U6VD3AVHNGBJ"]: {
token: {
code: "DT",
issuer: {
key: "CCXVDIGMR6WTXZQX2OEVD6YM6AYCYPXPQ7YYH6OZMRS7U6VD3AVHNGBJ",
},
},
decimals: 7,
total: new BigNumber("1000000000"),
available: new BigNumber("1000000000"),
blockaidData: defaultBlockaidScanAssetResult,
},
["USDC:GCK3D3V2XNLLKRFGFFFDEJXA4O2J4X36HET2FE446AV3M4U7DPHO3PEM"]: {
token: {
code: "USDC",
issuer: {
key: "GCK3D3V2XNLLKRFGFFFDEJXA4O2J4X36HET2FE446AV3M4U7DPHO3PEM",
},
},
total: new BigNumber("100"),
available: new BigNumber("100"),
blockaidData: defaultBlockaidScanAssetResult,
},
native: {
token: { type: "native", code: "XLM" },
total: new BigNumber("50"),
available: new BigNumber("50"),
blockaidData: defaultBlockaidScanAssetResult,
},
} as any as Balances,
isFunded: true,
subentryCount: 1,
};

export const mockTokenBalance = {
balance: 10,
decimals: 0,
Expand Down
53 changes: 44 additions & 9 deletions extension/src/popup/components/WarningMessages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1126,18 +1126,27 @@ export const BlockAidSiteScanLabel = ({

export const BlockaidTxScanLabel = ({
scanResult,
isPopup = false,
}: {
scanResult: BlockAidScanTxResult;
isPopup?: boolean;
}) => {
const { t } = useTranslation();
const { simulation, validation } = scanResult;

if (simulation && "error" in simulation) {
const header = t("This transaction is expected to fail");
if (isPopup) {
return (
<BlockaidWarningModal
header={header}
description={[simulation.error]}
isWarning
/>
);
}
return (
<WarningMessage
header="This transaction is expected to fail"
variant={WarningMessageVariant.warning}
>
<WarningMessage header={header} variant={WarningMessageVariant.warning}>
<div>
<p>{t(simulation.error)}</p>
</div>
Expand All @@ -1150,10 +1159,21 @@ export const BlockaidTxScanLabel = ({
switch (validation.result_type) {
case "Malicious": {
message = {
header: "This transaction was flagged as malicious",
header: t("This transaction was flagged as malicious"),
variant: WarningMessageVariant.highAlert,
message: validation.description,
};

if (isPopup) {
return (
<BlockaidWarningModal
header={message.header}
description={[message.message]}
isWarning={false}
/>
);
}

return (
<WarningMessage header={message.header} variant={message.variant}>
<div>
Expand All @@ -1169,6 +1189,17 @@ export const BlockaidTxScanLabel = ({
variant: WarningMessageVariant.warning,
message: validation.description,
};

if (isPopup) {
return (
<BlockaidWarningModal
header={message.header}
description={[message.message]}
isWarning
/>
);
}

return (
<WarningMessage header={message.header} variant={message.variant}>
<div>
Expand Down Expand Up @@ -1257,15 +1288,18 @@ export const BlockaidWarningModal = ({
);
}

return <span>{word} </span>;
return <span key={word}>{word} </span>;
});
};

return isModalActive ? (
<>
<WarningInfoBlock />
{createPortal(
<div className="BlockaidWarningModal">
<div
className="BlockaidWarningModal"
data-testid={`BlockaidWarningModal__${isAsset ? "asset" : "tx"}`}
>
<LoadingBackground isActive />
<div className="BlockaidWarningModal__modal">
<div
Expand All @@ -1292,7 +1326,7 @@ export const BlockaidWarningModal = ({
:
<ul className="ScamAssetWarning__list">
{description.map((d) => (
<li key={d.replace(" ", "-")}>{truncatedDescription(d)}</li>
<li key={d}>{truncatedDescription(d)}</li>
))}
</ul>
</div>
Expand All @@ -1301,6 +1335,7 @@ export const BlockaidWarningModal = ({
</div>

<Button
data-testid="BlockaidWarningModal__button"
size="md"
variant="secondary"
isFullWidth
Expand All @@ -1320,7 +1355,7 @@ export const BlockaidWarningModal = ({
<div
className="WarningMessage__activate-button"
onClick={() => setIsModalActive(true)}
data-testid="BlockaidWarningModal__button"
data-testid={`BlockaidWarningModal__button__${isAsset ? "asset" : "tx"}`}
>
<WarningInfoBlock />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
} from "@shared/helpers/stellar";
import {
isAssetSuspicious,
isBlockaidWarning,
isTxSuspicious,
useScanAsset,
useScanTx,
Expand Down Expand Up @@ -72,7 +71,7 @@ import {
} from "popup/components/account/AccountAssets";
import { HardwareSign } from "popup/components/hardwareConnect/HardwareSign";
import {
BlockaidWarningModal,
BlockaidTxScanLabel,
FlaggedWarningMessage,
} from "popup/components/WarningMessages";
import { View } from "popup/basics/layout/View";
Expand Down Expand Up @@ -702,17 +701,9 @@ export const TransactionDetails = ({
</div>
)}
<div className="TransactionDetails__warnings">
{scanResult?.validation &&
"result_type" in scanResult.validation && (
<BlockaidWarningModal
header={`This transaction was flagged as ${scanResult.validation.result_type}`}
description={[scanResult.validation.description]}
isWarning={isBlockaidWarning(
scanResult.validation.result_type,
)}
isAsset
/>
)}
{scanResult && (
<BlockaidTxScanLabel scanResult={scanResult} isPopup />
)}
{submission.submitStatus === ActionStatus.IDLE && (
<FlaggedWarningMessage
isMemoRequired={isMemoRequired}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@
}

&__warnings {
display: flex;
flex-flow: column;
gap: 0.5rem;
margin-top: 1.5rem;

.WarningMessage__infoBlock {
margin-bottom: 0.375rem;
margin-bottom: 0;
}
}
}
Expand Down
Loading

0 comments on commit 4315dba

Please sign in to comment.