1- import { put , select , takeLatest } from 'redux-saga/effects'
1+ import {
2+ call , put , select , takeLatest ,
3+ } from 'redux-saga/effects'
24import { LOCATION_CHANGE , replace } from 'redux-first-history'
35import { isEmpty } from '@bitfinex/lib-js-util-base'
46
@@ -14,22 +16,19 @@ import { getLastRoute, getRouteParams } from './selectors'
1416
1517const { MENU_ORDER_TRADES } = queryConstants
1618
17- let isFirstRendering = true
19+ // handles legacy route redirects on app startup
20+ // runs once before LOCATION_CHANGE listeners are set up, avoiding takeLatest race conditions
21+ function * handleLegacyRedirects ( ) {
22+ const { pathname, search } = window . location
23+ if ( pathname . includes ( '/deposits' ) || pathname . includes ( '/withdrawals' ) ) {
24+ const [ , , symbols ] = pathname . split ( '/' )
25+ yield put ( replace ( `/movements${ symbols ? `/${ symbols } ` : '' } ${ search || '' } ` , { isSkipped : true } ) )
26+ }
27+ }
1828
1929function * locationChange ( { payload } ) {
2030 const { location } = payload
21- const { pathname, search, state } = location
22-
23- const isFirstRender = isFirstRendering
24- if ( isFirstRender ) {
25- isFirstRendering = false
26- // redirects from legacy sections `deposits' and 'withdrawals' to 'movements' on first render
27- if ( pathname . includes ( '/deposits' ) || pathname . includes ( '/withdrawals' ) ) {
28- const [ , , symbols ] = pathname . split ( '/' )
29- yield put ( replace ( `/movements${ symbols ? `/${ symbols } ` : '' } ${ search || '' } ` , { isSkipped : true } ) )
30- return
31- }
32- }
31+ const { pathname, state } = location
3332
3433 if ( ! isEmpty ( state ) && state . isSkipped ) {
3534 return
@@ -46,8 +45,8 @@ function* locationChange({ payload }) {
4645 return
4746 }
4847
49- // return previously saved params on route change
50- if ( route !== lastRoute && ! isFirstRender ) {
48+ // return previously saved params on route change (skip on first load when lastRoute is not yet set)
49+ if ( route !== lastRoute && lastRoute ) {
5150 const routeParams = yield select ( getRouteParams , route )
5251 if ( isEmpty ( routeParams ) ) {
5352 const query = getQueryWithoutParams ( Object . keys ( FILTER_KEYS ) ) // remove filters of current section
@@ -104,6 +103,7 @@ function* filtersSet({ payload }) {
104103}
105104
106105export default function * routingSaga ( ) {
106+ yield call ( handleLegacyRedirects )
107107 yield takeLatest ( LOCATION_CHANGE , locationChange )
108108 yield takeLatest ( LOCATION_CHANGE , lastRouteSet )
109109 yield takeLatest ( filterTypes . SET_FILTERS , filtersSet )
0 commit comments