eslint fixes

pull/69/head
Szymon Lesisz 6 years ago
parent 1e4a6c3c21
commit d9239495fa

@ -12,6 +12,7 @@
"jest": true "jest": true
}, },
"rules": { "rules": {
"no-use-before-define": 0,
"no-plusplus": 0, "no-plusplus": 0,
"class-methods-use-this": 0, "class-methods-use-this": 0,
"react/require-default-props": 0, "react/require-default-props": 0,

@ -17,7 +17,7 @@ import type { RouterAction } from 'react-router-redux';
/* /*
* Parse url string to RouterLocationState object (key/value) * Parse url string to RouterLocationState object (key/value)
*/ */
export const pathToParams = (path: string): PayloadAction<RouterLocationState> => (dispatch: Dispatch, getState: GetState): RouterLocationState => { export const pathToParams = (path: string): PayloadAction<RouterLocationState> => (): RouterLocationState => {
// split url into parts // split url into parts
const parts: Array<string> = path.split('/').slice(1); const parts: Array<string> = path.split('/').slice(1);
const params: RouterLocationState = {}; const params: RouterLocationState = {};
@ -34,8 +34,9 @@ export const pathToParams = (path: string): PayloadAction<RouterLocationState> =
if (params.hasOwnProperty('device')) { if (params.hasOwnProperty('device')) {
const isClonedDevice: Array<string> = params.device.split(':'); const isClonedDevice: Array<string> = params.device.split(':');
if (isClonedDevice.length > 1) { if (isClonedDevice.length > 1) {
params.device = isClonedDevice[0]; const [device, instance] = isClonedDevice;
params.deviceInstance = isClonedDevice[1]; params.device = device;
params.deviceInstance = instance;
} }
} }
return params; return params;
@ -74,22 +75,22 @@ export const paramsValidation = (params: RouterLocationState): PayloadAction<boo
// } // }
return true; return true;
} };
/* /*
* Composing url string from given RouterLocationState object * Composing url string from given RouterLocationState object
* Filters unrecognized fields and sorting in correct order * Filters unrecognized fields and sorting in correct order
*/ */
export const paramsToPath = (params: RouterLocationState): PayloadAction<?string> => (dispatch: Dispatch, getState: GetState): ?string => { export const paramsToPath = (params: RouterLocationState): PayloadAction<?string> => (): ?string => {
// get patterns (fields) from routes and sort them by complexity // get patterns (fields) from routes and sort them by complexity
const patterns: Array<Array<string>> = routes.map(r => r.fields).sort((a, b) => { const patterns: Array<Array<string>> = routes.map(r => r.fields).sort((a, b) => (a.length > b.length ? -1 : 1));
return a.length > b.length ? -1 : 1;
});
// find pattern // find pattern
const keys: Array<string> = Object.keys(params); const keys: Array<string> = Object.keys(params);
let patternToUse: ?Array<string>; let patternToUse: ?Array<string>;
for (let pattern of patterns) { let i: number;
for (i = 0; i < patterns.length; i++) {
const pattern = patterns[i];
const match: Array<string> = keys.filter(key => pattern.indexOf(key) >= 0); const match: Array<string> = keys.filter(key => pattern.indexOf(key) >= 0);
if (match.length === pattern.length) { if (match.length === pattern.length) {
patternToUse = pattern; patternToUse = pattern;
@ -102,7 +103,7 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction<?string
// compose url string from pattern // compose url string from pattern
let url: string = ''; let url: string = '';
patternToUse.forEach(field => { patternToUse.forEach((field) => {
if (field === params[field]) { if (field === params[field]) {
// standalone (odd) fields // standalone (odd) fields
url += `/${field}`; url += `/${field}`;
@ -114,10 +115,9 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction<?string
} }
} }
} }
}); });
return url; return url;
} };
export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dispatch: Dispatch, getState: GetState): string => { export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dispatch: Dispatch, getState: GetState): string => {
const { location } = getState().router; const { location } = getState().router;
@ -138,8 +138,7 @@ export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dis
// example 2 (invalid blocking): url changes while passphrase modal opened because device disconnect // example 2 (invalid blocking): url changes while passphrase modal opened because device disconnect
const currentParams = dispatch(pathToParams(location.pathname)); const currentParams = dispatch(pathToParams(location.pathname));
const currentParamsAreValid = dispatch(paramsValidation(currentParams)); const currentParamsAreValid = dispatch(paramsValidation(currentParams));
if (currentParamsAreValid) if (currentParamsAreValid) { return location.pathname; }
return location.pathname;
} }
// there are no connected devices or application isn't ready or initialization error occurred // there are no connected devices or application isn't ready or initialization error occurred
@ -169,8 +168,7 @@ export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dis
// Compose valid url from requested params // Compose valid url from requested params
const composedUrl = dispatch(paramsToPath(requestedParams)); const composedUrl = dispatch(paramsToPath(requestedParams));
return composedUrl || location.pathname; return composedUrl || location.pathname;
} };
/* /*
@ -216,7 +214,7 @@ export const selectDevice = (device: TrezorDevice | Device): ThunkAction => (dis
if (currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) { if (currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) {
dispatch(goto(url)); dispatch(goto(url));
} }
} };
/* /*
* Try to find first available device using order: * Try to find first available device using order:
@ -239,7 +237,7 @@ export const selectFirstAvailableDevice = (): ThunkAction => (dispatch: Dispatch
} else { } else {
dispatch(gotoLandingPage()); dispatch(gotoLandingPage());
} }
} };
/* /*
* Internal method. redirect to given url * Internal method. redirect to given url
@ -248,28 +246,29 @@ const goto = (url: string): ThunkAction => (dispatch: Dispatch, getState: GetSta
if (getState().router.location.pathname !== url) { if (getState().router.location.pathname !== url) {
dispatch(push(url)); dispatch(push(url));
} }
} };
/* /*
* Check if requested OR current url is landing page * Check if requested OR current url is landing page
*/ */
export const isLandingPageUrl = (url?: string): PayloadAction<boolean> => (dispatch: Dispatch, getState: GetState): boolean => { export const isLandingPageUrl = ($url?: string): PayloadAction<boolean> => (dispatch: Dispatch, getState: GetState): boolean => {
let url: ?string = $url;
if (typeof url !== 'string') { if (typeof url !== 'string') {
url = getState().router.location.pathname; url = getState().router.location.pathname;
} }
// TODO: add more landing page cases/urls to config.json (like /tools etc) // TODO: add more landing page cases/urls to config.json (like /tools etc)
return (url === '/' || url === '/bridge'); return (url === '/' || url === '/bridge');
} };
/* /*
* Try to redirect to landing page * Try to redirect to landing page
*/ */
export const gotoLandingPage = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { export const gotoLandingPage = (): ThunkAction => (dispatch: Dispatch): void => {
const isLandingPage = dispatch(isLandingPageUrl()); const isLandingPage = dispatch(isLandingPageUrl());
if (!isLandingPage) { if (!isLandingPage) {
dispatch(goto('/')); dispatch(goto('/'));
} }
} };
/* /*
* Go to given device settings page * Go to given device settings page
@ -291,10 +290,10 @@ export const setInitialUrl = (): PayloadAction<boolean> => (dispatch: Dispatch,
type: LOCATION_CHANGE, type: LOCATION_CHANGE,
payload: { payload: {
pathname: initialPathname, pathname: initialPathname,
hash: "", hash: '',
search: "", search: '',
state: {} state: {},
} },
})); }));
if (valid === initialPathname) { if (valid === initialPathname) {
dispatch(goto(valid)); dispatch(goto(valid));
@ -302,4 +301,4 @@ export const setInitialUrl = (): PayloadAction<boolean> => (dispatch: Dispatch,
} }
} }
return false; return false;
} };

@ -20,8 +20,6 @@ import type {
State, State,
} from 'flowtype'; } from 'flowtype';
export type SelectedAccountAction = { export type SelectedAccountAction = {
type: typeof ACCOUNT.DISPOSE, type: typeof ACCOUNT.DISPOSE,
} | { } | {
@ -55,7 +53,6 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
|| prevState.discovery !== state.discovery || prevState.discovery !== state.discovery
|| prevState.tokens !== state.tokens || prevState.tokens !== state.tokens
|| prevState.pending !== state.pending) { || prevState.pending !== state.pending) {
const account = stateUtils.getSelectedAccount(state); const account = stateUtils.getSelectedAccount(state);
const network = stateUtils.getSelectedNetwork(state); const network = stateUtils.getSelectedNetwork(state);
const discovery = stateUtils.getDiscoveryProcess(state); const discovery = stateUtils.getDiscoveryProcess(state);

@ -1,10 +1,9 @@
/* @flow */ /* @flow */
import TrezorConnect, { import TrezorConnect, {
UI, DEVICE, DEVICE_EVENT, UI_EVENT, TRANSPORT_EVENT, BLOCKCHAIN_EVENT DEVICE, DEVICE_EVENT, UI_EVENT, TRANSPORT_EVENT, BLOCKCHAIN_EVENT,
} from 'trezor-connect'; } from 'trezor-connect';
import * as CONNECT from 'actions/constants/TrezorConnect'; import * as CONNECT from 'actions/constants/TrezorConnect';
import * as NOTIFICATION from 'actions/constants/notification'; import * as NOTIFICATION from 'actions/constants/notification';
import * as WALLET from 'actions/constants/wallet';
import { getDuplicateInstanceNumber } from 'reducers/utils'; import { getDuplicateInstanceNumber } from 'reducers/utils';
import * as RouterActions from 'actions/RouterActions'; import * as RouterActions from 'actions/RouterActions';
@ -27,7 +26,6 @@ import type {
AsyncAction, AsyncAction,
Device, Device,
TrezorDevice, TrezorDevice,
RouterLocationState,
} from 'flowtype'; } from 'flowtype';
import * as DiscoveryActions from './DiscoveryActions'; import * as DiscoveryActions from './DiscoveryActions';
@ -82,7 +80,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
// set listeners // set listeners
TrezorConnect.on(DEVICE_EVENT, (event: DeviceMessage): void => { TrezorConnect.on(DEVICE_EVENT, (event: DeviceMessage): void => {
// post event to reducers // post event to reducers
const type: DeviceMessageType = event.type; // assert flow type const type: DeviceMessageType = event.type; // eslint-disable-line prefer-destructuring
dispatch({ dispatch({
type, type,
device: event.payload, device: event.payload,
@ -91,7 +89,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
TrezorConnect.on(UI_EVENT, (event: UiMessage): void => { TrezorConnect.on(UI_EVENT, (event: UiMessage): void => {
// post event to reducers // post event to reducers
const type: UiMessageType = event.type; // assert flow type const type: UiMessageType = event.type; // eslint-disable-line prefer-destructuring
dispatch({ dispatch({
type, type,
payload: event.payload, payload: event.payload,
@ -100,7 +98,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
TrezorConnect.on(TRANSPORT_EVENT, (event: TransportMessage): void => { TrezorConnect.on(TRANSPORT_EVENT, (event: TransportMessage): void => {
// post event to reducers // post event to reducers
const type: TransportMessageType = event.type; // assert flow type const type: TransportMessageType = event.type; // eslint-disable-line prefer-destructuring
dispatch({ dispatch({
type, type,
payload: event.payload, payload: event.payload,
@ -109,16 +107,17 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
TrezorConnect.on(BLOCKCHAIN_EVENT, (event: BlockchainMessage): void => { TrezorConnect.on(BLOCKCHAIN_EVENT, (event: BlockchainMessage): void => {
// post event to reducers // post event to reducers
const type: BlockchainMessageType = event.type; // assert flow type const type: BlockchainMessageType = event.type; // eslint-disable-line prefer-destructuring
dispatch({ dispatch({
type, type,
payload: event.payload, payload: event.payload,
}); });
}); });
/* global LOCAL */
// $FlowIssue LOCAL not declared // $FlowIssue LOCAL not declared
window.__TREZOR_CONNECT_SRC = typeof LOCAL === 'string' ? LOCAL : 'https://sisyfos.trezor.io/connect/'; window.__TREZOR_CONNECT_SRC = typeof LOCAL === 'string' ? LOCAL : 'https://sisyfos.trezor.io/connect/'; // eslint-disable-line no-underscore-dangle
// window.__TREZOR_CONNECT_SRC = typeof LOCAL === 'string' ? LOCAL : 'https://connect.trezor.io/5/'; // window.__TREZOR_CONNECT_SRC = typeof LOCAL === 'string' ? LOCAL : 'https://connect.trezor.io/5/'; // eslint-disable-line no-underscore-dangle
try { try {
await TrezorConnect.init({ await TrezorConnect.init({
@ -138,7 +137,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
// called after backend was initialized // called after backend was initialized
// set listeners for connect/disconnect // set listeners for connect/disconnect
export const postInit = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { export const postInit = (): ThunkAction => (dispatch: Dispatch): void => {
const handleDeviceConnect = (device: Device) => { const handleDeviceConnect = (device: Device) => {
dispatch(RouterActions.selectDevice(device)); dispatch(RouterActions.selectDevice(device));
}; };
@ -149,12 +148,10 @@ export const postInit = (): ThunkAction => (dispatch: Dispatch, getState: GetSta
TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect); TrezorConnect.on(DEVICE.CONNECT, handleDeviceConnect);
TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect); TrezorConnect.on(DEVICE.CONNECT_UNACQUIRED, handleDeviceConnect);
const { devices } = getState();
// try to redirect to initial url // try to redirect to initial url
if (!dispatch(RouterActions.setInitialUrl())) { if (!dispatch(RouterActions.setInitialUrl())) {
// if initial redirection fails try to switch to first available device // if initial redirection fails try to switch to first available device
dispatch( RouterActions.selectFirstAvailableDevice() ) dispatch(RouterActions.selectFirstAvailableDevice());
} }
}; };
@ -237,7 +234,7 @@ export const coinChanged = (network: ?string): ThunkAction => (dispatch: Dispatc
}; };
export function reload(): AsyncAction { export function reload(): AsyncAction {
return async (dispatch: Dispatch, getState: GetState): Promise<void> => { return async (): Promise<void> => {
}; };
} }

@ -9,7 +9,6 @@ import type {
PayloadAction as ReduxPayloadAction, PayloadAction as ReduxPayloadAction,
AsyncAction as ReduxAsyncAction, AsyncAction as ReduxAsyncAction,
PromiseAction as ReduxPromiseAction, PromiseAction as ReduxPromiseAction,
ThunkDispatch as ReduxThunkDispatch,
PlainDispatch as ReduxPlainDispatch, PlainDispatch as ReduxPlainDispatch,
} from 'redux'; } from 'redux';

@ -1,6 +1,4 @@
/* @flow */ /* @flow */
import * as ACCOUNT from 'actions/constants/account'; import * as ACCOUNT from 'actions/constants/account';
import type { import type {
@ -14,7 +12,6 @@ import type {
export type State = { export type State = {
location?: string; location?: string;
account: ?Account; account: ?Account;
network: ?Coin; network: ?Coin;
tokens: Array<Token>, tokens: Array<Token>,

@ -37,8 +37,8 @@ export default function wallet(state: State = initialState, action: Action): Sta
case WALLET.ON_BEFORE_UNLOAD: case WALLET.ON_BEFORE_UNLOAD:
return { return {
...state, ...state,
unloading: true unloading: true,
} };
case WALLET.SET_INITIAL_URL: case WALLET.SET_INITIAL_URL:
return { return {

@ -7,9 +7,6 @@ import type {
MiddlewareAPI, MiddlewareAPI,
MiddlewareDispatch, MiddlewareDispatch,
Action, Action,
ThunkAction,
RouterLocationState,
TrezorDevice,
} from 'flowtype'; } from 'flowtype';
/** /**
@ -27,22 +24,23 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
// compose valid url // compose valid url
const validUrl = api.dispatch(RouterActions.getValidUrl(action)); const validUrl = api.dispatch(RouterActions.getValidUrl(action));
// override action state (to be stored in RouterReducer) // override action state (to be stored in RouterReducer)
action.payload.state = api.dispatch( RouterActions.pathToParams(validUrl) ); const override = action;
override.payload.state = api.dispatch(RouterActions.pathToParams(validUrl));
const redirect = action.payload.pathname !== validUrl; const redirect = action.payload.pathname !== validUrl;
if (redirect) { if (redirect) {
// override action pathname // override action pathname
action.payload.pathname = validUrl; override.payload.pathname = validUrl;
} }
// pass action // pass action
next(action); next(override);
if (redirect) { if (redirect) {
// replace invalid url // replace invalid url
api.dispatch(replace(validUrl)); api.dispatch(replace(validUrl));
} }
return action; return override;
}; };
export default RouterService; export default RouterService;

@ -1,7 +1,7 @@
/* @flow */ /* @flow */
import TrezorConnect, { import {
TRANSPORT, DEVICE_EVENT, UI_EVENT, UI, DEVICE, BLOCKCHAIN TRANSPORT, DEVICE, BLOCKCHAIN,
} from 'trezor-connect'; } from 'trezor-connect';
import * as TrezorConnectActions from 'actions/TrezorConnectActions'; import * as TrezorConnectActions from 'actions/TrezorConnectActions';
import * as DiscoveryActions from 'actions/DiscoveryActions'; import * as DiscoveryActions from 'actions/DiscoveryActions';

@ -1,6 +1,4 @@
/* @flow */ /* @flow */
import { DEVICE } from 'trezor-connect'; import { DEVICE } from 'trezor-connect';
import { LOCATION_CHANGE } from 'react-router-redux'; import { LOCATION_CHANGE } from 'react-router-redux';
import * as WALLET from 'actions/constants/wallet'; import * as WALLET from 'actions/constants/wallet';
@ -49,7 +47,7 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
case WALLET.SET_INITIAL_URL: case WALLET.SET_INITIAL_URL:
api.dispatch(LocalStorageActions.loadData()); api.dispatch(LocalStorageActions.loadData());
break; break;
case WALLET.SET_SELECTED_DEVICE: { case WALLET.SET_SELECTED_DEVICE:
if (action.device) { if (action.device) {
// try to authorize device // try to authorize device
api.dispatch(TrezorConnectActions.getSelectedDeviceState()); api.dispatch(TrezorConnectActions.getSelectedDeviceState());
@ -57,7 +55,6 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
// try select different device // try select different device
api.dispatch(RouterActions.selectFirstAvailableDevice()); api.dispatch(RouterActions.selectFirstAvailableDevice());
} }
}
break; break;
case DEVICE.CONNECT: case DEVICE.CONNECT:
api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device)); api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device));

@ -10,78 +10,78 @@ export const routes: Array<Route> = [
{ {
name: 'landing-home', name: 'landing-home',
pattern: '/', pattern: '/',
fields: [] fields: [],
}, },
{ {
name: 'landing-bridge', name: 'landing-bridge',
pattern: '/bridge', pattern: '/bridge',
fields: ['bridge'] fields: ['bridge'],
}, },
{ {
name: 'landing-import', name: 'landing-import',
pattern: '/import', pattern: '/import',
fields: ['import'] fields: ['import'],
}, },
{ {
name: 'wallet-setting', name: 'wallet-setting',
pattern: '/settings', pattern: '/settings',
fields: ['settings'] fields: ['settings'],
}, },
{ {
name: 'wallet-acquire', name: 'wallet-acquire',
pattern: '/device/:device/acquire', pattern: '/device/:device/acquire',
fields: ['device', 'acquire'] fields: ['device', 'acquire'],
}, },
{ {
name: 'wallet-unreadable', name: 'wallet-unreadable',
pattern: '/device/:device/unreadable', pattern: '/device/:device/unreadable',
fields: ['device', 'unreadable'] fields: ['device', 'unreadable'],
}, },
{ {
name: 'wallet-bootloader', name: 'wallet-bootloader',
pattern: '/device/:device/bootloader', pattern: '/device/:device/bootloader',
fields: ['device', 'bootloader'] fields: ['device', 'bootloader'],
}, },
{ {
name: 'wallet-initialize', name: 'wallet-initialize',
pattern: '/device/:device/initialize', pattern: '/device/:device/initialize',
fields: ['device', 'initialize'] fields: ['device', 'initialize'],
}, },
{ {
name: 'wallet-device-settings', name: 'wallet-device-settings',
pattern: '/device/:device/settings', pattern: '/device/:device/settings',
fields: ['device', 'settings'] fields: ['device', 'settings'],
}, },
{ {
name: 'wallet-dashboard', name: 'wallet-dashboard',
pattern: '/device/:device', pattern: '/device/:device',
fields: ['device'] fields: ['device'],
}, },
{ {
name: 'wallet-account-summary', name: 'wallet-account-summary',
pattern: '/device/:device/network/:network/account/:account', pattern: '/device/:device/network/:network/account/:account',
fields: ['device', 'network', 'account'] fields: ['device', 'network', 'account'],
}, },
{ {
name: 'wallet-account-send', name: 'wallet-account-send',
pattern: '/device/:device/network/:network/account/:account/send', pattern: '/device/:device/network/:network/account/:account/send',
fields: ['device', 'network', 'account', 'send'] fields: ['device', 'network', 'account', 'send'],
}, },
{ {
name: 'wallet-account-send-override', name: 'wallet-account-send-override',
pattern: '/device/:device/network/:network/account/:account/send/override', pattern: '/device/:device/network/:network/account/:account/send/override',
fields: ['device', 'network', 'account', 'send'] fields: ['device', 'network', 'account', 'send'],
}, },
{ {
name: 'wallet-account-receive', name: 'wallet-account-receive',
pattern: '/device/:device/network/:network/account/:account/receive', pattern: '/device/:device/network/:network/account/:account/receive',
fields: ['device', 'network', 'account', 'receive'] fields: ['device', 'network', 'account', 'receive'],
}, },
{ {
name: 'wallet-account-signverify', name: 'wallet-account-signverify',
pattern: '/device/:device/network/:network/account/:account/signverify', pattern: '/device/:device/network/:network/account/:account/signverify',
fields: ['device', 'network', 'account', 'signverify'] fields: ['device', 'network', 'account', 'signverify'],
} },
]; ];
export const getPattern = (name: string): string => { export const getPattern = (name: string): string => {
@ -91,4 +91,4 @@ export const getPattern = (name: string): string => {
return '/'; return '/';
} }
return entry.pattern; return entry.pattern;
} };

@ -30,7 +30,7 @@ const SelectedAccount = (props: Props) => {
const { const {
account, account,
discovery, discovery,
network network,
} = accountState; } = accountState;
// corner case: accountState didn't finish loading state after LOCATION_CHANGE action // corner case: accountState didn't finish loading state after LOCATION_CHANGE action
@ -44,12 +44,13 @@ const SelectedAccount = (props: Props) => {
title="Backend not connected" title="Backend not connected"
actions={ actions={
[{ [{
label: "Try again", label: 'Try again',
callback: async () => { callback: async () => {
await props.blockchainReconnect(network.network); await props.blockchainReconnect(network.network);
} },
}] }]
} /> }
/>
); );
} }

Loading…
Cancel
Save