mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-11 06:25:57 +00:00
move explorer search to its own file
This commit is contained in:
parent
29ec199195
commit
cf294d8bb2
@ -3,7 +3,8 @@ import * as api from '../services/api';
|
|||||||
import * as storage from '../services/storage';
|
import * as storage from '../services/storage';
|
||||||
import {eventChannel} from 'redux-saga';
|
import {eventChannel} from 'redux-saga';
|
||||||
import {all, call, fork, put, takeLatest, takeEvery, take, select, race} from 'redux-saga/effects';
|
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) {
|
function *doRequest(entity, serviceFn, payload) {
|
||||||
payload.credentials = yield select(getCredentials);
|
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 fetchPlugins = doRequest.bind(null, actions.plugins, api.fetchPlugins);
|
||||||
export const fetchVersions = doRequest.bind(null, actions.versions, api.fetchVersions);
|
export const fetchVersions = doRequest.bind(null, actions.versions, api.fetchVersions);
|
||||||
export const fetchAccount = doRequest.bind(null, actions.account, api.fetchAccount);
|
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 deleteFile = doRequest.bind(null, actions.removeFile, api.deleteFile);
|
||||||
export const fetchEthGas = doRequest.bind(null, actions.gasOracle, api.getEthGasAPI);
|
export const fetchEthGas = doRequest.bind(null, actions.gasOracle, api.getEthGasAPI);
|
||||||
export const authenticate = doRequest.bind(null, actions.authenticate, api.authenticate);
|
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 fetchCurrentFile = doRequest.bind(null, actions.currentFile, storage.fetchCurrentFile);
|
||||||
export const postCurrentFile = doRequest.bind(null, actions.saveCurrentFile, storage.postCurrentFile);
|
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 changeTheme = doRequest.bind(null, actions.changeTheme, storage.changeTheme);
|
||||||
export const fetchTheme = doRequest.bind(null, actions.fetchTheme, storage.fetchTheme);
|
export const fetchTheme = doRequest.bind(null, actions.fetchTheme, storage.fetchTheme);
|
||||||
|
|
||||||
|
export const explorerSearch = searchExplorer.bind(null, actions.explorerSearch);
|
||||||
|
|
||||||
|
|
||||||
export function *watchFetchTransaction() {
|
export function *watchFetchTransaction() {
|
||||||
yield takeEvery(actions.TRANSACTION[actions.REQUEST], fetchTransaction);
|
yield takeEvery(actions.TRANSACTION[actions.REQUEST], fetchTransaction);
|
||||||
|
44
embark-ui/src/sagas/searchSaga.js
Normal file
44
embark-ui/src/sagas/searchSaga.js
Normal file
@ -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'}));
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user