Skip to content

Commit

Permalink
Simplify form data for ActionFormModal component
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosiorowska committed May 14, 2024
1 parent e2cec5f commit 0a420d1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions dapp/src/components/TransactionModal/ActionFormModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from "react"
import React, { ReactNode, useCallback, useState } from "react"
import { Box, ModalBody, ModalCloseButton, ModalHeader } from "@chakra-ui/react"
import {
useStakeFlowContext,
Expand All @@ -14,21 +14,21 @@ import UnstakeFormModal from "./ActiveUnstakingStep/UnstakeFormModal"
const FORM_DATA: Record<
ActionFlowType,
{
header: string
FormComponent: (
heading: string
renderComponent: (
props: React.ComponentProps<
typeof StakeFormModal | typeof UnstakeFormModal
>,
) => React.ReactNode
) => ReactNode
}
> = {
stake: {
header: "Deposit",
FormComponent: StakeFormModal,
heading: "Deposit",
renderComponent: StakeFormModal,
},
unstake: {
header: "Withdraw",
FormComponent: UnstakeFormModal,
heading: "Withdraw",
renderComponent: UnstakeFormModal,
},
}

Expand All @@ -39,7 +39,7 @@ function ActionFormModal({ type }: { type: ActionFlowType }) {

const [isLoading, setIsLoading] = useState(false)

const { header, FormComponent } = FORM_DATA[type]
const { heading, renderComponent } = FORM_DATA[type]

const handleInitStake = useCallback(async () => {
const btcAddress = btcAccount?.address
Expand Down Expand Up @@ -78,10 +78,10 @@ function ActionFormModal({ type }: { type: ActionFlowType }) {
return (
<>
{!isLoading && <ModalCloseButton />}
<ModalHeader>{header}</ModalHeader>
<ModalHeader>{heading}</ModalHeader>
<ModalBody>
<Box w="100%">
<FormComponent onSubmitForm={handleSubmitFormWrapper} />
{renderComponent({ onSubmitForm: handleSubmitFormWrapper })}
</Box>
</ModalBody>
</>
Expand Down

0 comments on commit 0a420d1

Please sign in to comment.