@metamask/smart-transactions-controller 12.0.1 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -6,10 +6,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [13.1.0]
10
+ ### Changed
11
+ - Emit a new "smartTransactionConfirmationDone" event ([#424](https://github.com/MetaMask/smart-transactions-controller/pull/424))
12
+ - Use a new API (Sentinel) for a health check ([#411](https://github.com/MetaMask/smart-transactions-controller/pull/411))
13
+
14
+ ## [13.0.0]
15
+ ### Changed
16
+ - **BREAKING:** Updated `SmartTransactionsController` to inherit from `StaticIntervalPollingController` instead of `StaticIntervalPollingControllerV1` ([#397](https://github.com/MetaMask/smart-transactions-controller/pull/397)).
17
+ - The constructor for `SmartTransactionsController` now accepts a single options object instead of three separate arguments, with configuration options merged into this object.
18
+ - `SmartTransactionsController` now requires a `messenger` option (with the corresponding type `SmartTransactionsControllerMessenger` now available).
19
+ - The constructor no longer accepts `onNetworkStateChange`; instead, it subscribes to `NetworkController:stateChange`.
20
+ - The `getNetworkClientById` argument has been removed from the constructor and is now accessed through the messenger.
21
+ - The controller no longer subscribes to its own events; this is now managed via the messenger.
22
+ - Event emission is no longer handled by `EventEmitter`; the messenger is now used for emitting events.
23
+ - The `SmartTransactionsControllerConfig` type has been removed and replaced with `SmartTransactionsControllerOptions`.
24
+ - Added and exported the following types: `SmartTransactionsControllerMessenger`, `SmartTransactionsControllerState`, `SmartTransactionsControllerGetStateAction`, `SmartTransactionsControllerActions`, `SmartTransactionsControllerStateChangeEvent`, `SmartTransactionsControllerSmartTransactionEvent`, and `SmartTransactionsControllerEvents`.
25
+
9
26
  ## [12.0.1]
27
+ ### Changed
28
+ - Remove logic for ensuring uniqueness of smart transactions ([#404](https://github.com/MetaMask/smart-transactions-controller/pull/404))
29
+ - This issue has been resolved in production.
30
+
10
31
  ### Fixed
11
32
  - Fix issue where this.ethQuery is sometimes unexpectedly undefined ([#405](https://github.com/MetaMask/smart-transactions-controller/pull/405))
12
- - Remove code that is no longer needed to ensure unique smart transactions ([#404](https://github.com/MetaMask/smart-transactions-controller/pull/404))
13
33
 
14
34
  ## [12.0.0]
15
35
  ### Changed
@@ -330,7 +350,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
330
350
  - Add initial SmartTransactionsController ([#1](https://github.com/MetaMask/smart-transactions-controller/pull/1))
331
351
  - Initial commit
332
352
 
333
- [Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v12.0.1...HEAD
353
+ [Unreleased]: https://github.com/MetaMask/smart-transactions-controller/compare/v13.1.0...HEAD
354
+ [13.1.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v13.0.0...v13.1.0
355
+ [13.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v12.0.1...v13.0.0
334
356
  [12.0.1]: https://github.com/MetaMask/smart-transactions-controller/compare/v12.0.0...v12.0.1
335
357
  [12.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v11.0.0...v12.0.0
336
358
  [11.0.0]: https://github.com/MetaMask/smart-transactions-controller/compare/v10.2.0...v11.0.0
@@ -1,65 +1,92 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import type { BaseConfig, BaseState } from '@metamask/base-controller';
4
- import type { NetworkClientId, NetworkController, NetworkState } from '@metamask/network-controller';
5
- import { StaticIntervalPollingControllerV1 } from '@metamask/polling-controller';
6
- import type { TransactionMeta } from '@metamask/transaction-controller';
7
- import EventEmitter from 'events';
2
+ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from '@metamask/base-controller';
3
+ import type { NetworkClientId, NetworkControllerGetNetworkClientByIdAction, NetworkControllerStateChangeEvent } from '@metamask/network-controller';
4
+ import { StaticIntervalPollingController } from '@metamask/polling-controller';
5
+ import type { TransactionController, TransactionMeta, TransactionParams } from '@metamask/transaction-controller';
6
+ import { MetaMetricsEventCategory, MetaMetricsEventName } from './constants';
8
7
  import type { Fees, Hex, IndividualTxFees, SignedCanceledTransaction, SignedTransaction, SmartTransaction, SmartTransactionsStatus, UnsignedTransaction, GetTransactionsOptions, MetaMetricsProps } from './types';
9
8
  import { SmartTransactionStatuses } from './types';
9
+ import { getSmartTransactionMetricsProperties, getSmartTransactionMetricsSensitiveProperties } from './utils';
10
10
  export declare const DEFAULT_INTERVAL: number;
11
- export declare type SmartTransactionsControllerConfig = BaseConfig & {
12
- interval: number;
13
- clientId: string;
14
- chainId: Hex;
15
- supportedChainIds: Hex[];
16
- };
11
+ /**
12
+ * The name of the {@link SmartTransactionsController}
13
+ */
14
+ declare const controllerName = "SmartTransactionsController";
17
15
  declare type FeeEstimates = {
18
- approvalTxFees: IndividualTxFees | undefined;
19
- tradeTxFees: IndividualTxFees | undefined;
16
+ approvalTxFees: IndividualTxFees | null;
17
+ tradeTxFees: IndividualTxFees | null;
20
18
  };
21
- export declare type SmartTransactionsControllerState = BaseState & {
19
+ export declare type SmartTransactionsControllerState = {
22
20
  smartTransactionsState: {
23
21
  smartTransactions: Record<Hex, SmartTransaction[]>;
24
- userOptIn: boolean | undefined;
25
- userOptInV2: boolean | undefined;
26
- liveness: boolean | undefined;
22
+ userOptIn: boolean | null;
23
+ userOptInV2: boolean | null;
24
+ liveness: boolean | null;
27
25
  fees: FeeEstimates;
28
26
  feesByChainId: Record<Hex, FeeEstimates>;
29
27
  livenessByChainId: Record<Hex, boolean>;
30
28
  };
31
29
  };
32
- export default class SmartTransactionsController extends StaticIntervalPollingControllerV1<SmartTransactionsControllerConfig, SmartTransactionsControllerState> {
30
+ /**
31
+ * Get the default {@link SmartTransactionsController} state.
32
+ *
33
+ * @returns The default {@link SmartTransactionsController} state.
34
+ */
35
+ export declare function getDefaultSmartTransactionsControllerState(): SmartTransactionsControllerState;
36
+ export declare type SmartTransactionsControllerGetStateAction = ControllerGetStateAction<typeof controllerName, SmartTransactionsControllerState>;
37
+ /**
38
+ * The actions that can be performed using the {@link SmartTransactionsController}.
39
+ */
40
+ export declare type SmartTransactionsControllerActions = SmartTransactionsControllerGetStateAction;
41
+ export declare type AllowedActions = NetworkControllerGetNetworkClientByIdAction;
42
+ export declare type SmartTransactionsControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SmartTransactionsControllerState>;
43
+ export declare type SmartTransactionsControllerSmartTransactionEvent = {
44
+ type: 'SmartTransactionsController:smartTransaction';
45
+ payload: [SmartTransaction];
46
+ };
47
+ export declare type SmartTransactionsControllerSmartTransactionConfirmationDoneEvent = {
48
+ type: 'SmartTransactionsController:smartTransactionConfirmationDone';
49
+ payload: [SmartTransaction];
50
+ };
51
+ /**
52
+ * The events that {@link SmartTransactionsController} can emit.
53
+ */
54
+ export declare type SmartTransactionsControllerEvents = SmartTransactionsControllerStateChangeEvent | SmartTransactionsControllerSmartTransactionEvent | SmartTransactionsControllerSmartTransactionConfirmationDoneEvent;
55
+ export declare type AllowedEvents = NetworkControllerStateChangeEvent;
56
+ /**
57
+ * The messenger of the {@link SmartTransactionsController}.
58
+ */
59
+ export declare type SmartTransactionsControllerMessenger = RestrictedControllerMessenger<typeof controllerName, SmartTransactionsControllerActions | AllowedActions, SmartTransactionsControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
60
+ declare type SmartTransactionsControllerOptions = {
61
+ interval?: number;
62
+ clientId?: string;
63
+ chainId?: Hex;
64
+ supportedChainIds?: Hex[];
65
+ getNonceLock: TransactionController['getNonceLock'];
66
+ confirmExternalTransaction: TransactionController['confirmExternalTransaction'];
67
+ trackMetaMetricsEvent: (event: {
68
+ event: MetaMetricsEventName;
69
+ category: MetaMetricsEventCategory;
70
+ properties?: ReturnType<typeof getSmartTransactionMetricsProperties>;
71
+ sensitiveProperties?: ReturnType<typeof getSmartTransactionMetricsSensitiveProperties>;
72
+ }, options?: {
73
+ metaMetricsId?: string;
74
+ } & Record<string, boolean>) => void;
75
+ state?: Partial<SmartTransactionsControllerState>;
76
+ messenger: SmartTransactionsControllerMessenger;
77
+ getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
78
+ getMetaMetricsProps: () => Promise<MetaMetricsProps>;
79
+ };
80
+ export default class SmartTransactionsController extends StaticIntervalPollingController<typeof controllerName, SmartTransactionsControllerState, SmartTransactionsControllerMessenger> {
33
81
  #private;
34
- /**
35
- * Name of this controller used during composition
36
- */
37
- name: string;
38
82
  timeoutHandle?: NodeJS.Timeout;
39
- private readonly getNonceLock;
40
- private ethQuery;
41
- confirmExternalTransaction: any;
42
- getRegularTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
43
- private readonly trackMetaMetricsEvent;
44
- eventEmitter: EventEmitter;
45
- private readonly getNetworkClientById;
46
- private readonly getMetaMetricsProps;
47
- private fetch;
48
- constructor({ onNetworkStateChange, getNonceLock, confirmExternalTransaction, getTransactions, trackMetaMetricsEvent, getNetworkClientById, getMetaMetricsProps, }: {
49
- onNetworkStateChange: (listener: (networkState: NetworkState) => void) => void;
50
- getNonceLock: any;
51
- confirmExternalTransaction: any;
52
- getTransactions: (options?: GetTransactionsOptions) => TransactionMeta[];
53
- trackMetaMetricsEvent: any;
54
- getNetworkClientById: NetworkController['getNetworkClientById'];
55
- getMetaMetricsProps: () => Promise<MetaMetricsProps>;
56
- }, config?: Partial<SmartTransactionsControllerConfig>, state?: Partial<SmartTransactionsControllerState>);
83
+ constructor({ interval, clientId, chainId: InitialChainId, supportedChainIds, getNonceLock, confirmExternalTransaction, trackMetaMetricsEvent, state, messenger, getTransactions, getMetaMetricsProps, }: SmartTransactionsControllerOptions);
57
84
  _executePoll(networkClientId: string): Promise<void>;
58
- checkPoll(state: any): void;
85
+ checkPoll({ smartTransactionsState: { smartTransactions }, }: SmartTransactionsControllerState): void;
59
86
  initializeSmartTransactionsForChainId(): void;
60
87
  poll(interval?: number): Promise<void>;
61
88
  stop(): Promise<void>;
62
- setOptInState(state: boolean | undefined): void;
89
+ setOptInState(optInState: boolean | null): void;
63
90
  trackStxStatusChange(smartTransaction: SmartTransaction, prevSmartTransaction?: SmartTransaction): void;
64
91
  isNewSmartTransaction(smartTransactionUuid: string): boolean;
65
92
  updateSmartTransaction(smartTransaction: SmartTransaction, { networkClientId }?: {
@@ -79,8 +106,8 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
79
106
  submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions, networkClientId, }: {
80
107
  signedTransactions: SignedTransaction[];
81
108
  signedCanceledTransactions: SignedCanceledTransaction[];
82
- transactionMeta?: any;
83
- txParams?: any;
109
+ transactionMeta?: TransactionMeta;
110
+ txParams?: TransactionParams;
84
111
  networkClientId?: NetworkClientId;
85
112
  }): Promise<any>;
86
113
  cancelSmartTransaction(uuid: string, { networkClientId, }?: {