Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/match metamask network on wallet unlock #1384

Merged
merged 9 commits into from
Sep 11, 2019
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Release v5.1.3

### Bug

- Fix network mismatch when using metamask [#1384](https://github.com/MyEtherWallet/MyEtherWallet/pull/1384)

### Devop

- Compress images, Remove unused images and components [#1389](https://github.com/MyEtherWallet/MyEtherWallet/pull/1389)
Expand Down
33 changes: 21 additions & 12 deletions src/layouts/InterfaceLayout/InterfaceLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,25 @@ export default {
}
});
},
checkAndSetNetwork(id) {
if (this.network.type.chainID.toString() !== `${id}`) {
Object.keys(networkTypes).some(net => {
if (
networkTypes[net].chainID.toString() === `${id}` &&
this.Networks[net]
) {
this.$store.dispatch('switchNetwork', this.Networks[net][0]);
return true;
}
});
}
},
matchMetamaskNetwork() {
this.web3.eth.net.getId().then(id => {
this.checkAndSetNetwork(id);
});
window.ethereum.on('networkChanged', netId => {
if (this.network.type.chainID.toString() !== netId) {
Object.keys(networkTypes).some(net => {
if (
networkTypes[net].chainID.toString() === netId &&
this.Networks[net]
) {
this.$store.dispatch('switchNetwork', this.Networks[net][0]);
return true;
}
});
}
this.checkAndSetNetwork(netId);
});
},
setupOnlineEnvironment: web3Utils._.debounce(function() {
Expand All @@ -498,7 +504,10 @@ export default {
if (this.online) {
if (this.account.address !== null) {
if (this.account.identifier === WEB3_TYPE) {
if (window.web3.currentProvider.isMetamask) {
if (
window.web3.currentProvider.isMetaMask ||
window.web3.currentProvider.isMew
) {
this.checkMetamaskAddrChange();
this.matchMetamaskNetwork();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/networks/types/GOERLI.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { GOERLI } from '../tlds';
import goerli from '@/assets/images/icons/network.svg';

export default {
name: 'GöETH',
name: 'GOERLI',
gamalielhere marked this conversation as resolved.
Show resolved Hide resolved
name_long: 'Goerli',
homePage: 'https://github.com/goerli/testnet',
blockExplorerTX: 'https://blockscout.com/eth/goerli/tx/[[txHash]]',
Expand Down
8 changes: 7 additions & 1 deletion src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ const updateNotification = function({ commit, state }, val) {
newNotif[item] = state.notifications[item];
});

newNotif[address][val[1]] = val[2];
const idIndex = newNotif[address].findIndex(entry => entry.id === val[2].id);
if (idIndex > -1) {
newNotif[address][idIndex] = val[2];
} else {
newNotif[address][val[1]] = val[2];
}

commit('UPDATE_NOTIFICATION', newNotif);
};

Expand Down