Skip to content

Commit

Permalink
Change SwapsController onNetworkStateChange to networkDidChange (#21923)
Browse files Browse the repository at this point in the history
## **Description**

Fixes bug with the Web3Provider being reinstantiated with the provider
proxy before it was updated to point to the new network. This is
achieved by changing the listened event from `stateChange` to
`networkDidChange`

## **Related issues**

Fixes: #21904

## **Manual testing steps**

1. Change your network to Linea
2. Restart extension
3. Open extension
4. Change network to Mainnet
5. Open swaps
6. Swap 1 WETH for ETH 
7. Should no longer error

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
jiexi authored Nov 22, 2023
1 parent 74624fe commit a9398f3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,9 +1566,12 @@ export default class MetamaskController extends EventEmitter {
this.txController.txGasUtil,
),
networkController: this.networkController,
// This handler is misnamed. We must listen to networkDidChange
// to ensure the network provider has been set by the time we
// try to use it in this controller
onNetworkStateChange: networkControllerMessenger.subscribe.bind(
networkControllerMessenger,
'NetworkController:stateChange',
'NetworkController:networkDidChange',
),
provider: this.provider,
getProviderConfig: () => this.networkController.state.providerConfig,
Expand Down

0 comments on commit a9398f3

Please sign in to comment.