1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

code cleaning

This commit is contained in:
Szymon Lesisz 2018-05-11 21:01:43 +02:00
parent 1a08e4be6a
commit fce5f9d36f
4 changed files with 8 additions and 158 deletions

View File

@ -288,18 +288,6 @@ const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): Asy
AccountsActions.setBalance(ethAddress, network, device.state || 'undefined', web3instance.web3.fromWei(balance.toString(), 'ether')) AccountsActions.setBalance(ethAddress, network, device.state || 'undefined', web3instance.web3.fromWei(balance.toString(), 'ether'))
); );
const userTokens = [];
// const userTokens = [
// { symbol: 'T01', address: '0x58cda554935e4a1f2acbe15f8757400af275e084' },
// { symbol: 'Lahod', address: '0x3360d0ee34a49d9ac34dce88b000a2903f2806ee' },
// ];
for (let i = 0; i < userTokens.length; i++) {
const tokenBalance: string = await getTokenBalanceAsync(web3instance.erc20, userTokens[i]);
if (discoveryProcess.interrupted) return;
dispatch( setTokenBalance(userTokens[i].address, ethAddress, tokenBalance) )
}
const nonce: number = await getNonceAsync(web3instance.web3, ethAddress); const nonce: number = await getNonceAsync(web3instance.web3, ethAddress);
if (discoveryProcess.interrupted) return; if (discoveryProcess.interrupted) return;
dispatch(AccountsActions.setNonce(ethAddress, network, device.state || 'undefined', nonce)); dispatch(AccountsActions.setNonce(ethAddress, network, device.state || 'undefined', nonce));
@ -342,7 +330,7 @@ export const restore = (): ThunkAction => {
} }
} }
// TODO: rename method to something intuitive
// there is no discovery process but it should be // there is no discovery process but it should be
// this is possible race condition when "network" was changed in url but device was not authenticated yet // this is possible race condition when "network" was changed in url but device was not authenticated yet
// try to start discovery after CONNECT.AUTH_DEVICE action // try to start discovery after CONNECT.AUTH_DEVICE action

View File

@ -1,138 +0,0 @@
// flow-typed signature: ba132c96664f1a05288f3eb2272a3c35
// flow-typed version: c4bbd91cfc/redux_v3.x.x/flow_>=v0.33.x
// from : https://github.com/hmeerlo/redux-thunk-flow/blob/master/flow-typed/npm/redux_v3.x.x.js
// declare module 'redux' {
// /*
// S = State
// A = Action
// */
// /* NEW: We create a few extra action and dispatch types */
// declare export type ThunkAction<S, R> = (dispatch: Dispatch<S, any>, getState: () => S) => R;
// declare type PromiseAction<R> = { type: string, payload: Promise<R> };
// declare type ThunkDispatch<S> = <R>(action: ThunkAction<S, R>) => R;
// declare type PromiseDispatch = <R>(action: PromiseAction<R>) => Promise<R>;
// declare type PlainDispatch<A: {type: $Subtype<string>}> = (action: A) => A;
// /* NEW: Dispatch is now a combination of these different dispatch types */
// declare export type Dispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S> & PromiseDispatch;
// declare export type MiddlewareAPI<S, A> = {
// dispatch: Dispatch<S, A>;
// getState(): S;
// };
// declare export type Store<S, A> = {
// // rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
// dispatch: Dispatch<S, A>;
// getState(): S;
// subscribe(listener: () => void): () => void;
// replaceReducer(nextReducer: Reducer<S, A>): void
// };
// declare type Reducer<S, A> = (state: S, action: A) => S;
// declare export type Middleware<S, A> =
// (api: MiddlewareAPI<S, A>) =>
// (next: Dispatch<S, A>) => Dispatch<S, A>;
// declare type StoreCreator<S, A> = {
// (reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
// (reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
// };
// declare type StoreEnhancer<S, A> = (next: StoreCreator<S, A>) => StoreCreator<S, A>;
// declare function createStore<S, A>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
// declare function createStore<S, A>(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
// declare function applyMiddleware<S, A>(...middlewares: Array<Middleware<S, A>>): StoreEnhancer<S, A>;
// declare type ActionCreator<A, B> = (...args: Array<B>) => A;
// declare type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> };
// declare function bindActionCreators<S, A, C: ActionCreator<A, any>>(actionCreator: C, dispatch: Dispatch<S, A>): C;
// declare function bindActionCreators<S, A, K, C: ActionCreators<K, A>>(actionCreators: C, dispatch: Dispatch<S, A>): C;
// declare function combineReducers<O: Object, A>(reducers: O): Reducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
// declare function compose<S, A>(...fns: Array<StoreEnhancer<S, A>>): Function;
// }
// flow-typed signature: cca4916b0213065533df8335c3285a4a
// flow-typed version: cab04034e7/redux_v3.x.x/flow_>=v0.55.x
declare module 'redux' {
/*
S = State
A = Action
D = Dispatch
*/
declare export type DispatchAPI<A> = (action: A) => A;
// declare export type Dispatch<A: { type: $Subtype<string> }> = DispatchAPI<A>;
declare export type ThunkAction<S, A> = (dispatch: Dispatch<S, any>, getState: () => S) => Promise<void> | void;
declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void;
declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>;
/* NEW: Dispatch is now a combination of these different dispatch types */
declare export type Dispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A>;
// declare export type ThunkAction<S, D> = (dispatch: D, getState: () => S) => Promise<void> | void;
// declare type ThunkDispatch<S, D> = (action: ThunkAction<S, D & ThunkDispatch<S, D>>) => void;
declare export type MiddlewareAPI<S, A> = {
dispatch: Dispatch<S, A>;
getState(): S;
};
declare export type Store<S, A, D = Dispatch<S, A>> = {
// rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
dispatch: D;
getState(): S;
subscribe(listener: () => void): () => void;
replaceReducer(nextReducer: Reducer<S, A>): void
};
declare export type Reducer<S, A> = (state: S | void, action: A) => S;
declare export type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;
declare export type Middleware<S, A> =
(api: MiddlewareAPI<S, A>) =>
(next: PlainDispatch<A>) => PlainDispatch<A>;
declare export type StoreCreator<S, A, D = Dispatch<S, A>> = {
(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
};
declare export type StoreEnhancer<S, A, D = Dispatch<S, A>> = (next: StoreCreator<S, A, D>) => StoreCreator<S, A, D>;
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, preloadedState?: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
declare export function applyMiddleware<S, A, D>(...middlewares: Array<Middleware<S, A>>): StoreEnhancer<S, A, D>;
declare export type ActionCreator<A, B> = (...args: Array<B>) => A;
declare export type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> };
declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: DispatchAPI<A>>(actionCreator: C, dispatch: D): C;
declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: DispatchAPI<A>>(actionCreators: C, dispatch: D): C;
// declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: Dispatch>(actionCreator: C, dispatch: D): C;
// declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: Dispatch>(actionCreators: C, dispatch: D): C;
declare export function combineReducers<O: Object, A>(reducers: O): CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
declare export var compose: $Compose;
}

