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

chore: centralize redesigned confirmation decision logic #28445

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ee24909
chore: centralize redesigned confirmation decision logic
cryptotavares Nov 13, 2024
83ae8ca
Merge branch 'develop' into cryptotavares/centralize-redesigned-confi…
cryptotavares Nov 14, 2024
b493085
fix: import redesign dev transaction types
cryptotavares Nov 14, 2024
acee5ae
fix: lint
cryptotavares Nov 14, 2024
487c1f0
test:fix createRPCMethodTrackingMiddleware unit tests
cryptotavares Nov 14, 2024
f8fa89f
test: reomve unnecessary unit test
cryptotavares Nov 14, 2024
7702e54
chore: improve signature redesign approval type readability
cryptotavares Nov 14, 2024
ce7bc59
Merge branch 'develop' into cryptotavares/centralize-redesigned-confi…
cryptotavares Nov 19, 2024
f35fac3
chore: use function declarations instead of expressions
cryptotavares Nov 19, 2024
5fc5817
chore: add jsdoc comments
cryptotavares Nov 19, 2024
af3819b
chore: remove useless comment
cryptotavares Nov 19, 2024
a59ed51
chore: stop exporting REDESIGN_SIGNATURE_APPROVAL_TYPES
cryptotavares Nov 19, 2024
2cd99ef
chore: stop exporting REDESIGN_DEV_TRANSACTION_TYPES
cryptotavares Nov 19, 2024
03b5a3c
chore: move confirmation utils from shared/modules to shared/lib
cryptotavares Nov 19, 2024
18e2fde
improve shouldUseRedesignForTransactions args readability
cryptotavares Nov 19, 2024
74939a6
improve shouldUseRedesignForSignatures args readability
cryptotavares Nov 19, 2024
0154d58
fix: lint
cryptotavares Nov 19, 2024
34dc9df
fix: disable jsdoc lint
cryptotavares Nov 20, 2024
746342a
Merge branch 'develop' into cryptotavares/centralize-redesigned-confi…
cryptotavares Nov 20, 2024
6c56694
Merge branch 'develop' into cryptotavares/centralize-redesigned-confi…
cryptotavares Nov 20, 2024
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
20 changes: 12 additions & 8 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from '../../../ui/helpers/utils/metrics';
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
import { REDESIGN_APPROVAL_TYPES } from '../../../ui/pages/confirmations/utils/confirm';
import { shouldUseRedesignForSignatures } from '../../../shared/lib/confirmation.utils';
import { getSnapAndHardwareInfoForMetrics } from './snap-keyring/metrics';

