<commit_before>import * as types from './types'
import { DEFAULT_PROFILE } from '../../../utils/profile-utils'

const initialState = {
  default: 0, // persist
  localIdentities: [], 
  publicIdentities: {},
  nameTransfers: [],
  zoneFileUpdates: [],
  createProfileError: null
}

function IdentityReducer(state = initialState, action) {
  switch (action.type) {
    case types.UPDATE_PUBLIC_IDENTITY:
      return Object.assign({}, state, {
        publicIdentities: Object.assign({}, state.publicIdentities, {
          [action.username]: {
            username: action.username,
            ownerAddress: action.ownerAddress,
            zoneFile: action.zoneFile,
            profile: JSON.parse(JSON.stringify(action.profile)),
            verifications: JSON.parse(JSON.stringify(action.verifications)),
            trustLevel: action.trustLevel
          }
        })
      })
    case types.SET_DEFAULT:
      return Object.assign({}, state, {
        default: action.index
      })
    case types.CREATE_NEW:
      return Object.assign({}, state, {
        localIdentities: [...state.localIdentities, {
          username: null,
          usernameOwned: false,
          usernamePending: false,
          profile: DEFAULT_PROFILE,
          verifications: [],
          trustLevel: 0,
          registered: false,
          ownerAddress: action.ownerAddress,
          zoneFile: null
        }
      ]
      })
    case types.UPDATE_PROFILE: {
      const newLocalIdentities = state.localIdentities.slice()
      newLocalIdentities[action.index].profile = action.profile
      newLocalIdentities[action.index].zoneFile = action.zoneFile
      return Object.assign({}, state, {
        localIdentities: newLocalIdentities
      })
    }
    case types.UPDATE_SOCIAL_PROOF_VERIFICATIONS: {
      const newLocalIdentities = state.localIdentities.slice()
      newLocalIdentities[action.index].verifications =
      JSON.parse(JSON.stringify(action.verifications))
      newLocalIdentities[action.index].trustLevel = action.trustLevel
      return Object.assign({}, state, {
        localIdentities: newLocalIdentities
      })
    }
    case types.ADD_USERNAME: {
      const newLocalIdentities = state.localIdentities.slice()
      newLocalIdentities[action.index].username = action.username
      newLocalIdentities[action.index].usernamePending = true
      newLocalIdentities[action.index].usernameOwned = false
      return Object.assign({}, state, {<commit_msg>Fix duplicated profiles when creating new ID. #1040 #1173.<commit_after>import * as types from './types'
import { DEFAULT_PROFILE } from '../../../utils/profile-utils'

const initialState = {
  default: 0, // persist
  localIdentities: [], 
  publicIdentities: {},
  nameTransfers: [],
  zoneFileUpdates: [],
  createProfileError: null
}

function IdentityReducer(state = initialState, action) {
  switch (action.type) {
    case types.UPDATE_PUBLIC_IDENTITY:
      return Object.assign({}, state, {
        publicIdentities: Object.assign({}, state.publicIdentities, {
          [action.username]: {
            username: action.username,
            ownerAddress: action.ownerAddress,
            zoneFile: action.zoneFile,
            profile: JSON.parse(JSON.stringify(action.profile)),
            verifications: JSON.parse(JSON.stringify(action.verifications)),
            trustLevel: action.trustLevel
          }
        })
      })
    case types.SET_DEFAULT:
      return Object.assign({}, state, {
        default: action.index
      })
    case types.CREATE_NEW:
      return Object.assign({}, state, {
        localIdentities: [...state.localIdentities, {
          username: null,
          usernameOwned: false,
          usernamePending: false,
          profile: Object.assign({}, DEFAULT_PROFILE),
          verifications: [],
          trustLevel: 0,
          registered: false,
          ownerAddress: action.ownerAddress,
          zoneFile: null
        }
      ]
      })
    case types.UPDATE_PROFILE: {
      const newLocalIdentities = state.localIdentities.slice()
      newLocalIdentities[action.index].profile = action.profile
      newLocalIdentities[action.index].zoneFile = action.zoneFile
      return Object.assign({}, state, {
        localIdentities: newLocalIdentities
      })
    }
    case types.UPDATE_SOCIAL_PROOF_VERIFICATIONS: {
      const newLocalIdentities = state.localIdentities.slice()
      newLocalIdentities[action.index].verifications =
      JSON.parse(JSON.stringify(action.verifications))
      newLocalIdentities[action.index].trustLevel = action.trustLevel
      return Object.assign({}, state, {
        localIdentities: newLocalIdentities
      })
    }
    case types.ADD_USERNAME: {
      const newLocalIdentities = state.localIdentities.slice()
      newLocalIdentities[action.index].username = action.username
      newLocalIdentities[action.index].usernamePending = true
      newLocalIdentities[action.index].usernameOwned = false
      return Object.assign({}, state, {
{'fraction_non_alphanumeric': 0.10814046288906624, 'fraction_numerical': 0.0023942537909018356, 'mean_word_length': 2.7271375464684016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4029578', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1348, 'n_words': 249}