-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
261 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Grid } from "@chakra-ui/react"; | ||
import type { IconType } from "react-icons"; | ||
import { MdCheck, MdHowToVote, MdPerson } from "react-icons/md"; | ||
|
||
import type { PermissionFilterValue } from "lib/hooks"; | ||
|
||
import { SelectInput } from "./SelectInput"; | ||
|
||
interface PermissionOption { | ||
label: string; | ||
value: PermissionFilterValue; | ||
disabled: boolean; | ||
icon?: IconType; | ||
iconColor: string; | ||
} | ||
|
||
interface FilterByPermissionProps { | ||
setPermissionValue: (newVal: PermissionFilterValue) => void; | ||
initialSelected: string; | ||
} | ||
|
||
const options: PermissionOption[] = [ | ||
{ | ||
label: "All", | ||
value: "all", | ||
disabled: false, | ||
icon: MdCheck, | ||
iconColor: "gray.600", | ||
}, | ||
{ | ||
label: "Can Instantiate without proposal", | ||
value: "without-proposal", | ||
disabled: false, | ||
icon: MdPerson, | ||
iconColor: "primary.main", | ||
}, | ||
{ | ||
label: "Instantiate through proposal only", | ||
value: "with-proposal", | ||
disabled: false, | ||
icon: MdHowToVote, | ||
iconColor: "text.dark", | ||
}, | ||
]; | ||
|
||
export const FilterByPermission = ({ | ||
setPermissionValue, | ||
initialSelected, | ||
}: FilterByPermissionProps) => { | ||
return ( | ||
<Grid columnGap="16px" w="full" mb="16px" maxW="360px"> | ||
<SelectInput<PermissionFilterValue> | ||
formLabel="Filter by Instantiate Permission" | ||
options={options} | ||
onChange={setPermissionValue} | ||
placeholder="Select" | ||
initialSelected={initialSelected} | ||
/> | ||
</Grid> | ||
); | ||
}; |
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,46 @@ | ||
import { useWallet } from "@cosmos-kit/react"; | ||
import { useCallback } from "react"; | ||
|
||
import type { CodeInfo, HumanAddr } from "lib/types"; | ||
import { InstantiatePermission } from "lib/types"; | ||
|
||
export type PermissionFilterValue = | ||
| "all" | ||
| "without-proposal" | ||
| "with-proposal"; | ||
|
||
export const usePermissionFilter = (filterValue?: PermissionFilterValue) => { | ||
const { address } = useWallet(); | ||
return useCallback( | ||
({ instantiatePermission, permissionAddresses }: CodeInfo) => { | ||
const isAllowed = | ||
permissionAddresses.includes(address as HumanAddr) || | ||
instantiatePermission === InstantiatePermission.EVERYBODY; | ||
|
||
switch (filterValue) { | ||
case "with-proposal": | ||
return !isAllowed; | ||
case "without-proposal": | ||
return isAllowed; | ||
case "all": | ||
default: | ||
return true; | ||
} | ||
}, | ||
[address, filterValue] | ||
); | ||
}; | ||
|
||
export const useSearchFilter = (keyword = "") => { | ||
return useCallback( | ||
(code: CodeInfo) => { | ||
const computedKeyword = keyword.trim(); | ||
if (!computedKeyword.length) return true; | ||
return ( | ||
code.id.toString().startsWith(computedKeyword) || | ||
code.description?.toLowerCase().includes(computedKeyword.toLowerCase()) | ||
); | ||
}, | ||
[keyword] | ||
); | ||
}; |
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
Oops, something went wrong.