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 34259a3 commit cfdb159
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
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
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 cfdb159

Please sign in to comment.