mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
eslint ./src/actions
This commit is contained in:
parent
d684eec819
commit
ef235e6ab8
@ -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,
|
||||
});
|
||||
|
@ -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));
|
||||
},
|
||||
},
|
||||
],
|
||||
|
@ -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];
|
||||
@ -47,6 +48,8 @@ export const load = (input: string, network: string): AsyncAction => async (disp
|
||||
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,
|
||||
|
@ -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> => {
|
||||
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumTransaction> => async (dispatch: Dispatch): Promise<EthereumTransaction> => {
|
||||
const instance = await dispatch(initWeb3(tx.network));
|
||||
const token = tx.token;
|
||||
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 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;
|
||||
@ -59,11 +54,10 @@ export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<Ethereum
|
||||
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() );
|
||||
}
|
||||
};
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user