diff --git a/embark-ui/src/components/ExplorerLayout.js b/embark-ui/src/components/ExplorerLayout.js index cd06477cc..8f238b16b 100644 --- a/embark-ui/src/components/ExplorerLayout.js +++ b/embark-ui/src/components/ExplorerLayout.js @@ -1,8 +1,9 @@ import PropTypes from "prop-types"; import React from 'react'; import connect from "react-redux/es/connect/connect"; -import {Route, Switch} from 'react-router-dom'; +import {Route, Switch, withRouter} from 'react-router-dom'; import {explorerSearch} from "../actions"; +import {searchResult} from "../reducers/selectors"; import AccountsContainer from '../containers/AccountsContainer'; import AccountContainer from '../containers/AccountContainer'; @@ -12,31 +13,59 @@ import TransactionsContainer from '../containers/TransactionsContainer'; import TransactionContainer from '../containers/TransactionContainer'; import SearchBar from '../components/SearchBar'; -const ExplorerLayout = ({explorerSearch}) => ( - - explorerSearch(searchValue)}/> - - - - - - - - - -); +class ExplorerLayout extends React.Component { + shouldComponentUpdate(nextProps) { + if (nextProps.searchResult && nextProps.searchResult !== this.props.searchResult) { + console.log('New result', nextProps.searchResult); + if (nextProps.searchResult.address) { + this.props.history.push(`/embark/explorer/accounts/${nextProps.searchResult.address}`); + return false; + } + if (nextProps.searchResult.hasOwnProperty('transactionIndex')) { + this.props.history.push(`/embark/explorer/transactions/${nextProps.searchResult.hash}`); + return false; + } + if (nextProps.searchResult.hasOwnProperty('number')) { + this.props.history.push(`/embark/explorer/blocks/${nextProps.searchResult.number}`); + return false; + } + // Returned something we didn't know existed + } + return true; + } + + render() { + const {explorerSearch} = this.props; + return ( + + explorerSearch(searchValue)}/> + {searchResult && {JSON.stringify(searchResult)}} + + + + + + + + + + ); + } +} ExplorerLayout.propTypes = { - explorerSearch: PropTypes.func + explorerSearch: PropTypes.func, + searchResult: PropTypes.object, + history: PropTypes.object }; -// function mapStateToProps(state) { -// return {accounts: getAccounts(state), error: state.errorMessage, loading: state.loading}; -// } +function mapStateToProps(state) { + return {searchResult: searchResult(state)}; +} -export default connect( - null, +export default withRouter(connect( + mapStateToProps, { explorerSearch: explorerSearch.request }, -)(ExplorerLayout); +)(ExplorerLayout)); diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 34f8dd827..9d2eda39f 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -231,7 +231,7 @@ function theme(state=DARK_THEME, action) { return state; } -function searchResult(state = '', action) { +function searchResult(state = {}, action) { if (action.type === EXPLORER_SEARCH[SUCCESS]) { return action.searchResult; } diff --git a/embark-ui/src/reducers/selectors.js b/embark-ui/src/reducers/selectors.js index b59174e4f..bf5708c27 100644 --- a/embark-ui/src/reducers/selectors.js +++ b/embark-ui/src/reducers/selectors.js @@ -172,3 +172,7 @@ export function getCurrentFile(state) { export function getBaseEther(state) { return state.baseEther; } + +export function searchResult(state) { + return state.searchResult; +} diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 90fdd875c..355d53702 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -32,8 +32,9 @@ function *searchExplorer(entity, payload) { // Blocks yield fetchBlocks({limit: 100}); const blocks = yield select(getBlocks); + const intSearchValue = parseInt(payload.searchValue, 10); result = blocks.find(block => { - return block.hash === payload.searchValue; + return block.hash === payload.searchValue || block.number === intSearchValue; }); if (result) {