mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
First init added to reducer
This commit is contained in:
parent
cdd325c078
commit
0f9d864347
@ -105,7 +105,6 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction<?string
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// pattern not found, redirect back
|
||||
if (!patternToUse) return null;
|
||||
|
||||
@ -129,12 +128,14 @@ export const paramsToPath = (params: RouterLocationState): PayloadAction<?string
|
||||
|
||||
export const getValidUrl = (action: RouterAction): PayloadAction<string> => (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 '/';
|
||||
|
||||
const requestedUrl = action.payload.pathname;
|
||||
console.log('action', action);
|
||||
|
||||
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<boolean> => (dispatch: Dispatch,
|
||||
const valid = dispatch(getValidUrl({
|
||||
type: LOCATION_CHANGE,
|
||||
payload: {
|
||||
pathname: initialPathname,
|
||||
hash: '',
|
||||
search: '',
|
||||
state: {},
|
||||
location: {
|
||||
pathname: initialPathname,
|
||||
hash: '',
|
||||
search: '',
|
||||
state: {},
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
|
@ -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:
|
||||
|
@ -25,10 +25,9 @@ import type {
|
||||
*/
|
||||
const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => async (action: Action): Promise<Action> => {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user