Skip to content

Commit

Permalink
fix: Consistent confirmation navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronfigueiredo committed Sep 23, 2024
1 parent c323433 commit 8586fa8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
16 changes: 8 additions & 8 deletions ui/pages/confirmations/hooks/useCurrentConfirmation.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
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 { isMMI } from '../../../helpers/utils/build-types';
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';
import { isMMI } from '../../../helpers/utils/build-types';

/**
* Determine the current confirmation based on the pending approvals and controller state.
Expand All @@ -33,8 +33,8 @@ import { isMMI } from '../../../helpers/utils/build-types';
*/
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
10 changes: 2 additions & 8 deletions ui/pages/confirmations/selectors/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ export function pendingConfirmationsSortedSelector(
.sort((a1, a2) => a1.time - a2.time);
}

const internalLatestPendingConfirmationSelector = createSelector(
export const oldestPendingConfirmationSelector = createSelector(
pendingConfirmationsSortedSelector,
(pendingConfirmations) =>
pendingConfirmations.sort((a1, a2) => a2.time - a1.time)[0],
);

export const latestPendingConfirmationSelector = createDeepEqualSelector(
internalLatestPendingConfirmationSelector,
(latestPendingConfirmation) => latestPendingConfirmation,
(pendingConfirmations) => pendingConfirmations[0],
);

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

0 comments on commit 8586fa8

Please sign in to comment.