From 69e208361562d4b6c4342efd42032efac0cbad0c Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Tue, 22 May 2018 10:26:34 +0200 Subject: [PATCH] web3 chainId from config --- src/data/appConfig.json | 4 +++ src/js/actions/Web3Actions.js | 37 ++++++++++++++------------ src/js/reducers/LocalStorageReducer.js | 1 + src/js/reducers/SendFormReducer.js | 2 -- src/js/reducers/Web3Reducer.js | 13 ++------- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/data/appConfig.json b/src/data/appConfig.json index 065d5d34..bf0d4277 100644 --- a/src/data/appConfig.json +++ b/src/data/appConfig.json @@ -5,6 +5,7 @@ "symbol": "ETH", "network": "ethereum", "bip44": "m/44'/60'/0'/0", + "chainId": 1, "defaultGasPrice": 64, "defaultGasLimit": 21000, "defaultGasLimitTokens": 200000, @@ -27,6 +28,7 @@ "name": "Ethereum Classic", "symbol": "ETC", "network": "ethereum-classic", + "chainId": 61, "bip44": "m/44'/61'/0'/0", "defaultGasPrice": 64, "defaultGasLimit": 21000, @@ -50,6 +52,7 @@ "name": "Ethereum Ropsten", "symbol": "tETH", "network": "ropsten", + "chainId": 3, "bip44": "m/44'/60'/0'/0", "defaultGasPrice": 64, "defaultGasLimit": 21000, @@ -73,6 +76,7 @@ "name": "Ethereum Rinkeby", "symbol": "tETH", "network": "rinkeby", + "chainId": 4, "bip44": "m/44'/61'/0'/0", "defaultGasPrice": 64, "defaultGasLimit": 21000, diff --git a/src/js/actions/Web3Actions.js b/src/js/actions/Web3Actions.js index e6b28c9e..e30f64aa 100644 --- a/src/js/actions/Web3Actions.js +++ b/src/js/actions/Web3Actions.js @@ -30,18 +30,13 @@ import type { NetworkToken } from '../reducers/LocalStorageReducer'; export type Web3Action = { type: typeof WEB3.READY, -} | Web3CreateAction +} | { + type: typeof WEB3.CREATE, + instance: Web3Instance +} | Web3UpdateBlockAction | Web3UpdateGasPriceAction; -export type Web3CreateAction = { - type: typeof WEB3.CREATE, - network: string, - web3: Web3, - erc20: ContractFactory, - chainId: string; -}; - export type Web3UpdateBlockAction = { type: typeof WEB3.BLOCK_UPDATED, network: string, @@ -85,10 +80,14 @@ export function init(instance: ?Web3, coinIndex: number = 0): AsyncAction { dispatch({ type: WEB3.CREATE, - network, - web3: instance, - erc20: instance.eth.contract(ERC20Abi), - chainId: '0' + instance: { + network, + web3: instance, + chainId: coin.chainId, + erc20: instance.eth.contract(ERC20Abi), + latestBlock: '0', + gasPrice: '0', + } }); // try next coin @@ -120,10 +119,14 @@ export function init(instance: ?Web3, coinIndex: number = 0): AsyncAction { dispatch({ type: WEB3.CREATE, - network, - web3: web3, - erc20, - chainId: web3.version.network + instance: { + network, + web3: web3, + chainId: coin.chainId, + erc20, + latestBlock: '0', + gasPrice: '0', + } }); // dispatch({ diff --git a/src/js/reducers/LocalStorageReducer.js b/src/js/reducers/LocalStorageReducer.js index 2f8df178..72e677d9 100644 --- a/src/js/reducers/LocalStorageReducer.js +++ b/src/js/reducers/LocalStorageReducer.js @@ -13,6 +13,7 @@ export type Coin = { defaultGasLimit: number; defaultGasLimitTokens: number; defaultGasPrice: number; + chainId: number; explorer: { tx: string; address: string; diff --git a/src/js/reducers/SendFormReducer.js b/src/js/reducers/SendFormReducer.js index 67934984..210a33c5 100644 --- a/src/js/reducers/SendFormReducer.js +++ b/src/js/reducers/SendFormReducer.js @@ -10,8 +10,6 @@ import { getFeeLevels } from '../actions/SendFormActions'; import type { Action } from '~/flowtype'; import type { - Web3CreateAction, - Web3UpdateBlockAction, Web3UpdateGasPriceAction } from '../actions/Web3Actions'; diff --git a/src/js/reducers/Web3Reducer.js b/src/js/reducers/Web3Reducer.js index ff47a311..cd5393d6 100644 --- a/src/js/reducers/Web3Reducer.js +++ b/src/js/reducers/Web3Reducer.js @@ -8,7 +8,6 @@ import * as WEB3 from '../actions/constants/web3'; import type { Action } from '~/flowtype'; import type { - Web3CreateAction, Web3UpdateBlockAction, Web3UpdateGasPriceAction } from '../actions/Web3Actions'; @@ -27,15 +26,7 @@ export type State = Array; const initialState: State = []; -const createWeb3 = (state: State, action: Web3CreateAction): State => { - const instance: Web3Instance = { - network: action.network, - web3: action.web3, - chainId: parseInt(action.chainId), - latestBlock: '0', - gasPrice: '0', - erc20: action.erc20 - } +const createWeb3 = (state: State, instance: Web3Instance): State => { const newState: Array = [ ...state ]; newState.push(instance); return newState; @@ -60,7 +51,7 @@ export default function web3(state: State = initialState, action: Action): State switch (action.type) { case WEB3.CREATE : - return createWeb3(state, action); + return createWeb3(state, action.instance); case WEB3.BLOCK_UPDATED : return updateLatestBlock(state, action); case WEB3.GAS_PRICE_UPDATED :