From ef235e6ab8123a3a62948810b06c8506d36a2d03 Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Sun, 23 Sep 2018 08:49:43 +0200 Subject: [PATCH] eslint ./src/actions --- src/actions/AccountsActions.js | 4 ++-- src/actions/ReceiveActions.js | 6 +++--- src/actions/TokenActions.js | 11 +++++++---- src/actions/TxActions.js | 34 ++++++++++++++-------------------- src/actions/WalletActions.js | 4 ---- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/actions/AccountsActions.js b/src/actions/AccountsActions.js index 8c14e594..27d4c46b 100644 --- a/src/actions/AccountsActions.js +++ b/src/actions/AccountsActions.js @@ -1,7 +1,7 @@ /* @flow */ import * as ACCOUNT from 'actions/constants/account'; -import type { Action, TrezorDevice } from 'flowtype'; +import type { Action } from 'flowtype'; import type { Account, State } from 'reducers/AccountsReducer'; export type AccountFromStorageAction = { @@ -60,5 +60,5 @@ export const setNonce = (address: string, network: string, deviceState: string, export const update = (account: Account): Action => ({ type: ACCOUNT.UPDATE, - payload: account + payload: account, }); diff --git a/src/actions/ReceiveActions.js b/src/actions/ReceiveActions.js index 51b7f548..6f193e48 100644 --- a/src/actions/ReceiveActions.js +++ b/src/actions/ReceiveActions.js @@ -48,7 +48,7 @@ export const showUnverifiedAddress = (): Action => ({ }); //export const showAddress = (address_n: string): AsyncAction => { -export const showAddress = (address_n: Array): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const showAddress = (path: Array): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { const selected = getState().wallet.selectedDevice; if (!selected) return; @@ -66,7 +66,7 @@ export const showAddress = (address_n: Array): AsyncAction => async (dis instance: selected.instance, state: selected.state, }, - path: address_n, + path, useEmptyPassphrase: !selected.instance, }); @@ -90,7 +90,7 @@ export const showAddress = (address_n: Array): AsyncAction => async (dis { label: 'Try again', callback: () => { - dispatch(showAddress(address_n)); + dispatch(showAddress(path)); }, }, ], diff --git a/src/actions/TokenActions.js b/src/actions/TokenActions.js index 68860968..eea041e8 100644 --- a/src/actions/TokenActions.js +++ b/src/actions/TokenActions.js @@ -27,7 +27,8 @@ export type TokenAction = { // action from component -export const load = (input: string, network: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const load = ($input: string, network: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { + let input = $input; if (input.length < 1) input = '0x'; const tokens = getState().localStorage.tokens[network]; @@ -43,10 +44,12 @@ export const load = (input: string, network: string): AsyncAction => async (disp return result.slice(0, 100); } - const info = await dispatch( BlockchainActions.getTokenInfo(input, network) ); + const info = await dispatch(BlockchainActions.getTokenInfo(input, network)); if (info) { return [info]; } + + return null; }; export const setBalance = (tokenAddress: string, ethAddress: string, balance: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { @@ -63,7 +66,7 @@ export const setBalance = (tokenAddress: string, ethAddress: string, balance: st }); }; -export const add = (token: NetworkToken, account: Account): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const add = (token: NetworkToken, account: Account): AsyncAction => async (dispatch: Dispatch): Promise => { const tkn: Token = { loaded: false, deviceState: account.deviceState, @@ -81,7 +84,7 @@ export const add = (token: NetworkToken, account: Account): AsyncAction => async payload: tkn, }); - const tokenBalance = await dispatch( BlockchainActions.getTokenBalance(tkn) ); + const tokenBalance = await dispatch(BlockchainActions.getTokenBalance(tkn)); dispatch(setBalance(token.address, account.address, tokenBalance)); }; diff --git a/src/actions/TxActions.js b/src/actions/TxActions.js index 8bdaed0e..67c93c9f 100644 --- a/src/actions/TxActions.js +++ b/src/actions/TxActions.js @@ -3,19 +3,15 @@ import EthereumjsTx from 'ethereumjs-tx'; import EthereumjsUnits from 'ethereumjs-units'; import BigNumber from 'bignumber.js'; -import { toHex } from 'web3-utils'; -import { initWeb3 } from './Web3Actions'; +import { toHex } from 'web3-utils'; // eslint-disable-line import/no-extraneous-dependencies +import { initWeb3 } from 'actions/Web3Actions'; import type { Dispatch, - GetState, PromiseAction, } from 'flowtype'; -import type { - EthereumTransaction -} from 'trezor-connect'; - +import type { EthereumTransaction } from 'trezor-connect'; import type { Token } from 'reducers/TokensReducer'; type EthereumTxRequest = { @@ -30,19 +26,18 @@ type EthereumTxRequest = { nonce: number; } - -export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { - const instance = await dispatch( initWeb3(tx.network) ); - const token = tx.token; +export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction => async (dispatch: Dispatch): Promise => { + const instance = await dispatch(initWeb3(tx.network)); + const { token } = tx; let data: string = `0x${tx.data}`; // TODO: check if already prefixed - let value: string = toHex( EthereumjsUnits.convert(tx.amount, 'ether', 'wei') ); - let to: string = tx.to; + let value: string = toHex(EthereumjsUnits.convert(tx.amount, 'ether', 'wei')); + let to: string = tx.to; // eslint-disable-line prefer-destructuring if (token) { // smart contract transaction const contract = instance.erc20.clone(); contract.options.address = token.address; - const tokenAmount: string = new BigNumber(tx.amount).times(Math.pow(10, token.decimals)).toString(10); + const tokenAmount: string = new BigNumber(tx.amount).times(10 ** token.decimals).toString(10); data = instance.erc20.methods.transfer(to, tokenAmount).encodeABI(); value = '0x00'; to = token.address; @@ -55,15 +50,14 @@ export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const serializeEthereumTx = (tx: EthereumTransaction): PromiseAction => async (): Promise => { const ethTx = new EthereumjsTx(tx); - return `0x${ ethTx.serialize().toString('hex') }`; - // return toHex( ethTx.serialize() ); -} \ No newline at end of file + return `0x${ethTx.serialize().toString('hex')}`; +}; \ No newline at end of file diff --git a/src/actions/WalletActions.js b/src/actions/WalletActions.js index 32830e26..9126c541 100644 --- a/src/actions/WalletActions.js +++ b/src/actions/WalletActions.js @@ -6,10 +6,6 @@ import * as WALLET from 'actions/constants/wallet'; import * as stateUtils from 'reducers/utils'; import type { - Account, - Coin, - Discovery, - Token, Device, TrezorDevice, RouterLocationState,