about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/reducers/identity_proofs.js
blob: 58af0a5faaa780b64506fa8e2a569d1a2e8c8ea7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { Map as ImmutableMap, fromJS } from 'immutable';
import {
  IDENTITY_PROOFS_ACCOUNT_FETCH_REQUEST,
  IDENTITY_PROOFS_ACCOUNT_FETCH_SUCCESS,
  IDENTITY_PROOFS_ACCOUNT_FETCH_FAIL,
} from '../actions/identity_proofs';

const initialState = ImmutableMap();

export default function identityProofsReducer(state = initialState, action) {
  switch(action.type) {
  case IDENTITY_PROOFS_ACCOUNT_FETCH_REQUEST:
    return state.set('isLoading', true);
  case IDENTITY_PROOFS_ACCOUNT_FETCH_FAIL:
    return state.set('isLoading', false);
  case IDENTITY_PROOFS_ACCOUNT_FETCH_SUCCESS:
    return state.update(identity_proofs => identity_proofs.withMutations(map => {
      map.set('isLoading', false);
      map.set('loaded', true);
      map.set(action.accountId, fromJS(action.identity_proofs));
    }));
  default:
    return state;
  }
};