Skip to content

Commit

Permalink
Fix breaking changes in SmartTransactionsController instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Sep 12, 2024
1 parent 097fcaa commit 23fbcab
Showing 1 changed file with 51 additions and 40 deletions.
91 changes: 51 additions & 40 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
AddressBookController,
AddressBookState,
} from '@metamask/address-book-controller';
import { BaseState } from '@metamask/base-controller';
import { BaseState, Listener } from '@metamask/base-controller';
import { ComposableController } from '@metamask/composable-controller';
import {
KeyringController,
Expand Down Expand Up @@ -213,17 +213,26 @@ import {
networkIdUpdated,
networkIdWillUpdate,
} from '../core/redux/slices/inpageProvider';
import SmartTransactionsController from '@metamask/smart-transactions-controller';
import SmartTransactionsController, {
type SmartTransactionsControllerState,
} from '@metamask/smart-transactions-controller';
import { getAllowedSmartTransactionsChainIds } from '../../app/constants/smartTransactions';
import { selectShouldUseSmartTransaction } from '../selectors/smartTransactionsController';
import { selectSwapsChainFeatureFlags } from '../reducers/swaps';
import { SmartTransactionStatuses } from '@metamask/smart-transactions-controller/dist/types';
import { submitSmartTransactionHook } from '../util/smart-transactions/smart-publish-hook';
import { SmartTransactionsControllerState } from '@metamask/smart-transactions-controller/dist/SmartTransactionsController';
import { zeroAddress } from 'ethereumjs-util';
import { toChecksumHexAddress } from '@metamask/controller-utils';
import { ExtendedControllerMessenger } from './ExtendedControllerMessenger';
import EthQuery from '@metamask/eth-query';
import {
MetaMetricsEventCategory,
MetaMetricsEventName,
} from '@metamask/smart-transactions-controller/dist/constants';
import {
getSmartTransactionMetricsProperties,
getSmartTransactionMetricsSensitiveProperties,
} from '@metamask/smart-transactions-controller/dist/utils';

const NON_EMPTY = 'NON_EMPTY';

Expand Down Expand Up @@ -1261,13 +1270,20 @@ class Engine {

const codefiTokenApiV2 = new CodefiTokenPricesServiceV2();

const smartTransactionsControllerTrackMetaMetricsEvent = (params: {
event: string;
category: string;
// TODO: Replace "any" with type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sensitiveProperties: any;
}) => {
const smartTransactionsControllerTrackMetaMetricsEvent = (
params: {
event: MetaMetricsEventName;
category: MetaMetricsEventCategory;
properties?: ReturnType<typeof getSmartTransactionMetricsProperties>;
sensitiveProperties?: ReturnType<
typeof getSmartTransactionMetricsSensitiveProperties
>;
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
options?: {
metaMetricsId?: string;
},
) => {
const { event, category, ...restParams } = params;

MetaMetrics.getInstance().trackEvent(
Expand All @@ -1280,40 +1296,35 @@ class Engine {
restParams,
);
};
this.smartTransactionsController = new SmartTransactionsController(
{
confirmExternalTransaction:
this.transactionController.confirmExternalTransaction.bind(
this.transactionController,
),
getNetworkClientById:
networkController.getNetworkClientById.bind(networkController),
getNonceLock: this.transactionController.getNonceLock.bind(
this.smartTransactionsController = new SmartTransactionsController({
confirmExternalTransaction:
this.transactionController.confirmExternalTransaction.bind(
this.transactionController,
),
getTransactions: this.transactionController.getTransactions.bind(
this.transactionController,
getNetworkClientById:
networkController.getNetworkClientById.bind(networkController),
getNonceLock: this.transactionController.getNonceLock.bind(
this.transactionController,
),
getTransactions: this.transactionController.getTransactions.bind(
this.transactionController,
),
onNetworkStateChange: (listener: Listener<NetworkState>) =>
this.controllerMessenger.subscribe(
AppConstants.NETWORK_STATE_CHANGE_EVENT,
listener,
),
onNetworkStateChange: (listener) =>
this.controllerMessenger.subscribe(
AppConstants.NETWORK_STATE_CHANGE_EVENT,
listener,
),

// TODO: Replace "any" with type
provider:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
networkController.getProviderAndBlockTracker().provider as any,
// TODO: Replace "any" with type
provider:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
networkController.getProviderAndBlockTracker().provider as any,

trackMetaMetricsEvent: smartTransactionsControllerTrackMetaMetricsEvent,
getMetaMetricsProps: () => Promise.resolve({}), // Return MetaMetrics props once we enable HW wallets for smart transactions.
},
{
// @ts-expect-error TODO: resolve types
supportedChainIds: getAllowedSmartTransactionsChainIds(),
},
initialState.SmartTransactionsController,
);
trackMetaMetricsEvent: smartTransactionsControllerTrackMetaMetricsEvent,
getMetaMetricsProps: () => Promise.resolve({}), // Return MetaMetrics props once we enable HW wallets for smart transactions.
// @ts-expect-error TODO: resolve types
supportedChainIds: getAllowedSmartTransactionsChainIds(),
state: initialState.SmartTransactionsController,
});

const controllers: Controllers[keyof Controllers][] = [
keyringController,
Expand Down

0 comments on commit 23fbcab

Please sign in to comment.