mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Fix swaps controller: update provider after networkIdStore state update (#18670)
* Fix swaps controller: update provider after networkIdStore state update * Listen for changes on networkController.store, instead of networkController.networkIdStore, in the swaps controller * Fix unit tests
This commit is contained in:
parent
5bb87978ac
commit
7ca9383785
@ -113,7 +113,7 @@ export default class SwapsController {
|
||||
fetchTradesInfo = defaultFetchTradesInfo,
|
||||
getCurrentChainId,
|
||||
getEIP1559GasFeeEstimates,
|
||||
onNetworkDidChange,
|
||||
onNetworkStateChange,
|
||||
}) {
|
||||
this.store = new ObservableStore({
|
||||
swapsState: { ...initialState.swapsState },
|
||||
@ -137,7 +137,7 @@ export default class SwapsController {
|
||||
|
||||
this.ethersProvider = new Web3Provider(provider);
|
||||
this._currentNetworkId = networkController.store.getState().networkId;
|
||||
onNetworkDidChange(() => {
|
||||
onNetworkStateChange(() => {
|
||||
const { networkId, networkStatus } = networkController.store.getState();
|
||||
if (
|
||||
networkStatus === NetworkStatus.Available &&
|
||||
|
@ -160,7 +160,7 @@ describe('SwapsController', function () {
|
||||
return new SwapsController({
|
||||
getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
|
||||
networkController: getMockNetworkController(),
|
||||
onNetworkDidChange: sinon.stub(),
|
||||
onNetworkStateChange: sinon.stub(),
|
||||
provider: _provider,
|
||||
getProviderConfig: MOCK_GET_PROVIDER_CONFIG,
|
||||
getTokenRatesState: MOCK_TOKEN_RATES_STORE,
|
||||
@ -208,11 +208,11 @@ describe('SwapsController', function () {
|
||||
|
||||
it('should replace ethers instance when network changes', function () {
|
||||
const networkController = getMockNetworkController();
|
||||
const onNetworkDidChange = sinon.stub();
|
||||
const onNetworkStateChange = sinon.stub();
|
||||
const swapsController = new SwapsController({
|
||||
getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
|
||||
networkController,
|
||||
onNetworkDidChange,
|
||||
onNetworkStateChange,
|
||||
provider,
|
||||
getProviderConfig: MOCK_GET_PROVIDER_CONFIG,
|
||||
getTokenRatesState: MOCK_TOKEN_RATES_STORE,
|
||||
@ -220,7 +220,7 @@ describe('SwapsController', function () {
|
||||
getCurrentChainId: getCurrentChainIdStub,
|
||||
});
|
||||
const currentEthersInstance = swapsController.ethersProvider;
|
||||
const changeNetwork = onNetworkDidChange.getCall(0).args[0];
|
||||
const changeNetwork = onNetworkStateChange.getCall(0).args[0];
|
||||
|
||||
networkController.store.getState.returns({
|
||||
networkId: NETWORK_IDS.MAINNET,
|
||||
@ -238,11 +238,11 @@ describe('SwapsController', function () {
|
||||
|
||||
it('should not replace ethers instance when network changes to loading', function () {
|
||||
const networkController = getMockNetworkController();
|
||||
const onNetworkDidChange = sinon.stub();
|
||||
const onNetworkStateChange = sinon.stub();
|
||||
const swapsController = new SwapsController({
|
||||
getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
|
||||
networkController,
|
||||
onNetworkDidChange,
|
||||
onNetworkStateChange,
|
||||
provider,
|
||||
getProviderConfig: MOCK_GET_PROVIDER_CONFIG,
|
||||
getTokenRatesState: MOCK_TOKEN_RATES_STORE,
|
||||
@ -250,7 +250,7 @@ describe('SwapsController', function () {
|
||||
getCurrentChainId: getCurrentChainIdStub,
|
||||
});
|
||||
const currentEthersInstance = swapsController.ethersProvider;
|
||||
const changeNetwork = onNetworkDidChange.getCall(0).args[0];
|
||||
const changeNetwork = onNetworkStateChange.getCall(0).args[0];
|
||||
|
||||
networkController.store.getState.returns({
|
||||
networkId: null,
|
||||
@ -268,11 +268,11 @@ describe('SwapsController', function () {
|
||||
|
||||
it('should not replace ethers instance when network changes to the same network', function () {
|
||||
const networkController = getMockNetworkController();
|
||||
const onNetworkDidChange = sinon.stub();
|
||||
const onNetworkStateChange = sinon.stub();
|
||||
const swapsController = new SwapsController({
|
||||
getBufferedGasLimit: MOCK_GET_BUFFERED_GAS_LIMIT,
|
||||
networkController,
|
||||
onNetworkDidChange,
|
||||
onNetworkStateChange,
|
||||
provider,
|
||||
getProviderConfig: MOCK_GET_PROVIDER_CONFIG,
|
||||
getTokenRatesState: MOCK_TOKEN_RATES_STORE,
|
||||
@ -280,7 +280,7 @@ describe('SwapsController', function () {
|
||||
getCurrentChainId: getCurrentChainIdStub,
|
||||
});
|
||||
const currentEthersInstance = swapsController.ethersProvider;
|
||||
const changeNetwork = onNetworkDidChange.getCall(0).args[0];
|
||||
const changeNetwork = onNetworkStateChange.getCall(0).args[0];
|
||||
|
||||
networkController.store.getState.returns({
|
||||
networkId: NETWORK_IDS.GOERLI,
|
||||
|
@ -1195,10 +1195,8 @@ export default class MetamaskController extends EventEmitter {
|
||||
this.txController.txGasUtil,
|
||||
),
|
||||
networkController: this.networkController,
|
||||
onNetworkDidChange: networkControllerMessenger.subscribe.bind(
|
||||
networkControllerMessenger,
|
||||
NetworkControllerEventType.NetworkDidChange,
|
||||
),
|
||||
onNetworkStateChange: (listener) =>
|
||||
this.networkController.store.subscribe(listener),
|
||||
provider: this.provider,
|
||||
getProviderConfig: () => this.networkController.store.getState().provider,
|
||||
getTokenRatesState: () => this.tokenRatesController.state,
|
||||
|
Loading…
Reference in New Issue
Block a user