-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #822 from alleslabs/feat/api-v1-validator-list
feat: validator list
- Loading branch information
Showing
24 changed files
with
967 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Flex, Text } from "@chakra-ui/react"; | ||
import { Select } from "chakra-react-select"; | ||
import { useMemo } from "react"; | ||
|
||
import type { Option } from "lib/types"; | ||
|
||
interface ActiveFilterProps { | ||
isActive: boolean; | ||
setIsActive: (value: boolean) => void; | ||
activeCount: Option<number>; | ||
inactiveCount: Option<number>; | ||
} | ||
|
||
const getOptionLabel = (label: string, count: Option<number>) => | ||
label + (count ? ` (${count})` : ""); | ||
|
||
export const ActiveFilter = ({ | ||
isActive, | ||
setIsActive, | ||
activeCount, | ||
inactiveCount, | ||
}: ActiveFilterProps) => { | ||
const activeOptions = useMemo( | ||
() => [ | ||
{ label: getOptionLabel("Active validators", activeCount), value: true }, | ||
{ | ||
label: getOptionLabel("Inactive validators", inactiveCount), | ||
value: false, | ||
}, | ||
], | ||
[activeCount, inactiveCount] | ||
); | ||
|
||
return ( | ||
<Flex direction="column" gap={1} minW={{ base: "full", md: "240px" }}> | ||
<Text variant="body3" color="text.dark" pl={{ base: 1, md: 3 }}> | ||
Show only | ||
</Text> | ||
<Select | ||
size="lg" | ||
options={activeOptions} | ||
value={activeOptions.find(({ value }) => value === isActive)} | ||
onChange={(selectedOption) => | ||
selectedOption && setIsActive(selectedOption.value) | ||
} | ||
chakraStyles={{ | ||
valueContainer: (provided) => ({ | ||
...provided, | ||
pl: 3, | ||
pr: 0, | ||
}), | ||
dropdownIndicator: (provided) => ({ | ||
...provided, | ||
px: 2, | ||
}), | ||
option: (provided) => ({ | ||
...provided, | ||
color: "text.main", | ||
fontSize: "16px", | ||
_hover: { | ||
bg: "gray.700", | ||
}, | ||
_selected: { | ||
bg: "gray.800", | ||
}, | ||
}), | ||
}} | ||
isSearchable={false} | ||
/> | ||
</Flex> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { Flex, Text } from "@chakra-ui/react"; | ||
import { Select } from "chakra-react-select"; | ||
|
||
import { ValidatorOrder } from "../types"; | ||
|
||
const ORDER_OPTIONS = [ | ||
{ | ||
label: "Validator Name (A to Z)", | ||
value: { order: ValidatorOrder.Moniker, isDesc: false }, | ||
}, | ||
{ | ||
label: "Validator Name (Z to A)", | ||
value: { order: ValidatorOrder.Moniker, isDesc: true }, | ||
}, | ||
{ | ||
label: "Voting Power (High to Low)", | ||
value: { order: ValidatorOrder.VotingPower, isDesc: true }, | ||
}, | ||
{ | ||
label: "Voting Power (Low to High)", | ||
value: { order: ValidatorOrder.VotingPower, isDesc: false }, | ||
}, | ||
{ | ||
label: "Uptime (High to Low)", | ||
value: { order: ValidatorOrder.Uptime, isDesc: true }, | ||
}, | ||
{ | ||
label: "Uptime (Low to High)", | ||
value: { order: ValidatorOrder.Uptime, isDesc: false }, | ||
}, | ||
{ | ||
label: "Commission (High to Low)", | ||
value: { order: ValidatorOrder.Commission, isDesc: true }, | ||
}, | ||
{ | ||
label: "Commission (Low to High)", | ||
value: { order: ValidatorOrder.Commission, isDesc: false }, | ||
}, | ||
]; | ||
|
||
interface OrderSelectProps { | ||
order: ValidatorOrder; | ||
setOrder: (value: ValidatorOrder) => void; | ||
isDesc: boolean; | ||
setIsDesc: (value: boolean) => void; | ||
} | ||
|
||
export const OrderSelect = ({ | ||
order, | ||
setOrder, | ||
isDesc, | ||
setIsDesc, | ||
}: OrderSelectProps) => ( | ||
<Flex direction="column" gap={1} minW="full"> | ||
<Text variant="body3" color="text.dark" pl={1}> | ||
Sorted by | ||
</Text> | ||
<Select | ||
size="lg" | ||
options={ORDER_OPTIONS} | ||
value={ORDER_OPTIONS.find( | ||
({ value }) => value.order === order && value.isDesc === isDesc | ||
)} | ||
onChange={(selectedOption) => { | ||
if (selectedOption) { | ||
setOrder(selectedOption.value.order); | ||
setIsDesc(selectedOption.value.isDesc); | ||
} | ||
}} | ||
chakraStyles={{ | ||
valueContainer: (provided) => ({ | ||
...provided, | ||
pl: 3, | ||
pr: 0, | ||
}), | ||
dropdownIndicator: (provided) => ({ | ||
...provided, | ||
px: 2, | ||
}), | ||
option: (provided) => ({ | ||
...provided, | ||
color: "text.main", | ||
fontSize: "16px", | ||
_hover: { | ||
bg: "gray.700", | ||
}, | ||
_selected: { | ||
bg: "gray.800", | ||
}, | ||
}), | ||
}} | ||
isSearchable={false} | ||
/> | ||
</Flex> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./ActiveFilter"; | ||
export * from "./OrderSelect"; |
Oops, something went wrong.