Skip to content

Commit

Permalink
chore: improve signature redesign approval type readability
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptotavares committed Nov 14, 2024
1 parent f8fa89f commit 7702e54
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions shared/modules/confirmation.utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TransactionType } from '@metamask/transaction-controller';
import { ApprovalType } from '@metamask/controller-utils';
import {
REDESIGN_APPROVAL_TYPES,
REDESIGN_SIGNATURE_APPROVAL_TYPES,
shouldUseRedesignForTransactions,
shouldUseRedesignForSignatures,
} from './confirmation.utils';
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('confirmation.utils', () => {
});

it('should return true for supported approval types when user setting is enabled', () => {
REDESIGN_APPROVAL_TYPES.forEach((approvalType) => {
REDESIGN_SIGNATURE_APPROVAL_TYPES.forEach((approvalType) => {
expect(
shouldUseRedesignForSignatures(
approvalType,
Expand All @@ -152,7 +152,7 @@ describe('confirmation.utils', () => {
it('should return true for supported approval types when developer mode is enabled via env', () => {
process.env.ENABLE_CONFIRMATION_REDESIGN = 'true';

REDESIGN_APPROVAL_TYPES.forEach((approvalType) => {
REDESIGN_SIGNATURE_APPROVAL_TYPES.forEach((approvalType) => {
expect(
shouldUseRedesignForSignatures(
approvalType,
Expand All @@ -164,7 +164,7 @@ describe('confirmation.utils', () => {
});

it('should return true for supported approval types when developer setting is enabled', () => {
REDESIGN_APPROVAL_TYPES.forEach((approvalType) => {
REDESIGN_SIGNATURE_APPROVAL_TYPES.forEach((approvalType) => {
expect(
shouldUseRedesignForSignatures(
approvalType,
Expand All @@ -190,7 +190,7 @@ describe('confirmation.utils', () => {
it('should return false when both user setting and developer mode are disabled', () => {
process.env.ENABLE_CONFIRMATION_REDESIGN = 'false';

REDESIGN_APPROVAL_TYPES.forEach((approvalType) => {
REDESIGN_SIGNATURE_APPROVAL_TYPES.forEach((approvalType) => {
expect(
shouldUseRedesignForSignatures(
approvalType,
Expand Down
8 changes: 4 additions & 4 deletions shared/modules/confirmation.utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TransactionType } from '@metamask/transaction-controller';
import { ApprovalType } from '@metamask/controller-utils';

export const REDESIGN_APPROVAL_TYPES = [
export const REDESIGN_SIGNATURE_APPROVAL_TYPES = [
ApprovalType.EthSignTypedData,
ApprovalType.PersonalSign,
];
Expand Down Expand Up @@ -30,8 +30,8 @@ const isCorrectUserTransactionType = (
transactionMetadataType: TransactionType,
): boolean => REDESIGN_USER_TRANSACTION_TYPES.includes(transactionMetadataType);

const isCorrectApprovalType = (approvalType: ApprovalType): boolean =>
REDESIGN_APPROVAL_TYPES.includes(approvalType);
const isCorrectSignatureApprovalType = (approvalType: ApprovalType): boolean =>
REDESIGN_SIGNATURE_APPROVAL_TYPES.includes(approvalType);

const shouldUseRedesignForTransactionsDeveloperMode = (
isRedesignedConfirmationsDeveloperEnabled: boolean,
Expand Down Expand Up @@ -71,7 +71,7 @@ export const shouldUseRedesignForSignatures = (
process.env.ENABLE_CONFIRMATION_REDESIGN === 'true' ||
isRedesignedConfirmationsDeveloperEnabled;

if (!isCorrectApprovalType(approvalType)) {
if (!isCorrectSignatureApprovalType(approvalType)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion ui/pages/confirmations/hooks/useCurrentConfirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const useCurrentConfirmation = () => {
// If the developer toggle or the build time environment variable are enabled,
// all the signatures and transactions in development are shown. If the user
// facing feature toggles for signature or transactions are enabled, we show
// only confirmations that shipped (contained in `REDESIGN_APPROVAL_TYPES` and
// only confirmations that shipped (contained in `REDESIGN_SIGNATURE_APPROVAL_TYPES` and
// `REDESIGN_USER_TRANSACTION_TYPES` or `REDESIGN_DEV_TRANSACTION_TYPES`
// respectively).
const shouldUseRedesign =
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/confirmations/utils/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { parseTypedDataMessage } from '../../../../shared/modules/transaction.ut
import { sanitizeMessage } from '../../../helpers/utils/util';
import { Confirmation, SignatureRequestType } from '../types/confirm';
import { TYPED_SIGNATURE_VERSIONS } from '../constants';
import { REDESIGN_APPROVAL_TYPES } from '../../../../shared/modules/confirmation.utils';
import { REDESIGN_SIGNATURE_APPROVAL_TYPES } from '../../../../shared/modules/confirmation.utils';

export const isSignatureApprovalRequest = (
request: ApprovalRequest<Record<string, Json>>,
) => REDESIGN_APPROVAL_TYPES.includes(request.type as ApprovalType);
) => REDESIGN_SIGNATURE_APPROVAL_TYPES.includes(request.type as ApprovalType);

export const SIGNATURE_TRANSACTION_TYPES = [
TransactionType.personalSign,
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/routes/routes.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import NftFullImage from '../../components/app/assets/nfts/nft-details/nft-full-
import CrossChainSwap from '../bridge';
import { ToastMaster } from '../../components/app/toast-master/toast-master';
import {
REDESIGN_APPROVAL_TYPES,
REDESIGN_SIGNATURE_APPROVAL_TYPES,
REDESIGN_DEV_TRANSACTION_TYPES,
} from '../../../shared/modules/confirmation.utils';
import {
Expand Down Expand Up @@ -471,7 +471,7 @@ export default class Routes extends Component {
const pendingApproval = pendingApprovals.find(
(approval) => approval.id === confirmationId,
);
const isCorrectApprovalType = REDESIGN_APPROVAL_TYPES.includes(
const isCorrectApprovalType = REDESIGN_SIGNATURE_APPROVAL_TYPES.includes(
pendingApproval?.type,
);
const isCorrectDeveloperTransactionType =
Expand Down

0 comments on commit 7702e54

Please sign in to comment.