1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-25 00:18:07 +00:00

eslint ./src/actions

This commit is contained in:
Szymon Lesisz 2018-09-23 08:49:43 +02:00
parent d684eec819
commit ef235e6ab8
5 changed files with 26 additions and 33 deletions

View File

@ -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,
});

View File

@ -48,7 +48,7 @@ export const showUnverifiedAddress = (): Action => ({
});
//export const showAddress = (address_n: string): AsyncAction => {
export const showAddress = (address_n: Array<number>): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
export const showAddress = (path: Array<number>): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const selected = getState().wallet.selectedDevice;
if (!selected) return;
@ -66,7 +66,7 @@ export const showAddress = (address_n: Array<number>): 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<number>): AsyncAction => async (dis
{
label: 'Try again',
callback: () => {
dispatch(showAddress(address_n));
dispatch(showAddress(path));
},
},
],

View File

@ -27,7 +27,8 @@ export type TokenAction = {
// action from component <reactSelect>
export const load = (input: string, network: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<any> => {
export const load = ($input: string, network: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<any> => {
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<void> => {
@ -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<void> => {
export const add = (token: NetworkToken, account: Account): AsyncAction => async (dispatch: Dispatch): Promise<void> => {
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));
};

View File

@ -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<EthereumTransaction> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumTransaction> => {
const instance = await dispatch( initWeb3(tx.network) );
const token = tx.token;
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumTransaction> => async (dispatch: Dispatch): Promise<EthereumTransaction> => {
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<Ethereum
chainId: instance.chainId,
nonce: toHex(tx.nonce),
gasLimit: toHex(tx.gasLimit),
gasPrice: toHex( EthereumjsUnits.convert(tx.gasPrice, 'gwei', 'wei') ),
gasPrice: toHex(EthereumjsUnits.convert(tx.gasPrice, 'gwei', 'wei')),
r: '',
s: '',
v: '',
}
};
};
export const serializeEthereumTx = (tx: EthereumTransaction): PromiseAction<string> => async (dispatch: Dispatch, getState: GetState): Promise<string> => {
export const serializeEthereumTx = (tx: EthereumTransaction): PromiseAction<string> => async (): Promise<string> => {
const ethTx = new EthereumjsTx(tx);
return `0x${ ethTx.serialize().toString('hex') }`;
// return toHex( ethTx.serialize() );
}
return `0x${ethTx.serialize().toString('hex')}`;
};

View File

@ -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,