mirror of https://github.com/embarklabs/embark.git
Merge pull request #1036 from embark-framework/features/eth-search
Add searching ENS names in cockpit search bar
This commit is contained in:
commit
70b26176db
|
@ -157,6 +157,10 @@ export function getEnsRecords(state) {
|
|||
return state.entities.ensRecords;
|
||||
}
|
||||
|
||||
export function getEnsRecordForName(state, name) {
|
||||
return state.entities.ensRecords.find((record) => record.name === name);
|
||||
}
|
||||
|
||||
export function getEnsErrors(state) {
|
||||
return state.errorEntities.ensRecords;
|
||||
}
|
||||
|
|
|
@ -1,16 +1,28 @@
|
|||
import {put, select} from "redux-saga/effects";
|
||||
import {getAccounts, getBlocks, getTransactions, getContracts} from "../reducers/selectors";
|
||||
import {fetchAccounts, fetchBlocks, fetchTransactions, fetchContracts} from "./index";
|
||||
import {getAccounts, getBlocks, getTransactions, getContracts, getEnsRecordForName} from "../reducers/selectors";
|
||||
import {fetchAccounts, fetchBlocks, fetchTransactions, fetchContracts, fetchEnsRecord} from "./index";
|
||||
import {ELEMENTS_LIMIT} from '../constants';
|
||||
|
||||
export function *searchExplorer(entity, payload) {
|
||||
let result;
|
||||
let searchValue = payload.searchValue;
|
||||
let isENSName = false;
|
||||
if (searchValue.endsWith('.eth')) {
|
||||
isENSName = true;
|
||||
yield fetchEnsRecord({name: payload.searchValue});
|
||||
const ensRecord = yield select(getEnsRecordForName, searchValue);
|
||||
|
||||
if (!ensRecord) {
|
||||
return yield put(entity.success({error: 'No ENS record for that name'}));
|
||||
}
|
||||
searchValue = ensRecord.address;
|
||||
}
|
||||
|
||||
// Accounts
|
||||
yield fetchAccounts({});
|
||||
const accounts = yield select(getAccounts);
|
||||
result = accounts.find(account => {
|
||||
return account.address === payload.searchValue;
|
||||
return account.address === searchValue;
|
||||
});
|
||||
|
||||
if (result) {
|
||||
|
@ -21,7 +33,7 @@ export function *searchExplorer(entity, payload) {
|
|||
yield fetchContracts({});
|
||||
const contracts = yield select(getContracts);
|
||||
result = contracts.find(contract => {
|
||||
return contract.address === payload.searchValue;
|
||||
return contract.address === searchValue;
|
||||
});
|
||||
|
||||
if (result) {
|
||||
|
@ -31,9 +43,9 @@ export function *searchExplorer(entity, payload) {
|
|||
// Blocks
|
||||
yield fetchBlocks({limit: ELEMENTS_LIMIT});
|
||||
const blocks = yield select(getBlocks);
|
||||
const intSearchValue = parseInt(payload.searchValue, 10);
|
||||
const intSearchValue = parseInt(searchValue, 10);
|
||||
result = blocks.find(block => {
|
||||
return block.hash === payload.searchValue || block.number === intSearchValue;
|
||||
return block.hash === searchValue || block.number === intSearchValue;
|
||||
});
|
||||
|
||||
if (result) {
|
||||
|
@ -44,12 +56,16 @@ export function *searchExplorer(entity, payload) {
|
|||
yield fetchTransactions({blockLimit: ELEMENTS_LIMIT});
|
||||
const transactions = yield select(getTransactions);
|
||||
result = transactions.find(transaction => {
|
||||
return transaction.hash === payload.searchValue;
|
||||
return transaction.hash === searchValue;
|
||||
});
|
||||
|
||||
if (result) {
|
||||
return yield put(entity.success(result));
|
||||
}
|
||||
|
||||
if (isENSName) {
|
||||
return yield put(entity.success({error: `ENS resolved to ${searchValue}, but Embark couldn't find what this address represents`}));
|
||||
}
|
||||
|
||||
return yield put(entity.success({error: `No result found in transactions, accounts, contracts, or blocks. Please note: We limit the search to the last ${ELEMENTS_LIMIT} elements for performance`}));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue