mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 11:18:16 +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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pattern not found, redirect back
|
// pattern not found, redirect back
|
||||||
if (!patternToUse) return null;
|
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 => {
|
export const getValidUrl = (action: RouterAction): PayloadAction<string> => (dispatch: Dispatch, getState: GetState): string => {
|
||||||
const { location } = getState().router;
|
const { location } = getState().router;
|
||||||
|
const { firstLocationChange } = getState().wallet;
|
||||||
// redirect to landing page (loading screen)
|
// redirect to landing page (loading screen)
|
||||||
// and wait until application is ready
|
// 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)
|
// 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;
|
||||||
|
|
||||||
@ -269,6 +270,7 @@ export const selectFirstAvailableDevice = (gotoRoot: boolean = false): ThunkActi
|
|||||||
const url = dispatch(getFirstAvailableDeviceUrl());
|
const url = dispatch(getFirstAvailableDeviceUrl());
|
||||||
if (url) {
|
if (url) {
|
||||||
const currentParams = getState().router.location.state;
|
const currentParams = getState().router.location.state;
|
||||||
|
console.log('currentParams', currentParams);
|
||||||
const requestedParams = dispatch(pathToParams(url));
|
const requestedParams = dispatch(pathToParams(url));
|
||||||
if (gotoRoot || currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) {
|
if (gotoRoot || currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) {
|
||||||
dispatch(goto(url));
|
dispatch(goto(url));
|
||||||
@ -351,11 +353,13 @@ export const setInitialUrl = (): PayloadAction<boolean> => (dispatch: Dispatch,
|
|||||||
const valid = dispatch(getValidUrl({
|
const valid = dispatch(getValidUrl({
|
||||||
type: LOCATION_CHANGE,
|
type: LOCATION_CHANGE,
|
||||||
payload: {
|
payload: {
|
||||||
|
location: {
|
||||||
pathname: initialPathname,
|
pathname: initialPathname,
|
||||||
hash: '',
|
hash: '',
|
||||||
search: '',
|
search: '',
|
||||||
state: {},
|
state: {},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (valid === initialPathname) {
|
if (valid === initialPathname) {
|
||||||
|
@ -16,6 +16,7 @@ type State = {
|
|||||||
showBetaDisclaimer: boolean;
|
showBetaDisclaimer: boolean;
|
||||||
initialParams: ?RouterLocationState;
|
initialParams: ?RouterLocationState;
|
||||||
initialPathname: ?string;
|
initialPathname: ?string;
|
||||||
|
firstLocationChange: boolean;
|
||||||
disconnectRequest: ?TrezorDevice;
|
disconnectRequest: ?TrezorDevice;
|
||||||
selectedDevice: ?TrezorDevice;
|
selectedDevice: ?TrezorDevice;
|
||||||
}
|
}
|
||||||
@ -24,6 +25,7 @@ const initialState: State = {
|
|||||||
ready: false,
|
ready: false,
|
||||||
online: navigator.onLine,
|
online: navigator.onLine,
|
||||||
dropdownOpened: false,
|
dropdownOpened: false,
|
||||||
|
firstLocationChange: true,
|
||||||
showBetaDisclaimer: false,
|
showBetaDisclaimer: false,
|
||||||
initialParams: null,
|
initialParams: null,
|
||||||
initialPathname: null,
|
initialPathname: null,
|
||||||
@ -38,6 +40,7 @@ export default function wallet(state: State = initialState, action: Action): Sta
|
|||||||
...state,
|
...state,
|
||||||
initialParams: action.state,
|
initialParams: action.state,
|
||||||
initialPathname: action.pathname,
|
initialPathname: action.pathname,
|
||||||
|
firstLocationChange: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
case TRANSPORT.START:
|
case TRANSPORT.START:
|
||||||
|
@ -25,10 +25,9 @@ import type {
|
|||||||
*/
|
*/
|
||||||
const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => async (action: Action): Promise<Action> => {
|
const WalletService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispatch) => async (action: Action): Promise<Action> => {
|
||||||
const prevState = api.getState();
|
const prevState = api.getState();
|
||||||
|
|
||||||
// Application live cycle starts HERE!
|
// Application live cycle starts HERE!
|
||||||
// when first LOCATION_CHANGE is called router does not have "location" set yet
|
// 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
|
// initialize wallet
|
||||||
api.dispatch(WalletActions.init());
|
api.dispatch(WalletActions.init());
|
||||||
// set initial url
|
// set initial url
|
||||||
|
Loading…
Reference in New Issue
Block a user