@@ -2,9 +2,8 @@ import { hexlify } from '@ethersproject/bytes';
22import type {
33 ControllerGetStateAction ,
44 ControllerStateChangeEvent ,
5- RestrictedMessenger ,
65 StateMetadata ,
7- } from '@metamask/base-controller' ;
6+ } from '@metamask/base-controller/next ' ;
87import {
98 query ,
109 safelyExecute ,
@@ -13,6 +12,7 @@ import {
1312 type TraceCallback ,
1413} from '@metamask/controller-utils' ;
1514import EthQuery from '@metamask/eth-query' ;
15+ import type { Messenger } from '@metamask/messenger' ;
1616import type {
1717 NetworkClientId ,
1818 NetworkControllerGetNetworkClientByIdAction ,
@@ -82,7 +82,7 @@ const controllerMetadata: StateMetadata<SmartTransactionsControllerState> = {
8282 smartTransactionsState : {
8383 includeInStateLogs : true ,
8484 persist : false ,
85- anonymous : true ,
85+ includeInDebugSnapshot : true ,
8686 usedInUi : true ,
8787 } ,
8888} ;
@@ -187,12 +187,10 @@ type AllowedEvents = NetworkControllerStateChangeEvent;
187187/**
188188 * The messenger of the {@link SmartTransactionsController}.
189189 */
190- export type SmartTransactionsControllerMessenger = RestrictedMessenger <
190+ export type SmartTransactionsControllerMessenger = Messenger <
191191 typeof controllerName ,
192192 SmartTransactionsControllerActions | AllowedActions ,
193- SmartTransactionsControllerEvents | AllowedEvents ,
194- AllowedActions [ 'type' ] ,
195- AllowedEvents [ 'type' ]
193+ SmartTransactionsControllerEvents | AllowedEvents
196194> ;
197195
198196type SmartTransactionsControllerOptions = {
@@ -294,13 +292,13 @@ export class SmartTransactionsController extends StaticIntervalPollingController
294292
295293 this . initializeSmartTransactionsForChainId ( ) ;
296294
297- this . messagingSystem . subscribe (
295+ this . messenger . subscribe (
298296 'NetworkController:stateChange' ,
299297 ( { selectedNetworkClientId } ) => {
300298 const {
301299 configuration : { chainId } ,
302300 provider,
303- } = this . messagingSystem . call (
301+ } = this . messenger . call (
304302 'NetworkController:getNetworkClientById' ,
305303 selectedNetworkClientId ,
306304 ) ;
@@ -311,9 +309,8 @@ export class SmartTransactionsController extends StaticIntervalPollingController
311309 } ,
312310 ) ;
313311
314- this . messagingSystem . subscribe (
315- `${ controllerName } :stateChange` ,
316- ( currentState ) => this . checkPoll ( currentState ) ,
312+ this . messenger . subscribe ( `${ controllerName } :stateChange` , ( currentState ) =>
313+ this . checkPoll ( currentState ) ,
317314 ) ;
318315 }
319316
@@ -430,7 +427,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
430427 let ethQuery = this . #ethQuery;
431428 let chainId = this . #chainId;
432429 if ( networkClientId ) {
433- const { configuration, provider } = this . messagingSystem . call (
430+ const { configuration, provider } = this . messenger . call (
434431 'NetworkController:getNetworkClientById' ,
435432 networkClientId ,
436433 ) ;
@@ -565,7 +562,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
565562
566563 // We have to emit this event here, because then a txHash is returned to the TransactionController once it's available
567564 // and the #doesTransactionNeedConfirmation function will work properly, since it will find the txHash in the regular transactions list.
568- this . messagingSystem . publish (
565+ this . messenger . publish (
569566 `SmartTransactionsController:smartTransaction` ,
570567 nextSmartTransaction ,
571568 ) ;
@@ -580,9 +577,9 @@ export class SmartTransactionsController extends StaticIntervalPollingController
580577 markRegularTransactionAsFailed ( {
581578 smartTransaction : nextSmartTransaction ,
582579 getRegularTransactions : ( ) =>
583- this . messagingSystem . call ( 'TransactionController:getTransactions' ) ,
580+ this . messenger . call ( 'TransactionController:getTransactions' ) ,
584581 updateTransaction : ( transactionMeta : TransactionMeta , note : string ) =>
585- this . messagingSystem . call (
582+ this . messenger . call (
586583 'TransactionController:updateTransaction' ,
587584 transactionMeta ,
588585 note ,
@@ -650,7 +647,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
650647 if ( ! txHash ) {
651648 return true ;
652649 }
653- const transactions = this . messagingSystem . call (
650+ const transactions = this . messenger . call (
654651 'TransactionController:getTransactions' ,
655652 ) ;
656653 const foundTransaction = transactions ?. find ( ( tx ) => {
@@ -733,7 +730,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
733730 : originalTxMeta ;
734731
735732 if ( this . #doesTransactionNeedConfirmation( txHash ) ) {
736- this . messagingSystem . call (
733+ this . messenger . call (
737734 'TransactionController:confirmExternalTransaction' ,
738735 // TODO: Replace 'as' assertion with correct typing for `txMeta`
739736 txMeta as TransactionMeta ,
@@ -763,7 +760,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
763760 } ) ;
764761 console . error ( 'confirm error' , error ) ;
765762 } finally {
766- this . messagingSystem . publish (
763+ this . messenger . publish (
767764 `SmartTransactionsController:smartTransactionConfirmationDone` ,
768765 smartTransaction ,
769766 ) ;
@@ -829,7 +826,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
829826 transaction : UnsignedTransaction ,
830827 networkClientId : NetworkClientId ,
831828 ) : Promise < UnsignedTransaction > {
832- const nonceLock = await this . messagingSystem . call (
829+ const nonceLock = await this . messenger . call (
833830 'TransactionController:getNonceLock' ,
834831 transaction . from ,
835832 networkClientId ,
@@ -861,8 +858,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
861858 ) : Promise < Fees > {
862859 const selectedNetworkClientId =
863860 networkClientId ??
864- this . messagingSystem . call ( 'NetworkController:getState' )
865- . selectedNetworkClientId ;
861+ this . messenger . call ( 'NetworkController:getState' ) . selectedNetworkClientId ;
866862 const chainId = this . #getChainId( {
867863 networkClientId : selectedNetworkClientId ,
868864 } ) ;
@@ -942,8 +938,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
942938 } ) {
943939 const selectedNetworkClientId =
944940 networkClientId ??
945- this . messagingSystem . call ( 'NetworkController:getState' )
946- . selectedNetworkClientId ;
941+ this . messenger . call ( 'NetworkController:getState' ) . selectedNetworkClientId ;
947942 const chainId = this . #getChainId( {
948943 networkClientId : selectedNetworkClientId ,
949944 } ) ;
@@ -985,7 +980,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
985980 // This should only happen for Swaps. Non-swaps transactions should already have a nonce
986981 if ( requiresNonce ) {
987982 try {
988- nonceLock = await this . messagingSystem . call (
983+ nonceLock = await this . messenger . call (
989984 'TransactionController:getNonceLock' ,
990985 txParams . from ,
991986 selectedNetworkClientId ,
@@ -1041,7 +1036,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
10411036 networkClientId,
10421037 } : { networkClientId ?: NetworkClientId } = { } ) : Hex {
10431038 if ( networkClientId ) {
1044- return this . messagingSystem . call (
1039+ return this . messenger . call (
10451040 'NetworkController:getNetworkClientById' ,
10461041 networkClientId ,
10471042 ) . configuration . chainId ;
@@ -1051,7 +1046,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
10511046 }
10521047
10531048 #getChainIds( ) : Hex [ ] {
1054- const { networkConfigurationsByChainId } = this . messagingSystem . call (
1049+ const { networkConfigurationsByChainId } = this . messenger . call (
10551050 'NetworkController:getState' ,
10561051 ) ;
10571052 return Object . keys ( networkConfigurationsByChainId ) . filter (
@@ -1061,7 +1056,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
10611056 }
10621057
10631058 #getNetworkClientId( { chainId } : { chainId : string } ) : string {
1064- const { networkConfigurationsByChainId } = this . messagingSystem . call (
1059+ const { networkConfigurationsByChainId } = this . messenger . call (
10651060 'NetworkController:getState' ,
10661061 ) ;
10671062 return networkConfigurationsByChainId [ chainId as Hex ] . rpcEndpoints [
@@ -1075,7 +1070,7 @@ export class SmartTransactionsController extends StaticIntervalPollingController
10751070 networkClientId ?: NetworkClientId ;
10761071 } = { } ) : EthQuery {
10771072 if ( networkClientId ) {
1078- const { provider } = this . messagingSystem . call (
1073+ const { provider } = this . messenger . call (
10791074 'NetworkController:getNetworkClientById' ,
10801075 networkClientId ,
10811076 ) ;
0 commit comments