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

[FIX] Release - Error message for missing chain ID in deeplink #3738

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/constants/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// NETWORK ERRORS
export const NETWORK_ERROR_MISSING_NETWORK_ID = 'Missing network id';
export const NETWORK_ERROR_UNKNOWN_NETWORK_ID = 'Unknown network with id';
export const NETWORK_ERROR_MISSING_CHAIN_ID = 'Missing chain id';
14 changes: 10 additions & 4 deletions app/core/DeeplinkManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import WalletConnect from '../core/WalletConnect';
import AppConstants from './AppConstants';
import Engine from './Engine';
import { generateApproveData } from '../util/transactions';
import { NETWORK_ERROR_MISSING_NETWORK_ID } from '../constants/error';
import { strings } from '../../locales/i18n';
import { getNetworkTypeById } from '../util/networks';
import { WalletDevice } from '@metamask/controllers/';
Expand Down Expand Up @@ -121,10 +122,15 @@ class DeeplinkManager {
TransactionController.addTransaction(txParams, origin, WalletDevice.MM_MOBILE);
}
} catch (e) {
Alert.alert(
strings('send.network_not_found_title'),
strings('send.network_not_found_description', { chain_id: ethUrl.chain_id })
);
let alertMessage;
switch (e.message) {
case NETWORK_ERROR_MISSING_NETWORK_ID:
alertMessage = strings('send.network_missing_id');
break;
default:
alertMessage = strings('send.network_not_found_description', { chain_id: ethUrl.chain_id });
}
Alert.alert(strings('send.network_not_found_title'), alertMessage);
}
}

Expand Down
11 changes: 8 additions & 3 deletions app/util/networks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { colors } from '../../styles/common';
import URL from 'url-parse';
import AppConstants from '../../core/AppConstants';
import { MAINNET, ROPSTEN, KOVAN, RINKEBY, GOERLI, RPC } from '../../../app/constants/network';
import {
NETWORK_ERROR_MISSING_NETWORK_ID,
NETWORK_ERROR_UNKNOWN_NETWORK_ID,
NETWORK_ERROR_MISSING_CHAIN_ID,
} from '../../../app/constants/error';
import { util } from '@metamask/controllers';
import Engine from '../../core/Engine';
import { toLowerCaseEquals } from './../general';
Expand Down Expand Up @@ -88,19 +93,19 @@ export const getNetworkName = (id) => NetworkListKeys.find((key) => NetworkList[

export function getNetworkTypeById(id) {
if (!id) {
throw new Error('Missing network Id');
throw new Error(NETWORK_ERROR_MISSING_NETWORK_ID);
}
const network = NetworkListKeys.filter((key) => NetworkList[key].networkId === parseInt(id, 10));
if (network.length > 0) {
return network[0];
}

throw new Error(`Unknown network with id ${id}`);
throw new Error(`${NETWORK_ERROR_UNKNOWN_NETWORK_ID} ${id}`);
}

export function getDefaultNetworkByChainId(chainId) {
if (!chainId) {
throw new Error('Missing chain Id');
throw new Error(NETWORK_ERROR_MISSING_CHAIN_ID);
}

let returnNetwork;
Expand Down
5 changes: 3 additions & 2 deletions app/util/networks/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isMainNet, getNetworkName, getAllNetworks, getNetworkTypeById } from '.';
import { MAINNET, ROPSTEN, GOERLI, RPC, KOVAN } from '../../../app/constants/network';
import { NETWORK_ERROR_MISSING_NETWORK_ID, NETWORK_ERROR_UNKNOWN_NETWORK_ID } from '../../../app/constants/error';

describe('getAllNetworks', () => {
const allNetworks = getAllNetworks();
Expand Down Expand Up @@ -69,15 +70,15 @@ describe('getNetworkTypeById', () => {
try {
getNetworkTypeById();
} catch (error) {
expect(error.message).toEqual('Missing network Id');
expect(error.message).toEqual(NETWORK_ERROR_MISSING_NETWORK_ID);
}
});
it('should fail if network Id is unknown', () => {
const id = 9999;
try {
getNetworkTypeById(id);
} catch (error) {
expect(error.message).toEqual(`Unknown network with id ${id}`);
expect(error.message).toEqual(`${NETWORK_ERROR_UNKNOWN_NETWORK_ID} ${id}`);
}
});
});
3 changes: 2 additions & 1 deletion locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
"amount": "Amount",
"confirm": "Confirm",
"network_not_found_title": "Network not found",
"network_not_found_description": "Network with chain id {{chain_id}} not found in your wallet. Please add the network first."
"network_not_found_description": "Network with chain id {{chain_id}} not found in your wallet. Please add the network first.",
"network_missing_id": "Missing chain id."
},
"deposit": {
"title": "Deposit"
Expand Down