Skip to content

Commit

Permalink
feat: do not require scroll if Permit Simulation is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
digiwand committed Sep 4, 2024
1 parent 9f30b98 commit dcf9a9c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
38 changes: 37 additions & 1 deletion ui/pages/confirmations/components/confirm/footer/footer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
signatureRequestSIWE,
unapprovedPersonalSignMsg,
} from '../../../../../../test/data/confirmations/personal_sign';
import { permitSignatureMsg } from '../../../../../../test/data/confirmations/typed_sign';
import mockState from '../../../../../../test/data/mock-state.json';
import { fireEvent, renderWithProvider } from '../../../../../../test/jest';
import * as MMIConfirmations from '../../../../../hooks/useMMIConfirmations';
Expand All @@ -33,10 +34,11 @@ jest.mock(
}),
);

const render = (args = {}) => {
const render = (args = {}, metamaskState = {}) => {
const store = configureStore({
metamask: {
...mockState.metamask,
...metamaskState,
},
confirm: {
currentConfirmation: {
Expand Down Expand Up @@ -105,6 +107,23 @@ describe('ConfirmFooter', () => {
const confirmButton = getByText('Confirm');
expect(confirmButton).not.toBeDisabled();
});

it('when the confirmation is a Permit with the transaction simulation setting enabled', () => {
const { getByText } = render(
{
confirm: {
currentConfirmation: permitSignatureMsg,
isScrollToBottomCompleted: false,
},
},
{
useTransactionSimulations: true,
},
);

const confirmButton = getByText('Confirm');
expect(confirmButton).not.toBeDisabled();
});
});

describe('renders disabled "Confirm" Button', () => {
Expand All @@ -119,6 +138,23 @@ describe('ConfirmFooter', () => {
const confirmButton = getByText('Confirm');
expect(confirmButton).toBeDisabled();
});

it('when the confirmation is a Permit with the transaction simulation setting disabled', () => {
const { getByText } = render(
{
confirm: {
currentConfirmation: permitSignatureMsg,
isScrollToBottomCompleted: false,
},
},
{
useTransactionSimulations: false,
},
);

const confirmButton = getByText('Confirm');
expect(confirmButton).toBeDisabled();
});
});

it('invoke action rejectPendingApproval when cancel button is clicked', () => {
Expand Down
22 changes: 16 additions & 6 deletions ui/pages/confirmations/components/confirm/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import {
///: END:ONLY_INCLUDE_IF
} from '../../../../../store/actions';
import { confirmSelector } from '../../../selectors';
import { selectUseTransactionSimulations } from '../../../selectors/preferences';

import {
REDESIGN_DEV_TRANSACTION_TYPES,
isPermitSignatureRequest,
isSIWESignatureRequest,
} from '../../../utils';
import { getConfirmationSender } from '../utils';
Expand Down Expand Up @@ -111,6 +114,9 @@ const Footer = () => {
const t = useI18nContext();
const confirm = useSelector(confirmSelector);
const customNonceValue = useSelector(getCustomNonceValue);
const useTransactionSimulations = useSelector(
selectUseTransactionSimulations,
);

const { currentConfirmation, isScrollToBottomCompleted } = confirm;
const { from } = getConfirmationSender(currentConfirmation);
Expand All @@ -128,14 +134,18 @@ const Footer = () => {
});

const isSIWE = isSIWESignatureRequest(currentConfirmation);
const isPermit = isPermitSignatureRequest(currentConfirmation);
const isPermitSimulationShown = isPermit && useTransactionSimulations;

console.log('isPermit', isPermit);
console.log('isPermitSimulationShown', isPermitSimulationShown);

const isConfirmDisabled =
!isSIWE &&
(!isScrollToBottomCompleted ||
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
mmiSubmitDisabled ||
///: END:ONLY_INCLUDE_IF
hardwareWalletRequiresConnection);
(!isScrollToBottomCompleted && !isSIWE && !isPermitSimulationShown) ||
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
mmiSubmitDisabled ||
///: END:ONLY_INCLUDE_IF
hardwareWalletRequiresConnection;

const onCancel = useCallback(
({ location }: { location?: MetaMetricsEventLocation }) => {
Expand Down

0 comments on commit dcf9a9c

Please sign in to comment.