Skip to content

Commit

Permalink
constants++
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed Jan 8, 2021
1 parent de735a8 commit 05dcde4
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 29 deletions.
3 changes: 2 additions & 1 deletion app/components/UI/AccountApproval/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import AccountApproval from './';
import { shallow } from 'enzyme';
import configureMockStore from 'redux-mock-store';
import { ROPSTEN } from '../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -15,7 +16,7 @@ describe('AccountApproval', () => {
},
NetworkController: {
provider: {
type: 'ropsten'
type: ROPSTEN
}
},
AssetsController: {
Expand Down
7 changes: 4 additions & 3 deletions app/components/UI/DrawerView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { protectWalletModalVisible } from '../../../actions/user';
import DeeplinkManager from '../../../core/DeeplinkManager';
import SettingsNotification from '../SettingsNotification';
import WhatsNewModal from '../WhatsNewModal';
import { RPC } from '../../../constants/network';

const styles = StyleSheet.create({
wrapper: {
Expand Down Expand Up @@ -582,7 +583,7 @@ class DrawerView extends PureComponent {
},
frequentRpcList
} = this.props;
if (network.provider.type === 'rpc') {
if (network.provider.type === RPC) {
const blockExplorer = findBlockExplorerForRpc(rpcTarget, frequentRpcList);
const url = `${blockExplorer}/address/${selectedAddress}`;
const title = new URL(blockExplorer).hostname;
Expand Down Expand Up @@ -642,7 +643,7 @@ class DrawerView extends PureComponent {

hasBlockExplorer = providerType => {
const { frequentRpcList } = this.props;
if (providerType === 'rpc') {
if (providerType === RPC) {
const {
network: {
provider: { rpcTarget }
Expand Down Expand Up @@ -697,7 +698,7 @@ class DrawerView extends PureComponent {
paymentChannelsEnabled
} = this.props;
let blockExplorer, blockExplorerName;
if (type === 'rpc') {
if (type === RPC) {
blockExplorer = findBlockExplorerForRpc(rpcTarget, frequentRpcList);
blockExplorerName = getBlockExplorerName(blockExplorer);
}
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/NetworkList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Networks, { getAllNetworks } from '../../../util/networks';
import { connect } from 'react-redux';
import Analytics from '../../../core/Analytics';
import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import { MAINNET } from '../../../constants/network';
import { MAINNET, RPC } from '../../../constants/network';

const styles = StyleSheet.create({
wrapper: {
Expand Down Expand Up @@ -200,7 +200,7 @@ export class NetworkList extends PureComponent {
return frequentRpcList.map(({ nickname, rpcUrl }, i) => {
const { color, name } = { name: nickname || rpcUrl, color: null };
const selected =
provider.rpcTarget === rpcUrl && provider.type === 'rpc' ? (
provider.rpcTarget === rpcUrl && provider.type === RPC ? (
<Icon name="check" size={20} color={colors.fontSecondary} />
) : null;
return this.networkElement(selected, this.onSetRpcTarget, name, color, i, rpcUrl);
Expand Down
3 changes: 2 additions & 1 deletion app/components/UI/SignatureRequest/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import SignatureRequest from './';
import configureMockStore from 'redux-mock-store';
import { ROPSTEN } from '../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -19,7 +20,7 @@ describe('SignatureRequest', () => {
},
NetworkController: {
provider: {
type: 'ropsten'
type: ROPSTEN
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import AppConstants from '../../../../core/AppConstants';
import StatusText from '../../../Base/StatusText';
import Text from '../../../Base/Text';
import DetailsModal from '../../../Base/DetailsModal';
import { RPC } from '../../../../constants/network';

const styles = StyleSheet.create({
viewOnEtherscan: {
Expand Down Expand Up @@ -107,7 +108,7 @@ class TransactionDetails extends PureComponent {
frequentRpcList
} = this.props;
let blockExplorer;
if (type === 'rpc') {
if (type === RPC) {
blockExplorer = findBlockExplorerForRpc(rpcTarget, frequentRpcList) || NO_RPC_BLOCK_EXPLORER;
}
this.setState({ rpcBlockExplorer: blockExplorer });
Expand All @@ -125,7 +126,7 @@ class TransactionDetails extends PureComponent {
} = this.props;
const { rpcBlockExplorer } = this.state;
try {
if (type === 'rpc') {
if (type === RPC) {
const url = `${rpcBlockExplorer}/tx/${transactionHash}`;
const title = new URL(rpcBlockExplorer).hostname;
navigation.push('Webview', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import TransactionDetails from './';
import configureMockStore from 'redux-mock-store';
import { shallow } from 'enzyme';
import { RPC } from '../../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -20,7 +21,7 @@ describe('TransactionDetails', () => {
NetworkController: {
provider: {
rpcTarget: '',
type: 'rpc'
type: RPC
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/components/UI/TransactionHeader/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import TransactionHeader from './';
import configureMockStore from 'redux-mock-store';
import { ROPSTEN } from '../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -12,7 +13,7 @@ describe('TransactionHeader', () => {
backgroundState: {
NetworkController: {
provider: {
type: 'ropsten'
type: ROPSTEN
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/components/UI/UrlAutocomplete/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { shallow } from 'enzyme';
import UrlAutocomplete from './';
import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import { ROPSTEN } from '../../../constants/network';

const mockStore = configureMockStore();
const store = mockStore({});
Expand All @@ -11,7 +12,7 @@ describe('UrlAutocomplete', () => {
it('should render correctly', () => {
const wrapper = shallow(
<Provider store={store}>
<UrlAutocomplete network={'ropsten'} />
<UrlAutocomplete network={ROPSTEN} />
</Provider>
);
expect(wrapper).toMatchSnapshot();
Expand Down
3 changes: 2 additions & 1 deletion app/components/Views/Approval/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import Approval from './';
import configureMockStore from 'redux-mock-store';
import { shallow } from 'enzyme';
import { ROPSTEN } from '../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -28,7 +29,7 @@ describe('Approval', () => {
},
NetworkController: {
provider: {
type: 'ropsten'
type: ROPSTEN
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions app/components/Views/Asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Transactions from '../../UI/Transactions';
import { getNetworkNavbarOptions } from '../../UI/Navbar';
import Engine from '../../../core/Engine';
import { safeToChecksumAddress } from '../../../util/address';
import { RPC } from '../../../constants/network';

const styles = StyleSheet.create({
wrapper: {
Expand Down Expand Up @@ -140,7 +141,7 @@ class Asset extends PureComponent {
return (
(safeToChecksumAddress(from) === selectedAddress || safeToChecksumAddress(to) === selectedAddress) &&
((networkId && networkId.toString() === tx.networkID) ||
(networkType === 'rpc' && !isKnownNetwork(tx.networkID))) &&
(networkType === RPC && !isKnownNetwork(tx.networkID))) &&
tx.status !== 'unapproved'
);
};
Expand All @@ -157,7 +158,7 @@ class Asset extends PureComponent {
return (
(from & (from.toLowerCase() === this.navAddress) || (to && to.toLowerCase() === this.navAddress)) &&
((networkId && networkId.toString() === tx.networkID) ||
(networkType === 'rpc' && !isKnownNetwork(tx.networkID))) &&
(networkType === RPC && !isKnownNetwork(tx.networkID))) &&
tx.status !== 'unapproved'
);
};
Expand Down
5 changes: 3 additions & 2 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { ethErrors } from 'eth-json-rpc-errors';
import EntryScriptWeb3 from '../../../core/EntryScriptWeb3';
import { getVersion } from 'react-native-device-info';
import ErrorBoundary from '../ErrorBoundary';
import { RPC } from '../../../constants/network';

const { HOMEPAGE_URL, USER_AGENT, NOTIFICATION_NAMES } = AppConstants;
const HOMEPAGE_HOST = 'home.metamask.io';
Expand Down Expand Up @@ -511,7 +512,7 @@ export const BrowserTab = props => {
const data = JSON.parse(req.params[1]);
const chainId = data.domain.chainId;
const activeChainId =
props.networkType === 'rpc' ? props.network : Networks[props.networkType].networkId;
props.networkType === RPC ? props.network : Networks[props.networkType].networkId;

// eslint-disable-next-line
if (chainId && chainId != activeChainId) {
Expand Down Expand Up @@ -545,7 +546,7 @@ export const BrowserTab = props => {
const data = JSON.parse(req.params[1]);
const chainId = data.domain.chainId;
const activeChainId =
props.networkType === 'rpc' ? props.network : Networks[props.networkType].networkId;
props.networkType === RPC ? props.network : Networks[props.networkType].networkId;

// eslint-disable-next-line eqeqeq
if (chainId && chainId != activeChainId) {
Expand Down
3 changes: 2 additions & 1 deletion app/components/Views/Login/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import Login from './';
import configureMockStore from 'redux-mock-store';
import { ROPSTEN } from '../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -15,7 +16,7 @@ describe('Login', () => {
},
NetworkController: {
provider: {
type: 'ropsten'
type: ROPSTEN
}
},
AssetsController: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import PaymentChannelDeposit from './';
import configureMockStore from 'redux-mock-store';
import { ROPSTEN } from '../../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -24,7 +25,7 @@ describe('PaymentChannelDeposit', () => {
},
NetworkController: {
provider: {
type: 'ropsten',
type: ROPSTEN,
ticker: 'ETH'
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/components/Views/PaymentChannel/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme';
import PaymentChannel from './';
import configureMockStore from 'redux-mock-store';
import { ROPSTEN } from '../../../constants/network';

const mockStore = configureMockStore();

Expand All @@ -15,7 +16,7 @@ describe('PaymentChannel', () => {
backgroundState: {
NetworkController: {
provider: {
type: 'ropsten',
type: ROPSTEN,
ticker: 'ETH'
}
},
Expand Down
9 changes: 5 additions & 4 deletions app/components/Views/Settings/NetworksSettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { strings } from '../../../../../locales/i18n';
import Networks, { getAllNetworks } from '../../../../util/networks';
import StyledButton from '../../../UI/StyledButton';
import Engine from '../../../../core/Engine';
import { MAINNET, RPC } from '../../../../constants/network';

const styles = StyleSheet.create({
wrapper: {
Expand Down Expand Up @@ -105,7 +106,7 @@ class NetworksSettings extends PureComponent {
switchToMainnet = () => {
const { NetworkController, CurrencyRateController } = Engine.context;
CurrencyRateController.configure({ nativeCurrency: 'ETH' });
NetworkController.setProviderType('mainnet');
NetworkController.setProviderType(MAINNET);
this.props.thirdPartyApiMode &&
setTimeout(() => {
Engine.refreshTransactionHistory();
Expand All @@ -115,7 +116,7 @@ class NetworksSettings extends PureComponent {
removeNetwork = () => {
// Check if it's the selected network and then switch to mainnet first
const { provider } = this.props;
if (provider.rpcTarget === this.networkToRemove && provider.type === 'rpc') {
if (provider.rpcTarget === this.networkToRemove && provider.type === RPC) {
this.switchToMainnet();
}
const { PreferencesController } = Engine.context;
Expand Down Expand Up @@ -180,8 +181,8 @@ class NetworksSettings extends PureComponent {
<View style={styles.mainnetHeader}>
<TouchableOpacity
style={styles.network}
key={`network-mainnet`}
onPress={() => this.onPress('mainnet')} // eslint-disable-line
key={`network-${MAINNET}`}
onPress={() => this.onPress(MAINNET)} // eslint-disable-line
>
<View style={styles.networkWrapper}>
<View style={[styles.networkIcon, { backgroundColor: mainnetColor }]} />
Expand Down
3 changes: 2 additions & 1 deletion app/components/Views/TransactionsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { colors } from '../../../styles/common';
import Transactions from '../../UI/Transactions';
import Networks, { isKnownNetwork } from '../../../util/networks';
import { safeToChecksumAddress } from '../../../util/address';
import { RPC } from '../../../constants/network';

const styles = StyleSheet.create({
wrapper: {
Expand Down Expand Up @@ -120,7 +121,7 @@ class TransactionsView extends PureComponent {
return (
(safeToChecksumAddress(from) === selectedAddress || safeToChecksumAddress(to) === selectedAddress) &&
((networkId && networkId.toString() === tx.networkID) ||
(networkType === 'rpc' && !isKnownNetwork(tx.networkID))) &&
(networkType === RPC && !isKnownNetwork(tx.networkID))) &&
tx.status !== 'unapproved'
);
};
Expand Down
3 changes: 2 additions & 1 deletion app/core/NotificationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Alert, AppState } from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
import AppConstants from './AppConstants';
import { PUSH_NOTIFICATIONS_PROMPT_COUNT, PUSH_NOTIFICATIONS_PROMPT_TIME } from '../constants/storage';
import { RPC } from '../constants/network';

/**
* Singleton class responsible for managing all the
Expand Down Expand Up @@ -382,7 +383,7 @@ class NotificationManager {
toChecksumAddress(tx.transaction.to) === selectedAddress &&
toChecksumAddress(tx.transaction.from) !== selectedAddress &&
((networkId && networkId.toString() === tx.networkID) ||
(networkType === 'rpc' && !isKnownNetwork(tx.networkID))) &&
(networkType === RPC && !isKnownNetwork(tx.networkID))) &&
tx.status === 'confirmed' &&
lastBlock <= parseInt(tx.blockNumber, 10) &&
tx.time > oldestTimeAllowed
Expand Down
3 changes: 2 additions & 1 deletion app/util/accountSecurity.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Networks, { isKnownNetwork } from './networks';
import { toChecksumAddress } from 'ethereumjs-util';
import { toBN, hexToBN, renderFromWei, renderFromTokenMinimalUnit } from './number';
import { strings } from '../../locales/i18n';
import { RPC } from '../constants/network';

export default async function findFirstIncomingTransaction(networkType, selectedAddress, thirPartyApiMode) {
// Pull txs if allowed
Expand All @@ -17,7 +18,7 @@ export default async function findFirstIncomingTransaction(networkType, selected
tx.transaction.to &&
toChecksumAddress(tx.transaction.to) === selectedAddress &&
((networkId && networkId.toString() === tx.networkID) ||
(networkType === 'rpc' && !isKnownNetwork(tx.networkID))) &&
(networkType === RPC && !isKnownNetwork(tx.networkID))) &&
tx.status === 'confirmed'
);
if (txs.length > 0) {
Expand Down
4 changes: 2 additions & 2 deletions app/util/networks.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isMainNet, getNetworkName, getAllNetworks, getNetworkTypeById } from './networks';
import { MAINNET, ROPSTEN, GOERLI, RPC } from '../../app/constants/network';
import { MAINNET, ROPSTEN, GOERLI, RPC, KOVAN } from '../../app/constants/network';

describe('getAllNetworks', () => {
const allNetworks = getAllNetworks();
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('getNetworkName', () => {
describe('getNetworkTypeById', () => {
it('should get network type by Id', () => {
const type = getNetworkTypeById(42);
expect(type).toEqual('kovan');
expect(type).toEqual(KOVAN);
});
it('should fail if network Id is missing', () => {
try {
Expand Down

0 comments on commit 05dcde4

Please sign in to comment.