mirror of
https://github.com/trezor/trezor-wallet
synced 2024-12-25 00:18:07 +00:00
web3 chainId from config
This commit is contained in:
parent
783b47b2db
commit
69e2083615
@ -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,
|
||||
|
@ -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({
|
||||
|
@ -13,6 +13,7 @@ export type Coin = {
|
||||
defaultGasLimit: number;
|
||||
defaultGasLimitTokens: number;
|
||||
defaultGasPrice: number;
|
||||
chainId: number;
|
||||
explorer: {
|
||||
tx: string;
|
||||
address: string;
|
||||
|
@ -10,8 +10,6 @@ import { getFeeLevels } from '../actions/SendFormActions';
|
||||
|
||||
import type { Action } from '~/flowtype';
|
||||
import type {
|
||||
Web3CreateAction,
|
||||
Web3UpdateBlockAction,
|
||||
Web3UpdateGasPriceAction
|
||||
} from '../actions/Web3Actions';
|
||||
|
||||
|
@ -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<Web3Instance>;
|
||||
|
||||
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<Web3Instance> = [ ...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 :
|
||||
|
Loading…
Reference in New Issue
Block a user