View File

@ -6,13 +6,8 @@ import { render } from 'react-dom';
import store from './store'; import store from './store';
import router from './router'; import router from './router';
import { onBeforeUnload } from './actions/WalletActions'; import { onBeforeUnload } from './actions/WalletActions';
import Raven from 'raven-js';
import styles from '../styles/index.less'; import styles from '../styles/index.less';
Raven.config('https://497392c3ff6e46dc9e54eef123979378@sentry.io/294339').install();
const root: ?HTMLElement = document.getElementById('root'); const root: ?HTMLElement = document.getElementById('root');
if (root) { if (root) {
render(router, root); render(router, root);
@ -22,5 +17,5 @@ window.onbeforeunload = () => {
store.dispatch( onBeforeUnload() ); store.dispatch( onBeforeUnload() );
} }
// workaround // workaround for web3
// yarn add web3@^0.19.0 // yarn add web3@^0.19.0

View File

@ -10,17 +10,22 @@ import createHistory from 'history/createHashHistory';
import { createLogger } from 'redux-logger'; import { createLogger } from 'redux-logger';
import reducers from '../reducers'; import reducers from '../reducers';
import services from '../services'; import services from '../services';
import Raven from 'raven-js';
import RavenMiddleware from 'redux-raven-middleware'; import RavenMiddleware from 'redux-raven-middleware';
import type { Action, GetState, Store } from '../flowtype'; import type { Action, GetState, Store } from '../flowtype';
export const history: History = createHistory( { queryKey: false } ); export const history: History = createHistory( { queryKey: false } );
const RAVEN_KEY: string = 'https://497392c3ff6e46dc9e54eef123979378@sentry.io/294339'
Raven.config(RAVEN_KEY).install();
const initialState: any = {}; const initialState: any = {};
const enhancers = []; const enhancers = [];
const middleware = [ const middleware = [
thunk, thunk,
RavenMiddleware('https://497392c3ff6e46dc9e54eef123979378@sentry.io/294339'), RavenMiddleware(RAVEN_KEY),
routerMiddleware(history) routerMiddleware(history)
]; ];