<commit_before>import {Blockchains, IBackendApi, HDPath, AnyCoinCode, IVault} from "@emeraldwallet/core";
import {SagaIterator} from "redux-saga";
import {all, call, put, takeEvery, takeLatest} from "@redux-saga/core/effects";
import {ActionTypes, ILoadAddresses, ILoadBalances} from "./types";
import * as actions from "./actions";

function* loadAddresses(vault: IVault, action: ILoadAddresses): SagaIterator {
  const accountId = HDPath.parse(action.hdpath).account
  for (const blockchain of action.blockchains) {
    const blockchainDetails = Blockchains[blockchain.toLowerCase()];
    const hdpath = blockchainDetails.params.hdPath.forAccount(accountId).toString();
    const addresses: { [key: string]: string } = yield call([vault, vault.listSeedAddresses], action.seed, "ethereum", [hdpath]);
    yield put(actions.setAddresses(action.seed, blockchain, addresses))
    for (const address of Object.values(addresses)) {
      yield put(actions.loadBalances(blockchain, address, blockchainDetails.getAssets()))
    }
  }
}

function* loadBalances(backendApi: IBackendApi, action: ILoadBalances): SagaIterator {
  const balance: { [key in AnyCoinCode]: string } = yield call([backendApi, backendApi.getBalance], action.blockchain, action.address, action.assets)
  for (const asset of Object.keys(balance)) {
    yield put(actions.setBalance(action.blockchain, action.address, asset as AnyCoinCode, balance[asset as AnyCoinCode]))
  }
}

export function* root(vault: IVault, backendApi: IBackendApi) {
  yield all([
    takeLatest(ActionTypes.LOAD_ADDRESSES, loadAddresses, vault),
    takeLatest(ActionTypes.LOAD_BALANCES, loadBalances, backendApi)
  ]);
}<commit_msg>problem: loads balance only for one of the blockchains<commit_after>import {Blockchains, IBackendApi, HDPath, AnyCoinCode, IVault} from "@emeraldwallet/core";
import {SagaIterator} from "redux-saga";
import {all, call, put, takeEvery, takeLatest} from "@redux-saga/core/effects";
import {ActionTypes, ILoadAddresses, ILoadBalances} from "./types";
import * as actions from "./actions";

function* loadAddresses(vault: IVault, action: ILoadAddresses): SagaIterator {
  const accountId = HDPath.parse(action.hdpath).account
  for (const blockchain of action.blockchains) {
    const blockchainDetails = Blockchains[blockchain.toLowerCase()];
    const hdpath = blockchainDetails.params.hdPath.forAccount(accountId).toString();
    const addresses: { [key: string]: string } = yield call([vault, vault.listSeedAddresses], action.seed, "ethereum", [hdpath]);
    yield put(actions.setAddresses(action.seed, blockchain, addresses))
    for (const address of Object.values(addresses)) {
      yield put(actions.loadBalances(blockchain, address, blockchainDetails.getAssets()))
    }
  }
}

function* loadBalances(backendApi: IBackendApi, action: ILoadBalances): SagaIterator {
  const balance: { [key in AnyCoinCode]: string } = yield call([backendApi, backendApi.getBalance], action.blockchain, action.address, action.assets)
  for (const asset of Object.keys(balance)) {
    yield put(actions.setBalance(action.blockchain, action.address, asset as AnyCoinCode, balance[asset as AnyCoinCode]))
  }
}

export function* root(vault: IVault, backendApi: IBackendApi) {
  yield all([
    takeEvery(ActionTypes.LOAD_ADDRESSES, loadAddresses, vault),
    takeEvery(ActionTypes.LOAD_BALANCES, loadBalances, backendApi)
  ]);
}
{'fraction_non_alphanumeric': 0.12075583111898436, 'fraction_numerical': 0.0, 'mean_word_length': 5.95687885010267, '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': '4429528', 'n_tokens_mistral': 1043, 'n_tokens_neox': 1027, 'n_words': 250}