mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
eslint fixes
This commit is contained in:
parent
91f731c34e
commit
590e0ca642
@ -1,42 +1,28 @@
|
||||
/* @flow */
|
||||
|
||||
import Web3 from 'web3';
|
||||
import HDKey from 'hdkey';
|
||||
|
||||
import EthereumjsUtil from 'ethereumjs-util';
|
||||
import EthereumjsUnits from 'ethereumjs-units';
|
||||
import EthereumjsTx from 'ethereumjs-tx';
|
||||
import TrezorConnect from 'trezor-connect';
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import type { EstimateGasOptions } from 'web3';
|
||||
import type { TransactionStatus, TransactionReceipt } from 'web3';
|
||||
import { strip } from 'utils/ethUtils';
|
||||
import * as BLOCKCHAIN from 'actions/constants/blockchain';
|
||||
import * as WEB3 from 'actions/constants/web3';
|
||||
import * as PENDING from 'actions/constants/pendingTx';
|
||||
|
||||
import * as AccountsActions from './AccountsActions';
|
||||
import * as Web3Actions from './Web3Actions';
|
||||
|
||||
import type {
|
||||
TrezorDevice,
|
||||
Dispatch,
|
||||
GetState,
|
||||
Action,
|
||||
AsyncAction,
|
||||
PromiseAction,
|
||||
ThunkAction,
|
||||
} from 'flowtype';
|
||||
import type { EthereumAccount } from 'trezor-connect';
|
||||
import type { Token } from 'reducers/TokensReducer';
|
||||
import type { NetworkToken } from 'reducers/LocalStorageReducer';
|
||||
import * as Web3Actions from './Web3Actions';
|
||||
import * as AccountsActions from './AccountsActions';
|
||||
|
||||
export type BlockchainAction = {
|
||||
type: typeof BLOCKCHAIN.READY,
|
||||
}
|
||||
|
||||
export const discoverAccount = (device: TrezorDevice, address: string, network: string): PromiseAction<EthereumAccount> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumAccount> => {
|
||||
export const discoverAccount = (device: TrezorDevice, address: string, network: string): PromiseAction<EthereumAccount> => async (dispatch: Dispatch): Promise<EthereumAccount> => {
|
||||
// get data from connect
|
||||
// Temporary disabled, enable after trezor-connect@5.0.32 release
|
||||
const txs = await TrezorConnect.ethereumGetAccountInfo({
|
||||
@ -44,8 +30,8 @@ export const discoverAccount = (device: TrezorDevice, address: string, network:
|
||||
address,
|
||||
block: 0,
|
||||
transactions: 0,
|
||||
balance: "0",
|
||||
nonce: 0
|
||||
balance: '0',
|
||||
nonce: 0,
|
||||
},
|
||||
coin: network,
|
||||
});
|
||||
@ -55,7 +41,7 @@ export const discoverAccount = (device: TrezorDevice, address: string, network:
|
||||
}
|
||||
|
||||
// blockbook web3 fallback
|
||||
const web3account = await dispatch( Web3Actions.discoverAccount(address, network) );
|
||||
const web3account = await dispatch(Web3Actions.discoverAccount(address, network));
|
||||
// return { transactions: txs.payload, ...web3account };
|
||||
return {
|
||||
address,
|
||||
@ -66,22 +52,18 @@ export const discoverAccount = (device: TrezorDevice, address: string, network:
|
||||
};
|
||||
};
|
||||
|
||||
export const getTokenInfo = (input: string, network: string): PromiseAction<NetworkToken> => async (dispatch: Dispatch, getState: GetState): Promise<NetworkToken> => {
|
||||
return await dispatch( Web3Actions.getTokenInfo(input, network) );
|
||||
}
|
||||
export const getTokenInfo = (input: string, network: string): PromiseAction<NetworkToken> => async (dispatch: Dispatch): Promise<NetworkToken> => dispatch(Web3Actions.getTokenInfo(input, network));
|
||||
|
||||
export const getTokenBalance = (token: Token): PromiseAction<string> => async (dispatch: Dispatch, getState: GetState): Promise<string> => {
|
||||
return await dispatch( Web3Actions.getTokenBalance(token) );
|
||||
}
|
||||
export const getTokenBalance = (token: Token): PromiseAction<string> => async (dispatch: Dispatch): Promise<string> => dispatch(Web3Actions.getTokenBalance(token));
|
||||
|
||||
export const getGasPrice = (network: string, defaultGasPrice: number): PromiseAction<BigNumber> => async (dispatch: Dispatch, getState: GetState): Promise<BigNumber> => {
|
||||
export const getGasPrice = (network: string, defaultGasPrice: number): PromiseAction<BigNumber> => async (dispatch: Dispatch): Promise<BigNumber> => {
|
||||
try {
|
||||
const gasPrice = await dispatch( Web3Actions.getCurrentGasPrice(network) );
|
||||
const gasPrice = await dispatch(Web3Actions.getCurrentGasPrice(network));
|
||||
return new BigNumber(gasPrice);
|
||||
} catch (error) {
|
||||
return new BigNumber(defaultGasPrice);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const estimateProxy: Array<Promise<string>> = [];
|
||||
export const estimateGasLimit = (network: string, data: string, value: string, gasPrice: string): PromiseAction<string> => async (dispatch: Dispatch): Promise<string> => {
|
||||
@ -114,9 +96,9 @@ export const onBlockMined = (coinInfo: any): PromiseAction<void> => async (dispa
|
||||
const network: string = coinInfo.shortcut.toLowerCase();
|
||||
|
||||
// try to resolve pending transactions
|
||||
await dispatch( Web3Actions.resolvePendingTransactions(network) );
|
||||
await dispatch(Web3Actions.resolvePendingTransactions(network));
|
||||
|
||||
await dispatch( Web3Actions.updateGasPrice(network) );
|
||||
await dispatch(Web3Actions.updateGasPrice(network));
|
||||
|
||||
const accounts: Array<any> = getState().accounts.filter(a => a.network === network);
|
||||
if (accounts.length > 0) {
|
||||
@ -130,34 +112,31 @@ export const onBlockMined = (coinInfo: any): PromiseAction<void> => async (dispa
|
||||
response.payload.forEach((a, i) => {
|
||||
if (a.transactions > 0) {
|
||||
// load additional data from Web3 (balance, nonce, tokens)
|
||||
dispatch( Web3Actions.updateAccount(accounts[i], a, network) )
|
||||
dispatch(Web3Actions.updateAccount(accounts[i], a, network));
|
||||
} else {
|
||||
// there are no new txs, just update block
|
||||
dispatch( AccountsActions.update( { ...accounts[i], block: a.block }) );
|
||||
dispatch(AccountsActions.update({ ...accounts[i], block: a.block }));
|
||||
|
||||
// HACK: since blockbook can't work with smart contracts for now
|
||||
// try to update tokens balances added to this account using Web3
|
||||
dispatch( Web3Actions.updateAccountTokens(accounts[i]) );
|
||||
dispatch(Web3Actions.updateAccountTokens(accounts[i]));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// not used for now, waiting for fix in blockbook
|
||||
export const onNotification = (payload: any): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
|
||||
// this event can be triggered multiple times
|
||||
// 1. check if pair [txid + address] is already in reducer
|
||||
const network: string = payload.coin.shortcut.toLowerCase();
|
||||
const address: string = EthereumjsUtil.toChecksumAddress(payload.tx.address);
|
||||
const txInfo = await dispatch( Web3Actions.getPendingInfo(network, payload.tx.txid) );
|
||||
const txInfo = await dispatch(Web3Actions.getPendingInfo(network, payload.tx.txid));
|
||||
|
||||
// const exists = getState().pending.filter(p => p.id === payload.tx.txid && p.address === address);
|
||||
const exists = getState().pending.filter(p => {
|
||||
return p.address === address;
|
||||
});
|
||||
const exists = getState().pending.filter(p => p.address === address);
|
||||
if (exists.length < 1) {
|
||||
if (txInfo) {
|
||||
dispatch({
|
||||
@ -166,14 +145,14 @@ export const onNotification = (payload: any): PromiseAction<void> => async (disp
|
||||
type: 'send',
|
||||
id: payload.tx.txid,
|
||||
network,
|
||||
currency: "tETH",
|
||||
currency: 'tETH',
|
||||
amount: txInfo.value,
|
||||
total: "0",
|
||||
total: '0',
|
||||
tx: {},
|
||||
nonce: txInfo.nonce,
|
||||
address,
|
||||
rejected: false
|
||||
}
|
||||
rejected: false,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// tx info not found (yet?)
|
||||
@ -186,18 +165,17 @@ export const onNotification = (payload: any): PromiseAction<void> => async (disp
|
||||
// });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const subscribe = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const addresses: Array<string> = getState().accounts.filter(a => a.network === network).map(a => a.address);
|
||||
// $FlowIssue: trezor-connect@5.0.32
|
||||
return await TrezorConnect.blockchainSubscribe({
|
||||
const addresses: Array<string> = getState().accounts.filter(a => a.network === network).map(a => a.address); // eslint-disable-line no-unused-vars
|
||||
await TrezorConnect.blockchainSubscribe({
|
||||
// accounts: addresses,
|
||||
accounts: [],
|
||||
coin: network
|
||||
coin: network,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Conditionally subscribe to blockchain backend
|
||||
// called after TrezorConnect.init successfully emits TRANSPORT.START event
|
||||
@ -207,26 +185,26 @@ export const init = (): PromiseAction<void> => async (dispatch: Dispatch, getSta
|
||||
if (getState().discovery.length > 0) {
|
||||
// get unique networks
|
||||
const networks: Array<string> = [];
|
||||
getState().discovery.forEach(discovery => {
|
||||
getState().discovery.forEach((discovery) => {
|
||||
if (networks.indexOf(discovery.network) < 0) {
|
||||
networks.push(discovery.network);
|
||||
}
|
||||
});
|
||||
|
||||
// subscribe
|
||||
for (let i = 0; i < networks.length; i++) {
|
||||
await dispatch( subscribe(networks[i]) );
|
||||
}
|
||||
const results = networks.map(n => dispatch(subscribe(n)));
|
||||
// wait for all subscriptions
|
||||
await Promise.all(results);
|
||||
}
|
||||
|
||||
// continue wallet initialization
|
||||
dispatch({
|
||||
type: BLOCKCHAIN.READY
|
||||
type: BLOCKCHAIN.READY,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Handle BLOCKCHAIN.ERROR event from TrezorConnect
|
||||
// disconnect and remove Web3 webscocket instance if exists
|
||||
export const error = (payload: any): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
dispatch( Web3Actions.disconnect(payload.coin) );
|
||||
}
|
||||
export const error = (payload: any): PromiseAction<void> => async (dispatch: Dispatch): Promise<void> => {
|
||||
dispatch(Web3Actions.disconnect(payload.coin));
|
||||
};
|
@ -1,15 +1,10 @@
|
||||
/* @flow */
|
||||
import Web3 from 'web3';
|
||||
import HDKey from 'hdkey';
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import EthereumjsUtil from 'ethereumjs-util';
|
||||
import EthereumjsUnits from 'ethereumjs-units';
|
||||
import EthereumjsTx from 'ethereumjs-tx';
|
||||
// import InputDataDecoder from 'ethereum-input-data-decoder';
|
||||
import TrezorConnect from 'trezor-connect';
|
||||
import type { EstimateGasOptions, TransactionStatus, TransactionReceipt } from 'web3';
|
||||
import { strip } from 'utils/ethUtils';
|
||||
import type { EstimateGasOptions } from 'web3';
|
||||
import * as WEB3 from 'actions/constants/web3';
|
||||
import * as PENDING from 'actions/constants/pendingTx';
|
||||
|
||||
@ -17,13 +12,11 @@ import type {
|
||||
Dispatch,
|
||||
GetState,
|
||||
ThunkAction,
|
||||
AsyncAction,
|
||||
PromiseAction,
|
||||
} from 'flowtype';
|
||||
|
||||
import type { EthereumAccount } from 'trezor-connect';
|
||||
import type { Account } from 'reducers/AccountsReducer';
|
||||
import type { PendingTx } from 'reducers/PendingTxReducer';
|
||||
import type { Web3Instance } from 'reducers/Web3Reducer';
|
||||
import type { Token } from 'reducers/TokensReducer';
|
||||
import type { NetworkToken } from 'reducers/LocalStorageReducer';
|
||||
@ -52,8 +45,7 @@ export type Web3Action = {
|
||||
} | Web3UpdateBlockAction
|
||||
| Web3UpdateGasPriceAction;
|
||||
|
||||
export const initWeb3 = (network: string, urlIndex: number = 0): PromiseAction<Web3Instance> => async (dispatch: Dispatch, getState: GetState): Promise<Web3Instance> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
export const initWeb3 = (network: string, urlIndex: number = 0): PromiseAction<Web3Instance> => async (dispatch: Dispatch, getState: GetState): Promise<Web3Instance> => new Promise(async (resolve, reject) => {
|
||||
// check if requested web was initialized before
|
||||
const instance = getState().web3.find(w3 => w3.network === network);
|
||||
if (instance && instance.web3.currentProvider.connected) {
|
||||
@ -67,47 +59,45 @@ export const initWeb3 = (network: string, urlIndex: number = 0): PromiseAction<W
|
||||
const coin = config.coins.find(c => c.network === network);
|
||||
if (!coin) {
|
||||
// coin not found
|
||||
reject(new Error(`Network ${ network} not found in application config.`));
|
||||
reject(new Error(`Network ${network} not found in application config.`));
|
||||
return;
|
||||
}
|
||||
|
||||
// get first url
|
||||
const url = coin.web3[ urlIndex ];
|
||||
const url = coin.web3[urlIndex];
|
||||
if (!url) {
|
||||
reject(new Error('Web3 backend is not responding'));
|
||||
return;
|
||||
}
|
||||
|
||||
const web3 = new Web3( new Web3.providers.WebsocketProvider(url) );
|
||||
const web3 = new Web3(new Web3.providers.WebsocketProvider(url));
|
||||
|
||||
const onConnect = async () => {
|
||||
|
||||
const latestBlock = await web3.eth.getBlockNumber();
|
||||
const gasPrice = await web3.eth.getGasPrice();
|
||||
|
||||
const instance = {
|
||||
const newInstance = {
|
||||
network,
|
||||
web3,
|
||||
chainId: coin.chainId,
|
||||
erc20: new web3.eth.Contract(ERC20Abi),
|
||||
latestBlock,
|
||||
gasPrice,
|
||||
}
|
||||
};
|
||||
|
||||
dispatch({
|
||||
type: WEB3.CREATE,
|
||||
instance,
|
||||
instance: newInstance,
|
||||
});
|
||||
|
||||
resolve(instance);
|
||||
}
|
||||
resolve(newInstance);
|
||||
};
|
||||
|
||||
const onEnd = async () => {
|
||||
|
||||
web3.currentProvider.reset();
|
||||
const instance = getState().web3.find(w3 => w3.network === network);
|
||||
const oldInstance = getState().web3.find(w3 => w3.network === network);
|
||||
|
||||
if (instance && instance.web3.currentProvider.connected) {
|
||||
if (oldInstance && oldInstance.web3.currentProvider.connected) {
|
||||
// backend disconnects
|
||||
// dispatch({
|
||||
// type: 'WEB3.DISCONNECT',
|
||||
@ -116,22 +106,21 @@ export const initWeb3 = (network: string, urlIndex: number = 0): PromiseAction<W
|
||||
} else {
|
||||
// backend initialization error for given url, try next one
|
||||
try {
|
||||
const web3 = await dispatch( initWeb3(network, urlIndex + 1) );
|
||||
resolve(web3);
|
||||
const otherWeb3 = await dispatch(initWeb3(network, urlIndex + 1));
|
||||
resolve(otherWeb3);
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
web3.currentProvider.on('connect', onConnect);
|
||||
web3.currentProvider.on('end', onEnd);
|
||||
web3.currentProvider.on('error', onEnd);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const discoverAccount = (address: string, network: string): PromiseAction<EthereumAccount> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumAccount> => {
|
||||
const instance: Web3Instance = await dispatch( initWeb3(network) );
|
||||
export const discoverAccount = (address: string, network: string): PromiseAction<EthereumAccount> => async (dispatch: Dispatch): Promise<EthereumAccount> => {
|
||||
const instance: Web3Instance = await dispatch(initWeb3(network));
|
||||
const balance = await instance.web3.eth.getBalance(address);
|
||||
const nonce = await instance.web3.eth.getTransactionCount(address);
|
||||
return {
|
||||
@ -139,12 +128,12 @@ export const discoverAccount = (address: string, network: string): PromiseAction
|
||||
transactions: 0,
|
||||
block: 0,
|
||||
balance: EthereumjsUnits.convert(balance, 'wei', 'ether'),
|
||||
nonce
|
||||
nonce,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const resolvePendingTransactions = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const instance: Web3Instance = await dispatch( initWeb3(network) );
|
||||
const instance: Web3Instance = await dispatch(initWeb3(network));
|
||||
const pending = getState().pending.filter(p => p.network === network);
|
||||
for (const tx of pending) {
|
||||
const status = await instance.web3.eth.getTransaction(tx.id);
|
||||
@ -170,13 +159,14 @@ export const resolvePendingTransactions = (network: string): PromiseAction<void>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getPendingInfo = (network: string, txid: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const instance: Web3Instance = await dispatch( initWeb3(network) );
|
||||
/*
|
||||
export const getPendingInfo = (network: string, txid: string): PromiseAction<void> => async (dispatch: Dispatch): Promise<void> => {
|
||||
const instance: Web3Instance = await dispatch(initWeb3(network));
|
||||
const tx = await instance.web3.eth.getTransaction(txid);
|
||||
|
||||
/*
|
||||
|
||||
if (tx.input !== "0x") {
|
||||
// find token:
|
||||
// tx.to <= smart contract address
|
||||
@ -190,31 +180,33 @@ export const getPendingInfo = (network: string, txid: string): PromiseAction<voi
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
// return tx;
|
||||
}
|
||||
|
||||
export const getTxInput = (): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const instance: Web3Instance = await dispatch( initWeb3("ropsten") );
|
||||
// return tx;
|
||||
};
|
||||
|
||||
export const getTxInput = (): PromiseAction<void> => async (dispatch: Dispatch): Promise<void> => {
|
||||
const instance: Web3Instance = await dispatch(initWeb3('ropsten'));
|
||||
// const inputData = instance.web3.utils.hexToAscii("0xa9059cbb00000000000000000000000073d0385f4d8e00c5e6504c6030f47bf6212736a80000000000000000000000000000000000000000000000000000000000000001");
|
||||
// console.warn("input data!", inputData);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
export const updateAccount = (account: Account, newAccount: EthereumAccount, network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const instance: Web3Instance = await dispatch( initWeb3(network) );
|
||||
export const updateAccount = (account: Account, newAccount: EthereumAccount, network: string): PromiseAction<void> => async (dispatch: Dispatch): Promise<void> => {
|
||||
const instance: Web3Instance = await dispatch(initWeb3(network));
|
||||
const balance = await instance.web3.eth.getBalance(account.address);
|
||||
const nonce = await instance.web3.eth.getTransactionCount(account.address);
|
||||
dispatch( AccountsActions.update( { ...account, ...newAccount, balance: EthereumjsUnits.convert(balance, 'wei', 'ether'), nonce }) );
|
||||
dispatch(AccountsActions.update({
|
||||
...account, ...newAccount, balance: EthereumjsUnits.convert(balance, 'wei', 'ether'), nonce,
|
||||
}));
|
||||
|
||||
// update tokens for this account
|
||||
dispatch( updateAccountTokens(account) );
|
||||
}
|
||||
dispatch(updateAccountTokens(account));
|
||||
};
|
||||
|
||||
export const updateAccountTokens = (account: Account): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
const tokens = getState().tokens.filter(t => t.network === account.network && t.ethAddress === account.address);
|
||||
for (const token of tokens) {
|
||||
const balance = await dispatch( getTokenBalance(token) );
|
||||
const balance = await dispatch(getTokenBalance(token));
|
||||
// const newBalance: string = balance.dividedBy(Math.pow(10, token.decimals)).toString(10);
|
||||
if (balance !== token.balance) {
|
||||
dispatch(TokenActions.setBalance(
|
||||
@ -224,10 +216,10 @@ export const updateAccountTokens = (account: Account): PromiseAction<void> => as
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getTokenInfo = (address: string, network: string): PromiseAction<NetworkToken> => async (dispatch: Dispatch, getState: GetState): Promise<NetworkToken> => {
|
||||
const instance: Web3Instance = await dispatch( initWeb3(network) );
|
||||
export const getTokenInfo = (address: string, network: string): PromiseAction<NetworkToken> => async (dispatch: Dispatch): Promise<NetworkToken> => {
|
||||
const instance: Web3Instance = await dispatch(initWeb3(network));
|
||||
const contract = instance.erc20.clone();
|
||||
contract.options.address = address;
|
||||
|
||||
@ -243,40 +235,39 @@ export const getTokenInfo = (address: string, network: string): PromiseAction<Ne
|
||||
};
|
||||
};
|
||||
|
||||
export const getTokenBalance = (token: Token): PromiseAction<string> => async (dispatch: Dispatch, getState: GetState): Promise<string> => {
|
||||
const instance = await dispatch( initWeb3(token.network) );
|
||||
export const getTokenBalance = (token: Token): PromiseAction<string> => async (dispatch: Dispatch): Promise<string> => {
|
||||
const instance = await dispatch(initWeb3(token.network));
|
||||
const contract = instance.erc20.clone();
|
||||
contract.options.address = token.address;
|
||||
|
||||
const balance = await contract.methods.balanceOf(token.ethAddress).call();
|
||||
return new BigNumber(balance).dividedBy(Math.pow(10, token.decimals)).toString(10);
|
||||
return new BigNumber(balance).dividedBy(10 ** token.decimals).toString(10);
|
||||
};
|
||||
|
||||
export const getCurrentGasPrice = (network: string): PromiseAction<string> => async (dispatch: Dispatch, getState: GetState): Promise<string> => {
|
||||
const instance = getState().web3.find(w3 => w3.network === network);
|
||||
if (instance) {
|
||||
return EthereumjsUnits.convert(instance.gasPrice, 'wei', 'gwei');
|
||||
} else {
|
||||
throw "0";
|
||||
}
|
||||
}
|
||||
return '0';
|
||||
};
|
||||
|
||||
export const updateGasPrice = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
export const updateGasPrice = (network: string): PromiseAction<void> => async (dispatch: Dispatch): Promise<void> => {
|
||||
try {
|
||||
const instance = await dispatch( initWeb3(network) );
|
||||
const instance = await dispatch(initWeb3(network));
|
||||
const gasPrice = await instance.web3.eth.getGasPrice();
|
||||
if (instance.gasPrice !== gasPrice) {
|
||||
dispatch({
|
||||
type: WEB3.GAS_PRICE_UPDATED,
|
||||
network,
|
||||
gasPrice
|
||||
gasPrice,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// silent action
|
||||
// nothing happens if this fails
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const estimateGasLimit = (network: string, $options: EstimateGasOptions): PromiseAction<string> => async (dispatch: Dispatch): Promise<string> => {
|
||||
@ -308,7 +299,7 @@ export const disconnect = (coinInfo: any): ThunkAction => (dispatch: Dispatch, g
|
||||
// remove instance from reducer
|
||||
dispatch({
|
||||
type: WEB3.DISCONNECT,
|
||||
instance
|
||||
instance,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user