on master help sign in
fix: add check for valid network type
commitec64ded16219703447ad8ab59760017ad0beee34 authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 11 Jun 2019, 15:29 (7 years ago) parente06fa4c
2 files changed+10−11
src/bridge/Bridge.js−10 src/bridge/store/network.js+10−1
src/bridge/Bridge.js−10
@@ -139,16 +139,6 @@ class Bridge extends React.Component {
139139 }
140140 }
141141
142− setNetworkType(symbol) {
143− if (includes(NETWORK_TYPES, symbol)) {
144− this.setState({
145− networkType: symbol,
146− });
147− } else {
148− throw BRIDGE_ERROR.INVALID_NETWORK_TYPE;
149− }
150− }
151−
152142 setNetworkSeedCache(networkSeed, revision) {
153143 this.setState({
154144 networkSeedCache: networkSeed,
src/bridge/store/network.js+10−1
@@ -8,13 +8,22 @@ import React, {
88import * as azimuth from 'azimuth-js';
99import Web3 from 'web3';
1010import Maybe from 'folktale/maybe';
11+import { includes } from 'lodash';
1112
1213import { CONTRACT_ADDRESSES } from '../lib/contracts';
1314import { NETWORK_TYPES } from '../lib/network';
1415import { isDevelopment } from '../lib/flags';
16+import { BRIDGE_ERROR } from '../lib/error';
1517
1618function _useNetwork(initialNetworkType = null) {
17− const [networkType, setNetworkType] = useState(initialNetworkType);
19+ const [networkType, _setNetworkType] = useState(initialNetworkType);
20+
21+ const setNetworkType = networkType => {
22+ if (!includes(NETWORK_TYPES, networkType)) {
23+ throw BRIDGE_ERROR.INVALID_NETWORK_TYPE;
24+ }
25+ _setNetworkType(networkType);
26+ };
1827
1928 const { web3, contracts } = useMemo(() => {
2029 if (networkType === NETWORK_TYPES.LOCAL) {