@@ -14,6 +14,7 @@ import EthQuery from '@metamask/eth-query';
14
14
import type {
15
15
NetworkClientId ,
16
16
NetworkControllerGetNetworkClientByIdAction ,
17
+ NetworkControllerGetStateAction ,
17
18
NetworkControllerStateChangeEvent ,
18
19
} from '@metamask/network-controller' ;
19
20
import { StaticIntervalPollingController } from '@metamask/polling-controller' ;
@@ -138,7 +139,9 @@ export type SmartTransactionsControllerGetStateAction =
138
139
export type SmartTransactionsControllerActions =
139
140
SmartTransactionsControllerGetStateAction ;
140
141
141
- export type AllowedActions = NetworkControllerGetNetworkClientByIdAction ;
142
+ type AllowedActions =
143
+ | NetworkControllerGetNetworkClientByIdAction
144
+ | NetworkControllerGetStateAction ;
142
145
143
146
export type SmartTransactionsControllerStateChangeEvent =
144
147
ControllerStateChangeEvent <
@@ -164,7 +167,7 @@ export type SmartTransactionsControllerEvents =
164
167
| SmartTransactionsControllerSmartTransactionEvent
165
168
| SmartTransactionsControllerSmartTransactionConfirmationDoneEvent ;
166
169
167
- export type AllowedEvents = NetworkControllerStateChangeEvent ;
170
+ type AllowedEvents = NetworkControllerStateChangeEvent ;
168
171
169
172
/**
170
173
* The messenger of the {@link SmartTransactionsController}.
@@ -763,6 +766,7 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
763
766
status : calculateStatus ( stxStatus ) ,
764
767
cancellable : isSmartTransactionCancellable ( stxStatus ) ,
765
768
uuid,
769
+ networkClientId,
766
770
} ;
767
771
await this . #createOrUpdateSmartTransaction( smartTransaction , {
768
772
chainId,
@@ -773,10 +777,14 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
773
777
return data ;
774
778
}
775
779
776
- async addNonceToTransaction (
780
+ async # addNonceToTransaction(
777
781
transaction : UnsignedTransaction ,
782
+ networkClientId : NetworkClientId ,
778
783
) : Promise < UnsignedTransaction > {
779
- const nonceLock = await this . #getNonceLock( transaction . from ) ;
784
+ const nonceLock = await this . #getNonceLock(
785
+ transaction . from ,
786
+ networkClientId ,
787
+ ) ;
780
788
const nonce = nonceLock . nextNonce ;
781
789
nonceLock . releaseLock ( ) ;
782
790
return {
@@ -802,12 +810,18 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
802
810
approvalTx ?: UnsignedTransaction ,
803
811
{ networkClientId } : { networkClientId ?: NetworkClientId } = { } ,
804
812
) : Promise < Fees > {
805
- const chainId = this . #getChainId( { networkClientId } ) ;
813
+ const selectedNetworkClientId =
814
+ networkClientId ??
815
+ this . messagingSystem . call ( 'NetworkController:getState' )
816
+ . selectedNetworkClientId ;
817
+ const chainId = this . #getChainId( {
818
+ networkClientId : selectedNetworkClientId ,
819
+ } ) ;
806
820
const transactions = [ ] ;
807
821
let unsignedTradeTransactionWithNonce ;
808
822
if ( approvalTx ) {
809
823
const unsignedApprovalTransactionWithNonce =
810
- await this . addNonceToTransaction ( approvalTx ) ;
824
+ await this . # addNonceToTransaction( approvalTx , selectedNetworkClientId ) ;
811
825
transactions . push ( unsignedApprovalTransactionWithNonce ) ;
812
826
unsignedTradeTransactionWithNonce = {
813
827
...tradeTx ,
@@ -817,8 +831,9 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
817
831
} else if ( tradeTx . nonce ) {
818
832
unsignedTradeTransactionWithNonce = tradeTx ;
819
833
} else {
820
- unsignedTradeTransactionWithNonce = await this . addNonceToTransaction (
834
+ unsignedTradeTransactionWithNonce = await this . # addNonceToTransaction(
821
835
tradeTx ,
836
+ selectedNetworkClientId ,
822
837
) ;
823
838
}
824
839
transactions . push ( unsignedTradeTransactionWithNonce ) ;
@@ -875,8 +890,16 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
875
890
txParams ?: TransactionParams ;
876
891
networkClientId ?: NetworkClientId ;
877
892
} ) {
878
- const chainId = this . #getChainId( { networkClientId } ) ;
879
- const ethQuery = this . #getEthQuery( { networkClientId } ) ;
893
+ const selectedNetworkClientId =
894
+ networkClientId ??
895
+ this . messagingSystem . call ( 'NetworkController:getState' )
896
+ . selectedNetworkClientId ;
897
+ const chainId = this . #getChainId( {
898
+ networkClientId : selectedNetworkClientId ,
899
+ } ) ;
900
+ const ethQuery = this . #getEthQuery( {
901
+ networkClientId : selectedNetworkClientId ,
902
+ } ) ;
880
903
const data = await this . #fetch(
881
904
getAPIRequestURL ( APIType . SUBMIT_TRANSACTIONS , chainId ) ,
882
905
{
@@ -904,7 +927,10 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
904
927
let nonceDetails = { } ;
905
928
906
929
if ( requiresNonce ) {
907
- nonceLock = await this . #getNonceLock( txParams . from ) ;
930
+ nonceLock = await this . #getNonceLock(
931
+ txParams . from ,
932
+ selectedNetworkClientId ,
933
+ ) ;
908
934
nonce = hexlify ( nonceLock . nextNonce ) ;
909
935
nonceDetails = nonceLock . nonceDetails ;
910
936
txParams . nonce ??= nonce ;
@@ -928,6 +954,7 @@ export default class SmartTransactionsController extends StaticIntervalPollingCo
928
954
cancellable : true ,
929
955
type : transactionMeta ?. type ?? 'swap' ,
930
956
transactionId : transactionMeta ?. id ,
957
+ networkClientId : selectedNetworkClientId ,
931
958
} ,
932
959
{ chainId, ethQuery } ,
933
960
) ;
0 commit comments