@@ -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 ,
@@ -732,9 +738,7 @@ describe('SmartTransactionsController', () => {
732738
733739 await withController (
734740 {
735- options : {
736- getNonceLock : mockGetNonceLock ,
737- } ,
741+ getNonceLock : mockGetNonceLock ,
738742 } ,
739743 async ( { controller } ) => {
740744 const signedTransaction = createSignedTransaction ( ) ;
@@ -801,9 +805,7 @@ describe('SmartTransactionsController', () => {
801805
802806 await withController (
803807 {
804- options : {
805- getNonceLock : mockGetNonceLock ,
806- } ,
808+ getNonceLock : mockGetNonceLock ,
807809 } ,
808810 async ( { controller } ) => {
809811 const signedTransaction = createSignedTransaction ( ) ;
@@ -858,9 +860,7 @@ describe('SmartTransactionsController', () => {
858860
859861 await withController (
860862 {
861- options : {
862- getNonceLock : mockGetNonceLock ,
863- } ,
863+ getNonceLock : mockGetNonceLock ,
864864 } ,
865865 async ( { controller } ) => {
866866 const signedTransaction = createSignedTransaction ( ) ;
@@ -1239,9 +1239,9 @@ describe('SmartTransactionsController', () => {
12391239 } ,
12401240 } ,
12411241 } ,
1242- confirmExternalTransaction : confirmExternalTransactionSpy ,
1243- getTransactions : getRegularTransactionsSpy ,
12441242 } ,
1243+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1244+ getTransactions : getRegularTransactionsSpy ,
12451245 } ,
12461246 async ( { controller } ) => {
12471247 const updateTransaction = {
@@ -1298,9 +1298,9 @@ describe('SmartTransactionsController', () => {
12981298 } ,
12991299 } ,
13001300 } ,
1301- confirmExternalTransaction : confirmExternalTransactionSpy ,
1302- getTransactions : getRegularTransactionsSpy ,
13031301 } ,
1302+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1303+ getTransactions : getRegularTransactionsSpy ,
13041304 } ,
13051305 async ( { controller } ) => {
13061306 const updateTransaction = {
@@ -1357,9 +1357,9 @@ describe('SmartTransactionsController', () => {
13571357 } ,
13581358 } ,
13591359 } ,
1360- confirmExternalTransaction : confirmExternalTransactionSpy ,
1361- getTransactions : getRegularTransactionsSpy ,
13621360 } ,
1361+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1362+ getTransactions : getRegularTransactionsSpy ,
13631363 } ,
13641364 async ( { controller } ) => {
13651365 const updateTransaction = {
@@ -1416,9 +1416,9 @@ describe('SmartTransactionsController', () => {
14161416 } ,
14171417 } ,
14181418 } ,
1419- confirmExternalTransaction : confirmExternalTransactionSpy ,
1420- getTransactions : getRegularTransactionsSpy ,
14211419 } ,
1420+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1421+ getTransactions : getRegularTransactionsSpy ,
14221422 } ,
14231423 async ( { controller } ) => {
14241424 const updateTransaction = {
@@ -1475,9 +1475,9 @@ describe('SmartTransactionsController', () => {
14751475 } ,
14761476 } ,
14771477 } ,
1478- confirmExternalTransaction : confirmExternalTransactionSpy ,
1479- getTransactions : getRegularTransactionsSpy ,
14801478 } ,
1479+ confirmExternalTransaction : confirmExternalTransactionSpy ,
1480+ getTransactions : getRegularTransactionsSpy ,
14811481 } ,
14821482 async ( { controller } ) => {
14831483 const updateTransaction = {
@@ -1519,24 +1519,11 @@ describe('SmartTransactionsController', () => {
15191519 await withController (
15201520 {
15211521 options : {
1522- updateTransaction : mockUpdateTransaction ,
15231522 getFeatureFlags : ( ) => ( {
15241523 smartTransactions : {
15251524 mobileReturnTxHashAsap : true ,
15261525 } ,
15271526 } ) ,
1528- getTransactions : ( ) => [
1529- {
1530- id : 'test-tx-id' ,
1531- status : TransactionStatus . submitted ,
1532- chainId : '0x1' ,
1533- time : 123 ,
1534- txParams : {
1535- from : '0x123' ,
1536- } ,
1537- networkClientId : NetworkType . mainnet ,
1538- } ,
1539- ] ,
15401527 state : {
15411528 smartTransactionsState : {
15421529 ...defaultState . smartTransactionsState ,
@@ -1546,6 +1533,19 @@ describe('SmartTransactionsController', () => {
15461533 } ,
15471534 } ,
15481535 } ,
1536+ updateTransaction : mockUpdateTransaction ,
1537+ getTransactions : ( ) => [
1538+ {
1539+ id : 'test-tx-id' ,
1540+ status : TransactionStatus . submitted ,
1541+ chainId : '0x1' ,
1542+ time : 123 ,
1543+ txParams : {
1544+ from : '0x123' ,
1545+ } ,
1546+ networkClientId : NetworkType . mainnet ,
1547+ } ,
1548+ ] ,
15491549 } ,
15501550 async ( { controller } ) => {
15511551 const smartTransaction = {
@@ -1582,25 +1582,25 @@ describe('SmartTransactionsController', () => {
15821582 await withController (
15831583 {
15841584 options : {
1585- updateTransaction : mockUpdateTransaction ,
15861585 getFeatureFlags : ( ) => ( {
15871586 smartTransactions : {
15881587 mobileReturnTxHashAsap : false ,
15891588 } ,
15901589 } ) ,
1591- getTransactions : ( ) => [
1592- {
1593- id : 'test-tx-id' ,
1594- status : TransactionStatus . submitted ,
1595- chainId : '0x1' ,
1596- time : 123 ,
1597- txParams : {
1598- from : '0x123' ,
1599- } ,
1600- networkClientId : NetworkType . mainnet ,
1601- } ,
1602- ] ,
16031590 } ,
1591+ updateTransaction : mockUpdateTransaction ,
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+ ] ,
16041604 } ,
16051605 async ( { controller } ) => {
16061606 const smartTransaction = {
@@ -1622,14 +1622,14 @@ describe('SmartTransactionsController', () => {
16221622 await withController (
16231623 {
16241624 options : {
1625- updateTransaction : mockUpdateTransaction ,
16261625 getFeatureFlags : ( ) => ( {
16271626 smartTransactions : {
16281627 mobileReturnTxHashAsap : true ,
16291628 } ,
16301629 } ) ,
1631- getTransactions : ( ) => [ ] ,
16321630 } ,
1631+ updateTransaction : mockUpdateTransaction ,
1632+ getTransactions : ( ) => [ ] ,
16331633 } ,
16341634 async ( { controller } ) => {
16351635 const smartTransaction = {
@@ -1650,25 +1650,25 @@ describe('SmartTransactionsController', () => {
16501650 await withController (
16511651 {
16521652 options : {
1653- updateTransaction : mockUpdateTransaction ,
16541653 getFeatureFlags : ( ) => ( {
16551654 smartTransactions : {
16561655 mobileReturnTxHashAsap : true ,
16571656 } ,
16581657 } ) ,
1659- getTransactions : ( ) => [
1660- {
1661- id : 'test-tx-id' ,
1662- status : TransactionStatus . submitted ,
1663- chainId : '0x1' ,
1664- time : 123 ,
1665- txParams : {
1666- from : '0x123' ,
1667- } ,
1668- networkClientId : NetworkType . mainnet ,
1669- } ,
1670- ] ,
16711658 } ,
1659+ updateTransaction : mockUpdateTransaction ,
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+ ] ,
16721672 } ,
16731673 async ( { controller } ) => {
16741674 const smartTransaction = {
@@ -2682,6 +2682,10 @@ type WithControllerOptions = {
26822682 options ?: Partial <
26832683 ConstructorParameters < typeof SmartTransactionsController > [ 0 ]
26842684 > ;
2685+ getNonceLock ?: TransactionControllerGetNonceLockAction [ 'handler' ] ;
2686+ confirmExternalTransaction ?: TransactionControllerConfirmExternalTransactionAction [ 'handler' ] ;
2687+ getTransactions ?: TransactionControllerGetTransactionsAction [ 'handler' ] ;
2688+ updateTransaction ?: TransactionControllerUpdateTransactionAction [ 'handler' ] ;
26852689} ;
26862690
26872691type WithControllerArgs < ReturnValue > =
@@ -2701,11 +2705,25 @@ async function withController<ReturnValue>(
27012705 ...args : WithControllerArgs < ReturnValue >
27022706) : Promise < ReturnValue > {
27032707 const [ { ...rest } , fn ] = args . length === 2 ? args : [ { } , args [ 0 ] ] ;
2704- const { options } = rest ;
2708+ const {
2709+ options,
2710+ getNonceLock = jest . fn ( ) . mockResolvedValue ( {
2711+ nextNonce : 42 ,
2712+ releaseLock : jest . fn ( ) ,
2713+ } ) ,
2714+ confirmExternalTransaction = jest . fn ( ) ,
2715+ getTransactions = jest . fn ( ) ,
2716+ updateTransaction = jest . fn ( ) ,
2717+ } = rest ;
2718+
27052719 const controllerMessenger = new Messenger <
27062720 | SmartTransactionsControllerActions
27072721 | NetworkControllerGetNetworkClientByIdAction
2708- | NetworkControllerGetStateAction ,
2722+ | NetworkControllerGetStateAction
2723+ | TransactionControllerGetNonceLockAction
2724+ | TransactionControllerConfirmExternalTransactionAction
2725+ | TransactionControllerGetTransactionsAction
2726+ | TransactionControllerUpdateTransactionAction ,
27092727 SmartTransactionsControllerEvents | NetworkControllerStateChangeEvent
27102728 > ( ) ;
27112729 controllerMessenger . registerActionHandler (
@@ -2731,7 +2749,6 @@ async function withController<ReturnValue>(
27312749 }
27322750 } ) ,
27332751 ) ;
2734-
27352752 controllerMessenger . registerActionHandler (
27362753 'NetworkController:getState' ,
27372754 jest . fn ( ) . mockReturnValue ( {
@@ -2770,25 +2787,39 @@ async function withController<ReturnValue>(
27702787 } ,
27712788 } ) ,
27722789 ) ;
2790+ controllerMessenger . registerActionHandler (
2791+ 'TransactionController:getNonceLock' ,
2792+ getNonceLock ,
2793+ ) ;
2794+ controllerMessenger . registerActionHandler (
2795+ 'TransactionController:confirmExternalTransaction' ,
2796+ confirmExternalTransaction ,
2797+ ) ;
2798+ controllerMessenger . registerActionHandler (
2799+ 'TransactionController:getTransactions' ,
2800+ getTransactions ,
2801+ ) ;
2802+ controllerMessenger . registerActionHandler (
2803+ 'TransactionController:updateTransaction' ,
2804+ updateTransaction ,
2805+ ) ;
27732806
27742807 const messenger = controllerMessenger . getRestricted ( {
27752808 name : 'SmartTransactionsController' ,
27762809 allowedActions : [
27772810 'NetworkController:getNetworkClientById' ,
27782811 'NetworkController:getState' ,
2812+ 'TransactionController:getNonceLock' ,
2813+ 'TransactionController:confirmExternalTransaction' ,
2814+ 'TransactionController:getTransactions' ,
2815+ 'TransactionController:updateTransaction' ,
27792816 ] ,
27802817 allowedEvents : [ 'NetworkController:stateChange' ] ,
27812818 } ) ;
27822819
27832820 const controller = new SmartTransactionsController ( {
27842821 messenger,
27852822 clientId : ClientId . Mobile ,
2786- getNonceLock : jest . fn ( ) . mockResolvedValue ( {
2787- nextNonce : 42 ,
2788- releaseLock : jest . fn ( ) ,
2789- } ) ,
2790- confirmExternalTransaction : jest . fn ( ) ,
2791- getTransactions : jest . fn ( ) ,
27922823 trackMetaMetricsEvent : trackMetaMetricsEventSpy ,
27932824 getMetaMetricsProps : jest . fn ( async ( ) => {
27942825 return Promise . resolve ( {
@@ -2798,7 +2829,6 @@ async function withController<ReturnValue>(
27982829 } ) ;
27992830 } ) ,
28002831 getFeatureFlags : jest . fn ( ) ,
2801- updateTransaction : jest . fn ( ) ,
28022832 ...options ,
28032833 } ) ;
28042834
0 commit comments