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

fix: Simulations on signature pages should be displayed only if preference is enabled #25186

Merged
merged 7 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('PersonalSignInfo', () => {

it('does not render if required data is not present in the transaction', () => {
const state = {
...mockState,
confirm: {
currentConfirmation: {
id: '0050d5b0-c023-11ee-a0cb-3390a510a0ab',
Expand Down Expand Up @@ -74,9 +75,13 @@ describe('PersonalSignInfo', () => {
expect(getByText('Signing in with')).toBeDefined();
});

it('display simulation for SIWE request', () => {
it('display simulation for SIWE request if preference useTransactionSimulations is enabled', () => {
const state = {
...mockState,
metamask: {
...mockState.metamask,
useTransactionSimulations: true,
},
confirm: {
currentConfirmation: signatureRequestSIWE,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
sanitizeString,
} from '../../../../../../helpers/utils/util';
import { SignatureRequestType } from '../../../../types/confirm';
import { selectUseTransactionSimulations } from '../../../../selectors/preferences';
import { isSIWESignatureRequest } from '../../../../utils';
import { AlertRow } from '../../../../../../components/app/confirm/info/row/alert-row/alert-row';

Expand All @@ -27,6 +28,9 @@ const PersonalSignInfo: React.FC = () => {
const currentConfirmation = useSelector(
currentConfirmationSelector,
) as SignatureRequestType;
const useTransactionSimulations = useSelector(
selectUseTransactionSimulations,
);

if (!currentConfirmation?.msgParams) {
return null;
Expand All @@ -37,7 +41,7 @@ const PersonalSignInfo: React.FC = () => {

return (
<>
{isSiweSigReq && (
{isSiweSigReq && useTransactionSimulations && (
<Box
backgroundColor={BackgroundColor.backgroundDefault}
borderRadius={BorderRadius.MD}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ describe('TypedSignInfo', () => {
expect(container).toMatchSnapshot();
});

it('display simulation details for permit signature', () => {
it('display simulation details for permit signature if flag useTransactionSimulations is set', () => {
const state = {
...mockState,
metamask: {
...mockState.metamask,
useTransactionSimulations: true,
},
confirm: {
currentConfirmation: permitSignatureMsg,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../../../../../../helpers/constants/design-system';
import { SignatureRequestType } from '../../../../types/confirm';
import { isPermitSignatureRequest } from '../../../../utils';
import { selectUseTransactionSimulations } from '../../../../selectors/preferences';
import { ConfirmInfoRowTypedSignData } from '../../row/typed-sign-data/typedSignData';
import { PermitSimulation } from './permit-simulation';

Expand All @@ -26,6 +27,9 @@ const TypedSignInfo: React.FC = () => {
const currentConfirmation = useSelector(
currentConfirmationSelector,
) as SignatureRequestType;
const useTransactionSimulations = useSelector(
selectUseTransactionSimulations,
);

if (!currentConfirmation?.msgParams) {
return null;
Expand All @@ -40,7 +44,7 @@ const TypedSignInfo: React.FC = () => {

return (
<>
{isPermit && <PermitSimulation />}
{isPermit && useTransactionSimulations && <PermitSimulation />}
<Box
backgroundColor={BackgroundColor.backgroundDefault}
borderRadius={BorderRadius.MD}
Expand Down
19 changes: 19 additions & 0 deletions ui/pages/confirmations/selectors/preferences.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { selectUseTransactionSimulations } from './preferences';

describe('preference selectors', () => {
describe('getUseTransactionSimulations', () => {
it('returns value of useTransactionSimulations from state', () => {
const result = selectUseTransactionSimulations({
metamask: {
useTransactionSimulations: true,
},
});
expect(result).toStrictEqual(true);
});

it('returns undefined if useTransactionSimulations is not set', () => {
const result = selectUseTransactionSimulations({ metamask: {} });
expect(result).toStrictEqual(undefined);
});
});
});
8 changes: 8 additions & 0 deletions ui/pages/confirmations/selectors/preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type RootState = {
metamask: {
useTransactionSimulations?: boolean;
};
};

export const selectUseTransactionSimulations = (state: RootState) =>
state.metamask.useTransactionSimulations;