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

Handle network changes for incoming deeplink and qr code requests. #3650

Merged
merged 13 commits into from
Feb 8, 2022
Merged
24 changes: 24 additions & 0 deletions app/components/Views/Send/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { MAINNET } from '../../../constants/network';
import BigNumber from 'bignumber.js';
import { WalletDevice } from '@metamask/controllers/';
import { getTokenList } from '../../../reducers/tokens';
import { getNetworkTypeById } from '../../../util/networks';

const REVIEW = 'review';
const EDIT = 'edit';
Expand Down Expand Up @@ -352,8 +353,31 @@ class Send extends PureComponent {
* @param switchToChainId - Corresponding chain id for new network
*/
handleNetworkSwitch = (switchToChainId) => {
try {
const networkType = getNetworkTypeById(switchToChainId);
if (networkType) {
const { NetworkController, CurrencyRateController } = Engine.context;
CurrencyRateController.setNativeCurrency('ETH');
NetworkController.setProviderType(networkType);
this.props.showAlert({
isVisible: true,
autodismiss: 5000,
content: 'clipboard-alert',
data: { msg: strings('send.warn_network_change') + networkType },
});
return;
}
} catch (e) {
/**
* If we can't get the network type we don't need to throw an error,
* since it can still be a custom RPC network
*/
}

const { frequentRpcList } = this.props;

const rpc = frequentRpcList.find(({ chainId }) => chainId === switchToChainId);

if (rpc) {
const { rpcUrl, chainId, ticker, nickname } = rpc;
const { NetworkController, CurrencyRateController } = Engine.context;
Expand Down