<commit_before>import {combineReducers} from "redux";
import {LOAD_ACCOUNT, LOAD_STATE, NEW_ACCOUNT} from "b:actions/index";
import {addSpecs} from "b:spec";

const noAccount = "";

const accounts = combineReducers({
  byAddress,
  current,
  loaded,
});

export default accounts;

function byAddress(state = {}, action) {
  switch(action.type) {
    case LOAD_STATE:
      return action.wallet.byAddress || state;
    case NEW_ACCOUNT:
      let address = action.keypair.address();
      let seed = action.keypair.seed();

      return Object.assign({}, state, {
        [address]: { address, seed }
      })
    default:
      return state;
  }
}

function current(state = noAccount, action) {
  switch(action.type) {
    case LOAD_STATE:
      if (state) return state;


      let fromWallet = action.wallet.current;
      if (fromWallet in action.wallet.byAddress) {
        return fromWallet;
      }
      return Object.keys(action.wallet.byAddress)[0] || noAccount;
    case LOAD_ACCOUNT:
      return action.address
    default:
      return state;
  }
}

function loaded(state = false, action) {
   switch(action.type) {
    case LOAD_STATE:
      return true
    default:
      return state;
  }
}


export function specs(s) {
  let {expect} = s;
  let {describe} = s.reducer;

  describe(byAddress, context => {
    context({
      state: {},
      action: {
        type: LOAD_STATE,
        wallet: {
          byAddress: {"123": 3}
        }
      }
    }, it => {
      it("replaces the state", (state, action) => {
        expect(state).to.equal(action.wallet.byAddress);
      });
    });
  });

  describe(loaded, context => {
    // for reducer tests, context takes both a<commit_msg>Add current account reducer spec<commit_after>import {combineReducers} from "redux";
import {LOAD_ACCOUNT, LOAD_STATE, NEW_ACCOUNT} from "b:actions/index";
import {addSpecs} from "b:spec";

const noAccount = "";

const accounts = combineReducers({
  byAddress,
  current,
  loaded,
});

export default accounts;

function byAddress(state = {}, action) {
  switch(action.type) {
    case LOAD_STATE:
      return action.wallet.byAddress || state;
    case NEW_ACCOUNT:
      let address = action.keypair.address();
      let seed = action.keypair.seed();

      return Object.assign({}, state, {
        [address]: { address, seed }
      })
    default:
      return state;
  }
}

function current(state = noAccount, action) {
  switch(action.type) {
    case LOAD_STATE:
      if (state) return state;


      let fromWallet = action.wallet.current;
      if (fromWallet in action.wallet.byAddress) {
        return fromWallet;
      }
      return Object.keys(action.wallet.byAddress)[0] || noAccount;
    case LOAD_ACCOUNT:
      return action.address
    default:
      return state;
  }
}

function loaded(state = false, action) {
   switch(action.type) {
    case LOAD_STATE:
      return true
    default:
      return state;
  }
}


export function specs(s) {
  let {expect, contracts} = s;
  let {describe} = s.reducer;

  describe(byAddress, context => {
    context({
      state: {},
      action: {
        type: LOAD_STATE,
        wallet: {
          byAddress: {"123": 3}
        }
      }
    }, it => {
      it("replaces the state", (state, action) => {
        expect(state).to.equal(action.wallet.byAddress);
      });
    });
  });

  describe(current, context => {
    context({
      state: noAccount,
      action: {
        type: LOAD_ACCOUNT,
        address: "123",
      }
    }, it => {
      it("replaces the state", (state, action) =>  {
        expect(state).to.equal(action.address);
      })
    })
  })

  describe(loaded, context => {
    // for reducer tests, context takes both a
{'fraction_non_alphanumeric': 0.13007256113947863, 'fraction_numerical': 0.0034936844934157483, 'mean_word_length': 2.5179584120982987, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 14, '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': '7227176', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1182, 'n_words': 279}