Skip to content

Commit fe28ed1

Browse files
authored
Merge pull request #1053 from alexstotsky/redirection-fixes
(fix) Redirection and message duplication issues
2 parents a0b341a + 9a14b29 commit fe28ed1

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

src/components/Status/Status.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,24 @@ export const AppToaster = Toaster.create({
1414
position: Position.BOTTOM_RIGHT,
1515
})
1616

17+
let lastShownMsg = null
18+
1719
export const Status = ({
1820
clearStatus,
1921
intent,
2022
msg = {},
2123
}) => {
2224
if (!msg.id) {
25+
lastShownMsg = null
2326
return ''
2427
}
2528

29+
if (msg === lastShownMsg) {
30+
return ''
31+
}
32+
33+
lastShownMsg = msg
34+
2635
const params = {
2736
...msg,
2837
topic: msg.topic ? i18n.t(msg.topic) || msg.topic : undefined,

src/state/routing/saga.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { put, select, takeLatest } from 'redux-saga/effects'
1+
import {
2+
call, put, select, takeLatest,
3+
} from 'redux-saga/effects'
24
import { LOCATION_CHANGE, replace } from 'redux-first-history'
35
import { isEmpty } from '@bitfinex/lib-js-util-base'
46

@@ -14,22 +16,19 @@ import { getLastRoute, getRouteParams } from './selectors'
1416

1517
const { 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

1929
function* 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

106105
export 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

Comments
 (0)