-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update deposit flow #401
Update deposit flow #401
Changes from 13 commits
d4ea05b
148117f
a51979f
4d9e3db
69e0169
964dadf
9dad5b3
10729f8
879ffcc
f97c58a
126acdd
8d94038
e2cec5f
0a420d1
a14030f
fa1ba0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React from "react" | ||
import { | ||
Box, | ||
Card, | ||
CardBody, | ||
Flex, | ||
useMultiStyleConfig, | ||
Image, | ||
} from "@chakra-ui/react" | ||
import { useSidebar, useDocsDrawer } from "#/hooks" | ||
import rewardsBoostArrow from "#/assets/images/rewards-boost-arrow.svg" | ||
import mysteryBoxIcon from "#/assets/images/mystery-box.svg" | ||
import seasonKeyIcon from "#/assets/images/season-key.svg" | ||
import ButtonLink from "./shared/ButtonLink" | ||
import { TextSm } from "./shared/Typography" | ||
|
||
const BUTTONS = [ | ||
{ label: "Docs", variant: "solid" }, | ||
{ label: "FAQ", colorScheme: "gold" }, | ||
{ label: "Token Contract", colorScheme: "gold" }, | ||
{ label: "Bridge Contract", colorScheme: "gold" }, | ||
] | ||
|
||
const BENEFITS = [ | ||
{ label: "1x Rewards Boost", iconSrc: rewardsBoostArrow }, | ||
{ label: "1x Mystery Box", iconSrc: mysteryBoxIcon }, | ||
{ label: "1x Season Key", iconSrc: seasonKeyIcon }, | ||
] | ||
|
||
export default function Sidebar() { | ||
const { isOpen } = useSidebar() | ||
const { onOpen: openDocsDrawer } = useDocsDrawer() | ||
const styles = useMultiStyleConfig("Sidebar") | ||
|
||
return ( | ||
<Box | ||
as="aside" | ||
mt="header_height" | ||
w={isOpen ? "sidebar_width" : "0"} | ||
__css={styles.sidebarContainer} | ||
> | ||
<Box __css={styles.sidebar}> | ||
<TextSm fontWeight="bold">Rewards you’ll unlock</TextSm> | ||
|
||
<Flex mt={2} mb={7} flexDir="column" gap={2}> | ||
{BENEFITS.map(({ label, iconSrc }) => ( | ||
<Card | ||
key={label} | ||
bg="gold.300" | ||
borderWidth="1px" | ||
borderColor="white" | ||
> | ||
<CardBody | ||
display="flex" | ||
flexDirection="row" | ||
justifyContent="space-between" | ||
alignItems="center" | ||
py={0} | ||
px={4} | ||
> | ||
<TextSm fontWeight="semibold">{label}</TextSm> | ||
<Image src={iconSrc} boxSize="3.75rem" /> | ||
</CardBody> | ||
</Card> | ||
))} | ||
</Flex> | ||
|
||
{BUTTONS.map(({ label, variant, colorScheme }) => ( | ||
<ButtonLink | ||
key={label} | ||
onClick={openDocsDrawer} | ||
variant={variant} | ||
colorScheme={colorScheme} | ||
> | ||
{label} | ||
</ButtonLink> | ||
))} | ||
</Box> | ||
</Box> | ||
) | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,6 @@ | ||
import React, { useCallback, useState } from "react" | ||
import { Box, ModalBody, ModalCloseButton, ModalHeader } from "@chakra-ui/react" | ||
import { | ||
ModalBody, | ||
Tabs, | ||
TabList, | ||
Tab, | ||
TabPanels, | ||
TabPanel, | ||
ModalCloseButton, | ||
} from "@chakra-ui/react" | ||
import { | ||
useModalFlowContext, | ||
useStakeFlowContext, | ||
useTransactionContext, | ||
useWalletContext, | ||
|
@@ -20,16 +11,36 @@ import { logPromiseFailure } from "#/utils" | |
import StakeFormModal from "./ActiveStakingStep/StakeFormModal" | ||
import UnstakeFormModal from "./ActiveUnstakingStep/UnstakeFormModal" | ||
|
||
const TABS = Object.values(ACTION_FLOW_TYPES) | ||
const FORM_DATA: Record< | ||
ActionFlowType, | ||
{ | ||
header: string | ||
FormComponent: ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep the key in camel case. It's confusing. const { foo: Foo } = bar There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm this was a special trick to make it clear that it should be used as a component. However, if there is any doubt I can simplify it. |
||
props: React.ComponentProps< | ||
typeof StakeFormModal | typeof UnstakeFormModal | ||
>, | ||
) => React.ReactNode | ||
} | ||
> = { | ||
stake: { | ||
header: "Deposit", | ||
FormComponent: StakeFormModal, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
unstake: { | ||
header: "Withdraw", | ||
FormComponent: UnstakeFormModal, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}, | ||
} | ||
|
||
function ActionFormModal({ defaultType }: { defaultType: ActionFlowType }) { | ||
function ActionFormModal({ type }: { type: ActionFlowType }) { | ||
const { btcAccount, ethAccount } = useWalletContext() | ||
const { type, setType } = useModalFlowContext() | ||
const { setTokenAmount } = useTransactionContext() | ||
const { initStake } = useStakeFlowContext() | ||
|
||
const [isLoading, setIsLoading] = useState(false) | ||
|
||
const { header, FormComponent } = FORM_DATA[type] | ||
|
||
const handleInitStake = useCallback(async () => { | ||
const btcAddress = btcAccount?.address | ||
const ethAddress = ethAccount?.address | ||
|
@@ -67,34 +78,11 @@ function ActionFormModal({ defaultType }: { defaultType: ActionFlowType }) { | |
return ( | ||
<> | ||
{!isLoading && <ModalCloseButton />} | ||
<ModalHeader>{header}</ModalHeader> | ||
<ModalBody> | ||
<Tabs | ||
w="100%" | ||
variant="underline" | ||
defaultIndex={TABS.indexOf(defaultType)} | ||
> | ||
<TabList pb={6}> | ||
{TABS.map((actionFlowType) => ( | ||
<Tab | ||
key={actionFlowType} | ||
w="50%" | ||
pb={4} | ||
onClick={() => setType(actionFlowType)} | ||
isDisabled={actionFlowType !== type && isLoading} | ||
> | ||
{actionFlowType} | ||
</Tab> | ||
))} | ||
</TabList> | ||
<TabPanels> | ||
<TabPanel> | ||
<StakeFormModal onSubmitForm={handleSubmitFormWrapper} /> | ||
</TabPanel> | ||
<TabPanel> | ||
<UnstakeFormModal onSubmitForm={handleSubmitFormWrapper} /> | ||
</TabPanel> | ||
</TabPanels> | ||
</Tabs> | ||
<Box w="100%"> | ||
<FormComponent onSubmitForm={handleSubmitFormWrapper} /> | ||
</Box> | ||
</ModalBody> | ||
</> | ||
) | ||
|
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.
I'd rename "header" to "heading". By header we usually mean the very top component on a page. It's a little confusing
Also we don't need such strict type safety for
formComponent
. It's declared only once for private use of the component only. JustReact.ReactNode
is enough.,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.
Sure, let's change it. 0a420d1
We call the content in the component and need to pass the necessary props. Therefore, we need to declare it in such a way as to pass the right props to the component. So even though this is called once I think we need to declare the type here. As a result, when calling
renderComponent
, we get a suggestion of what props should be given.However, I have simplified the definition of form component type. - a14030f