Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/components/SearchSmall.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import {
pageChanged
} from '../features/layout/layoutSlice';
import { useGetValidatorsQuery } from '../features/api/validatorsSlice';

export default function SearchSmall({width = 512}) {
// const theme = useTheme();
Expand All @@ -25,14 +26,31 @@ export default function SearchSmall({width = 512}) {
const currentSelected = useSelector(selectAddress);
const [address, setAddress] = React.useState("");
let [searchParams, setSearchParams] = useSearchParams();

const { data: validators } = useGetValidatorsQuery({
show_profile: true,
size: 20
}, {
skip: !address || address.length < 3
});

const handleChange = (event) => {
setAddress(event.target.value);
}

const handleSubmit = (event) => {
event.preventDefault()
if (isValidAddress(address)) {
const validatorMatch = validators?.data?.find(v =>
v.identity?.display?.toLowerCase() === address.toLowerCase()
);

if (validatorMatch) {
const defaultSS58 = addressSS58(validatorMatch.address);
dispatch(addressChanged(defaultSS58));
dispatch(pageChanged(`validator/${defaultSS58}`));
navigate(`/validator/${validatorMatch.address}`)
setAddress("");
} else if (isValidAddress(address)) {
const defaultSS58 = addressSS58(address)
dispatch(addressChanged(defaultSS58));
dispatch(pageChanged(`validator/${defaultSS58}`));
Expand All @@ -52,7 +70,7 @@ export default function SearchSmall({width = 512}) {
width,
}}
variant="outlined"
placeholder="Search by validator stash address"
placeholder="Search by identity or stash address"
color="primary"
value={address}
onChange={handleChange}
Expand Down Expand Up @@ -84,4 +102,4 @@ export default function SearchSmall({width = 512}) {
/>
</form>
)
}
}