/**
Expand Down Expand Up @@ -196,6 +196,7 @@ function finalizeSignatureFragment(
* @param {Function} opts.getAccountType
* @param {Function} opts.getDeviceModel
* @param {Function} opts.isConfirmationRedesignEnabled
* @param {Function} opts.isRedesignedConfirmationsDeveloperEnabled
* @param {RestrictedControllerMessenger} opts.snapAndHardwareMessenger
* @param {number} [opts.globalRateLimitTimeout] - time, in milliseconds, of the sliding
* time window that should limit the number of method calls tracked to globalRateLimitMaxAmount.
Expand All @@ -214,6 +215,7 @@ export default function createRPCMethodTrackingMiddleware({
getAccountType,
getDeviceModel,
isConfirmationRedesignEnabled,
isRedesignedConfirmationsDeveloperEnabled,
snapAndHardwareMessenger,
appStateController,
metaMetricsController,
Expand Down Expand Up @@ -315,13 +317,15 @@ export default function createRPCMethodTrackingMiddleware({
req.securityAlertResponse.description;
}

const isConfirmationRedesign =
isConfirmationRedesignEnabled() &&
REDESIGN_APPROVAL_TYPES.find(
(type) => type === MESSAGE_TYPE_TO_APPROVAL_TYPE[method],
);

if (isConfirmationRedesign) {
if (
shouldUseRedesignForSignatures({
approvalType: MESSAGE_TYPE_TO_APPROVAL_TYPE[method],
isRedesignedSignaturesUserSettingEnabled:
isConfirmationRedesignEnabled(),
isRedesignedConfirmationsDeveloperEnabled:
isRedesignedConfirmationsDeveloperEnabled(),
})
) {
eventProperties.ui_customizations = [
...(eventProperties.ui_customizations || []),
MetaMetricsEventUiCustomization.RedesignedConfirmation,
Expand Down
13 changes: 13 additions & 0 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const createHandler = (opts) =>
appStateController,
metaMetricsController,
isConfirmationRedesignEnabled: () => false,
isRedesignedConfirmationsDeveloperEnabled: () => false,
...opts,
});

Expand Down Expand Up @@ -217,10 +218,22 @@ describe('createRPCMethodTrackingMiddleware', () => {
});

describe('participateInMetaMetrics is set to true', () => {
const originalEnableConfirmationRedesign =
process.env.ENABLE_CONFIRMATION_REDESIGN;

beforeEach(() => {
metaMetricsController.setParticipateInMetaMetrics(true);
});

beforeAll(() => {
process.env.ENABLE_CONFIRMATION_REDESIGN = 'false';
});

afterAll(() => {
process.env.ENABLE_CONFIRMATION_REDESIGN =
originalEnableConfirmationRedesign;
});

it(`should immediately track a ${MetaMetricsEventName.SignatureRequested} event`, async () => {
const req = {
id: MOCK_ID,
Expand Down
32 changes: 10 additions & 22 deletions app/scripts/lib/transaction/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ import {
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
} from '../../../../ui/helpers/utils/metrics';
import {
REDESIGN_DEV_TRANSACTION_TYPES,
REDESIGN_USER_TRANSACTION_TYPES,
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
} from '../../../../ui/pages/confirmations/utils';

import {
getSnapAndHardwareInfoForMetrics,
type SnapAndHardwareMessenger,
} from '../snap-keyring/metrics';
import { shouldUseRedesignForTransactions } from '../../../../shared/lib/confirmation.utils';

export type TransactionMetricsRequest = {
createEventFragment: (
Expand Down Expand Up @@ -996,23 +992,15 @@ async function buildEventFragmentProperties({
if (simulationFails) {
uiCustomizations.push(MetaMetricsEventUiCustomization.GasEstimationFailed);
}
const isRedesignedConfirmationsDeveloperSettingEnabled =
transactionMetricsRequest.getIsRedesignedConfirmationsDeveloperEnabled() ||
process.env.ENABLE_CONFIRMATION_REDESIGN === 'true';

const isRedesignedTransactionsUserSettingEnabled =
transactionMetricsRequest.getRedesignedTransactionsEnabled();

if (
(isRedesignedConfirmationsDeveloperSettingEnabled &&
REDESIGN_DEV_TRANSACTION_TYPES.includes(
transactionMeta.type as TransactionType,
)) ||
(isRedesignedTransactionsUserSettingEnabled &&
REDESIGN_USER_TRANSACTION_TYPES.includes(
transactionMeta.type as TransactionType,
))
) {
const isRedesignedForTransaction = shouldUseRedesignForTransactions({
transactionMetadataType: transactionMeta.type as TransactionType,
isRedesignedTransactionsUserSettingEnabled:
transactionMetricsRequest.getRedesignedTransactionsEnabled(),
isRedesignedConfirmationsDeveloperEnabled:
transactionMetricsRequest.getIsRedesignedConfirmationsDeveloperEnabled(),
});
if (isRedesignedForTransaction) {
uiCustomizations.push(
MetaMetricsEventUiCustomization.RedesignedConfirmation,
);
Expand Down
43 changes: 25 additions & 18 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5789,16 +5789,14 @@ export default class MetamaskController extends EventEmitter {
),
);

const isConfirmationRedesignEnabled = () => {
return this.preferencesController.state.preferences
.redesignedConfirmationsEnabled;
};

engine.push(
createRPCMethodTrackingMiddleware({
getAccountType: this.getAccountType.bind(this),
getDeviceModel: this.getDeviceModel.bind(this),
isConfirmationRedesignEnabled,
isConfirmationRedesignEnabled:
this.isConfirmationRedesignEnabled.bind(this),
isRedesignedConfirmationsDeveloperEnabled:
this.isConfirmationRedesignDeveloperEnabled.bind(this),
snapAndHardwareMessenger: this.controllerMessenger.getRestricted({
name: 'SnapAndHardwareMessenger',
allowedActions: [
Expand Down Expand Up @@ -6436,6 +6434,21 @@ export default class MetamaskController extends EventEmitter {
});
}

isConfirmationRedesignEnabled() {
return this.preferencesController.state.preferences
.redesignedConfirmationsEnabled;
}

isTransactionsRedesignEnabled() {
return this.preferencesController.state.preferences
.redesignedTransactionsEnabled;
}

isConfirmationRedesignDeveloperEnabled() {
return this.preferencesController.state.preferences
.isRedesignedConfirmationsDeveloperEnabled;
}

/**
* The chain list is fetched live at runtime, falling back to a cache.
* This preseeds the cache at startup with a static list provided at build.
Expand Down Expand Up @@ -6620,14 +6633,10 @@ export default class MetamaskController extends EventEmitter {
txHash,
);
},
getRedesignedConfirmationsEnabled: () => {
return this.preferencesController.state.preferences
.redesignedConfirmationsEnabled;
},
getRedesignedTransactionsEnabled: () => {
return this.preferencesController.state.preferences
.redesignedTransactionsEnabled;
},
getRedesignedConfirmationsEnabled:
this.isConfirmationRedesignEnabled.bind(this),
getRedesignedTransactionsEnabled:
this.isTransactionsRedesignEnabled.bind(this),
getMethodData: (data) => {
if (!data) {
return null;
Expand All @@ -6645,10 +6654,8 @@ export default class MetamaskController extends EventEmitter {
this.provider,
);
},
getIsRedesignedConfirmationsDeveloperEnabled: () => {
return this.preferencesController.state.preferences
.isRedesignedConfirmationsDeveloperEnabled;
},
getIsRedesignedConfirmationsDeveloperEnabled:
this.isConfirmationRedesignDeveloperEnabled.bind(this),
getIsConfirmationAdvancedDetailsOpen: () => {
return this.preferencesController.state.preferences
.showConfirmationAdvancedDetails;
Expand Down
Loading
Loading