From a913759ef402a2fbe4db6713ca2a5d571f6267d7 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Wed, 12 Sep 2018 13:24:07 +0200 Subject: [PATCH] web3 reducer (new types) --- src/reducers/Web3Reducer.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/reducers/Web3Reducer.js b/src/reducers/Web3Reducer.js index 40903eec..d0d45d23 100644 --- a/src/reducers/Web3Reducer.js +++ b/src/reducers/Web3Reducer.js @@ -3,7 +3,8 @@ import Web3 from 'web3'; -import type { ContractFactory } from 'web3'; +import type { Contract } from 'web3'; +import * as STORAGE from 'actions/constants/localStorage'; import * as WEB3 from 'actions/constants/web3'; import type { Action } from 'flowtype'; @@ -18,7 +19,7 @@ export type Web3Instance = { chainId: number; latestBlock: any; gasPrice: string; - erc20: ContractFactory; + erc20: Contract; } export type State = Array; @@ -26,8 +27,13 @@ export type State = Array; const initialState: State = []; const createWeb3 = (state: State, instance: Web3Instance): State => { + const index: number = state.findIndex(w3 => w3.network === instance.network); const newState: Array = [...state]; - newState.push(instance); + if (index >= 0) { + newState[index] = instance; + } else { + newState.push(instance); + } return newState; };