@@ -12,6 +12,12 @@ import {
1212 RpcEndpointType ,
1313 type NetworkState ,
1414} from '@metamask/network-controller' ;
15+ import type {
16+ TransactionControllerConfirmExternalTransactionAction ,
17+ TransactionControllerGetNonceLockAction ,
18+ TransactionControllerGetTransactionsAction ,
19+ TransactionControllerUpdateTransactionAction ,
20+ } from '@metamask/transaction-controller' ;
1521import {
1622 type TransactionParams ,
1723 TransactionStatus ,
@@ -733,9 +739,7 @@ describe('SmartTransactionsController', () => {
733739
734740 await withController (
735741 {
736- options : {
737- getNonceLock : mockGetNonceLock ,
738- } ,
742+ getNonceLock : mockGetNonceLock ,
739743 } ,
740744 async ( { controller } ) => {
741745 const signedTransaction = createSignedTransaction ( ) ;
@@ -802,9 +806,7 @@ describe('SmartTransactionsController', () => {
802806
803807 await withController (
804808 {
805- options : {
806- getNonceLock : mockGetNonceLock ,
807- } ,
809+ getNonceLock : mockGetNonceLock ,
808810 } ,
809811 async ( { controller } ) => {
810812 const signedTransaction = createSignedTransaction ( ) ;
@@ -859,9 +861,7 @@ describe('SmartTransactionsController', () => {
859861
860862 await withController (
861863 {
862- options : {
863- getNonceLock : mockGetNonceLock ,
864- } ,
864+ getNonceLock : mockGetNonceLock ,
865865 } ,
866866 async ( { controller } ) => {
867867 const signedTransaction = createSignedTransaction ( ) ;
@@ -1240,9 +1240,9 @@ describe('SmartTransactionsController', () => {
12401240 } ,
12411241 } ,
12421242 } ,
1243- confirmExternalTransaction : confirmExternalTransactionSpy ,
1244- getTransactions : getRegularTransactionsSpy ,
12451243 } ,
1244+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1245+ getTransactions : getRegularTransactionsSpy ,
12461246 } ,
12471247 async ( { controller } ) => {
12481248 const updateTransaction = {
@@ -1299,9 +1299,9 @@ describe('SmartTransactionsController', () => {
12991299 } ,
13001300 } ,
13011301 } ,
1302- confirmExternalTransaction : confirmExternalTransactionSpy ,
1303- getTransactions : getRegularTransactionsSpy ,
13041302 } ,
1303+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1304+ getTransactions : getRegularTransactionsSpy ,
13051305 } ,
13061306 async ( { controller } ) => {
13071307 const updateTransaction = {
@@ -1358,9 +1358,9 @@ describe('SmartTransactionsController', () => {
13581358 } ,
13591359 } ,
13601360 } ,
1361- confirmExternalTransaction : confirmExternalTransactionSpy ,
1362- getTransactions : getRegularTransactionsSpy ,
13631361 } ,
1362+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1363+ getTransactions : getRegularTransactionsSpy ,
13641364 } ,
13651365 async ( { controller } ) => {
13661366 const updateTransaction = {
@@ -1417,9 +1417,9 @@ describe('SmartTransactionsController', () => {
14171417 } ,
14181418 } ,
14191419 } ,
1420- confirmExternalTransaction : confirmExternalTransactionSpy ,
1421- getTransactions : getRegularTransactionsSpy ,
14221420 } ,
1421+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1422+ getTransactions : getRegularTransactionsSpy ,
14231423 } ,
14241424 async ( { controller } ) => {
14251425 const updateTransaction = {
@@ -1476,9 +1476,9 @@ describe('SmartTransactionsController', () => {
14761476 } ,
14771477 } ,
14781478 } ,
1479- confirmExternalTransaction : confirmExternalTransactionSpy ,
1480- getTransactions : getRegularTransactionsSpy ,
14811479 } ,
1480+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1481+ getTransactions : getRegularTransactionsSpy ,
14821482 } ,
14831483 async ( { controller } ) => {
14841484 const updateTransaction = {
@@ -1520,24 +1520,11 @@ describe('SmartTransactionsController', () => {
15201520 await withController (
15211521 {
15221522 options : {
1523- updateTransaction : mockUpdateTransaction ,
15241523 getFeatureFlags : ( ) => ( {
15251524 smartTransactions : {
15261525 mobileReturnTxHashAsap : true ,
15271526 } ,
15281527 } ) ,
1529- getTransactions : ( ) => [
1530- {
1531- id : 'test-tx-id' ,
1532- status : TransactionStatus . submitted ,
1533- chainId : '0x1' ,
1534- time : 123 ,
1535- txParams : {
1536- from : '0x123' ,
1537- } ,
1538- networkClientId : NetworkType . mainnet ,
1539- } ,
1540- ] ,
15411528 state : {
15421529 smartTransactionsState : {
15431530 ...defaultState . smartTransactionsState ,
@@ -1547,6 +1534,19 @@ describe('SmartTransactionsController', () => {
15471534 } ,
15481535 } ,
15491536 } ,
1537+ updateTransaction : mockUpdateTransaction ,
1538+ getTransactions : ( ) => [
1539+ {
1540+ id : 'test-tx-id' ,
1541+ status : TransactionStatus . submitted ,
1542+ chainId : '0x1' ,
1543+ time : 123 ,
1544+ txParams : {
1545+ from : '0x123' ,
1546+ } ,
1547+ networkClientId : NetworkType . mainnet ,
1548+ } ,
1549+ ] ,
15501550 } ,
15511551 async ( { controller } ) => {
15521552 const smartTransaction = {
@@ -1583,25 +1583,25 @@ describe('SmartTransactionsController', () => {
15831583 await withController (
15841584 {
15851585 options : {
1586- updateTransaction : mockUpdateTransaction ,
15871586 getFeatureFlags : ( ) => ( {
15881587 smartTransactions : {
15891588 mobileReturnTxHashAsap : false ,
15901589 } ,
15911590 } ) ,
1592- getTransactions : ( ) => [
1593- {
1594- id : 'test-tx-id' ,
1595- status : TransactionStatus . submitted ,
1596- chainId : '0x1' ,
1597- time : 123 ,
1598- txParams : {
1599- from : '0x123' ,
1600- } ,
1601- networkClientId : NetworkType . mainnet ,
1602- } ,
1603- ] ,
16041591 } ,
1592+ updateTransaction : mockUpdateTransaction ,
1593+ getTransactions : ( ) => [
1594+ {
1595+ id : 'test-tx-id' ,
1596+ status : TransactionStatus . submitted ,
1597+ chainId : '0x1' ,
1598+ time : 123 ,
1599+ txParams : {
1600+ from : '0x123' ,
1601+ } ,
1602+ networkClientId : NetworkType . mainnet ,
1603+ } ,
1604+ ] ,
16051605 } ,
16061606 async ( { controller } ) => {
16071607 const smartTransaction = {
@@ -1623,14 +1623,14 @@ describe('SmartTransactionsController', () => {
16231623 await withController (
16241624 {
16251625 options : {
1626- updateTransaction : mockUpdateTransaction ,
16271626 getFeatureFlags : ( ) => ( {
16281627 smartTransactions : {
16291628 mobileReturnTxHashAsap : true ,
16301629 } ,
16311630 } ) ,
1632- getTransactions : ( ) => [ ] ,
16331631 } ,
1632+ updateTransaction : mockUpdateTransaction ,
1633+ getTransactions : ( ) => [ ] ,
16341634 } ,
16351635 async ( { controller } ) => {
16361636 const smartTransaction = {
@@ -1651,25 +1651,25 @@ describe('SmartTransactionsController', () => {
16511651 await withController (
16521652 {
16531653 options : {
1654- updateTransaction : mockUpdateTransaction ,
16551654 getFeatureFlags : ( ) => ( {
16561655 smartTransactions : {
16571656 mobileReturnTxHashAsap : true ,
16581657 } ,
16591658 } ) ,
1660- getTransactions : ( ) => [
1661- {
1662- id : 'test-tx-id' ,
1663- status : TransactionStatus . submitted ,
1664- chainId : '0x1' ,
1665- time : 123 ,
1666- txParams : {
1667- from : '0x123' ,
1668- } ,
1669- networkClientId : NetworkType . mainnet ,
1670- } ,
1671- ] ,
16721659 } ,
1660+ updateTransaction : mockUpdateTransaction ,
1661+ getTransactions : ( ) => [
1662+ {
1663+ id : 'test-tx-id' ,
1664+ status : TransactionStatus . submitted ,
1665+ chainId : '0x1' ,
1666+ time : 123 ,
1667+ txParams : {
1668+ from : '0x123' ,
1669+ } ,
1670+ networkClientId : NetworkType . mainnet ,
1671+ } ,
1672+ ] ,
16731673 } ,
16741674 async ( { controller } ) => {
16751675 const smartTransaction = {
@@ -2683,6 +2683,10 @@ type WithControllerOptions = {
26832683 options ?: Partial <
26842684 ConstructorParameters < typeof SmartTransactionsController > [ 0 ]
26852685 > ;
2686+ getNonceLock ?: TransactionControllerGetNonceLockAction [ 'handler' ] ;
2687+ confirmExternalTransaction ?: TransactionControllerConfirmExternalTransactionAction [ 'handler' ] ;
2688+ getTransactions ?: TransactionControllerGetTransactionsAction [ 'handler' ] ;
2689+ updateTransaction ?: TransactionControllerUpdateTransactionAction [ 'handler' ] ;
26862690} ;
26872691
26882692type WithControllerArgs < ReturnValue > =
@@ -2702,11 +2706,25 @@ async function withController<ReturnValue>(
27022706 ...args : WithControllerArgs < ReturnValue >
27032707) : Promise < ReturnValue > {
27042708 const [ { ...rest } , fn ] = args . length === 2 ? args : [ { } , args [ 0 ] ] ;
2705- const { options } = rest ;
2709+ const {
2710+ options,
2711+ getNonceLock = jest . fn ( ) . mockResolvedValue ( {
2712+ nextNonce : 42 ,
2713+ releaseLock : jest . fn ( ) ,
2714+ } ) ,
2715+ confirmExternalTransaction = jest . fn ( ) ,
2716+ getTransactions = jest . fn ( ) ,
2717+ updateTransaction = jest . fn ( ) ,
2718+ } = rest ;
2719+
27062720 const controllerMessenger = new Messenger <
27072721 | SmartTransactionsControllerActions
27082722 | NetworkControllerGetNetworkClientByIdAction
2709- | NetworkControllerGetStateAction ,
2723+ | NetworkControllerGetStateAction
2724+ | TransactionControllerGetNonceLockAction
2725+ | TransactionControllerConfirmExternalTransactionAction
2726+ | TransactionControllerGetTransactionsAction
2727+ | TransactionControllerUpdateTransactionAction ,
27102728 SmartTransactionsControllerEvents | NetworkControllerStateChangeEvent
27112729 > ( ) ;
27122730 controllerMessenger . registerActionHandler (
@@ -2732,7 +2750,6 @@ async function withController<ReturnValue>(
27322750 }
27332751 } ) ,
27342752 ) ;
2735-
27362753 controllerMessenger . registerActionHandler (
27372754 'NetworkController:getState' ,
27382755 jest . fn ( ) . mockReturnValue ( {
@@ -2771,25 +2788,39 @@ async function withController<ReturnValue>(
27712788 } ,
27722789 } ) ,
27732790 ) ;
2791+ controllerMessenger . registerActionHandler (
2792+ 'TransactionController:getNonceLock' ,
2793+ getNonceLock ,
2794+ ) ;
2795+ controllerMessenger . registerActionHandler (
2796+ 'TransactionController:confirmExternalTransaction' ,
2797+ confirmExternalTransaction ,
2798+ ) ;
2799+ controllerMessenger . registerActionHandler (
2800+ 'TransactionController:getTransactions' ,
2801+ getTransactions ,
2802+ ) ;
2803+ controllerMessenger . registerActionHandler (
2804+ 'TransactionController:updateTransaction' ,
2805+ updateTransaction ,
2806+ ) ;
27742807
27752808 const messenger = controllerMessenger . getRestricted ( {
27762809 name : 'SmartTransactionsController' ,
27772810 allowedActions : [
27782811 'NetworkController:getNetworkClientById' ,
27792812 'NetworkController:getState' ,
2813+ 'TransactionController:getNonceLock' ,
2814+ 'TransactionController:confirmExternalTransaction' ,
2815+ 'TransactionController:getTransactions' ,
2816+ 'TransactionController:updateTransaction' ,
27802817 ] ,
27812818 allowedEvents : [ 'NetworkController:stateChange' ] ,
27822819 } ) ;
27832820
27842821 const controller = new SmartTransactionsController ( {
27852822 messenger,
27862823 clientId : ClientId . Mobile ,
2787- getNonceLock : jest . fn ( ) . mockResolvedValue ( {
2788- nextNonce : 42 ,
2789- releaseLock : jest . fn ( ) ,
2790- } ) ,
2791- confirmExternalTransaction : jest . fn ( ) ,
2792- getTransactions : jest . fn ( ) ,
27932824 trackMetaMetricsEvent : trackMetaMetricsEventSpy ,
27942825 getMetaMetricsProps : jest . fn ( async ( ) => {
27952826 return Promise . resolve ( {
@@ -2799,7 +2830,6 @@ async function withController<ReturnValue>(
27992830 } ) ;
28002831 } ) ,
28012832 getFeatureFlags : jest . fn ( ) ,
2802- updateTransaction : jest . fn ( ) ,
28032833 ...options ,
28042834 } ) ;
28052835
0 commit comments