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
|
"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;
|
||||||
@ -99,25 +100,24 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction<?string
|
|||||||
|
|
||||||
// pattern not found, redirect back
|
// pattern not found, redirect back
|
||||||
if (!patternToUse) return null;
|
if (!patternToUse) return null;
|
||||||
|
|
||||||
// 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}`;
|
||||||
} else {
|
} else {
|
||||||
url += `/${ field }/${ params[field] }`;
|
url += `/${field}/${params[field]}`;
|
||||||
if (field === 'device') {
|
if (field === 'device') {
|
||||||
if (params.hasOwnProperty('deviceInstance')) {
|
if (params.hasOwnProperty('deviceInstance')) {
|
||||||
url += `:${ params.deviceInstance }`;
|
url += `:${params.deviceInstance}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
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;
|
||||||
@ -129,23 +129,22 @@ export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dis
|
|||||||
const requestedUrl = action.payload.pathname;
|
const requestedUrl = action.payload.pathname;
|
||||||
// Corner case: LOCATION_CHANGE was called but pathname didn't changed (redirect action from RouterService)
|
// Corner case: LOCATION_CHANGE was called but pathname didn't changed (redirect action from RouterService)
|
||||||
if (requestedUrl === location.pathname) return requestedUrl;
|
if (requestedUrl === location.pathname) return requestedUrl;
|
||||||
|
|
||||||
// Modal is opened
|
// Modal is opened
|
||||||
// redirect to previous url
|
// redirect to previous url
|
||||||
if (getState().modal.opened) {
|
if (getState().modal.opened) {
|
||||||
// Corner case: modal is opened and currentParams are still valid
|
// Corner case: modal is opened and currentParams are still valid
|
||||||
// example 1 (valid blocking): url changed while passphrase modal opened but device is still connected (we want user to finish this action)
|
// example 1 (valid blocking): url changed while passphrase modal opened but device is still connected (we want user to finish this action)
|
||||||
// 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
|
||||||
// redirect to landing page
|
// redirect to landing page
|
||||||
const shouldBeLandingPage = getState().devices.length < 1 || !getState().wallet.ready || getState().connect.error !== null;
|
const shouldBeLandingPage = getState().devices.length < 1 || !getState().wallet.ready || getState().connect.error !== null;
|
||||||
const landingPageUrl = dispatch( isLandingPageUrl(requestedUrl) );
|
const landingPageUrl = dispatch(isLandingPageUrl(requestedUrl));
|
||||||
if (shouldBeLandingPage) {
|
if (shouldBeLandingPage) {
|
||||||
return !landingPageUrl ? '/' : requestedUrl;
|
return !landingPageUrl ? '/' : requestedUrl;
|
||||||
}
|
}
|
||||||
@ -157,8 +156,8 @@ export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dis
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Regular url change during application live cycle
|
// Regular url change during application live cycle
|
||||||
const requestedParams = dispatch( pathToParams(requestedUrl) );
|
const requestedParams = dispatch(pathToParams(requestedUrl));
|
||||||
const requestedParamsAreValid: boolean = dispatch( paramsValidation(requestedParams) );
|
const requestedParamsAreValid: boolean = dispatch(paramsValidation(requestedParams));
|
||||||
|
|
||||||
// Requested params are not valid
|
// Requested params are not valid
|
||||||
// Neither device or network doesn't exists
|
// Neither device or network doesn't exists
|
||||||
@ -167,10 +166,9 @@ 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;
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -212,11 +210,11 @@ export const selectDevice = (device: TrezorDevice | Device): ThunkAction => (dis
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentParams: RouterLocationState = getState().router.location.state;
|
const currentParams: RouterLocationState = getState().router.location.state;
|
||||||
const requestedParams = dispatch( pathToParams(url) );
|
const requestedParams = dispatch(pathToParams(url));
|
||||||
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:
|
||||||
@ -230,46 +228,47 @@ export const selectFirstAvailableDevice = (): ThunkAction => (dispatch: Dispatch
|
|||||||
if (devices.length > 0) {
|
if (devices.length > 0) {
|
||||||
const unacquired = devices.find(d => !d.features);
|
const unacquired = devices.find(d => !d.features);
|
||||||
if (unacquired) {
|
if (unacquired) {
|
||||||
dispatch( selectDevice(unacquired) );
|
dispatch(selectDevice(unacquired));
|
||||||
} else {
|
} else {
|
||||||
const latest: Array<TrezorDevice> = sortDevices(devices);
|
const latest: Array<TrezorDevice> = sortDevices(devices);
|
||||||
const firstConnected: ?TrezorDevice = latest.find(d => d.connected);
|
const firstConnected: ?TrezorDevice = latest.find(d => d.connected);
|
||||||
dispatch( selectDevice(firstConnected || latest[0]) );
|
dispatch(selectDevice(firstConnected || latest[0]));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dispatch( gotoLandingPage() );
|
dispatch(gotoLandingPage());
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal method. redirect to given url
|
* Internal method. redirect to given url
|
||||||
*/
|
*/
|
||||||
const goto = (url: string): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
const goto = (url: string): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
||||||
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
|
||||||
@ -277,7 +276,7 @@ export const gotoLandingPage = (): ThunkAction => (dispatch: Dispatch, getState:
|
|||||||
export const gotoDeviceSettings = (device: TrezorDevice): ThunkAction => (dispatch: Dispatch): void => {
|
export const gotoDeviceSettings = (device: TrezorDevice): ThunkAction => (dispatch: Dispatch): void => {
|
||||||
if (device.features) {
|
if (device.features) {
|
||||||
const devUrl: string = `${device.features.device_id}${device.instance ? `:${device.instance}` : ''}`;
|
const devUrl: string = `${device.features.device_id}${device.instance ? `:${device.instance}` : ''}`;
|
||||||
dispatch( goto(`/device/${devUrl}/settings`) );
|
dispatch(goto(`/device/${devUrl}/settings`));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -287,19 +286,19 @@ export const gotoDeviceSettings = (device: TrezorDevice): ThunkAction => (dispat
|
|||||||
export const setInitialUrl = (): PayloadAction<boolean> => (dispatch: Dispatch, getState: GetState): boolean => {
|
export const setInitialUrl = (): PayloadAction<boolean> => (dispatch: Dispatch, getState: GetState): boolean => {
|
||||||
const { initialPathname } = getState().wallet;
|
const { initialPathname } = getState().wallet;
|
||||||
if (typeof initialPathname === 'string' && !dispatch(isLandingPageUrl(initialPathname))) {
|
if (typeof initialPathname === 'string' && !dispatch(isLandingPageUrl(initialPathname))) {
|
||||||
const valid = dispatch( getValidUrl({
|
const valid = dispatch(getValidUrl({
|
||||||
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));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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,
|
||||||
} | {
|
} | {
|
||||||
@ -46,7 +44,7 @@ export const updateSelectedValues = (prevState: State, action: Action): AsyncAct
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (prevState.sendForm !== state.sendForm) {
|
if (prevState.sendForm !== state.sendForm) {
|
||||||
dispatch( SessionStorageActions.save() );
|
dispatch(SessionStorageActions.save());
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle devices state change (from trezor-connect events or location change)
|
// handle devices state change (from trezor-connect events or location change)
|
||||||
@ -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,9 +137,9 @@ 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));
|
||||||
};
|
};
|
||||||
|
|
||||||
TrezorConnect.off(DEVICE.CONNECT, handleDeviceConnect);
|
TrezorConnect.off(DEVICE.CONNECT, handleDeviceConnect);
|
||||||
@ -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';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,24 +22,25 @@ 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';
|
||||||
@ -42,7 +42,7 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
|||||||
api.dispatch(ModalActions.onRememberRequest(prevModalState));
|
api.dispatch(ModalActions.onRememberRequest(prevModalState));
|
||||||
} else if (action.type === CONNECT.FORGET) {
|
} else if (action.type === CONNECT.FORGET) {
|
||||||
//api.dispatch( TrezorConnectActions.forgetDevice(action.device) );
|
//api.dispatch( TrezorConnectActions.forgetDevice(action.device) );
|
||||||
api.dispatch( RouterActions.selectFirstAvailableDevice() );
|
api.dispatch(RouterActions.selectFirstAvailableDevice());
|
||||||
} else if (action.type === CONNECT.FORGET_SINGLE) {
|
} else if (action.type === CONNECT.FORGET_SINGLE) {
|
||||||
if (api.getState().devices.length < 1 && action.device.connected) {
|
if (api.getState().devices.length < 1 && action.device.connected) {
|
||||||
// prompt disconnect device info in LandingPage
|
// prompt disconnect device info in LandingPage
|
||||||
@ -50,9 +50,9 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
|||||||
type: CONNECT.DISCONNECT_REQUEST,
|
type: CONNECT.DISCONNECT_REQUEST,
|
||||||
device: action.device,
|
device: action.device,
|
||||||
});
|
});
|
||||||
api.dispatch( RouterActions.gotoLandingPage() );
|
api.dispatch(RouterActions.gotoLandingPage());
|
||||||
} else {
|
} else {
|
||||||
api.dispatch( RouterActions.selectFirstAvailableDevice() );
|
api.dispatch(RouterActions.selectFirstAvailableDevice());
|
||||||
}
|
}
|
||||||
} else if (action.type === DEVICE.CONNECT || action.type === DEVICE.CONNECT_UNACQUIRED) {
|
} else if (action.type === DEVICE.CONNECT || action.type === DEVICE.CONNECT_UNACQUIRED) {
|
||||||
api.dispatch(DiscoveryActions.restore());
|
api.dispatch(DiscoveryActions.restore());
|
||||||
@ -68,7 +68,7 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
|||||||
} else if (action.type === BLOCKCHAIN.NOTIFICATION) {
|
} else if (action.type === BLOCKCHAIN.NOTIFICATION) {
|
||||||
// api.dispatch(BlockchainActions.onNotification(action.payload));
|
// api.dispatch(BlockchainActions.onNotification(action.payload));
|
||||||
} else if (action.type === BLOCKCHAIN.ERROR) {
|
} else if (action.type === BLOCKCHAIN.ERROR) {
|
||||||
api.dispatch( BlockchainActions.error(action.payload) );
|
api.dispatch(BlockchainActions.error(action.payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
return action;
|
return action;
|
||||||
|
@ -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,8 +55,7 @@ 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));
|
||||||
break;
|
break;
|
||||||
|
@ -10,85 +10,85 @@ 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 => {
|
||||||
const entry = routes.find(r => r.name === name);
|
const entry = routes.find(r => r.name === name);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
console.error(`Route for ${ name } not found`);
|
console.error(`Route for ${name} not found`);
|
||||||
return '/';
|
return '/';
|
||||||
}
|
}
|
||||||
return entry.pattern;
|
return entry.pattern;
|
||||||
}
|
};
|
@ -30,26 +30,27 @@ 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
|
||||||
if (!network) return (<Notification type="info" title="Loading account state..." />);
|
if (!network) return (<Notification type="info" title="Loading account state..." />);
|
||||||
|
|
||||||
const blockchain = props.blockchain.find(b => b.name === network.network);
|
const blockchain = props.blockchain.find(b => b.name === network.network);
|
||||||
if (blockchain && !blockchain.connected) {
|
if (blockchain && !blockchain.connected) {
|
||||||
return (
|
return (
|
||||||
<Notification
|
<Notification
|
||||||
type="error"
|
type="error"
|
||||||
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);
|
||||||
}
|
},
|
||||||
}]
|
}]
|
||||||
} />
|
}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,24 +30,24 @@ const App = () => (
|
|||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<ConnectedRouter history={history}>
|
<ConnectedRouter history={history}>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path={ getPattern('landing-home') } component={LandingContainer} />
|
<Route exact path={getPattern('landing-home')} component={LandingContainer} />
|
||||||
<Route exact path={ getPattern('landing-bridge') } component={LandingContainer} />
|
<Route exact path={getPattern('landing-bridge')} component={LandingContainer} />
|
||||||
<Route exact path={ getPattern('landing-import') } component={LandingContainer} />
|
<Route exact path={getPattern('landing-import')} component={LandingContainer} />
|
||||||
<Route>
|
<Route>
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<WalletContainer>
|
<WalletContainer>
|
||||||
<Route exact path={ getPattern('wallet-setting') } component={WalletSettings} />
|
<Route exact path={getPattern('wallet-setting')} component={WalletSettings} />
|
||||||
<Route exact path={ getPattern('wallet-dashboard') } component={WalletDashboard} />
|
<Route exact path={getPattern('wallet-dashboard')} component={WalletDashboard} />
|
||||||
<Route exact path={ getPattern('wallet-acquire') } component={WalletAcquire} />
|
<Route exact path={getPattern('wallet-acquire')} component={WalletAcquire} />
|
||||||
<Route exact path={ getPattern('wallet-unreadable') } component={WalletUnreadableDevice} />
|
<Route exact path={getPattern('wallet-unreadable')} component={WalletUnreadableDevice} />
|
||||||
<Route exact path={ getPattern('wallet-bootloader') } component={WalletBootloader} />
|
<Route exact path={getPattern('wallet-bootloader')} component={WalletBootloader} />
|
||||||
<Route exact path={ getPattern('wallet-initialize') } component={WalletInitialize} />
|
<Route exact path={getPattern('wallet-initialize')} component={WalletInitialize} />
|
||||||
<Route exact path={ getPattern('wallet-device-settings') } component={WalletDeviceSettings} />
|
<Route exact path={getPattern('wallet-device-settings')} component={WalletDeviceSettings} />
|
||||||
<Route exact path={ getPattern('wallet-account-summary') } component={AccountSummary} />
|
<Route exact path={getPattern('wallet-account-summary')} component={AccountSummary} />
|
||||||
<Route path={ getPattern('wallet-account-send') } component={AccountSend} />
|
<Route path={getPattern('wallet-account-send')} component={AccountSend} />
|
||||||
<Route path={ getPattern('wallet-account-send-override') } component={AccountSend} />
|
<Route path={getPattern('wallet-account-send-override')} component={AccountSend} />
|
||||||
<Route path={ getPattern('wallet-account-receive') } component={AccountReceive} />
|
<Route path={getPattern('wallet-account-receive')} component={AccountReceive} />
|
||||||
<Route path={ getPattern('wallet-account-signverify') } component={AccountSignVerify} />
|
<Route path={getPattern('wallet-account-signverify')} component={AccountSignVerify} />
|
||||||
</WalletContainer>
|
</WalletContainer>
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</Route>
|
</Route>
|
||||||
|
Loading…
Reference in New Issue
Block a user