-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify the logic for
TransactionModal
(#408)
Ref #394 This PR simplifies the logic of opening modal windows and does a refactor for the `TransacionModal` component. The component of the modal type should be global and should not be rendered inside nested components. The new logic allows to define a modal component only once. This will make it easier to call up the deposit flow from the dashboard and landing page. Previously `TransacionModal` used contexts by what caused a mess in the component. To manage the state of action flow logic, a special slice was created in the redux store.
- Loading branch information
Showing
37 changed files
with
341 additions
and
232 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, { ElementType } from "react" | ||
import { useModal } from "#/hooks" | ||
import { ModalType } from "#/types" | ||
import TransactionModal from "../TransactionModal" | ||
|
||
const MODALS: Record<ModalType, ElementType> = { | ||
STAKE: TransactionModal, | ||
UNSTAKE: TransactionModal, | ||
} as const | ||
|
||
export default function ModalRoot() { | ||
const { modalType, modalProps, closeModal } = useModal() | ||
|
||
if (!modalType) { | ||
return null | ||
} | ||
const SpecificModal = MODALS[modalType] | ||
return <SpecificModal closeModal={closeModal} {...modalProps} /> | ||
} |
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,29 @@ | ||
import React, { ComponentType } from "react" | ||
import { Modal, ModalContent, ModalOverlay } from "@chakra-ui/react" | ||
import { BaseModalProps } from "#/types" | ||
|
||
export const MODAL_BASE_SIZE = "lg" | ||
|
||
function withBaseModal<T extends BaseModalProps>( | ||
WrappedModalContent: ComponentType<T>, | ||
) { | ||
return function ModalBase(props: T) { | ||
const { closeModal } = props | ||
return ( | ||
<Modal | ||
isOpen | ||
onClose={closeModal} | ||
scrollBehavior="inside" | ||
closeOnOverlayClick={false} | ||
size={MODAL_BASE_SIZE} | ||
> | ||
<ModalOverlay mt="header_height" /> | ||
<ModalContent mt="modal_shift"> | ||
<WrappedModalContent {...props} /> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
} | ||
|
||
export default withBaseModal |
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
9 changes: 5 additions & 4 deletions
9
dapp/src/components/TransactionModal/ActiveStakingStep/StakingErrorModal/index.tsx
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.