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 */
|
/* @flow */
|
||||||
|
|
||||||
import * as ACCOUNT from 'actions/constants/account';
|
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';
|
import type { Account, State } from 'reducers/AccountsReducer';
|
||||||
|
|
||||||
export type AccountFromStorageAction = {
|
export type AccountFromStorageAction = {
|
||||||
@ -60,5 +60,5 @@ export const setNonce = (address: string, network: string, deviceState: string,
|
|||||||
|
|
||||||
export const update = (account: Account): Action => ({
|
export const update = (account: Account): Action => ({
|
||||||
type: ACCOUNT.UPDATE,
|
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: 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;
|
const selected = getState().wallet.selectedDevice;
|
||||||
if (!selected) return;
|
if (!selected) return;
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ export const showAddress = (address_n: Array<number>): AsyncAction => async (dis
|
|||||||
instance: selected.instance,
|
instance: selected.instance,
|
||||||
state: selected.state,
|
state: selected.state,
|
||||||
},
|
},
|
||||||
path: address_n,
|
path,
|
||||||
useEmptyPassphrase: !selected.instance,
|
useEmptyPassphrase: !selected.instance,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ export const showAddress = (address_n: Array<number>): AsyncAction => async (dis
|
|||||||
{
|
{
|
||||||
label: 'Try again',
|
label: 'Try again',
|
||||||
callback: () => {
|
callback: () => {
|
||||||
dispatch(showAddress(address_n));
|
dispatch(showAddress(path));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -27,7 +27,8 @@ export type TokenAction = {
|
|||||||
|
|
||||||
|
|
||||||
// action from component <reactSelect>
|
// 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';
|
if (input.length < 1) input = '0x';
|
||||||
|
|
||||||
const tokens = getState().localStorage.tokens[network];
|
const tokens = getState().localStorage.tokens[network];
|
||||||
@ -47,6 +48,8 @@ export const load = (input: string, network: string): AsyncAction => async (disp
|
|||||||
if (info) {
|
if (info) {
|
||||||
return [info];
|
return [info];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setBalance = (tokenAddress: string, ethAddress: string, balance: string): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
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 = {
|
const tkn: Token = {
|
||||||
loaded: false,
|
loaded: false,
|
||||||
deviceState: account.deviceState,
|
deviceState: account.deviceState,
|
||||||
|
@ -3,19 +3,15 @@
|
|||||||
import EthereumjsTx from 'ethereumjs-tx';
|
import EthereumjsTx from 'ethereumjs-tx';
|
||||||
import EthereumjsUnits from 'ethereumjs-units';
|
import EthereumjsUnits from 'ethereumjs-units';
|
||||||
import BigNumber from 'bignumber.js';
|
import BigNumber from 'bignumber.js';
|
||||||
import { toHex } from 'web3-utils';
|
import { toHex } from 'web3-utils'; // eslint-disable-line import/no-extraneous-dependencies
|
||||||
import { initWeb3 } from './Web3Actions';
|
import { initWeb3 } from 'actions/Web3Actions';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Dispatch,
|
Dispatch,
|
||||||
GetState,
|
|
||||||
PromiseAction,
|
PromiseAction,
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
|
|
||||||
import type {
|
import type { EthereumTransaction } from 'trezor-connect';
|
||||||
EthereumTransaction
|
|
||||||
} from 'trezor-connect';
|
|
||||||
|
|
||||||
import type { Token } from 'reducers/TokensReducer';
|
import type { Token } from 'reducers/TokensReducer';
|
||||||
|
|
||||||
type EthereumTxRequest = {
|
type EthereumTxRequest = {
|
||||||
@ -30,19 +26,18 @@ type EthereumTxRequest = {
|
|||||||
nonce: number;
|
nonce: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumTransaction> => async (dispatch: Dispatch): Promise<EthereumTransaction> => {
|
||||||
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumTransaction> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumTransaction> => {
|
|
||||||
const instance = await dispatch(initWeb3(tx.network));
|
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 data: string = `0x${tx.data}`; // TODO: check if already prefixed
|
||||||
let value: string = toHex(EthereumjsUnits.convert(tx.amount, 'ether', 'wei'));
|
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) {
|
if (token) {
|
||||||
// smart contract transaction
|
// smart contract transaction
|
||||||
const contract = instance.erc20.clone();
|
const contract = instance.erc20.clone();
|
||||||
contract.options.address = token.address;
|
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();
|
data = instance.erc20.methods.transfer(to, tokenAmount).encodeABI();
|
||||||
value = '0x00';
|
value = '0x00';
|
||||||
to = token.address;
|
to = token.address;
|
||||||
@ -59,11 +54,10 @@ export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<Ethereum
|
|||||||
r: '',
|
r: '',
|
||||||
s: '',
|
s: '',
|
||||||
v: '',
|
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);
|
const ethTx = new EthereumjsTx(tx);
|
||||||
return `0x${ethTx.serialize().toString('hex')}`;
|
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 * as stateUtils from 'reducers/utils';
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
Account,
|
|
||||||
Coin,
|
|
||||||
Discovery,
|
|
||||||
Token,
|
|
||||||
Device,
|
Device,
|
||||||
TrezorDevice,
|
TrezorDevice,
|
||||||
RouterLocationState,
|
RouterLocationState,
|
||||||
|
Loading…
Reference in New Issue
Block a user