mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 17:28:10 +00:00
web3 reducer (new types)
This commit is contained in:
parent
6c387967f9
commit
a913759ef4
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
import Web3 from 'web3';
|
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 * as WEB3 from 'actions/constants/web3';
|
||||||
|
|
||||||
import type { Action } from 'flowtype';
|
import type { Action } from 'flowtype';
|
||||||
@ -18,7 +19,7 @@ export type Web3Instance = {
|
|||||||
chainId: number;
|
chainId: number;
|
||||||
latestBlock: any;
|
latestBlock: any;
|
||||||
gasPrice: string;
|
gasPrice: string;
|
||||||
erc20: ContractFactory;
|
erc20: Contract;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type State = Array<Web3Instance>;
|
export type State = Array<Web3Instance>;
|
||||||
@ -26,8 +27,13 @@ export type State = Array<Web3Instance>;
|
|||||||
const initialState: State = [];
|
const initialState: State = [];
|
||||||
|
|
||||||
const createWeb3 = (state: State, instance: Web3Instance): State => {
|
const createWeb3 = (state: State, instance: Web3Instance): State => {
|
||||||
|
const index: number = state.findIndex(w3 => w3.network === instance.network);
|
||||||
const newState: Array<Web3Instance> = [...state];
|
const newState: Array<Web3Instance> = [...state];
|
||||||
|
if (index >= 0) {
|
||||||
|
newState[index] = instance;
|
||||||
|
} else {
|
||||||
newState.push(instance);
|
newState.push(instance);
|
||||||
|
}
|
||||||
return newState;
|
return newState;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user