mirror of
https://github.com/trezor/trezor-wallet
synced 2025-02-24 14:02:09 +00:00
eslint fixes
This commit is contained in:
parent
1e4a6c3c21
commit
d9239495fa
@ -12,6 +12,7 @@
|
||||
"jest": true
|
||||
},
|
||||
"rules": {
|
||||
"no-use-before-define": 0,
|
||||
"no-plusplus": 0,
|
||||
"class-methods-use-this": 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)
|
||||
*/
|
||||
export const pathToParams = (path: string): PayloadAction<RouterLocationState> => (dispatch: Dispatch, getState: GetState): RouterLocationState => {
|
||||
export const pathToParams = (path: string): PayloadAction<RouterLocationState> => (): RouterLocationState => {
|
||||
// split url into parts
|
||||
const parts: Array<string> = path.split('/').slice(1);
|
||||
const params: RouterLocationState = {};
|
||||
@ -34,8 +34,9 @@ export const pathToParams = (path: string): PayloadAction<RouterLocationState> =
|
||||
if (params.hasOwnProperty('device')) {
|
||||
const isClonedDevice: Array<string> = params.device.split(':');
|
||||
if (isClonedDevice.length > 1) {
|
||||
params.device = isClonedDevice[0];
|
||||
params.deviceInstance = isClonedDevice[1];
|
||||
const [device, instance] = isClonedDevice;
|
||||
params.device = device;
|
||||
params.deviceInstance = instance;
|
||||
}
|
||||
}
|
||||
return params;
|
||||
@ -74,22 +75,22 @@ export const paramsValidation = (params: RouterLocationState): PayloadAction<boo
|
||||
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Composing url string from given RouterLocationState object
|
||||
* 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
|
||||
const patterns: Array<Array<string>> = routes.map(r => r.fields).sort((a, b) => {
|
||||
return a.length > b.length ? -1 : 1;
|
||||
});
|
||||
const patterns: Array<Array<string>> = routes.map(r => r.fields).sort((a, b) => (a.length > b.length ? -1 : 1));
|
||||
|
||||
// find pattern
|
||||
const keys: Array<string> = Object.keys(params);
|
||||
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);
|
||||
if (match.length === pattern.length) {
|
||||
patternToUse = pattern;
|
||||
@ -102,7 +103,7 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction<?string
|
||||
|
||||
// compose url string from pattern
|
||||
let url: string = '';
|
||||
patternToUse.forEach(field => {
|
||||
patternToUse.forEach((field) => {
|
||||
if (field === params[field]) {
|
||||
// standalone (odd) fields
|
||||
url += `/${field}`;
|
||||
@ -114,10 +115,9 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction<?string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
return url;
|
||||
}
|
||||
};
|
||||
|
||||
export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dispatch: Dispatch, getState: GetState): string => {
|
||||
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
|
||||
const currentParams = dispatch(pathToParams(location.pathname));
|
||||
const currentParamsAreValid = dispatch(paramsValidation(currentParams));
|
||||
if (currentParamsAreValid)
|
||||
return location.pathname;
|
||||
if (currentParamsAreValid) { return location.pathname; }
|
||||
}
|
||||
|
||||
// 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
|
||||
const composedUrl = dispatch(paramsToPath(requestedParams));
|
||||
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) {
|
||||
dispatch(goto(url));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Try to find first available device using order:
|
||||
@ -239,7 +237,7 @@ export const selectFirstAvailableDevice = (): ThunkAction => (dispatch: Dispatch
|
||||
} else {
|
||||
dispatch(gotoLandingPage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* 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) {
|
||||
dispatch(push(url));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* 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') {
|
||||
url = getState().router.location.pathname;
|
||||
}
|
||||
// TODO: add more landing page cases/urls to config.json (like /tools etc)
|
||||
return (url === '/' || url === '/bridge');
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* 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());
|
||||
if (!isLandingPage) {
|
||||
dispatch(goto('/'));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Go to given device settings page
|
||||
@ -291,10 +290,10 @@ export const setInitialUrl = (): PayloadAction<boolean> => (dispatch: Dispatch,
|
||||
type: LOCATION_CHANGE,
|
||||
payload: {
|
||||
pathname: initialPathname,
|
||||
hash: "",
|
||||
search: "",
|
||||
state: {}
|
||||
}
|
||||
hash: '',
|
||||
search: '',
|
||||
state: {},
|
||||
},
|
||||
}));
|
||||
if (valid === initialPathname) {
|
||||
dispatch(goto(valid));
|
||||
@ -302,4 +301,4 @@ export const setInitialUrl = (): PayloadAction<boolean> => (dispatch: Dispatch,
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
@ -20,8 +20,6 @@ import type {
|
||||
State,
|
||||
} from 'flowtype';
|
||||
|
||||
|
||||
|
||||
export type SelectedAccountAction = {
|
||||
type: typeof ACCOUNT.DISPOSE,
|
||||
} | {
|
||||
@ -55,7 +53,6 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
|
||||
|| prevState.discovery !== state.discovery
|
||||
|| prevState.tokens !== state.tokens
|
||||
|| prevState.pending !== state.pending) {
|
||||
|
||||
const account = stateUtils.getSelectedAccount(state);
|
||||
const network = stateUtils.getSelectedNetwork(state);
|
||||
const discovery = stateUtils.getDiscoveryProcess(state);
|
||||
|
@ -1,10 +1,9 @@
|
||||
/* @flow */
|
||||
import TrezorConnect, {
|
||||
UI, DEVICE, DEVICE_EVENT, UI_EVENT, TRANSPORT_EVENT, BLOCKCHAIN_EVENT
|
||||
DEVICE, DEVICE_EVENT, UI_EVENT, TRANSPORT_EVENT, BLOCKCHAIN_EVENT,
|
||||
} from 'trezor-connect';
|
||||
import * as CONNECT from 'actions/constants/TrezorConnect';
|
||||
import * as NOTIFICATION from 'actions/constants/notification';
|
||||
import * as WALLET from 'actions/constants/wallet';
|
||||
import { getDuplicateInstanceNumber } from 'reducers/utils';
|
||||
import * as RouterActions from 'actions/RouterActions';
|
||||
|
||||
@ -27,7 +26,6 @@ import type {
|
||||
AsyncAction,
|
||||
Device,
|
||||
TrezorDevice,
|
||||
RouterLocationState,
|
||||
} from 'flowtype';
|
||||
import * as DiscoveryActions from './DiscoveryActions';
|
||||
|
||||
@ -82,7 +80,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
|
||||
// set listeners
|
||||
TrezorConnect.on(DEVICE_EVENT, (event: DeviceMessage): void => {
|
||||
// post event to reducers
|
||||
const type: DeviceMessageType = event.type; // assert flow type
|
||||
const type: DeviceMessageType = event.type; // eslint-disable-line prefer-destructuring
|
||||
dispatch({
|
||||
type,
|
||||
device: event.payload,
|
||||
@ -91,7 +89,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
|
||||
|
||||
TrezorConnect.on(UI_EVENT, (event: UiMessage): void => {
|
||||
// post event to reducers
|
||||
const type: UiMessageType = event.type; // assert flow type
|
||||
const type: UiMessageType = event.type; // eslint-disable-line prefer-destructuring
|
||||
dispatch({
|
||||
type,
|
||||
payload: event.payload,
|
||||
@ -100,7 +98,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
|
||||
|
||||
TrezorConnect.on(TRANSPORT_EVENT, (event: TransportMessage): void => {
|
||||
// post event to reducers
|
||||
const type: TransportMessageType = event.type; // assert flow type
|
||||
const type: TransportMessageType = event.type; // eslint-disable-line prefer-destructuring
|
||||
dispatch({
|
||||
type,
|
||||
payload: event.payload,
|
||||
@ -109,16 +107,17 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
|
||||
|
||||
TrezorConnect.on(BLOCKCHAIN_EVENT, (event: BlockchainMessage): void => {
|
||||
// post event to reducers
|
||||
const type: BlockchainMessageType = event.type; // assert flow type
|
||||
const type: BlockchainMessageType = event.type; // eslint-disable-line prefer-destructuring
|
||||
dispatch({
|
||||
type,
|
||||
payload: event.payload,
|
||||
});
|
||||
});
|
||||
|
||||
/* global LOCAL */
|
||||
// $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://connect.trezor.io/5/';
|
||||
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/'; // eslint-disable-line no-underscore-dangle
|
||||
|
||||
try {
|
||||
await TrezorConnect.init({
|
||||
@ -138,7 +137,7 @@ export const init = (): AsyncAction => async (dispatch: Dispatch, getState: GetS
|
||||
|
||||
// called after backend was initialized
|
||||
// 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) => {
|
||||
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_UNACQUIRED, handleDeviceConnect);
|
||||
|
||||
const { devices } = getState();
|
||||
|
||||
// try to redirect to initial url
|
||||
if (!dispatch(RouterActions.setInitialUrl())) {
|
||||
// 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 {
|
||||
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||
return async (): Promise<void> => {
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import type {
|
||||
PayloadAction as ReduxPayloadAction,
|
||||
AsyncAction as ReduxAsyncAction,
|
||||
PromiseAction as ReduxPromiseAction,
|
||||
ThunkDispatch as ReduxThunkDispatch,
|
||||
PlainDispatch as ReduxPlainDispatch,
|
||||
} from 'redux';
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
/* @flow */
|
||||
|
||||
|
||||
import * as ACCOUNT from 'actions/constants/account';
|
||||
|
||||
import type {
|
||||
@ -14,7 +12,6 @@ import type {
|
||||
|
||||
export type State = {
|
||||
location?: string;
|
||||
|
||||
account: ?Account;
|
||||
network: ?Coin;
|
||||
tokens: Array<Token>,
|
||||
|
@ -37,8 +37,8 @@ export default function wallet(state: State = initialState, action: Action): Sta
|
||||
case WALLET.ON_BEFORE_UNLOAD:
|
||||
return {
|
||||
...state,
|
||||
unloading: true
|
||||
}
|
||||
unloading: true,
|
||||
};
|
||||
|
||||
case WALLET.SET_INITIAL_URL:
|
||||
return {
|
||||
|
@ -7,9 +7,6 @@ import type {
|
||||
MiddlewareAPI,
|
||||
MiddlewareDispatch,
|
||||
Action,
|
||||
ThunkAction,
|
||||
RouterLocationState,
|
||||
TrezorDevice,
|
||||
} from 'flowtype';
|
||||
|
||||
/**
|
||||
@ -27,22 +24,23 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
||||
// compose valid url
|
||||
const validUrl = api.dispatch(RouterActions.getValidUrl(action));
|
||||
// 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;
|
||||
if (redirect) {
|
||||
// override action pathname
|
||||
action.payload.pathname = validUrl;
|
||||
override.payload.pathname = validUrl;
|
||||
}
|
||||
|
||||
// pass action
|
||||
next(action);
|
||||
next(override);
|
||||
|
||||
if (redirect) {
|
||||
// replace invalid url
|
||||
api.dispatch(replace(validUrl));
|
||||
}
|
||||
|
||||
return action;
|
||||
return override;
|
||||
};
|
||||
|
||||
export default RouterService;
|
@ -1,7 +1,7 @@
|
||||
/* @flow */
|
||||
|
||||
import TrezorConnect, {
|
||||
TRANSPORT, DEVICE_EVENT, UI_EVENT, UI, DEVICE, BLOCKCHAIN
|
||||
import {
|
||||
TRANSPORT, DEVICE, BLOCKCHAIN,
|
||||
} from 'trezor-connect';
|
||||
import * as TrezorConnectActions from 'actions/TrezorConnectActions';
|
||||
import * as DiscoveryActions from 'actions/DiscoveryActions';
|
||||
|
@ -1,6 +1,4 @@
|
||||
/* @flow */
|
||||
|
||||
|
||||
import { DEVICE } from 'trezor-connect';
|
||||
import { LOCATION_CHANGE } from 'react-router-redux';
|
||||
import * as WALLET from 'actions/constants/wallet';
|
||||
@ -49,7 +47,7 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
||||
case WALLET.SET_INITIAL_URL:
|
||||
api.dispatch(LocalStorageActions.loadData());
|
||||
break;
|
||||
case WALLET.SET_SELECTED_DEVICE: {
|
||||
case WALLET.SET_SELECTED_DEVICE:
|
||||
if (action.device) {
|
||||
// try to authorize device
|
||||
api.dispatch(TrezorConnectActions.getSelectedDeviceState());
|
||||
@ -57,7 +55,6 @@ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
||||
// try select different device
|
||||
api.dispatch(RouterActions.selectFirstAvailableDevice());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DEVICE.CONNECT:
|
||||
api.dispatch(WalletActions.clearUnavailableDevicesData(prevState, action.device));
|
||||
|
@ -10,78 +10,78 @@ export const routes: Array<Route> = [
|
||||
{
|
||||
name: 'landing-home',
|
||||
pattern: '/',
|
||||
fields: []
|
||||
fields: [],
|
||||
},
|
||||
{
|
||||
name: 'landing-bridge',
|
||||
pattern: '/bridge',
|
||||
fields: ['bridge']
|
||||
fields: ['bridge'],
|
||||
},
|
||||
{
|
||||
name: 'landing-import',
|
||||
pattern: '/import',
|
||||
fields: ['import']
|
||||
fields: ['import'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-setting',
|
||||
pattern: '/settings',
|
||||
fields: ['settings']
|
||||
fields: ['settings'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-acquire',
|
||||
pattern: '/device/:device/acquire',
|
||||
fields: ['device', 'acquire']
|
||||
fields: ['device', 'acquire'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-unreadable',
|
||||
pattern: '/device/:device/unreadable',
|
||||
fields: ['device', 'unreadable']
|
||||
fields: ['device', 'unreadable'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-bootloader',
|
||||
pattern: '/device/:device/bootloader',
|
||||
fields: ['device', 'bootloader']
|
||||
fields: ['device', 'bootloader'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-initialize',
|
||||
pattern: '/device/:device/initialize',
|
||||
fields: ['device', 'initialize']
|
||||
fields: ['device', 'initialize'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-device-settings',
|
||||
pattern: '/device/:device/settings',
|
||||
fields: ['device', 'settings']
|
||||
fields: ['device', 'settings'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-dashboard',
|
||||
pattern: '/device/:device',
|
||||
fields: ['device']
|
||||
fields: ['device'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-account-summary',
|
||||
pattern: '/device/:device/network/:network/account/:account',
|
||||
fields: ['device', 'network', 'account']
|
||||
fields: ['device', 'network', 'account'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-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',
|
||||
pattern: '/device/:device/network/:network/account/:account/send/override',
|
||||
fields: ['device', 'network', 'account', 'send']
|
||||
fields: ['device', 'network', 'account', 'send'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-account-receive',
|
||||
pattern: '/device/:device/network/:network/account/:account/receive',
|
||||
fields: ['device', 'network', 'account', 'receive']
|
||||
fields: ['device', 'network', 'account', 'receive'],
|
||||
},
|
||||
{
|
||||
name: 'wallet-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 => {
|
||||
@ -91,4 +91,4 @@ export const getPattern = (name: string): string => {
|
||||
return '/';
|
||||
}
|
||||
return entry.pattern;
|
||||
}
|
||||
};
|
@ -30,7 +30,7 @@ const SelectedAccount = (props: Props) => {
|
||||
const {
|
||||
account,
|
||||
discovery,
|
||||
network
|
||||
network,
|
||||
} = accountState;
|
||||
|
||||
// corner case: accountState didn't finish loading state after LOCATION_CHANGE action
|
||||
@ -44,12 +44,13 @@ const SelectedAccount = (props: Props) => {
|
||||
title="Backend not connected"
|
||||
actions={
|
||||
[{
|
||||
label: "Try again",
|
||||
label: 'Try again',
|
||||
callback: async () => {
|
||||
await props.blockchainReconnect(network.network);
|
||||
}
|
||||
},
|
||||
}]
|
||||
} />
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user