add WALLET.SET_FIRST_LOCATION_CHANGE action

pull/289/head
Szymon Lesisz 5 years ago committed by Szymon Lesisz
parent 5a6ea6610e
commit e7ae73c570

@ -2,7 +2,7 @@
import { push, LOCATION_CHANGE } from 'connected-react-router';
import { CONTEXT_NONE } from 'actions/constants/modal';
import { SET_INITIAL_URL } from 'actions/constants/wallet';
import { SET_INITIAL_URL, SET_FIRST_LOCATION_CHANGE } from 'actions/constants/wallet';
import { routes } from 'support/routes';
import * as deviceUtils from 'utils/device';
@ -133,7 +133,12 @@ export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dis
const { firstLocationChange } = getState().wallet;
// redirect to landing page (loading screen)
// and wait until application is ready
if (firstLocationChange) return '/';
if (firstLocationChange) {
dispatch({
type: SET_FIRST_LOCATION_CHANGE,
});
return '/';
}
console.log('action', action);

@ -39,7 +39,7 @@ export type WalletAction = {
type: typeof WALLET.CLEAR_UNAVAILABLE_DEVICE_DATA,
devices: Array<TrezorDevice>
} | {
type: typeof WALLET.SHOW_BETA_DISCLAIMER | typeof WALLET.HIDE_BETA_DISCLAIMER,
type: typeof WALLET.SHOW_BETA_DISCLAIMER | typeof WALLET.HIDE_BETA_DISCLAIMER | typeof WALLET.SET_FIRST_LOCATION_CHANGE,
}
export const init = (): ThunkAction => (dispatch: Dispatch): void => {

@ -2,6 +2,7 @@
export const TOGGLE_DEVICE_DROPDOWN: 'wallet__toggle_dropdown' = 'wallet__toggle_dropdown';
export const SET_INITIAL_URL: 'wallet__set_initial_url' = 'wallet__set_initial_url';
export const SET_FIRST_LOCATION_CHANGE: 'wallet__set_first_location_change' = 'wallet__set_first_location_change';
export const ONLINE_STATUS: 'wallet__online_status' = 'wallet__online_status';
export const SET_SELECTED_DEVICE: 'wallet__set_selected_device' = 'wallet__set_selected_device';

@ -19,7 +19,10 @@ declare module 'connected-react-router' {
declare export type RouterAction = {
type: typeof LOCATION_CHANGE,
payload: Location;
payload: {
action: string,
location: Location,
},
}
declare export type State = {
@ -35,6 +38,7 @@ declare module 'connected-react-router' {
//declare export function routerReducer<S, A>(state?: S, action: A): S;
declare export function routerReducer(state?: State, action: any): State;
declare export function routerMiddleware(history: any): any;
declare export function connectRouter(history: any): any;
declare export class ConnectedRouter extends React$Component<{
history: any

@ -36,11 +36,14 @@ const initialState: State = {
export default function wallet(state: State = initialState, action: Action): State {
switch (action.type) {
case WALLET.SET_INITIAL_URL:
console.log('action2', action);
return {
...state,
initialParams: action.state,
initialPathname: action.pathname,
};
case WALLET.SET_FIRST_LOCATION_CHANGE:
return {
...state,
firstLocationChange: false,
};

@ -28,6 +28,7 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
console.log('api.dispatch(RouterActions.pathToParams(validUrl))', api.dispatch(RouterActions.pathToParams(validUrl)));
override.payload.location.state = api.dispatch(RouterActions.pathToParams(validUrl));
const redirect = action.payload.location.pathname !== validUrl;
console.warn('OVERRIDE', action.payload.location.pathname, validUrl);
if (redirect) {
// override action pathname
override.payload.location.pathname = validUrl;

Loading…
Cancel
Save