1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

web3 chainId from config

This commit is contained in:
Szymon Lesisz 2018-05-22 10:26:34 +02:00
parent 783b47b2db
commit 69e2083615
5 changed files with 27 additions and 30 deletions

View File

@ -5,6 +5,7 @@
"symbol": "ETH", "symbol": "ETH",
"network": "ethereum", "network": "ethereum",
"bip44": "m/44'/60'/0'/0", "bip44": "m/44'/60'/0'/0",
"chainId": 1,
"defaultGasPrice": 64, "defaultGasPrice": 64,
"defaultGasLimit": 21000, "defaultGasLimit": 21000,
"defaultGasLimitTokens": 200000, "defaultGasLimitTokens": 200000,
@ -27,6 +28,7 @@
"name": "Ethereum Classic", "name": "Ethereum Classic",
"symbol": "ETC", "symbol": "ETC",
"network": "ethereum-classic", "network": "ethereum-classic",
"chainId": 61,
"bip44": "m/44'/61'/0'/0", "bip44": "m/44'/61'/0'/0",
"defaultGasPrice": 64, "defaultGasPrice": 64,
"defaultGasLimit": 21000, "defaultGasLimit": 21000,
@ -50,6 +52,7 @@
"name": "Ethereum Ropsten", "name": "Ethereum Ropsten",
"symbol": "tETH", "symbol": "tETH",
"network": "ropsten", "network": "ropsten",
"chainId": 3,
"bip44": "m/44'/60'/0'/0", "bip44": "m/44'/60'/0'/0",
"defaultGasPrice": 64, "defaultGasPrice": 64,
"defaultGasLimit": 21000, "defaultGasLimit": 21000,
@ -73,6 +76,7 @@
"name": "Ethereum Rinkeby", "name": "Ethereum Rinkeby",
"symbol": "tETH", "symbol": "tETH",
"network": "rinkeby", "network": "rinkeby",
"chainId": 4,
"bip44": "m/44'/61'/0'/0", "bip44": "m/44'/61'/0'/0",
"defaultGasPrice": 64, "defaultGasPrice": 64,
"defaultGasLimit": 21000, "defaultGasLimit": 21000,

View File

@ -30,18 +30,13 @@ import type { NetworkToken } from '../reducers/LocalStorageReducer';
export type Web3Action = { export type Web3Action = {
type: typeof WEB3.READY, type: typeof WEB3.READY,
} | Web3CreateAction } | {
type: typeof WEB3.CREATE,
instance: Web3Instance
}
| Web3UpdateBlockAction | Web3UpdateBlockAction
| Web3UpdateGasPriceAction; | Web3UpdateGasPriceAction;
export type Web3CreateAction = {
type: typeof WEB3.CREATE,
network: string,
web3: Web3,
erc20: ContractFactory,
chainId: string;
};
export type Web3UpdateBlockAction = { export type Web3UpdateBlockAction = {
type: typeof WEB3.BLOCK_UPDATED, type: typeof WEB3.BLOCK_UPDATED,
network: string, network: string,
@ -85,10 +80,14 @@ export function init(instance: ?Web3, coinIndex: number = 0): AsyncAction {
dispatch({ dispatch({
type: WEB3.CREATE, type: WEB3.CREATE,
network, instance: {
web3: instance, network,
erc20: instance.eth.contract(ERC20Abi), web3: instance,
chainId: '0' chainId: coin.chainId,
erc20: instance.eth.contract(ERC20Abi),
latestBlock: '0',
gasPrice: '0',
}
}); });
// try next coin // try next coin
@ -120,10 +119,14 @@ export function init(instance: ?Web3, coinIndex: number = 0): AsyncAction {
dispatch({ dispatch({
type: WEB3.CREATE, type: WEB3.CREATE,
network, instance: {
web3: web3, network,
erc20, web3: web3,
chainId: web3.version.network chainId: coin.chainId,
erc20,
latestBlock: '0',
gasPrice: '0',
}
}); });
// dispatch({ // dispatch({

View File

@ -13,6 +13,7 @@ export type Coin = {
defaultGasLimit: number; defaultGasLimit: number;
defaultGasLimitTokens: number; defaultGasLimitTokens: number;
defaultGasPrice: number; defaultGasPrice: number;
chainId: number;
explorer: { explorer: {
tx: string; tx: string;
address: string; address: string;

View File

@ -10,8 +10,6 @@ import { getFeeLevels } from '../actions/SendFormActions';
import type { Action } from '~/flowtype'; import type { Action } from '~/flowtype';
import type { import type {
Web3CreateAction,
Web3UpdateBlockAction,
Web3UpdateGasPriceAction Web3UpdateGasPriceAction
} from '../actions/Web3Actions'; } from '../actions/Web3Actions';

View File

@ -8,7 +8,6 @@ import * as WEB3 from '../actions/constants/web3';
import type { Action } from '~/flowtype'; import type { Action } from '~/flowtype';
import type { import type {
Web3CreateAction,
Web3UpdateBlockAction, Web3UpdateBlockAction,
Web3UpdateGasPriceAction Web3UpdateGasPriceAction
} from '../actions/Web3Actions'; } from '../actions/Web3Actions';
@ -27,15 +26,7 @@ export type State = Array<Web3Instance>;
const initialState: State = []; const initialState: State = [];
const createWeb3 = (state: State, action: Web3CreateAction): State => { const createWeb3 = (state: State, instance: Web3Instance): State => {
const instance: Web3Instance = {
network: action.network,
web3: action.web3,
chainId: parseInt(action.chainId),
latestBlock: '0',
gasPrice: '0',
erc20: action.erc20
}
const newState: Array<Web3Instance> = [ ...state ]; const newState: Array<Web3Instance> = [ ...state ];
newState.push(instance); newState.push(instance);
return newState; return newState;
@ -60,7 +51,7 @@ export default function web3(state: State = initialState, action: Action): State
switch (action.type) { switch (action.type) {
case WEB3.CREATE : case WEB3.CREATE :
return createWeb3(state, action); return createWeb3(state, action.instance);
case WEB3.BLOCK_UPDATED : case WEB3.BLOCK_UPDATED :
return updateLatestBlock(state, action); return updateLatestBlock(state, action);
case WEB3.GAS_PRICE_UPDATED : case WEB3.GAS_PRICE_UPDATED :