diff --git a/src/actions/RouterActions.js b/src/actions/RouterActions.js index 0e632a16..052af898 100644 --- a/src/actions/RouterActions.js +++ b/src/actions/RouterActions.js @@ -105,7 +105,6 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction => (dispatch: Dispatch, getState: GetState): string => { const { location } = getState().router; - + const { firstLocationChange } = getState().wallet; // redirect to landing page (loading screen) // and wait until application is ready - if (!location) return '/'; + if (firstLocationChange) return '/'; + + console.log('action', action); - const requestedUrl = action.payload.pathname; + const requestedUrl = action.payload.location.pathname; // Corner case: LOCATION_CHANGE was called but pathname didn't changed (redirect action from RouterService) if (requestedUrl === location.pathname) return requestedUrl; @@ -269,6 +270,7 @@ export const selectFirstAvailableDevice = (gotoRoot: boolean = false): ThunkActi const url = dispatch(getFirstAvailableDeviceUrl()); if (url) { const currentParams = getState().router.location.state; + console.log('currentParams', currentParams); const requestedParams = dispatch(pathToParams(url)); if (gotoRoot || currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) { dispatch(goto(url)); @@ -351,10 +353,12 @@ export const setInitialUrl = (): PayloadAction => (dispatch: Dispatch, const valid = dispatch(getValidUrl({ type: LOCATION_CHANGE, payload: { - pathname: initialPathname, - hash: '', - search: '', - state: {}, + location: { + pathname: initialPathname, + hash: '', + search: '', + state: {}, + }, }, })); diff --git a/src/reducers/WalletReducer.js b/src/reducers/WalletReducer.js index 15086746..edcf674d 100644 --- a/src/reducers/WalletReducer.js +++ b/src/reducers/WalletReducer.js @@ -16,6 +16,7 @@ type State = { showBetaDisclaimer: boolean; initialParams: ?RouterLocationState; initialPathname: ?string; + firstLocationChange: boolean; disconnectRequest: ?TrezorDevice; selectedDevice: ?TrezorDevice; } @@ -24,6 +25,7 @@ const initialState: State = { ready: false, online: navigator.onLine, dropdownOpened: false, + firstLocationChange: true, showBetaDisclaimer: false, initialParams: null, initialPathname: null, @@ -38,6 +40,7 @@ export default function wallet(state: State = initialState, action: Action): Sta ...state, initialParams: action.state, initialPathname: action.pathname, + firstLocationChange: false, }; case TRANSPORT.START: diff --git a/src/services/WalletService.js b/src/services/WalletService.js index 815818df..33239f28 100644 --- a/src/services/WalletService.js +++ b/src/services/WalletService.js @@ -25,10 +25,9 @@ import type { */ const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => async (action: Action): Promise => { const prevState = api.getState(); - // Application live cycle starts HERE! // when first LOCATION_CHANGE is called router does not have "location" set yet - if (action.type === LOCATION_CHANGE && !prevState.router.location) { + if (action.type === LOCATION_CHANGE && prevState.wallet.firstLocationChange) { // initialize wallet api.dispatch(WalletActions.init()); // set initial url