diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 5f47313aa..16a8c6519 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -3,7 +3,8 @@ import * as api from '../services/api'; import * as storage from '../services/storage'; import {eventChannel} from 'redux-saga'; import {all, call, fork, put, takeLatest, takeEvery, take, select, race} from 'redux-saga/effects'; -import {getCredentials, getBlocks, getTransactions, getAccounts} from '../reducers/selectors'; +import {getCredentials} from '../reducers/selectors'; +import {searchExplorer} from './searchSaga'; function *doRequest(entity, serviceFn, payload) { payload.credentials = yield select(getCredentials); @@ -15,47 +16,6 @@ function *doRequest(entity, serviceFn, payload) { } } -function *searchExplorer(entity, payload) { - let result; - const SEARCH_LIMIT = 100; - - // Accounts - yield fetchAccounts({}); - const accounts = yield select(getAccounts); - result = accounts.find(account => { - return account.address === payload.searchValue; - }); - - if (result) { - return yield put(entity.success(result)); - } - - // Blocks - yield fetchBlocks({limit: SEARCH_LIMIT}); - const blocks = yield select(getBlocks); - const intSearchValue = parseInt(payload.searchValue, 10); - result = blocks.find(block => { - return block.hash === payload.searchValue || block.number === intSearchValue; - }); - - if (result) { - return yield put(entity.success(result)); - } - - // Transactions - yield fetchTransactions({blockLimit: SEARCH_LIMIT}); - const transactions = yield select(getTransactions); - result = transactions.find(transaction => { - return transaction.hash === payload.searchValue; - }); - - if (result) { - return yield put(entity.success(result)); - } - - return yield put(entity.success({error: 'No result found in transactions, accounts or blocks'})); -} - export const fetchPlugins = doRequest.bind(null, actions.plugins, api.fetchPlugins); export const fetchVersions = doRequest.bind(null, actions.versions, api.fetchVersions); export const fetchAccount = doRequest.bind(null, actions.account, api.fetchAccount); @@ -85,7 +45,6 @@ export const postFile = doRequest.bind(null, actions.saveFile, api.postFile); export const deleteFile = doRequest.bind(null, actions.removeFile, api.deleteFile); export const fetchEthGas = doRequest.bind(null, actions.gasOracle, api.getEthGasAPI); export const authenticate = doRequest.bind(null, actions.authenticate, api.authenticate); -export const explorerSearch = searchExplorer.bind(null, actions.explorerSearch); export const fetchCurrentFile = doRequest.bind(null, actions.currentFile, storage.fetchCurrentFile); export const postCurrentFile = doRequest.bind(null, actions.saveCurrentFile, storage.postCurrentFile); @@ -96,6 +55,8 @@ export const logout = doRequest.bind(null, actions.logout, storage.logout); export const changeTheme = doRequest.bind(null, actions.changeTheme, storage.changeTheme); export const fetchTheme = doRequest.bind(null, actions.fetchTheme, storage.fetchTheme); +export const explorerSearch = searchExplorer.bind(null, actions.explorerSearch); + export function *watchFetchTransaction() { yield takeEvery(actions.TRANSACTION[actions.REQUEST], fetchTransaction); diff --git a/embark-ui/src/sagas/searchSaga.js b/embark-ui/src/sagas/searchSaga.js new file mode 100644 index 000000000..5ba0e89f6 --- /dev/null +++ b/embark-ui/src/sagas/searchSaga.js @@ -0,0 +1,44 @@ +import {put, select} from "redux-saga/effects"; +import {getAccounts, getBlocks, getTransactions} from "../reducers/selectors"; +import {fetchAccounts, fetchBlocks, fetchTransactions} from "./index"; + +export function *searchExplorer(entity, payload) { + let result; + const SEARCH_LIMIT = 100; + + // Accounts + yield fetchAccounts({}); + const accounts = yield select(getAccounts); + result = accounts.find(account => { + return account.address === payload.searchValue; + }); + + if (result) { + return yield put(entity.success(result)); + } + + // Blocks + yield fetchBlocks({limit: SEARCH_LIMIT}); + const blocks = yield select(getBlocks); + const intSearchValue = parseInt(payload.searchValue, 10); + result = blocks.find(block => { + return block.hash === payload.searchValue || block.number === intSearchValue; + }); + + if (result) { + return yield put(entity.success(result)); + } + + // Transactions + yield fetchTransactions({blockLimit: SEARCH_LIMIT}); + const transactions = yield select(getTransactions); + result = transactions.find(transaction => { + return transaction.hash === payload.searchValue; + }); + + if (result) { + return yield put(entity.success(result)); + } + + return yield put(entity.success({error: 'No result found in transactions, accounts or blocks'})); +}