1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-30 19:00:53 +00:00

RouterService postActions

This commit is contained in:
Szymon Lesisz 2018-05-16 19:39:27 +02:00
parent ae4b27d968
commit e677a7580d
2 changed files with 15 additions and 6 deletions

View File

@ -103,7 +103,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
} = this.state; } = this.state;
if (!device) { if (!device) {
return (<section>Device with state {accountState.deviceState} not found</section>); return (<section><Notification className="warning" title={ `Device with state ${accountState.deviceState} not found` } /></section>);
} }
// account not found. checking why... // account not found. checking why...

View File

@ -94,20 +94,19 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
const requestedParams: RouterLocationState = pathToParams(action.payload.pathname); const requestedParams: RouterLocationState = pathToParams(action.payload.pathname);
const currentParams: RouterLocationState = pathToParams(location ? location.pathname : '/'); const currentParams: RouterLocationState = pathToParams(location ? location.pathname : '/');
const postActions: Array<Action> = [];
let redirectPath: ?string; let redirectPath: ?string;
// first event after application loads // first event after application loads
if (!location) { if (!location) {
api.dispatch({ postActions.push({
type: WALLET.SET_INITIAL_URL, type: WALLET.SET_INITIAL_URL,
pathname: action.payload.pathname, pathname: action.payload.pathname,
state: requestedParams state: requestedParams
}); });
redirectPath = '/'; redirectPath = '/';
//return next(action);
} else { } else {
const isModalOpened: boolean = api.getState().modal.opened; const isModalOpened: boolean = api.getState().modal.opened;
@ -132,7 +131,7 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
} else if (requestedParams.device) { } else if (requestedParams.device) {
if (currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) { if (currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) {
api.dispatch({ postActions.push({
type: CONNECT.SELECT_DEVICE, type: CONNECT.SELECT_DEVICE,
payload: { payload: {
id: requestedParams.device, id: requestedParams.device,
@ -142,7 +141,7 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
} }
if (requestedParams.network !== currentParams.network) { if (requestedParams.network !== currentParams.network) {
api.dispatch({ postActions.push({
type: CONNECT.COIN_CHANGED, type: CONNECT.COIN_CHANGED,
payload: { payload: {
network: requestedParams.network network: requestedParams.network
@ -165,7 +164,17 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
action.payload.state = requestedParams; action.payload.state = requestedParams;
} }
// resolve LOCATION_CHANGE action
next(action);
// resolve post actions
postActions.forEach(a => {
api.dispatch(a);
});
api.dispatch( NotificationActions.clear(currentParams, requestedParams) ); api.dispatch( NotificationActions.clear(currentParams, requestedParams) );
return action;
} }
// Pass all actions through by default // Pass all actions through by default