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: Consistent confirmation navigation #27326

Merged
merged 4 commits into from
Sep 24, 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
14 changes: 7 additions & 7 deletions ui/pages/confirmations/hooks/useCurrentConfirmation.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
import { ApprovalType } from '@metamask/controller-utils';
import {
TransactionMeta,
TransactionType,
} from '@metamask/transaction-controller';
import { ApprovalType } from '@metamask/controller-utils';
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { useParams } from 'react-router-dom';
import {
ApprovalsMetaMaskState,
getIsRedesignedConfirmationsDeveloperEnabled,
getRedesignedConfirmationsEnabled,
getRedesignedTransactionsEnabled,
getUnapprovedTransaction,
latestPendingConfirmationSelector,
oldestPendingConfirmationSelector,
selectPendingApproval,
} from '../../../selectors';
import { selectUnapprovedMessage } from '../../../selectors/signatures';
import {
REDESIGN_APPROVAL_TYPES,
REDESIGN_DEV_TRANSACTION_TYPES,
REDESIGN_USER_TRANSACTION_TYPES,
} from '../utils';
import { selectUnapprovedMessage } from '../../../selectors/signatures';

/**
* Determine the current confirmation based on the pending approvals and controller state.
Expand All @@ -32,8 +32,8 @@ import { selectUnapprovedMessage } from '../../../selectors/signatures';
*/
const useCurrentConfirmation = () => {
const { id: paramsConfirmationId } = useParams<{ id: string }>();
const latestPendingApproval = useSelector(latestPendingConfirmationSelector);
const confirmationId = paramsConfirmationId ?? latestPendingApproval?.id;
const oldestPendingApproval = useSelector(oldestPendingConfirmationSelector);
const confirmationId = paramsConfirmationId ?? oldestPendingApproval?.id;

const isRedesignedSignaturesUserSettingEnabled = useSelector(
getRedesignedConfirmationsEnabled,
Expand Down
10 changes: 5 additions & 5 deletions ui/pages/confirmations/selectors/confirm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApprovalType } from '@metamask/controller-utils';
import { ConfirmMetamaskState } from '../types/confirm';
import {
getIsRedesignedConfirmationsDeveloperEnabled,
latestPendingConfirmationSelector,
oldestPendingConfirmationSelector,
pendingConfirmationsSelector,
} from './confirm';

Expand Down Expand Up @@ -54,11 +54,11 @@ describe('confirm selectors', () => {
});
});

describe('latestPendingConfirmationSelector', () => {
it('should return latest pending confirmation from state', () => {
const result = latestPendingConfirmationSelector(mockedState);
describe('oldestPendingConfirmationSelector', () => {
it('should return oldest pending confirmation from state', () => {
const result = oldestPendingConfirmationSelector(mockedState);

expect(result).toStrictEqual(mockedState.metamask.pendingApprovals[2]);
expect(result).toStrictEqual(mockedState.metamask.pendingApprovals[3]);
});
});

Expand Down
15 changes: 7 additions & 8 deletions ui/pages/confirmations/selectors/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { ApprovalType } from '@metamask/controller-utils';

import { createSelector } from 'reselect';
import { getPendingApprovals } from '../../../selectors/approvals';
import { ConfirmMetamaskState } from '../types/confirm';
import { createDeepEqualSelector } from '../../../selectors/util';
import { getPreferences } from '../../../selectors/selectors';
import { createDeepEqualSelector } from '../../../selectors/util';
import { ConfirmMetamaskState } from '../types/confirm';

const ConfirmationApprovalTypes = [
ApprovalType.PersonalSign,
Expand All @@ -28,15 +28,14 @@ export function pendingConfirmationsSortedSelector(
.sort((a1, a2) => a1.time - a2.time);
matthewwalsh0 marked this conversation as resolved.
Show resolved Hide resolved
}

const internalLatestPendingConfirmationSelector = createSelector(
const firstPendingConfirmationSelector = createSelector(
pendingConfirmationsSortedSelector,
(pendingConfirmations) =>
pendingConfirmations.sort((a1, a2) => a2.time - a1.time)[0],
(pendingConfirmations) => pendingConfirmations[0],
matthewwalsh0 marked this conversation as resolved.
Show resolved Hide resolved
);

export const latestPendingConfirmationSelector = createDeepEqualSelector(
internalLatestPendingConfirmationSelector,
(latestPendingConfirmation) => latestPendingConfirmation,
export const oldestPendingConfirmationSelector = createDeepEqualSelector(
firstPendingConfirmationSelector,
(firstPendingConfirmation) => firstPendingConfirmation,
);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down