mirror of https://github.com/embarklabs/embark.git
feat(cockpit): add searching ENS names in search bar
This commit is contained in:
parent
c25c644b5a
commit
dca52d0d4e
|
@ -157,6 +157,10 @@ export function getEnsRecords(state) {
|
||||||
return state.entities.ensRecords;
|
return state.entities.ensRecords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getEnsRecordForName(state, name) {
|
||||||
|
return state.entities.ensRecords.find((record) => record.name === name);
|
||||||
|
}
|
||||||
|
|
||||||
export function getEnsErrors(state) {
|
export function getEnsErrors(state) {
|
||||||
return state.errorEntities.ensRecords;
|
return state.errorEntities.ensRecords;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,28 @@
|
||||||
import {put, select} from "redux-saga/effects";
|
import {put, select} from "redux-saga/effects";
|
||||||
import {getAccounts, getBlocks, getTransactions, getContracts} from "../reducers/selectors";
|
import {getAccounts, getBlocks, getTransactions, getContracts, getEnsRecordForName} from "../reducers/selectors";
|
||||||
import {fetchAccounts, fetchBlocks, fetchTransactions, fetchContracts} from "./index";
|
import {fetchAccounts, fetchBlocks, fetchTransactions, fetchContracts, fetchEnsRecord} from "./index";
|
||||||
import {ELEMENTS_LIMIT} from '../constants';
|
import {ELEMENTS_LIMIT} from '../constants';
|
||||||
|
|
||||||
export function *searchExplorer(entity, payload) {
|
export function *searchExplorer(entity, payload) {
|
||||||
let result;
|
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
|
// Accounts
|
||||||
yield fetchAccounts({});
|
yield fetchAccounts({});
|
||||||
const accounts = yield select(getAccounts);
|
const accounts = yield select(getAccounts);
|
||||||
result = accounts.find(account => {
|
result = accounts.find(account => {
|
||||||
return account.address === payload.searchValue;
|
return account.address === searchValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -21,7 +33,7 @@ export function *searchExplorer(entity, payload) {
|
||||||
yield fetchContracts({});
|
yield fetchContracts({});
|
||||||
const contracts = yield select(getContracts);
|
const contracts = yield select(getContracts);
|
||||||
result = contracts.find(contract => {
|
result = contracts.find(contract => {
|
||||||
return contract.address === payload.searchValue;
|
return contract.address === searchValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -31,9 +43,9 @@ export function *searchExplorer(entity, payload) {
|
||||||
// Blocks
|
// Blocks
|
||||||
yield fetchBlocks({limit: ELEMENTS_LIMIT});
|
yield fetchBlocks({limit: ELEMENTS_LIMIT});
|
||||||
const blocks = yield select(getBlocks);
|
const blocks = yield select(getBlocks);
|
||||||
const intSearchValue = parseInt(payload.searchValue, 10);
|
const intSearchValue = parseInt(searchValue, 10);
|
||||||
result = blocks.find(block => {
|
result = blocks.find(block => {
|
||||||
return block.hash === payload.searchValue || block.number === intSearchValue;
|
return block.hash === searchValue || block.number === intSearchValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
|
@ -44,12 +56,16 @@ export function *searchExplorer(entity, payload) {
|
||||||
yield fetchTransactions({blockLimit: ELEMENTS_LIMIT});
|
yield fetchTransactions({blockLimit: ELEMENTS_LIMIT});
|
||||||
const transactions = yield select(getTransactions);
|
const transactions = yield select(getTransactions);
|
||||||
result = transactions.find(transaction => {
|
result = transactions.find(transaction => {
|
||||||
return transaction.hash === payload.searchValue;
|
return transaction.hash === searchValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
return yield put(entity.success(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`}));
|
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