-
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 #65 from alleslabs/feat/instantiate-button
Feat/instantiate button
- Loading branch information
Showing
17 changed files
with
281 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { chakra, Tag } from "@chakra-ui/react"; | ||
import { useWallet } from "@cosmos-kit/react"; | ||
import type { CSSProperties } from "react"; | ||
|
||
import type { HumanAddr, PermissionAddresses } from "lib/types"; | ||
import { InstantiatePermission } from "lib/types"; | ||
|
||
const StyledTag = chakra(Tag, { | ||
baseStyle: { | ||
borderRadius: "16px", | ||
fontSize: "12px", | ||
fontWeight: 400, | ||
color: "text.main", | ||
}, | ||
}); | ||
|
||
interface PermissionChipProps { | ||
instantiatePermission: InstantiatePermission; | ||
permissionAddresses: PermissionAddresses; | ||
} | ||
|
||
export const PermissionChip = ({ | ||
instantiatePermission, | ||
permissionAddresses, | ||
}: PermissionChipProps) => { | ||
const { address } = useWallet(); | ||
|
||
const isAllowed = | ||
permissionAddresses.includes(address as HumanAddr) || | ||
instantiatePermission === InstantiatePermission.EVERYBODY; | ||
|
||
const tagBgColor: CSSProperties["backgroundColor"] = isAllowed | ||
? "rgba(161, 230, 143, 0.5)" | ||
: "rgba(173, 173, 173, 0.6)"; | ||
|
||
return <StyledTag bgColor={tagBgColor}>{instantiatePermission}</StyledTag>; | ||
}; |
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,94 @@ | ||
import type { ButtonProps } from "@chakra-ui/react"; | ||
import { Button, chakra, Icon, Tooltip } from "@chakra-ui/react"; | ||
import { useWallet } from "@cosmos-kit/react"; | ||
import { useRouter } from "next/router"; | ||
import { MdHowToVote, MdPerson } from "react-icons/md"; | ||
|
||
import type { HumanAddr, PermissionAddresses } from "lib/types"; | ||
import { InstantiatePermission } from "lib/types"; | ||
|
||
interface InstantiateButtonProps extends ButtonProps { | ||
instantiatePermission: InstantiatePermission; | ||
permissionAddresses: PermissionAddresses; | ||
codeId: number; | ||
} | ||
|
||
const StyledIcon = chakra(Icon, { | ||
baseStyle: { | ||
boxSize: "4", | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
}); | ||
|
||
const getInstantiateButtonProps = ( | ||
isAllowed: boolean, | ||
isDisabled: boolean | ||
): { | ||
tooltipLabel: string; | ||
variant: string; | ||
icon: JSX.Element | undefined; | ||
} => { | ||
if (isAllowed) { | ||
return { | ||
tooltipLabel: isDisabled | ||
? "You need to connect wallet to instantiate" | ||
: "You can instantiate without opening proposal", | ||
variant: "outline-primary", | ||
icon: <StyledIcon as={MdPerson} />, | ||
}; | ||
} | ||
return { | ||
tooltipLabel: isDisabled | ||
? "" | ||
: "Instantiate through proposal only, Coming soon", | ||
variant: "outline-gray", | ||
icon: isDisabled ? undefined : <StyledIcon as={MdHowToVote} />, | ||
}; | ||
}; | ||
|
||
export const InstantiateButton = ({ | ||
instantiatePermission = InstantiatePermission.UNKNOWN, | ||
permissionAddresses = [], | ||
codeId, | ||
...buttonProps | ||
}: InstantiateButtonProps) => { | ||
const router = useRouter(); | ||
const { address } = useWallet(); | ||
const goToInstantiate = () => | ||
router.push({ pathname: "/instantiate", query: { "code-id": codeId } }); | ||
|
||
const isAllowed = | ||
permissionAddresses.includes(address as HumanAddr) || | ||
instantiatePermission === InstantiatePermission.EVERYBODY; | ||
const isDisabled = | ||
instantiatePermission === InstantiatePermission.UNKNOWN || !address; | ||
|
||
const { tooltipLabel, variant, icon } = getInstantiateButtonProps( | ||
isAllowed, | ||
isDisabled | ||
); | ||
|
||
return ( | ||
<Tooltip | ||
hasArrow | ||
label={tooltipLabel} | ||
placement="top" | ||
arrowSize={8} | ||
bg="primary.dark" | ||
> | ||
<Button | ||
// Change to isDisabled when create proposal flow is done | ||
disabled={!isAllowed} | ||
// disabled={isDisabled} | ||
variant={variant} | ||
leftIcon={icon} | ||
size="sm" | ||
onClick={isAllowed ? goToInstantiate : () => null} | ||
{...buttonProps} | ||
> | ||
Instantiate | ||
</Button> | ||
</Tooltip> | ||
); | ||
}; |
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
Oops, something went wrong.
974c931
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
celatone-frontend-staging – ./
celatone-frontend-staging-git-develop-alles-labs.vercel.app
celatone-frontend-staging-alles-labs.vercel.app
celatone-frontend-staging.vercel.app
osmosis-staging.celat.one