Skip to content

Commit

Permalink
feat: add handleClearAlert thunk
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbodnar committed Jan 25, 2022
1 parent c78c696 commit 92ef8ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/frontend/src/redux/reducers/status/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getRouter } from 'connected-react-router';
import reduceReducers from 'reduce-reducers';
import { handleActions } from 'redux-actions';

Expand All @@ -7,6 +8,7 @@ import {
clearGlobalAlert,
setMainLoader
} from '../../actions/status';
import { selectAccountGlobalAlertPreventClear } from '../../slices/account';


const initialState = {
Expand All @@ -16,6 +18,16 @@ const initialState = {
localAlert: {}
};

export const handleClearAlert = () => (dispatch, getState) => {
const router = getRouter(getState());
const globalAlertPreventClear = selectAccountGlobalAlertPreventClear(getState());

if (!router.location.state?.globalAlertPreventClear && !globalAlertPreventClear) {
dispatch(clearGlobalAlert());
}
dispatch(clearLocalAlert());
};

const alertReducer = (state, { error, ready, payload, meta, type }) => {

// temporary solution to handle both `showAlert` and `showAlertToolkit`
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/redux/slices/account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const selectAccountFullAccessKeys = createSelector(selectAccountSlice, (a

export const selectAccountLedgerKey = createSelector(selectAccountSlice, (account) => account.ledgerKey);

export const selectAccountGlobalAlertPreventClear = createSelector(selectAccountSlice, (account) => account.globalAlertPreventClear);

// balance - state
export const selectBalance = createSelector(selectAccountSlice, (account) => account.balance || {});
export const selectAvailableBalance = createSelector(selectBalance, (balance) => balance.balanceAvailable);
Expand Down

0 comments on commit 92ef8ec

Please sign in to comment.